|
|
@@ -4,14 +4,12 @@ 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 com.tuoheng.common.core.utils.HttpUtils; |
|
|
|
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; |
|
|
@@ -23,14 +21,8 @@ public class ExecuteTaskService { |
|
|
|
@Autowired |
|
|
|
private TenantMapper tenantMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private InspectionMapper inspectionMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private InspectionHistoryMapper inspectionHistoryMapper; |
|
|
|
|
|
|
|
public JsonResult executeTask(String userId, Inspection inspection) { |
|
|
|
log.info("进入调用机场平台方法"); |
|
|
|
log.info("进入调用机场平台方法,执行任务"); |
|
|
|
// 读取不同租户的机场平台url |
|
|
|
Tenant tenant = tenantMapper.selectById(inspection.getTenantId()); |
|
|
|
if (ObjectUtil.isEmpty(tenant)) { |
|
|
@@ -54,61 +46,12 @@ public class ExecuteTaskService { |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class); |
|
|
|
if (jsonResult.getCode() != 0) { |
|
|
|
log.info("立即执行任务业务:机场接口返回结果:失败:{}", jsonResult.getMsg()); |
|
|
|
inspection.setStatus(InspectionStatusEnum.FLIGHT_FAILED.getCode()); |
|
|
|
this.updateInspection(userId, inspection); |
|
|
|
|
|
|
|
this.insertInspectionHistory(userId, inspection.getTenantId(), inspection, jsonResult.getMsg()); |
|
|
|
|
|
|
|
return JsonResult.error(jsonResult.getMsg()); |
|
|
|
} else { |
|
|
|
inspection.setStatus(InspectionStatusEnum.IN_FLIGHT.getCode()); |
|
|
|
this.updateInspection(userId, inspection); |
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改任务执行时数据 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param inspection |
|
|
|
*/ |
|
|
|
private void updateInspection(String userId, Inspection inspection) { |
|
|
|
inspection.setExecutionStatus(2); |
|
|
|
inspection.setStatus(inspection.getStatus()); |
|
|
|
inspection.setUpdateUser(userId); |
|
|
|
inspection.setUpdateTime(DateUtils.now()); |
|
|
|
inspection.setExecutionStartTime(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); |
|
|
|
log.info("进入调用机场平台方法: 等待机场平台回调,修改执行任务状态"); |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |