Browse Source

重构获取航线 机场 气象数据接口代码

tags/v1.3.1
chengwang 1 year ago
parent
commit
8d361b8c61
15 changed files with 72 additions and 103 deletions
  1. +4
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java
  2. +3
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java
  3. +4
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java
  4. +6
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/GetAirLineListService.java
  5. +4
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/GetAirportListService.java
  6. +6
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/request/TZHLGetAirportLineListRequest.java
  7. +12
    -5
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/CallTianYiPlatformService.java
  8. +3
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airport/TZHLGetAirportListService.java
  9. +7
    -38
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airport/TZHLGetAirportMsgService.java
  10. +11
    -32
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airportline/TZHLGetAirportLineListService.java
  11. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/data/FlyDataService.java
  12. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/log/FlyLogService.java
  13. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/onlineuav/OnlineUavService.java
  14. +3
    -2
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportLineListServiceTest.java
  15. +6
    -1
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportListServiceTest.java

+ 4
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java View File

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import java.util.List;

/** /**
* 机场前端控制器 * 机场前端控制器
* *
* 获取巡检机场 * 获取巡检机场
*/ */
@GetMapping("/list") @GetMapping("/list")
public JsonResult getList() {
return airportService.getAirportList();
public JsonResult getList(List<Long> ids) {
return airportService.getAirportList(ids);
} }
/** /**
* 获取巡检线路 * 获取巡检线路

+ 3
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java View File

import com.tuoheng.admin.entity.Inspection; import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;


import java.util.List;

public interface AirportService { public interface AirportService {


JsonResult getAirportList();
JsonResult getAirportList(List<Long> ids);


JsonResult getAirLineList(String sn); JsonResult getAirLineList(String sn);



+ 4
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java View File

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.List;

@Service @Service
public class AirportServiceImpl implements AirportService { public class AirportServiceImpl implements AirportService {


private GetAirportVideoService getAirportVideoService; private GetAirportVideoService getAirportVideoService;


@Override @Override
public JsonResult getAirportList() {
return getAirportListService.getAirportList();
public JsonResult getAirportList(List<Long> ids) {
return getAirportListService.getAirportList(ids);
} }


@Override @Override

+ 6
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/GetAirLineListService.java View File



public JsonResult getAirLineList(String sn) { 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;


} }



+ 4
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/GetAirportListService.java View File

package com.tuoheng.admin.service.third.airport; package com.tuoheng.admin.service.third.airport;


import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportListService; import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportListService;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.List;

@Slf4j @Slf4j
@Service @Service
public class GetAirportListService { public class GetAirportListService {


@Autowired
private TenantMapper tenantMapper;

@Autowired @Autowired
private TZHLGetAirportListService tzhlGetAirportListService; 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){ if(result.getCode() != 0){
return JsonResult.error(result.getMsg()); return JsonResult.error(result.getMsg());

+ 6
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/request/TZHLGetAirportLineListRequest.java View File

private String name; private String name;


/** /**
* 方舱序列号机场id
* 方舱序列号sn
*/ */
private String sn; private String sn;


/**
* 航线id
*/
private Long id;

/** /**
* 航线类型 线状航线 面状航线 带状航线 * 航线类型 线状航线 面状航线 带状航线
*/ */

+ 12
- 5
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/CallTianYiPlatformService.java View File

import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;


import java.util.List;
import java.util.Map;

@Slf4j @Slf4j
@Service @Service
public class CallTianYiPlatformService { public class CallTianYiPlatformService {
@Qualifier("restTemplate") @Qualifier("restTemplate")
private RestTemplate restTemplate; private RestTemplate restTemplate;


public String callGet(String apiPath, HttpEntity<Object> httpEntity) {
public String callGet(String apiPath, Object request) {
String token = this.getToken(); String token = this.getToken();
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "token不能为空"); throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "token不能为空");
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", properties); headers.add("Authorization", properties);


HttpEntity<Object> httpEntity = new HttpEntity<>(request, headers);

ResponseEntity<JsonResult> response; ResponseEntity<JsonResult> response;
try { try {
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JsonResult.class); response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JsonResult.class);
return JSONObject.toJSONString(response.getBody().getData()); return JSONObject.toJSONString(response.getBody().getData());
} }


public String callPost(String apiPath, HttpEntity<Object> httpEntity) {
public String callPost(String apiPath, Object request) {
// 获取同行令牌token // 获取同行令牌token
String token = this.getToken(); String token = this.getToken();
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", properties); headers.add("Authorization", properties);


HttpEntity<Object> httpEntity = new HttpEntity<>(request, headers);

String url = TZHLConfig.tzhlURL + apiPath; String url = TZHLConfig.tzhlURL + apiPath;
ResponseEntity<TZHLTokenResponse> response;
ResponseEntity<JsonResult> response;
try { try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, TZHLTokenResponse.class);
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
} catch (Exception e) { } catch (Exception e) {
log.info("泰州海陵区城管,接口异常, url:{}", url); log.info("泰州海陵区城管,接口异常, url:{}", url);
log.info("泰州海陵区城管,接口异常, httpEntity:{}", httpEntity); log.info("泰州海陵区城管,接口异常, httpEntity:{}", httpEntity);
log.info("泰州海陵区城管,接口失败, httpEntity:{}", httpEntity); log.info("泰州海陵区城管,接口失败, httpEntity:{}", httpEntity);
throw new ServiceException("南京海事局,接口失败"); throw new ServiceException("南京海事局,接口失败");
} }
return JSONObject.toJSONString(response.getBody());
return JSONObject.toJSONString(response.getBody().getData());
} }


/** /**

+ 3
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airport/TZHLGetAirportListService.java View File

import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;


import java.util.List; import java.util.List;
import java.util.Map;


/** /**
* 获取机场列表 * 获取机场列表
String param = "?ids=" + idList; 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> getAirportListDtoLists = JSON.parseArray(JSON.parse(body).toString(), GetAirportListDto.class);
List<GetAirportListDto> getAirportListDtoList = JSON.parseArray(data, GetAirportListDto.class); List<GetAirportListDto> getAirportListDtoList = JSON.parseArray(data, GetAirportListDto.class);
if(ObjectUtil.isNull(getAirportListDtoList)){ if(ObjectUtil.isNull(getAirportListDtoList)){

+ 7
- 38
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airport/TZHLGetAirportMsgService.java View File

package com.tuoheng.admin.tzhl.service.airport; package com.tuoheng.admin.tzhl.service.airport;


import com.tuoheng.admin.tzhl.constant.TZHLConstant; 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.admin.tzhl.service.token.TZHLGetTokenService;
import com.tuoheng.common.core.config.common.CommonConfig; import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
public class TZHLGetAirportMsgService { public class TZHLGetAirportMsgService {


@Autowired @Autowired
@Qualifier("restTemplate")
private RestTemplate restTemplate;

@Autowired
private TZHLGetTokenService tzhlGetTokenService;
private CallTianYiPlatformService callTianYiPlatformService;


public JsonResult getAirportMsg(String sn){ 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){ if(jsonResult.getCode() != 0){
return JsonResult.error(jsonResult.getMsg()); return JsonResult.error(jsonResult.getMsg());
} }
//读取全量机场平台列表 //读取全量机场平台列表
String param = "?sn=" +sn; 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); 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)){ if(StringUtils.isEmpty(sn)){
return JsonResult.error("机场方舱序列号为空"); return JsonResult.error("机场方舱序列号为空");
} }

+ 11
- 32
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/airportline/TZHLGetAirportLineListService.java View File

import com.tuoheng.admin.tzhl.constant.TZHLConstant; import com.tuoheng.admin.tzhl.constant.TZHLConstant;
import com.tuoheng.admin.tzhl.request.TZHLGetAirportLineListRequest; import com.tuoheng.admin.tzhl.request.TZHLGetAirportLineListRequest;
import com.tuoheng.admin.tzhl.response.TZHLAirportLineResponse; 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.admin.tzhl.service.token.TZHLGetTokenService;
import com.tuoheng.common.core.config.common.CommonConfig; import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException; import com.tuoheng.common.core.exception.ServiceException;
@Autowired @Autowired
private TZHLGetTokenService tzhlGetTokenService; private TZHLGetTokenService tzhlGetTokenService;


@Autowired
private CallTianYiPlatformService callTianYiPlatformService;

@Autowired @Autowired
private RestTemplate restTemplate; 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(); TZHLGetAirportLineListRequest request = new TZHLGetAirportLineListRequest();
request.setName(name); request.setName(name);
request.setSn(sn); request.setSn(sn);
request.setId(id);
request.setLineType(lineType); 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); return JsonResult.success(tzhlAirportLineResponses);

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/data/FlyDataService.java View File

HttpEntity httpEntity = new HttpEntity(request, headers); 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); TZHLFlyLogResponse flyDataResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class);



+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/log/FlyLogService.java View File

headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity httpEntity = new HttpEntity(request, headers); 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); TZHLFlyLogResponse flyLogResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class);



+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/onlineuav/OnlineUavService.java View File

headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity httpEntity = new HttpEntity(null, headers); 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); TZHLOnlineUavResponse onlineUavResponse = JSON.parseObject(dataJson, TZHLOnlineUavResponse.class);



+ 3
- 2
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportLineListServiceTest.java View File

String name = null; String name = null;
String sn = "4TADKCC0010018"; String sn = "4TADKCC0010018";
String lineType = null; 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());
} }


} }

+ 6
- 1
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/tzhl/TZHLGetAirportListServiceTest.java View File

import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;


import java.util.ArrayList;
import java.util.List;

/** /**
* @Author ChengWang * @Author ChengWang
* @Date 2023/8/9 * @Date 2023/8/9


@Test @Test
public void testGetAirportListTest() { 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()); System.out.println("data" + result.getData());
} }



Loading…
Cancel
Save