Selaa lähdekoodia

任务管理接口

tags/V1.0.1^2
chengwang 1 vuosi sitten
vanhempi
commit
b316d05c6e
9 muutettua tiedostoa jossa 122 lisäystä ja 89 poistoa
  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 Näytä tiedosto

@@ -128,4 +128,9 @@ public class FlightData extends BaseEntity {
*/
private String mileage;

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

}

+ 2
- 32
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/inspection/AddInspectionRequest.java Näytä tiedosto

@@ -48,36 +48,11 @@ public class AddInspectionRequest {
*/
private String inspectionLineName;

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

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

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

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

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

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

/**
* 是否直播,1:实时 2:离线 默认:null
*/
@@ -112,13 +87,8 @@ public class AddInspectionRequest {
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 Näytä tiedosto

@@ -92,4 +92,9 @@ public class InspectionRequest implements Serializable {
*/
private String mileage;

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

}

+ 15
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/inspection/InspectionDetailsVo.java Näytä tiedosto

@@ -40,16 +40,6 @@ public class InspectionDetailsVo {
*/
private Integer inspectionType;

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

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

/**
* 巡检机场名称
*/
@@ -106,6 +96,21 @@ public class InspectionDetailsVo {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
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 Näytä tiedosto

@@ -13,30 +13,19 @@ public enum AddInspectionCodeEnum {

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

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

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

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

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

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

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

/**

+ 17
- 28
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/add/AddInspectionService.java Näytä tiedosto

@@ -21,6 +21,7 @@ import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@@ -57,24 +58,25 @@ public class AddInspectionService {
*/
public JsonResult add(AddInspectionRequest addInspectionRequest) {
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);
if (0 != result.getCode()) {
log.info("添加任务业务:校验参数失败:{}", result.getMsg());
return result;
}
User user = (User) result.getData();
//User user = (User) result.getData();

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

// 调用第三方平台
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);
log.info("添加任务, 返回结果: rowId={}", rowId);
if (rowId <= 0) {
@@ -96,20 +98,8 @@ public class AddInspectionService {
if (StringUtils.isEmpty(addInspectionRequest.getName())) {
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()) {
// 巡检方式:机场巡逻,可选择巡检机场和巡检路线
@@ -134,13 +124,16 @@ public class AddInspectionService {
if (StringUtils.isEmpty(addInspectionRequest.getEndLongitude())) {
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());
}
}
if (null == addInspectionRequest.getInspectionTime()) {
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();
}

@@ -154,6 +147,8 @@ public class AddInspectionService {
*/
private Inspection buildInspection(User user, String tenantId, AddInspectionRequest addInspectionRequest) {
Inspection inspection = InspectionConverMapper.INSTANCE.fromAddInspectionRequestToInspection(addInspectionRequest);
//Inspection inspection = new Inspection();
//BeanUtils.copyProperties(addInspectionRequest,inspection);
String code = DateUtils.generateCode("XJRW");
inspection.setCode(code);
inspection.setTenantId(tenantId);
@@ -161,12 +156,6 @@ public class AddInspectionService {
inspection.setCreateTime(DateUtils.now());
inspection.setMobile(user.getMobile());
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()) {
// 机场巡逻,只有直播,将isLive设置为1
inspection.setIsLive(1);

+ 36
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspection/query/QueryInspectionDetailsByIdService.java Näytä tiedosto

@@ -1,17 +1,24 @@
package com.tuoheng.admin.service.inspection.query;

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.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.InspectionHistory;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.MarkEnum;
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.InspectionMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
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.StringUtils;
import lombok.extern.slf4j.Slf4j;
@@ -20,6 +27,7 @@ import org.springframework.stereotype.Service;

import java.util.List;


/**
* 根据Id查询巡检任务详情业务层处理
*
@@ -37,6 +45,9 @@ public class QueryInspectionDetailsByIdService {
@Autowired
private InspectionHistoryMapper inspectionHistoryMapper;

@Autowired
private FlightDataMapper flightDataMapper;

public JsonResult getInspectionDetails(String id) {
log.info("进入查询巡检任务详情业务");
String tenantId = CurrentUserUtil.getTenantId();
@@ -50,6 +61,9 @@ public class QueryInspectionDetailsByIdService {

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

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

// 任务失败,查询任务失败记录
if (InspectionStatusEnum.FLIGHT_FAILED.getCode() == inspection.getStatus()) {
List<InspectionHistory> inspectionHistoryList = this.getInspectionHistoryList(id);
@@ -62,6 +76,28 @@ public class QueryInspectionDetailsByIdService {
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 Näytä tiedosto

@@ -0,0 +1,40 @@
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 Näytä tiedosto

@@ -56,18 +56,12 @@ public class InspectionServiceTest {
@Test
public void testAdd() {
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.setAirportId(1);
request.setAirportName("禄口-2022112501");
request.setInspectionLine(1);
request.setInspectionLineName("路线1");
request.setInspectionTime(DateUtils.now());


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

Loading…
Peruuta
Tallenna