@@ -30,7 +30,6 @@ public class InspectionController { | |||
*/ | |||
@GetMapping("/list") | |||
public JsonResult inspectionCardList(){ | |||
// log.info("进入查询巡检任务列表接口"); | |||
return iInspectionService.inspectionCardList(); | |||
} | |||
@@ -23,7 +23,7 @@ public class FlightDataHl implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* ID | |||
*主键id | |||
*/ | |||
private Long id; | |||
@@ -88,6 +88,11 @@ public class Inspection extends BaseEntity { | |||
*/ | |||
private Long airportId; | |||
/** | |||
* 机场sn | |||
*/ | |||
private String sn; | |||
/** | |||
* 巡检无人机id | |||
*/ |
@@ -1,12 +1,17 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.admin.entity.FlightData; | |||
import com.tuoheng.admin.entity.FlightDataHl; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/8/8 | |||
*/ | |||
public interface FlightDataHlMapper extends BaseMapper<FlightDataHl> { | |||
List<FlightData> selectListByInspectionId(String id); | |||
} |
@@ -5,6 +5,7 @@ import com.tuoheng.admin.entity.FlightData; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.enums.code.inspection.QueryInspectionInfoByIdCodeEnum; | |||
import com.tuoheng.admin.mapper.FlightDataHlMapper; | |||
import com.tuoheng.admin.mapper.FlightDataMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -29,7 +30,7 @@ public class QueryFindFlightDataService { | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private FlightDataMapper flightDataMapper; | |||
private FlightDataHlMapper flightDataHlMapper; | |||
public JsonResult findFlightData(String id) { | |||
if (StringUtils.isEmpty(id)) { | |||
@@ -42,7 +43,7 @@ public class QueryFindFlightDataService { | |||
id = inspection.getEmergencyDataInspectionId(); | |||
} | |||
//根据任务id查询对应的云盒遥测数据 | |||
List<FlightData> listData = flightDataMapper.selectListByInspectionId(id); | |||
List<FlightData> listData = flightDataHlMapper.selectListByInspectionId(id); | |||
return JsonResult.success(listData); | |||
} | |||
} |
@@ -1,6 +1,5 @@ | |||
package com.tuoheng.admin.service.inspection.add; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.conver.InspectionConverMapper; | |||
import com.tuoheng.admin.entity.*; | |||
@@ -11,8 +10,8 @@ import com.tuoheng.admin.enums.code.inspection.AddInspectionCodeEnum; | |||
import com.tuoheng.admin.mapper.*; | |||
import com.tuoheng.admin.request.inspection.AddInspectionRequest; | |||
import com.tuoheng.admin.service.third.pilot.PilotService; | |||
import com.tuoheng.admin.utils.GaodeUtil; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.utils.GaodeUtil; | |||
import com.tuoheng.common.core.constant.CommonConstants; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -52,10 +51,10 @@ public class AddInspectionService { | |||
@Autowired | |||
private PilotService pilotService; | |||
@Autowired | |||
private DspServiceInstMapper dspServiceInstMapper; | |||
/** | |||
* 添加任务 | |||
* | |||
@@ -63,14 +62,14 @@ public class AddInspectionService { | |||
*/ | |||
public JsonResult add(AddInspectionRequest addInspectionRequest) { | |||
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.checkParam(userId, tenantId, addInspectionRequest); | |||
if (0 != result.getCode()) { | |||
log.info("添加任务业务:校验参数失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
User user = (User) result.getData(); | |||
// 构造inspection对象 | |||
Inspection inspection = this.buildInspection(user, tenantId, addInspectionRequest); | |||
@@ -119,11 +118,11 @@ public class AddInspectionService { | |||
} | |||
if (InspectionTypeEnum.AIRPORT.getCode() == addInspectionRequest.getInspectionType()) { | |||
// 巡检方式:机场巡逻,可选择巡检机场和巡检路线 | |||
if (null == addInspectionRequest.getAirportId() || StringUtils.isEmpty(addInspectionRequest.getAirportName())) { | |||
if (null == addInspectionRequest.getAirportId()) { | |||
return JsonResult.error(AddInspectionCodeEnum.AIRPORT_IS_NULL.getCode(), AddInspectionCodeEnum.AIRPORT_IS_NULL.getMsg()); | |||
} | |||
if (null == addInspectionRequest.getInspectionLine() || StringUtils.isEmpty(addInspectionRequest.getInspectionLineName())) { | |||
if (null == addInspectionRequest.getInspectionLine()) { | |||
return JsonResult.error(AddInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getCode(), AddInspectionCodeEnum.INSPECTION_LINE_IS_NULL.getMsg()); | |||
} | |||
} else if (InspectionTypeEnum.MABNNEDFLIGHT.getCode() == addInspectionRequest.getInspectionType()) { | |||
@@ -165,22 +164,7 @@ public class AddInspectionService { | |||
return JsonResult.error(AddInspectionCodeEnum.SECTION_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.SECTION_IS_NOT_EXIST.getMsg()); | |||
} | |||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||
.eq(User::getTenantId, tenantId) | |||
.eq(User::getId, userId) | |||
.eq(User::getMark, MarkEnum.VALID.getCode())); | |||
if (null == user) { | |||
return JsonResult.error(AddInspectionCodeEnum.USER_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.USER_IS_NOT_EXIST.getMsg()); | |||
} | |||
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, tenantId) | |||
.eq(Dept::getId, user.getDeptId()) | |||
.eq(Dept::getMark, MarkEnum.VALID.getCode())); | |||
if (null == dept) { | |||
return JsonResult.error(AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getCode(), AddInspectionCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); | |||
} | |||
return JsonResult.success(user); | |||
return JsonResult.success(); | |||
} | |||
/** |
@@ -65,7 +65,6 @@ public class QueryAirportMsgByIdService { | |||
} | |||
AirportMsgVo vo = new AirportMsgVo(); | |||
BeanUtils.copyProperties(flightData,vo); | |||
//属性赋值 | |||
//高度 | |||
Double.parseDouble(flightData.getAlt()); | |||
double round = CommonNumberTypeUtils.round(Double.parseDouble(flightData.getAlt()), 2); |
@@ -68,22 +68,19 @@ public class QueryInspectionCardListService { | |||
*/ | |||
public JsonResult getInspectionCardList() { | |||
//根据当前登录用户获取数据权限信息 | |||
String userId = CurrentUserUtil.getUserId(); | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = user.getId(); | |||
if(StringUtils.isEmpty(userId)){ | |||
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_ID_IS_NULL.getCode() | |||
,QueryUserInfoByIdCodeEnum.USER_ID_IS_NULL.getMsg()); | |||
} | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
String tenantId = user.getTenantId(); | |||
if(StringUtils.isEmpty(tenantId)){ | |||
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_TENANT_ID_NULL.getCode() | |||
,QueryUserInfoByIdCodeEnum.USER_TENANT_ID_NULL.getMsg()); | |||
} | |||
Tenant tenant = tenantMapper.selectById(tenantId); | |||
User user = userMapper.selectById(userId); | |||
if(ObjectUtil.isNull(user)){ | |||
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getCode(), | |||
QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getMsg()); | |||
} | |||
//部门 | |||
Dept dept = deptMapper.selectById(user.getDeptId()); | |||
if(ObjectUtil.isNull(dept)){ |
@@ -39,9 +39,6 @@ public class QueryInspectionListService { | |||
private UserMapper userMapper; | |||
public JsonResult getListByAirportId(InspectionDto dto) { | |||
// if(null == dto.getAirportId() && StringUtils.isEmpty(dto.getUserId())){ | |||
// return JsonResult.error(QueryInspectionListServiceEnum.QUERY_IS_FAILED.getCode(),QueryInspectionListServiceEnum.QUERY_IS_FAILED.getMsg()); | |||
// } | |||
String username = SecurityUserUtils.username(); | |||
if(StringUtils.isEmpty(username)){ | |||
return JsonResult.error(QueryInspectionListServiceEnum.QUERY_IS_FAILED.getCode(),QueryInspectionListServiceEnum.QUERY_IS_FAILED.getMsg()); |
@@ -9,6 +9,7 @@ import com.tuoheng.admin.entity.Business; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.LiveChannel; | |||
import com.tuoheng.admin.entity.Report; | |||
import com.tuoheng.admin.enums.AiAnalyseStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.*; | |||
@@ -33,30 +34,24 @@ public class UpdateFlightStatusService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private LiveChannelMapper liveChannelMapper; | |||
@Autowired | |||
private BusinessMapper businessMapper; | |||
@Autowired | |||
private ReportMapper reportMapper; | |||
@Autowired | |||
private IDspService dspService; | |||
@Autowired | |||
private WebSocketService webSocketService; | |||
public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) { | |||
Inspection inspectionUpdate = new Inspection(); | |||
inspectionUpdate.setId(inspection.getId()); | |||
JsonResult result = dspService.startAI(missionStatusRequest,inspection.getDspServiceInstId()); | |||
inspectionUpdate.setExecutionStartTime(DateUtils.now()); | |||
JsonResult result = dspService.startAI(inspection, missionStatusRequest.getPushUrl(), missionStatusRequest.getPullUrl()); | |||
if (0 != result.getCode()) { | |||
//如果调用DSP失败就直接失败! | |||
log.info("修改任务状态业务接口:调用DSP数据失败:{}", result.getMsg()); | |||
inspectionUpdate.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
inspectionUpdate.setExecutionStartTime(DateUtils.now()); | |||
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.WAITING.getCode()); | |||
inspectionMapper.updateById(inspectionUpdate); | |||
// 修改报告状态和开始时间 | |||
@@ -64,28 +59,9 @@ public class UpdateFlightStatusService { | |||
return result; | |||
} | |||
JSONObject jsonObject = (JSONObject) result.getData(); | |||
DspCallbackVo dspCallbackVo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackVo.class); | |||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(dspCallbackVo)); | |||
log.info("修改inspection status 开始"); | |||
inspectionUpdate.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
inspectionUpdate.setExecutionStartTime(DateUtils.now()); | |||
inspectionUpdate.setUpdateTime(DateUtils.now()); | |||
log.info("inspectionUpdate:{}", inspectionUpdate); | |||
Integer count = inspectionMapper.updateStatus(inspectionUpdate); | |||
if (count <= 0) { | |||
log.info("修改inspection status 失败"); | |||
} else { | |||
log.info("修改inspection status 成功"); | |||
} | |||
log.info("修改inspection status 结束"); | |||
// 处理通道数据 | |||
this.liveChannelHandle(inspection, dspCallbackVo); | |||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | |||
this.businessHandle(inspection, dspCallbackVo); | |||
// 修改任务的状态 | |||
this.updateInspection(inspectionUpdate); | |||
// 修改报告状态和开始时间 | |||
this.updateReport(inspection); | |||
@@ -94,54 +70,19 @@ public class UpdateFlightStatusService { | |||
} | |||
/** | |||
* 处理通道数据 | |||
* 修改任务的状态 | |||
* | |||
* @param inspection | |||
* @param dspCallbackVo | |||
* @param inspectionUpdate | |||
*/ | |||
private void liveChannelHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
log.info("进入处理通道数据方法"); | |||
// 通道表新增 | |||
LiveChannel liveChannel = this.buildLiveChannel(inspection, dspCallbackVo); | |||
// 查验是否存在 | |||
LiveChannel liveChannelQuery = liveChannelMapper.selectOne(new LambdaQueryWrapper<LiveChannel>() | |||
.eq(LiveChannel::getInspectionId, inspection.getId()) | |||
.eq(LiveChannel::getMark, MarkEnum.VALID.getCode())); | |||
if (liveChannelQuery == null) { | |||
// 添加通道使用记录 | |||
liveChannel.setCreateTime(DateUtils.now()); | |||
liveChannelMapper.insert(liveChannel); | |||
private void updateInspection(Inspection inspectionUpdate) { | |||
inspectionUpdate.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | |||
inspectionUpdate.setUpdateTime(DateUtils.now()); | |||
Integer count = inspectionMapper.updateStatus(inspectionUpdate); | |||
if (count <= 0) { | |||
log.info("修改inspection status 失败"); | |||
} else { | |||
// 更新通道使用记录 | |||
liveChannel.setId(liveChannelQuery.getId()); | |||
liveChannelMapper.updateById(liveChannel); | |||
log.info("修改inspection status 成功"); | |||
} | |||
webSocketService.accidentNotice(inspection.getTenantId()); | |||
} | |||
private LiveChannel buildLiveChannel(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
LiveChannel liveChannel = new LiveChannel(); | |||
liveChannel.setTenantId(inspection.getTenantId()); | |||
liveChannel.setDeptId(inspection.getDeptId()); | |||
liveChannel.setInspectionId(inspection.getId()); | |||
liveChannel.setChannelCode("0"); | |||
liveChannel.setPushUrl(dspCallbackVo.getPushUrl()); | |||
liveChannel.setPullUrl(dspCallbackVo.getPlayUrl()); | |||
liveChannel.setAipushUrl(dspCallbackVo.getAipushUrl()); | |||
liveChannel.setAipullUrl(dspCallbackVo.getAiplayUrl()); | |||
return liveChannel; | |||
} | |||
private void businessHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | |||
Business business = new Business(); | |||
business.setTenantId(inspection.getTenantId()); | |||
business.setMsgId(dspCallbackVo.getRequestId()); | |||
business.setType(1); | |||
business.setTypeId(inspection.getId()); | |||
business.setCreateTime(DateUtils.now()); | |||
businessMapper.insert(business); | |||
} | |||
private void updateReport(Inspection inspection) { |
@@ -1,6 +1,7 @@ | |||
package com.tuoheng.admin.service.third.dsp; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -45,8 +46,8 @@ public class DspServiceImpl implements IDspService { | |||
} | |||
@Override | |||
public JsonResult startAI(MissionStatusRequest missionStatusRequest, String dspServiceInstId) { | |||
return startAIService.startAI(missionStatusRequest, dspServiceInstId); | |||
public JsonResult startAI(Inspection inspection, String pushUrl, String pullUrl) { | |||
return startAIService.startAI(inspection, pushUrl, pullUrl); | |||
} | |||
@Override |
@@ -1,6 +1,7 @@ | |||
package com.tuoheng.admin.service.third.dsp; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -12,10 +13,14 @@ public interface IDspService { | |||
/** | |||
* 调用DSP进行AI分析 | |||
* | |||
* @param missionStatusRequest | |||
* @param inspection | |||
* @param pushUrl | |||
* @param pullUrl | |||
* | |||
* | |||
* @return | |||
*/ | |||
JsonResult startAI(MissionStatusRequest missionStatusRequest, String dspServiceInstId); | |||
JsonResult startAI(Inspection inspection, String pushUrl, String pullUrl); | |||
/** | |||
* 硬件停止后,停止AI分析 |
@@ -1,9 +1,23 @@ | |||
package com.tuoheng.admin.service.third.dsp; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONArray; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.Business; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.LiveChannel; | |||
import com.tuoheng.admin.enums.AiAnalyseStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum; | |||
import com.tuoheng.admin.mapper.BusinessMapper; | |||
import com.tuoheng.admin.mapper.LiveChannelMapper; | |||
import com.tuoheng.admin.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.admin.vo.DspCallbackVo; | |||
import com.tuoheng.admin.websocket.WebSocketService; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.RedisUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -12,7 +26,6 @@ import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Locale; | |||
@Slf4j | |||
@Service | |||
public class StartAIService { | |||
@@ -26,21 +39,82 @@ public class StartAIService { | |||
@Value("${tuoheng.dsp-callback-url:}") | |||
private String dspCallbackUrl; | |||
@Value("${tuoheng.dsp-service-inst-id:}") | |||
private String dspServiceInstId; | |||
@Autowired | |||
private RedisUtils redisUtils; | |||
@Autowired | |||
private LiveChannelMapper liveChannelMapper; | |||
@Autowired | |||
private BusinessMapper businessMapper; | |||
@Autowired | |||
private WebSocketService webSocketService; | |||
/** | |||
* 调用DSP接口 | |||
* | |||
* @param missionStatusRequest | |||
* @param inspection | |||
* @param pushUrl | |||
* @param pullUrl | |||
* | |||
* @return | |||
*/ | |||
public JsonResult startAI(MissionStatusRequest missionStatusRequest, String dspServiceInstId) { | |||
log.info("进入调用DSP接口方法, missionStatusRequest={}", missionStatusRequest); | |||
log.info("进入调用DSP接口方法, dspServiceInstId={}", dspServiceInstId); | |||
public JsonResult startAI(Inspection inspection, String pushUrl, String pullUrl) { | |||
log.info("调用DSP进行分析, inspectionId={}, pushUrl:{}, pullUrl:{}", inspection.getId(), pushUrl, pullUrl); | |||
String dspServiceInstId = inspection.getDspServiceInstId(); | |||
JsonResult result = this.callDsp(dspServiceInstId, pushUrl, pullUrl); | |||
if (0 != result.getCode()) { | |||
// 如果调用DSP失败就直接失败! | |||
log.info("调用DSP数据失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
JSONObject jsonObject = (JSONObject) result.getData(); | |||
DspCallbackVo dspCallbackVo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackVo.class); | |||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(dspCallbackVo)); | |||
// 处理通道数据 | |||
this.liveChannelHandle(inspection, dspCallbackVo); | |||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | |||
this.businessHandle(inspection, dspCallbackVo); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 调用DSP接口 | |||
* | |||
* @param dspServiceInstId | |||
* @param pushUrl | |||
* @param pullUrl | |||
* | |||
* @return | |||
*/ | |||
public JsonResult callDsp(String dspServiceInstId, String pushUrl, String pullUrl) { | |||
String url = String.format(Locale.ENGLISH, "%s/api/web/serviceInst/%s/application", dspDomainUrl, dspServiceInstId); | |||
JSONObject jsonObject = this.getJSONObject(pushUrl, pullUrl); | |||
log.info("调用DSP服务, url:{}", url); | |||
log.info("调用DSP服务, jsonObject:{}", jsonObject); | |||
String result = SendPost.doPost(url, jsonObject, null); | |||
log.info("调用DSP服务, result:{}", result); | |||
JSONObject responseJson = JSONObject.parseObject(result); | |||
if (responseJson.getIntValue("code") == 0) { | |||
String requestId = responseJson.getJSONObject("data").getString("requestId"); | |||
log.info("调用DSP进行分析,dsp实时调用响应,requestId:{}", requestId); | |||
} else { | |||
log.error("dsp实时调用失败:{}", responseJson); | |||
return JsonResult.error(EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getCode(), EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getMsg()); | |||
} | |||
return JsonResult.success(responseJson); | |||
} | |||
private JSONObject getJSONObject(String pushUrl, String pullUrl) { | |||
JSONObject request = new JSONObject(); | |||
JSONArray configList = new JSONArray(); | |||
JSONObject instConfigMode = new JSONObject(); | |||
@@ -57,32 +131,65 @@ public class StartAIService { | |||
JSONObject instReqUrlPush = new JSONObject(); | |||
instReqUrlPush.put("ename", "push_url"); | |||
instReqUrlPush.put("evalue", missionStatusRequest.getPushUrl()); | |||
instReqUrlPush.put("evalue", pushUrl); | |||
reqList.add(instReqUrlPush); | |||
JSONObject instReqUrlPull = new JSONObject(); | |||
instReqUrlPull.put("ename", "pull_url"); | |||
instReqUrlPull.put("evalue", missionStatusRequest.getPullUrl()); | |||
instReqUrlPull.put("evalue", pullUrl); | |||
reqList.add(instReqUrlPull); | |||
request.put("serviceInstReqList", reqList); | |||
JSONObject responseJson = this.serviceInstApplication(request, dspServiceInstId); | |||
if (responseJson.getIntValue("code") == 0) { | |||
String requestId = responseJson.getJSONObject("data").getString("requestId"); | |||
log.info("dsp实时调用响应requestId:{}", requestId); | |||
return request; | |||
} | |||
/** | |||
* 处理通道数据 | |||
* | |||
* @param inspection | |||
* @param dspCallbackVo | |||
*/ | |||
private void liveChannelHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
log.info("进入处理通道数据方法"); | |||
// 通道表新增 | |||
LiveChannel liveChannel = this.buildLiveChannel(inspection, dspCallbackVo); | |||
// 查验是否存在 | |||
LiveChannel liveChannelQuery = liveChannelMapper.selectOne(new LambdaQueryWrapper<LiveChannel>() | |||
.eq(LiveChannel::getInspectionId, inspection.getId()) | |||
.eq(LiveChannel::getMark, MarkEnum.VALID.getCode())); | |||
if (liveChannelQuery == null) { | |||
// 添加通道使用记录 | |||
liveChannel.setCreateTime(DateUtils.now()); | |||
liveChannelMapper.insert(liveChannel); | |||
} else { | |||
log.error("dsp实时调用失败:{}", responseJson); | |||
return JsonResult.error(EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getCode(), EditInspectionStatusCodeEnum.TASK_ANALYSIS_FAILED.getMsg()); | |||
// 更新通道使用记录 | |||
liveChannel.setId(liveChannelQuery.getId()); | |||
liveChannelMapper.updateById(liveChannel); | |||
} | |||
return JsonResult.success(responseJson); | |||
webSocketService.accidentNotice(inspection.getTenantId()); | |||
} | |||
private JSONObject serviceInstApplication(JSONObject jsonObject, String dspServiceInstId) { | |||
String url = String.format(Locale.ENGLISH, "%s/api/web/serviceInst/%s/application", dspDomainUrl, dspServiceInstId); | |||
log.info("调用DSP服务, url:{}", url); | |||
log.info("调用DSP服务, jsonObject:{}", jsonObject); | |||
String result = SendPost.doPost(url, jsonObject, null); | |||
log.info("调用DSP服务, result:{}", result); | |||
return JSONObject.parseObject(result); | |||
private LiveChannel buildLiveChannel(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
LiveChannel liveChannel = new LiveChannel(); | |||
liveChannel.setTenantId(inspection.getTenantId()); | |||
liveChannel.setDeptId(inspection.getDeptId()); | |||
liveChannel.setInspectionId(inspection.getId()); | |||
liveChannel.setChannelCode("0"); | |||
liveChannel.setPushUrl(dspCallbackVo.getPushUrl()); | |||
liveChannel.setPullUrl(dspCallbackVo.getPlayUrl()); | |||
liveChannel.setAipushUrl(dspCallbackVo.getAipushUrl()); | |||
liveChannel.setAipullUrl(dspCallbackVo.getAiplayUrl()); | |||
return liveChannel; | |||
} | |||
private void businessHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | |||
Business business = new Business(); | |||
business.setTenantId(inspection.getTenantId()); | |||
business.setMsgId(dspCallbackVo.getRequestId()); | |||
business.setType(1); | |||
business.setTypeId(inspection.getId()); | |||
business.setCreateTime(DateUtils.now()); | |||
businessMapper.insert(business); | |||
} | |||
} |
@@ -7,12 +7,12 @@ import lombok.Data; | |||
* @Date 2023/8/14 | |||
*/ | |||
@Data | |||
public class TZHLAirportFlightDataResponse { | |||
public class TZHLAirportFlightDataResponse{ | |||
/** | |||
* ID | |||
*/ | |||
private Long id; | |||
//private Long id; | |||
/** | |||
* 租户ID | |||
@@ -271,7 +271,7 @@ public class TZHLAirportFlightDataResponse { | |||
private String gimbalPitch; | |||
/** | |||
* 云台偏航 | |||
* 云台偏航gimbal_yaw | |||
*/ | |||
private String gimbalYaw; | |||
@@ -5,34 +5,26 @@ 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.DateUtils; | |||
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; | |||
import org.springframework.http.HttpHeaders; | |||
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.ArrayList; | |||
import java.util.Comparator; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
@@ -44,10 +36,6 @@ public class FlyDataService { | |||
@Autowired | |||
private RedisUtils redisUtils; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Autowired | |||
private FlightDataHlMapper flightDataHlMapper; | |||
@@ -59,7 +47,7 @@ public class FlyDataService { | |||
String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; | |||
JSONObject jsonObject = this.jsonObjectRequest(inspection); | |||
log.info("封装的请求参数信息,jsonObject:{}", jsonObject.toString()); | |||
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); | |||
List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); | |||
@@ -67,6 +55,7 @@ public class FlyDataService { | |||
//查询到的数据 入库 | |||
this.addFlightDataHl(inspection,flightDataHlList); | |||
} | |||
/** | |||
@@ -77,20 +66,30 @@ public class FlyDataService { | |||
*/ | |||
private void addFlightDataHl(Inspection inspection, List<TZHLAirportFlightDataResponse> flightDataHlList) { | |||
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); | |||
flightDataHl.setTenantId(inspection.getTenantId()); | |||
flightDataHl.setInspectionId(inspection.getId()); | |||
flightDataHl.setCreateTime(DateUtils.now()); | |||
flightDataHl.setCreateUser(inspection.getCreateUser()); | |||
//将最新的一条数据存入缓存,并设置过期时间 | |||
redisUtils.set(String.valueOf(inspection.getId()),flightDataHl,10); | |||
int count = flightDataHlMapper.insert(flightDataHl); | |||
if(count<=0){ | |||
log.info("输入插入失败,responseData:{}",responseData); | |||
throw new SecurityException("飞行数据插入失败"); | |||
} | |||
flightDataHls.add(flightDataHl); | |||
} | |||
//将最新的一条数据存入缓存,并设置过期时间 | |||
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); | |||
} | |||
} | |||
return; |
@@ -100,4 +100,9 @@ public class InspectionCardVo { | |||
*/ | |||
private String accidentId; | |||
/** | |||
* 机场sn号 | |||
*/ | |||
private String sn; | |||
} |
@@ -68,8 +68,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="mark" column="mark" /> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id, tenant_id, inspection_id, recordId, attachRD, uavId, uavNo, time, alt, lng, lat, spd, ht, | |||
head, pit, roll, bat, vol, fuel, act, mode, flightMode, arm, air, absp, temp, tc, velocityZ, remainingFlightTime, | |||
moduleSignal, satellite, deptId, appConnected, groundConnected, controlDevice, rcControlPosition, gps, ultrasonicHeight, | |||
altitudeFused, latLonAltitude, homeLocation, duration, battery1CapacityPercent, battery1Voltage, battery1Temperature, | |||
battery1HeatState, battery2CapacityPercent, battery2Voltage, battery2Temperature, battery2HeatState, gimbalPitch, gimbalYaw, | |||
gimbalRoll, zoomRatio, focalLength, videoStreamSource, create_user, create_time, update_user, update_time, mark | |||
</sql> | |||
<sql id="selectThFlightDataHlVo"> | |||
select id, tenant_id, inspection_id, recordId, attachRD, uavId, uavNo, time, alt, lng, lat, spd, ht, head, pit, roll, bat, vol, fuel, act, mode, flightMode, arm, air, absp, temp, tc, velocityZ, remainingFlightTime, moduleSignal, satellite, deptId, appConnected, groundConnected, controlDevice, rcControlPosition, gps, ultrasonicHeight, altitudeFused, latLonAltitude, homeLocation, duration, battery1CapacityPercent, battery1Voltage, battery1Temperature, battery1HeatState, battery2CapacityPercent, battery2Voltage, battery2Temperature, battery2HeatState, gimbalPitch, gimbalYaw, gimbalRoll, zoomRatio, focalLength, videoStreamSource, create_user, create_time, update_user, update_time, mark from th_flight_data_hl | |||
</sql> | |||
<select id="selectListByInspectionId" resultMap="BaseResultMap"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from th_flight_data_hl | |||
where inspection_id = #{id} | |||
and mark = 1 | |||
order by create_time asc | |||
</select> | |||
</mapper> |
@@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="legName" column="leg_name" /> | |||
<result property="inspectionType" column="inspection_type" /> | |||
<result property="recordId" column="record_id" /> | |||
<result property="sn" column="sn" /> | |||
<result property="airportId" column="airport_id" /> | |||
<result property="airportName" column="airport_name" /> | |||
<result property="droneId" column="drone_id" /> | |||
@@ -67,7 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<sql id="Base_Column_list"> | |||
id, tenant_id, dept_id, code, name, type, channel_id, channel_name, leg_id, leg_name, inspection_type, | |||
record_id, airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
record_id, airport_id, sn, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
equipment_mount_name, cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time, | |||
execution_start_time, execution_end_time, is_live, is_taken, is_tilt, video_url, ai_video_url, report_url, srt_url, | |||
status, analyse_status, progressbar, note, weather, fly_height, srt_name, heartbeat_time, execution_status, | |||
@@ -77,7 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<sql id="selectInspectionVo"> | |||
select id, tenant_id, dept_id, code, name, type, channel_id, channel_name, leg_id, leg_name, inspection_type, | |||
record_id, airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
record_id, airport_id, sn, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
equipment_mount_name, cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time, | |||
execution_start_time, execution_end_time, is_live, is_taken, is_tilt, video_url, ai_video_url, report_url, srt_url, | |||
status, analyse_status, progressbar, note, weather, fly_height, srt_name, heartbeat_time, execution_status, | |||
@@ -146,6 +147,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<if test="legName != null">leg_name = #{legName},</if> | |||
<if test="recordId != null"> record_id = #{RecordId},</if> | |||
<if test="airportId != null">airport_id = #{airportId},</if> | |||
<if test="sn != null">sn = #{sn},</if> | |||
<if test="airportName != null">airport_name = #{airportName},</if> | |||
<if test="droneId != null"> drone_id = #{droneId},</if> | |||
<if test="inspectionLine != null">inspection_line = #{inspectionLine},</if> |
@@ -24,11 +24,9 @@ public class TZHLGetAirportMsgServiceTest { | |||
@Test | |||
public void testGetAirportListTest() { | |||
String sn = "4TADKCC0010018"; | |||
TZHLAirportMsgResponse airportMsg = tzhlGetAirportMsgService.getAirportMsg(sn); | |||
log.info("获取结果值为result:{}",airportMsg); | |||
System.out.println("data" + airportMsg); | |||
TZHLAirportMsgResponse response = tzhlGetAirportMsgService.getAirportMsg(sn); | |||
log.info("获取结果值为result:{}", response); | |||
} | |||
} |
@@ -0,0 +1,110 @@ | |||
package com.tuoheng.admin.tzhl; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.tzhl.response.TZHLAirportFlightDataResponse; | |||
import com.tuoheng.admin.tzhl.service.fly.data.FlyDataService; | |||
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; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/8/16 | |||
*/ | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class TZHLGetFlightDataServiceTest { | |||
@Autowired | |||
private FlyDataService flyDataService; | |||
@Test | |||
public void test(){ | |||
List<TZHLAirportFlightDataResponse> list = new ArrayList<>(); | |||
TZHLAirportFlightDataResponse response = new TZHLAirportFlightDataResponse(); | |||
response.setAbsp("0"); | |||
response.setAct(1l); | |||
response.setAir("qww"); | |||
response.setAlt("rerer"); | |||
response.setAbsp("rrrr"); | |||
response.setAltitudeFused("gggg"); | |||
response.setAppConnected("kkkk"); | |||
response.setArm("llll"); | |||
response.setAttachRD(4l); | |||
response.setBat("eee"); | |||
response.setBattery1CapacityPercent("nnnn"); | |||
response.setBattery1HeatState("iiii"); | |||
response.setBattery1Temperature("45"); | |||
response.setBattery1Voltage("4.5"); | |||
response.setBattery2CapacityPercent("333"); | |||
response.setBattery2HeatState("2333"); | |||
response.setBattery2Temperature("334"); | |||
response.setBattery2Voltage("3.4"); | |||
response.setControlDevice("ffff"); | |||
response.setDeptId(23l); | |||
response.setAttachRD(5l); | |||
response.setDuration("kkkklll"); | |||
response.setFlightMode("hahah"); | |||
response.setAppConnected("sssss"); | |||
response.setFocalLength("3434"); | |||
response.setFuel("eee"); | |||
response.setGimbalPitch("ooooo"); | |||
response.setGimbalRoll("mmmm"); | |||
response.setGimbalYaw("ccccc"); | |||
response.setGps("223.44"); | |||
response.setGroundConnected("fffff"); | |||
response.setHead("eggffe"); | |||
response.setHomeLocation("江苏生"); | |||
response.setHt("dddd"); | |||
//response.setId(3l); | |||
response.setInspectionId("23ddfgggg"); | |||
response.setLat("rrrr"); | |||
response.setLatLonAltitude("eet"); | |||
response.setLng("2222"); | |||
response.setMode(5l); | |||
response.setModuleSignal("qqqqq"); | |||
response.setPit("weffg"); | |||
response.setRcControlPosition("eeeeee"); | |||
response.setRecordId(34l); | |||
response.setRemainingFlightTime("223344"); | |||
response.setRoll("ergghy"); | |||
response.setSatellite("rnrnrne"); | |||
response.setSpd("rrrredddd"); | |||
response.setTc("lllleeee"); | |||
response.setTemp("eeedwws"); | |||
response.setTenantId("wewewew"); | |||
response.setTime(3344l); | |||
response.setUavId(3l); | |||
response.setUavNo("rewwqs"); | |||
response.setUltrasonicHeight("enrhhhh"); | |||
response.setVelocityZ("gghhffdr"); | |||
response.setVideoStreamSource("2gg33345"); | |||
response.setVol("eefght"); | |||
response.setZoomRatio("sddrhgt"); | |||
//list.add(null); | |||
Inspection inspection = new Inspection(); | |||
inspection.setTenantId("112"); | |||
inspection.setId("12334"); | |||
//flyDataService.getFlyData(inspection,list); | |||
log.info("数据入库成功"); | |||
System.out.println("数据入库成功"); | |||
} | |||
} |