|
|
@@ -47,20 +47,21 @@ public class FlyDataService { |
|
|
|
private TZHLGetAirportListService getAirportListService; |
|
|
|
|
|
|
|
public void getFlyData(Inspection inspection) { |
|
|
|
log.info("执行获取飞行数据操作,inspection:{}",inspection.toString()); |
|
|
|
log.info("获取飞行数据操作, inspectionId:{}", inspection.getId()); |
|
|
|
String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; |
|
|
|
JSONObject jsonObject = this.jsonObjectRequest(inspection); |
|
|
|
JSONObject jsonObject = this.jsonObjectRequest(inspection); |
|
|
|
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); |
|
|
|
log.info("获取飞行数据dataJson:{}",dataJson); |
|
|
|
log.info("获取飞行数据, dataJson:{}", dataJson); |
|
|
|
|
|
|
|
List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); |
|
|
|
|
|
|
|
// 查询到的数据入库 |
|
|
|
this.addFlightDataHl(inspection,flightDataHlList); |
|
|
|
this.addFlightDataHl(inspection, flightDataHlList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 飞行数据入库 |
|
|
|
* |
|
|
|
* @param inspection |
|
|
|
* @param flightDataHlList |
|
|
|
* @return |
|
|
@@ -68,11 +69,11 @@ public class FlyDataService { |
|
|
|
private void addFlightDataHl(Inspection inspection, List<TZHLAirportFlightDataResponse> flightDataHlList) { |
|
|
|
log.info("开始飞行数据保存入库"); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
if(CollectionUtil.isNotEmpty(flightDataHlList) && flightDataHlList.size() != 0){ |
|
|
|
if (CollectionUtil.isNotEmpty(flightDataHlList) && flightDataHlList.size() != 0) { |
|
|
|
List<FlightDataHl> flightDataHls = new ArrayList<>(flightDataHlList.size()); |
|
|
|
for (TZHLAirportFlightDataResponse responseData : flightDataHlList) { |
|
|
|
FlightDataHl flightDataHl = new FlightDataHl(); |
|
|
|
BeanUtils.copyProperties(responseData,flightDataHl); |
|
|
|
BeanUtils.copyProperties(responseData, flightDataHl); |
|
|
|
flightDataHl.setTenantId(inspection.getTenantId()); |
|
|
|
flightDataHl.setInspectionId(inspection.getId()); |
|
|
|
try { |
|
|
@@ -84,20 +85,20 @@ public class FlyDataService { |
|
|
|
|
|
|
|
int count = flightDataHlMapper.insert(flightDataHl); |
|
|
|
|
|
|
|
if(count<=0){ |
|
|
|
log.info("输入插入失败,responseData:{}",responseData); |
|
|
|
if (count <= 0) { |
|
|
|
log.info("输入插入失败,responseData:{}", responseData); |
|
|
|
throw new SecurityException("飞行数据插入失败"); |
|
|
|
} |
|
|
|
flightDataHls.add(flightDataHl); |
|
|
|
log.info("结束飞行数据保存入库, flightDataHls:{}",flightDataHls); |
|
|
|
log.info("结束飞行数据保存入库, flightDataHls:{}", flightDataHls); |
|
|
|
|
|
|
|
} |
|
|
|
//将最新的一条数据存入缓存,并设置过期时间 |
|
|
|
log.info("开始存入最新一条数据于缓存中"); |
|
|
|
if(CollectionUtil.isNotEmpty(flightDataHls) && flightDataHls.size()>0){ |
|
|
|
if (CollectionUtil.isNotEmpty(flightDataHls) && flightDataHls.size() > 0) { |
|
|
|
flightDataHls = flightDataHls.stream().sorted(Comparator.comparing(FlightDataHl::getCreateTime).reversed()).collect(Collectors.toList()); |
|
|
|
//倒序排列的第一个最新数据保存到缓存 |
|
|
|
redisUtils.set(inspection.getId(),flightDataHls.get(0),10); |
|
|
|
redisUtils.set(inspection.getId(), flightDataHls.get(0), 10); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@@ -106,7 +107,7 @@ public class FlyDataService { |
|
|
|
|
|
|
|
private JSONObject jsonObjectRequest(Inspection inspection) { |
|
|
|
JsonResult jsonResult = this.check(inspection); |
|
|
|
if(jsonResult.getCode() != 0){ |
|
|
|
if (jsonResult.getCode() != 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
//根据任务获取对应的部门 |
|
|
@@ -119,20 +120,21 @@ public class FlyDataService { |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("recordId",recordId); |
|
|
|
jsonObject.put("deptId",deptId); |
|
|
|
jsonObject.put("recordId", recordId); |
|
|
|
jsonObject.put("deptId", deptId); |
|
|
|
//查飞行数据最新一条的生成时间 |
|
|
|
this.getCreateTime(inspection,jsonObject); |
|
|
|
this.getCreateTime(inspection, jsonObject); |
|
|
|
|
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取最新的一条数据信息 |
|
|
|
* |
|
|
|
* @param inspection |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void getCreateTime(Inspection inspection,JSONObject jsonObject) { |
|
|
|
private void getCreateTime(Inspection inspection, JSONObject jsonObject) { |
|
|
|
String tenantId = inspection.getTenantId(); |
|
|
|
|
|
|
|
List<FlightDataHl> flightDataHl = flightDataHlMapper.selectList(new LambdaQueryWrapper<FlightDataHl>() |
|
|
@@ -142,30 +144,29 @@ public class FlyDataService { |
|
|
|
.orderByDesc(FlightDataHl::getCreateTime) |
|
|
|
.last("limit 1")); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(flightDataHl) && flightDataHl.size() == 0){ |
|
|
|
if (CollectionUtil.isEmpty(flightDataHl) && flightDataHl.size() == 0) { |
|
|
|
//查出的数据为空,直接结束返回 |
|
|
|
return; |
|
|
|
} |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(flightDataHl.get(0))){ |
|
|
|
if (ObjectUtil.isNotNull(flightDataHl.get(0))) { |
|
|
|
Date createTime = flightDataHl.get(0).getCreateTime(); |
|
|
|
String dateString = sdf.format(createTime); |
|
|
|
jsonObject.put("createTime",dateString); |
|
|
|
}else { |
|
|
|
jsonObject.put("createTime", dateString); |
|
|
|
} else { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private JsonResult check(Inspection inspection) { |
|
|
|
if(StringUtils.isEmpty(inspection.getDeptId())){ |
|
|
|
if (StringUtils.isEmpty(inspection.getDeptId())) { |
|
|
|
return JsonResult.error("任务部门id为空"); |
|
|
|
} |
|
|
|
if(null == inspection.getRecordId()){ |
|
|
|
if (null == inspection.getRecordId()) { |
|
|
|
return JsonResult.error("飞行记录id为空"); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |