Переглянути джерело

Merge branch 'develop' of gitadmin/tuoheng_air_monitor into release

pull/101/head
wanjing 10 місяці тому
джерело
коміт
c46cfac814
8 змінених файлів з 195 додано та 21 видалено
  1. +7
    -0
      tuoheng-service/tuoheng-admin/sql/sql_change_v1.0.5.sql
  2. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java
  3. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/Inspection.java
  4. +81
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/airport/AirPortCreateTaskVo.java
  5. +2
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/ExecuteInspectionCodeEnum.java
  6. +88
    -11
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/ExecuteTaskService.java
  7. +2
    -5
      tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml
  8. +5
    -4
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/InspectionMapper.xml

+ 7
- 0
tuoheng-service/tuoheng-admin/sql/sql_change_v1.0.5.sql Переглянути файл

@@ -0,0 +1,7 @@
-- 2023-12-26 15:30
-- v1.0.5

use tuoheng_airmonitor;

-- 任务表
alter table tuoheng_airmonitor.th_inspection add airport_task_id int default 0 not null comment '机场任务ID' after inspection_type;

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/constant/SystemConstant.java Переглянути файл

@@ -95,6 +95,11 @@ public interface SystemConstant {
*/
String API_AIRPORT_STATUS = "/airportInterface/getAirportStatus";

/**
* 机场平台:周期性任务创建/修改
*/
String API_AIRPORT_INSPECTION = "/airportInterface/inspection";

/**
* Dsp平台,开始录制
*/

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/Inspection.java Переглянути файл

@@ -53,6 +53,11 @@ public class Inspection extends BaseEntity {
*/
private Integer inspectionType;

/**
* 机场任务ID
*/
private Integer airportTaskId;

/**
* 巡检机场id
*/

+ 81
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/airport/AirPortCreateTaskVo.java Переглянути файл

@@ -0,0 +1,81 @@
package com.tuoheng.admin.entity.vo.airport;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 机场平台创建任务视图Vo
*
* @author wanjing
* @team tuoheng
* @date 2023-07-27
*/
@NoArgsConstructor
@Data
public class AirPortCreateTaskVo implements Serializable {

private static final long serialVersionUID = 1L;

/**
* 任务ID(执行任务时传此ID)
*/
private Integer id;

/**
* 租户ID
*/
private String tenantId;

/**
* 任务编号
*/
private String code;

/**
* 任务名称
*/
private String name;

/**
* 机场ID
*/
private Integer aid;

/**
* 机场名称
*/
private String aname;

/**
* 执飞无人机ID
*/
private Integer droneId;

/**
* 航线文件ID
*/
private Integer airlineFileId;

/**
* 任务状态:1,待执行;2,执行中;3,执行完成
*/
private Integer status;

/**
* 任务来源
*/
private String taskSource;

/**
* 任务来源名称
*/
private String taskSourceName;

/**
* 执行类型:1,单次;2,每天; 5,每周;6,每月
*/
private Integer type;

}

+ 2
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/ExecuteInspectionCodeEnum.java Переглянути файл

@@ -18,7 +18,8 @@ public enum ExecuteInspectionCodeEnum {
TENANT_IS_NOT_EXIST(1230804, "租户不存在"),
AIRPORT_URL_IS_NULL(1230805, "机场平台URL为空"),
AIRPORT_RETURN_DATA_IS_NULL(1230806, "机场接口返回数据为空"),
INSPECTION_CANNOT_REPEATED_EXECUTE(1230807, "任务不能被重复执行"),;
INSPECTION_CANNOT_REPEATED_EXECUTE(1230807, "任务不能被重复执行"),
AIRPORT_RETURN_TASK_ID_IS_NULL(1230808, "机场接口返回taskId为空");

/**
* 错误码

+ 88
- 11
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/ExecuteTaskService.java Переглянути файл

@@ -5,18 +5,23 @@ import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.domain.Tenant;
import com.tuoheng.admin.entity.vo.airport.AirPortCreateTaskVo;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.code.inspection.ExecuteInspectionCodeEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.mapper.TenantMapper;
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.HttpUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Service
@@ -28,6 +33,10 @@ public class ExecuteTaskService {
@Autowired
private InspectionMapper inspectionMapper;

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

public JsonResult executeTask(String userId, Inspection inspection) {
log.info("进入调用机场平台方法,执行任务");
// 读取不同租户的机场平台url
@@ -36,32 +45,89 @@ public class ExecuteTaskService {
log.info("进入调用机场平台方法: 租户不存在");
return JsonResult.error(ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getCode(), ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getMsg());
}
AirPortCreateTaskVo airPortCreateTaskVo = this.createAirportTask(tenant, inspection);
if (ObjectUtil.isEmpty(airPortCreateTaskVo)) {
log.info("进入调用机场平台方法: 获取机场平台taskId失败");
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_RETURN_TASK_ID_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_RETURN_TASK_ID_IS_NULL.getMsg());
}

Integer airportTaskId = airPortCreateTaskVo.getId();
Integer airlineFileId = airPortCreateTaskVo.getAirlineFileId();

String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_EXECUTE_TASK;
JSONObject jsonObject = new JSONObject();
jsonObject.put("taskId", inspection.getInspectionLine());
jsonObject.put("taskId", airportTaskId);
jsonObject.put("requestId", inspection.getId());
jsonObject.put("requestName", inspection.getName());
jsonObject.put("code", SystemConstant.PLATFORM_CODE); // 与机场平台约定好的
jsonObject.put("tenantCode", tenant.getCode());

log.info("进入调用机场平台方法: url:{}", url);
log.info("进入调用机场平台方法: jsonObject:{}", jsonObject);
log.info("执行任务, 调用机场平台: url:{}", url);
log.info("执行任务, 调用机场平台: jsonObject:{}", jsonObject);

String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST");
if (StringUtils.isEmpty(airPortStr)) {
log.info("立即执行任务业务:机场接口返回数据为空,飞行失败,任务id:{},任务名称:{},机场id:{},机场名称:{}, 路线id:{},路线名称:{}",
inspection.getId(), inspection.getName(), inspection.getAirportId(), inspection.getAirportName(), inspection.getInspectionLine(), inspection.getInspectionLineName());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity httpEntity = new HttpEntity(jsonObject, headers);
try {
restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
} catch (Exception e) {
log.info("执行任务, 调用机场平台:机场接口异常, url:{}", url);
log.info("执行任务, 调用机场平台:机场接口异常, httpEntity:{}", httpEntity);
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getMsg());
}

// 修改任务执行状态,防止手动执行和定时重复
inspection.setAirportTaskId(airportTaskId);
inspection.setInspectionLine(airlineFileId);
this.updateInspectionExecutionStatus(userId, inspection);

log.info("进入调用机场平台方法: 等待机场平台回调,修改执行任务状态");
log.info("执行任务, 调用机场平台: 等待机场平台回调,修改执行任务状态");
return JsonResult.success();
}

/**
* 机场平台:周期性任务创建/修改
*
* @return
*/
private AirPortCreateTaskVo createAirportTask(Tenant tenant, Inspection inspection) {
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_INSPECTION;
JSONObject jsonObject = new JSONObject();
jsonObject.put("tenantCode", tenant.getCode());
jsonObject.put("bnCode", SystemConstant.PLATFORM_CODE);
jsonObject.put("name", inspection.getName());
jsonObject.put("aid", inspection.getAirportId());
jsonObject.put("airlineFileId", inspection.getInspectionLine());
jsonObject.put("type", 1); // 执行类型:1,单次;2,每天;3,指点;4,直面;5,每周;6,每月
jsonObject.put("singleTime", inspection.getInspectionTime()); // 单次执行时间,如:2021-10-15 12:12:12

log.info("调用机场平台,周期性任务创建,url:{}", url);
log.info("调用机场平台,周期性任务创建,jsonObject:{}", jsonObject);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity httpEntity = new HttpEntity(jsonObject, headers);
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
} catch (Exception e) {
log.error("调用机场平台,周期性任务创建接口异常, url:{}", url);
log.error("调用机场平台,周期性任务创建接口异常, httpEntity:{}", httpEntity);
throw new ServiceException("调用机场平台,周期性任务创建接口异常");
}
JsonResult jsonResult = response.getBody();
if (0 != jsonResult.getCode()) {
log.info("调用机场平台,周期性任务创建,机场返回失败,jsonResult:{}", jsonResult.getMsg());
throw new ServiceException("调用机场平台,周期性任务创建,机场返回失败");
}

AirPortCreateTaskVo airPortCreateTaskVo = JSONObject.parseObject(JSONObject.toJSONString(jsonResult.getData()), AirPortCreateTaskVo.class);

log.info("调用机场平台,自主规划航线,airPortCreateTaskVo:{}", airPortCreateTaskVo);

return airPortCreateTaskVo;
}

/**
* 修改任务执行状态
*
@@ -69,11 +135,22 @@ public class ExecuteTaskService {
* @param inspection
*/
private void updateInspectionExecutionStatus(String userId, Inspection inspection) {
inspection.setStatus(InspectionStatusEnum.PREPARING.getCode());
Inspection inspectionTmp = inspectionMapper.selectById(inspection.getId());
if (InspectionStatusEnum.WAIT_FLIGHT.getCode() == inspectionTmp.getStatus()) {
inspection.setStatus(InspectionStatusEnum.PREPARING.getCode());
} else {
// 此处是为解决将任务状态改为准备中之前,机场平台已经推送失败信息过来
log.info("该任务状态不是待飞行,不需要修改为准备中,使用最新的状态,inspectionId={}, status={},", inspectionTmp.getId(), inspectionTmp.getStatus());
inspection.setStatus(inspectionTmp.getStatus());
}
inspection.setExecutionStatus(2);
inspection.setStatus(inspection.getStatus());
inspection.setExecutionStartTime(DateUtils.now());
inspection.setUpdateUser(userId);
inspection.setUpdateTime(DateUtils.now());
inspectionMapper.update(inspection);
Integer count = inspectionMapper.update(inspection);
if (count <= 0) {
log.info("执行任务,修改任务状态失败,inspectionId={}, status={}", inspection.getId(), inspection.getStatus());
}
log.info("执行任务,修改任务状态成功,inspectionId={}, status={}", inspection.getId(), inspection.getStatus());
}
}

+ 2
- 5
tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml Переглянути файл

@@ -2,7 +2,7 @@ spring:
# 注册中心consul地址
cloud:
consul:
host: 192.168.11.13 # consul 所在服务地址
host: localhost # consul 所在服务地址
port: 8500 # consul 服务端口
discovery:
# 是否启用服务发现
@@ -11,7 +11,7 @@ spring:
register: false
deregister: false
## consul ip地址
hostname: 192.168.11.13
hostname: localhost
# 注册到consul的服务名称
service-name: ${spring.application.name} # 服务提供者名称
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} #实例ID
@@ -32,9 +32,6 @@ spring:
url: jdbc:mysql://192.168.11.13:3306/tuoheng_airmonitor?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
username: root
password: idontcare
# url: jdbc:mysql://rm-uf6z740323e8053pj4o.mysql.rds.aliyuncs.com:3306/tuoheng_airmonitor?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8&useSSL=true&tinyInt1isBit=false
# username: root
# password: TH22#2022
filter:
slf4j:
enabled: true

+ 5
- 4
tuoheng-service/tuoheng-admin/src/main/resources/mapper/InspectionMapper.xml Переглянути файл

@@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="name" column="name" />
<result property="type" column="type" />
<result property="inspectionType" column="inspection_type" />
<result property="airportTaskId" column="airport_task_id" />
<result property="airportId" column="airport_id" />
<result property="airportName" column="airport_name" />
<result property="droneId" column="drone_id" />
@@ -62,7 +63,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

<sql id="Base_Column_list">
id, tenant_id, code, name, type, inspection_type,
airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, equipment_mount_type, equipment_mount_code
airport_task_id, airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id,
equipment_name, equipment_mount_id, equipment_mount_type, equipment_mount_code
equipment_mount_name, cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time,
execution_start_time, execution_end_time, is_live, is_taken, is_tilt, video_url, ai_video_url, report_url, srt_url,
status, analyse_status, progressbar, note, weather, fly_height, srt_name, heartbeat_time, execution_status,
@@ -72,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

<sql id="selectInspectionVo">
select id, tenant_id, code, name, type, inspection_type,
airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id,
airport_task_id, airport_id, airport_name, drone_id, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id,
equipment_mount_name, equipment_mount_type,equipment_mount_code,cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time,
execution_start_time, execution_end_time, is_live, is_taken, is_tilt, video_url, ai_video_url, report_url, srt_url,
status, analyse_status, progressbar, note, weather, fly_height, srt_name, heartbeat_time, execution_status,
@@ -124,11 +126,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="update" parameterType="com.tuoheng.admin.entity.domain.Inspection">
update th_inspection
<trim prefix="SET" suffixOverrides=",">
<if test="tenantId != null and tenantId != ''">tenant_id = #{tenantId},</if>
<if test="code != null">code = #{code},</if>
<if test="name != null">name = #{name},</if>
<if test="type != null">type = #{type},</if>
<if test="inspectionType != null">inspection_type = #{inspectionType},</if>
<if test="airportTaskId != null">airport_task_id = #{airportTaskId},</if>
<if test="airportId != null">airport_id = #{airportId},</if>
<if test="airportName != null">airport_name = #{airportName},</if>
<if test="droneId != null"> drone_id = #{droneId},</if>

Завантаження…
Відмінити
Зберегти