| | |
| | | Set<Integer> terminalSet = TERMINAL_OR_WAITING_STATUS; |
| | | List<String> codes = tasks.stream().map(Task::getTaskCode).filter(Objects::nonNull).distinct().collect(Collectors.toList()); |
| | | if (codes.isEmpty()) { |
| | | tasks.forEach(t -> t.setCanComplete(Boolean.FALSE)); |
| | | tasks.forEach(t -> { |
| | | t.setCanComplete(Boolean.FALSE); |
| | | t.setCanCancel(Boolean.FALSE); |
| | | if (t.getTaskStatus() != null && t.getTaskStatus().equals(TaskStsType.MISSION_INITIAL.id) && !isPhase2InboundType(t.getTaskType())) { |
| | | t.setCanCancel(Boolean.TRUE); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | List<FlowStepInstance> steps = codes.size() == 1 |
| | |
| | | for (Task task : tasks) { |
| | | if (task.getTaskStatus() != null && terminalSet.contains(task.getTaskStatus())) { |
| | | task.setCanComplete(Boolean.FALSE); |
| | | task.setCanCancel(Boolean.FALSE); |
| | | continue; |
| | | } |
| | | // taskStatus=0(路径规划中)可取消;二阶段入库(拣料/盘点/并板入库)不可取消 |
| | | if (task.getTaskStatus() != null && task.getTaskStatus().equals(TaskStsType.MISSION_INITIAL.id)) { |
| | | task.setCanCancel(!isPhase2InboundType(task.getTaskType())); |
| | | task.setCanComplete(Boolean.FALSE); |
| | | continue; |
| | | } |
| | | List<FlowStepInstance> taskSteps = stepsByTaskNo.get(task.getTaskCode()); |
| | | if (taskSteps == null || taskSteps.isEmpty()) { |
| | | task.setCanComplete(Boolean.FALSE); |
| | | task.setCanCancel(Boolean.FALSE); |
| | | continue; |
| | | } |
| | | FlowStepInstance match = taskSteps.stream() |
| | |
| | | .findFirst().orElse(null); |
| | | if (match == null) { |
| | | task.setCanComplete(Boolean.FALSE); |
| | | task.setCanCancel(Boolean.FALSE); |
| | | continue; |
| | | } |
| | | boolean isLastStep = match.getWmsNextTaskStatus() == null || match.getWmsNextTaskStatus().equals(TaskStsType.MISSION_TRANSFER.id); |
| | | task.setCanComplete(!isLastStep); |
| | | task.setCanCancel(!isLastStep && !isPhase2InboundType(task.getTaskType())); |
| | | } |
| | | } |
| | | |
| | | /** 二阶段入库:拣料入库、盘点入库、并板入库,不可取消 */ |
| | | private boolean isPhase2InboundType(Integer taskType) { |
| | | if (taskType == null) return false; |
| | | return taskType.equals(TaskType.TASK_TYPE_PICK_IN.type) |
| | | || taskType.equals(TaskType.TASK_TYPE_CHECK_IN.type) |
| | | || taskType.equals(TaskType.TASK_TYPE_MERGE_IN.type); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 盘点再入库完成后,将关联的盘点差异单置为已审核(有单按 orderId,无单按 出库任务号 orderCode) |
| | | * 盘点再入库完成后,将本单对应的差异明细置为已审核,全部明细已审核后差异单本身置为已审核(有单按 orderId,无单按 出库任务号 orderCode) |
| | | */ |
| | | @Override |
| | | public void markCheckDiffApprovedWhenCheckInDone(Task checkInTask) { |
| | | List<TaskItem> items = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, checkInTask.getId()).last("limit 1")); |
| | | Long orderId = items.isEmpty() ? null : items.get(0).getOrderId(); |
| | | CheckDiff checkDiff = null; |
| | | if (orderId != null && !orderId.equals(0L)) { |
| | | checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>().eq(CheckDiff::getOrderId, orderId).last("limit 1")); |
| | | } else { |
| | | Task outTask = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getBarcode, checkInTask.getBarcode()) |
| | | .eq(Task::getTaskType, TaskType.TASK_TYPE_CHECK_OUT.type) |
| | | .last("limit 1")); |
| | | if (outTask != null) { |
| | | if (outTask == null) { |
| | | return; |
| | | } |
| | | List<TaskItem> inItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, checkInTask.getId())); |
| | | Long orderId = inItems.isEmpty() ? null : inItems.get(0).getOrderId(); |
| | | CheckDiff checkDiff = null; |
| | | if (orderId != null && !orderId.equals(0L)) { |
| | | checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>().eq(CheckDiff::getOrderId, orderId).last("limit 1")); |
| | | } else { |
| | | checkDiff = checkDiffService.getOne(new LambdaQueryWrapper<CheckDiff>() |
| | | .eq(CheckDiff::getOrderCode, outTask.getTaskCode()) |
| | | .and(w -> w.isNull(CheckDiff::getOrderId).or().eq(CheckDiff::getOrderId, 0)) |
| | | .last("limit 1")); |
| | | } |
| | | if (checkDiff == null) { |
| | | return; |
| | | } |
| | | if (checkDiff != null && !CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val.equals(checkDiff.getExceStatus())) { |
| | | List<TaskItem> outItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, outTask.getId())); |
| | | List<Long> outTaskItemIds = outItems.stream().map(TaskItem::getId).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | if (!outTaskItemIds.isEmpty()) { |
| | | checkDiffItemService.update(new LambdaUpdateWrapper<CheckDiffItem>() |
| | | .eq(CheckDiffItem::getCheckId, checkDiff.getId()) |
| | | .in(CheckDiffItem::getTaskItemId, outTaskItemIds) |
| | | .set(CheckDiffItem::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val)); |
| | | } |
| | | long unApprovedCount = checkDiffItemService.count(new LambdaQueryWrapper<CheckDiffItem>() |
| | | .eq(CheckDiffItem::getCheckId, checkDiff.getId()) |
| | | .ne(CheckDiffItem::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val)); |
| | | if (unApprovedCount == 0 && !CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val.equals(checkDiff.getExceStatus())) { |
| | | checkDiffService.update(new LambdaUpdateWrapper<CheckDiff>() |
| | | .eq(CheckDiff::getId, checkDiff.getId()) |
| | | .set(CheckDiff::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val)); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R removeTask(Long[] ids, Long loginUserId) { |
| | | List<Integer> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id); |
| | | List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, |
| | | TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_EMPTY_IN.type, TaskType.TASK_TYPE_LOC_MOVE.type, |
| | | TaskType.TASK_TYPE_EMPTY_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type); |
| | | TaskType.TASK_TYPE_EMPTY_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type, |
| | | TaskType.TASK_TYPE_PICK_IN.type, TaskType.TASK_TYPE_CHECK_IN.type); |
| | | List<Task> tasks = this.list(new LambdaQueryWrapper<Task>() |
| | | .in(Task::getTaskType, list) |
| | | .in(Task::getId, ids) |
| | | .in(Task::getTaskStatus, longs)); |
| | | .in(Task::getId, ids)); |
| | | if (tasks.isEmpty()) { |
| | | throw new CoolException("任务已处执行状态不可取消!!"); |
| | | throw new CoolException("任务不存在或类型不允许取消!!"); |
| | | } |
| | | fillCanComplete(tasks); |
| | | List<Task> notCancelable = tasks.stream().filter(t -> !Boolean.TRUE.equals(t.getCanCancel())).collect(Collectors.toList()); |
| | | if (!notCancelable.isEmpty()) { |
| | | throw new CoolException("部分任务不可取消(拣料/盘点/并板入库为二阶段任务不可取消;其他仅 taskStatus=0 或流程未到 9999 时可取消)!!"); |
| | | } |
| | | for (Task task : tasks) { |
| | | //取消移库任务 |
| | |
| | | } |
| | | } |
| | | }); |
| | | List<Long> orderIds = taskItems.stream() |
| | | .map(TaskItem::getOrderId) |
| | | .filter(Objects::nonNull) |
| | | .filter(id -> !id.equals(0L)) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | for (Long orderId : orderIds) { |
| | | checkOrderService.update(new LambdaUpdateWrapper<WkOrder>() |
| | | .eq(WkOrder::getId, orderId) |
| | | .set(WkOrder::getExceStatus, CheckExceStatus.CHECK_ORDER_STATUS_UN_EXCE.val)); |
| | | } |
| | | } |
| | | |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | |
| | | } |
| | | } |
| | | |
| | | // 出库类任务取消时,回退路径规划阶段占用的目标站点(S→O) |
| | | 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_MERGE_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) |
| | | || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_OUT.type)) { |
| | | if (!Cools.isEmpty(task.getTargSite())) { |
| | | LambdaQueryWrapper<BasStation> stationWrapper = new LambdaQueryWrapper<BasStation>() |
| | | .eq(BasStation::getStationName, task.getTargSite()) |
| | | .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_S.type); |
| | | if (!Cools.isEmpty(task.getBarcode())) { |
| | | stationWrapper.eq(BasStation::getBarcode, task.getBarcode()); |
| | | } |
| | | BasStation targStation = basStationService.getOne(stationWrapper); |
| | | if (targStation != null) { |
| | | targStation.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | targStation.setBarcode(null); |
| | | if (!basStationService.updateById(targStation)) { |
| | | throw new CoolException("释放目标站点失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!Objects.isNull(task.getWarehType()) && task.getWarehType().equals(WarehType.WAREHOUSE_TYPE_AGV.val)) { |
| | | BasStation basStation = null; |
| | | if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_IN.type)) { |