Просмотр исходного кода

修改调用dspdiam

pull/88/head
wanjing 10 месяцев назад
Родитель
Сommit
937e130190
13 измененных файлов: 416 добавлений и 190 удалений
  1. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java
  2. +12
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/callback/DspCallbackController.java
  3. +54
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/third/DspRecordingCallbackRequest.java
  4. +4
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java
  5. +10
    -180
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspCallbackServiceImpl.java
  6. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspCallbackService.java
  7. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartRecordService.java
  8. +220
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/callback/DspQuestionCallbackService.java
  9. +91
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/callback/DspRecordingCallbackService.java
  10. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/resources/application-dev.yml
  11. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml
  12. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/resources/application-prod.yml
  13. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/resources/application-test.yml

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java Просмотреть файл

@@ -120,4 +120,14 @@ public interface SystemConstant {
*/
String DSP_QUERY_RECORD = "/api/web/screen/recording/video/url/";

/**
* Dsp平台,回调问题信息
*/
String DSP_CALLBACK_QUESTION_FILE = "/question";

/**
* Dsp平台,回调录制信息
*/
String DSP_CALLBACK_RECORDING = "/recording";

}

+ 12
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/callback/DspCallbackController.java Просмотреть файл

@@ -1,6 +1,7 @@
package com.tuoheng.admin.controller.callback;

import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.entity.request.third.DspRecordingCallbackRequest;
import com.tuoheng.admin.service.third.dsp.IDspCallbackService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,11 +30,21 @@ public class DspCallbackController {
* @param dspCallbackRequest 回调请求体
* @return JsonResult
*/
@PostMapping("/{requestId}")
@PostMapping("/question/{requestId}")
public JsonResult callback(@Valid @Pattern(regexp = "^[a-zA-Z0-9]{0,36}$")
@NotBlank @PathVariable String requestId,
@Valid @RequestBody DspCallbackRequest dspCallbackRequest) {
return dspCallbackService.saveCallbackData(requestId, dspCallbackRequest);
}

/**
* 视频地址回调接口
*
* @param request 回调请求体
* @return JsonResult
*/
@PostMapping("/recording")
public JsonResult recordingCallBack(@Valid @RequestBody DspRecordingCallbackRequest request) {
return dspCallbackService.recordingCallbackData(request);
}
}

+ 54
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/third/DspRecordingCallbackRequest.java Просмотреть файл

@@ -0,0 +1,54 @@
package com.tuoheng.admin.entity.request.third;
import lombok.Getter;
import lombok.Setter;
/**
* 录制回调
*
* @author chenyukun
*/
@Setter
@Getter
public class DspRecordingCallbackRequest {
/**
* 请求id
*/
private String requestId;
/**
* 状态 5:待执行 10:执行中 15:完成 20:超时 25:失败
*/
private Integer status;
/**
* 录制状态 录制状态 0:初始化状态 5:待录制 10:重试中 15:录制中 20:录制完成 25:录制超时 30:录制失败
*/
private Integer recordingStatus;
/**
* 异常编号
*/
private String errorCode;
/**
* 异常描述
*/
private String errorMsg;
/**
* 进度
*/
private Double process;
/**
* 录屏视频地址
*/
private String recordingVideoUrl;
/**
* 当前时间
*/
private String currentTime;
}

+ 4
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java Просмотреть файл

@@ -45,6 +45,9 @@ public class UpdateFlightStatusService {
private IDspService dspService;

public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) {
// 处理通道数据
this.liveChannelHandle(inspection, missionStatusRequest);

Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspection.getId());
JsonResult result = dspService.startRecord(missionStatusRequest);
@@ -60,7 +63,7 @@ public class UpdateFlightStatusService {

return result;
}
log.info("调用DSP开始录制, 返回:result={}", JacksonUtil.obj2StringPretty(result));
log.info("调用DSP开始录制, 返回:result={}", result);

DspCallbackRecordVo vo = (DspCallbackRecordVo) result.getData();

@@ -77,9 +80,6 @@ public class UpdateFlightStatusService {
}
log.info("修改inspection status 结束");

// 处理通道数据
this.liveChannelHandle(inspection, missionStatusRequest);

// 将请求id和业务id消息存入数据库,用于监听获取任务信息
this.businessHandle(inspection, vo);


+ 10
- 180
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspCallbackServiceImpl.java Просмотреть файл

@@ -1,28 +1,13 @@
package com.tuoheng.admin.service.third.dsp;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.domain.*;
import com.tuoheng.admin.enums.*;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.entity.request.third.QuestionFile;
import com.tuoheng.admin.service.inspection.update.flyer.DeliverStreamingService;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.*;
import com.tuoheng.admin.entity.request.third.DspRecordingCallbackRequest;
import com.tuoheng.admin.service.third.dsp.callback.DspQuestionCallbackService;
import com.tuoheng.admin.service.third.dsp.callback.DspRecordingCallbackService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* DSP回调 服务实现类
@@ -35,22 +20,10 @@ import java.util.stream.Collectors;
public class DspCallbackServiceImpl implements IDspCallbackService {

@Autowired
private BusinessMapper businessMapper;

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private FlightDataMapper flightDataMapper;

@Autowired
private QuestionTypeMapper questionTypeMapper;

@Autowired
private LiveChannelMapper liveChannelMapper;
private DspQuestionCallbackService dspQuestionCallbackService;

@Autowired
private DeliverStreamingService deliverStreamingService;
private DspRecordingCallbackService dspRecordingCallbackService;

/**
* 保存DSP回调数据
@@ -61,156 +34,13 @@ public class DspCallbackServiceImpl implements IDspCallbackService {
*/
@Override
public JsonResult saveCallbackData(String requestId, DspCallbackRequest dspCallbackRequest) {
log.info("DSP服务回调地址接收成功, requestId:{}, callbackRequest:{}", requestId, JacksonUtil.obj2StringPretty(dspCallbackRequest));
log.info("以下为打印的回调参数");
log.info("requestId为:{}", requestId);
log.info(JSON.toJSONString(dspCallbackRequest));

// 查询业务表数据
Business business = businessMapper.selectOne(new LambdaQueryWrapper<Business>()
.eq(Business::getMsgId, requestId)
.eq(Business::getType, 1)
.last("limit 1"));
if (StringUtils.isNull(business)) {
log.info("业务关系数据不存在,requestId:{}", requestId);
throw new ServiceException(0, "业务数据不存在");
}
if (StringUtils.isNull(business.getTypeId())) {
log.info("业务关系数据,巡检任务ID不存在,typeId:{}", business.getTypeId());
throw new ServiceException(0, "业务数据中巡检任务ID不存在");
}
log.info("业务关系数据, business:{}", business);

// 查询任务
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getId, business.getTypeId())
.eq(Inspection::getTenantId, business.getTenantId()));
if (ObjectUtil.isNull(inspection)) {
log.info("任务不存在");
throw new ServiceException(0, "巡检任务不存在");
}
// 巡检任务ID
String inspectionId = inspection.getId();
log.info("巡检任务查询成功,分析状态为:{}", dspCallbackRequest.getAnalyseStatus());
// 分析状态处理: 5:waiting(等待)、10:running(分析中)、15:success(分析完成)、20:timeout(成功超时)、25:failed(分析失败)
if (dspCallbackRequest.getAnalyseStatus().equals(5)) {
// 等待
inspection.setAnalyseStatus(2);
} else if (dspCallbackRequest.getAnalyseStatus().equals(10)) {
// 分析中
inspection.setAnalyseStatus(3);
} else if (dspCallbackRequest.getAnalyseStatus().equals(15)) {
// 分析完成
inspection.setAnalyseStatus(4);
} else if (dspCallbackRequest.getAnalyseStatus().equals(20)) {
// 成功超时
inspection.setAnalyseStatus(5);
} else if (dspCallbackRequest.getAnalyseStatus().equals(25)) {
// 分析失败
inspection.setAnalyseStatus(6);
}
// 分析进度
log.info("巡检任务查询成功,分析进度为:{}", dspCallbackRequest.getProgress());
inspection.setProgressbar(dspCallbackRequest.getProgress());
// 视频处理
if (dspCallbackRequest.getType().equals(1)) {
// 实时直播
log.info("实时直播视频处理");
log.info("实时直播视频,原视频地址:{}", dspCallbackRequest.getVideoUrl());
log.info("实时直播视频,分析后视频地址:{}", dspCallbackRequest.getAiVideoUrl());
if (StringUtils.isNotBlank(dspCallbackRequest.getVideoUrl())) {
inspection.setVideoUrl(StringUtils.removeHost(dspCallbackRequest.getVideoUrl(), CommonConfig.videoURL));
}
if (StringUtils.isNotBlank(dspCallbackRequest.getAiVideoUrl())) {
inspection.setAiVideoUrl(StringUtils.removeHost(dspCallbackRequest.getAiVideoUrl(), CommonConfig.videoURL));
}
} else if (dspCallbackRequest.getType().equals(2)) {
// 离线识别
log.info("离线检测视频处理");
log.info("离线检测视频,分析后视频地址:{}", dspCallbackRequest.getAiVideoUrl());
if (StringUtils.isNotBlank(dspCallbackRequest.getAiVideoUrl())) {
inspection.setAiVideoUrl(StringUtils.removeHost(dspCallbackRequest.getAiVideoUrl(), CommonConfig.videoURL));
}
}
inspection.setUpdateTime(DateUtils.now());
inspectionMapper.updateByPrimaryKey(inspection);
log.info("巡检任务状态更新成功");

log.info("巡检任务分析问题图片处理开始,此处图片数量为:{}张", StringUtils.isNull(dspCallbackRequest.getQuestionFiles()) ? 0 : dspCallbackRequest.getQuestionFiles().size());

// 分析处理图片并入库
log.info("以下为本地问题图片信息:");
log.info(JSON.toJSONString(dspCallbackRequest.getQuestionFiles()));
List<QuestionFile> questionFiles = dspCallbackRequest.getQuestionFiles();
if (!CollectionUtils.isEmpty(questionFiles)) {
log.info("问题图片处理开始, 图片数量:{}", questionFiles.size());
// 坐标
boolean online_condition = AiAnalyseTypeEnum.ONLINE.getCode() == inspection.getIsLive();
boolean offline_condition = AiAnalyseTypeEnum.OFFLINE.getCode() == inspection.getIsLive();
log.info("在线:{}, 离线:{}", online_condition, offline_condition);
List<FlightData> flightDataList = flightDataMapper.selectList(new LambdaQueryWrapper<FlightData>()
.eq(FlightData::getInspectionId, business.getTypeId())
.notLike(online_condition, FlightData::getLng, "E-")
.notLike(online_condition, FlightData::getLng, "0.0")
.notLike(online_condition, FlightData::getLat, "E-")
.notLike(online_condition, FlightData::getLat, "0.0")
.orderByDesc(FlightData::getTimestamp));
if (!CollectionUtils.isEmpty(flightDataList)) {
log.info("飞行坐标大小:{}", flightDataList.size());
}
}
//释放通道
if (4 == inspection.getAnalyseStatus() || 5 == inspection.getAnalyseStatus() || 6 == inspection.getAnalyseStatus()) {

LiveChannel liveChannel = liveChannelMapper.selectOne(Wrappers.<LiveChannel>lambdaQuery()
.eq(LiveChannel::getInspectionId, inspectionId)
.eq(LiveChannel::getMark, 1));
// 释放小程序选择的通道
if(null != liveChannel)
deliverStreamingService.deliver(liveChannel.getChannelCode());
}

return JsonResult.success();
return dspQuestionCallbackService.callback(requestId, dspCallbackRequest);
}

/**
* 根据问题类型封装成map
* @return
*/
private Map<String, QuestionType> getStringQuestionTypeMap() {
List<QuestionType> questionTypeList = questionTypeMapper.selectList(Wrappers.<QuestionType>lambdaQuery()
.eq(QuestionType::getMark, MarkEnum.VALID.getCode()));
Map<String, QuestionType> questionTypeMap = new HashMap<>();
for (QuestionType type : questionTypeList) {
questionTypeMap.put(type.getCode(), type);
}
return questionTypeMap;
@Override
public JsonResult recordingCallbackData(DspRecordingCallbackRequest request) {
return dspRecordingCallbackService.callback(request);
}

/**
* 获取飞行坐标
*
* @param flightDataList 飞行坐标集合
* @param time 当前时间
* @return 当前飞行对象
*/
private FlightData getFlightDataByTime(List<FlightData> flightDataList, long time) {
if (CollectionUtils.isEmpty(flightDataList)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取无人机飞行坐标失败!");
}
List<FlightData> flightData = flightDataList.stream().filter(data -> {
try {
return Long.valueOf(data.getTimestamp()) <= time;
} catch (Exception e) {
log.error("获取飞行数据异常:", e);
log.error("批量插入问题图片数据:{}", JacksonUtil.obj2StringPretty(data));
return false;
}
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(flightData)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取无人机飞行坐标失败!");
}
return flightData.get(0);
}

}

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspCallbackService.java Просмотреть файл

@@ -1,6 +1,7 @@
package com.tuoheng.admin.service.third.dsp;

import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.entity.request.third.DspRecordingCallbackRequest;
import com.tuoheng.common.core.utils.JsonResult;

/**
@@ -10,6 +11,7 @@ import com.tuoheng.common.core.utils.JsonResult;
* @since 2021-09-02
*/
public interface IDspCallbackService {

/**
* 回调数据入库
*
@@ -18,4 +20,12 @@ public interface IDspCallbackService {
* @return
*/
JsonResult saveCallbackData(String requestId, DspCallbackRequest dspCallbackRequest);

/**
* 回调数据入库
*
* @param request 回调请求体
* @return
*/
JsonResult recordingCallbackData(DspRecordingCallbackRequest request);
}

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/StartRecordService.java Просмотреть файл

@@ -44,7 +44,7 @@ public class StartRecordService {
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId", request.getRequestId());
jsonObject.put("pullUrl", request.getPullUrl());
jsonObject.put("callbackUrl", dspCallbackUrl);
jsonObject.put("callbackUrl", dspCallbackUrl + SystemConstant.DSP_CALLBACK_RECORDING);

log.info("调用dsp平台,开始录制接口,url:{}", url);
log.info("调用dsp平台,开始录制接口,jsonObject:{}", jsonObject);

+ 220
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/callback/DspQuestionCallbackService.java Просмотреть файл

@@ -0,0 +1,220 @@
package com.tuoheng.admin.service.third.dsp.callback;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.domain.*;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.entity.request.third.QuestionFile;
import com.tuoheng.admin.enums.AiAnalyseTypeEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.service.inspection.update.flyer.DeliverStreamingService;
import com.tuoheng.admin.service.third.dsp.IDspCallbackService;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
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.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* DSP回调 服务实现类
*
* @author WangHaoran
* @since 2021-09-01
*/
@Slf4j
@Service
public class DspQuestionCallbackService {

@Autowired
private BusinessMapper businessMapper;

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private FlightDataMapper flightDataMapper;

@Autowired
private QuestionTypeMapper questionTypeMapper;

@Autowired
private LiveChannelMapper liveChannelMapper;

@Autowired
private DeliverStreamingService deliverStreamingService;

/**
* 保存DSP回调数据
*
* @param requestId 请求id
* @param dspCallbackRequest 回调请求体
* @return
*/
public JsonResult callback(String requestId, DspCallbackRequest dspCallbackRequest) {
log.info("DSP服务回调地址接收成功, requestId:{}, callbackRequest:{}", requestId, JacksonUtil.obj2StringPretty(dspCallbackRequest));
log.info("以下为打印的回调参数");
log.info("requestId为:{}", requestId);
log.info(JSON.toJSONString(dspCallbackRequest));

// 查询业务表数据
Business business = businessMapper.selectOne(new LambdaQueryWrapper<Business>()
.eq(Business::getMsgId, requestId)
.eq(Business::getType, 1)
.last("limit 1"));
if (StringUtils.isNull(business)) {
log.info("业务关系数据不存在,requestId:{}", requestId);
throw new ServiceException(0, "业务数据不存在");
}
if (StringUtils.isNull(business.getTypeId())) {
log.info("业务关系数据,巡检任务ID不存在,typeId:{}", business.getTypeId());
throw new ServiceException(0, "业务数据中巡检任务ID不存在");
}
log.info("业务关系数据, business:{}", business);

// 查询任务
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getId, business.getTypeId())
.eq(Inspection::getTenantId, business.getTenantId()));
if (ObjectUtil.isNull(inspection)) {
log.info("任务不存在");
throw new ServiceException(0, "巡检任务不存在");
}
// 巡检任务ID
String inspectionId = inspection.getId();
log.info("巡检任务查询成功,分析状态为:{}", dspCallbackRequest.getAnalyseStatus());
// 分析状态处理: 5:waiting(等待)、10:running(分析中)、15:success(分析完成)、20:timeout(成功超时)、25:failed(分析失败)
if (dspCallbackRequest.getAnalyseStatus().equals(5)) {
// 等待
inspection.setAnalyseStatus(2);
} else if (dspCallbackRequest.getAnalyseStatus().equals(10)) {
// 分析中
inspection.setAnalyseStatus(3);
} else if (dspCallbackRequest.getAnalyseStatus().equals(15)) {
// 分析完成
inspection.setAnalyseStatus(4);
} else if (dspCallbackRequest.getAnalyseStatus().equals(20)) {
// 成功超时
inspection.setAnalyseStatus(5);
} else if (dspCallbackRequest.getAnalyseStatus().equals(25)) {
// 分析失败
inspection.setAnalyseStatus(6);
}
// 分析进度
log.info("巡检任务查询成功,分析进度为:{}", dspCallbackRequest.getProgress());
inspection.setProgressbar(dspCallbackRequest.getProgress());
// 视频处理
if (dspCallbackRequest.getType().equals(1)) {
// 实时直播
log.info("实时直播视频处理");
log.info("实时直播视频,原视频地址:{}", dspCallbackRequest.getVideoUrl());
log.info("实时直播视频,分析后视频地址:{}", dspCallbackRequest.getAiVideoUrl());
if (StringUtils.isNotBlank(dspCallbackRequest.getVideoUrl())) {
inspection.setVideoUrl(StringUtils.removeHost(dspCallbackRequest.getVideoUrl(), CommonConfig.videoURL));
}
if (StringUtils.isNotBlank(dspCallbackRequest.getAiVideoUrl())) {
inspection.setAiVideoUrl(StringUtils.removeHost(dspCallbackRequest.getAiVideoUrl(), CommonConfig.videoURL));
}
} else if (dspCallbackRequest.getType().equals(2)) {
// 离线识别
log.info("离线检测视频处理");
log.info("离线检测视频,分析后视频地址:{}", dspCallbackRequest.getAiVideoUrl());
if (StringUtils.isNotBlank(dspCallbackRequest.getAiVideoUrl())) {
inspection.setAiVideoUrl(StringUtils.removeHost(dspCallbackRequest.getAiVideoUrl(), CommonConfig.videoURL));
}
}
inspection.setUpdateTime(DateUtils.now());
inspectionMapper.updateByPrimaryKey(inspection);
log.info("巡检任务状态更新成功");

log.info("巡检任务分析问题图片处理开始,此处图片数量为:{}张", StringUtils.isNull(dspCallbackRequest.getQuestionFiles()) ? 0 : dspCallbackRequest.getQuestionFiles().size());

// 分析处理图片并入库
log.info("以下为本地问题图片信息:");
log.info(JSON.toJSONString(dspCallbackRequest.getQuestionFiles()));
List<QuestionFile> questionFiles = dspCallbackRequest.getQuestionFiles();
if (!CollectionUtils.isEmpty(questionFiles)) {
log.info("问题图片处理开始, 图片数量:{}", questionFiles.size());
// 坐标
boolean online_condition = AiAnalyseTypeEnum.ONLINE.getCode() == inspection.getIsLive();
boolean offline_condition = AiAnalyseTypeEnum.OFFLINE.getCode() == inspection.getIsLive();
log.info("在线:{}, 离线:{}", online_condition, offline_condition);
List<FlightData> flightDataList = flightDataMapper.selectList(new LambdaQueryWrapper<FlightData>()
.eq(FlightData::getInspectionId, business.getTypeId())
.notLike(online_condition, FlightData::getLng, "E-")
.notLike(online_condition, FlightData::getLng, "0.0")
.notLike(online_condition, FlightData::getLat, "E-")
.notLike(online_condition, FlightData::getLat, "0.0")
.orderByDesc(FlightData::getTimestamp));
if (!CollectionUtils.isEmpty(flightDataList)) {
log.info("飞行坐标大小:{}", flightDataList.size());
}
}
//释放通道
if (4 == inspection.getAnalyseStatus() || 5 == inspection.getAnalyseStatus() || 6 == inspection.getAnalyseStatus()) {

LiveChannel liveChannel = liveChannelMapper.selectOne(Wrappers.<LiveChannel>lambdaQuery()
.eq(LiveChannel::getInspectionId, inspectionId)
.eq(LiveChannel::getMark, 1));
// 释放小程序选择的通道
if(null != liveChannel)
deliverStreamingService.deliver(liveChannel.getChannelCode());
}

return JsonResult.success();
}

/**
* 根据问题类型封装成map
* @return
*/
private Map<String, QuestionType> getStringQuestionTypeMap() {
List<QuestionType> questionTypeList = questionTypeMapper.selectList(Wrappers.<QuestionType>lambdaQuery()
.eq(QuestionType::getMark, MarkEnum.VALID.getCode()));
Map<String, QuestionType> questionTypeMap = new HashMap<>();
for (QuestionType type : questionTypeList) {
questionTypeMap.put(type.getCode(), type);
}
return questionTypeMap;
}

/**
* 获取飞行坐标
*
* @param flightDataList 飞行坐标集合
* @param time 当前时间
* @return 当前飞行对象
*/
private FlightData getFlightDataByTime(List<FlightData> flightDataList, long time) {
if (CollectionUtils.isEmpty(flightDataList)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取无人机飞行坐标失败!");
}
List<FlightData> flightData = flightDataList.stream().filter(data -> {
try {
return Long.valueOf(data.getTimestamp()) <= time;
} catch (Exception e) {
log.error("获取飞行数据异常:", e);
log.error("批量插入问题图片数据:{}", JacksonUtil.obj2StringPretty(data));
return false;
}
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(flightData)) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取无人机飞行坐标失败!");
}
return flightData.get(0);
}

}

+ 91
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/callback/DspRecordingCallbackService.java Просмотреть файл

@@ -0,0 +1,91 @@
package com.tuoheng.admin.service.third.dsp.callback;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.domain.*;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.entity.request.third.DspRecordingCallbackRequest;
import com.tuoheng.admin.entity.request.third.QuestionFile;
import com.tuoheng.admin.enums.AiAnalyseTypeEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.service.inspection.update.flyer.DeliverStreamingService;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
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.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* DSP回调 服务实现类
*
* @author WangHaoran
* @since 2021-09-01
*/
@Slf4j
@Service
public class DspRecordingCallbackService {

@Autowired
private BusinessMapper businessMapper;

@Autowired
private InspectionMapper inspectionMapper;

/**
* 保存DSP回调数据
*
* @param request 回调请求体
* @return
*/
public JsonResult callback(DspRecordingCallbackRequest request) {
log.info("DSP服务回调地址接收成功, request:{}", request);

// 查询业务表数据
Business business = businessMapper.selectOne(new LambdaQueryWrapper<Business>()
.eq(Business::getMsgId, request.getRequestId())
.eq(Business::getType, 1)
.last("limit 1"));
if (StringUtils.isNull(business)) {
log.info("业务关系数据不存在,requestId:{}", request.getRequestId());
return JsonResult.error("业务数据不存在");
}
if (StringUtils.isNull(business.getTypeId())) {
log.info("业务关系数据,巡检任务ID不存在,typeId:{}", business.getTypeId());
return JsonResult.error("业务关系数据,巡检任务ID不存在");
}
log.info("业务关系数据, business:{}", business);

// 查询任务
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getId, business.getTypeId())
.eq(Inspection::getTenantId, business.getTenantId()));
if (ObjectUtil.isNull(inspection)) {
log.info("任务不存在");
return JsonResult.error("巡检任务不存在");
}
inspection.setVideoUrl(request.getRecordingVideoUrl());

Integer count = inspectionMapper.update(inspection);
if (count <= 0) {
log.info("dsp回调,修改视频地址失败");
} else {
log.info("dsp回调,修改视频地址成功");
}
return JsonResult.success();
}

}

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/resources/application-dev.yml Просмотреть файл

@@ -153,7 +153,7 @@ tuoheng:
# DSP服务域名
dsp-domain-url: http://192.168.11.11:7011
# DSP回调地址
dsp-callback-url: https://192.168.11.11:9130/dsp/callback/{requestId}
dsp-callback-url: https://192.168.11.11:9130/dsp/callback
#飞手平台地址
pilot-url: http://192.168.11.11:7011/pilot/web/
#airport配置地址

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml Просмотреть файл

@@ -162,7 +162,7 @@ tuoheng:
# DSP服务域名
dsp-domain-url: http://192.168.11.241:7011
# DSP回调地址
dsp-callback-url: https://127.0.0.1:9120/dsp/callback/{requestId}
dsp-callback-url: https://127.0.0.1:9120/dsp/callback
#飞手平台地址
pilot-url: http://192.168.11.241:7011/pilot/web/
#airport配置地址

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/resources/application-prod.yml Просмотреть файл

@@ -154,7 +154,7 @@ tuoheng:
# DSP服务域名
dsp-domain-url: https://dsp-portal.t-aaron.com
# DSP回调地址
dsp-callback-url: https://airmonitor.t-aaron.com/airmonitor/admin/dsp/callback/{requestId}
dsp-callback-url: https://airmonitor.t-aaron.com/airmonitor/admin/dsp/callback
#飞手平台地址
pilot-url: https://pilot.t-aaron.com/pilot/web/
#airport配置地址

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/resources/application-test.yml Просмотреть файл

@@ -154,7 +154,7 @@ tuoheng:
# DSP服务域名
dsp-domain-url: http://172.15.1.11:7011
# DSP回调地址
dsp-callback-url: https://airmonitor-test.t-aaron.com/airmonitor/admin/dsp/callback/{requestId}
dsp-callback-url: https://airmonitor-test.t-aaron.com/airmonitor/admin/dsp/callback
#飞手平台地址
pilot-url: http://172.15.1.11:7011/pilot/web/
#airport配置地址

Загрузка…
Отмена
Сохранить