Browse Source

Merge branch 'develop' of gitadmin/tuoheng_telecomumale into release

tags/v1.3.1
wanjing 1 year ago
parent
commit
f4e83b45be
2 changed files with 60 additions and 23 deletions
  1. +24
    -23
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/data/FlyDataService.java
  2. +36
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/log/FlyLogBySuccessService.java

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

@@ -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();
}


}

+ 36
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/tzhl/service/fly/log/FlyLogBySuccessService.java View File

@@ -8,11 +8,13 @@ import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.service.third.dsp.IDspService;
import com.tuoheng.admin.tzhl.response.TZHLFlyLogResponse;
import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportListService;
import com.tuoheng.admin.tzhl.service.fly.data.FlyDataService;
import com.tuoheng.common.core.utils.DateUtils;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@@ -28,6 +30,9 @@ public class FlyLogBySuccessService {
@Autowired
private IDspService dspService;

@Autowired
private FlyDataService flyDataService;

public void getFlyLog(Inspection inspection, TZHLFlyLogResponse flyLogResponse) {
log.info("获取飞行日志,status=success,inspectionId={}, title={}", inspection.getId(), flyLogResponse.getTitle());
if (InspectionStatusEnum.IN_FLIGHT.getCode() == inspection.getStatus()) {
@@ -41,6 +46,8 @@ public class FlyLogBySuccessService {

log.info("获取飞行日志,status=success,修改任务状态,inspectionId={}, status={}", inspection.getId(), inspection.getStatus());

this.exec(inspection.getId());

AirportDto airportDto = tzhlGetAirportListService.getAirport(inspection.getAirportId());
if (ObjectUtil.isEmpty(airportDto)) {
log.info("获取飞行日志,获取推流地址失败,inspectionId={}", inspection.getId());
@@ -60,4 +67,33 @@ public class FlyLogBySuccessService {
}
}

@Async
public void exec(String inspectionId) {
log.info("轮训飞行数据,inspectionId:{}", inspectionId);
try {
Long beginTime = System.currentTimeMillis();
while (true) {
Thread.sleep(2000);
if (System.currentTimeMillis() - beginTime > 7200000) {
// 超过120分钟,停止轮询
log.info("轮询飞行数据,超时60分钟,停止轮询,inspectionId:{}", inspectionId);
break;
}
Inspection inspection = inspectionMapper.selectById(inspectionId);
if (ObjectUtil.isEmpty(inspection)) {
log.info("轮询飞行数据,任务不存在,停止轮询,inspectionId:{}", inspectionId);
break;
}
if (InspectionStatusEnum.IN_FLIGHT.getCode() != inspection.getStatus()) {
log.info("轮询飞行数据,任务状态,不在飞行中,停止轮询,inspectionId:{}", inspectionId);
break;
}

// 拉取飞行数据
flyDataService.getFlyData(inspection);
}
} catch (Exception e) {
}
}

}

Loading…
Cancel
Save