|
|
@@ -2,23 +2,16 @@ package com.tuoheng.admin.tzhl.service.airport; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.tuoheng.admin.constant.SystemConstant; |
|
|
|
import com.tuoheng.admin.dto.GetAirportListDto; |
|
|
|
import com.tuoheng.admin.tzhl.constant.TZHLConstant; |
|
|
|
import com.tuoheng.admin.tzhl.service.token.TZHLGetTokenService; |
|
|
|
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; |
|
|
|
import com.tuoheng.common.core.config.common.CommonConfig; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.client.RestClientException; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
@@ -37,56 +30,23 @@ public class TZHLGetAirportListService { |
|
|
|
private RestTemplate restTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TZHLGetTokenService tzhlGetTokenService; |
|
|
|
private CallTianYiPlatformService callTianYiPlatformService; |
|
|
|
|
|
|
|
public JsonResult getAirportList(){ |
|
|
|
//获取同行令牌token |
|
|
|
String token = tzhlGetTokenService.getToken(); |
|
|
|
JsonResult jsonResult = this.check(token); |
|
|
|
if(jsonResult.getCode() != 0){ |
|
|
|
return JsonResult.error(jsonResult.getMsg()); |
|
|
|
} |
|
|
|
//读取全量机场平台列表 |
|
|
|
String url = CommonConfig.tianYiUrl + TZHLConstant.TIAN_YI_API_AIRPORT_LIST; |
|
|
|
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("请求获取机场列表失败"); |
|
|
|
} |
|
|
|
public JsonResult getAirportList(List<Long> idList){ |
|
|
|
String param = "?ids=" + idList; |
|
|
|
|
|
|
|
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); |
|
|
|
//读取全量机场平台列表 |
|
|
|
String url = CommonConfig.tianYiUrl + TZHLConstant.TIAN_YI_API_AIRPORT_LIST + param; |
|
|
|
|
|
|
|
String body = JSONObject.toJSONString(response.getBody().getData()); |
|
|
|
HttpEntity<Object> httpEntity = new HttpEntity<>(null); |
|
|
|
|
|
|
|
List<GetAirportListDto> getAirportListDtoLists = JSON.parseArray(JSON.parse(body).toString(), GetAirportListDto.class); |
|
|
|
if(ObjectUtil.isNull(getAirportListDtoLists)){ |
|
|
|
String data = callTianYiPlatformService.callGet(url, httpEntity); |
|
|
|
//List<GetAirportListDto> getAirportListDtoLists = JSON.parseArray(JSON.parse(body).toString(), GetAirportListDto.class); |
|
|
|
List<GetAirportListDto> getAirportListDtoList = JSON.parseArray(data, GetAirportListDto.class); |
|
|
|
if(ObjectUtil.isNull(getAirportListDtoList)){ |
|
|
|
return JsonResult.error("查询机场列表数据为空"); |
|
|
|
} |
|
|
|
return JsonResult.success(getAirportListDtoLists); |
|
|
|
} |
|
|
|
|
|
|
|
private JsonResult check(String token) { |
|
|
|
if(StringUtils.isEmpty(token)){ |
|
|
|
return JsonResult.error("token不存在或已过期"); |
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
|
return JsonResult.success(getAirportListDtoList); |
|
|
|
} |
|
|
|
|
|
|
|
|