| | |
| | | import com.vincent.rsf.server.api.config.RemotesInfoProperties; |
| | | import com.vincent.rsf.server.api.controller.erp.params.InOutResultReportParam; |
| | | import com.vincent.rsf.server.api.controller.erp.params.TaskInParam; |
| | | import com.vincent.rsf.server.api.service.RcsBusTaskNoticeService; |
| | | import com.vincent.rsf.server.api.entity.CommonResponse; |
| | | import com.vincent.rsf.server.api.entity.constant.RcsConstant; |
| | | import com.vincent.rsf.server.api.entity.dto.InTaskMsgDto; |
| | |
| | | private CloudWmsNotifyLogService cloudWmsNotifyLogService; |
| | | @Autowired |
| | | private WarehouseService warehouseService; |
| | | @Autowired |
| | | private RcsBusTaskNoticeService rcsBusTaskNoticeService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 手动完成任务 |
| | | * 手动完成任务:入库类置 98、出库类置 198,库位/单据扣减与上报由对应定时任务执行 |
| | | * |
| | | * @param id |
| | | * @param loginUserId |
| | |
| | | } |
| | | |
| | | modiftyTaskSort(task, loginUserId); |
| | | |
| | | // 如果任务状态已经是AWAIT (196),再次点击完结时,直接完成 |
| | | if (task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { |
| | | // AWAIT状态的任务再次完结,直接设置为出库完成 |
| | | |
| | | // 入库:->98,出库:-> 198,由 complateOutStock 定时任务 更新库存 |
| | | if (task.getTaskType() < 100) { |
| | | task.setTaskStatus(TaskStsType.COMPLETE_IN.id); |
| | | if (StringUtils.isNotBlank(task.getOrgSite())) { |
| | | BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>() |
| | | .eq(BasStation::getStationName, task.getOrgSite())); |
| | | if (Objects.nonNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | station.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("入库站点状态修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); |
| | | |
| | | // 更新出库站点状态(与RCS通知完结保持一致) |
| | | if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type && StringUtils.isNotBlank(task.getTargSite())) { |
| | | BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>() |
| | | .eq(BasStation::getStationName, task.getTargSite())); |
| | |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 其他情况按原有逻辑处理 |
| | | // 入库任务(taskType < 100):设置为入库完成 |
| | | // 出库任务(taskType >= 100):设置为等待确认 |
| | | Integer newStatus = task.getTaskType() < 100 ? TaskStsType.COMPLETE_IN.id : TaskStsType.AWAIT.id; |
| | | task.setTaskStatus(newStatus); |
| | | |
| | | // 如果是入库任务完成,更新入库站点状态(与RCS通知完结保持一致) |
| | | if (newStatus.equals(TaskStsType.COMPLETE_IN.id) && StringUtils.isNotBlank(task.getOrgSite())) { |
| | | BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>() |
| | | .eq(BasStation::getStationName, task.getOrgSite())); |
| | | if (Objects.nonNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) { |
| | | station.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("入库站点状态修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 原:196 时再点一次才置 198;出库首次点击曾置 196(AWAIT) |
| | | // if (task.getTaskStatus().equals(TaskStsType.AWAIT.id)) { task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); ... } |
| | | // else { Integer newStatus = task.getTaskType() < 100 ? COMPLETE_IN.id : AWAIT.id; ... } |
| | | |
| | | if (!this.updateById(task)) { |
| | | throw new CoolException("完成任务失败"); |
| | | } |
| | | // 管理后台「完成任务」通知 RCS |
| | | if (StringUtils.isNotBlank(task.getTaskCode())) { |
| | | rcsBusTaskNoticeService.notifyTaskStatus(task.getTaskCode(), task.getTaskStatus()); |
| | | } |
| | | return task; |
| | | } |
| | |
| | | * |
| | | * @param id 任务ID |
| | | * @param loginUserId 登录用户ID |
| | | * @param notifyRcsFromAdmin 管理后台全版出库完结接口为 true 时通知 RCS;定时/PDA 等为 false |
| | | * @return 任务对象 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Task completeFullOutStock(Long id, Long loginUserId) { |
| | | public Task completeFullOutStock(Long id, Long loginUserId, boolean notifyRcsFromAdmin) { |
| | | // 查询任务 |
| | | Task task = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getId, id)); |
| | |
| | | if (!this.updateById(task)) { |
| | | throw new CoolException("任务状态更新失败!!"); |
| | | } |
| | | if (notifyRcsFromAdmin && StringUtils.isNotBlank(task.getTaskCode())) { |
| | | rcsBusTaskNoticeService.notifyTaskStatus(task.getTaskCode(), TaskStsType.UPDATED_OUT.id); |
| | | } |
| | | |
| | | return task; |
| | | } |
| | |
| | | String curLoc; |
| | | if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) { |
| | | curLoc = task.getTargLoc(); |
| | | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) { |
| | | curLoc = task.getTargLoc(); |
| | | if (StringUtils.isBlank(curLoc)) { |
| | | return task; |
| | | } |
| | | } else { |
| | | curLoc = task.getOrgLoc(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 如果有任务已下发到RCS,先调用RCS取消接口 |
| | | // 已下发 RCS 的工作档:必须先调 RCS 取消接口成功,否则不允许取消工作档 |
| | | boolean rcsCancelSuccess = false; |
| | | if (!rcsTaskCodes.isEmpty()) { |
| | | // 检查 RCS API 配置是否有效 |
| | | if (rcsApi == null || StringUtils.isBlank(rcsApi.getHost()) || StringUtils.isBlank(rcsApi.getPort())) { |
| | | log.error("========== RCS任务取消失败 =========="); |
| | | log.error("RCS API 配置无效!host: {}, port: {}", |
| | | rcsApi != null ? rcsApi.getHost() : "null", |
| | | rcsApi != null ? rcsApi.getPort() : "null"); |
| | | // 即使配置无效,也继续执行任务删除操作 |
| | | } else { |
| | | try { |
| | | log.info("========== 开始取消RCS任务 =========="); |
| | | log.info("需要取消的RCS任务编号:{}", rcsTaskCodes); |
| | | String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask; |
| | | log.info("RCS取消任务请求地址:{}", rcsUrl); |
| | | |
| | | // 如果没有批次编号,使用第一个任务编号作为批次编号 |
| | | if (StringUtils.isBlank(batchNo) && !rcsTaskCodes.isEmpty()) { |
| | | throw new CoolException("任务已下发RCS,但未配置RCS地址,无法取消!!"); |
| | | } |
| | | if (restTemplate == null) { |
| | | throw new CoolException("任务已下发RCS,但无法调用RCS取消接口,无法取消!!"); |
| | | } |
| | | try { |
| | | log.info("========== 开始取消RCS任务 =========="); |
| | | log.info("需要取消的RCS任务编号:{}", rcsTaskCodes); |
| | | String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask; |
| | | log.info("RCS取消任务请求地址:{}", rcsUrl); |
| | | |
| | | if (StringUtils.isBlank(batchNo)) { |
| | | batchNo = rcsTaskCodes.get(0); |
| | | } |
| | | |
| | | |
| | | Map<String, Object> cancelParams = new HashMap<>(); |
| | | cancelParams.put("tasks", rcsTaskCodes); |
| | | if (StringUtils.isNotBlank(batchNo)) { |
| | | cancelParams.put("batchNo", batchNo); |
| | | } |
| | | |
| | | |
| | | log.info("RCS取消任务请求参数:{}", JSONObject.toJSONString(cancelParams)); |
| | | |
| | | |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-Type", "application/json"); |
| | | headers.add("api-version", "v2.0"); |
| | | HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(cancelParams, headers); |
| | | |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class); |
| | | long endTime = System.currentTimeMillis(); |
| | | |
| | | |
| | | log.info("RCS取消任务响应耗时:{}ms", (endTime - startTime)); |
| | | log.info("RCS取消任务响应状态码:{}", exchange.getStatusCode()); |
| | | log.info("RCS取消任务响应体:{}", exchange.getBody()); |
| | | |
| | | |
| | | if (Objects.isNull(exchange.getBody())) { |
| | | log.error("RCS取消任务失败:响应体为空"); |
| | | throw new CoolException("RCS取消任务失败:响应体为空"); |
| | | } |
| | | |
| | | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.coercionConfigDefaults() |
| | | .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty); |
| | | CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class); |
| | | |
| | | |
| | | if (result.getCode() == 200) { |
| | | log.info("========== RCS任务取消成功 =========="); |
| | | log.info("成功取消的RCS任务编号:{}", rcsTaskCodes); |
| | |
| | | log.error("RCS取消任务失败:{}", result.getMsg()); |
| | | throw new CoolException("RCS取消任务失败:" + result.getMsg()); |
| | | } |
| | | } catch (JsonProcessingException e) { |
| | | log.error("RCS取消任务响应解析失败:{}", e.getMessage(), e); |
| | | throw new CoolException("RCS取消任务响应解析失败:" + e.getMessage()); |
| | | } catch (Exception e) { |
| | | log.error("RCS取消任务异常:{}", e.getMessage(), e); |
| | | throw new CoolException("RCS取消任务异常:" + e.getMessage()); |
| | | } |
| | | } catch (CoolException e) { |
| | | throw e; |
| | | } catch (JsonProcessingException e) { |
| | | log.error("RCS取消任务响应解析失败:{}", e.getMessage(), e); |
| | | throw new CoolException("RCS取消任务响应解析失败:" + e.getMessage()); |
| | | } catch (Exception e) { |
| | | log.error("RCS取消任务异常:{}", e.getMessage(), e); |
| | | throw new CoolException("RCS取消任务异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // 查询符合取消条件的任务(状态为1、101、199) |
| | | List<Integer> allowedStatuses = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id, TaskStsType.WAVE_SEED.id); |
| | | // 可取消状态:原 1/101(不含 199);拣料/盘点出库 RCS 执行中(<198);拣料/盘点再入库(53/57)不支持取消 |
| | | List<Task> tasks = this.list(new LambdaQueryWrapper<Task>() |
| | | .in(Task::getTaskType, list) |
| | | .in(Task::getId, (Object[]) ids) |
| | | .in(Task::getTaskStatus, allowedStatuses)); |
| | | .and(w -> w |
| | | .in(Task::getTaskStatus, Arrays.asList( |
| | | TaskStsType.GENERATE_IN.id, |
| | | TaskStsType.GENERATE_OUT.id)) |
| | | .or(w2 -> w2 |
| | | .in(Task::getTaskType, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type) |
| | | .lt(Task::getTaskStatus, TaskStsType.COMPLETE_OUT.id)))); |
| | | |
| | | // 如果符合取消条件的任务为空,但RCS取消成功,允许继续(可能是任务状态已变更) |
| | | if (tasks.isEmpty() && !rcsCancelSuccess) { |
| | |
| | | }); |
| | | log.debug("[拣料入库] 即将扣减库位 locId={}, locCode={}", loc.getId(), loc.getCode()); |
| | | subtractLocItemByTaskItems(loc, taskItems, SystemAuthUtils.getLoginUserId()); |
| | | // 料箱已全部用完则不生成拣货入库单,仅完结出库 |
| | | double totalRemaining = taskItems.stream().mapToDouble(ti -> ti.getAnfme() != null && ti.getAnfme().compareTo(0.0) > 0 ? ti.getAnfme() : 0.0).sum(); |
| | | if (totalRemaining <= 0.0) { |
| | | task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type); |
| | | task.setTaskStatus(TaskStsType.UPDATED_OUT.id); |
| | | this.updateById(task); |
| | | locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId())); |
| | | return task; |
| | | } |
| | | } |
| | | |
| | | tempLocs.forEach(working -> { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 同箱码下多条 200 拣料出库一次性处理:按相同物料合计扣减库位、更新出库单/库存明细、生成一张拣料入库单(有余量时)、更新库位状态 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void processPickOutBarcodeAll200(List<Task> all200Tasks) { |
| | | if (all200Tasks == null || all200Tasks.isEmpty()) { |
| | | return; |
| | | } |
| | | Task first = all200Tasks.get(0); |
| | | if (!TaskType.TASK_TYPE_PICK_AGAIN_OUT.type.equals(first.getTaskType()) || !TaskStsType.UPDATED_OUT.id.equals(first.getTaskStatus())) { |
| | | throw new CoolException("非拣料出库200任务,不可批量处理"); |
| | | } |
| | | List<Long> taskIds = all200Tasks.stream().map(Task::getId).collect(Collectors.toList()); |
| | | List<TaskItem> allItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, taskIds)); |
| | | if (allItems.isEmpty()) { |
| | | throw new CoolException("任务明细为空"); |
| | | } |
| | | Long loginUserId = SystemAuthUtils.getLoginUserId(); |
| | | if (loginUserId == null) { |
| | | loginUserId = 1L; |
| | | } |
| | | String orgLoc = first.getOrgLoc(); |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, orgLoc)); |
| | | if (loc == null) { |
| | | throw new CoolException("库位不存在:" + orgLoc); |
| | | } |
| | | // 按物料+批次+票号汇总已拣数量 |
| | | Map<String, List<TaskItem>> byKey = allItems.stream().collect(Collectors.groupingBy(ti -> |
| | | (ti.getMatnrId() != null ? ti.getMatnrId() : "") + "_" + (ti.getBatch() != null ? ti.getBatch() : "") + "_" + (ti.getFieldsIndex() != null ? ti.getFieldsIndex() : ""))); |
| | | List<TaskItem> aggregatedForDeduct = new ArrayList<>(); |
| | | Map<String, Double> remainderByKey = new LinkedHashMap<>(); |
| | | for (Map.Entry<String, List<TaskItem>> e : byKey.entrySet()) { |
| | | List<TaskItem> group = e.getValue(); |
| | | double totalQty = group.stream().mapToDouble(ti -> ti.getQty() != null && ti.getQty() > 0 ? ti.getQty() : (ti.getAnfme() != null ? ti.getAnfme() : 0)).sum(); |
| | | TaskItem rep = group.get(0); |
| | | TaskItem forDeduct = new TaskItem(); |
| | | forDeduct.setMatnrId(rep.getMatnrId()).setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setQty(totalQty); |
| | | aggregatedForDeduct.add(forDeduct); |
| | | LambdaQueryWrapper<LocItem> qw = new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()).eq(LocItem::getMatnrId, rep.getMatnrId()); |
| | | if (StringUtils.isNotBlank(rep.getBatch())) qw.eq(LocItem::getBatch, rep.getBatch()); |
| | | else qw.and(w -> w.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, "")); |
| | | if (StringUtils.isNotBlank(rep.getFieldsIndex())) qw.eq(LocItem::getFieldsIndex, rep.getFieldsIndex()); |
| | | else qw.and(w -> w.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, "")); |
| | | LocItem li = locItemService.getOne(qw); |
| | | double remainder = (li != null && li.getAnfme() != null ? li.getAnfme() : 0) - totalQty; |
| | | if (remainder > 0) { |
| | | remainderByKey.put(e.getKey(), remainder); |
| | | } |
| | | } |
| | | subtractLocItemByTaskItems(loc, aggregatedForDeduct, loginUserId); |
| | | // 按 source 分组更新出库单并写库存流水 |
| | | Map<Long, List<TaskItem>> bySource = allItems.stream().collect(Collectors.groupingBy(TaskItem::getSource)); |
| | | for (Map.Entry<Long, List<TaskItem>> e : bySource.entrySet()) { |
| | | Long key = e.getKey(); |
| | | List<TaskItem> items = e.getValue(); |
| | | if (first.getResource() != null && first.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) { |
| | | WaveItem waveItem = waveItemService.getById(key); |
| | | if (waveItem != null) { |
| | | try { |
| | | saveOutStockItem(items, null, waveItem, null, loginUserId); |
| | | } catch (Exception ex) { |
| | | throw new CoolException(ex.getMessage()); |
| | | } |
| | | } |
| | | } else if (first.getResource() != null && first.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) { |
| | | WkOrderItem orderItem = asnOrderItemService.getById(key); |
| | | if (orderItem != null) { |
| | | try { |
| | | saveOutStockItem(items, orderItem, null, null, loginUserId); |
| | | } catch (Exception ex) { |
| | | throw new CoolException(ex.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 有余量则生成一张拣料入库单 |
| | | if (!remainderByKey.isEmpty()) { |
| | | Task pickInTask = new Task(); |
| | | pickInTask.setTaskCode(SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, first)); |
| | | pickInTask.setTaskType(TaskType.TASK_TYPE_PICK_IN.type); |
| | | pickInTask.setTaskStatus(TaskStsType.GENERATE_IN.id); |
| | | pickInTask.setBarcode(first.getBarcode()); |
| | | pickInTask.setOrgLoc(orgLoc); |
| | | pickInTask.setTargLoc(orgLoc); |
| | | pickInTask.setOrgSite(first.getTargSite()); |
| | | pickInTask.setTargSite(first.getTargSite()); |
| | | pickInTask.setResource(first.getResource()); |
| | | if (!this.save(pickInTask)) { |
| | | throw new CoolException("拣料入库任务创建失败"); |
| | | } |
| | | List<LocItemWorking> workings = new ArrayList<>(); |
| | | for (Map.Entry<String, Double> re : remainderByKey.entrySet()) { |
| | | String k = re.getKey(); |
| | | Double rem = re.getValue(); |
| | | if (rem == null || rem <= 0) continue; |
| | | List<TaskItem> group = byKey.get(k); |
| | | if (group == null || group.isEmpty()) continue; |
| | | TaskItem rep = group.get(0); |
| | | TaskItem ti = new TaskItem(); |
| | | ti.setTaskId(pickInTask.getId()); |
| | | ti.setMatnrId(rep.getMatnrId()).setMaktx(rep.getMaktx()).setMatnrCode(rep.getMatnrCode()); |
| | | ti.setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setUnit(rep.getUnit()).setSpec(rep.getSpec()).setModel(rep.getModel()); |
| | | ti.setAnfme(rem).setQty(0.0); |
| | | taskItemService.save(ti); |
| | | LocItemWorking w = new LocItemWorking(); |
| | | w.setTaskId(pickInTask.getId()); |
| | | w.setLocId(loc.getId()); |
| | | w.setLocCode(loc.getCode()); |
| | | w.setMatnrId(rep.getMatnrId()).setMaktx(rep.getMaktx()).setMatnrCode(rep.getMatnrCode()); |
| | | w.setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setUnit(rep.getUnit()); |
| | | w.setAnfme(rem); |
| | | workings.add(w); |
| | | } |
| | | if (!workings.isEmpty()) { |
| | | locItemWorkingService.saveBatch(workings); |
| | | } |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type); |
| | | locService.updateById(loc); |
| | | } else { |
| | | loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type); |
| | | loc.setBarcode(null); |
| | | loc.setUpdateBy(loginUserId); |
| | | loc.setUpdateTime(new Date()); |
| | | locService.updateById(loc); |
| | | } |
| | | for (Long tid : taskIds) { |
| | | locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, tid)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/5/20 |
| | | * @description: 完成出库任务,更新出库库存信息 |
| | |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | } |
| | | |
| | | |
| | | // 空板出库:无任务明细,不需要 PDA 拣货确认,RCS 回调后直接完成库位更新并置为 UPDATED_OUT |
| | | if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)) { |
| | | List<TaskItem> emptyItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (emptyItems.isEmpty()) { |
| | | if (!LocStsType.LOC_STS_TYPE_R.type.equals(loc.getUseStatus())) { |
| | | log.warn("空板出库任务{}的库位{}状态不是R.出库预约,跳过", task.getId(), loc.getCode()); |
| | | return; |
| | | } |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .eq(Loc::getId, loc.getId()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type) |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()))) { |
| | | throw new CoolException("空板出库库位状态更新失败!!"); |
| | | } |
| | | if (!this.update(new LambdaUpdateWrapper<Task>() |
| | | .eq(Task::getId, task.getId()) |
| | | .set(Task::getUpdateBy, loginUserId) |
| | | .set(Task::getUpdateTime, new Date()) |
| | | .set(Task::getTaskStatus, TaskStsType.UPDATED_OUT.id))) { |
| | | throw new CoolException("空板出库任务状态更新失败!!"); |
| | | } |
| | | log.info("[空板出库] 任务{} RCS回调后已直接完成库位更新,无需PDA确认", task.getTaskCode()); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("任务明细不存在!!"); |
| | |
| | | |
| | | // 根据任务类型更新库位状态 |
| | | if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) { |
| | | /**修改为库位状态为S.预约入库,保留原有库位*/ |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>() |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type) |
| | | .set(Loc::getBarcode, null) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()) |
| | | .eq(Loc::getId, loc.getId()))) { |
| | | throw new CoolException("库位状态修改失败!!"); |
| | | } |
| | | // 拣料出库/盘点出库:在未生成拣料入库单之前保持 R.预约出库,否则下发任务时查不到该库位(只查 F+R)导致“库存不足” |
| | | // 等 PDA 确认并生成拣料入库任务时,再在 pickOrCheckTask 中将目标库位改为 S.预约入库 |
| | | } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) { |
| | | // 全版出库:不更新库位状态为O,等待PDA快速拣货确认时再更新 |
| | | // 库位状态保持原样(R.出库预约状态) |
| | |
| | | rcsApi != null ? rcsApi.getPort() : "null"); |
| | | return; |
| | | } |
| | | |
| | | // 同料箱号规则:101 任务所在料箱号下若已存在 196/198/199/200 任务,则不向 RCS 发送该 101 任务(/api/open/bus/submit) |
| | | List<Integer> higherStatuses = Arrays.asList(TaskStsType.AWAIT.id, TaskStsType.COMPLETE_OUT.id, TaskStsType.WAVE_SEED.id, TaskStsType.UPDATED_OUT.id); |
| | | List<Task> higherTasks = this.list(new LambdaQueryWrapper<Task>() |
| | | .in(Task::getTaskStatus, higherStatuses) |
| | | .isNotNull(Task::getBarcode) |
| | | .ne(Task::getBarcode, "")); |
| | | Set<String> barcodesWithHigher = higherTasks.stream().map(Task::getBarcode).filter(StringUtils::isNotBlank).collect(Collectors.toSet()); |
| | | List<Task> toSend = tasks.stream() |
| | | .filter(t -> { |
| | | if (TaskStsType.GENERATE_OUT.id.equals(t.getTaskStatus()) && StringUtils.isNotBlank(t.getBarcode()) && barcodesWithHigher.contains(t.getBarcode())) { |
| | | log.debug("同料箱号{}下已存在196/198/199/200任务,跳过101任务下发:taskId={}", t.getBarcode(), t.getId()); |
| | | return false; |
| | | } |
| | | return true; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | if (toSend.isEmpty()) { |
| | | log.debug("过滤后无待下发任务"); |
| | | return; |
| | | } |
| | | tasks = toSend; |
| | | |
| | | String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask; |
| | | |
| | | |
| | | for (Task task : tasks) { |
| | | WcsTaskParams taskParams = new WcsTaskParams(); |
| | | List<TaskItemParam> items = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId())); |
| | | // 空板入库无任务明细,仅更新库位为空板(D)、任务状态为库存更新完成 |
| | | if (TaskType.TASK_TYPE_EMPITY_IN.type.equals(task.getTaskType())) { |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()) |
| | | .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type) |
| | | .set(Loc::getUpdateBy, loginUserId) |
| | | .set(Loc::getUpdateTime, new Date()))) { |
| | | throw new CoolException("空板入库库位状态修改失败!!"); |
| | | } |
| | | if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) { |
| | | throw new CoolException("空板入库任务状态修改失败!!"); |
| | | } |
| | | reportInOutResultToCloud(task, loc, Collections.emptyList(), null, true); |
| | | return; |
| | | } |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("任务明细不存在!!"); |
| | | } |
| | |
| | | .set(WaitPakin::getUpdateBy, loginUserId) |
| | | .in(WaitPakin::getId, pakinIds))) { |
| | | throw new CoolException("组拖状态修改失败!!"); |
| | | } |
| | | |
| | | // 组托入库完成后累加订单及明细的已收数量,用于后续判断整单是否可置为已完成 |
| | | Map<Long, Double> orderIdToAdd = new HashMap<>(); |
| | | Map<Long, Double> itemIdToAdd = new HashMap<>(); |
| | | for (WaitPakinItem p : pakinItems) { |
| | | if (StringUtils.isBlank(p.getAsnCode())) { |
| | | continue; |
| | | } |
| | | WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, p.getAsnCode())); |
| | | if (order == null) { |
| | | continue; |
| | | } |
| | | double addQty = (p.getAnfme() != null ? p.getAnfme() : 0.0); |
| | | orderIdToAdd.merge(order.getId(), addQty, Double::sum); |
| | | if (p.getAsnItemId() != null) { |
| | | itemIdToAdd.merge(p.getAsnItemId(), addQty, Double::sum); |
| | | } |
| | | } |
| | | for (Map.Entry<Long, Double> e : orderIdToAdd.entrySet()) { |
| | | WkOrder o = asnOrderService.getById(e.getKey()); |
| | | if (o != null) { |
| | | Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(o.getQty() != null ? o.getQty() : 0.0, e.getValue())); |
| | | o.setQty(newQty); |
| | | if (!asnOrderService.updateById(o)) { |
| | | throw new CoolException("入库单完成数量更新失败!!"); |
| | | } |
| | | } |
| | | } |
| | | for (Map.Entry<Long, Double> e : itemIdToAdd.entrySet()) { |
| | | WkOrderItem oi = asnOrderItemService.getById(e.getKey()); |
| | | if (oi != null) { |
| | | Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(oi.getQty() != null ? oi.getQty() : 0.0, e.getValue())); |
| | | oi.setQty(newQty); |
| | | if (!asnOrderItemService.updateById(oi)) { |
| | | throw new CoolException("入库单明细完成数量更新失败!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /**修改库位状态为F.在库*/ |
| | |
| | | locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, "")); |
| | | } |
| | | |
| | | // 票号匹配:如果taskItem有票号,则必须匹配;如果taskItem没有票号,则查询票号为null或空字符串的记录 |
| | | if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) { |
| | | locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex()); |
| | | } else { |
| | | locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, "")); |
| | | } |
| | | // 票号暂不使用,不按票号匹配,只查票号为 null 或空的库位明细 |
| | | // if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) { |
| | | // locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex()); |
| | | // } else { |
| | | locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, "")); |
| | | // } |
| | | |
| | | LocItem locItem = locItemService.getOne(locItemWrapper); |
| | | if (Objects.isNull(locItem)) { |