| | |
| | | import com.vincent.rsf.server.api.config.RemotesInfoProperties; |
| | | import com.vincent.rsf.server.api.entity.CommonResponse; |
| | | import com.vincent.rsf.server.api.entity.constant.RcsConstant; |
| | | import com.vincent.rsf.server.api.entity.params.MissionTaskIssueParam; |
| | | import com.vincent.rsf.server.api.entity.params.TaskItemParam; |
| | | import com.vincent.rsf.server.api.entity.params.WcsTaskParams; |
| | | import com.vincent.rsf.server.api.utils.LocUtils; |
| | |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.entity.*; |
| | | import com.vincent.rsf.server.system.service.ConfigService; |
| | | import com.vincent.rsf.server.system.service.impl.FlowInstanceServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.FlowStepInstanceServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.TaskInstanceNodeServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.TaskInstanceServiceImpl; |
| | | import com.vincent.rsf.server.system.service.impl.*; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import com.vincent.rsf.server.system.utils.SystemAuthUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @Autowired |
| | | private RemotesInfoProperties.RcsApi rcsApi; |
| | | @Autowired |
| | | private RemotesInfoProperties.WmsOpenApi wmsOpenApi; |
| | | @Autowired |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private FlowStepInstanceServiceImpl flowStepInstanceService; |
| | |
| | | private TaskInstanceNodeServiceImpl taskInstanceNodeService; |
| | | @Autowired |
| | | private TaskInstanceServiceImpl taskInstanceService; |
| | | @Autowired |
| | | private SubsystemFlowTemplateServiceImpl subsystemFlowTemplateService; |
| | | @Autowired |
| | | private FlowStepTemplateServiceImpl flowStepTemplateService; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Scheduled(cron = "0/2 * * * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void missionTaskEXECUTE() { |
| | | List<String> typeList = Arrays.asList(MissionStepType.MISSION_STEP_TYPE_REQUEST.type, MissionStepType.MISSION_STEP_TYPE_OBTAIN.type,MissionStepType.MISSION_STEP_TYPE_NO_EXECUTE.type); |
| | | List<FlowStepInstance> flowStepInstanceList = flowStepInstanceService.list(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getStatus, 1).in(FlowStepInstance::getStepType,typeList)); |
| | | for (FlowStepInstance flowStepInstance : flowStepInstanceList) { |
| | | FlowInstance flowInstance = flowInstanceService.getById(flowStepInstance.getFlowInstanceId()); |
| | | if (Cools.isEmpty(flowInstance)) { continue;} |
| | | TaskInstanceNode taskInstanceNode = taskInstanceNodeService.getById(flowInstance.getNodeInstanceId()); |
| | | if (Cools.isEmpty(taskInstanceNode)) { continue;} |
| | | TaskInstance taskInstance = taskInstanceService.getById(flowInstance.getTaskId()); |
| | | if (Cools.isEmpty(taskInstance)) { continue;} |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskCode, taskInstance.getTaskNo())); |
| | | if (Cools.isEmpty(task)) { continue;} |
| | | if (!task.getTaskStatus().equals(flowStepInstance.getWmsNowTaskStatus())) { |
| | | log.error("任务号:"+task.getTaskCode()+"的任务状态与执行档案任务状态:"+flowStepInstance.getWmsNowTaskStatus()+"不一致!!!"); |
| | | continue; |
| | | } |
| | | |
| | | if (flowStepInstance.getStepType().equals(MissionStepType.MISSION_STEP_TYPE_NO_EXECUTE.type)) { |
| | | /**基础配置链接*/ |
| | | log.info("任务越过, 请求参数: {}", JSONObject.toJSONString(flowStepInstance)); |
| | | try { |
| | | task.setTaskStatus(flowStepInstance.getWmsNextTaskStatus()); |
| | | flowStepInstance.setStatus((short)3); |
| | | |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | taskService.updateById(task); |
| | | |
| | | if (flowStepInstance.getWmsNextTaskStatus() != 9999) { |
| | | FlowStepInstance nextFlowStepInstance = flowStepInstanceService.getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getFlowInstanceId, flowStepInstance.getFlowInstanceId()) |
| | | .eq(FlowStepInstance::getFlowInstanceNo, flowStepInstance.getFlowInstanceNo()) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder() + 1) |
| | | .eq(FlowStepInstance::getWmsNowTaskStatus, flowStepInstance.getWmsNextTaskStatus())); |
| | | nextFlowStepInstance.setStatus((short)1); |
| | | |
| | | flowStepInstanceService.updateById(nextFlowStepInstance); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new CoolException(e.getMessage()); |
| | | public synchronized void missionTaskEXECUTE() { |
| | | try{ |
| | | List<FlowStepInstance> flowStepInstanceList = flowStepInstanceService.list(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getStatus, 1).in(FlowStepInstance::getStepType,MissionStepType.getTaskISSUE())); |
| | | for (FlowStepInstance flowStepInstance : flowStepInstanceList) { |
| | | FlowInstance flowInstance = flowInstanceService.getById(flowStepInstance.getFlowInstanceId()); |
| | | if (Cools.isEmpty(flowInstance)) { continue;} |
| | | List<FlowStepInstance> flowStepInstances = flowStepInstanceService.list(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getFlowInstanceId, flowInstance.getId()).eq(FlowStepInstance::getStatus, (short) 0)); |
| | | flowInstance.setStatus(flowStepInstances.isEmpty()? (short) 2:(short) 1); |
| | | TaskInstanceNode taskInstanceNode = taskInstanceNodeService.getById(flowInstance.getNodeInstanceId()); |
| | | if (Cools.isEmpty(taskInstanceNode)) { continue;} |
| | | taskInstanceNode.setStatus(flowInstance.getStatus()); |
| | | TaskInstance taskInstance = taskInstanceService.getById(flowInstance.getTaskId()); |
| | | if (Cools.isEmpty(taskInstance)) { continue;} |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskCode, taskInstance.getTaskNo())); |
| | | if (Cools.isEmpty(task)) { continue;} |
| | | if (!task.getTaskStatus().equals(flowStepInstance.getWmsNowTaskStatus())) { |
| | | log.error("任务号:"+task.getTaskCode()+"的任务状态与执行档案任务状态:"+flowStepInstance.getWmsNowTaskStatus()+"不一致!!!"); |
| | | continue; |
| | | } |
| | | } else { |
| | | /**任务下发接口*/ |
| | | String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.MISSION_TRANSFER_STATION; |
| | | |
| | | /**基础配置链接*/ |
| | | log.info("任务下发,请求地址: {}, 请求参数: {}", pubTakUrl, JSONObject.toJSONString("")); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | HttpEntity httpEntity = new HttpEntity(flowStepInstance, headers); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class); |
| | | log.info("任务下发后,响应结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("任务下发失败!!,返回参数为空!!!"); |
| | | } else { |
| | | if (flowStepInstance.getStepType().equals(MissionStepType.MISSION_STEP_TYPE_NO_EXECUTE.type)) { |
| | | /**基础配置链接*/ |
| | | log.info("任务越过, 请求参数: {}", JSONObject.toJSONString(flowStepInstance)); |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | | .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | task.setTaskStatus(flowStepInstance.getWmsNextTaskStatus()); |
| | | flowStepInstance.setStatus((short)3); |
| | | task.setTaskStatus(flowStepInstance.getWmsNextTaskStatus()); |
| | | flowStepInstance.setStatus((short)3); |
| | | |
| | | if (flowStepInstance.getStepType().equals(MissionStepType.MISSION_STEP_TYPE_OBTAIN.type)) { |
| | | //获取数据解析 |
| | | //录入 |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | taskService.updateById(task); |
| | | |
| | | if (flowStepInstance.getWmsNextTaskStatus() != 9999) { |
| | | FlowStepInstance nextFlowStepInstance = flowStepInstanceService.getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getStatus, (short)0) |
| | | .eq(FlowStepInstance::getTaskNo, flowStepInstance.getTaskNo()) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder() + 1) |
| | | .eq(FlowStepInstance::getWmsNowTaskStatus, flowStepInstance.getWmsNextTaskStatus())); |
| | | if (Cools.isEmpty(nextFlowStepInstance)) { |
| | | throw new CoolException("任务号"+task.getTaskCode()+"任务步骤丢失!!!"); |
| | | } |
| | | nextFlowStepInstance.setStatus((short)1); |
| | | |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | taskService.updateById(task); |
| | | |
| | | if (flowStepInstance.getWmsNextTaskStatus() != 9999) { |
| | | FlowStepInstance nextFlowStepInstance = flowStepInstanceService.getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getFlowInstanceId, flowStepInstance.getFlowInstanceId()) |
| | | .eq(FlowStepInstance::getFlowInstanceNo, flowStepInstance.getFlowInstanceNo()) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder() + 1) |
| | | .eq(FlowStepInstance::getWmsNowTaskStatus, flowStepInstance.getWmsNextTaskStatus())); |
| | | nextFlowStepInstance.setStatus((short)1); |
| | | |
| | | flowStepInstanceService.updateById(nextFlowStepInstance); |
| | | } |
| | | flowStepInstanceService.updateById(nextFlowStepInstance); |
| | | } else { |
| | | flowStepInstance.setRetryTimes(flowStepInstance.getRetryTimes() + 1); |
| | | if (flowStepInstance.getRetryTimes()>5){ |
| | | flowStepInstance.setStatus((short)4); |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | log.error("任务下发失败,重试次数大于等于五次,标记为失败!!!"); |
| | | } else { |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | log.error("任务下发失败,等待重试...."); |
| | | } |
| | | taskInstance.setStatus((short)2); |
| | | taskInstanceService.updateById(taskInstance); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | flowInstanceService.updateById(flowInstance); |
| | | taskInstanceNodeService.updateById(taskInstanceNode); |
| | | } catch (Exception e) { |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | } else { |
| | | SubsystemFlowTemplate subsystemFlowTemplate = subsystemFlowTemplateService.getById(flowInstance.getFlowTemplateId()); |
| | | FlowStepTemplate flowStepTemplate = flowStepTemplateService.getById(flowStepInstance.getStepTemplateId()); |
| | | |
| | | MissionTaskIssueParam missionTaskIssueParam = new MissionTaskIssueParam(flowStepInstance,subsystemFlowTemplate,flowStepTemplate); |
| | | |
| | | missionTaskIssueParam.setType(RcsTaskType.getTypeDesc(task.getTaskType())); |
| | | |
| | | missionTaskIssueParam.setSourceCode(taskInstance.getSourceCode()); |
| | | missionTaskIssueParam.setTargetCode(taskInstance.getTargetCode()); |
| | | /**任务下发接口*/ |
| | | String pubTakUrl = wmsOpenApi.getHost() + ":" + wmsOpenApi.getPort() + RcsConstant.MISSION_TRANSFER_STATION; |
| | | |
| | | /**基础配置链接*/ |
| | | log.info("任务下发,请求地址: {}, 请求参数: {}", pubTakUrl, JSONObject.toJSONString(flowStepInstance)); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | HttpEntity httpEntity = new HttpEntity(missionTaskIssueParam, headers); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class); |
| | | log.info("任务下发后,响应结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("任务下发失败!!,返回参数为空!!!"); |
| | | } else { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | | .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | task.setTaskStatus(flowStepInstance.getWmsNextTaskStatus()); |
| | | flowStepInstance.setStatus((short)3); |
| | | |
| | | if (flowStepInstance.getStepType().equals(MissionStepType.MISSION_STEP_TYPE_OBTAIN.type)) { |
| | | //获取数据解析 |
| | | //录入 |
| | | } |
| | | |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | taskService.updateById(task); |
| | | |
| | | if (flowStepInstance.getWmsNextTaskStatus() != 9999) { |
| | | FlowStepInstance nextFlowStepInstance = flowStepInstanceService.getOne(new LambdaQueryWrapper<FlowStepInstance>() |
| | | .eq(FlowStepInstance::getStatus, (short)0) |
| | | .eq(FlowStepInstance::getTaskNo, flowStepInstance.getTaskNo()) |
| | | .eq(FlowStepInstance::getStepOrder, flowStepInstance.getStepOrder() + 1) |
| | | .eq(FlowStepInstance::getWmsNowTaskStatus, flowStepInstance.getWmsNextTaskStatus())); |
| | | if (Cools.isEmpty(nextFlowStepInstance)) { |
| | | throw new CoolException("任务号"+task.getTaskCode()+"任务步骤丢失!!!"); |
| | | } |
| | | nextFlowStepInstance.setStatus((short)1); |
| | | |
| | | flowStepInstanceService.updateById(nextFlowStepInstance); |
| | | } else { |
| | | taskInstance.setStatus((short)2); |
| | | taskInstanceService.updateById(taskInstance); |
| | | } |
| | | } else { |
| | | flowStepInstance.setRetryTimes(flowStepInstance.getRetryTimes() + 1); |
| | | if (flowStepInstance.getRetryTimes()>5){ |
| | | flowStepInstance.setStatus((short)4); |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | log.error("任务下发失败,重试次数大于等于五次,标记为失败!!!"); |
| | | } else { |
| | | flowStepInstanceService.updateById(flowStepInstance); |
| | | log.error("任务下发失败,等待重试...."); |
| | | } |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | completeInStock(); |
| | | complateOutStock(); |
| | | completeStock9999(); |
| | | completeStock10000(); |
| | | } |
| | | |
| | | |
| | | public void completeStock9999() throws Exception { |
| | | try{ |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.MISSION_TRANSFER.id).select(Task::getId)); |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.MISSION_TRANSFER.id)); |
| | | if (tasks.isEmpty()) { |
| | | return; |
| | | } |
| | | for (Task task : tasks) { |
| | | /**任务下发接口*/ |
| | | String pubTakUrl = wmsOpenApi.getHost() + ":" + wmsOpenApi.getPort() + RcsConstant.REPORT_TASKS; |
| | | |
| | | /**基础配置链接*/ |
| | | log.info("任务上报,请求地址: {}, 请求参数: {}", pubTakUrl, JSONObject.toJSONString("")); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | HttpEntity httpEntity = new HttpEntity(task, headers); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class); |
| | | log.info("任务上报,响应结果: {}", exchange); |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | throw new CoolException("任务上报失败!!,返回参数为空!!!"); |
| | | } else { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | | .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | if (result.getCode() == 200) { |
| | | task.setTaskStatus( TaskStsType.MISSION_TRANSFER_END.id); |
| | | taskService.updateById(task); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | // List<Long> longSet = tasks.stream().map(Task::getId).collect(Collectors.toList()); |
| | | // List<Task> vaildTasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getId, longSet)); |
| | | // taskService.complateInTask(vaildTasks); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void completeStock10000() throws Exception { |
| | | try{ |
| | | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.MISSION_TRANSFER_END.id)); |
| | | if (tasks.isEmpty()) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | // |
| | | // /** |
| | | // * 非光电站点任务下发 |
| | | // * 非智能站点任务下发 |
| | | // */ |
| | | // @Scheduled(cron = "0/5 * * * * ? ") |
| | | // @Transactional(rollbackFor = Exception.class) |
| | |
| | | // .eq(BasStation::getStationName, |
| | | // task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite())); |
| | | // if (Cools.isEmpty(station)){ |
| | | // log.info("非光电站点任务下发:站点信息异常,任务信息:"+ JSON.toJSONString(task)); |
| | | // log.info("非智能站点任务下发:站点信息异常,任务信息:"+ JSON.toJSONString(task)); |
| | | // continue; |
| | | // } |
| | | // if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) { |
| | |
| | | // /** |
| | | // * @author Ryan |
| | | // * @date 2025/9/4 |
| | | // * @description: 光电站点任务下发 |
| | | // * @description: 智能站点任务下发 |
| | | // * @version 1.0 |
| | | // */ |
| | | // @Scheduled(cron = "0/5 * * * * ? ") |
| | |
| | | } |
| | | |
| | | |
| | | /**判断是否光电站点,非光店站点需管控站点状态*/ //目标站点 |
| | | /**判断是否智能站点,非光店站点需管控站点状态*/ //目标站点 |
| | | if (!Objects.isNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { |
| | | // if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) { |
| | |
| | | tasks.forEach(task -> { |
| | | TaskLog taskLog = new TaskLog(); |
| | | BeanUtils.copyProperties(task, taskLog); |
| | | taskLog.setOrgLoc(task.getOrgLoc()) |
| | | .setTargLoc(task.getTargLoc()) |
| | | .setTargSite(task.getTargSite()) |
| | | .setOrgSite(task.getOrgSite()); |
| | | taskLog.setTaskId(task.getId()) |
| | | .setId(null); |
| | | if (!taskLogService.save(taskLog)) { |