Browse Source

新增被硬件调用,存任务状态接口

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
8f504e36a4
19 changed files with 958 additions and 14 deletions
  1. +11
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/InspectionController.java
  2. +33
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Business.java
  3. +42
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/AiAnalyseStatusEnum.java
  4. +23
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/AirPortTaskStatusEnum.java
  5. +24
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/MarkTypeEnum.java
  6. +31
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/TaskStatusEnum.java
  7. +51
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/EditInspectionStatusCodeEnum.java
  8. +14
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/BusinessMapper.java
  9. +49
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/MissionStatusRequest.java
  10. +6
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/IInspectionService.java
  11. +13
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/InspectionServiceImpl.java
  12. +159
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java
  13. +100
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateInspectionStatusService.java
  14. +156
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java
  15. +88
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java
  16. +9
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspService.java
  17. +19
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/AirWeatherUtil.java
  18. +87
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/AirWeatherVO.java
  19. +43
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/DspCallbackVo.java

+ 11
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/InspectionController.java View File

@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.dto.InspectionDto;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.query.InspectionFileQuery;
import com.tuoheng.admin.request.inspection.AddInspectionRequest;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.request.inspection.InspectionRequest;
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest;
import com.tuoheng.admin.request.inspection.*;
import com.tuoheng.admin.service.inspection.IInspectionService;
import com.tuoheng.common.core.common.OperationEnum;
import com.tuoheng.common.core.utils.JsonResult;
@@ -128,6 +125,16 @@ public class InspectionController {
return iInspectionService.getFlightDataByInspectionId(inspectionId);
}

/**
* 被硬件调用,存任务状态
*/
@PutMapping("/status")
public JsonResult updateStatus(@RequestBody @Valid MissionStatusRequest missionStatusRequest) {
log.info("被硬件调用,存任务状态:{}", JSONObject.toJSONString(missionStatusRequest));
return iInspectionService.updateStatus(missionStatusRequest);
}


/**
* 被硬件调用,存飞行轨迹
*/

+ 33
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Business.java View File

@@ -0,0 +1,33 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("th_business")
public class Business extends BaseEntity {
/**
* 消息id
*/
private String msgId;

/**
* 类型:1巡检任务
*/
private Integer type;

/**
* 类型ID(type对应类型对应的业务ID)
*/
private String typeId;

/**
* 租户id
*/
private String tenantId;
}

+ 42
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/AiAnalyseStatusEnum.java View File

@@ -0,0 +1,42 @@
package com.tuoheng.admin.enums;

import lombok.Getter;

/**
* Ai分析状态
*/
public enum AiAnalyseStatusEnum {
UPLOADED(1,"uploaded"),

WAITING(2,"waiting"),

RUNNING(3,"running"),

SUCCESS(4,"success"),

SUCCESS_TIMEOUT(5,"success_timeout"),

FAILED(6,"failed"),

DEFAULT(0,"default");

AiAnalyseStatusEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;

public static AiAnalyseStatusEnum getByDesc(String description){
for (AiAnalyseStatusEnum analyseStatusEnum : values()) {
if(analyseStatusEnum.getDescription().equals(description)){
return analyseStatusEnum;
}
}
return null;
}
}

+ 23
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/AirPortTaskStatusEnum.java View File

@@ -0,0 +1,23 @@
package com.tuoheng.admin.enums;

import lombok.Getter;

/**
* 任务状态枚举
*/
public enum AirPortTaskStatusEnum {
//任务状态1待执行 2执行中
WAIT(1,"待执行"),
FLIGHT(2,"执行中");

AirPortTaskStatusEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;
}

+ 24
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/MarkTypeEnum.java View File

@@ -0,0 +1,24 @@
package com.tuoheng.admin.enums;

import lombok.Getter;

/**
* 逻辑删除标记类型
* @author chenyukun
*/
public enum MarkTypeEnum {
VALID(1,"有效"),

NOTVALID(0,"失效");

MarkTypeEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;
}

+ 31
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/TaskStatusEnum.java View File

@@ -0,0 +1,31 @@
package com.tuoheng.admin.enums;

import lombok.Getter;

/**
* 任务状态枚举
*/
public enum TaskStatusEnum {
NOTREVIEWED(1,"任务待审核"),
TOFLY(5,"任务待飞行"),
INFLIGHT(10,"任务飞行中"),
FAIL(12,"任务执行失败"),
COMPLETE(15,"任务飞行完成(图片待审核)"),
AUDITFAILED(20,"审核未通过"),
REVIEWED(25,"图片已审核(问题待分派)"),
PENDING(30,"问题待处理"),
PROCESSING(35,"问题处理中"),
PROCESSED(40,"问题已处理(报告待生成)"),
GENERATED(45,"报告已生成");

TaskStatusEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;
}

+ 51
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/EditInspectionStatusCodeEnum.java View File

@@ -0,0 +1,51 @@
package com.tuoheng.admin.enums.code.inspection;

/**
* 修改任务状态信息返回码
* 模块代码:23(任务管理)
* 接口代码:09 (修改任务状态)
*
* @author wanjing
* @team tuoheng
* @date 2022-12-22
*/
public enum EditInspectionStatusCodeEnum {

EDIT_IS_FAILED(1230900, "修改任务失败"),
INSPECTION_IS_NOT_EXIST(1230901, "巡检任务不存在,请先创建巡检任务!"),
TASK_NOT_STATUS(1230902, "飞行状态出错!"),
TASK_ANALYSIS_FAILED(1230903, "任务分析失败!"),
GET_WEATHER_FAILED(1230904, "获取天气信息失败,请重试!");

/**
* 错误码
*/
private int code;

/**
* 错误信息
*/
private String msg;

EditInspectionStatusCodeEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

}

+ 14
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/BusinessMapper.java View File

@@ -0,0 +1,14 @@
package com.tuoheng.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.admin.entity.Business;

/**
* kafka对应发送消息消息与任务id绑定
*
* @author 拓恒
* @since 2022-03-09
*/
public interface BusinessMapper extends BaseMapper<Business> {

}

+ 49
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/MissionStatusRequest.java View File

@@ -0,0 +1,49 @@
package com.tuoheng.admin.request.inspection;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
* 巡检任务 新增或修改请求参数
* @author: qiujinyang
* @date: 2021/9/7
*/
@Data
public class MissionStatusRequest implements Serializable {

private static final long serialVersionUID = 1L;

/**
* 巡检任务ID
*/
@NotNull(message = "巡检任务ID不能为空!")
private Integer id;

/**
* 视频推流地址
*/
private String pushUrl;

/**
* 视频拉流地址
*/
private String pullUrl;

/**
* 任务状态1待执行 2执行中
*/
private Integer status;

/**
* 任务里程
*/
private String mileage;

/**
* 请求ID
*/
private String requestId;

}

+ 6
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/IInspectionService.java View File

@@ -4,10 +4,7 @@ import com.tuoheng.admin.dto.InspectionDto;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.query.InspectionFileQuery;
import com.tuoheng.admin.request.inspection.AddInspectionRequest;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.request.inspection.InspectionRequest;
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest;
import com.tuoheng.admin.request.inspection.*;
import com.tuoheng.common.core.common.OperationEnum;
import com.tuoheng.common.core.utils.JsonResult;

@@ -116,6 +113,11 @@ public interface IInspectionService {
*/
JsonResult getNewInspectionList();

/**
* 被硬件调用,存任务状态
*/
JsonResult updateStatus(MissionStatusRequest missionStatusRequest);

/**
* 被硬件调用,存飞行轨迹
* @param inspectionRequest

+ 13
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/InspectionServiceImpl.java View File

@@ -3,17 +3,14 @@ package com.tuoheng.admin.service.inspection;
import com.tuoheng.admin.dto.InspectionDto;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.query.InspectionFileQuery;
import com.tuoheng.admin.request.inspection.AddInspectionRequest;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.request.inspection.InspectionRequest;
import com.tuoheng.admin.request.inspection.QueryInspectionPageListRequest;
import com.tuoheng.admin.request.inspection.*;
import com.tuoheng.admin.service.inspection.add.AddInspectionService;
import com.tuoheng.admin.service.inspection.execute.ExecuteInspectionService;
import com.tuoheng.admin.service.inspection.resubmit.ResubmitInspectionService;
import com.tuoheng.admin.service.inspection.delete.DeleteInspectionService;
import com.tuoheng.admin.service.inspection.query.*;
import com.tuoheng.admin.service.inspection.update.UpdateInspectionService;
import com.tuoheng.admin.service.inspection.update.status.UpdateInspectionStatusService;
import com.tuoheng.common.core.common.OperationEnum;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
@@ -74,8 +71,10 @@ public class InspectionServiceImpl implements IInspectionService {
private QueryNewInspectionListService queryNewInspectionListService;

@Autowired
private QueryFlightDataTrackService queryFlightDataTrackService;
private UpdateInspectionStatusService updateInspectionStatusService;

@Autowired
private QueryFlightDataTrackService queryFlightDataTrackService;

/**
* 查询巡检任务分页分页列表
@@ -228,6 +227,14 @@ public class InspectionServiceImpl implements IInspectionService {
return queryNewInspectionListService.getList();
}

/**
* 被硬件调用,存任务状态
*/
@Override
public JsonResult updateStatus(MissionStatusRequest missionStatusRequest) {
return updateInspectionStatusService.updateStatus(missionStatusRequest);
}

/**
* 被硬件调用,存飞行轨迹
* @param inspectionRequest

+ 159
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateFlightStatusService.java View File

@@ -0,0 +1,159 @@
package com.tuoheng.admin.service.inspection.update.status;

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.MarkTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum;
import com.tuoheng.admin.mapper.BusinessMapper;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.LiveChannelMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.admin.service.third.dsp.IDspService;
import com.tuoheng.admin.vo.DspCallbackVo;
import com.tuoheng.common.core.utils.DateUtils;
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.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UpdateFlightStatusService {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private LiveChannelMapper liveChannelMapper;

@Autowired
private BusinessMapper businessMapper;

@Autowired
private IDspService dspService;

@Value("${tuoheng.dsp-callback-url:}")
private String dspCallbackUrl;

public JsonResult updateFlightStatus(Inspection inspection, MissionStatusRequest missionStatusRequest) {
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspection.getId());
JsonResult result = startAI(missionStatusRequest);

if (0 != result.getCode()) {
//如果调用DSP失败就直接失败!
log.info("修改任务状态业务接口:调用DSP数据失败:{}", result.getMsg());

inspectionUpdate.setStatus(TaskStatusEnum.FAIL.getCode());
inspectionMapper.updateById(inspectionUpdate);
return result;
}
JSONObject jsonObject = (JSONObject) result.getData();
DspCallbackVo dspCallbackVo = JSON.toJavaObject(jsonObject.getJSONObject("data"), DspCallbackVo.class);
log.info("dsp响应体:{}", JacksonUtil.obj2StringPretty(dspCallbackVo));

inspectionUpdate.setStatus(TaskStatusEnum.INFLIGHT.getCode());
inspectionMapper.updateById(inspectionUpdate);

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

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

return JsonResult.success();
}

private JsonResult startAI(MissionStatusRequest missionStatusRequest) {
//调用DSP接口
JSONObject request = new JSONObject();
JSONArray configList = new JSONArray();
JSONObject instConfigMode = new JSONObject();
instConfigMode.put("ename", "service_mode");
instConfigMode.put("evalue", "1");
configList.add(instConfigMode);
JSONObject instConfigUrl = new JSONObject();
instConfigUrl.put("ename", "callback_url");
instConfigUrl.put("evalue", dspCallbackUrl);
configList.add(instConfigUrl);
request.put("serviceInstConfigList", configList);

JSONArray reqList = new JSONArray();

JSONObject instReqUrlPush = new JSONObject();
instReqUrlPush.put("ename", "push_url");
instReqUrlPush.put("evalue", missionStatusRequest.getPushUrl());
reqList.add(instReqUrlPush);

JSONObject instReqUrlPull = new JSONObject();
instReqUrlPull.put("ename", "pull_url");
instReqUrlPull.put("evalue", missionStatusRequest.getPullUrl());
reqList.add(instReqUrlPull);

request.put("serviceInstReqList", reqList);
JSONObject responseJson = dspService.serviceInstApplication(request);
if (responseJson.getIntValue("code") == 0) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("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 void liveChannelHandle(Inspection inspection, DspCallbackVo dspCallbackVo) {
// 通道表新增
LiveChannel liveChannel = this.buildLiveChannel(inspection, dspCallbackVo);
// 查验是否存在
LiveChannel liveChannelQuery = liveChannelMapper.selectOne(new LambdaQueryWrapper<LiveChannel>()
.eq(LiveChannel::getInspectionId, inspection.getId())
.eq(LiveChannel::getMark, MarkTypeEnum.VALID.getCode()));
if (liveChannelQuery == null) {
// 添加通道使用记录
liveChannel.setCreateTime(DateUtils.now());
liveChannelMapper.insert(liveChannel);
} else {
// 更新通道使用记录
liveChannel.setId(liveChannelQuery.getId());
liveChannelMapper.updateById(liveChannel);
}
}

private LiveChannel buildLiveChannel(Inspection inspection, DspCallbackVo dspCallbackVo) {
LiveChannel liveChannel = new LiveChannel();
liveChannel.setTenantId(inspection.getTenantId());
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);
}
}

+ 100
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateInspectionStatusService.java View File

@@ -0,0 +1,100 @@
package com.tuoheng.admin.service.inspection.update.status;

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;
import com.tuoheng.admin.conver.InspectionConverMapper;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.AirPortTaskStatusEnum;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.enums.code.dept.AddDeptCodeEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionCodeEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.request.inspection.EditInspectionRequest;
import com.tuoheng.admin.request.inspection.MissionStatusRequest;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.DspCallbackVo;
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 java.util.List;

/**
* 修改任务状态业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2022-11-24
*/
@Slf4j
@Service
public class UpdateInspectionStatusService {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private UpdateFlightStatusService updateFlightStatusService;

@Autowired
private UpdateWaittStatusService updateWaittStatusService;

/**
* 添加任务
*
* @return
*/
public JsonResult updateStatus(MissionStatusRequest missionStatusRequest) {
log.info("进入修改任务状态业务接口");
String tenantId = CurrentUserUtil.getTenantId();
JsonResult result = this.check(tenantId, missionStatusRequest);
if (0 != result.getCode()) {
log.info("修改任务状态业务接口:校验失败:{}", result.getMsg());
return result;
}

Inspection inspection = (Inspection) result.getData();

if (AirPortTaskStatusEnum.FLIGHT.getCode() != missionStatusRequest.getStatus() && AirPortTaskStatusEnum.WAIT.getCode() == missionStatusRequest.getStatus()) {
return JsonResult.error(EditInspectionStatusCodeEnum.TASK_NOT_STATUS.getCode(), EditInspectionStatusCodeEnum.TASK_NOT_STATUS.getMsg());
}

if (AirPortTaskStatusEnum.FLIGHT.getCode() == missionStatusRequest.getStatus()) {
updateFlightStatusService.updateFlightStatus(inspection, missionStatusRequest);
} else if (AirPortTaskStatusEnum.WAIT.getCode() == missionStatusRequest.getStatus()) {
updateWaittStatusService.updateWaittStatus(inspection);
}

log.info("修改任务业务接口:修改任务成功:{}");
return JsonResult.success();
}

/**
* 检查参数
* @param tenantId
* @param missionStatusRequest
* @return
*/
private JsonResult check(String tenantId, MissionStatusRequest missionStatusRequest) {
//查询出对应的巡检任务
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>()
.eq(Inspection::getMark, MarkTypeEnum.VALID.getCode())
.eq(Inspection::getId, missionStatusRequest.getRequestId())
.eq(Inspection::getInspectionLine, missionStatusRequest.getId()));
if (ObjectUtil.isEmpty(inspection)) {
return JsonResult.error(EditInspectionStatusCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), EditInspectionStatusCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
}
return JsonResult.success(inspection);
}

}

+ 156
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/update/status/UpdateWaittStatusService.java View File

@@ -0,0 +1,156 @@
package com.tuoheng.admin.service.inspection.update.status;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.Business;
import com.tuoheng.admin.entity.FlightData;
import com.tuoheng.admin.entity.Inspection;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.enums.AiAnalyseStatusEnum;
import com.tuoheng.admin.enums.MarkTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionStatusCodeEnum;
import com.tuoheng.admin.mapper.BusinessMapper;
import com.tuoheng.admin.mapper.FlightDataMapper;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.service.third.dsp.IDspService;
import com.tuoheng.admin.utils.AirWeatherUtil;
import com.tuoheng.admin.vo.AirWeatherVO;
import com.tuoheng.common.core.utils.HttpUtils;
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 java.util.List;
import java.util.Objects;

@Slf4j
@Service
public class UpdateWaittStatusService {

@Autowired
private BusinessMapper businessMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private FlightDataMapper flightDataMapper;

@Autowired
private IDspService dspService;

public void updateWaittStatus(Inspection inspection) {
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspection.getId());
inspectionUpdate.setStatus(TaskStatusEnum.COMPLETE.getCode());

List<Business> businessList = businessMapper.selectList(new LambdaQueryWrapper<Business>()
.eq(Business::getTypeId, inspection.getId())
.eq(Business::getMark, MarkTypeEnum.VALID.getCode())
.orderByDesc(Business::getCreateTime));

if (CollectionUtil.isNotEmpty(businessList)) {
inspectionMapper.updateById(inspectionUpdate);
return;
}

//硬件停止后,停止AI分析
stopAI(businessList.get(0).getMsgId(), inspection.getId());

//获取天气信息
//查询业务对应的租户信息
Tenant tenant = tenantMapper.selectById(inspection.getTenantId());

JsonResult result = this.getWeather(tenant.getAirportUrl(), inspection.getAirportId());
if (0 != result.getCode()) {
log.info("修改任务状态业务接口:获取天气信息失败:{}", result.getMsg());
inspectionUpdate.setWeather("");
inspectionMapper.updateById(inspectionUpdate);
return;
}

AirWeatherVO weather = (AirWeatherVO) result.getData();
String weatherStr = AirWeatherUtil.getWeather(weather);
inspectionUpdate.setWeather(weatherStr);

Integer flightDataCount = flightDataMapper.selectCount(new LambdaQueryWrapper<FlightData>()
.eq(FlightData::getInspectionId, inspection.getId())
.eq(FlightData::getTenantId, inspection.getTenantId())
.eq(FlightData::getMark, MarkTypeEnum.VALID.getCode()));
if (flightDataCount > 0) {
int index = (int) Math.ceil((double) flightDataCount / 2);
FlightData flightData = flightDataMapper.selectOne(new LambdaQueryWrapper<FlightData>()
.eq(FlightData::getInspectionId, inspection.getId())
.eq(FlightData::getTenantId, inspection.getTenantId())
.eq(FlightData::getMark, MarkTypeEnum.VALID.getCode())
.orderByDesc(FlightData::getTimestamp)
.last("limit " + index + ",1"));
if (ObjectUtil.isNotNull(flightData)) {
inspectionUpdate.setFlyHeight(flightData.getUltrasonic());
}
}
inspectionMapper.updateById(inspectionUpdate);
}

private JsonResult stopAI(String msgId, String inspectionId) {
//任务调用完成之后,调用发送通道,请求DSP关闭请求
//调用DSP接口
JSONObject jsonObject = new JSONObject();
jsonObject.put("requestId", msgId);
JSONObject responseJson = new JSONObject();
Inspection inspectionUpdate = new Inspection();
inspectionUpdate.setId(inspectionId);
try {
responseJson = dspService.serviceStopApplication(jsonObject);
if (responseJson.getIntValue("code") == 0) {
if (responseJson.containsKey("data") && ObjectUtil.isNotEmpty(responseJson.get("data"))) {
String requestId = responseJson.getJSONObject("data").getString("requestId");
log.info("dsp实时调用响应requestId:{}", requestId);
} else {
log.info("dsp实时调用响应:{}", responseJson);
}
return JsonResult.success();
} else {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
}
inspectionMapper.updateById(inspectionUpdate);
} catch (Exception e) {
log.error("dsp实时调用失败:{}", responseJson);
inspectionUpdate.setAnalyseStatus(AiAnalyseStatusEnum.FAILED.getCode());
inspectionMapper.updateById(inspectionUpdate);
}
return JsonResult.success();
}

public JsonResult getWeather(String airportUrl, Integer airportId) {
String url = airportUrl + "/api/airportInterface/getWeather";
String param = "airportId=" + airportId;
String weatherStr = HttpUtils.sendGet(url, param);
JsonResult jsonResult;
try {
jsonResult = JacksonUtil.json2pojo(weatherStr, JsonResult.class);
if (ObjectUtil.isEmpty(jsonResult) || Objects.requireNonNull(jsonResult).getCode() != 0) {
return JsonResult.error(EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getCode(), EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getMsg());
}
if (ObjectUtil.isEmpty(jsonResult.getData())) {
return JsonResult.success(new AirWeatherVO());
}
AirWeatherVO airWeatherVO = JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), AirWeatherVO.class);
return JsonResult.success(airWeatherVO);
} catch (Exception e) {
return JsonResult.error(EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getCode(), EditInspectionStatusCodeEnum.GET_WEATHER_FAILED.getMsg());
}
}
}

+ 88
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/DspServiceImpl.java View File

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

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.common.core.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

@Slf4j
@Service
public class DspServiceImpl implements IDspService {

/**
* DSP服务API接口域名
*/
@Value("${tuoheng.dsp-domain-url:}")
private String dspDomainUrl;

@Override
public JSONObject serviceInstApplication(JSONObject jsonObject) {
String url = dspDomainUrl + "api/web/serviceInst/827938791cf98ec2dfceea59726e5085/application";
String result = doPost(url, jsonObject, null);
return JSONObject.parseObject(result);
}

@Override
public JSONObject serviceStopApplication(JSONObject jsonObject) {
String url = dspDomainUrl + "api/web/serviceInst/"+jsonObject.getString("requestId")+"/stop";
String result = HttpUtils.doSend(url, jsonObject, null,"PUT");
return JSONObject.parseObject(result);
}

/**
* 处理post请求
* @param urlStr 请求url
* @param data 请求体数据
* @param properties 请求头参数
* @return
*/
public static String doPost(String urlStr, JSONObject data, Map<String, String> properties){
try {
log.info("请求url={}", urlStr);
log.info("请求体数据data={}", data.toJSONString());
log.info("请求头参数properties={}", properties);
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setDoInput(true); // 设置可输入
connection.setDoOutput(true); // 设置该连接是可以输出的
//设置连接超时时间和读取超时时间
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
//设置请求方式
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
if(null != properties && !properties.isEmpty()){
for (String key:properties.keySet()){
connection.setRequestProperty(key, properties.get(key));
}
}

PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()));
pw.write(data.toJSONString());
pw.flush();
pw.close();

BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
String line = null;
StringBuilder result = new StringBuilder();
while ((line = br.readLine()) != null) { // 读取数据
result.append(line + "\n");
}
connection.disconnect();
return result.toString();
} catch (Exception e) {
log.error("post请求失败");
return "post请求失败!";
}
}
}

+ 9
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/dsp/IDspService.java View File

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

import com.alibaba.fastjson.JSONObject;

public interface IDspService {
JSONObject serviceInstApplication(JSONObject jsonObject);

JSONObject serviceStopApplication(JSONObject jsonObject);
}

+ 19
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/AirWeatherUtil.java View File

@@ -0,0 +1,19 @@
package com.tuoheng.admin.utils;

import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.admin.vo.AirWeatherVO;

import java.math.BigDecimal;

public class AirWeatherUtil {

public static String getWeather(AirWeatherVO airWeather) {
if(ObjectUtil.isEmpty(airWeather) ||ObjectUtil.isEmpty(airWeather.getWth())){
return "";
}
return "气温:" + new BigDecimal(airWeather.getWth().getParm().getTmp()).divide(new BigDecimal(10))+"℃"
+ ";湿度:" + new BigDecimal(airWeather.getWth().getParm().getHum()).divide(new BigDecimal(10))+"RH"
+ ";风速:" + new BigDecimal(airWeather.getWth().getParm().getWspd()).divide(new BigDecimal(10))+"M/S"
+ ";风向:" + airWeather.getWth().getParm().getWdir() + "°";
}
}

+ 87
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/AirWeatherVO.java View File

@@ -0,0 +1,87 @@
package com.tuoheng.admin.vo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* @User qiujinyang
* @Description
* @Date Created by 2022/7/28 13:31
*/
@NoArgsConstructor
@Data
public class AirWeatherVO implements Serializable {

private static final long serialVersionUID = 1L;


private ACDDTO acd;
private WTHDTO wth;
private TAHDTO tah;

@NoArgsConstructor
@Data
public static class ACDDTO {
private ParmDTO parm;
private Integer mid;
private String deviceid;
private Integer timestamp;

@NoArgsConstructor
@Data
public static class ParmDTO {
private Integer tmp;
}
}

@NoArgsConstructor
@Data
public static class WTHDTO {
private ParmDTO parm;
private Integer mid;
private String deviceid;
private Integer timestamp;

@NoArgsConstructor
@Data
public static class ParmDTO {
private Integer hum;
private Integer rainfull;
private Integer noise;
private Integer co2;
private Integer lux;
private Integer rainType;
private Integer tmp;
private Integer _$Pm25111;// FIXME check this code
private Integer dew;
private Integer hpa;
private Integer wspd;
private Integer pm10;
private Integer wdir;
}
}

@NoArgsConstructor
@Data
public static class TAHDTO {
private ParmDTO parm;
private Integer mid;
private String deviceid;
private Integer timestamp;

@NoArgsConstructor
@Data
public static class ParmDTO {
/**
* 湿度
*/
private Integer hum;
/**
* 温度
*/
private Integer tmp;
}
}
}

+ 43
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/vo/DspCallbackVo.java View File

@@ -0,0 +1,43 @@
package com.tuoheng.admin.vo;

import lombok.Data;

@Data
public class DspCallbackVo {

/**
* 请求ID
*/
private String requestId;

/**
* 推流地址
*/
private String pushUrl;

/**
* 拉流地址
*/
private String pullUrl;

/**
* 播放地址(m3u8格式)
*/
private String playUrl;

/**
* AI推流地址
*/
private String aipushUrl;

/**
* AI拉流地址
*/
private String aipullUrl;

/**
* AI播放地址
*/
private String aiplayUrl;

}

Loading…
Cancel
Save