*/ | */ | ||||
String ADD_PILOTTASK = "apiTask/add"; | String ADD_PILOTTASK = "apiTask/add"; | ||||
/** | |||||
* 机场平台:获取机场路线列表接口 | |||||
*/ | |||||
String API_AIRPORT_LINE_FILE_LIST = "/airportInterface/getAirlineFileListForThird"; | |||||
/** | /** | ||||
* 机场平台:获取机场状态 | * 机场平台:获取机场状态 | ||||
*/ | */ |
package com.tuoheng.admin.controller; | package com.tuoheng.admin.controller; | ||||
import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | ||||
import com.tuoheng.admin.entity.vo.AirportLineVo; | |||||
import com.tuoheng.admin.service.airportline.IAirportLineService; | import com.tuoheng.admin.service.airportline.IAirportLineService; | ||||
import com.tuoheng.admin.service.third.airport.AirportService; | |||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
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; | |||||
/** | /** | ||||
* 航线前端控制器 | * 航线前端控制器 | ||||
* | * | ||||
return airportLineService.getInfoByInspectionId(inspectionId); | return airportLineService.getInfoByInspectionId(inspectionId); | ||||
} | } | ||||
/** | |||||
* 根据机场ID获取航线列表 | |||||
* @param airportId | |||||
* @return | |||||
*/ | |||||
@GetMapping("/list/byAirportId/{airportId}") | |||||
public JsonResult getListByAirportIdId(@PathVariable("airportId") String airportId) { | |||||
return airportLineService.getListByAirportIdId(airportId); | |||||
} | |||||
/** | /** | ||||
*添加航线 | *添加航线 | ||||
* @param request | * @param request |
package com.tuoheng.admin.entity.vo; | |||||
import lombok.Data; | |||||
import lombok.NoArgsConstructor; | |||||
import java.io.Serializable; | |||||
/** | |||||
* 机场线路视图Vo | |||||
* | |||||
* @author wanjing | |||||
* @team tuoheng | |||||
* @date 2022-11-23 | |||||
*/ | |||||
@Data | |||||
@NoArgsConstructor | |||||
public class AirportLineVo implements Serializable { | |||||
private static final long serialVersionUID = 1L; | |||||
/** | |||||
* 航线id | |||||
*/ | |||||
private Integer id; | |||||
/** | |||||
* 航线名称 | |||||
*/ | |||||
private String fileName; | |||||
/** | |||||
* 航线地址 | |||||
*/ | |||||
private String fileUrl; | |||||
/** | |||||
* 机场ID | |||||
*/ | |||||
private String airportId; | |||||
/** | |||||
* 机场名称 | |||||
*/ | |||||
private String airportName; | |||||
/** | |||||
* 航线类型:1,航点航线;2,指点航线;3,指面航线 | |||||
*/ | |||||
private String type; | |||||
/** | |||||
* 备注 | |||||
*/ | |||||
private String note; | |||||
} |
import com.tuoheng.admin.entity.domain.AirportLine; | import com.tuoheng.admin.entity.domain.AirportLine; | ||||
import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | ||||
import com.tuoheng.admin.entity.vo.AirportLineVo; | |||||
import com.tuoheng.admin.mapper.AirportLineMapper; | import com.tuoheng.admin.mapper.AirportLineMapper; | ||||
import com.tuoheng.admin.service.airportline.add.AddAirportLineService; | import com.tuoheng.admin.service.airportline.add.AddAirportLineService; | ||||
import com.tuoheng.admin.service.airportline.query.inspection.QueryAirportLineByInspectionIdFactory; | import com.tuoheng.admin.service.airportline.query.inspection.QueryAirportLineByInspectionIdFactory; | ||||
import com.tuoheng.admin.service.third.airport.AirportService; | |||||
import com.tuoheng.common.core.common.BaseServiceImpl; | import com.tuoheng.common.core.common.BaseServiceImpl; | ||||
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 org.springframework.web.bind.annotation.PathVariable; | |||||
import java.util.List; | |||||
/** | /** | ||||
* @Author ChengWang | * @Author ChengWang | ||||
@Autowired | @Autowired | ||||
private AddAirportLineService addAirportLineService; | private AddAirportLineService addAirportLineService; | ||||
@Autowired | |||||
private AirportService airportService; | |||||
/** | /** | ||||
* 查询航线信息 | * 查询航线信息 | ||||
* | * | ||||
return queryAirportLineByInspectionIdFactory.getAirportLineList(inspectionId); | return queryAirportLineByInspectionIdFactory.getAirportLineList(inspectionId); | ||||
} | } | ||||
/** | |||||
* 查询航线信息 | |||||
* | |||||
* @param airportId 任务Id | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public JsonResult getListByAirportIdId(String airportId) { | |||||
List<AirportLineVo> airportLineVoList = airportService.getAirportLineListByAirportIdAndLineIdList(airportId, null); | |||||
return JsonResult.success(airportLineVoList); | |||||
} | |||||
/** | /** | ||||
*添加航线 | *添加航线 | ||||
* @param request | * @param request |
import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | import com.tuoheng.admin.entity.request.inspection.AirportLineRequest; | ||||
import com.tuoheng.common.core.common.IBaseService; | import com.tuoheng.common.core.common.IBaseService; | ||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import org.springframework.web.bind.annotation.PathVariable; | |||||
/** | /** | ||||
* @Author ChengWang | * @Author ChengWang | ||||
*/ | */ | ||||
JsonResult getInfoByInspectionId(String inspectionId); | JsonResult getInfoByInspectionId(String inspectionId); | ||||
/** | |||||
* 查询航线列表 | |||||
* | |||||
* @param airportId 机场Id | |||||
* @return | |||||
*/ | |||||
JsonResult getListByAirportIdId(String airportId); | |||||
/** | /** | ||||
*新增航线 | *新增航线 | ||||
* @param request | * @param request |
import com.tuoheng.admin.entity.domain.Inspection; | import com.tuoheng.admin.entity.domain.Inspection; | ||||
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest; | import com.tuoheng.admin.entity.request.airport.DroneHoverRequest; | ||||
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest; | import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest; | ||||
import com.tuoheng.admin.entity.vo.AirportLineVo; | |||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
import java.util.List; | |||||
public interface AirportService { | public interface AirportService { | ||||
List<AirportLineVo> getAirportLineListByAirportIdAndLineIdList(String airportId, List<Integer> airportLineIdList); | |||||
JsonResult getAirportList(); | JsonResult getAirportList(); | ||||
JsonResult getAirLineList(Integer droneId); | JsonResult getAirLineList(Integer droneId); |
import com.tuoheng.admin.entity.domain.Inspection; | import com.tuoheng.admin.entity.domain.Inspection; | ||||
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest; | import com.tuoheng.admin.entity.request.airport.DroneHoverRequest; | ||||
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest; | import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest; | ||||
import com.tuoheng.admin.entity.vo.AirportLineVo; | |||||
import com.tuoheng.admin.service.third.airport.drone.DroneService; | import com.tuoheng.admin.service.third.airport.drone.DroneService; | ||||
import com.tuoheng.admin.service.third.airport.reversal.ReversalFlightService; | import com.tuoheng.admin.service.third.airport.reversal.ReversalFlightService; | ||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
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 { | ||||
@Autowired | @Autowired | ||||
private ReversalFlightService reversalFlightService; | private ReversalFlightService reversalFlightService; | ||||
@Override | |||||
public List<AirportLineVo> getAirportLineListByAirportIdAndLineIdList(String airportId, List<Integer> airportLineIdList) { | |||||
return getAirLineListService.getList(airportId, airportLineIdList); | |||||
} | |||||
@Override | @Override | ||||
public JsonResult getAirportList() { | public JsonResult getAirportList() { | ||||
return getAirportListService.getAirportList(); | return getAirportListService.getAirportList(); |
package com.tuoheng.admin.service.third.airport; | package com.tuoheng.admin.service.third.airport; | ||||
import cn.hutool.core.collection.CollectionUtil; | |||||
import cn.hutool.core.util.ObjectUtil; | import cn.hutool.core.util.ObjectUtil; | ||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.tuoheng.admin.constant.SystemConstant; | import com.tuoheng.admin.constant.SystemConstant; | ||||
import com.tuoheng.admin.entity.domain.Tenant; | import com.tuoheng.admin.entity.domain.Tenant; | ||||
import com.tuoheng.admin.entity.vo.AirportLineVo; | |||||
import com.tuoheng.admin.enums.code.AriportCodeEnum; | import com.tuoheng.admin.enums.code.AriportCodeEnum; | ||||
import com.tuoheng.admin.mapper.TenantMapper; | import com.tuoheng.admin.mapper.TenantMapper; | ||||
import com.tuoheng.admin.utils.CurrentUserUtil; | import com.tuoheng.admin.utils.CurrentUserUtil; | ||||
import com.tuoheng.admin.entity.vo.AirLineVO; | import com.tuoheng.admin.entity.vo.AirLineVO; | ||||
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.utils.HttpUtils; | import com.tuoheng.common.core.utils.HttpUtils; | ||||
import com.tuoheng.common.core.utils.JacksonUtil; | import com.tuoheng.common.core.utils.JacksonUtil; | ||||
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.beans.factory.annotation.Qualifier; | |||||
import org.springframework.http.*; | |||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import org.springframework.web.client.RestTemplate; | |||||
import org.springframework.web.util.UriComponentsBuilder; | |||||
import java.util.List; | |||||
import java.util.Objects; | import java.util.Objects; | ||||
@Slf4j | @Slf4j | ||||
@Autowired | @Autowired | ||||
private TenantMapper tenantMapper; | private TenantMapper tenantMapper; | ||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
public JsonResult getAirLineList(Integer droneId) { | public JsonResult getAirLineList(Integer droneId) { | ||||
//读取不同租户的机场平台url | //读取不同租户的机场平台url | ||||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | ||||
if (ObjectUtil.isEmpty(tenant)) { | if (ObjectUtil.isEmpty(tenant)) { | ||||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | ||||
} | } | ||||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_LINE_LIST; | |||||
String param = "page=1&limit=100&droneId=" + droneId; | |||||
String airPortStr = HttpUtils.sendGet(url, param); | |||||
log.info("调用机场平台,获取航线列表:airPortStr={}",airPortStr); | |||||
//string----->JsonResult | |||||
JsonResult<AirLineVO> jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_LINE_LIST) | |||||
.queryParam("page", 1) | |||||
.queryParam("limit", 100) | |||||
.queryParam("droneId", droneId) | |||||
.toUriString(); | |||||
JsonResult jsonResult; | |||||
try { | |||||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.info("获机航线列表接口异常, url:{}", url); | |||||
throw new ServiceException("获机航线列表接口异常"); | |||||
} | |||||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | ||||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | ||||
} | } | ||||
return jsonResult; | return jsonResult; | ||||
} | } | ||||
public List<AirportLineVo> getList(String airportId, List<Integer> airportLineIdList) { | |||||
//读取不同租户的机场平台url | |||||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||||
if (ObjectUtil.isEmpty(tenant)) { | |||||
return null; | |||||
} | |||||
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_LINE_FILE_LIST; | |||||
JSONObject jsonObject = new JSONObject(); | |||||
jsonObject.put("tenantCode", tenant.getCode()); | |||||
jsonObject.put("airportId", airportId); | |||||
jsonObject.put("airlineFileIds", airportLineIdList); | |||||
log.info("调用机场平台,获取航线列表,url:{}", url); | |||||
log.info("调用机场平台,获取航线列表,jsonObject:{}", jsonObject); | |||||
HttpHeaders headers = new HttpHeaders(); | |||||
headers.setContentType(MediaType.APPLICATION_JSON); | |||||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||||
ResponseEntity<JsonResult> response; | |||||
try { | |||||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.info("调用机场平台,获取航线列表接口异常,url:{}", url); | |||||
log.info("调用机场平台,获取航线列表接口异常,jsonObject:{}", jsonObject); | |||||
return null; | |||||
} | |||||
if (ObjectUtil.isEmpty(response)) { | |||||
log.info("调用机场平台,获取航线列表接口返回为空,url:{}", url); | |||||
log.info("调用机场平台,获取航线列表接口返回为空,jsonObject:{}", jsonObject); | |||||
return null; | |||||
} | |||||
JsonResult jsonResult = response.getBody(); | |||||
if (0 != jsonResult.getCode()) { | |||||
log.info("调用机场平台,获取航线列表,失败,url:{}", url); | |||||
log.info("调用机场平台,获取航线列表,失败,jsonObject:{}", jsonObject); | |||||
log.info("调用机场平台,获取航线列表,失败,jsonResult:{}", jsonResult.getMsg()); | |||||
return null; | |||||
} | |||||
List<AirportLineVo> airportLineVoList = JSONObject.parseArray(JSONObject.toJSONString(jsonResult.getData()), AirportLineVo.class); | |||||
if (CollectionUtil.isEmpty(airportLineVoList)) { | |||||
log.info("调用机场平台,获取航线列表,数据为空"); | |||||
} | |||||
return airportLineVoList; | |||||
} | |||||
} | } |