@@ -33,4 +33,10 @@ public interface SystemConstant { | |||
* 机场平台:定点飞行 | |||
*/ | |||
String API_AIRPORT_POINT_FLIGH = "/api/airportInterface/createPointLine"; | |||
/** | |||
* 机场平台:定点飞行 | |||
*/ | |||
String API_AIRPORT_DRONE_CONTROL = "/api/createPointLine/droneCommand"; | |||
} |
@@ -1,14 +1,12 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.entity.request.airport.DroneControlRequest; | |||
import com.tuoheng.admin.entity.request.airport.PointFlightRequest; | |||
import com.tuoheng.admin.service.airport.AirportService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import org.springframework.web.bind.annotation.*; | |||
/** | |||
* 机场前端控制器 | |||
@@ -36,8 +34,24 @@ public class AirPortController { | |||
/** | |||
* 定点飞行 | |||
*/ | |||
@PostMapping("/pointFlight") | |||
public JsonResult pointFlight(PointFlightRequest request) { | |||
@PostMapping("/pointflight") | |||
public JsonResult pointFlight(PointFlightRequest request) { | |||
return airportService.pointFlight(request); | |||
} | |||
/** | |||
* 无人机信息 | |||
*/ | |||
@GetMapping("/drone/data/{airportId}") | |||
public JsonResult getDroneDataById(@PathVariable("airportId") String airportId) { | |||
return airportService.getDroneDataById(airportId); | |||
} | |||
/** | |||
* 操制无人机 | |||
*/ | |||
@PostMapping("/drone/control") | |||
public JsonResult droneControl(DroneControlRequest request) { | |||
return airportService.droneControl(request); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.tuoheng.admin.conver; | |||
import com.tuoheng.admin.entity.domain.ThInspection; | |||
import com.tuoheng.admin.entity.domain.Warning; | |||
import com.tuoheng.admin.entity.vo.index.DroneDataVo; | |||
import com.tuoheng.admin.entity.vo.warning.WarningListVo; | |||
import org.mapstruct.Mapper; | |||
import org.mapstruct.factory.Mappers; | |||
import java.util.List; | |||
@Mapper | |||
public interface InspectionConverMapper { | |||
InspectionConverMapper INSTANCE = Mappers.getMapper(InspectionConverMapper.class); | |||
List<DroneDataVo> fromInspectionListToDroneDataVoList(List<ThInspection> inspectionList); | |||
} |
@@ -61,6 +61,11 @@ public class ThInspection extends BaseEntity implements Serializable { | |||
*/ | |||
private String altitude; | |||
/** | |||
* 飞行速度 | |||
*/ | |||
private String speed; | |||
/** | |||
* 经度 | |||
*/ | |||
@@ -77,4 +82,14 @@ public class ThInspection extends BaseEntity implements Serializable { | |||
*/ | |||
private Long flyTime; | |||
/** | |||
* 距离机场距离(米) | |||
*/ | |||
private String distHome; | |||
/** | |||
* 遥测信号 | |||
*/ | |||
private String ysingal; | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.tuoheng.admin.entity.request.airport; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import java.io.Serializable; | |||
/** | |||
* 无人机控制请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2023-02-15 | |||
*/ | |||
@Data | |||
public class DroneControlRequest implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
private String value; | |||
} |
@@ -6,7 +6,7 @@ import lombok.Data; | |||
import java.io.Serializable; | |||
/** | |||
* 查询巡检任务请求实体 | |||
* 定点飞行请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
@@ -18,10 +18,22 @@ public class PointFlightRequest implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
@ApiModelProperty(value = "机场id") | |||
private String airportId; | |||
private Integer airportId; | |||
@ApiModelProperty(value = "业务系统任务id") | |||
private String requestId; | |||
@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; |
@@ -0,0 +1,58 @@ | |||
package com.tuoheng.admin.entity.vo.index; | |||
import lombok.Data; | |||
@Data | |||
public class DroneDataVo { | |||
/** | |||
* 任务ID | |||
*/ | |||
private Integer missionId; | |||
/** | |||
* 巡检ID,跟硬件对接的时候,硬件的巡检ID | |||
*/ | |||
private Integer inspectionId; | |||
/** | |||
* 地面站标识 | |||
*/ | |||
private String hostIp; | |||
/** | |||
* 飞行高度 | |||
*/ | |||
private String altitude; | |||
/** | |||
* 飞行速度 | |||
*/ | |||
private String speed; | |||
/** | |||
* 经度 | |||
*/ | |||
private String lng; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String lat; | |||
/** | |||
* 飞行时间 | |||
*/ | |||
private Long flyTime; | |||
/** | |||
* 距离机场距离(米) | |||
*/ | |||
private String distHome; | |||
/** | |||
* 遥测信号 | |||
*/ | |||
private String ysingal; | |||
} |
@@ -0,0 +1,28 @@ | |||
package com.tuoheng.admin.enums; | |||
import lombok.Getter; | |||
/** | |||
* 巡检方式类型 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-11-23 | |||
*/ | |||
public enum InspectionTypeEnum { | |||
AIRPORT(1,"机场巡逻"), | |||
MABNNEDFLIGHT(2,"人工巡检"); | |||
InspectionTypeEnum(int code, String description){ | |||
this.code = code; | |||
this.description = description; | |||
} | |||
@Getter | |||
private int code; | |||
@Getter | |||
private String description; | |||
} |
@@ -7,6 +7,7 @@ import com.tuoheng.admin.entity.domain.ThMission; | |||
import java.util.List; | |||
public interface ThInspectionMapper extends BaseMapper<ThInspection> { | |||
List<ThInspection> selectListByInspectionId(Integer id); | |||
List<ThInspection> selectListByMissionId(Integer missionId); | |||
} |
@@ -1,7 +1,9 @@ | |||
package com.tuoheng.admin.service.airport; | |||
import com.tuoheng.admin.entity.request.airport.DroneControlRequest; | |||
import com.tuoheng.admin.entity.request.airport.PointFlightRequest; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
public interface AirportService { | |||
@@ -12,10 +14,24 @@ public interface AirportService { | |||
*/ | |||
JsonResult getList(); | |||
/** | |||
* 定点飞行 | |||
* @param airportId | |||
* @return | |||
*/ | |||
JsonResult getDroneDataById(String airportId); | |||
/** | |||
* 定点飞行 | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult pointFlight(PointFlightRequest request); | |||
/** | |||
* 操制无人机 | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult droneControl(DroneControlRequest request); | |||
} |
@@ -1,6 +1,9 @@ | |||
package com.tuoheng.admin.service.airport; | |||
import com.tuoheng.admin.entity.request.airport.DroneControlRequest; | |||
import com.tuoheng.admin.entity.request.airport.PointFlightRequest; | |||
import com.tuoheng.admin.service.airport.drone.QueryDroneDataService; | |||
import com.tuoheng.admin.service.third.airport.DroneControlService; | |||
import com.tuoheng.admin.service.third.airport.PointFlightService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
@@ -9,9 +12,15 @@ import org.springframework.stereotype.Service; | |||
@Service | |||
public class AirportServiceImpl implements AirportService { | |||
@Autowired | |||
private QueryDroneDataService queryDroneDataService; | |||
@Autowired | |||
private PointFlightService pointFlightService; | |||
@Autowired | |||
private DroneControlService droneControlService; | |||
/** | |||
* 获取机场列表 | |||
* | |||
@@ -22,6 +31,16 @@ public class AirportServiceImpl implements AirportService { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 定点飞行 | |||
* @param airportId | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult getDroneDataById(String airportId) { | |||
return queryDroneDataService.getDroneDataById(airportId); | |||
} | |||
/** | |||
* 定点飞行 | |||
* @param request | |||
@@ -31,4 +50,14 @@ public class AirportServiceImpl implements AirportService { | |||
public JsonResult pointFlight(PointFlightRequest request) { | |||
return pointFlightService.executePointFligh(request); | |||
} | |||
/** | |||
* 操制无人机 | |||
* @param request | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult droneControl(DroneControlRequest request) { | |||
return droneControlService.execute(request); | |||
} | |||
} |
@@ -0,0 +1,98 @@ | |||
package com.tuoheng.admin.service.airport.drone; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.InspectionConverMapper; | |||
import com.tuoheng.admin.entity.domain.Tenant; | |||
import com.tuoheng.admin.entity.domain.ThInspection; | |||
import com.tuoheng.admin.entity.domain.ThMission; | |||
import com.tuoheng.admin.entity.vo.index.DroneDataVo; | |||
import com.tuoheng.admin.enums.TaskStatusEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.mapper.ThInspectionMapper; | |||
import com.tuoheng.admin.mapper.ThMissionMapper; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
@Slf4j | |||
@Service | |||
public class QueryDroneDataService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private ThMissionMapper missionMapper; | |||
@Autowired | |||
private ThInspectionMapper inspectionMapper; | |||
public JsonResult getDroneDataById(String airportId) { | |||
log.info("获取无人机数据信息"); | |||
this.check(airportId); | |||
// 读取不同租户的机场平台url | |||
User user = ShiroUtils.getUserInfo(); | |||
Integer tenantId = user.getTenantId(); | |||
ThMission mission = missionMapper.selectOne(new LambdaQueryWrapper<ThMission>() | |||
.eq(ThMission::getTenantId, tenantId) | |||
.eq(ThMission::getStatus, TaskStatusEnum.FLIGHT.getCode()) | |||
.eq(ThMission::getAirportId, airportId) | |||
.eq(ThMission::getMark, 1)); | |||
if (ObjectUtil.isNull(mission)) { | |||
throw new ServiceException("没有正在飞行的任务"); | |||
} | |||
List<ThInspection> inspectionList = inspectionMapper.selectListByMissionId(mission.getId()); | |||
if (CollectionUtil.isEmpty(inspectionList)) { | |||
JsonResult.success("无人机数据为空"); | |||
} | |||
List<DroneDataVo> droneDataVoList = InspectionConverMapper.INSTANCE.fromInspectionListToDroneDataVoList(inspectionList); | |||
return JsonResult.success(droneDataVoList); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param airportId | |||
* @return | |||
*/ | |||
private void check(String airportId) { | |||
if (StringUtils.isEmpty(airportId)) { | |||
throw new ServiceException("机场ID为空"); | |||
} | |||
} | |||
/** | |||
* 获取租户 | |||
* | |||
* @param tenantId | |||
* @return | |||
*/ | |||
private Tenant getTenant(Integer tenantId) { | |||
Tenant tenant = tenantMapper.selectById(tenantId); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
log.info("调用机场平台,操作无人机: 租户不存在"); | |||
throw new ServiceException("租户不存在"); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
log.info("调用机场平台,操作无人机: 机场平台URL为空"); | |||
throw new ServiceException("机场平台URL为空"); | |||
} | |||
return tenant; | |||
} | |||
} |
@@ -231,7 +231,7 @@ public class ThInspectionServiceImpl extends BaseServiceImpl<ThInspectionMapper, | |||
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL); | |||
} | |||
//根据任务id查询对应的遥测数据 | |||
List<ThInspection> listData = inspectionMapper.selectListByInspectionId(id); | |||
List<ThInspection> listData = inspectionMapper.selectListByMissionId(id); | |||
return JsonResult.success(listData); | |||
} |
@@ -0,0 +1,93 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.config.SystemConstant; | |||
import com.tuoheng.admin.entity.domain.Tenant; | |||
import com.tuoheng.admin.entity.request.airport.DroneControlRequest; | |||
import com.tuoheng.admin.entity.request.airport.PointFlightRequest; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.HttpUtils; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
import com.tuoheng.system.entity.User; | |||
import com.tuoheng.system.utils.ShiroUtils; | |||
import io.swagger.models.auth.In; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
@Slf4j | |||
@Service | |||
public class DroneControlService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
public JsonResult execute(DroneControlRequest request) { | |||
log.info("进入调用机场平台,操作无人机"); | |||
this.check(request); | |||
// 读取不同租户的机场平台url | |||
User user = ShiroUtils.getUserInfo(); | |||
Integer tenantId = user.getTenantId(); | |||
Tenant tenant = this.getTenant(tenantId); | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_POINT_FLIGH; | |||
JSONObject jsonObject = new JSONObject().parseObject(request.getValue()); | |||
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("调用机场平台方法: 操作无人机结束"); | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private void check(DroneControlRequest request) { | |||
if (StringUtils.isEmpty(request.getValue())) { | |||
throw new ServiceException("操作无人机,传参空"); | |||
} | |||
} | |||
/** | |||
* 获取租户 | |||
* | |||
* @param tenantId | |||
* @return | |||
*/ | |||
private Tenant getTenant(Integer tenantId) { | |||
Tenant tenant = tenantMapper.selectById(tenantId); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
log.info("调用机场平台,操作无人机: 租户不存在"); | |||
throw new ServiceException("租户不存在"); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
log.info("调用机场平台,操作无人机: 机场平台URL为空"); | |||
throw new ServiceException("机场平台URL为空"); | |||
} | |||
return tenant; | |||
} | |||
} |
@@ -4,9 +4,16 @@ import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
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.request.airport.PointFlightRequest; | |||
import com.tuoheng.admin.enums.AirportFlyTypeEnum; | |||
import com.tuoheng.admin.enums.InspectionTypeEnum; | |||
import com.tuoheng.admin.enums.UpdateOrCreateEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.mapper.ThMissionMapper; | |||
import com.tuoheng.admin.utils.CodeUtil; | |||
import com.tuoheng.common.exception.ServiceException; | |||
import com.tuoheng.common.utils.DateUtils; | |||
import com.tuoheng.common.utils.HttpUtils; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.common.utils.StringUtils; | |||
@@ -23,6 +30,9 @@ public class PointFlightService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private ThMissionMapper missionMapper; | |||
public JsonResult executePointFligh(PointFlightRequest request) { | |||
log.info("进入调用机场平台,执行定点飞行"); | |||
// 读取不同租户的机场平台url | |||
@@ -40,10 +50,13 @@ public class PointFlightService { | |||
throw new ServiceException("机场平台URL为空"); | |||
} | |||
// 创建应急任务 | |||
this.createMission(user, request); | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_POINT_FLIGH; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("airportId", request.getAirportId()); | |||
jsonObject.put("requestId", request.getRequestId()); | |||
jsonObject.put("requestId", request.getInspectionLine()); | |||
jsonObject.put("code", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
jsonObject.put("alt", request.getAlt()); | |||
@@ -63,4 +76,28 @@ public class PointFlightService { | |||
return JsonResult.success(); | |||
} | |||
private void createMission(User user, PointFlightRequest request) { | |||
ThMission mission = new ThMission(UpdateOrCreateEnum.CREATE.getCode()); | |||
String code = "XJRW" + CodeUtil.createCodeNo(); | |||
mission.setCode(code); | |||
mission.setName("应急任务" + code); | |||
mission.setTenantId(user.getTenantId()); | |||
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.setExecutionStartTime(DateUtils.now()); | |||
mission.setAirportFlyType(AirportFlyTypeEnum.POINTING_FLIGHT.getCode()); | |||
mission.setCreateUser(user.getId()); | |||
mission.setCreateTime(DateUtils.now()); | |||
Integer count = missionMapper.insert(mission); | |||
if (count <= 0) { | |||
log.info("创建应急任务失败"); | |||
throw new ServiceException("创建应急任务失败"); | |||
} | |||
} | |||
} |
@@ -75,7 +75,7 @@ public class WarningServiceImpl extends BaseServiceImpl<WarningMapper, Warning> | |||
*/ | |||
@Override | |||
public JsonResult getOneById(Integer id) { | |||
return null; | |||
return queryWarningByIdService.getOneById(id); | |||
} | |||
@Override |
@@ -11,7 +11,10 @@ | |||
<result column="lat" jdbcType="VARCHAR" property="lat" /> | |||
<result column="host_ip" jdbcType="VARCHAR" property="hostIp" /> | |||
<result column="altitude" jdbcType="VARCHAR" property="altitude" /> | |||
<result column="speed" jdbcType="VARCHAR" property="speed" /> | |||
<result column="fly_time" jdbcType="INTEGER" property="flyTime" /> | |||
<result column="dist_home" jdbcType="VARCHAR" property="distHome" /> | |||
<result column="ysingal" jdbcType="VARCHAR" property="ysingal" /> | |||
<result column="create_user" jdbcType="INTEGER" property="createUser" /> | |||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> | |||
<result column="update_user" jdbcType="INTEGER" property="updateUser" /> | |||
@@ -20,11 +23,11 @@ | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id, tenant_id, inspection_id, mission_id, lng, lat, host_ip, altitude, fly_time, create_user, create_time, update_user, | |||
update_time, mark | |||
id, tenant_id, inspection_id, mission_id, lng, lat, host_ip, altitude, speed, fly_time, dist_home, ysingal | |||
create_user, create_time, update_user, update_time, mark | |||
</sql> | |||
<select id="selectListByInspectionId" resultType="com.tuoheng.admin.entity.domain.ThInspection"> | |||
<select id="selectListByMissionId" resultType="com.tuoheng.admin.entity.domain.ThInspection"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from th_inspection |