@@ -1,6 +1,6 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.service.airport.AirportService; | |||
import com.tuoheng.admin.service.third.airport.AirportService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; |
@@ -13,6 +13,7 @@ import com.tuoheng.admin.mapper.InspectionHistoryMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.service.third.airport.AirportService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.utils.*; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -42,6 +43,9 @@ public class ExecuteInspectionService { | |||
@Autowired | |||
private InspectionHistoryMapper inspectionHistoryMapper; | |||
@Autowired | |||
private AirportService airportService; | |||
/** | |||
* 重新提交任务 | |||
* | |||
@@ -61,7 +65,7 @@ public class ExecuteInspectionService { | |||
Inspection inspection = (Inspection) result.getData(); | |||
// 立即执行任务 | |||
this.executeTask(userId, tenantId, inspection); | |||
airportService.executeTask(userId, inspection); | |||
log.info("立即执行任务业务:立即执行成功:id:{}", inspection.getId()); | |||
return JsonResult.success(); | |||
@@ -94,83 +98,4 @@ public class ExecuteInspectionService { | |||
return JsonResult.success(inspection); | |||
} | |||
/** | |||
* 调用机场平台 | |||
* | |||
* @param tenantId | |||
* @param inspection | |||
* @return | |||
*/ | |||
public JsonResult executeTask(String userId, String tenantId, Inspection inspection) { | |||
log.info("进入调用机场平台方法"); | |||
// 读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(inspection.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
log.info("进入调用机场平台方法: 租户不存在"); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getCode(), ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
log.info("进入调用机场平台方法: 机场平台URL为空"); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_URL_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_URL_IS_NULL.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_EXECUTE_TASK; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("taskId", inspection.getInspectionLine()); | |||
jsonObject.put("requestId", inspection.getId()); | |||
jsonObject.put("code", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
log.info("进入调用机场平台方法: url:{}", url); | |||
log.info("进入调用机场平台方法: jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("立即执行任务业务:机场接口返回数据为空,任务id:{},任务名称:{},机场id:{},机场名称:{}, 路线id:{},路线名称:{}", | |||
inspection.getId(), inspection.getName(), inspection.getAirportId(), inspection.getAirportName(), inspection.getInspectionLine(), inspection.getInspectionLineName()); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getMsg()); | |||
} | |||
this.updateInspection(userId, inspection); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (jsonResult.getCode() != 0) { | |||
log.info("立即执行任务业务:机场接口返回结果:失败:{}", jsonResult.getMsg()); | |||
this.insertInspectionHistory(userId, tenantId, inspection, jsonResult.getMsg()); | |||
return JsonResult.error(jsonResult.getMsg()); | |||
} else { | |||
return JsonResult.success(); | |||
} | |||
} | |||
/** | |||
* 修改任务执行状态 | |||
* | |||
* @param userId | |||
* @param inspection | |||
*/ | |||
private void updateInspection(String userId, Inspection inspection) { | |||
inspection.setExecutionStatus(2); | |||
inspection.setUpdateUser(userId); | |||
inspection.setUpdateTime(DateUtils.now()); | |||
inspectionMapper.update(inspection); | |||
} | |||
/** | |||
* 更新任务中 | |||
* | |||
* @param tenantId | |||
* @param inspection | |||
*/ | |||
private void insertInspectionHistory(String userId, String tenantId, Inspection inspection, String msg) { | |||
InspectionHistory inspectionHistory = new InspectionHistory(); | |||
inspectionHistory.setTenantId(tenantId); | |||
inspectionHistory.setInspectionId(inspection.getId()); | |||
inspectionHistory.setHistoryName(msg); | |||
inspectionHistory.setCreateUser(userId); | |||
inspectionHistory.setCreateTime(DateUtils.now()); | |||
inspectionHistoryMapper.insert(inspectionHistory); | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.tuoheng.admin.service.airport; | |||
package com.tuoheng.admin.service.third.airport; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
public interface AirportService { | |||
@@ -8,4 +9,5 @@ public interface AirportService { | |||
JsonResult getAirLineList(Integer droneId); | |||
JsonResult executeTask(String userId, Inspection inspection); | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Service | |||
public class AirportServiceImpl implements AirportService { | |||
@Autowired | |||
private GetAirportListService getAirportListService; | |||
@Autowired | |||
private GetAirLineListService getAirLineListService; | |||
@Autowired | |||
private ExecuteTaskService executeTaskService; | |||
@Override | |||
public JsonResult getAirportList() { | |||
return getAirportListService.getAirportList(); | |||
} | |||
@Override | |||
public JsonResult getAirLineList(Integer droneId) { | |||
return getAirLineListService.getAirLineList(droneId); | |||
} | |||
@Override | |||
public JsonResult executeTask(String userId, Inspection inspection) { | |||
return executeTaskService.executeTask(userId, inspection); | |||
} | |||
} |
@@ -0,0 +1,106 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionHistory; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.code.inspection.ExecuteInspectionCodeEnum; | |||
import com.tuoheng.admin.mapper.InspectionHistoryMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.common.core.utils.*; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Slf4j | |||
@Service | |||
public class ExecuteTaskService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private InspectionHistoryMapper inspectionHistoryMapper; | |||
public JsonResult executeTask(String userId, Inspection inspection) { | |||
log.info("进入调用机场平台方法"); | |||
// 读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(inspection.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
log.info("进入调用机场平台方法: 租户不存在"); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getCode(), ExecuteInspectionCodeEnum.TENANT_IS_NOT_EXIST.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
log.info("进入调用机场平台方法: 机场平台URL为空"); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_URL_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_URL_IS_NULL.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_EXECUTE_TASK; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("taskId", inspection.getInspectionLine()); | |||
jsonObject.put("requestId", inspection.getId()); | |||
jsonObject.put("code", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
log.info("进入调用机场平台方法: url:{}", url); | |||
log.info("进入调用机场平台方法: jsonObject:{}", jsonObject); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
log.info("立即执行任务业务:机场接口返回数据为空,飞行失败,任务id:{},任务名称:{},机场id:{},机场名称:{}, 路线id:{},路线名称:{}", | |||
inspection.getId(), inspection.getName(), inspection.getAirportId(), inspection.getAirportName(), inspection.getInspectionLine(), inspection.getInspectionLineName()); | |||
// 飞行失败 | |||
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); | |||
this.updateInspection(userId, inspection); | |||
return JsonResult.error(ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getCode(), ExecuteInspectionCodeEnum.AIRPORT_RETURN_DATA_IS_NULL.getMsg()); | |||
} | |||
this.updateInspection(userId, inspection); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (jsonResult.getCode() != 0) { | |||
log.info("立即执行任务业务:机场接口返回结果:失败:{}", jsonResult.getMsg()); | |||
this.insertInspectionHistory(userId, inspection.getTenantId(), inspection, jsonResult.getMsg()); | |||
return JsonResult.error(jsonResult.getMsg()); | |||
} else { | |||
return JsonResult.success(); | |||
} | |||
} | |||
/** | |||
* 修改任务执行状态 | |||
* | |||
* @param userId | |||
* @param inspection | |||
*/ | |||
private void updateInspection(String userId, Inspection inspection) { | |||
inspection.setExecutionStatus(2); | |||
inspection.setUpdateUser(userId); | |||
inspection.setUpdateTime(DateUtils.now()); | |||
inspectionMapper.update(inspection); | |||
} | |||
/** | |||
* 更新任务中 | |||
* | |||
* @param tenantId | |||
* @param inspection | |||
*/ | |||
private void insertInspectionHistory(String userId, String tenantId, Inspection inspection, String msg) { | |||
InspectionHistory inspectionHistory = new InspectionHistory(); | |||
inspectionHistory.setTenantId(tenantId); | |||
inspectionHistory.setInspectionId(inspection.getId()); | |||
inspectionHistory.setHistoryName(msg); | |||
inspectionHistory.setCreateUser(userId); | |||
inspectionHistory.setCreateTime(DateUtils.now()); | |||
inspectionHistoryMapper.insert(inspectionHistory); | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
package com.tuoheng.admin.service.airport; | |||
package com.tuoheng.admin.service.third.airport; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
@@ -11,44 +11,19 @@ import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.io.UnsupportedEncodingException; | |||
import java.net.URLEncoder; | |||
import java.util.Objects; | |||
@Slf4j | |||
@Service | |||
public class AirportServiceImpl implements AirportService { | |||
public class GetAirLineListService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Override | |||
public JsonResult getAirportList() { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_LIST; | |||
String param = "page=1&limit=100&tenantCode=" + tenant.getCode(); | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} | |||
return jsonResult; | |||
} | |||
@Override | |||
public JsonResult getAirLineList(Integer droneId) { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||
@@ -69,4 +44,5 @@ public class AirportServiceImpl implements AirportService { | |||
} | |||
return jsonResult; | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.enums.code.AriportCodeEnum; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
@Slf4j | |||
@Service | |||
public class GetAirportListService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
public JsonResult getAirportList() { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(CurrentUserUtil.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant)) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
if (StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
return JsonResult.error(AriportCodeEnum.GET_NO_TENANT.getCode(), AriportCodeEnum.GET_NO_TENANT.getMsg()); | |||
} | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_LIST; | |||
String param = "page=1&limit=100&tenantCode=" + tenant.getCode(); | |||
String airPortStr = HttpUtils.sendGet(url, param); | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(jsonResult.getData()) && jsonResult.getCode() != 0)) { | |||
return JsonResult.error(AriportCodeEnum.BAD_REQUEST.getCode(), AriportCodeEnum.BAD_REQUEST.getMsg()); | |||
} | |||
return jsonResult; | |||
} | |||
} |
@@ -1,23 +1,12 @@ | |||
package com.tuoheng.admin.task; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.InspectionTypeEnum; | |||
import com.tuoheng.admin.enums.MarkTypeEnum; | |||
import com.tuoheng.admin.enums.TaskStatusEnum; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.service.inspection.IInspectionService; | |||
import com.tuoheng.common.core.enums.ServiceExceptionEnum; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.HttpUtils; | |||
import com.tuoheng.common.core.utils.JacksonUtil; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.admin.service.third.airport.AirportService; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import com.xxl.job.core.handler.annotation.XxlJob; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -39,14 +28,11 @@ public class AirportTask { | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private IInspectionService inspectionService; | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
private AirportService airportService; | |||
@XxlJob("freewayAirportTaskHandler") | |||
public void airportTaskHandler() { | |||
//查询当前时间正负1分钟的时间跨度,xxljob执行频率为1分钟1次 | |||
// 查询当前时间正负1分钟的时间跨度,xxljob执行频率为1分钟1次 | |||
long start = new Date().getTime() - 1 * 60000L; | |||
long end = new Date().getTime() + 1 * 60000L; | |||
Date startTime = new Date(start); | |||
@@ -62,48 +48,15 @@ public class AirportTask { | |||
.eq(Inspection::getExecutionStatus, 1) | |||
//任务待飞行 | |||
.eq(Inspection::getStatus, InspectionStatusEnum.WAIT_FLIGHT.getCode())); | |||
if (StringUtils.isNotEmpty(inspectionList)) { | |||
for (Inspection inspection : inspectionList) { | |||
log.info("执行定时执行飞行任务开始:" + inspection.getId()); | |||
JsonResult jsonResult = this.executeTask(inspection); | |||
Inspection inspectionUpdate = new Inspection(); | |||
inspectionUpdate.setId(inspection.getId()); | |||
inspectionUpdate.setExecutionStatus(2); | |||
if (jsonResult.getCode() != 0 && ObjectUtil.isEmpty(jsonResult.getData())) { | |||
// 12任务飞行失败(机场) | |||
inspectionUpdate.setStatus(TaskStatusEnum.FAIL.getCode()); | |||
} | |||
inspectionMapper.updateById(inspectionUpdate); | |||
log.info("执行定时执行飞行任务结束"); | |||
} | |||
log.info("执行定时执行飞行任务:机场任务数" + inspectionList.size()); | |||
if (StringUtils.isEmpty(inspectionList)) { | |||
return; | |||
} | |||
} | |||
private JsonResult executeTask(Inspection inspection) { | |||
//读取不同租户的机场平台url | |||
Tenant tenant = tenantMapper.selectById(inspection.getTenantId()); | |||
if (ObjectUtil.isEmpty(tenant) && StringUtils.isEmpty(tenant.getAirportUrl())) { | |||
throw new ServiceException(ServiceExceptionEnum.GET_NO_DATA); | |||
} | |||
String url = tenant.getAirportUrl() + SystemConstant.API_AIRPORT_EXECUTE_TASK; | |||
JSONObject jsonObject = new JSONObject(); | |||
jsonObject.put("taskId", inspection.getInspectionLine()); | |||
jsonObject.put("requestId", String.valueOf(inspection.getId())); | |||
jsonObject.put("code", "gs"); // 与机场平台约定好的 | |||
jsonObject.put("tenantCode", tenant.getCode()); | |||
String airPortStr = HttpUtils.doSend(url, jsonObject, null, "POST"); | |||
if (StringUtils.isEmpty(airPortStr)) { | |||
return JsonResult.error("机场接口返回数据为空"); | |||
} | |||
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); | |||
if (jsonResult.getCode() != 0) { | |||
return JsonResult.error(jsonResult.getMsg()); | |||
for (Inspection inspection : inspectionList) { | |||
log.info("执行定时执行飞行任务开始: inspectionId:{}" + inspection.getId()); | |||
airportService.executeTask("", inspection); | |||
log.info("执行定时执行飞行任务结束: inspectionId:{}"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |