@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.List; | |||
/** | |||
* 机场前端控制器 | |||
* | |||
@@ -26,8 +28,8 @@ public class AirPortController { | |||
* 获取巡检机场 | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult getList() { | |||
return airportService.getAirportList(); | |||
public JsonResult getList(List<Long> ids) { | |||
return airportService.getAirportList(ids); | |||
} | |||
/** | |||
* 获取巡检线路 |
@@ -4,9 +4,11 @@ import com.tuoheng.admin.dto.ReversalFlightDto; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import java.util.List; | |||
public interface AirportService { | |||
JsonResult getAirportList(); | |||
JsonResult getAirportList(List<Long> ids); | |||
JsonResult getAirLineList(String sn); | |||
@@ -6,6 +6,8 @@ import com.tuoheng.common.core.utils.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
@Service | |||
public class AirportServiceImpl implements AirportService { | |||
@@ -28,8 +30,8 @@ public class AirportServiceImpl implements AirportService { | |||
private GetAirportVideoService getAirportVideoService; | |||
@Override | |||
public JsonResult getAirportList() { | |||
return getAirportListService.getAirportList(); | |||
public JsonResult getAirportList(List<Long> ids) { | |||
return getAirportListService.getAirportList(ids); | |||
} | |||
@Override |
@@ -19,13 +19,13 @@ public class GetAirLineListService { | |||
public JsonResult getAirLineList(String sn) { | |||
//根据机场序列号获取航线列表 | |||
JsonResult result = tzhlGetAirportLineListService.getAirportLine(null,sn,null); | |||
// JsonResult result = tzhlGetAirportLineListService.getAirportLine(null,sn,null); | |||
// | |||
// if(result.getCode() != 0){ | |||
// return JsonResult.error(result.getMsg()); | |||
// } | |||
if(result.getCode() != 0){ | |||
return JsonResult.error(result.getMsg()); | |||
} | |||
return result; | |||
return null; | |||
} | |||
@@ -1,25 +1,23 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportListService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
@Slf4j | |||
@Service | |||
public class GetAirportListService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private TZHLGetAirportListService tzhlGetAirportListService; | |||
public JsonResult getAirportList() { | |||
public JsonResult getAirportList(List<Long> ids) { | |||
//读取全量机场列表数据 | |||
JsonResult result = tzhlGetAirportListService.getAirportList(); | |||
JsonResult result = tzhlGetAirportListService.getAirportList(ids); | |||
if(result.getCode() != 0){ | |||
return JsonResult.error(result.getMsg()); |
@@ -16,10 +16,15 @@ public class TZHLGetAirportLineListRequest { | |||
private String name; | |||
/** | |||
* 方舱序列号机场id | |||
* 方舱序列号sn | |||
*/ | |||
private String sn; | |||
/** | |||
* 航线id | |||
*/ | |||
private Long id; | |||
/** | |||
* 航线类型 线状航线 面状航线 带状航线 | |||
*/ |
@@ -20,6 +20,9 @@ import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestClientException; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.List; | |||
import java.util.Map; | |||
@Slf4j | |||
@Service | |||
public class CallTianYiPlatformService { | |||
@@ -31,7 +34,7 @@ public class CallTianYiPlatformService { | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public String callGet(String apiPath, HttpEntity<Object> httpEntity) { | |||
public String callGet(String apiPath, Object request) { | |||
String token = this.getToken(); | |||
if (StringUtils.isEmpty(token)) { | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "token不能为空"); | |||
@@ -42,6 +45,8 @@ public class CallTianYiPlatformService { | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.add("Authorization", properties); | |||
HttpEntity<Object> httpEntity = new HttpEntity<>(request, headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JsonResult.class); | |||
@@ -64,7 +69,7 @@ public class CallTianYiPlatformService { | |||
return JSONObject.toJSONString(response.getBody().getData()); | |||
} | |||
public String callPost(String apiPath, HttpEntity<Object> httpEntity) { | |||
public String callPost(String apiPath, Object request) { | |||
// 获取同行令牌token | |||
String token = this.getToken(); | |||
if (StringUtils.isEmpty(token)) { | |||
@@ -74,10 +79,12 @@ public class CallTianYiPlatformService { | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.add("Authorization", properties); | |||
HttpEntity<Object> httpEntity = new HttpEntity<>(request, headers); | |||
String url = TZHLConfig.tzhlURL + apiPath; | |||
ResponseEntity<TZHLTokenResponse> response; | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, TZHLTokenResponse.class); | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("泰州海陵区城管,接口异常, url:{}", url); | |||
log.info("泰州海陵区城管,接口异常, httpEntity:{}", httpEntity); | |||
@@ -89,7 +96,7 @@ public class CallTianYiPlatformService { | |||
log.info("泰州海陵区城管,接口失败, httpEntity:{}", httpEntity); | |||
throw new ServiceException("南京海事局,接口失败"); | |||
} | |||
return JSONObject.toJSONString(response.getBody()); | |||
return JSONObject.toJSONString(response.getBody().getData()); | |||
} | |||
/** |
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 获取机场列表 | |||
@@ -36,11 +37,9 @@ public class TZHLGetAirportListService { | |||
String param = "?ids=" + idList; | |||
//读取全量机场平台列表 | |||
String url = CommonConfig.tianYiUrl + TZHLConstant.TIAN_YI_API_AIRPORT_LIST + param; | |||
String url = TZHLConstant.TIAN_YI_API_AIRPORT_LIST + param; | |||
HttpEntity<Object> httpEntity = new HttpEntity<>(null); | |||
String data = callTianYiPlatformService.callGet(url, httpEntity); | |||
String data = callTianYiPlatformService.callGet(url, null); | |||
//List<GetAirportListDto> getAirportListDtoLists = JSON.parseArray(JSON.parse(body).toString(), GetAirportListDto.class); | |||
List<GetAirportListDto> getAirportListDtoList = JSON.parseArray(data, GetAirportListDto.class); | |||
if(ObjectUtil.isNull(getAirportListDtoList)){ |
@@ -1,6 +1,7 @@ | |||
package com.tuoheng.admin.tzhl.service.airport; | |||
import com.tuoheng.admin.tzhl.constant.TZHLConstant; | |||
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; | |||
import com.tuoheng.admin.tzhl.service.token.TZHLGetTokenService; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -26,56 +27,24 @@ import org.springframework.web.client.RestTemplate; | |||
public class TZHLGetAirportMsgService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Autowired | |||
private TZHLGetTokenService tzhlGetTokenService; | |||
private CallTianYiPlatformService callTianYiPlatformService; | |||
public JsonResult getAirportMsg(String sn){ | |||
//获取同行令牌token | |||
String token = tzhlGetTokenService.getToken(); | |||
JsonResult jsonResult = this.check(sn,token); | |||
JsonResult jsonResult = this.check(sn); | |||
if(jsonResult.getCode() != 0){ | |||
return JsonResult.error(jsonResult.getMsg()); | |||
} | |||
//读取全量机场平台列表 | |||
String param = "?sn=" +sn; | |||
String url = CommonConfig.tianYiUrl + TZHLConstant.TIAN_YI_API_AIRPORT_MSG + param; | |||
String properties = "Bearer " + token; | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.add("Authorization",properties); | |||
HttpEntity<Object> httpEntity = new HttpEntity<>(null, headers); | |||
ResponseEntity<JsonResult> response; | |||
//获取全量机场列表 | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JsonResult.class); | |||
} catch (RestClientException e) { | |||
log.info("请求获取机场url:{}", url); | |||
log.info("请求获取机场列表, httpEntity:{}", httpEntity); | |||
return JsonResult.error("请求获取机场列表失败"); | |||
} | |||
if (null == response || !response.hasBody()) { | |||
log.error("请求获取机场,response为空"); | |||
return JsonResult.error("请求获取机场response为空"); | |||
} | |||
if (response.getBody().getCode() != 200) { | |||
log.error("请求获取机场列表" + response.getBody()); | |||
return JsonResult.error(response.getBody().getMsg()); | |||
} | |||
log.info("查询机场列表数据成功,response={}", response); | |||
Object data = response.getBody().getData(); | |||
String url = TZHLConstant.TIAN_YI_API_AIRPORT_MSG + param; | |||
String data = callTianYiPlatformService.callGet(url, null); | |||
return JsonResult.success(data); | |||
} | |||
private JsonResult check(String sn,String token) { | |||
if(StringUtils.isEmpty(token)){ | |||
return JsonResult.error("token不存在或已过期"); | |||
} | |||
private JsonResult check(String sn) { | |||
if(StringUtils.isEmpty(sn)){ | |||
return JsonResult.error("机场方舱序列号为空"); | |||
} |
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.tzhl.constant.TZHLConstant; | |||
import com.tuoheng.admin.tzhl.request.TZHLGetAirportLineListRequest; | |||
import com.tuoheng.admin.tzhl.response.TZHLAirportLineResponse; | |||
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; | |||
import com.tuoheng.admin.tzhl.service.token.TZHLGetTokenService; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
@@ -31,47 +32,25 @@ public class TZHLGetAirportLineListService { | |||
@Autowired | |||
private TZHLGetTokenService tzhlGetTokenService; | |||
@Autowired | |||
private CallTianYiPlatformService callTianYiPlatformService; | |||
@Autowired | |||
private RestTemplate restTemplate; | |||
public JsonResult getAirportLine(String name, String sn, String lineType){ | |||
String token = tzhlGetTokenService.getToken(); | |||
public JsonResult getAirportLine(String name, String sn, Long id, String lineType){ | |||
TZHLGetAirportLineListRequest request = new TZHLGetAirportLineListRequest(); | |||
request.setName(name); | |||
request.setSn(sn); | |||
request.setId(id); | |||
request.setLineType(lineType); | |||
JsonResult result =this.check(token); | |||
if(result.getCode() != 0){ | |||
return JsonResult.error(result.getMsg()); | |||
} | |||
//获取航线列表 | |||
String url = CommonConfig.tianYiUrl + TZHLConstant.TIAN_YI_API_FLY_LINE_LIST; | |||
String properties = "Bearer " + token; | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
headers.add("Authorization",properties); | |||
HttpEntity<Object> httpEntity = new HttpEntity<>(request,headers); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (RestClientException e) { | |||
log.info("请求获取机场url:{}", url); | |||
log.info("请求获取机场列表, httpEntity:{}", httpEntity); | |||
return JsonResult.error("请求获取机场列表失败"); | |||
} | |||
if(null == response || !response.hasBody()){ | |||
log.error("获取机场航线列表失败"); | |||
throw new ServiceException(HttpStatus.BAD_REQUEST.value(),"获取机场列表失败"); | |||
} | |||
if(response.getBody().getCode() != 200){ | |||
log.error("获取机场航线列表失"+response.getBody()); | |||
return JsonResult.error(response.getBody().getMsg()); | |||
} | |||
String url = TZHLConstant.TIAN_YI_API_FLY_LINE_LIST; | |||
String data = callTianYiPlatformService.callPost(url, request); | |||
List<TZHLAirportLineResponse> tzhlAirportLineResponses = JSON.parseArray(JSONObject.toJSONString(response.getBody().getData()), | |||
TZHLAirportLineResponse.class); | |||
List<TZHLAirportLineResponse> tzhlAirportLineResponses = JSON.parseArray(data,TZHLAirportLineResponse.class); | |||
return JsonResult.success(tzhlAirportLineResponses); |
@@ -44,7 +44,7 @@ public class FlyDataService { | |||
HttpEntity httpEntity = new HttpEntity(request, headers); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, httpEntity); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, null); | |||
TZHLFlyLogResponse flyDataResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class); | |||
@@ -43,7 +43,7 @@ public class FlyLogService { | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(request, headers); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, httpEntity); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, null); | |||
TZHLFlyLogResponse flyLogResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class); | |||
@@ -38,7 +38,7 @@ public class OnlineUavService { | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(null, headers); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, httpEntity); | |||
String dataJson = callTianYiPlatformService.callGet(apiPath, null); | |||
TZHLOnlineUavResponse onlineUavResponse = JSON.parseObject(dataJson, TZHLOnlineUavResponse.class); | |||
@@ -27,8 +27,9 @@ public class TZHLGetAirportLineListServiceTest { | |||
String name = null; | |||
String sn = "4TADKCC0010018"; | |||
String lineType = null; | |||
JsonResult result = tzhlGetAirportLineListService.getAirportLine(name,sn,lineType); | |||
System.out.println("data" + result.getData()); | |||
Long id = null; | |||
JsonResult result = tzhlGetAirportLineListService.getAirportLine(name,sn,id,lineType); | |||
System.out.println("data值为" + result.getData()); | |||
} | |||
} |
@@ -9,6 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/8/9 | |||
@@ -23,7 +26,9 @@ public class TZHLGetAirportListServiceTest { | |||
@Test | |||
public void testGetAirportListTest() { | |||
JsonResult result = tzhlGetAirportListService.getAirportList(); | |||
List<Long> ids = new ArrayList<>(); | |||
ids.add(7l); | |||
JsonResult result = tzhlGetAirportListService.getAirportList(ids); | |||
System.out.println("data" + result.getData()); | |||
} | |||