Ver código fonte

修改停止录制代码

pull/86/head
wanjing 10 meses atrás
pai
commit
42d5410e20
7 arquivos alterados com 102 adições e 74 exclusões
  1. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java
  2. +21
    -19
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java
  3. +6
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java
  4. +20
    -9
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/QueryRecordService.java
  5. +6
    -13
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartRecordService.java
  6. +23
    -21
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StopRecordService.java
  7. +25
    -5
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/DspCallbackServiceTest.java

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java Ver arquivo

/** /**
* Dsp平台,查询录制信息 * Dsp平台,查询录制信息
*/ */
String DSP_QUERY_RECORD = "/api/web/screen/recording/video/url";
String DSP_QUERY_RECORD = "/api/web/screen/recording/video/url/";


} }

+ 21
- 19
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java Ver arquivo



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.AirWeatherVO;
import com.tuoheng.admin.entity.vo.DspCallbackQueryVo; 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;
import com.tuoheng.admin.mapper.*; import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.service.third.dsp.IDspService; import com.tuoheng.admin.service.third.dsp.IDspService;
import com.tuoheng.admin.utils.AirWeatherUtil; 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.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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
inspectionUpdate.setExecutionEndTime(DateUtils.now()); inspectionUpdate.setExecutionEndTime(DateUtils.now());


List<Business> businessList = businessMapper.selectList(new LambdaQueryWrapper<Business>() 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)) { if (CollectionUtil.isEmpty(businessList)) {
log.info("业务数据为空");
log.info("业务数据为空, inspectionId", inspection.getId());
inspectionMapper.updateById(inspectionUpdate); inspectionMapper.updateById(inspectionUpdate);
return; 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()) { if (0 != result.getCode()) {
log.info("修改任务状态业务接口:获取天气信息失败:{}", result.getMsg()); log.info("修改任务状态业务接口:获取天气信息失败:{}", result.getMsg());
inspectionUpdate.setWeather(""); inspectionUpdate.setWeather("");

+ 6
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java Ver arquivo

private StopAIService stopAIService; private StopAIService stopAIService;


@Autowired @Autowired
private StartRecordIService startRecordIService;
private StartRecordService startRecordService;


@Autowired @Autowired
private StopRecordIService stopRecordIService;
private StopRecordService stopRecordService;
@Autowired @Autowired
private QueryRecordIService queryRecordIService;
private QueryRecordService queryRecordService;


/** /**
* DSP服务API接口域名 * DSP服务API接口域名


@Override @Override
public JsonResult startRecord(MissionStatusRequest missionStatusRequest) { public JsonResult startRecord(MissionStatusRequest missionStatusRequest) {
return startRecordIService.startRecord(missionStatusRequest);
return startRecordService.startRecord(missionStatusRequest);
} }


@Override @Override
public JsonResult stopRecord(String msgId) { public JsonResult stopRecord(String msgId) {
return stopRecordIService.stopRecord(msgId);
return stopRecordService.stopRecord(msgId);
} }


@Override @Override
public JsonResult queryRecord(String msgId) { public JsonResult queryRecord(String msgId) {
return queryRecordIService.queryRecord(msgId);
return queryRecordService.queryRecord(msgId);
} }
} }

tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/QueryRecordIService.java → tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/QueryRecordService.java Ver arquivo



import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.admin.constant.SystemConstant; 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.exception.ServiceException;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; 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.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;


import java.util.Objects; import java.util.Objects;


@Slf4j @Slf4j
@Service @Service
public class QueryRecordIService {
public class QueryRecordService {


@Autowired @Autowired
@Qualifier("restTemplate") @Qualifier("restTemplate")
private String dspDomainUrl; private String dspDomainUrl;


public JsonResult queryRecord(String msgId) { 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); log.info("调用dsp平台,查询录屏信息接口,url:{}", url);
JsonResult jsonResult;
ResponseEntity<JsonResult<DspCallbackQueryVo>> response;
ParameterizedTypeReference<JsonResult<DspCallbackQueryVo>> parameterizedTypeReference =
new ParameterizedTypeReference<>() {
};
try { try {
jsonResult = restTemplate.getForObject(url, JsonResult.class);
response =restTemplate.exchange(url, HttpMethod.GET, null, parameterizedTypeReference);
} catch (Exception e) { } catch (Exception e) {
log.info("调用dsp平台,查询录屏信息接口异常"); log.info("调用dsp平台,查询录屏信息接口异常");
throw new ServiceException("调用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; return jsonResult;
} }

tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartRecordIService.java → tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartRecordService.java Ver arquivo

package com.tuoheng.admin.service.third.dsp; package com.tuoheng.admin.service.third.dsp;


import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant; 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.request.inspection.MissionStatusRequest;
import com.tuoheng.admin.entity.vo.DspCallbackRecordVo; 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.exception.ServiceException;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; 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 @Slf4j
@Service @Service
public class StartRecordIService {
public class StartRecordService {

@Autowired @Autowired
@Qualifier("restTemplate") @Qualifier("restTemplate")
private RestTemplate restTemplate; private RestTemplate restTemplate;


/** /**
* 调用DSP接口 * 调用DSP接口
*
* @param request * @param request
* @return * @return
*/ */
public JsonResult startRecord(MissionStatusRequest request) { public JsonResult startRecord(MissionStatusRequest request) {
String url = dspDomainUrl+SystemConstant.DSP_START_RECORD;
String url = dspDomainUrl + SystemConstant.DSP_START_RECORD;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId", request.getRequestId()); jsonObject.put("requestId", request.getRequestId());
jsonObject.put("pullUrl", request.getPullUrl()); jsonObject.put("pullUrl", request.getPullUrl());
HttpEntity httpEntity = new HttpEntity(jsonObject, headers); HttpEntity httpEntity = new HttpEntity(jsonObject, headers);
ResponseEntity<JsonResult<DspCallbackRecordVo>> response; ResponseEntity<JsonResult<DspCallbackRecordVo>> response;
ParameterizedTypeReference<JsonResult<DspCallbackRecordVo>> parameterizedTypeReference = ParameterizedTypeReference<JsonResult<DspCallbackRecordVo>> parameterizedTypeReference =
new ParameterizedTypeReference<JsonResult<DspCallbackRecordVo>>() {
new ParameterizedTypeReference<>() {
}; };
try { try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, parameterizedTypeReference); response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, parameterizedTypeReference);

tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StopRecordIService.java → tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StopRecordService.java Ver arquivo

package com.tuoheng.admin.service.third.dsp; 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.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant; 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.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.exception.ServiceException;
import com.tuoheng.common.core.utils.HttpUtils;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;


import java.util.List;
import java.util.Objects;

@Slf4j @Slf4j
@Service @Service
public class StopRecordIService {
public class StopRecordService {

@Autowired @Autowired
private InspectionMapper inspectionMapper; private InspectionMapper inspectionMapper;


private RestTemplate restTemplate; private RestTemplate restTemplate;


public JsonResult stopRecord(String msgId) { 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); log.info("调用dsp平台,停止录制接口,url:{}", url);
JsonResult jsonResult;
log.info("调用dsp平台,停止录制接口,jsonObject:{}", jsonObject);

ResponseEntity<JsonResult> response;
try { try {
jsonResult = restTemplate.getForObject(url, JsonResult.class);
response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class);
} catch (Exception e) { } 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; return jsonResult;
} }

+ 25
- 5
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/DspCallbackServiceTest.java Ver arquivo

package com.tuoheng.admin.service; package com.tuoheng.admin.service;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest; import com.tuoheng.admin.entity.request.inspection.MissionStatusRequest;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest; 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 lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
private IDspCallbackService dspCallbackService; private IDspCallbackService dspCallbackService;


@Autowired @Autowired
private StartRecordIService startRecordIService;
private StartRecordService startRecordService;

@Autowired
private StopRecordService stopRecordService;

@Autowired
private QueryRecordService queryRecordService;


@Test @Test
public void testGetOneById() { public void testGetOneById() {
MissionStatusRequest request = new MissionStatusRequest(); MissionStatusRequest request = new MissionStatusRequest();
request.setRequestId("2199124367dd36d6c1d99d7b15d38c3b"); request.setRequestId("2199124367dd36d6c1d99d7b15d38c3b");
request.setPullUrl("https://live.play.t-aaron.com/live/test21.flv"); 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));
} }
} }

Carregando…
Cancelar
Salvar