* 机场平台:获取机场天气详情 | * 机场平台:获取机场天气详情 | ||||
*/ | */ | ||||
String API_AIRPORT_STATUS = "/airportInterface/getAirportStatus"; | String API_AIRPORT_STATUS = "/airportInterface/getAirportStatus"; | ||||
/** | |||||
* Dsp平台,开始录制 | |||||
*/ | |||||
String DSP_START_RECORD = "/api/component/screen/recording/start"; | |||||
/** | |||||
* Dsp平台,停止录制 | |||||
*/ | |||||
String DSP_STOP_RECORD = "/api/component/screen/recording/stop"; | |||||
/** | |||||
* Dsp平台,查询录制信息 | |||||
*/ | |||||
String DSP_QUERY_RECORD = "/api/component/screen/recording/video/url"; | |||||
} | } |
package com.tuoheng.admin.entity.vo; | |||||
import lombok.Data; | |||||
@Data | |||||
public class DspCallbackQueryVo { | |||||
/** | |||||
* 状态 5:待录制 10:录制中 15:录制完成 20:录制超时 25:录制失败 | |||||
*/ | |||||
private String status; | |||||
/** | |||||
* 异常编号 | |||||
*/ | |||||
private String errorCode; | |||||
/** | |||||
* 异常描述 | |||||
*/ | |||||
private String errorMsg; | |||||
/** | |||||
* 录屏视频地址 | |||||
*/ | |||||
private String recordingVideoUrl; | |||||
} |
package com.tuoheng.admin.entity.vo; | |||||
import lombok.Data; | |||||
@Data | |||||
public class DspCallbackRecordVo { | |||||
/** | |||||
* 请求ID | |||||
*/ | |||||
private String requestId; | |||||
} |
import com.tuoheng.admin.entity.domain.Inspection; | import com.tuoheng.admin.entity.domain.Inspection; | ||||
import com.tuoheng.admin.entity.domain.LiveChannel; | import com.tuoheng.admin.entity.domain.LiveChannel; | ||||
import com.tuoheng.admin.entity.domain.Report; | import com.tuoheng.admin.entity.domain.Report; | ||||
import com.tuoheng.admin.entity.vo.DspCallbackRecordVo; | |||||
import com.tuoheng.admin.enums.InspectionStatusEnum; | import com.tuoheng.admin.enums.InspectionStatusEnum; | ||||
import com.tuoheng.admin.enums.MarkEnum; | import com.tuoheng.admin.enums.MarkEnum; | ||||
import com.tuoheng.admin.mapper.*; | import com.tuoheng.admin.mapper.*; | ||||
import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest; | import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest; | ||||
import com.tuoheng.admin.service.third.dsp.IDspService; | import com.tuoheng.admin.service.third.dsp.IDspService; | ||||
import com.tuoheng.admin.entity.vo.DspCallbackVo; | |||||
import com.tuoheng.common.core.utils.DateUtils; | import com.tuoheng.common.core.utils.DateUtils; | ||||
import com.tuoheng.common.core.utils.JacksonUtil; | import com.tuoheng.common.core.utils.JacksonUtil; | ||||
import com.tuoheng.common.core.utils.JsonResult; | import com.tuoheng.common.core.utils.JsonResult; | ||||
public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) { | public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) { | ||||
Inspection inspectionUpdate = new Inspection(); | Inspection inspectionUpdate = new Inspection(); | ||||
inspectionUpdate.setId(inspection.getId()); | inspectionUpdate.setId(inspection.getId()); | ||||
JsonResult result = dspService.startAI(missionStatusRequest,inspection.getDspServiceInstId()); | |||||
JsonResult result = dspService.startRecord(missionStatusRequest); | |||||
if (0 != result.getCode()) { | if (0 != result.getCode()) { | ||||
//如果调用DSP失败就直接失败! | //如果调用DSP失败就直接失败! | ||||
log.info("修改任务状态业务接口:调用DSP数据失败:{}", result.getMsg()); | |||||
log.info("修改任务状态业务接口:调用DSP开始录制失败:{}", result.getMsg()); | |||||
inspectionUpdate.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | inspectionUpdate.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | ||||
inspectionUpdate.setExecutionStartTime(DateUtils.now()); | inspectionUpdate.setExecutionStartTime(DateUtils.now()); | ||||
inspectionMapper.updateById(inspectionUpdate); | inspectionMapper.updateById(inspectionUpdate); | ||||
return result; | return result; | ||||
} | } | ||||
JSONObject jsonObject = (JSONObject) result.getData(); | JSONObject jsonObject = (JSONObject) result.getData(); | ||||
DspCallbackVo dspCallbackVo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackVo.class); | |||||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(dspCallbackVo)); | |||||
DspCallbackRecordVo vo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackRecordVo.class); | |||||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(vo)); | |||||
log.info("修改inspection status 开始"); | log.info("修改inspection status 开始"); | ||||
inspectionUpdate.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | inspectionUpdate.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); | ||||
log.info("修改inspection status 结束"); | log.info("修改inspection status 结束"); | ||||
// 处理通道数据 | // 处理通道数据 | ||||
this.liveChannelHandle(inspection, dspCallbackVo); | |||||
// this.liveChannelHandle(inspection, vo); | |||||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | // 将请求id和业务id消息存入数据库,用于监听获取任务信息 | ||||
this.businessHandle(inspection, dspCallbackVo); | |||||
this.businessHandle(inspection, vo); | |||||
// 修改报告状态和开始时间 | // 修改报告状态和开始时间 | ||||
this.updateReport(inspection); | this.updateReport(inspection); | ||||
* @param inspection | * @param inspection | ||||
* @param dspCallbackVo | * @param dspCallbackVo | ||||
*/ | */ | ||||
private void liveChannelHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||||
private void liveChannelHandle(Inspection inspection, DspCallbackRecordVo dspCallbackVo) { | |||||
log.info("进入处理通道数据方法"); | log.info("进入处理通道数据方法"); | ||||
// 通道表新增 | // 通道表新增 | ||||
LiveChannel liveChannel = this.buildLiveChannel(inspection, dspCallbackVo); | LiveChannel liveChannel = this.buildLiveChannel(inspection, dspCallbackVo); | ||||
} | } | ||||
} | } | ||||
private LiveChannel buildLiveChannel(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||||
private LiveChannel buildLiveChannel(Inspection inspection, DspCallbackRecordVo dspCallbackVo) { | |||||
LiveChannel liveChannel = new LiveChannel(); | LiveChannel liveChannel = new LiveChannel(); | ||||
liveChannel.setTenantId(inspection.getTenantId()); | liveChannel.setTenantId(inspection.getTenantId()); | ||||
liveChannel.setInspectionId(inspection.getId()); | liveChannel.setInspectionId(inspection.getId()); | ||||
liveChannel.setChannelCode("0"); | liveChannel.setChannelCode("0"); | ||||
liveChannel.setPushUrl(dspCallbackVo.getPushUrl()); | |||||
liveChannel.setPullUrl(dspCallbackVo.getPlayUrl()); | |||||
liveChannel.setAipushUrl(dspCallbackVo.getAipushUrl()); | |||||
liveChannel.setAipullUrl(dspCallbackVo.getAiplayUrl()); | |||||
liveChannel.setPlayUrl(dspCallbackVo.getPlayUrl()); | |||||
// liveChannel.setPushUrl(dspCallbackVo.getPushUrl()); | |||||
// liveChannel.setPullUrl(dspCallbackVo.getPlayUrl()); | |||||
// liveChannel.setAipushUrl(dspCallbackVo.getAipushUrl()); | |||||
// liveChannel.setAipullUrl(dspCallbackVo.getAiplayUrl()); | |||||
// liveChannel.setPlayUrl(dspCallbackVo.getPlayUrl()); | |||||
return liveChannel; | return liveChannel; | ||||
} | } | ||||
private void businessHandle(Inspection inspection, DspCallbackVo dspCallbackVo) { | |||||
private void businessHandle(Inspection inspection, DspCallbackRecordVo dspCallbackRecordVo) { | |||||
// 将请求id和业务id消息存入数据库,用于监听获取任务信息 | // 将请求id和业务id消息存入数据库,用于监听获取任务信息 | ||||
Business business = new Business(); | Business business = new Business(); | ||||
business.setTenantId(inspection.getTenantId()); | business.setTenantId(inspection.getTenantId()); | ||||
business.setMsgId(dspCallbackVo.getRequestId()); | |||||
business.setMsgId(dspCallbackRecordVo.getRequestId()); | |||||
business.setType(1); | business.setType(1); | ||||
business.setTypeId(inspection.getId()); | business.setTypeId(inspection.getId()); | ||||
business.setCreateTime(DateUtils.now()); | business.setCreateTime(DateUtils.now()); |
} | } | ||||
if (AirPortTaskStatusEnum.FLIGHT.getCode() == missionStatusRequest.getStatus()) { | if (AirPortTaskStatusEnum.FLIGHT.getCode() == missionStatusRequest.getStatus()) { | ||||
log.info("修改任务状态业务接口:修改执行中状态"); | |||||
log.info("修改任务状态业务接口:修改任务状态:执行中"); | |||||
status = InspectionStatusEnum.IN_FLIGHT.getCode(); | status = InspectionStatusEnum.IN_FLIGHT.getCode(); | ||||
updateFlightStatusService.updateFlightStatus(inspection, missionStatusRequest); | updateFlightStatusService.updateFlightStatus(inspection, missionStatusRequest); | ||||
} else if (AirPortTaskStatusEnum.WAIT.getCode() == missionStatusRequest.getStatus()) { | } else if (AirPortTaskStatusEnum.WAIT.getCode() == missionStatusRequest.getStatus()) { | ||||
log.info("修改任务状态业务接口:修改待执行状态"); | |||||
log.info("修改任务状态业务接口:修改任务状态:结束"); | |||||
status = InspectionStatusEnum.FLIGHT_COMPLETED.getCode(); | status = InspectionStatusEnum.FLIGHT_COMPLETED.getCode(); | ||||
updateWaittStatusService.updateWaittStatus(inspection); | updateWaittStatusService.updateWaittStatus(inspection); | ||||
} | } |
import cn.hutool.core.collection.CollectionUtil; | import cn.hutool.core.collection.CollectionUtil; | ||||
import cn.hutool.core.util.ObjectUtil; | import cn.hutool.core.util.ObjectUtil; | ||||
import com.alibaba.fastjson.JSON; | |||||
import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
import com.tuoheng.admin.entity.domain.FlightData; | import com.tuoheng.admin.entity.domain.FlightData; | ||||
import com.tuoheng.admin.entity.domain.Inspection; | import com.tuoheng.admin.entity.domain.Inspection; | ||||
import com.tuoheng.admin.entity.domain.Report; | import com.tuoheng.admin.entity.domain.Report; | ||||
import com.tuoheng.admin.entity.vo.DspCallbackQueryVo; | |||||
import com.tuoheng.admin.entity.vo.DspCallbackRecordVo; | |||||
import com.tuoheng.admin.enums.MarkEnum; | import com.tuoheng.admin.enums.MarkEnum; | ||||
import com.tuoheng.admin.enums.TaskStatusEnum; | import com.tuoheng.admin.enums.TaskStatusEnum; | ||||
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum; | import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum; | ||||
return; | return; | ||||
} | } | ||||
// 硬件停止后,停止AI分析 | |||||
dspService.stopAI(businessList.get(0).getMsgId(), inspection.getId()); | |||||
// 硬件停止后,停止录制 | |||||
dspService.stopRecord(businessList.get(0).getMsgId()); | |||||
// 硬件停止后,查询录屏信息 | |||||
JsonResult queryRecord = dspService.queryRecord(businessList.get(0).getMsgId()); | |||||
JSONObject jsonObject = (JSONObject) queryRecord.getData(); | |||||
DspCallbackQueryVo vo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackQueryVo.class); | |||||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(vo)); | |||||
inspectionUpdate.setVideoUrl(vo.getRecordingVideoUrl()); | |||||
//获取天气信息 | //获取天气信息 | ||||
JsonResult result = this.getWeather(CommonConfig.airportURL, inspection.getAirportId()); | JsonResult result = this.getWeather(CommonConfig.airportURL, inspection.getAirportId()); |
@Autowired | @Autowired | ||||
private StopAIService stopAIService; | private StopAIService stopAIService; | ||||
@Autowired | |||||
private StartRecordIService startRecordIService; | |||||
@Autowired | |||||
private StopRecordIService stopRecordIService; | |||||
@Autowired | |||||
private QueryRecordIService queryRecordIService; | |||||
/** | /** | ||||
* DSP服务API接口域名 | * DSP服务API接口域名 | ||||
*/ | */ | ||||
public JsonResult stopAI(String msgId, String inspectionId) { | public JsonResult stopAI(String msgId, String inspectionId) { | ||||
return stopAIService.stopAI(msgId, inspectionId); | return stopAIService.stopAI(msgId, inspectionId); | ||||
} | } | ||||
@Override | |||||
public JsonResult startRecord(MissionStatusRequest missionStatusRequest) { | |||||
return startRecordIService.startRecord(missionStatusRequest); | |||||
} | |||||
@Override | |||||
public JsonResult stopRecord(String msgId) { | |||||
return stopRecordIService.stopRecord(msgId); | |||||
} | |||||
@Override | |||||
public JsonResult queryRecord(String msgId) { | |||||
return queryRecordIService.queryRecord(msgId); | |||||
} | |||||
} | } |
* @return | * @return | ||||
*/ | */ | ||||
JsonResult stopAI(String msgId, String inspectionId); | JsonResult stopAI(String msgId, String inspectionId); | ||||
/** | |||||
* 硬件停止后,调DSP开始录制 | |||||
* | |||||
* @param missionStatusRequest | |||||
* @return | |||||
*/ | |||||
JsonResult startRecord(MissionStatusRequest missionStatusRequest); | |||||
/** | |||||
* 硬件停止后,调DSP停止录制 | |||||
* | |||||
* @param msgId | |||||
* @return | |||||
*/ | |||||
JsonResult stopRecord(String msgId); | |||||
/** | |||||
* 硬件停止后,查询DSP录制信息 | |||||
* | |||||
* @param msgId | |||||
* @return | |||||
*/ | |||||
JsonResult queryRecord(String msgId); | |||||
} | } |
package com.tuoheng.admin.service.third.dsp; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.tuoheng.admin.constant.SystemConstant; | |||||
import com.tuoheng.common.core.exception.ServiceException; | |||||
import com.tuoheng.common.core.utils.JsonResult; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Qualifier; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.client.RestTemplate; | |||||
import org.springframework.web.util.UriComponentsBuilder; | |||||
import java.util.Objects; | |||||
@Slf4j | |||||
@Service | |||||
public class QueryRecordIService { | |||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
/** | |||||
* DSP服务API接口域名 | |||||
*/ | |||||
@Value("${tuoheng.dsp-domain-url:}") | |||||
private String dspDomainUrl; | |||||
public JsonResult queryRecord(String msgId) { | |||||
String url = UriComponentsBuilder.fromHttpUrl(dspDomainUrl+SystemConstant.DSP_QUERY_RECORD) | |||||
.queryParam("requestId", msgId) | |||||
.toUriString(); | |||||
JsonResult jsonResult; | |||||
try { | |||||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.info("调用查询录屏信息接口异常, url:{}", url); | |||||
throw new ServiceException("调用查询录屏信息接口异常"); | |||||
} | |||||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||||
return JsonResult.error("调用查询录屏信息接口失败,请重试!"); | |||||
} | |||||
return jsonResult; | |||||
} | |||||
} |
package com.tuoheng.admin.service.third.dsp; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.alibaba.fastjson.JSONArray; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.tuoheng.admin.constant.SystemConstant; | |||||
import com.tuoheng.admin.entity.domain.Inspection; | |||||
import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest; | |||||
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum; | |||||
import com.tuoheng.common.core.exception.ServiceException; | |||||
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.beans.factory.annotation.Qualifier; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.client.RestTemplate; | |||||
import org.springframework.web.util.UriComponentsBuilder; | |||||
import org.springframework.http.*; | |||||
import java.util.Locale; | |||||
import java.util.Objects; | |||||
@Slf4j | |||||
@Service | |||||
public class StartRecordIService { | |||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
/** | |||||
* DSP服务API接口域名 | |||||
*/ | |||||
@Value("${tuoheng.dsp-domain-url:}") | |||||
private String dspDomainUrl; | |||||
/** | |||||
* 调用DSP接口 | |||||
* @param request | |||||
* @return | |||||
*/ | |||||
public JsonResult startRecord(MissionStatusRequest request) { | |||||
String url = dspDomainUrl+SystemConstant.DSP_START_RECORD; | |||||
JSONObject jsonObject = new JSONObject(); | |||||
jsonObject.put("requestId", request.getRequestId()); | |||||
jsonObject.put("pullUrl", request.getPullUrl()); | |||||
HttpHeaders headers = new HttpHeaders(); | |||||
headers.setContentType(MediaType.APPLICATION_JSON); | |||||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||||
ResponseEntity<JsonResult> response; | |||||
try { | |||||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.info("调用dsp平台,调用开始录制接口异常,url:{}", url); | |||||
log.info("调用dsp平台,调用开始录制接口异常,jsonObject:{}", jsonObject); | |||||
return null; | |||||
} | |||||
if (ObjectUtil.isEmpty(response)) { | |||||
log.info("调用dsp平台,调用开始录制接口返回为空,url:{}", url); | |||||
log.info("调用dsp平台,调用开始录制接口返回为空,jsonObject:{}", jsonObject); | |||||
return null; | |||||
} | |||||
JsonResult jsonResult = response.getBody(); | |||||
if (0 != jsonResult.getCode()) { | |||||
log.info("调用dsp平台,调用开始录制接口,失败,url:{}", url); | |||||
log.info("调用dsp平台,调用开始录制接口,失败,jsonObject:{}", jsonObject); | |||||
log.info("调用dsp平台,调用开始录制接口,失败", jsonResult.getMsg()); | |||||
return null; | |||||
} | |||||
return jsonResult; | |||||
} | |||||
} |
package com.tuoheng.admin.service.third.dsp; | |||||
import cn.hutool.core.collection.CollectionUtil; | |||||
import cn.hutool.core.util.ObjectUtil; | |||||
import com.alibaba.fastjson.JSONObject; | |||||
import com.tuoheng.admin.constant.SystemConstant; | |||||
import com.tuoheng.admin.entity.domain.Inspection; | |||||
import com.tuoheng.admin.enums.AiAnalyseStatusEnum; | |||||
import com.tuoheng.admin.mapper.InspectionMapper; | |||||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||||
import com.tuoheng.common.core.config.common.CommonConfig; | |||||
import com.tuoheng.common.core.exception.ServiceException; | |||||
import com.tuoheng.common.core.utils.HttpUtils; | |||||
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.beans.factory.annotation.Qualifier; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.http.*; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.web.client.RestTemplate; | |||||
import org.springframework.web.util.UriComponentsBuilder; | |||||
import java.util.List; | |||||
import java.util.Objects; | |||||
@Slf4j | |||||
@Service | |||||
public class StopRecordIService { | |||||
@Autowired | |||||
private InspectionMapper inspectionMapper; | |||||
/** | |||||
* DSP服务API接口域名 | |||||
*/ | |||||
@Value("${tuoheng.dsp-domain-url:}") | |||||
private String dspDomainUrl; | |||||
@Autowired | |||||
@Qualifier("restTemplate") | |||||
private RestTemplate restTemplate; | |||||
public JsonResult stopRecord(String msgId) { | |||||
String url = dspDomainUrl+SystemConstant.DSP_START_RECORD+"?request="+msgId; | |||||
JsonResult jsonResult; | |||||
try { | |||||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||||
} catch (Exception e) { | |||||
log.info("调用停止录制接口异常, url:{}", url); | |||||
throw new ServiceException("调用停止录制接口异常"); | |||||
} | |||||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||||
return JsonResult.error("调用停止录制接口失败,请重试!"); | |||||
} | |||||
return jsonResult; | |||||
} | |||||
} |