| | |
| | | if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { |
| | | station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite())); |
| | | if (Objects.isNull(station)) { |
| | | throw new CoolException("站点不存在!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点不存在!!任务编码:{},目标站点:{}", task.getTaskCode(), task.getTargSite()); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | |
| | | if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) { |
| | | station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("站点状态更新失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点状态更新失败!!任务编码:{},站点:{}", task.getTaskCode(), station.getStationName()); |
| | | continue; |
| | | } |
| | | } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) { |
| | | station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("站点状态更新失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点状态更新失败!!任务编码:{},站点:{}", task.getTaskCode(), station.getStationName()); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) { |
| | | /**出库参数*/ |
| | | itemParam.setOriLoc(task.getOrgLoc()) |
| | | .setDestSta(task.getTargSite()); |
| | | /**出库参数 - 需要根据任务明细中的多个库位进行组装*/ |
| | | // 查询任务明细 |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (!taskItems.isEmpty()) { |
| | | // 通过TaskItem的source字段查询LocItem,获取库位信息 |
| | | Set<String> locCodes = new HashSet<>(); |
| | | Map<String, LocItem> locItemMap = new HashMap<>(); |
| | | |
| | | for (TaskItem taskItem : taskItems) { |
| | | if (taskItem.getSource() != null) { |
| | | // source字段对应LocItem的id |
| | | LocItem locItem = locItemService.getById(taskItem.getSource()); |
| | | if (locItem != null && StringUtils.isNotBlank(locItem.getLocCode())) { |
| | | locCodes.add(locItem.getLocCode()); |
| | | locItemMap.put(locItem.getLocCode(), locItem); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果通过source没有找到库位,使用Task的orgLoc作为默认值 |
| | | if (locCodes.isEmpty() && StringUtils.isNotBlank(task.getOrgLoc())) { |
| | | locCodes.add(task.getOrgLoc()); |
| | | } |
| | | |
| | | // 为每个不同的库位创建一个TaskItemParam |
| | | for (String locCode : locCodes) { |
| | | TaskItemParam outItemParam = new TaskItemParam(); |
| | | outItemParam.setTaskNo(task.getTaskCode()); |
| | | outItemParam.setPriority(1); |
| | | outItemParam.setOriLoc(locCode); |
| | | outItemParam.setDestSta(task.getTargSite()); |
| | | if (task.getBarcode() != null) { |
| | | outItemParam.setZpallet(task.getBarcode()); |
| | | } |
| | | items.add(outItemParam); |
| | | } |
| | | |
| | | log.info("出库任务包含{}个库位:{}", locCodes.size(), locCodes); |
| | | } else { |
| | | // 如果没有任务明细,使用Task的orgLoc |
| | | itemParam.setOriLoc(task.getOrgLoc()) |
| | | .setDestSta(task.getTargSite()); |
| | | items.add(itemParam); |
| | | } |
| | | } else { |
| | | /**站点间移库参数*/ |
| | | itemParam.setOriSta(task.getOrgSite()).setDestSta(task.getTargSite()); |
| | | |
| | | BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite())); |
| | | if (Objects.isNull(curSta)) { |
| | | throw new CoolException("站点不存在!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点不存在!!任务编码:{},源站点:{}", task.getTaskCode(), task.getOrgSite()); |
| | | continue; |
| | | } |
| | | if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | if (!curSta.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) { |
| | | throw new CoolException("当前站点不是F.在库状态!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("当前站点不是F.在库状态!!任务编码:{},站点:{},当前状态:{}", task.getTaskCode(), curSta.getStationName(), curSta.getUseStatus()); |
| | | continue; |
| | | } |
| | | } |
| | | // 站点间移库需要获取目标站点 |
| | | BasStation targetStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite())); |
| | | if (Objects.isNull(targetStation)) { |
| | | throw new CoolException("目标站点不存在!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("目标站点不存在!!任务编码:{},目标站点:{}", task.getTaskCode(), task.getTargSite()); |
| | | continue; |
| | | } |
| | | if (targetStation.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | if (!targetStation.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) { |
| | | throw new CoolException("目标站点不是O.空闲状态!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("目标站点不是O.空闲状态!!任务编码:{},站点:{},当前状态:{}", task.getTaskCode(), targetStation.getStationName(), targetStation.getUseStatus()); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | items.add(itemParam); |
| | | |
| | | // 对于非出库任务,添加单个itemParam |
| | | if (!(task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type))) { |
| | | items.add(itemParam); |
| | | } |
| | | |
| | | taskParams.setTasks(items); |
| | | |
| | | // 记录当前任务信息 |
| | |
| | | if (cause instanceof java.net.SocketTimeoutException || |
| | | (cause instanceof java.net.ConnectException && cause.getMessage() != null && cause.getMessage().contains("timed out")) || |
| | | (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout")))) { |
| | | throw new CoolException("RCS连接超时,任务下发失败!任务编码:" + task.getTaskCode() + ",错误信息:" + errorMsg); |
| | | log.error("RCS连接超时,任务下发失败!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg); |
| | | } else { |
| | | log.error("RCS资源访问异常,任务下发失败!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg); |
| | | } |
| | | throw new CoolException("RCS资源访问异常,任务下发失败!任务编码:" + task.getTaskCode() + ",错误信息:" + errorMsg); |
| | | continue; |
| | | } catch (Exception e) { |
| | | long endTime = System.currentTimeMillis(); |
| | | log.error("========== RCS任务下发异常 =========="); |
| | |
| | | String errorMsg = e.getMessage(); |
| | | // 检查是否是连接超时相关的异常 |
| | | if (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout"))) { |
| | | throw new CoolException("RCS连接超时,任务下发失败!任务编码:" + task.getTaskCode() + ",错误信息:" + errorMsg); |
| | | log.error("RCS连接超时,任务下发失败!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg); |
| | | } else { |
| | | log.error("RCS任务下发异常!任务编码:{},错误信息:{}", task.getTaskCode(), errorMsg); |
| | | } |
| | | throw new CoolException("RCS任务下发异常!任务编码:" + task.getTaskCode() + ",错误信息:" + errorMsg); |
| | | continue; |
| | | } |
| | | |
| | | if (Objects.isNull(exchange) || Objects.isNull(exchange.getBody())) { |
| | |
| | | log.error("请求RCS-地址:{}", pubTakUrl); |
| | | log.error("请求RCS-参数:{}", JSONObject.toJSONString(taskParams)); |
| | | log.error("请求RCS-失败的任务编码:{}", task.getTaskCode()); |
| | | throw new CoolException("任务下发失败,RCS响应体为空!!任务编码:" + task.getTaskCode()); |
| | | log.error("任务下发失败,RCS响应体为空!!任务编码:{}", task.getTaskCode()); |
| | | continue; |
| | | } else { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | |
| | | |
| | | BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite())); |
| | | if (Objects.isNull(curSta)) { |
| | | throw new CoolException("站点不存在!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点不存在!!任务编码:{},源站点:{}", task.getTaskCode(), task.getOrgSite()); |
| | | continue; |
| | | } |
| | | |
| | | log.info("更新入库任务状态 - 任务编码:{},新状态:{}", task.getTaskCode(), TaskStsType.WCS_EXECUTE_IN.id); |
| | | if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode()) |
| | | .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("任务状态修改失败!!任务编码:{}", task.getTaskCode()); |
| | | continue; |
| | | } |
| | | log.info("入库任务状态更新成功 - 任务编码:{}", task.getTaskCode()); |
| | | /**排除移库功能*/ |
| | |
| | | if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | curSta.setUseStatus(LocStsType.LOC_STS_TYPE_R.type); |
| | | if (!basStationService.updateById(curSta)) { |
| | | throw new CoolException("站点预约失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点预约失败!!任务编码:{},站点:{}", task.getTaskCode(), curSta.getStationName()); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) { |
| | | BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite())); |
| | | if (Objects.isNull(curSta)) { |
| | | throw new CoolException("站点不存在!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点不存在!!任务编码:{},目标站点:{}", task.getTaskCode(), task.getTargSite()); |
| | | continue; |
| | | } |
| | | |
| | | log.info("更新出库任务状态 - 任务编码:{},新状态:{}", task.getTaskCode(), TaskStsType.WCS_EXECUTE_OUT.id); |
| | | if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode()) |
| | | .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) { |
| | | throw new CoolException("任务状态修改失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("任务状态修改失败!!任务编码:{}", task.getTaskCode()); |
| | | continue; |
| | | } |
| | | log.info("出库任务状态更新成功 - 任务编码:{}", task.getTaskCode()); |
| | | /**如果是普通站点,修改站点状态为入库预约*/ |
| | | if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | curSta.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | if (!basStationService.updateById(curSta)) { |
| | | throw new CoolException("站点预约失败!!"); |
| | | log.error("========== RCS任务下发失败 =========="); |
| | | log.error("站点预约失败!!任务编码:{},站点:{}", task.getTaskCode(), curSta.getStationName()); |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | |
| | | log.error("RCS返回错误 - code:{},msg:{},data:{}", |
| | | result.getCode(), result.getMsg(), result.getData()); |
| | | log.error("失败的任务编码:{},任务类型:{}", task.getTaskCode(), task.getTaskType()); |
| | | throw new CoolException("任务下发失败!!任务编码:" + task.getTaskCode()); |
| | | log.error("任务下发失败!!任务编码:{}", task.getTaskCode()); |
| | | continue; |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | log.error("========== RCS任务下发异常 =========="); |
| | | log.error("解析RCS响应失败,响应体:{},任务编码:{}", exchange.getBody(), task.getTaskCode(), e); |
| | | throw new CoolException("解析RCS响应失败:" + e.getMessage() + ",任务编码:" + task.getTaskCode()); |
| | | log.error("解析RCS响应失败:{},任务编码:{}", e.getMessage(), task.getTaskCode()); |
| | | continue; |
| | | } catch (Exception e) { |
| | | log.error("========== RCS任务下发异常 =========="); |
| | | log.error("任务下发过程中发生异常,任务编码:{}", task.getTaskCode(), e); |
| | | throw e; |
| | | log.error("任务下发异常:{},任务编码:{}", e.getMessage(), task.getTaskCode()); |
| | | continue; |
| | | } |
| | | } |
| | | } |