| | |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.utils.LocUtils; |
| | | import com.vincent.rsf.server.manager.constant.CloudWmsInoutReportMode; |
| | | import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams; |
| | | import com.vincent.rsf.server.manager.entity.CloudWmsNotifyLog; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | |
| | | log.info("入/出库结果上报待办跳过:无云仓来源单据,taskId={}", task.getId()); |
| | | return; |
| | | } |
| | | Set<Long> orderIdSet = taskItems.stream() |
| | | .filter(Objects::nonNull) |
| | | .map(TaskItem::getOrderId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, WkOrder> orderById = new HashMap<>(); |
| | | if (!orderIdSet.isEmpty()) { |
| | | for (WkOrder o : asnOrderService.listByIds(orderIdSet)) { |
| | | if (o != null && o.getId() != null) { |
| | | orderById.put(o.getId(), o); |
| | | } |
| | | } |
| | | } |
| | | Set<String> orderCodeSet = new HashSet<>(); |
| | | for (TaskItem ti : taskItems) { |
| | | if (ti == null) { |
| | | continue; |
| | | } |
| | | String on = isInbound && ti.getSource() != null |
| | | ? sourceToOrderNo.get(ti.getSource()) |
| | | : (ti.getPlatOrderCode() != null ? ti.getPlatOrderCode() : ti.getPlatWorkCode()); |
| | | if (on == null && isInbound) { |
| | | on = ti.getPlatOrderCode() != null ? ti.getPlatOrderCode() : ti.getPlatWorkCode(); |
| | | } |
| | | if (StringUtils.isNotBlank(on)) { |
| | | orderCodeSet.add(on); |
| | | } |
| | | } |
| | | Map<String, WkOrder> orderByCode = new HashMap<>(); |
| | | if (!orderCodeSet.isEmpty()) { |
| | | for (WkOrder o : asnOrderService.list(new LambdaQueryWrapper<WkOrder>().in(WkOrder::getCode, orderCodeSet))) { |
| | | if (o != null && StringUtils.isNotBlank(o.getCode())) { |
| | | orderByCode.put(o.getCode(), o); |
| | | } |
| | | } |
| | | } |
| | | ObjectMapper om = new ObjectMapper(); |
| | | Date now = new Date(); |
| | | Map<String, List<InOutResultReportParam>> byOrder = new LinkedHashMap<>(); |
| | | for (TaskItem item : taskItems) { |
| | | if (item == null) { |
| | | continue; |
| | |
| | | if (orderNo == null || item.getMatnrCode() == null) { |
| | | continue; |
| | | } |
| | | WkOrder asnOrder = null; |
| | | if (item.getOrderId() != null) { |
| | | asnOrder = orderById.get(item.getOrderId()); |
| | | } |
| | | if (asnOrder == null) { |
| | | asnOrder = orderByCode.get(orderNo); |
| | | } |
| | | InOutResultReportParam param = new InOutResultReportParam() |
| | | .setOrderNo(orderNo) |
| | | .setPlanNo(item.getPlatWorkCode()) |
| | | .setWkType(item.getWkType()) |
| | | .setUnitNo(item.getUnit()) |
| | | .setLineId(item.getPlatItemId()) |
| | | .setWareHouseId(wareHouseId) |
| | | .setDocWarehouseNo(asnOrder != null ? asnOrder.getDocTaskWarehouseNo() : null) |
| | | .setOrgNo(asnOrder != null ? asnOrder.getDocOrgNo() : null) |
| | | .setInWarehouseNo(isInbound && asnOrder != null ? asnOrder.getDocInWarehouseNo() : null) |
| | | .setOutWarehouseNo(!isInbound && asnOrder != null ? asnOrder.getDocOutWarehouseNo() : null) |
| | | .setLocId(locId) |
| | | .setMatNr(item.getMatnrCode()) |
| | | .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0") |
| | | .setBatch(item.getBatch()) |
| | | .setInbound(isInbound) |
| | | .setBarcode(task.getBarcode()); |
| | | try { |
| | | String requestBody = om.writeValueAsString(param); |
| | | CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog() |
| | | .setReportType(cloudWmsNotifyLogService.getReportTypeInOutResult()) |
| | | .setRequestBody(requestBody) |
| | | .setNotifyStatus(cloudWmsNotifyLogService.getNotifyStatusPending()) |
| | | .setRetryCount(0) |
| | | .setBizRef("taskId=" + task.getId() + ",orderNo=" + orderNo) |
| | | .setCreateTime(now) |
| | | .setUpdateTime(now); |
| | | cloudWmsNotifyLogService.fillFromConfig(notifyLog); |
| | | cloudWmsNotifyLogService.save(notifyLog); |
| | | } catch (JsonProcessingException e) { |
| | | log.warn("入/出库结果上报待办落库失败(不影响主流程),taskId={},orderNo={}:{}", task.getId(), orderNo, e.getMessage()); |
| | | byOrder.computeIfAbsent(orderNo, k -> new ArrayList<>()).add(param); |
| | | } |
| | | String mode = resolveCloudWmsInoutReportMode(); |
| | | boolean sendHold = CloudWmsInoutReportMode.MANUAL.equals(mode) || CloudWmsInoutReportMode.WAIT_ORDER.equals(mode); |
| | | for (Map.Entry<String, List<InOutResultReportParam>> e : byOrder.entrySet()) { |
| | | String orderNo = e.getKey(); |
| | | for (InOutResultReportParam param : e.getValue()) { |
| | | try { |
| | | String requestBody = om.writeValueAsString(param); |
| | | CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog() |
| | | .setReportType(cloudWmsNotifyLogService.getReportTypeInOutResult()) |
| | | .setRequestBody(requestBody) |
| | | .setRetryCount(0) |
| | | .setBizRef("taskId=" + task.getId() + ",orderNo=" + orderNo) |
| | | .setCreateTime(now) |
| | | .setUpdateTime(now) |
| | | .setSourceOrderNo(orderNo) |
| | | .setInboundFlag(isInbound ? 1 : 0) |
| | | .setWareHouseCode(wareHouseId) |
| | | .setSendHold(sendHold ? 1 : 0) |
| | | .setSending(0); |
| | | cloudWmsNotifyLogService.fillFromConfig(notifyLog); |
| | | cloudWmsNotifyLogService.save(notifyLog); |
| | | } catch (JsonProcessingException ex) { |
| | | log.warn("入/出库结果上报待办落库失败(不影响主流程),taskId={},orderNo={}:{}", task.getId(), orderNo, ex.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | return StringUtils.isNotBlank(item.getPlatOrderCode()) |
| | | || StringUtils.isNotBlank(item.getPlatWorkCode()); |
| | | } |
| | | |
| | | /** sys_config CLOUD_WMS_INOUT_REPORT_MODE:immediate / wait_order / manual / single */ |
| | | private String resolveCloudWmsInoutReportMode() { |
| | | try { |
| | | Config cfg = configService.getCachedOrLoad(GlobalConfigCode.CLOUD_WMS_INOUT_REPORT_MODE); |
| | | if (cfg != null && StringUtils.isNotBlank(cfg.getVal())) { |
| | | return cfg.getVal().trim().toLowerCase(); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | return CloudWmsInoutReportMode.IMMEDIATE; |
| | | } |
| | | } |