Browse Source

任务管理接口

tags/V1.0.1^2
chengwang 1 year ago
parent
commit
b316d05c6e
9 changed files with 122 additions and 89 deletions
  1. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/FlightData.java
  2. +2
    -32
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/inspection/AddInspectionRequest.java
  3. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/inspection/InspectionRequest.java
  4. +15
    -10
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/inspection/InspectionDetailsVo.java
  5. +1
    -12
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/AddInspectionCodeEnum.java
  6. +17
    -28
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java
  7. +36
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/query/QueryInspectionDetailsByIdService.java
  8. +40
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/TimeUtil.java
  9. +1
    -7
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/InspectionServiceTest.java

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/FlightData.java View File

*/ */
private String mileage; private String mileage;


/**
* 飞行时间
*/
private Integer flyTime;

} }

+ 2
- 32
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/inspection/AddInspectionRequest.java View File

*/ */
private String inspectionLineName; private String inspectionLineName;


/**
* 巡检任务类型: 1 临时巡检(目前只有该一种类型)
*/
private Integer type;

/** /**
* 巡检方式类型: 1 无人机 2机场巡逻 3 飞手值飞 * 巡检方式类型: 1 无人机 2机场巡逻 3 飞手值飞
*/ */
private Integer inspectionType; private Integer inspectionType;


/**
* 航道Id
*/
private String channelId;

/**
* 航道名称
*/
private String channelName;

/**
* 航段Id
*/
private String legId;

/**
* 航段名称
*/
private String legName;

/** /**
* 是否直播,1:实时 2:离线 默认:null * 是否直播,1:实时 2:离线 默认:null
*/ */
private Date inspectionTime; private Date inspectionTime;


/** /**
* 算法实例
*/
private String dspServiceInstId;

/**
* 备注
* 飞行高度
*/ */
private String note;
private String flyHeight;


} }

+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/inspection/InspectionRequest.java View File

*/ */
private String mileage; private String mileage;


/**
* 飞行时间
*/
private Integer flyTime;

} }

+ 15
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/inspection/InspectionDetailsVo.java View File

*/ */
private Integer inspectionType; private Integer inspectionType;


/**
* 航道名称
*/
private String channelName;

/**
* 航段名称
*/
private String legName;

/** /**
* 巡检机场名称 * 巡检机场名称
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date executionEndTime; private Date executionEndTime;


/**
* 飞行时间
*/
private String flyTime;

/**
* 飞行里程
*/
private String mileage;

/**
* 备注
*/
private String note;

/** /**
* 飞行失败数据 * 飞行失败数据
*/ */

+ 1
- 12
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/inspection/AddInspectionCodeEnum.java View File



ADD_IS_FAILED(1230100, "添加任务失败"), ADD_IS_FAILED(1230100, "添加任务失败"),
NAME_IS_NULL(1230101, "任务名为空"), NAME_IS_NULL(1230101, "任务名为空"),
TYPE_IS_NULL(1230102, "任务类型为空"),
ROAD_IS_NULL(1230103, "航道信息为空"),
SECTION_IS_NULL(1230104, "航段信息为空"),
INSPECTION_TYPE_IS_NULL(1230105, "巡检方式为空"), INSPECTION_TYPE_IS_NULL(1230105, "巡检方式为空"),
AIRPORT_IS_NULL(1230106, "巡检机场为空"), AIRPORT_IS_NULL(1230106, "巡检机场为空"),
INSPECTION_LINE_IS_NULL(1230107, "巡检路线为空"), INSPECTION_LINE_IS_NULL(1230107, "巡检路线为空"),

LIVE_IS_NULL(1230108, "是否直播为空"), LIVE_IS_NULL(1230108, "是否直播为空"),

START_LONGITUDE_IS_NULL(1230109, "起点经度为空"), START_LONGITUDE_IS_NULL(1230109, "起点经度为空"),

START_LATITUDE_IS_NULL(1230110, "起点纬度为空"), START_LATITUDE_IS_NULL(1230110, "起点纬度为空"),

END_LONGITUDE_IS_NULL(1230111, "终点经度为空"), END_LONGITUDE_IS_NULL(1230111, "终点经度为空"),

END_LATITUDE_IS_NULL(1230112, "终点纬度为空"), END_LATITUDE_IS_NULL(1230112, "终点纬度为空"),

INSPECTION_TIME_IS_NULL(1230113, "巡检时间为空"), INSPECTION_TIME_IS_NULL(1230113, "巡检时间为空"),
ROAD_IS_NOT_EXIST(1230114, "航道不存在"),
SECTION_IS_NOT_EXIST(1230115, "航段不存在"),
USER_IS_NOT_EXIST(1230116, "用户不存在"), USER_IS_NOT_EXIST(1230116, "用户不存在"),
DEPT_IS_NOT_EXIST(1230117, "部门不存在"),
CALL_PILOT_IS_FAILED(123018, "对接飞手平台失败"), CALL_PILOT_IS_FAILED(123018, "对接飞手平台失败"),
CALL_DSP_IS_FAILED(1230119, "对接DSP平台失败"), CALL_DSP_IS_FAILED(1230119, "对接DSP平台失败"),
FLY_HEIGHT_IS_NULL(1230117, "飞行高度为空"),
CALL_AMAP_IS_FAILED(1230120, "对接高德地图平台失败"); CALL_AMAP_IS_FAILED(1230120, "对接高德地图平台失败");


/** /**

+ 17
- 28
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java View File

import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils; import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


*/ */
public JsonResult add(AddInspectionRequest addInspectionRequest) { public JsonResult add(AddInspectionRequest addInspectionRequest) {
log.info("进入添加任务业务"); log.info("进入添加任务业务");
String userId = CurrentUserUtil.getUserId();
String tenantId = CurrentUserUtil.getTenantId();
User user = CurrentUserUtil.getUserInfo();
String userId = user.getId();
String tenantId = user.getTenantId();
JsonResult result = this.checkParam(userId, tenantId, addInspectionRequest); JsonResult result = this.checkParam(userId, tenantId, addInspectionRequest);
if (0 != result.getCode()) { if (0 != result.getCode()) {
log.info("添加任务业务:校验参数失败:{}", result.getMsg()); log.info("添加任务业务:校验参数失败:{}", result.getMsg());
return result; return result;
} }
User user = (User) result.getData();
//User user = (User) result.getData();


// 构造inspection对象 // 构造inspection对象
Inspection inspection = this.buildInspection(user, tenantId, addInspectionRequest); Inspection inspection = this.buildInspection(user, tenantId, addInspectionRequest);


// 调用第三方平台 // 调用第三方平台
result = this.callThirdPlatform(user, tenantId, inspection); result = this.callThirdPlatform(user, tenantId, inspection);
if (0 != result.getCode()) {
log.info("添加任务业务:对接第三方平台失败:{}", result.getMsg());
return result;
}
// if (0 != result.getCode()) {
// log.info("添加任务业务:对接第三方平台失败:{}", result.getMsg());
// return result;
// }
Integer rowId = inspectionMapper.insert(inspection); Integer rowId = inspectionMapper.insert(inspection);
log.info("添加任务, 返回结果: rowId={}", rowId); log.info("添加任务, 返回结果: rowId={}", rowId);
if (rowId <= 0) { if (rowId <= 0) {
if (StringUtils.isEmpty(addInspectionRequest.getName())) { if (StringUtils.isEmpty(addInspectionRequest.getName())) {
return JsonResult.error(AddInspectionCodeEnum.NAME_IS_NULL.getCode(), AddInspectionCodeEnum.NAME_IS_NULL.getMsg()); return JsonResult.error(AddInspectionCodeEnum.NAME_IS_NULL.getCode(), AddInspectionCodeEnum.NAME_IS_NULL.getMsg());
} }

if (null == addInspectionRequest.getType()) {
return JsonResult.error(AddInspectionCodeEnum.TYPE_IS_NULL.getCode(), AddInspectionCodeEnum.TYPE_IS_NULL.getMsg());
}

if (null == addInspectionRequest.getInspectionType()) {
return JsonResult.error(AddInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getCode(), AddInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getMsg());
}
if (null == addInspectionRequest.getChannelId() || StringUtils.isEmpty(addInspectionRequest.getChannelName())) {
return JsonResult.error(AddInspectionCodeEnum.ROAD_IS_NULL.getCode(), AddInspectionCodeEnum.ROAD_IS_NULL.getMsg());
}

if (null == addInspectionRequest.getLegId() || StringUtils.isEmpty(addInspectionRequest.getLegName())) {
return JsonResult.error(AddInspectionCodeEnum.SECTION_IS_NULL.getCode(), AddInspectionCodeEnum.SECTION_IS_NULL.getMsg());
if(null == addInspectionRequest.getInspectionType()){
return JsonResult.error(AddInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getCode(),AddInspectionCodeEnum.INSPECTION_TYPE_IS_NULL.getMsg());
} }
if (InspectionTypeEnum.AIRPORT.getCode() == addInspectionRequest.getInspectionType()) { if (InspectionTypeEnum.AIRPORT.getCode() == addInspectionRequest.getInspectionType()) {
// 巡检方式:机场巡逻,可选择巡检机场和巡检路线 // 巡检方式:机场巡逻,可选择巡检机场和巡检路线
if (StringUtils.isEmpty(addInspectionRequest.getEndLongitude())) { if (StringUtils.isEmpty(addInspectionRequest.getEndLongitude())) {
return JsonResult.error(AddInspectionCodeEnum.END_LONGITUDE_IS_NULL.getCode(), AddInspectionCodeEnum.END_LONGITUDE_IS_NULL.getMsg()); return JsonResult.error(AddInspectionCodeEnum.END_LONGITUDE_IS_NULL.getCode(), AddInspectionCodeEnum.END_LONGITUDE_IS_NULL.getMsg());
} }
if (StringUtils.isEmpty(addInspectionRequest.getStartLatitude())) {
if (StringUtils.isEmpty(addInspectionRequest.getEndLatitude())) {
return JsonResult.error(AddInspectionCodeEnum.END_LATITUDE_IS_NULL.getCode(), AddInspectionCodeEnum.END_LATITUDE_IS_NULL.getMsg()); return JsonResult.error(AddInspectionCodeEnum.END_LATITUDE_IS_NULL.getCode(), AddInspectionCodeEnum.END_LATITUDE_IS_NULL.getMsg());
} }
} }
if (null == addInspectionRequest.getInspectionTime()) { if (null == addInspectionRequest.getInspectionTime()) {
return JsonResult.error(AddInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getCode(), AddInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getMsg()); return JsonResult.error(AddInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getCode(), AddInspectionCodeEnum.INSPECTION_TIME_IS_NULL.getMsg());
} }
if(StringUtils.isEmpty(addInspectionRequest.getFlyHeight())){
return JsonResult.error(AddInspectionCodeEnum.FLY_HEIGHT_IS_NULL.getCode(),AddInspectionCodeEnum.FLY_HEIGHT_IS_NULL.getMsg());
}
return JsonResult.success(); return JsonResult.success();
} }


*/ */
private Inspection buildInspection(User user, String tenantId, AddInspectionRequest addInspectionRequest) { private Inspection buildInspection(User user, String tenantId, AddInspectionRequest addInspectionRequest) {
Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest); Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest);
//Inspection inspection = new Inspection();
//BeanUtils.copyProperties(addInspectionRequest,inspection);
String code = DateUtils.generateCode("XJRW"); String code = DateUtils.generateCode("XJRW");
inspection.setCode(code); inspection.setCode(code);
inspection.setTenantId(tenantId); inspection.setTenantId(tenantId);
inspection.setCreateTime(DateUtils.now()); inspection.setCreateTime(DateUtils.now());
inspection.setMobile(user.getMobile()); inspection.setMobile(user.getMobile());
inspection.setStatus(InspectionStatusEnum.WAIT_FLIGHT.getCode()); inspection.setStatus(InspectionStatusEnum.WAIT_FLIGHT.getCode());
if (StringUtils.isEmpty(addInspectionRequest.getDspServiceInstId())) {
//提供默认服务实例id
DspServiceInst dspServiceInst = dspServiceInstMapper.selectOne(Wrappers.<DspServiceInst>lambdaQuery()
.eq(DspServiceInst::getIsDefault, CommonConstants.ONE));
inspection.setDspServiceInstId(dspServiceInst.getDspServiceInstId());
}
if (InspectionTypeEnum.AIRPORT.getCode() == addInspectionRequest.getInspectionType()) { if (InspectionTypeEnum.AIRPORT.getCode() == addInspectionRequest.getInspectionType()) {
// 机场巡逻,只有直播,将isLive设置为1 // 机场巡逻,只有直播,将isLive设置为1
inspection.setIsLive(1); inspection.setIsLive(1);

+ 36
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/query/QueryInspectionDetailsByIdService.java View File

package com.tuoheng.admin.service.inspection.query; package com.tuoheng.admin.service.inspection.query;


import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.conver.InspectionConverMapper; import com.tuoheng.admin.conver.InspectionConverMapper;
import com.tuoheng.admin.entity.domain.FlightData;
import com.tuoheng.admin.entity.domain.Inspection; import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.domain.InspectionHistory; import com.tuoheng.admin.entity.domain.InspectionHistory;
import com.tuoheng.admin.enums.InspectionStatusEnum; import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.MarkEnum; import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.code.inspection.QueryInspectionDetailsByIdCodeEnum; import com.tuoheng.admin.enums.code.inspection.QueryInspectionDetailsByIdCodeEnum;
import com.tuoheng.admin.mapper.FlightDataMapper;
import com.tuoheng.admin.mapper.InspectionHistoryMapper; import com.tuoheng.admin.mapper.InspectionHistoryMapper;
import com.tuoheng.admin.mapper.InspectionMapper; import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.utils.CurrentUserUtil; import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.entity.vo.inspection.InspectionDetailsVo; import com.tuoheng.admin.entity.vo.inspection.InspectionDetailsVo;
import com.tuoheng.admin.utils.TimeUtil;
import com.tuoheng.common.core.utils.CommonNumberTypeUtils;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils; import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;


import java.util.List; import java.util.List;



/** /**
* 根据Id查询巡检任务详情业务层处理 * 根据Id查询巡检任务详情业务层处理
* *
@Autowired @Autowired
private InspectionHistoryMapper inspectionHistoryMapper; private InspectionHistoryMapper inspectionHistoryMapper;


@Autowired
private FlightDataMapper flightDataMapper;

public JsonResult getInspectionDetails(String id) { public JsonResult getInspectionDetails(String id) {
log.info("进入查询巡检任务详情业务"); log.info("进入查询巡检任务详情业务");
String tenantId = CurrentUserUtil.getTenantId(); String tenantId = CurrentUserUtil.getTenantId();


InspectionDetailsVo inspectionDetailsVo = InspectionConverMapper.INSTANCE.fromInspectionToInspectionDetailsVo(inspection); InspectionDetailsVo inspectionDetailsVo = InspectionConverMapper.INSTANCE.fromInspectionToInspectionDetailsVo(inspection);


//获取最后一次的飞行时间 获取飞行里程
this.getFlyTimeAndMileage(inspection,inspectionDetailsVo);

// 任务失败,查询任务失败记录 // 任务失败,查询任务失败记录
if (InspectionStatusEnum.FLIGHT_FAILED.getCode() == inspection.getStatus()) { if (InspectionStatusEnum.FLIGHT_FAILED.getCode() == inspection.getStatus()) {
List<InspectionHistory> inspectionHistoryList = this.getInspectionHistoryList(id); List<InspectionHistory> inspectionHistoryList = this.getInspectionHistoryList(id);
return JsonResult.success(inspectionDetailsVo); return JsonResult.success(inspectionDetailsVo);
} }


private void getFlyTimeAndMileage(Inspection inspection, InspectionDetailsVo inspectionDetailsVo) {
//任务判断
if(inspectionDetailsVo.getStatus().equals(InspectionStatusEnum.FLIGHT_COMPLETED.getCode())
|| inspectionDetailsVo.getStatus().equals(InspectionStatusEnum.IN_FLIGHT.getCode())){
List<FlightData> flightDataList = flightDataMapper.selectList(Wrappers.<FlightData>lambdaQuery()
.eq(FlightData::getInspectionId, inspection.getId())
.eq(FlightData::getMark, MarkEnum.VALID.getCode())
.orderByDesc(FlightData::getCreateTime));
if(CollectionUtils.isNotEmpty(flightDataList) && flightDataList.size() > 0 ){
FlightData temp = flightDataList.get(0);
FlightData temp1 = flightDataList.get(flightDataList.size()-1);
//飞行时间
inspectionDetailsVo.setFlyTime(TimeUtil.getFormatFlyTime(temp.getFlyTime() * 1000));
//飞行路程
Double mileage = (Double.parseDouble(temp.getMileage()) - Double.parseDouble(temp1.getMileage()))/ 1000;
double round = CommonNumberTypeUtils.round(mileage, 2) ;
inspectionDetailsVo.setMileage(round + "公里");
}
}

}

/** /**
* 检查参数 * 检查参数
* *

+ 40
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/TimeUtil.java View File

package com.tuoheng.admin.utils;

import java.util.concurrent.TimeUnit;

public class TimeUtil {

/**
*
* @param milliseconds 毫秒
* @return
*/
public static String getFormatFlyTime(long milliseconds){

long day = TimeUnit.MILLISECONDS.toDays(milliseconds);

long hours = TimeUnit.MILLISECONDS.toHours(milliseconds)
- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(milliseconds));

long minutes = TimeUnit.MILLISECONDS.toMinutes(milliseconds)
- TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(milliseconds));

long seconds = TimeUnit.MILLISECONDS.toSeconds(milliseconds)
- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds));
System.out.println("milliseconds :" + milliseconds);

if(day!=0L){
return String.format("%d 天 %d 时 %d 分 %d 秒", day, hours, minutes, seconds);
}else if(hours!=0L){
return String.format("%d 时 %d 分 %d 秒", hours, minutes, seconds);
}else if(minutes!=0L ){
return String.format("%d 分 %d 秒", minutes, seconds);
}else{
return String.format("%d 秒",seconds);
}
}

public static void main(String[] args) {
System.out.println(getFormatFlyTime(10000));
}
}

+ 1
- 7
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/InspectionServiceTest.java View File

@Test @Test
public void testAdd() { public void testAdd() {
AddInspectionRequest request = new AddInspectionRequest(); AddInspectionRequest request = new AddInspectionRequest();
request.setType(1);
request.setName("test-2022112501-11");
request.setChannelId("1");
request.setChannelName("G2");
request.setLegId("1");
request.setLegName("航段1");
request.setInspectionType(1); request.setInspectionType(1);
request.setAirportId(1); request.setAirportId(1);
request.setAirportName("禄口-2022112501"); request.setAirportName("禄口-2022112501");
request.setInspectionLine(1); request.setInspectionLine(1);
request.setInspectionLineName("路线1"); request.setInspectionLineName("路线1");
request.setInspectionTime(DateUtils.now());



JSONObject json = (JSONObject) JSONObject.toJSON(request); JSONObject json = (JSONObject) JSONObject.toJSON(request);
log.info("-----> 新增任务请求参数:json={}", json); log.info("-----> 新增任务请求参数:json={}", json);

Loading…
Cancel
Save