Bladeren bron

无人机返航

tags/V1.0.1^2
chengwang 1 jaar geleden
bovenliggende
commit
3585d7ded7
5 gewijzigde bestanden met toevoegingen van 127 en 3 verwijderingen
  1. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java
  2. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/ReversalFlightRequest.java
  3. +7
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java
  4. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java
  5. +107
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/reversal/ReversalFlightService.java

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java Bestand weergeven

@@ -81,7 +81,7 @@ public class AirPortController {
@PostMapping("/reversalFlight")
public JsonResult reversalFlight(@RequestBody ReversalFlightRequest request){
log.info("进入无人机返航接口: request={}", request);
return JsonResult.success();
return airportService.reversalFlight(request);
}

}

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/ReversalFlightRequest.java Bestand weergeven

@@ -11,9 +11,9 @@ import lombok.Data;
public class ReversalFlightRequest {

/**
* 应急事故id
* 任务id
*/
private String accidentId;
private String inspectionId;

/**
* 校验数字符

+ 7
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java Bestand weergeven

@@ -2,6 +2,7 @@ package com.tuoheng.admin.service.third.airport;

import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.common.core.utils.JsonResult;

public interface AirportService {
@@ -25,4 +26,10 @@ public interface AirportService {
*/
JsonResult hover(DroneHoverRequest request);

/**
* 无人机返航
* @param request
* @return
*/
JsonResult reversalFlight(ReversalFlightRequest request);
}

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java Bestand weergeven

@@ -2,7 +2,9 @@ package com.tuoheng.admin.service.third.airport;

import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.admin.service.third.airport.drone.DroneService;
import com.tuoheng.admin.service.third.airport.reversal.ReversalFlightService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -28,6 +30,9 @@ public class AirportServiceImpl implements AirportService {
@Autowired
private DroneService droneService;

@Autowired
private ReversalFlightService reversalFlightService;

@Override
public JsonResult getAirportList() {
return getAirportListService.getAirportList();
@@ -58,4 +63,9 @@ public class AirportServiceImpl implements AirportService {
return droneService.hover(request.getInspectiontId());
}

@Override
public JsonResult reversalFlight(ReversalFlightRequest request) {
return reversalFlightService.reversal(request);
}

}

+ 107
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/reversal/ReversalFlightService.java Bestand weergeven

@@ -0,0 +1,107 @@
package com.tuoheng.admin.service.third.airport.reversal;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.domain.User;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionCodeEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @Author ChengWang
* @Date 2023/5/25
*/
@Service
@Slf4j
public class ReversalFlightService {

@Autowired
private InspectionMapper inspectionMapper;


public JsonResult reversal(ReversalFlightRequest request) {
User user = CurrentUserUtil.getUserInfo();
String userId = user.getId();
String tenantId = user.getTenantId();
JsonResult result = this.check(userId,tenantId,request);
if(0 != result.getCode()){
log.info("进入无人机返航校验失败:{}",result.getMsg());
}
request.setZhilin("03");
log.info("进入调用无人机平台,回仓指令值:{}",request.getZhilin());
JsonResult jsonResult = this.queryInspection(request);
if(0 != jsonResult.getCode()){
return JsonResult.error(jsonResult.getCode(),jsonResult.getMsg());
}
Inspection inspection = (Inspection) jsonResult.getData();
//回仓
JsonResult resultData = this.getReversalFlight(inspection);
if(0 != resultData.getCode()){
return JsonResult.error(jsonResult.getCode(),jsonResult.getMsg());
}

return JsonResult.success("无人机返航成功");
}

private JsonResult getReversalFlight(Inspection inspection) {
log.info("执行无人机回仓");
inspection.setStatus(InspectionStatusEnum.FLIGHT_COMPLETED.getCode());
inspection.setUpdateTime(DateUtils.now());
inspection.setUpdateUser(CurrentUserUtil.getUserId());
int count = inspectionMapper.updateById(inspection);
if(count<=0){
log.info("修改任务状态失败:{}",inspection);
throw new SecurityException("修改任务状态失败");
}
//调用机场平台返航
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_DRONE_CONTROL;
JSONObject jsonObject = new JSONObject();
jsonObject.put("airportId", inspection.getAirportId());
jsonObject.put("taskId", inspection.getId());
jsonObject.put("zhilin", "03");
jsonObject.put("msg", "回仓");
log.info("调用机场平台,无人机执行定点飞行返航:url:{}", url);
log.info("调用机场平台,原无人机执行定点飞行返航,jsonObject:{}", jsonObject);

String airPortStr = HttpUtils.doSend(url,jsonObject,null,"POST");
log.info("调用无人机平台,操作无人机:airPortStr:{}", airPortStr);
if (StringUtils.isEmpty(airPortStr)) {
log.info("原无人机执行定点飞行返航:机场接口返回数据为空,返航失败,jsonObject:{}", jsonObject);
throw new ServiceException("机场接口返回数据为空,返航失败");
}
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class);
if(0 != jsonResult.getCode()){
log.info("调用机场平台,无人机执行定点飞行:返航失败,jsonResult:{}", jsonResult.getMsg());
return JsonResult.error(-1, jsonResult.getMsg());
}
log.info("调用无人机平台返航结束");
return JsonResult.success();


}

private JsonResult queryInspection(ReversalFlightRequest request) {
Inspection inspection = inspectionMapper.selectById(request.getInspectionId());
if(ObjectUtil.isNull(inspection)){
return JsonResult.error("巡检任务为空");
}
return JsonResult.success(inspection);
}

private JsonResult check(String userId, String tenantId, ReversalFlightRequest request) {
if(StringUtils.isEmpty(request.getInspectionId())){
return JsonResult.error(EditInspectionCodeEnum.ID_IS_NULL.getCode(),EditInspectionCodeEnum.ID_IS_NULL.getMsg());
}
return JsonResult.success();
}
}

Laden…
Annuleren
Opslaan