@@ -118,6 +118,6 @@ public interface SystemConstant { | |||
/** | |||
* Dsp平台,查询录制信息 | |||
*/ | |||
String DSP_QUERY_RECORD = "/api/web/screen/recording/video/url"; | |||
String DSP_QUERY_RECORD = "/api/web/screen/recording/video/url/"; | |||
} |
@@ -2,7 +2,6 @@ package com.tuoheng.admin.service.inspection.update.status; | |||
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.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
@@ -11,17 +10,19 @@ import com.tuoheng.admin.entity.domain.Business; | |||
import com.tuoheng.admin.entity.domain.FlightData; | |||
import com.tuoheng.admin.entity.domain.Inspection; | |||
import com.tuoheng.admin.entity.domain.Report; | |||
import com.tuoheng.admin.entity.vo.AirWeatherVO; | |||
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.TaskStatusEnum; | |||
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum; | |||
import com.tuoheng.admin.mapper.*; | |||
import com.tuoheng.admin.service.third.dsp.IDspService; | |||
import com.tuoheng.admin.utils.AirWeatherUtil; | |||
import com.tuoheng.admin.entity.vo.AirWeatherVO; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.utils.*; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@@ -58,32 +59,33 @@ public class UpdateWaittStatusService { | |||
inspectionUpdate.setExecutionEndTime(DateUtils.now()); | |||
List<Business> businessList = businessMapper.selectList(new LambdaQueryWrapper<Business>() | |||
.eq(Business::getTypeId, inspection.getId()) | |||
.eq(Business::getMark, MarkEnum.VALID.getCode()) | |||
.orderByDesc(Business::getCreateTime)); | |||
.eq(Business::getTypeId, inspection.getId()) | |||
.eq(Business::getMark, MarkEnum.VALID.getCode()) | |||
.orderByDesc(Business::getCreateTime)); | |||
if (CollectionUtil.isEmpty(businessList)) { | |||
log.info("业务数据为空"); | |||
log.info("业务数据为空, inspectionId", inspection.getId()); | |||
inspectionMapper.updateById(inspectionUpdate); | |||
return; | |||
} | |||
// 硬件停止后,停止录制 | |||
JsonResult stopRecord = dspService.stopRecord(businessList.get(0).getMsgId()); | |||
if(0 != stopRecord.getCode()){ | |||
log.info("调用停止录制接口失败,请重试!",stopRecord.getMsg()); | |||
} | |||
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 jsonResult = dspService.queryRecord(businessList.get(0).getMsgId()); | |||
if (0 == jsonResult.getCode()) { | |||
DspCallbackQueryVo dspCallbackQueryVo = (DspCallbackQueryVo) jsonResult.getData(); | |||
log.info("查询录屏信息,dsp响应体:{}", JacksonUtil.obj2StringPretty(dspCallbackQueryVo)); | |||
if (ObjectUtil.isNotEmpty(dspCallbackQueryVo)) { | |||
inspectionUpdate.setVideoUrl(dspCallbackQueryVo.getRecordingVideoUrl()); | |||
} else { | |||
log.info("查询录屏信息,录屏视频地址为空"); | |||
} | |||
} | |||
//获取天气信息 | |||
JsonResult result = this.getWeather(CommonConfig.airportURL, inspection.getAirportId()); | |||
JsonResult result = this.getWeather(CommonConfig.airportURL, inspection.getAirportId()); | |||
if (0 != result.getCode()) { | |||
log.info("修改任务状态业务接口:获取天气信息失败:{}", result.getMsg()); | |||
inspectionUpdate.setWeather(""); |
@@ -22,12 +22,12 @@ public class DspServiceImpl implements IDspService { | |||
private StopAIService stopAIService; | |||
@Autowired | |||
private StartRecordIService startRecordIService; | |||
private StartRecordService startRecordService; | |||
@Autowired | |||
private StopRecordIService stopRecordIService; | |||
private StopRecordService stopRecordService; | |||
@Autowired | |||
private QueryRecordIService queryRecordIService; | |||
private QueryRecordService queryRecordService; | |||
/** | |||
* DSP服务API接口域名 | |||
@@ -64,16 +64,16 @@ public class DspServiceImpl implements IDspService { | |||
@Override | |||
public JsonResult startRecord(MissionStatusRequest missionStatusRequest) { | |||
return startRecordIService.startRecord(missionStatusRequest); | |||
return startRecordService.startRecord(missionStatusRequest); | |||
} | |||
@Override | |||
public JsonResult stopRecord(String msgId) { | |||
return stopRecordIService.stopRecord(msgId); | |||
return stopRecordService.stopRecord(msgId); | |||
} | |||
@Override | |||
public JsonResult queryRecord(String msgId) { | |||
return queryRecordIService.queryRecord(msgId); | |||
return queryRecordService.queryRecord(msgId); | |||
} | |||
} |
@@ -2,21 +2,25 @@ package com.tuoheng.admin.service.third.dsp; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.vo.DspCallbackQueryVo; | |||
import com.tuoheng.admin.entity.vo.DspCallbackRecordVo; | |||
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.core.ParameterizedTypeReference; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.ResponseEntity; | |||
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 { | |||
public class QueryRecordService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
@@ -29,19 +33,26 @@ public class QueryRecordIService { | |||
private String dspDomainUrl; | |||
public JsonResult queryRecord(String msgId) { | |||
String url = UriComponentsBuilder.fromHttpUrl(dspDomainUrl+SystemConstant.DSP_QUERY_RECORD) | |||
.queryParam("requestId", msgId) | |||
.toUriString(); | |||
String url = dspDomainUrl + SystemConstant.DSP_QUERY_RECORD + msgId; | |||
log.info("调用dsp平台,查询录屏信息接口,url:{}", url); | |||
JsonResult jsonResult; | |||
ResponseEntity<JsonResult<DspCallbackQueryVo>> response; | |||
ParameterizedTypeReference<JsonResult<DspCallbackQueryVo>> parameterizedTypeReference = | |||
new ParameterizedTypeReference<>() { | |||
}; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
response =restTemplate.exchange(url, HttpMethod.GET, null, parameterizedTypeReference); | |||
} catch (Exception e) { | |||
log.info("调用dsp平台,查询录屏信息接口异常"); | |||
throw new ServiceException("调用dsp平台,查询录屏信息接口异常"); | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
throw new ServiceException("调用dsp平台,查询录屏信息接口失败"); | |||
if (ObjectUtil.isEmpty(response)) { | |||
log.info("调用dsp平台,查询录屏信息返回为空"); | |||
throw new ServiceException("调用dsp平台,查询录屏信息返回为空"); | |||
} | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用dsp平台,查询录屏信息,失败,jsonResult:{}"); | |||
throw new ServiceException("调用dsp平台,查询录屏信息,失败"); | |||
} | |||
return jsonResult; | |||
} |
@@ -1,33 +1,25 @@ | |||
package com.tuoheng.admin.service.third.dsp; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSON; | |||
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.entity.vo.DspCallbackRecordVo; | |||
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.core.ParameterizedTypeReference; | |||
import org.springframework.http.*; | |||
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 { | |||
public class StartRecordService { | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@@ -40,11 +32,12 @@ public class StartRecordIService { | |||
/** | |||
* 调用DSP接口 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
public JsonResult startRecord(MissionStatusRequest request) { | |||
String url = dspDomainUrl+SystemConstant.DSP_START_RECORD; | |||
String url = dspDomainUrl + SystemConstant.DSP_START_RECORD; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("requestId", request.getRequestId()); | |||
jsonObject.put("pullUrl", request.getPullUrl()); | |||
@@ -57,7 +50,7 @@ public class StartRecordIService { | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
ResponseEntity<JsonResult<DspCallbackRecordVo>> response; | |||
ParameterizedTypeReference<JsonResult<DspCallbackRecordVo>> parameterizedTypeReference = | |||
new ParameterizedTypeReference<JsonResult<DspCallbackRecordVo>>() { | |||
new ParameterizedTypeReference<>() { | |||
}; | |||
try { | |||
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, parameterizedTypeReference); |
@@ -1,18 +1,10 @@ | |||
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; | |||
@@ -22,12 +14,10 @@ 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 { | |||
public class StopRecordService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@@ -42,19 +32,31 @@ public class StopRecordIService { | |||
private RestTemplate restTemplate; | |||
public JsonResult stopRecord(String msgId) { | |||
String url = UriComponentsBuilder.fromHttpUrl(dspDomainUrl+SystemConstant.DSP_STOP_RECORD) | |||
.queryParam("requestId", msgId) | |||
.toUriString(); | |||
String url = UriComponentsBuilder.fromHttpUrl(dspDomainUrl + SystemConstant.DSP_STOP_RECORD).toUriString(); | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("requestId", msgId); | |||
HttpHeaders headers = new HttpHeaders(); | |||
headers.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); | |||
log.info("调用dsp平台,停止录制接口,url:{}", url); | |||
JsonResult jsonResult; | |||
log.info("调用dsp平台,停止录制接口,jsonObject:{}", jsonObject); | |||
ResponseEntity<JsonResult> response; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("调用dsp平台,停止录制接异常, e:{}", e); | |||
throw new ServiceException("调用停止录制接口异常"); | |||
log.info("调用dsp平台,停止录制接口异常, e:{}", e); | |||
throw new ServiceException("调用dsp平台,停止录制接口异常"); | |||
} | |||
if (response == null || !response.hasBody()) { | |||
log.error("调用dsp平台,停止录制接口返回为空!"); | |||
throw new ServiceException("调用dsp平台,停止录制接口返回为空"); | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error("调用dsp平台,停止录制接失败,请重试!"); | |||
JsonResult jsonResult = response.getBody(); | |||
if (0 != jsonResult.getCode()) { | |||
log.info("调用dsp平台,停止录制接口返回失败,jsonResult:{}", jsonResult.getMsg()); | |||
throw new ServiceException("调用dsp平台,停止录制接口返回失败"); | |||
} | |||
return jsonResult; | |||
} |
@@ -1,12 +1,14 @@ | |||
package com.tuoheng.admin.service; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONArray; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest; | |||
import com.tuoheng.admin.entity.request.third.DspCallbackRequest; | |||
import com.tuoheng.admin.service.third.dsp.IDspCallbackService; | |||
import com.tuoheng.admin.service.third.dsp.SendPost; | |||
import com.tuoheng.admin.service.third.dsp.StartRecordIService; | |||
import com.tuoheng.admin.entity.vo.DspCallbackQueryVo; | |||
import com.tuoheng.admin.service.third.dsp.*; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
@@ -23,7 +25,13 @@ public class DspCallbackServiceTest { | |||
private IDspCallbackService dspCallbackService; | |||
@Autowired | |||
private StartRecordIService startRecordIService; | |||
private StartRecordService startRecordService; | |||
@Autowired | |||
private StopRecordService stopRecordService; | |||
@Autowired | |||
private QueryRecordService queryRecordService; | |||
@Test | |||
public void testGetOneById() { | |||
@@ -69,6 +77,18 @@ public class DspCallbackServiceTest { | |||
MissionStatusRequest request = new MissionStatusRequest(); | |||
request.setRequestId("2199124367dd36d6c1d99d7b15d38c3b"); | |||
request.setPullUrl("https://live.play.t-aaron.com/live/test21.flv"); | |||
startRecordIService.startRecord(request); | |||
startRecordService.startRecord(request); | |||
} | |||
@Test | |||
public void testStopRecord() { | |||
stopRecordService.stopRecord("2199124367dd36d6c1d99d7b15d38c3b"); | |||
} | |||
@Test | |||
public void testQueryRRecord() { | |||
JsonResult jsonResult = queryRecordService.queryRecord("2199124367dd36d6c1d99d7b15d38c3b"); | |||
DspCallbackQueryVo vo = (DspCallbackQueryVo) jsonResult.getData(); | |||
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(vo)); | |||
} | |||
} |