Parcourir la source

重构立即飞行代码逻辑,添加预警记录

tags/v1.2.0^2
wanjing il y a 1 an
Parent
révision
75cc86fa9a
7 fichiers modifiés avec 187 ajouts et 38 suppressions
  1. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/config/SystemConstant.java
  2. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/Warning.java
  3. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/WarningRecord.java
  4. +6
    -18
      tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/PointFlightRequest.java
  5. +162
    -18
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/PointFlightService.java
  6. +2
    -1
      tuoheng-admin/src/main/resources/mapper/WarningMapper.xml
  7. +2
    -1
      tuoheng-admin/src/main/resources/mapper/WarningRecordMapper.xml

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/config/SystemConstant.java Voir le fichier

@@ -2,6 +2,11 @@ package com.tuoheng.admin.config;

public interface SystemConstant {

/**
* 平台code
*/
String PLATFORM_CODE = "treefarm";

/**
* 机场平台:获取机场列表接口
*/

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/Warning.java Voir le fichier

@@ -31,6 +31,11 @@ public class Warning extends BaseEntity implements Serializable {
*/
private Integer tenantId;
/**
* 任务ID
*/
private Integer missionId;
/**
* 发现方式 1监控摄像 2无人机巡检 3人工巡检
*/

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/WarningRecord.java Voir le fichier

@@ -44,4 +44,9 @@ public class WarningRecord extends BaseEntity implements Serializable {
*/
private Integer missionId;
/**
* 应急任务ID
*/
private Integer emergencyMissionId;
}

+ 6
- 18
tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/PointFlightRequest.java Voir le fichier

@@ -17,30 +17,18 @@ public class PointFlightRequest implements Serializable {

private static final long serialVersionUID = 1L;

@ApiModelProperty(value = "预警id")
private Integer warningId;

@ApiModelProperty(value = "巡检任务id")
private Integer missionId;

@ApiModelProperty(value = "机场id")
private Integer airportId;

@ApiModelProperty(value = "机场名称")
private String airportName;

@ApiModelProperty(value = "路线id")
private Integer inspectionLine;

@ApiModelProperty(value = "路线名称")
private String inspectionLineName;

@ApiModelProperty(value = "无人机ID")
private Integer droneId;

@ApiModelProperty(value = "无人机名称")
private String droneName;

@ApiModelProperty(value = "业务系统标识")
private String code;

@ApiModelProperty(value = "租户代码")
private String tenantCode;

@ApiModelProperty(value = "指点高度")
private String alt;


+ 162
- 18
tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/PointFlightService.java Voir le fichier

@@ -2,15 +2,21 @@ package com.tuoheng.admin.service.third.airport;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.config.SystemConstant;
import com.tuoheng.admin.entity.domain.Tenant;
import com.tuoheng.admin.entity.domain.ThMission;
import com.tuoheng.admin.entity.domain.Warning;
import com.tuoheng.admin.entity.domain.WarningRecord;
import com.tuoheng.admin.entity.request.airport.PointFlightRequest;
import com.tuoheng.admin.enums.AirportFlyTypeEnum;
import com.tuoheng.admin.enums.InspectionTypeEnum;
import com.tuoheng.admin.enums.TaskStatusEnum;
import com.tuoheng.admin.enums.UpdateOrCreateEnum;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.ThMissionMapper;
import com.tuoheng.admin.mapper.WarningMapper;
import com.tuoheng.admin.mapper.WarningRecordMapper;
import com.tuoheng.admin.utils.CodeUtil;
import com.tuoheng.common.exception.ServiceException;
import com.tuoheng.common.utils.DateUtils;
@@ -22,6 +28,7 @@ import com.tuoheng.system.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@@ -30,53 +37,167 @@ public class PointFlightService {
@Autowired
private TenantMapper tenantMapper;

@Autowired
private WarningMapper warningMapper;

@Autowired
private ThMissionMapper missionMapper;

@Autowired
private WarningRecordMapper warningRecordMapper;

@Transactional
public JsonResult executePointFligh(PointFlightRequest request) {
log.info("进入调用机场平台,执行定点飞行");
// 读取不同租户的机场平台url
JsonResult result = this.check(request);
User user = ShiroUtils.getUserInfo();
Integer tenantId = user.getTenantId();

// 获取租户信息
Tenant tenant = this.getTenant(tenantId);

// 创建应急任务
ThMission mission = this.createMission(user, request);

// 调用机场平台
ThMission oldMission = (ThMission) result.getData();
if (oldMission.getAirportId().equals(request.getAirportId())) {
log.info("原机场执行定点飞行");
// this.callOldAirpor(tenant, request);
} else {
log.info("新机场执行定点飞行");
// this.callNewAirpor(tenant, request, mission.getId());
}

// 创建预警记录
this.createWarningRecord(user.getId(), tenantId, request, mission.getId());

log.info("调用机场平台方法: 执行定点飞行结束");
return JsonResult.success();
}

/**
* 检查参数
*
* @param request
*/
private JsonResult check(PointFlightRequest request) {
if (ObjectUtil.isNull(request.getWarningId())) {
throw new ServiceException("预警ID为空");
}
if (ObjectUtil.isNull(request.getMissionId())) {
throw new ServiceException("原巡检任务ID为空");
}
if (ObjectUtil.isNull(request.getAirportId())) {
throw new ServiceException("机场ID为空");
}
if (ObjectUtil.isNull(request.getAirportName())) {
throw new ServiceException("机场名称为空");
}
if (ObjectUtil.isNull(request.getAlt())) {
throw new ServiceException("指点高度为空");
}
if (ObjectUtil.isNull(request.getLon())) {
throw new ServiceException("经度为空");
}
if (ObjectUtil.isNull(request.getLat())) {
throw new ServiceException("纬度为空");
}
Warning warning = warningMapper.selectOne(new LambdaQueryWrapper<Warning>()
.eq(Warning::getId, request.getWarningId())
.eq(Warning::getMark, 1));
if (ObjectUtil.isNull(warning)) {
throw new ServiceException("该预警信息不存在");
}
ThMission mission = missionMapper.selectOne(new LambdaQueryWrapper<ThMission>()
.eq(ThMission::getId, request.getMissionId())
.eq(ThMission::getMark, 1));
if (ObjectUtil.isNull(mission)) {
throw new ServiceException("原巡检任务不存在");
}
return JsonResult.success(mission);
}

/**
* 获取租户信息
*
* @param tenantId
* @return
*/
private Tenant getTenant(Integer tenantId) {
Tenant tenant = tenantMapper.selectById(tenantId);
if (ObjectUtil.isEmpty(tenant)) {
log.info("调用机场平台,执行定点飞行: 租户不存在");
throw new ServiceException("租户不存在");
}

// 读取不同租户的机场平台url
if (StringUtils.isEmpty(tenant.getAirportUrl())) {
log.info("调用机场平台,执行定点飞行: 机场平台URL为空");
throw new ServiceException("机场平台URL为空");
}
return tenant;
}

// 创建应急任务
this.createMission(user, request);
/**
* 调用老机场平台
*
* @param tenant
* @param request
*/
private void callOldAirpor(Tenant tenant, PointFlightRequest request) {
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_DRONE_CONTROL;
JSONObject jsonObject = new JSONObject();
jsonObject.put("taskId", request.getMissionId());
jsonObject.put("airportId", request.getAirportId());
jsonObject.put("zalt", request.getAlt());
jsonObject.put("zlon", request.getLon());
jsonObject.put("zlat", request.getLat());

log.info("调用机场平台,原无人机执行定点飞行: url:{}", url);
log.info("调用机场平台,原无人机执行定点飞行: jsonObject:{}", jsonObject);

String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST");
if (StringUtils.isEmpty(airPortStr)) {
log.info("原无人机执行定点飞行:机场接口返回数据为空,飞行失败,jsonObject:{}", jsonObject);
throw new ServiceException("机场接口返回数据为空,飞行失败");
}
}

/**
* 调用新机场平台
*
* @param tenant
* @param request
*/
private void callNewAirpor(Tenant tenant, PointFlightRequest request, Integer emergencyMissionId) {
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_POINT_FLIGH;
JSONObject jsonObject = new JSONObject();
jsonObject.put("airportId", request.getAirportId());
jsonObject.put("requestId", request.getInspectionLine());
jsonObject.put("code", "gs"); // 与机场平台约定好的
jsonObject.put("requestId", emergencyMissionId);
jsonObject.put("code", SystemConstant.PLATFORM_CODE); // 与机场平台约定好的
jsonObject.put("tenantCode", tenant.getCode());
jsonObject.put("alt", request.getAlt());
jsonObject.put("lon", request.getLon());
jsonObject.put("lat", request.getLat());

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("执行定点飞行:机场接口返回数据为空,飞行失败,jsonObject:{}", jsonObject);
return JsonResult.error(-1, "机场接口返回数据为空");
log.info("新无人机执行定点飞行:机场接口返回数据为空,飞行失败,jsonObject:{}", jsonObject);
throw new ServiceException("机场接口返回数据为空,飞行失败");
}

log.info("调用机场平台方法: 执行定点飞行结束");
return JsonResult.success();
}

private void createMission(User user, PointFlightRequest request) {
/**
* 创建应急任务
*
* @param user
* @param request
* @return
*/
private ThMission createMission(User user, PointFlightRequest request) {
ThMission mission = new ThMission(UpdateOrCreateEnum.CREATE.getCode());
String code = "XJRW" + CodeUtil.createCodeNo();
mission.setCode(code);
@@ -85,10 +206,8 @@ public class PointFlightService {
mission.setInspectionType(InspectionTypeEnum.AIRPORT.getCode());
mission.setAirportId(request.getAirportId());
mission.setAirportName(request.getAirportName());
mission.setInspectionLine(request.getInspectionLine());
mission.setInspectionLineName(request.getInspectionLineName());
mission.setDroneId(request.getDroneId());
mission.setDroneName(request.getDroneName());
mission.setInspectionLine(0);
mission.setInspectionLineName("");
mission.setExecutionStartTime(DateUtils.now());
mission.setAirportFlyType(AirportFlyTypeEnum.POINTING_FLIGHT.getCode());
mission.setCreateUser(user.getId());
@@ -98,6 +217,31 @@ public class PointFlightService {
log.info("创建应急任务失败");
throw new ServiceException("创建应急任务失败");
}
return mission;
}

/**
* 创建预警记录
*
* @param userId
* @param tenantId
* @param request
* @param emergencyMissionId
*/
private void createWarningRecord(Integer userId, Integer tenantId, PointFlightRequest request, Integer emergencyMissionId) {
WarningRecord warningRecord = new WarningRecord();
warningRecord.setTenantId(tenantId);
warningRecord.setWarningId(request.getWarningId());
warningRecord.setMissionId(request.getMissionId());
warningRecord.setEmergencyMissionId(emergencyMissionId);
warningRecord.setName(request.getAirportName() + "执行任务");
warningRecord.setCreateUser(userId);
warningRecord.setCreateTime(DateUtils.now());
Integer count = warningRecordMapper.insert(warningRecord);
if (count <= 0) {
log.info("创建预计记录失败");
throw new ServiceException("创建预计记录失败");
}
}

}

+ 2
- 1
tuoheng-admin/src/main/resources/mapper/WarningMapper.xml Voir le fichier

@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.tuoheng.admin.entity.domain.Warning" id="WarningResult">
<result property="id" column="id" />
<result property="tenantId" column="tenant_id" />
<result property="missionId" column="mission_id" />
<result property="discoveryWay" column="discovery_way" />
<result property="location" column="location" />
<result property="status" column="status" />
@@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectWarningVo">
select id, tenant_id, discovery_way, location, status, question_id, create_user, create_time, update_user, update_time, check_user, check_time, check_result, mark from th_warning
select id, tenant_id, mission_id, discovery_way, location, status, question_id, create_user, create_time, update_user, update_time, check_user, check_time, check_result, mark from th_warning
</sql>
<select id="getList" parameterType="com.tuoheng.admin.entity.request.warning.QueryWarningListRequest" resultMap="WarningResult">

+ 2
- 1
tuoheng-admin/src/main/resources/mapper/WarningRecordMapper.xml Voir le fichier

@@ -8,8 +8,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="id" column="id" />
<result property="tenantId" column="tenant_id" />
<result property="warningId" column="warning_id" />
<result property="name" column="name" />
<result property="missionId" column="mission_id" />
<result property="emergencyMissionId" column="emergency_mission_id" />
<result property="name" column="name" />
<result property="createUser" column="create_user" />
<result property="createTime" column="create_time" />
<result property="updateUser" column="update_user" />

Chargement…
Annuler
Enregistrer