@@ -53,8 +53,9 @@ public class ExecuteInspectionService { | |||
*/ | |||
public JsonResult execute(String id) { | |||
log.info("进入立即执行任务业务"); | |||
String userId = CurrentUserUtil.getUserId(); | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = user.getId(); | |||
String tenantId = user.getTenantId(); | |||
JsonResult result = this.check(userId, tenantId, id); | |||
if (0 != result.getCode()) { |
@@ -3,8 +3,10 @@ package com.tuoheng.admin.service.third.airport.execute; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionHistory; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.code.inspection.ExecuteInspectionCodeEnum; | |||
import com.tuoheng.admin.mapper.InspectionHistoryMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.service.third.dsp.IDspService; | |||
@@ -37,16 +39,13 @@ public class ExecuteTaskService { | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private TZHLGetAirportLineListService tzhlGetAirportLineListService; | |||
private InspectionHistoryMapper inspectionHistoryMapper; | |||
@Autowired | |||
private ShelterTaskService shelterTaskService; | |||
@Autowired | |||
private OnlineUavService onlineUavService; | |||
private TZHLGetAirportLineListService tzhlGetAirportLineListService; | |||
@Autowired | |||
private IDspService dspService; | |||
private ShelterTaskService shelterTaskService; | |||
public JsonResult executeTask(String userId, Inspection inspection) { | |||
log.info("进入泰州海陵区城管,执行任务,inspectionId={}", inspection.getId()); | |||
@@ -59,27 +58,21 @@ public class ExecuteTaskService { | |||
Long recordId = shelterTaskService.distributeTask(inspection, tzhlAirportLineResponse); | |||
if (ObjectUtil.isEmpty(recordId)) { | |||
log.info("泰州海陵区城管,执行任务,下发任务失败"); | |||
return JsonResult.success("泰州海陵区城管,执行任务,下发任务失败"); | |||
} | |||
log.info("泰州海陵区城管,执行任务,下发任务失败,status={}", inspection.getStatus()); | |||
inspection.setStatus(InspectionStatusEnum.PREPARING.getCode()); | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
this.updateInspection(userId, inspection, recordId); | |||
this.insertInspectionHistory(inspection, "下发任务失败"); | |||
TZHLOnlineUavResponse tzhlOnlineUavResponse = onlineUavService.getOnlineUav(); | |||
if (ObjectUtil.isEmpty(tzhlOnlineUavResponse)) { | |||
log.info("泰州海陵区城管,执行任务,获取推流地址失败"); | |||
} else { | |||
// 通知DSP | |||
JsonResult result = dspService.startAI(inspection, tzhlOnlineUavResponse.getPlayUrl(), tzhlOnlineUavResponse.getPlayUrl()); | |||
if (0 != result.getCode()) { | |||
log.info("泰州海陵区城管,执行任务,通知DSP失败"); | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
} | |||
return JsonResult.success("泰州海陵区城管,执行任务,下发任务失败"); | |||
} | |||
inspection.setStatus(InspectionStatusEnum.PREPARING.getCode()); | |||
this.updateInspection(userId, inspection, recordId); | |||
log.info("进入调用机场平台方法: 等待机场平台回调,修改执行任务状态"); | |||
log.info("任务下发成功,修改任务状态,status={}", inspection.getStatus()); | |||
return JsonResult.success(); | |||
} | |||
@@ -97,4 +90,19 @@ public class ExecuteTaskService { | |||
inspection.setRecordId(recordId); | |||
inspectionMapper.update(inspection); | |||
} | |||
/** | |||
* 更新任务失败记录 | |||
* | |||
* @param inspection | |||
*/ | |||
private void insertInspectionHistory(Inspection inspection, String msg) { | |||
InspectionHistory inspectionHistory = new InspectionHistory(); | |||
inspectionHistory.setTenantId(inspection.getTenantId()); | |||
inspectionHistory.setInspectionId(inspection.getId()); | |||
inspectionHistory.setHistoryName(msg); | |||
inspectionHistory.setCreateUser(""); | |||
inspectionHistory.setCreateTime(DateUtils.now()); | |||
inspectionHistoryMapper.insert(inspectionHistory); | |||
} | |||
} |
@@ -42,4 +42,9 @@ public class TZHLOnlineUavResponse { | |||
*/ | |||
private String playUrl; | |||
/** | |||
* 推流地址 | |||
*/ | |||
private String pushUrl; | |||
} |
@@ -25,12 +25,12 @@ public class TZHLTokenResponse { | |||
/** | |||
* 部门ID | |||
*/ | |||
private String deptId; | |||
private Long deptId; | |||
/** | |||
* 无人机id | |||
*/ | |||
private String uavId; | |||
private Long uavId; | |||
/** | |||
* 访问token |
@@ -81,6 +81,10 @@ public class CallTianYiPlatformService { | |||
String url = TZHLConfig.tzhlURL + apiPath; | |||
ResponseEntity<JsonResult> response; | |||
log.info("泰州海陵区城管,url:{}", url); | |||
log.info("泰州海陵区城管,request:{}", request); | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||
} catch (Exception e) { |
@@ -45,5 +45,20 @@ public class TZHLGetAirportListService { | |||
return JsonResult.success(getAirportListDtoList); | |||
} | |||
public GetAirportListDto getAirport(Long id){ | |||
Long[] idArr = new Long[ ]{id}; | |||
TZHLAirportLineListRequest request = new TZHLAirportLineListRequest(); | |||
request.setIds(Arrays.toString(idArr)); | |||
//读取全量机场平台列表 | |||
String url = TZHLConstant.TIAN_YI_API_AIRPORT_LIST ; | |||
String data = callTianYiPlatformService.callGet(url, request); | |||
List<GetAirportListDto> getAirportListDtoList = JSON.parseArray(data, GetAirportListDto.class); | |||
if(ObjectUtil.isNull(getAirportListDtoList)){ | |||
log.info("查询机场列表数据为空"); | |||
return null; | |||
} | |||
return getAirportListDtoList.get(0); | |||
} | |||
} |
@@ -5,13 +5,17 @@ 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.dto.GetAirportListDto; | |||
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.tzhl.constant.TZHLConstant; | |||
import com.tuoheng.admin.tzhl.response.TZHLAirportFlightDataResponse; | |||
import com.tuoheng.admin.tzhl.response.TZHLTokenResponse; | |||
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; | |||
import com.tuoheng.admin.tzhl.service.airport.TZHLGetAirportListService; | |||
import com.tuoheng.admin.tzhl.service.token.TZHLGetTokenService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -42,21 +46,18 @@ public class FlyDataService { | |||
@Autowired | |||
private CallTianYiPlatformService callTianYiPlatformService; | |||
public void getFlyData(Inspection inspection) { | |||
@Autowired | |||
private TZHLGetAirportListService getAirportListService; | |||
public void getFlyData(Inspection inspection) { | |||
String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; | |||
log.info("请求机场平台获取飞行数据url,apiPath={}",apiPath); | |||
JSONObject jsonObject = this.jsonObjectRequest(inspection); | |||
log.info("封装的请求参数信息,jsonObject:{}", jsonObject.toString()); | |||
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); | |||
List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); | |||
//查询到的数据 入库 | |||
// 查询到的数据入库 | |||
this.addFlightDataHl(inspection,flightDataHlList); | |||
} | |||
/** | |||
@@ -102,9 +103,14 @@ public class FlyDataService { | |||
return null; | |||
} | |||
//根据任务获取对应的部门 | |||
String deptId = inspection.getDeptId(); | |||
Long recordId = inspection.getRecordId(); | |||
GetAirportListDto airportListDto = getAirportListService.getAirport(inspection.getAirportId()); | |||
Long deptId = 0L; | |||
if (ObjectUtil.isNotEmpty(airportListDto)) { | |||
deptId = airportListDto.getDeptId(); | |||
} | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("recordId",recordId); | |||
jsonObject.put("deptId",deptId); |
@@ -50,7 +50,7 @@ public class FlyLogByErrorService { | |||
} | |||
/** | |||
* 更新任务中 | |||
* 更新任务失败记录 | |||
* | |||
* @param inspection | |||
*/ |
@@ -48,7 +48,7 @@ public class FlyLogByNormalService { | |||
private FlyDataService flyDataService; | |||
public void getFlyLog(Inspection inspection, TZHLFlyLogResponse flyLogResponse) { | |||
log.info("获取飞行日志,status=error,title={}", flyLogResponse.getTitle()); | |||
log.info("获取飞行日志,status=normal,title={}", flyLogResponse.getTitle()); | |||
if (ObjectUtil.isEmpty(flyLogResponse)) { | |||
log.info("flyLogResponse:{}", flyLogResponse); | |||
@@ -79,12 +79,11 @@ public class FlyLogByNormalService { | |||
*/ | |||
private void prepareTask(Inspection inspection, TZHLFlyLogResponse flyLogResponse) { | |||
String title = flyLogResponse.getTitle().replace(PREPARE_TASK, ""); | |||
if (ObjectUtil.isEmpty(title) && title.length() < 2) { | |||
return; | |||
} | |||
String status = title.substring(0, 2); | |||
if (SUCCESS.equals(status)) { | |||
inspection.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
this.updateInspection(inspection); | |||
} else if (FAILED.equals(status)) { | |||
if (FAILED.equals(status)) { | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
this.updateInspection(inspection); | |||
@@ -103,13 +102,11 @@ public class FlyLogByNormalService { | |||
*/ | |||
private void executeTask(Inspection inspection, TZHLFlyLogResponse flyLogResponse) { | |||
String title = flyLogResponse.getTitle().replace(PREPARE_TASK, ""); | |||
if (ObjectUtil.isEmpty(title) && title.length() < 2) { | |||
return; | |||
} | |||
String status = title.substring(0, 2); | |||
if (SUCCESS.equals(status)) { | |||
inspection.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
this.updateInspection(inspection); | |||
} else if (FAILED.equals(status)) { | |||
if (FAILED.equals(status)) { | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
this.updateInspection(inspection); |
@@ -1,10 +1,15 @@ | |||
package com.tuoheng.admin.tzhl.service.fly.log; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
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.response.TZHLOnlineUavResponse; | |||
import com.tuoheng.admin.tzhl.service.fly.onlineuav.OnlineUavService; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@@ -16,13 +21,37 @@ public class FlyLogBySuccessService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private OnlineUavService onlineUavService; | |||
@Autowired | |||
private IDspService dspService; | |||
public void getFlyLog(Inspection inspection, TZHLFlyLogResponse flyLogResponse) { | |||
log.info("获取飞行日志,status=success,title={}", flyLogResponse.getTitle()); | |||
if ("已起飞".equals(flyLogResponse.getTitle())) { | |||
inspection.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
inspection.setUpdateUser(""); | |||
inspection.setUpdateTime(DateUtils.now()); | |||
inspectionMapper.updateStatus(inspection); | |||
if (InspectionStatusEnum.IN_FLIGHT.getCode() == inspection.getStatus()) { | |||
log.info("获取飞行日志,该任务状态已经改是飞行中,inspectionid={}", inspection.getId()); | |||
return; | |||
} | |||
log.info("获取飞行日志,status=success,title={}", flyLogResponse.getTitle()); | |||
inspection.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
inspection.setUpdateUser(""); | |||
inspection.setUpdateTime(DateUtils.now()); | |||
inspectionMapper.updateStatus(inspection); | |||
log.info("获取飞行日志,status=success,修改任务状态,status={}", inspection.getStatus()); | |||
TZHLOnlineUavResponse tzhlOnlineUavResponse = onlineUavService.getOnlineUav(); | |||
if (ObjectUtil.isEmpty(tzhlOnlineUavResponse)) { | |||
log.info("泰州海陵区城管,执行任务,获取推流地址失败"); | |||
return; | |||
} | |||
// 通知DSP | |||
JsonResult result = dspService.startAI(inspection, tzhlOnlineUavResponse.getPushUrl(), tzhlOnlineUavResponse.getPushUrl()); | |||
if (0 != result.getCode()) { | |||
log.info("泰州海陵区城管,执行任务,通知DSP失败"); | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
} | |||
} | |||
@@ -20,6 +20,8 @@ import org.springframework.http.MediaType; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import java.util.List; | |||
@Slf4j | |||
@Service | |||
public class FlyLogService { | |||
@@ -49,17 +51,25 @@ public class FlyLogService { | |||
request.setCreateTime(createTime); | |||
} | |||
String dataJson = callTianYiPlatformService.callPost(apiPath, request); | |||
TZHLFlyLogResponse flyLogResponse = JSON.parseObject(dataJson, TZHLFlyLogResponse.class); | |||
redisUtils.set(TZHLConstant.HL_FLY_LOG + inspection.getId(), flyLogResponse); | |||
log.info("获取飞行日志,flyLogResponse={}", flyLogResponse); | |||
if ("success".equals(flyLogResponse.getStatus())) { | |||
flyLogBySuccessService.getFlyLog(inspection, flyLogResponse); | |||
} else if ("error".equals(flyLogResponse.getStatus())) { | |||
flyLogByErrorService.getFlyLog(inspection, flyLogResponse); | |||
} else if ("normal".equals(flyLogResponse.getStatus())) { | |||
flyLogByNormalService.getFlyLog(inspection, flyLogResponse); | |||
} else { | |||
log.info("status类型不匹配"); | |||
List<TZHLFlyLogResponse> flyLogResponseList = JSON.parseArray(dataJson, TZHLFlyLogResponse.class); | |||
if (ObjectUtil.isEmpty(flyLogResponseList)) { | |||
log.info("获取飞行日志,flyLogResponseList为空"); | |||
return; | |||
} | |||
for (TZHLFlyLogResponse flyLogResponse : flyLogResponseList) { | |||
log.info("获取飞行日志,flyLogResponse={}", flyLogResponse); | |||
// redisUtils.set(TZHLConstant.HL_FLY_LOG + inspection.getId(), flyLogResponse); | |||
if ("success".equals(flyLogResponse.getStatus())) { | |||
flyLogBySuccessService.getFlyLog(inspection, flyLogResponse); | |||
} else if ("normal".equals(flyLogResponse.getStatus())) { | |||
flyLogByNormalService.getFlyLog(inspection, flyLogResponse); | |||
} else if ("error".equals(flyLogResponse.getStatus())) { | |||
// flyLogByErrorService.getFlyLog(inspection, flyLogResponse); | |||
} else { | |||
log.info("status类型不匹配"); | |||
} | |||
} | |||
} | |||
@@ -39,7 +39,7 @@ public class TZHLGetTokenService { | |||
return tokenResponse.getToken(); | |||
} | |||
private TZHLTokenResponse getTokenResponse() { | |||
public TZHLTokenResponse getTokenResponse() { | |||
TZHLGetTokenRequest request = new TZHLGetTokenRequest(); | |||
request.setTicket(TZHLConfig.tzhlTicket); | |||
HttpHeaders headers = new HttpHeaders(); |
@@ -11,6 +11,7 @@ import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest; | |||
import com.tuoheng.admin.service.inspection.IInspectionService; | |||
import com.tuoheng.admin.service.inspection.update.status.UpdateFlightStatusService; | |||
import com.tuoheng.admin.tzhl.service.fly.log.FlyLogService; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -34,11 +35,24 @@ public class InspectionServiceTest { | |||
@Autowired | |||
private UpdateFlightStatusService updateFlightStatusService; | |||
@Autowired | |||
private FlyLogService flyLogService; | |||
@Test | |||
public void testExecute() { | |||
String id = "2f0ab151d48edac218a579bf6cab274a"; | |||
iInspectionService.execute(id); | |||
String id = "da5da2c67dc152de5e43c7e7a104bfcf"; | |||
// iInspectionService.execute(id); | |||
// | |||
// try { | |||
// Thread.sleep(1000 * 5); | |||
// } catch (InterruptedException e) { | |||
// throw new RuntimeException(e); | |||
// } | |||
Inspection inspection = inspectionMapper.selectById(id); | |||
flyLogService.getFlyLog(inspection); | |||
} | |||
@Test |
@@ -0,0 +1,32 @@ | |||
package com.tuoheng.admin.tzhl; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.tzhl.service.fly.data.FlyDataService; | |||
import com.tuoheng.admin.tzhl.service.fly.log.FlyLogService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class TZHLFlyDataServiceTest { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private FlyDataService flyDataService; | |||
@Test | |||
public void testFlyLog() { | |||
String id = "da5da2c67dc152de5e43c7e7a104bfcf"; | |||
Inspection inspection = inspectionMapper.selectById(id); | |||
flyDataService.getFlyData(inspection); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
package com.tuoheng.admin.tzhl; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.tzhl.response.TZHLOnlineUavResponse; | |||
import com.tuoheng.admin.tzhl.service.fly.log.FlyLogService; | |||
import com.tuoheng.admin.tzhl.service.fly.onlineuav.OnlineUavService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class TZHLFlyLogServiceTest { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private FlyLogService flyLogService; | |||
@Test | |||
public void testFlyLog() { | |||
String id = "da5da2c67dc152de5e43c7e7a104bfcf"; | |||
Inspection inspection = inspectionMapper.selectById(id); | |||
flyLogService.getFlyLog(inspection); | |||
} | |||
} |