|
|
@@ -1,14 +1,28 @@ |
|
|
|
package com.tuoheng.admin.tzhl.service.fly.data; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.tuoheng.admin.entity.FlightData; |
|
|
|
import com.tuoheng.admin.entity.FlightDataHl; |
|
|
|
import com.tuoheng.admin.entity.Inspection; |
|
|
|
import com.tuoheng.admin.enums.MarkEnum; |
|
|
|
import com.tuoheng.admin.mapper.FlightDataHlMapper; |
|
|
|
import com.tuoheng.admin.mapper.FlightDataMapper; |
|
|
|
import com.tuoheng.admin.tzhl.constant.TZHLConstant; |
|
|
|
import com.tuoheng.admin.tzhl.request.TZHLFlyDataRequest; |
|
|
|
import com.tuoheng.admin.tzhl.response.TZHLAirportFlightDataResponse; |
|
|
|
import com.tuoheng.admin.tzhl.response.TZHLFlyDataResponse; |
|
|
|
import com.tuoheng.admin.tzhl.response.TZHLFlyLogResponse; |
|
|
|
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; |
|
|
|
import com.tuoheng.admin.utils.CurrentUserUtil; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.RedisUtils; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
import org.springframework.http.HttpEntity; |
|
|
@@ -17,6 +31,12 @@ import org.springframework.http.MediaType; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.sql.Wrapper; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class FlyDataService { |
|
|
@@ -28,28 +48,106 @@ public class FlyDataService { |
|
|
|
@Qualifier("restTemplate") |
|
|
|
private RestTemplate restTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FlightDataHlMapper flightDataHlMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CallTianYiPlatformService callTianYiPlatformService; |
|
|
|
|
|
|
|
public void getFlyData(Inspection inspection) { |
|
|
|
|
|
|
|
String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; |
|
|
|
|
|
|
|
TZHLFlyDataRequest request = new TZHLFlyDataRequest(); |
|
|
|
request.setRecordId(null); |
|
|
|
request.setDeptId(""); |
|
|
|
request.setCreateTime(null); |
|
|
|
JSONObject jsonObject = this.jsonObjectRequest(inspection); |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
HttpEntity httpEntity = new HttpEntity(request, headers); |
|
|
|
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); |
|
|
|
|
|
|
|
List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); |
|
|
|
|
|
|
|
String dataJson = callTianYiPlatformService.callGet(apiPath, null); |
|
|
|
//查询到的数据 入库 |
|
|
|
this.addFlightDataHl(inspection,flightDataHlList); |
|
|
|
|
|
|
|
TZHLFlyLogResponse flyDataResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 飞行数据入库 |
|
|
|
* @param inspection |
|
|
|
* @param flightDataHlList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void addFlightDataHl(Inspection inspection, List<TZHLAirportFlightDataResponse> flightDataHlList) { |
|
|
|
if(CollectionUtil.isNotEmpty(flightDataHlList) && flightDataHlList.size() != 0){ |
|
|
|
|
|
|
|
for (TZHLAirportFlightDataResponse responseData : flightDataHlList) { |
|
|
|
FlightDataHl flightDataHl = new FlightDataHl(); |
|
|
|
BeanUtils.copyProperties(responseData,flightDataHl); |
|
|
|
flightDataHl.setTenantId(inspection.getTenantId()); |
|
|
|
flightDataHl.setInspectionId(inspection.getId()); |
|
|
|
|
|
|
|
//将最新的一条数据存入缓存,并设置过期时间 |
|
|
|
redisUtils.set(String.valueOf(inspection.getId()),flightDataHl,10); |
|
|
|
int count = flightDataHlMapper.insert(flightDataHl); |
|
|
|
if(count<=0){ |
|
|
|
log.info("输入插入失败,responseData:{}",responseData); |
|
|
|
throw new SecurityException("飞行数据插入失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO |
|
|
|
private JSONObject jsonObjectRequest(Inspection inspection) { |
|
|
|
JsonResult jsonResult = this.check(inspection); |
|
|
|
if(jsonResult.getCode() != 0){ |
|
|
|
return null; |
|
|
|
} |
|
|
|
//根据任务获取对应的部门 |
|
|
|
String deptId = inspection.getDeptId(); |
|
|
|
Long recordId = inspection.getRecordId(); |
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("recordId",recordId); |
|
|
|
jsonObject.put("deptId",deptId); |
|
|
|
//查飞行数据最新一条的生成时间 |
|
|
|
this.getCreateTime(inspection,jsonObject); |
|
|
|
|
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取最新的一条数据信息 |
|
|
|
* @param inspection |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void getCreateTime(Inspection inspection,JSONObject jsonObject) { |
|
|
|
String tenantId = CurrentUserUtil.getTenantId(); |
|
|
|
|
|
|
|
List<FlightDataHl> flightDataHl = flightDataHlMapper.selectList(new LambdaQueryWrapper<FlightDataHl>() |
|
|
|
.eq(FlightDataHl::getMark, MarkEnum.VALID.getCode()) |
|
|
|
.eq(FlightDataHl::getTenantId, tenantId) |
|
|
|
.eq(FlightDataHl::getInspectionId, inspection.getId()) |
|
|
|
.orderByDesc(FlightDataHl::getCreateTime) |
|
|
|
.last("limit 1")); |
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
if(ObjectUtil.isNotNull(flightDataHl.get(0))){ |
|
|
|
Date createTime = flightDataHl.get(0).getCreateTime(); |
|
|
|
String dateString = sdf.format(createTime); |
|
|
|
jsonObject.put("createTime",dateString); |
|
|
|
}else { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private JsonResult check(Inspection inspection) { |
|
|
|
if(StringUtils.isEmpty(inspection.getDeptId())){ |
|
|
|
return JsonResult.error("任务部门id为空"); |
|
|
|
} |
|
|
|
if(null == inspection.getRecordId()){ |
|
|
|
return JsonResult.error("飞行记录id为空"); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|