@@ -35,4 +35,5 @@ create table th_inspection_cycle | |||
) comment '周期任务表' collate = utf8mb4_bin; | |||
-- 任务表中新增周期任务ID | |||
alter table tuoheng_freeway.th_inspection add inspection_cycle_id varchar(36) default '' not null comment '周期性任务ID' after inspection_type; | |||
alter table tuoheng_freeway.th_inspection add inspection_cycle_id varchar(36) default '' not null comment '周期性任务ID' after inspection_type; | |||
alter table tuoheng_freeway.th_inspection add airport_task_id int default 0 not null comment '机场任务ID' after inspection_cycle_id; |
@@ -90,4 +90,8 @@ public interface SystemConstant { | |||
*/ | |||
String API_AIRPORT_MSG_BY_AIRPORT_ID = "/airportInterface/queryAirportList"; | |||
/** | |||
* 机场平台:周期性任务创建/修改 | |||
*/ | |||
String API_AIRPORT_INSPECTION = "/airportInterface/inspection"; | |||
} |
@@ -83,6 +83,11 @@ public class Inspection extends BaseEntity { | |||
*/ | |||
private String inspectionCycleId; | |||
/** | |||
* 机场任务ID | |||
*/ | |||
private Integer airportTaskId; | |||
/** | |||
* 巡检机场id | |||
*/ |
@@ -11,10 +11,12 @@ import lombok.Getter; | |||
*/ | |||
public enum InspectionStatusEnum { | |||
WAIT_FLIGHT(5,"待飞行"), | |||
WAIT_FLIGHT(5,"待执行"), | |||
PREPARING(6,"准备中"), | |||
FLIGHT_FAILED(7,"飞行失败"), | |||
IN_FLIGHT(10,"飞行中"), | |||
FLIGHT_COMPLETED(15,"飞行完成"); | |||
FLIGHT_COMPLETED(15,"飞行完成"), | |||
FLIGHT_CANCELED(16,"已取消"); | |||
InspectionStatusEnum(int code, String description){ | |||
this.code = code; |
@@ -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为空"); | |||
/** | |||
* 错误码 |
@@ -5,19 +5,19 @@ import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.Tenant; | |||
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.admin.vo.airport.AirPortCreateTaskVo; | |||
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.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.http.HttpEntity; | |||
import org.springframework.http.HttpHeaders; | |||
import org.springframework.http.HttpMethod; | |||
import org.springframework.http.MediaType; | |||
import org.springframework.http.*; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
@@ -43,15 +43,23 @@ 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", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("code", SystemConstant.PLATFORM_CODE); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
log.info("执行任务, 调用机场平台: url:{}", url); | |||
log.info("执行任务, 调用机场平台: jsonObject:{}", jsonObject); | |||
@@ -67,12 +75,57 @@ public class ExecuteTaskService { | |||
} | |||
// 修改任务执行状态,防止手动执行和定时重复 | |||
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; | |||
} | |||
/** | |||
* 修改任务执行状态 | |||
* | |||
@@ -80,10 +133,22 @@ public class ExecuteTaskService { | |||
* @param inspection | |||
*/ | |||
private void updateInspectionExecutionStatus(String userId, Inspection inspection) { | |||
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()); | |||
} | |||
} |
@@ -16,6 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="sectionId" column="section_id" /> | |||
<result property="sectionName" column="section_name" /> | |||
<result property="inspectionType" column="inspection_type" /> | |||
<result property="inspectionCycleId" column="inspection_cycleId_id" /> | |||
<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" /> | |||
@@ -65,8 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<sql id="Base_Column_list"> | |||
id, tenant_id, dept_id, code, name, type, road_id, road_name, section_id, section_name, inspection_type, | |||
airport_id, drone_id, airport_name, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
equipment_mount_name, cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time, | |||
inspectionCycleI, airport_task_id, airport_id, drone_id, airport_name, inspection_line, inspection_line_name, | |||
equipment_id, equipment_name, equipment_mount_id, 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, | |||
start_longitude, start_latitude, end_longitude, end_latitude, mobile, patrol_location, | |||
@@ -75,8 +78,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<sql id="selectInspectionVo"> | |||
select id, tenant_id, dept_id, code, name, type, road_id, road_name, section_id, section_name, inspection_type, | |||
airport_id, drone_id, airport_name, inspection_line, inspection_line_name, equipment_id, equipment_name, equipment_mount_id, | |||
equipment_mount_name, cloud_box_id, cloud_box_name, box_sn, flight_hand, flight_hand_name, inspection_time, | |||
inspectionCycleI, airport_task_id, airport_id, drone_id, airport_name, inspection_line, inspection_line_name, | |||
equipment_id, equipment_name, equipment_mount_id, 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, | |||
start_longitude, start_latitude, end_longitude, end_latitude, mobile, patrol_location, | |||
@@ -146,16 +150,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<update id="update" parameterType="com.tuoheng.admin.entity.Inspection"> | |||
update th_inspection | |||
<trim prefix="SET" suffixOverrides=","> | |||
<if test="tenantId != null and tenantId != ''">tenant_id = #{tenantId},</if> | |||
<if test="deptId != null and deptId != ''">dept_id = #{deptId},</if> | |||
<if test="code != null">code = #{code},</if> | |||
<if test="name != null">name = #{name},</if> | |||
<if test="type != null">type = #{type},</if> | |||
<if test="roadId != null and roadId != ''">road_id = #{roadId},</if> | |||
<if test="roadName != null">road_name = #{roadName},</if> | |||
<if test="sectionId != null and sectionId != ''">section_id = #{sectionId},</if> | |||
<if test="sectionName != null">section_name = #{sectionName},</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="droneId != null">drone_id = #{droneId},</if> | |||
<if test="airportName != null">airport_name = #{airportName},</if> | |||
@@ -195,8 +195,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<if test="endLatitude != null">end_latitude = #{endLatitude},</if> | |||
<if test="mobile != null">mobile = #{mobile},</if> | |||
<if test="patrolLocation != null">patrol_location = #{patrolLocation},</if> | |||
<if test="createUser != null">create_user = #{createUser},</if> | |||
<if test="createTime != null">create_time = #{createTime},</if> | |||
<if test="updateUser != null">update_user = #{updateUser},</if> | |||
<if test="updateTime != null">update_time = #{updateTime},</if> | |||
<if test="mark != null">mark = #{mark},</if> |