diff --git a/src/main/java/com/gaotao/modules/api/entity/NotifyDataToWcs.java b/src/main/java/com/gaotao/modules/api/entity/NotifyDataToWcs.java index 708794c..9668732 100644 --- a/src/main/java/com/gaotao/modules/api/entity/NotifyDataToWcs.java +++ b/src/main/java/com/gaotao/modules/api/entity/NotifyDataToWcs.java @@ -8,6 +8,7 @@ import java.util.List; @Data public class NotifyDataToWcs { private String site;//工厂编码 + private String notifyNo;//申请单号 private String taskNo;//任务单号 private Integer itemNo; //任务行号 private String orderNo;//生产订单 diff --git a/src/main/java/com/gaotao/modules/customer/service/impl/ShipmentIssueServiceImpl.java b/src/main/java/com/gaotao/modules/customer/service/impl/ShipmentIssueServiceImpl.java index d67b890..54a0631 100644 --- a/src/main/java/com/gaotao/modules/customer/service/impl/ShipmentIssueServiceImpl.java +++ b/src/main/java/com/gaotao/modules/customer/service/impl/ShipmentIssueServiceImpl.java @@ -286,16 +286,16 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { @Override public SOIssueNotifyHeader checkUserHasUnissueShipment(SOIssueNotifyHeader data) { System.out.println("开始检查用户是否有未下达的shipment申请单 - rqrq,site=" + data.getSite() + ", username=" + data.getUsername()); - + // 调用Mapper查询用户是否有状态为UNISSUE且ordertype=shipment的数据 - rqrq SOIssueNotifyHeader result = shipmentIssueMapper.checkUserHasUnissueShipment(data); - + if (result != null) { System.out.println("用户有未下达的shipment申请单 - rqrq,notifyNo=" + result.getNotifyNo()); } else { System.out.println("用户没有未下达的shipment申请单 - rqrq"); } - + return result; } @@ -308,25 +308,25 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { @Transactional public void cancelIssueShipment(SOIssueNotifyHeader data) { System.out.println("开始取消下达发货申请单 - rqrq,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + // 查询申请单信息,检查是否已推送WCS - rqrq QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("site", data.getSite()); queryWrapper.eq("notify_no", data.getNotifyNo()); SOIssueNotifyHeader notifyHeader = shipmentIssueMapper.selectOne(queryWrapper); - + if (notifyHeader == null) { throw new RuntimeException("发货申请单不存在"); } - + // 判断是否已推送WCS,如果已推送则不允许取消下达 - rqrq if (!"未推送".equals(notifyHeader.getPushWcsFlag())) { throw new RuntimeException("发货申请单已推送WCS,不允许取消下达"); } - + // 更新申请单状态为UNISSUE - rqrq shipmentIssueMapper.cancelIssueShipment(data); - + System.out.println("取消下达发货申请单完成 - rqrq"); } @@ -339,11 +339,11 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { @Override public List checkShipmentInventory(SOIssueNotifyHeader data) { System.out.println("开始检查发货通知单物料库存匹配情况 - rqrq,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + // 调用存储过程CheckShipmentIssueNotifyInventory(只考虑立库) - rqrq - List list = + List list = shipmentIssueMapper.checkShipmentInventory(data.getSite(), data.getNotifyNo()); - + System.out.println("检查发货通知单物料库存匹配情况完成,共" + list.size() + "条记录 - rqrq"); return list; } @@ -359,32 +359,32 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { String username = ShiroUtils.getUserEntity().getUsername(); String site = data.getSite(); String notifyNo = data.getNotifyNo(); - + System.out.println("开始推送发货通知单库存预览数据至WCS - rqrq,notifyNo=" + notifyNo + ", site=" + site); - + List inventoryList = data.getShipmentInventoryList(); if (inventoryList == null || inventoryList.isEmpty()) { throw new RuntimeException("库存预览数据为空,无法推送"); } - + // 1. 筛选出orderSatisfactionStatus = 1 的数据(只有完全满足的才推送,发货通知单没有黄色状态) - rqrq List validList = inventoryList.stream() .filter(item -> item.getOrderSatisfactionStatus() != null && item.getOrderSatisfactionStatus() == 1) .collect(Collectors.toList()); - + // 2. 获取传入的原始订单总数(按生产订单分组统计)- rqrq int originalOrderCount = (int) data.getShipmentInventoryList().stream() .map(com.gaotao.modules.customer.entity.ShipmentInventoryCheckResult::getProductionOrderNo) .distinct() .count(); System.out.println("前端传入的订单总数:" + originalOrderCount + " - rqrq"); - + System.out.println("筛选后满足库存要求的数据:" + validList.size() + "条 - rqrq"); - + if (validList.isEmpty()) { throw new RuntimeException("没有满足库存要求的订单数据"); } - + // 3. 提取所有条码(序列号) - rqrq List allSerialNos = new ArrayList<>(); for (com.gaotao.modules.customer.entity.ShipmentInventoryCheckResult item : validList) { @@ -397,54 +397,54 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { } } } - + System.out.println("提取到条码总数:" + allSerialNos.size() + " - rqrq"); - + // 4. 前置校验:检查reserve_flag - rqrq List reservedUnits = newIssureMapper.checkReserveFlagBySerialNos(site, allSerialNos); if (!reservedUnits.isEmpty()) { throw new RuntimeException("已经有物料被其他任务领走,请重新打开推送界面计算库存。"); } System.out.println("reserve_flag校验通过 - rqrq"); - + // 5. 前置校验:查询栈板并检查calling_flag - rqrq List palletIds = newIssureMapper.getPalletIdsBySerialNos(site, allSerialNos); if (palletIds == null || palletIds.isEmpty()) { throw new RuntimeException("未找到条码对应的栈板信息"); } System.out.println("找到栈板数量:" + palletIds.size() + " - rqrq"); - + List callingPallets = newIssureMapper.checkCallingFlagByPalletIds(site, palletIds); if (!callingPallets.isEmpty()) { throw new RuntimeException("已经有栈板被其他任务领走,请重新打开推送界面计算库存。"); } System.out.println("calling_flag校验通过 - rqrq"); - + // 6. 按ProductionOrderNo分组 - rqrq Map> groupedByOrder = validList.stream() .collect(Collectors.groupingBy(com.gaotao.modules.customer.entity.ShipmentInventoryCheckResult::getProductionOrderNo)); - + int validOrderCount = groupedByOrder.size(); System.out.println("按生产订单分组,满足条件的订单数:" + validOrderCount + "个 - rqrq"); - + Date currentTime = new Date(); int successCount = 0; // 统计成功推送的订单数 - rqrq - + // 7. 遍历每个生产订单 - rqrq for (Map.Entry> entry : groupedByOrder.entrySet()) { String productionOrderNo = entry.getKey(); List orderItems = entry.getValue(); - + try { System.out.println("开始处理订单:" + productionOrderNo + " - rqrq"); - + // 7.1 获取itemNo - rqrq BigDecimal itemNo = newIssureMapper.getItemNoByNotifyNoAndOrderNo(site, notifyNo, productionOrderNo); if (itemNo == null) { throw new RuntimeException("未找到订单" + productionOrderNo + "的itemNo"); } System.out.println("订单" + productionOrderNo + "的itemNo=" + itemNo + " - rqrq"); - + // 7.1.1 一次性查询订单行完整信息(优化:减少数据库查询)- rqrq SOIssueNotifyOrderList orderInfo = newIssureMapper.getOrderListByNotifyNoAndItemNo(site, notifyNo, itemNo); if (orderInfo == null) { @@ -461,7 +461,7 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { TransNoControl transData = transNoService.getTransNo(site, "WOT", 10); String taskNo = transData.getNewTransNo(); System.out.println("生成任务编号:" + taskNo + " - rqrq"); - + // 7.3 准备wms_order_task对象(暂不插入数据库)- rqrq WmsOrderTask orderTask = new WmsOrderTask(); orderTask.setSite(site); @@ -494,7 +494,7 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { orderTask.setWmsStatus("已创建"); orderTask.setToArea(productionArea); // 设置生产区域 - rqrq System.out.println("准备wms_order_task对象 - rqrq"); - + // 7.4 提取本订单的所有序列号和栈板 - rqrq List orderSerialNos = new ArrayList<>(); for (com.gaotao.modules.customer.entity.ShipmentInventoryCheckResult item : orderItems) { @@ -507,15 +507,15 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { } } } - + List orderPalletIds = newIssureMapper.getPalletIdsBySerialNos(site, orderSerialNos); System.out.println("订单" + productionOrderNo + "涉及栈板数量:" + orderPalletIds.size() + " - rqrq"); - + // 7.5 准备wms_order_task_detail对象列表(暂不插入数据库)- rqrq List taskDetailList = new ArrayList<>(); int seqNo = 1; for (String palletId : orderPalletIds) { - com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail = + com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail = new com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail(); taskDetail.setSite(site); taskDetail.setTaskNo(taskNo); @@ -537,10 +537,10 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { wcsIntegrationMapper.updatePalletCallingFlag(site,palletId,"Y","发货申请单"); } System.out.println("准备wms_order_task_detail对象" + orderPalletIds.size() + "条 - rqrq"); - + // 7.6 准备SOIssueNotifyOrderMaterialList_detail对象列表(暂不插入数据库)- rqrq List detailList = new ArrayList<>(); - + // 构建序列号到栈板ID的映射关系 - rqrq Map serialNoPalletMap = new HashMap<>(); for (String serialNo : orderSerialNos) { @@ -550,34 +550,34 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { } } System.out.println("构建序列号到栈板的映射关系,共" + serialNoPalletMap.size() + "条 - rqrq"); - + // 构建栈板ID到SeqNo的映射关系 - rqrq Map palletSeqMap = new HashMap<>(); for (com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail : taskDetailList) { palletSeqMap.put(taskDetail.getPalletId(), taskDetail.getSeqNo()); } System.out.println("构建栈板到SeqNo的映射关系,共" + palletSeqMap.size() + "条 - rqrq"); - + for (com.gaotao.modules.customer.entity.ShipmentInventoryCheckResult item : orderItems) { String matchedBarcodes = item.getMatchedBarcodes(); if (StringUtils.isNotBlank(matchedBarcodes)) { String[] barcodes = matchedBarcodes.split(","); for (String barcode : barcodes) { String serialNo = barcode.trim().split("\\(")[0]; - + // 根据序列号得知这个序列号在哪个栈板上,再去taskDetailList去寻找SeqNo - rqrq String palletId = serialNoPalletMap.get(serialNo); Integer taskSeq = null; if (palletId != null) { taskSeq = palletSeqMap.get(palletId); } - + // 如果找不到对应的SeqNo,记录警告并跳过 - rqrq if (taskSeq == null) { System.err.println("警告:序列号" + serialNo + "找不到对应的栈板SeqNo,跳过 - rqrq"); taskSeq = 0; } - + // 查询序列号的location_id,如果不是AS区域则直接标记为已出库 - rqrq String locationId = newIssureMapper.getSerialNoLocationId(site, serialNo); String outWcsFlag = "N"; @@ -585,8 +585,8 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { outWcsFlag = "Y"; System.out.println("序列号" + serialNo + "不在AS区域(location_id=" + locationId + "),直接标记为已出库 - rqrq"); } - - com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail detail = + + com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail detail = new com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail(); detail.setSite(site); detail.setNotifyNo(notifyNo); @@ -604,9 +604,10 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { } } System.out.println("准备SOIssueNotifyOrderMaterialList_detail对象" + detailList.size() + "条 - rqrq"); - + // 7.7 构建WCS数据 - rqrq NotifyDataToWcs wcsData = new NotifyDataToWcs(); + wcsData.setNotifyNo(notifyNo); wcsData.setSite(site); wcsData.setTaskNo(taskNo); wcsData.setOrderNo(productionOrderNo); @@ -622,13 +623,13 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { wcsData.setOrderType(3); } System.out.println("订单类型映射:" + orderTypeFromDb + " -> " + wcsData.getOrderType() + " - rqrq"); - + // 构建栈板列表 - rqrq List palletList = new ArrayList<>(); for (String palletId : orderPalletIds) { // 查询该栈板上本订单相关的序列号的明细信息 - rqrq List palletDetails = newIssureMapper.getPalletDetailsByPalletAndSerials(site, palletId, orderSerialNos); - + if (palletDetails != null && !palletDetails.isEmpty()) { // 按position和layer分组 - rqrq Map>> groupedByPositionLayer = new java.util.HashMap<>(); @@ -636,97 +637,97 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { String position = detail.getPosition(); Integer layer = detail.getLayer(); String serialNo = detail.getSerialNo(); - + groupedByPositionLayer .computeIfAbsent(position, k -> new java.util.HashMap<>()) .computeIfAbsent(layer, k -> new ArrayList<>()) .add(serialNo); } - + // 构建NotifyDataToWcsPalletList - rqrq NotifyDataToWcsPalletList palletData = new NotifyDataToWcsPalletList(); palletData.setPalletCode(palletId); - + List subDetailList = new ArrayList<>(); for (Map.Entry>> posEntry : groupedByPositionLayer.entrySet()) { String position = posEntry.getKey(); for (Map.Entry> layerEntry : posEntry.getValue().entrySet()) { Integer layer = layerEntry.getKey(); List serialNos = layerEntry.getValue(); - + NotifyDataToWcsPalletSubDetail subDetail = new NotifyDataToWcsPalletSubDetail(); subDetail.setPosition(Integer.parseInt(position)); subDetail.setLayer(layer); subDetail.setRfidBarcodes(serialNos); - + subDetailList.add(subDetail); } } - + palletData.setMaterials(subDetailList); palletList.add(palletData); } } - + wcsData.setMaterialRequisitions(palletList); System.out.println("构建WCS数据完成,栈板数:" + palletList.size() + " - rqrq"); - + // 7.8 先调用WCS接口(成功后再执行数据库操作)- rqrq System.out.println("开始调用WCS接口 - rqrq"); try { wcsApiService.pushNotifyToWcsApi(wcsData); System.out.println("WCS接口调用成功 - rqrq"); - + } catch (Exception e) { String errorMsg = e.getMessage(); System.err.println("WCS接口调用失败:" + errorMsg + " - rqrq"); - + // 超时错误直接抛出 - rqrq if (errorMsg != null && (errorMsg.contains("timeout") || errorMsg.contains("超时"))) { throw new RuntimeException("WCS接口调用超时:" + errorMsg); } - + // 其他错误跳过本次循环 - rqrq System.err.println("订单" + productionOrderNo + "推送失败,跳过继续处理下一个订单 - rqrq"); continue; } - + // 7.9 WCS推送成功后,执行数据库操作 - rqrq System.out.println("WCS推送成功,开始保存数据库记录 - rqrq"); - + // 7.9.1 插入wms_order_task - rqrq wcsIntegrationMapper.insertOrderTask(orderTask); System.out.println("创建wms_order_task记录成功 - rqrq"); - + // 7.9.2 批量插入wms_order_task_detail - rqrq for (com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail : taskDetailList) { wcsIntegrationMapper.insertWmsOrderTaskDetail(taskDetail); } System.out.println("创建wms_order_task_detail记录" + taskDetailList.size() + "条 - rqrq"); - + // 7.9.3 更新handling_unit的reserve标志 - rqrq newIssureMapper.updateHandlingUnitReserveFlag(site, orderSerialNos, notifyNo, itemNo, productionOrderNo); System.out.println("更新handling_unit的reserve标志完成 - rqrq"); - + // 7.9.4 更新栈板的calling_flag - rqrq newIssureMapper.updatePalletCallingFlag(site, orderPalletIds); System.out.println("更新栈板calling_flag完成 - rqrq"); - + // 7.9.5 批量插入SOIssueNotifyOrderMaterialList_detail - rqrq if (!detailList.isEmpty()) { newIssureMapper.batchInsertMaterialListDetail(detailList); System.out.println("创建SOIssueNotifyOrderMaterialList_detail记录" + detailList.size() + "条 - rqrq"); } - + // 7.9.6 更新SOIssueNotifyOrderList的push_wms_flag - rqrq newIssureMapper.updateOrderListPushWmsFlag(site, notifyNo, itemNo); System.out.println("更新push_wms_flag=Y - rqrq"); - + System.out.println("订单" + productionOrderNo + "处理完成 - rqrq"); - + // 成功推送,计数+1 - rqrq successCount++; - + } catch (RuntimeException e) { // 超时错误向上抛出 - rqrq if (e.getMessage().contains("超时") || e.getMessage().contains("timeout")) { @@ -736,7 +737,7 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { System.err.println("处理订单" + productionOrderNo + "失败:" + e.getMessage() + " - rqrq"); } } - + // 8. 判断推送状态并更新SOIssueNotifyHeader的push_wcs_flag - rqrq if (successCount == 0) { // 一条都没成功,不改变push_wcs_flag状态 - rqrq @@ -745,11 +746,11 @@ public class ShipmentIssueServiceImpl implements ShipmentIssueService { // 使用原始订单总数判断,发货通知单只有完全推送完成/部分推送两种状态 - rqrq String pushWcsFlag = (successCount == originalOrderCount) ? "推送完成" : "部分推送"; System.out.println("推送结果统计:传入" + originalOrderCount + "个订单,满足条件" + validOrderCount + "个,成功推送" + successCount + "个,最终状态=" + pushWcsFlag + " - rqrq"); - + newIssureMapper.updateNotifyHeaderPushWcsFlag(site, notifyNo, pushWcsFlag); System.out.println("更新申请单push_wcs_flag=" + pushWcsFlag + " - rqrq"); } - + System.out.println("推送发货通知单库存预览数据至WCS完成 - rqrq"); } diff --git a/src/main/java/com/gaotao/modules/notify/service/impl/NewIssureServiceImpl.java b/src/main/java/com/gaotao/modules/notify/service/impl/NewIssureServiceImpl.java index c69be45..8fe091a 100644 --- a/src/main/java/com/gaotao/modules/notify/service/impl/NewIssureServiceImpl.java +++ b/src/main/java/com/gaotao/modules/notify/service/impl/NewIssureServiceImpl.java @@ -118,35 +118,35 @@ public class NewIssureServiceImpl implements NewIssureService { if (file == null || file.isEmpty()) { throw new RuntimeException("请选择要上传的文件"); } - + String fileName = file.getOriginalFilename(); if (StringUtils.isBlank(fileName)) { throw new RuntimeException("文件名不能为空"); } - + String fileExtension = fileName.substring(fileName.lastIndexOf(".")).toLowerCase(); if (!".xls".equals(fileExtension) && !".xlsx".equals(fileExtension)) { throw new RuntimeException("文件格式不正确,只支持.xls和.xlsx格式的Excel文件"); } - + // 使用ExcelUtil读取Excel文件 List> excelDataList = ExcelUtil.readExcelToMapList(file); - + if (excelDataList.isEmpty()) { throw new RuntimeException("Excel文件中没有有效数据"); } - + // 转换为NotifyExcelData列表 List notifyExcelDataList = new ArrayList<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - + for (int i = 0; i < excelDataList.size(); i++) { Map rowData = excelDataList.get(i); int rowIndex = i + 2; // Excel行号(考虑表头) - + try { NotifyExcelData notifyData = new NotifyExcelData(); - + // 第一列:site Object siteObj = rowData.get("0"); if (siteObj == null || StringUtils.isBlank(siteObj.toString())) { @@ -156,28 +156,28 @@ public class NewIssureServiceImpl implements NewIssureService { throw new RuntimeException("第" + rowIndex + "行的工厂编码(site)与当前工厂不一致"); } notifyData.setSite(siteObj.toString().trim()); - + // 第二列:orderNo Object orderNoObj = rowData.get("1"); if (orderNoObj == null || StringUtils.isBlank(orderNoObj.toString())) { throw new RuntimeException("第" + rowIndex + "行的订单号(orderNo)不能为空"); } notifyData.setOrderNo(orderNoObj.toString().trim()); - + // 第三列:releaseNo Object releaseNoObj = rowData.get("2"); if (releaseNoObj == null || StringUtils.isBlank(releaseNoObj.toString())) { throw new RuntimeException("第" + rowIndex + "行的发布号(releaseNo)不能为空"); } notifyData.setReleaseNo(releaseNoObj.toString().trim()); - + // 第四列:sequenceNo Object sequenceNoObj = rowData.get("3"); if (sequenceNoObj == null || StringUtils.isBlank(sequenceNoObj.toString())) { throw new RuntimeException("第" + rowIndex + "行的序列号(sequenceNo)不能为空"); } notifyData.setSequenceNo(sequenceNoObj.toString().trim()); - + // 第五列:bomLineNo Object bomLineNoObj = rowData.get("4"); if (bomLineNoObj == null || StringUtils.isBlank(bomLineNoObj.toString())) { @@ -192,14 +192,14 @@ public class NewIssureServiceImpl implements NewIssureService { } catch (NumberFormatException e) { throw new RuntimeException("第" + rowIndex + "行的BOM行号(bomLineNo)必须是有效的整数"); } - + // 第六列:materialPartNo Object materialPartNoObj = rowData.get("5"); if (materialPartNoObj == null || StringUtils.isBlank(materialPartNoObj.toString())) { throw new RuntimeException("第" + rowIndex + "行的物料编码(materialPartNo)不能为空"); } notifyData.setMaterialPartNo(materialPartNoObj.toString().trim()); - + // 第七列:needDate Object needDateObj = rowData.get("6"); if (needDateObj == null || StringUtils.isBlank(needDateObj.toString())) { @@ -211,7 +211,7 @@ public class NewIssureServiceImpl implements NewIssureService { } catch (ParseException e) { throw new RuntimeException("第" + rowIndex + "行的需求日期(needDate)格式不正确,请使用YYYY-MM-DD格式"); } - + // 第八列:qty Object qtyObj = rowData.get("7"); if (qtyObj == null || StringUtils.isBlank(qtyObj.toString())) { @@ -226,20 +226,20 @@ public class NewIssureServiceImpl implements NewIssureService { } catch (NumberFormatException e) { throw new RuntimeException("第" + rowIndex + "行的数量(qty)必须是有效的数字"); } - + notifyExcelDataList.add(notifyData); - + } catch (Exception e) { throw new RuntimeException("第" + rowIndex + "行数据处理异常: " + e.getMessage()); } } - + // 打印解析结果到控制台 System.out.println("=== Excel解析结果 ==="); System.out.println("共解析到 " + notifyExcelDataList.size() + " 条数据:"); for (int i = 0; i < notifyExcelDataList.size(); i++) { NotifyExcelData data = notifyExcelDataList.get(i); - System.out.println("第" + (i + 1) + "条: site=" + data.getSite() + System.out.println("第" + (i + 1) + "条: site=" + data.getSite() + ", orderNo=" + data.getOrderNo() + ", releaseNo=" + data.getReleaseNo() + ", sequenceNo=" + data.getSequenceNo() @@ -249,45 +249,45 @@ public class NewIssureServiceImpl implements NewIssureService { + ", qty=" + data.getQty()); } System.out.println("=== 解析完成 ==="); - + // 按 site+orderNo+releaseNo+sequenceNo 分组 Map> groupedDataMap = notifyExcelDataList.stream() - .collect(Collectors.groupingBy(data -> + .collect(Collectors.groupingBy(data -> data.getSite() + "|" + data.getOrderNo() + "|" + data.getReleaseNo() + "|" + data.getSequenceNo() )); - + System.out.println("=== 分组处理开始 ==="); System.out.println("共分为 " + groupedDataMap.size() + " 个工单组:"); - + // 遍历每个分组,进行业务处理 for (Map.Entry> entry : groupedDataMap.entrySet()) { String groupKey = entry.getKey(); List groupData = entry.getValue(); - + // 解析分组key String[] keyParts = groupKey.split("\\|"); String site2 = keyParts[0]; String orderNo = keyParts[1]; String releaseNo = keyParts[2]; String sequenceNo = keyParts[3]; - + System.out.println("处理工单组: site=" + site2 + ", orderNo=" + orderNo + - ", releaseNo=" + releaseNo + ", sequenceNo=" + sequenceNo + + ", releaseNo=" + releaseNo + ", sequenceNo=" + sequenceNo + ", 包含物料数量=" + groupData.size()); - + // TODO: 在这里添加你自己的业务逻辑代码 // 参数说明: // - site: 工厂编码 - // - orderNo: 订单号 + // - orderNo: 订单号 // - releaseNo: 发布号 // - sequenceNo: 序列号 // - groupData: 该工单下的所有物料列表 processWorkOrderGroup(site2, orderNo, releaseNo, sequenceNo, groupData, notifyNo); } - + System.out.println("=== 分组处理完成 ==="); } - + /** * 处理单个工单组的业务逻辑 * @param site 工厂编码 @@ -297,32 +297,32 @@ public class NewIssureServiceImpl implements NewIssureService { * @param materialList 该工单下的物料列表 * @param notifyNo 申请单号 */ - private void processWorkOrderGroup(String site, String orderNo, String releaseNo, + private void processWorkOrderGroup(String site, String orderNo, String releaseNo, String sequenceNo, List materialList, String notifyNo) { try { System.out.println(" 开始处理工单: " + orderNo + "-" + releaseNo + "-" + sequenceNo); - + // 1. 校验工单是否存在 IfsShopOrder shopOrderQuery = new IfsShopOrder(); shopOrderQuery.setSite(site); shopOrderQuery.setOrderNo(orderNo); shopOrderQuery.setReleaseNo(releaseNo); shopOrderQuery.setSequenceNo(sequenceNo); - + List shopOrders = ifsApiService.getShopOrderFromIFSWithOrderNo(shopOrderQuery); if (shopOrders == null || shopOrders.isEmpty()) { throw new RuntimeException("工单不存在: " + site + "-" + orderNo + "-" + releaseNo + "-" + sequenceNo); } - + IfsShopOrder shopOrder = shopOrders.get(0); System.out.println(" 工单校验通过: " + shopOrder.getPartNo() + " - " + shopOrder.getPartDesc()); - + // 2. 获取工单BOM信息 List bomMaterials = ifsApiService.getSoBomWithOrderNo(shopOrderQuery); if (bomMaterials == null || bomMaterials.isEmpty()) { throw new RuntimeException("工单BOM为空: " + site + "-" + orderNo + "-" + releaseNo + "-" + sequenceNo); } - + // 3. 校验Excel中的物料是否在BOM中存在 for (NotifyExcelData excelMaterial : materialList) { boolean found = false; @@ -334,13 +334,13 @@ public class NewIssureServiceImpl implements NewIssureService { } } if (!found) { - throw new RuntimeException("Excel中的物料在IFS工单BOM中不存在: 工单=" + orderNo + "-" + releaseNo + "-" + sequenceNo + - ", BOM行号=" + excelMaterial.getBomLineNo() + + throw new RuntimeException("Excel中的物料在IFS工单BOM中不存在: 工单=" + orderNo + "-" + releaseNo + "-" + sequenceNo + + ", BOM行号=" + excelMaterial.getBomLineNo() + ", 物料编码=" + excelMaterial.getMaterialPartNo()); } } System.out.println(" 物料校验通过,Excel中" + materialList.size() + "个物料均在BOM中存在"); - + // 4. 保存SOIssueNotifyOrderList记录 SOIssueNotifyOrderList orderListRecord = new SOIssueNotifyOrderList(); orderListRecord.setNotifyNo(notifyNo); @@ -352,27 +352,27 @@ public class NewIssureServiceImpl implements NewIssureService { orderListRecord.setOrderType("shoporder"); orderListRecord.setOutWorkOrderFlag("N"); orderListRecord.setNeedDate(materialList.get(0).getNeedDate()); // 使用第一个物料的需求日期 - + // 获取下一个item_no(使用原有的IssureNotifyMapper) BigDecimal nextItemNo = issureNotifyMapper.getNextItemForSOIssueNotifyOrderList(orderListRecord); orderListRecord.setItemNo(nextItemNo); - + // 保存工单记录(使用Excel专用方法) newIssureMapper.saveSOIssueNotifyOrderListForExcel(orderListRecord); System.out.println(" 保存工单记录成功,itemNo=" + nextItemNo); - + // 5. 删除该工单下的旧物料明细(如果存在) SOIssueNotifyOrderMaterialListData deleteParam = new SOIssueNotifyOrderMaterialListData(); deleteParam.setSite(site); deleteParam.setNotifyNo(notifyNo); deleteParam.setItemNo(nextItemNo); newIssureMapper.deleteSOIssueNotifyOrderMaterialListDataForExcel(deleteParam); - + // 6. 准备物料明细数据 List materialDetails = new ArrayList<>(); for (int i = 0; i < materialList.size(); i++) { NotifyExcelData excelMaterial = materialList.get(i); - + SOIssueNotifyOrderMaterialListData materialDetail = new SOIssueNotifyOrderMaterialListData(); materialDetail.setNotifyNo(notifyNo); materialDetail.setSite(site); @@ -384,18 +384,18 @@ public class NewIssureServiceImpl implements NewIssureService { materialDetail.setIssueType("BOM物料"); materialDetail.setOrderType("shoporder"); materialDetail.setRemark(""); - + materialDetails.add(materialDetail); } - + // 7. 批量保存物料明细 if (!materialDetails.isEmpty()) { newIssureMapper.batchSaveSOIssueNotifyOrderMaterialListDataForExcel(materialDetails); System.out.println(" 保存物料明细成功,共" + materialDetails.size() + "条记录"); } - + System.out.println(" 工单处理完成: " + orderNo + "-" + releaseNo + "-" + sequenceNo); - + } catch (Exception e) { System.err.println(" 工单处理失败: " + orderNo + "-" + releaseNo + "-" + sequenceNo + ", 错误: " + e.getMessage()); throw new RuntimeException("工单处理失败: " + orderNo + "-" + releaseNo + "-" + sequenceNo + ", 原因: " + e.getMessage(), e); @@ -404,7 +404,7 @@ public class NewIssureServiceImpl implements NewIssureService { /** * @Description 查询申请单主表 - AI制作 - * @Title searchNotifyHeaderNew + * @Title searchNotifyHeaderNew * @param data 查询条件 * @return PageUtils * @author AI制作 @@ -418,16 +418,16 @@ public class NewIssureServiceImpl implements NewIssureService { // 按照原有模式进行分页查询 IPage resultList = newIssureMapper.searchNotifyHeaderNew(page , data); PageUtils pageResult = new PageUtils(resultList); - + System.out.println("查询申请单主表完成,共" + resultList.getTotal() + "条记录"); - + return pageResult; } /** * @Description 查询申请单明细 - AI制作 * @Title searchNotifyOrderListNew - * @param data 查询条件 + * @param data 查询条件 * @return List * @author AI制作 * @date 2024/12/19 @@ -435,9 +435,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List searchNotifyOrderListNew(SOIssueNotifyHeaderData data) { System.out.println("开始查询申请单明细 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = newIssureMapper.searchNotifyOrderListNew(data); - + System.out.println("查询申请单明细完成,共" + list.size() + "条记录"); return list; } @@ -453,9 +453,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List searchNotifyMaterialListNew(SOIssueNotifyHeaderData data) { System.out.println("开始查询材料明细 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = newIssureMapper.searchNotifyMaterialListNew(data); - + System.out.println("查询材料明细完成,共" + list.size() + "条记录"); return list; } @@ -471,9 +471,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List searchSumNotifyMaterialListNew(SOIssueNotifyHeaderData data) { System.out.println("开始查询材料汇总 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = newIssureMapper.searchSumNotifyMaterialListNew(data); - + System.out.println("查询材料汇总完成,共" + list.size() + "条记录"); return list; } @@ -489,11 +489,11 @@ public class NewIssureServiceImpl implements NewIssureService { @Transactional public void updateNotifyStatusNew(SOIssueNotifyHeaderData data) { System.out.println("开始更新申请单状态为关闭 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + // 设置状态为CLOSED // data.setStatus("CLOSED"); newIssureMapper.updateNotifyStatusNew(data); - + System.out.println("更新申请单状态为关闭完成"); } @@ -508,9 +508,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List searchNotifyLogNew(SOIssueNotifyHeaderData data) { System.out.println("开始查询申请单日志 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = newIssureMapper.searchNotifyLogNew(data); - + System.out.println("查询申请单日志完成,共" + list.size() + "条记录"); return list; } @@ -526,9 +526,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List searchNotifyLogCloseNew(SOIssueNotifyHeaderData data) { System.out.println("开始查询申请单关闭日志 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = newIssureMapper.searchNotifyLogCloseNew(data); - + System.out.println("查询申请单关闭日志完成,共" + list.size() + "条记录"); return list; } @@ -545,78 +545,78 @@ public class NewIssureServiceImpl implements NewIssureService { public void pushNotifyToWcs(SOIssueNotifyHeaderData data) { String username = ShiroUtils.getUserEntity().getUsername(); Date currentTime = new Date(); - + System.out.println("开始推送申请单到WCS - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + // 1. 根据site和notify_no查询SOIssueNotifyOrderList List orderList = newIssureMapper.getOrderListForWcs(data); System.out.println("查询到申请单明细 " + orderList.size() + " 条"); - + if (orderList.isEmpty()) { throw new RuntimeException("申请单 " + data.getNotifyNo() + " 没有找到明细数据"); } - + List allSaveList = new ArrayList<>(); - + // 2. 遍历每条申请单明细 for (SOIssueNotifyOrderListData order : orderList) { System.out.println("处理申请单明细,itemNo=" + order.getItemNo()); - + // 根据site、notify_no和item_no查询材料明细 SOIssueNotifyOrderMaterialListData materialQuery = new SOIssueNotifyOrderMaterialListData(); materialQuery.setSite(data.getSite()); materialQuery.setNotifyNo(data.getNotifyNo()); materialQuery.setItemNo(order.getItemNo()); - + List materialList = newIssureMapper.getMaterialListForWcs(materialQuery); System.out.println("查询到材料明细 " + materialList.size() + " 条"); - + if (materialList.isEmpty()) { System.out.println("申请单明细 itemNo=" + order.getItemNo() + " 没有材料明细,跳过"); continue; } - + // 提取所有物料编码 List partNos = materialList.stream() .map(SOIssueNotifyOrderMaterialListData::getComponentPartNo) .distinct() .collect(Collectors.toList()); - + // 查询物料属性,筛选出is_in_wh='Y'的记录 List partAttributes = newIssureMapper.getPartAttributeListForWcs(data.getSite(), partNos); Map inWhPartMap = partAttributes.stream() .filter(attr -> "Y".equals(attr.getIsInWh())) .collect(Collectors.toMap(PartAttribute::getPartNo, attr -> attr)); - + System.out.println("筛选出需要进立库的物料 " + inWhPartMap.size() + " 个"); - + if (inWhPartMap.isEmpty()) { System.out.println("申请单明细 itemNo=" + order.getItemNo() + " 没有需要进立库的物料,跳过"); continue; } - + // 生成任务编号 TransNoControl transData = transNoService.getTransNo(data.getSite(), "WTT", 10); System.out.println("生成运输任务编号: " + transData.getNewTransNo()); - + // 为每个需要进立库的物料生成WCS任务 List orderSaveList = new ArrayList<>(); int itemNoSequence = 1; - + for (SOIssueNotifyOrderMaterialListData material : materialList) { if (inWhPartMap.containsKey(material.getComponentPartNo())) { WmsOrderTask task = new WmsOrderTask(); task.setSite(data.getSite()); task.setTaskNo(transData.getNewTransNo()); task.setItemNo(itemNoSequence++); - + // 设置任务基本信息 task.setSourceType("领料申请单"); task.setSourceBillNo(data.getNotifyNo()+"-"+order.getItemNo()); task.setSourceLineId(Long.valueOf(material.getBOMItemNo())); task.setPartNo(material.getComponentPartNo()); task.setQty(material.getQtyToIssue()); - + // 设置默认值(根据要求) task.setPalletId(""); task.setBatchNo(""); @@ -626,7 +626,7 @@ public class NewIssureServiceImpl implements NewIssureService { task.setAgvCode(null); task.setPriority(0); task.setStatus("已创建"); - + // 设置时间字段 task.setWmsSendTime(currentTime); task.setWcsReceiveTime(null); @@ -634,7 +634,7 @@ public class NewIssureServiceImpl implements NewIssureService { task.setCompleteTime(null); task.setErrorCode(null); task.setErrorMsg(null); - + // 设置审计字段 task.setCreatedBy(username); task.setCreatedTime(currentTime); @@ -642,30 +642,30 @@ public class NewIssureServiceImpl implements NewIssureService { task.setWcsTaskId(null); task.setFinishQty(BigDecimal.ZERO); task.setWmsStatus(null); - + orderSaveList.add(task); System.out.println("生成运输任务: " + material.getComponentPartNo() + ", 数量: " + material.getQtyToIssue()); } } - + allSaveList.addAll(orderSaveList); } - + if (!allSaveList.isEmpty()) { // 批量插入运输任务 wcsIntegrationMapper.batchSaveOrderTask(allSaveList); System.out.println("批量保存运输任务完成,共 " + allSaveList.size() + " 条"); - + // // TODO: 这里可以调用WCS接口通知立库执行运输任务 // wcsApiService.pushWCSTaskApi(allSaveList); - + // 更新申请单推送WCS状态 newIssureMapper.updatePushWcsFlag(data); System.out.println("更新申请单推送WCS状态为Y"); } else { throw new RuntimeException("申请单 " + data.getNotifyNo() + " 没有找到需要进立库的物料"); } - + System.out.println("推送申请单到WCS完成 - AI制作"); } @@ -680,9 +680,9 @@ public class NewIssureServiceImpl implements NewIssureService { @Override public List checkIssueNotifyInventory(SOIssueNotifyHeaderData data) { System.out.println("开始检查领料申请单物料库存匹配情况 - AI制作,notifyNo=" + data.getNotifyNo() + ", site=" + data.getSite()); - + List list = issureNotifyMapper.checkIssueNotifyInventory(data.getSite(), data.getNotifyNo()); - + System.out.println("检查领料申请单物料库存匹配情况完成,共" + list.size() + "条记录"); return list; } @@ -700,33 +700,33 @@ public class NewIssureServiceImpl implements NewIssureService { String username = ShiroUtils.getUserEntity().getUsername(); String site = data.getSite(); String notifyNo = data.getNotifyNo(); - + System.out.println("开始推送库存预览数据至WCS - rqrq,notifyNo=" + notifyNo + ", site=" + site); - + List inventoryList = data.getInventoryList(); if (inventoryList == null || inventoryList.isEmpty()) { throw new RuntimeException("库存预览数据为空,无法推送"); } - + // 1. 筛选出orderSatisfactionStatus = 1 或 2 的数据 - rqrq List validList = inventoryList.stream() - .filter(item -> item.getOrderSatisfactionStatus() != null && + .filter(item -> item.getOrderSatisfactionStatus() != null && (item.getOrderSatisfactionStatus() == 1 || item.getOrderSatisfactionStatus() == 2)) .collect(Collectors.toList()); - + // 2. 获取传入的原始订单总数(按生产订单分组统计)- rqrq int originalOrderCount = (int) data.getInventoryList().stream() .map(InventoryCheckResult::getProductionOrderNo) .distinct() .count(); System.out.println("前端传入的订单总数:" + originalOrderCount + " - rqrq"); - + System.out.println("筛选后满足库存要求的数据:" + validList.size() + "条 - rqrq"); - + if (validList.isEmpty()) { throw new RuntimeException("没有满足库存要求的订单数据"); } - + // 3. 提取所有条码(序列号) - rqrq List allSerialNos = new ArrayList<>(); for (InventoryCheckResult item : validList) { @@ -739,36 +739,36 @@ public class NewIssureServiceImpl implements NewIssureService { } } } - + System.out.println("提取到条码总数:" + allSerialNos.size() + " - rqrq"); - + // 4. 前置校验:检查reserve_flag - rqrq List reservedUnits = newIssureMapper.checkReserveFlagBySerialNos(site, allSerialNos); if (!reservedUnits.isEmpty()) { throw new RuntimeException("已经有物料被其他任务领走,请重新打开推送界面计算库存。"); } System.out.println("reserve_flag校验通过 - rqrq"); - + // 5. 前置校验:查询栈板并检查calling_flag - rqrq List palletIds = newIssureMapper.getPalletIdsBySerialNos(site, allSerialNos); if (palletIds == null || palletIds.isEmpty()) { throw new RuntimeException("未找到条码对应的栈板信息"); } System.out.println("找到栈板数量:" + palletIds.size() + " - rqrq"); - + List callingPallets = newIssureMapper.checkCallingFlagByPalletIds(site, palletIds); if ( !callingPallets.isEmpty()) { throw new RuntimeException("已经有栈板被其他任务领走,请重新打开推送界面计算库存。"); } System.out.println("calling_flag校验通过 - rqrq"); - + // 6. 按ProductionOrderNo分组 - rqrq Map> groupedByOrder = validList.stream() .collect(Collectors.groupingBy(InventoryCheckResult::getProductionOrderNo)); - + int validOrderCount = groupedByOrder.size(); System.out.println("按生产订单分组,满足条件的订单数:" + validOrderCount + "个 - rqrq"); - + Date currentTime = new Date(); int successCount = 0; // 统计成功推送的订单数 - rqrq @@ -778,10 +778,10 @@ public class NewIssureServiceImpl implements NewIssureService { for (Map.Entry> entry : groupedByOrder.entrySet()) { String productionOrderNo = entry.getKey(); List orderItems = entry.getValue(); - + try { System.out.println("开始处理订单:" + productionOrderNo + " - rqrq"); - + // 7.1 获取itemNo - rqrq BigDecimal itemNo = newIssureMapper.getItemNoByNotifyNoAndOrderNo(site, notifyNo, productionOrderNo); if (itemNo == null) { @@ -802,12 +802,12 @@ public class NewIssureServiceImpl implements NewIssureService { System.out.println("订单" + productionOrderNo + "信息 - fgPartNo=" + fgPartNo + ", 生产区域=" + (productionArea != null ? productionArea : "null") + ", 订单类型=" + (orderTypeFromDb != null ? orderTypeFromDb : "null") + " - rqrq"); - + // 6.2 生成taskNo - rqrq TransNoControl transData = transNoService.getTransNo(site, "WOT", 10); String taskNo = transData.getNewTransNo(); System.out.println("生成任务编号:" + taskNo + " - rqrq"); - + // 6.3 准备wms_order_task对象(暂不插入数据库)- rqrq WmsOrderTask orderTask = new WmsOrderTask(); orderTask.setSite(site); @@ -840,7 +840,7 @@ public class NewIssureServiceImpl implements NewIssureService { orderTask.setWmsStatus("已创建"); orderTask.setToArea(productionArea); // 设置生产区域 - rqrq System.out.println("准备wms_order_task对象 - rqrq"); - + // 7.4 提取本订单的所有序列号和栈板 - rqrq List orderSerialNos = new ArrayList<>(); for (InventoryCheckResult item : orderItems) { @@ -853,15 +853,15 @@ public class NewIssureServiceImpl implements NewIssureService { } } } - + List orderPalletIds = newIssureMapper.getPalletIdsBySerialNos(site, orderSerialNos); System.out.println("订单" + productionOrderNo + "涉及栈板数量:" + orderPalletIds.size() + " - rqrq"); - + // 7.5 准备wms_order_task_detail对象列表(暂不插入数据库)- rqrq List taskDetailList = new ArrayList<>(); int seqNo = 1; for (String palletId : orderPalletIds) { - com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail = + com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail = new com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail(); taskDetail.setSite(site); taskDetail.setTaskNo(taskNo); @@ -879,15 +879,15 @@ public class NewIssureServiceImpl implements NewIssureService { taskDetail.setErrorMsg(null); taskDetail.setPalletId(palletId); taskDetail.setWmsStatus("未执行"); - + taskDetailList.add(taskDetail); wcsIntegrationMapper.updatePalletCallingFlag(site,palletId,"Y","领料申请单"); } System.out.println("准备wms_order_task_detail对象" + orderPalletIds.size() + "条 - rqrq"); - + // 7.6 准备SOIssueNotifyOrderMaterialList_detail对象列表(暂不插入数据库)- rqrq List detailList = new ArrayList<>(); - + // 构建序列号到栈板ID的映射关系 - rqrq Map serialNoPalletMap = new HashMap<>(); for (String serialNo : orderSerialNos) { @@ -897,34 +897,34 @@ public class NewIssureServiceImpl implements NewIssureService { } } System.out.println("构建序列号到栈板的映射关系,共" + serialNoPalletMap.size() + "条 - rqrq"); - + // 构建栈板ID到SeqNo的映射关系 - rqrq Map palletSeqMap = new HashMap<>(); for (com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail : taskDetailList) { palletSeqMap.put(taskDetail.getPalletId(), taskDetail.getSeqNo()); } System.out.println("构建栈板到SeqNo的映射关系,共" + palletSeqMap.size() + "条 - rqrq"); - + for (InventoryCheckResult item : orderItems) { String matchedBarcodes = item.getMatchedBarcodes(); if (StringUtils.isNotBlank(matchedBarcodes)) { String[] barcodes = matchedBarcodes.split(","); for (String barcode : barcodes) { String serialNo = barcode.trim().split("\\(")[0]; - + // 根据序列号得知这个序列号在哪个栈板上,再去taskDetailList去寻找SeqNo - rqrq String palletId = serialNoPalletMap.get(serialNo); Integer taskSeq = null; if (palletId != null) { taskSeq = palletSeqMap.get(palletId); } - + // 如果找不到对应的SeqNo,记录警告并跳过 - rqrq if (taskSeq == null) { System.err.println("警告:序列号" + serialNo + "找不到对应的栈板SeqNo,跳过 - rqrq"); taskSeq=0; } - + // 查询序列号的location_id,如果不是AS区域则直接标记为已出库 - rqrq String locationId = newIssureMapper.getSerialNoLocationId(site, serialNo); String outWcsFlag = "N"; @@ -932,8 +932,8 @@ public class NewIssureServiceImpl implements NewIssureService { outWcsFlag = "Y"; System.out.println("序列号" + serialNo + "不在AS区域(location_id=" + locationId + "),直接标记为已出库 - rqrq"); } - - com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail detail = + + com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail detail = new com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail(); detail.setSite(site); detail.setNotifyNo(notifyNo); @@ -951,11 +951,12 @@ public class NewIssureServiceImpl implements NewIssureService { } } System.out.println("准备SOIssueNotifyOrderMaterialList_detail对象" + detailList.size() + "条 - rqrq"); - + // 6.7 构建WCS数据 - rqrq NotifyDataToWcs wcsData = new NotifyDataToWcs(); wcsData.setSite(site); + wcsData.setNotifyNo(notifyNo); wcsData.setTaskNo(taskNo); wcsData.setOrderNo(productionOrderNo); wcsData.setItemNo(orderTask.getItemNo()); @@ -975,7 +976,7 @@ public class NewIssureServiceImpl implements NewIssureService { for (String palletId : orderPalletIds) { // 查询该栈板上本订单相关的序列号的明细信息 - rqrq List palletDetails = newIssureMapper.getPalletDetailsByPalletAndSerials(site, palletId, orderSerialNos); - + if (palletDetails != null && !palletDetails.isEmpty()) { // 按position和layer分组 - rqrq Map>> groupedByPositionLayer = new java.util.HashMap<>(); @@ -983,97 +984,97 @@ public class NewIssureServiceImpl implements NewIssureService { String position = detail.getPosition(); Integer layer = detail.getLayer(); String serialNo = detail.getSerialNo(); - + groupedByPositionLayer .computeIfAbsent(position, k -> new java.util.HashMap<>()) .computeIfAbsent(layer, k -> new ArrayList<>()) .add(serialNo); } - + // 构建NotifyDataToWcsPalletList - rqrq NotifyDataToWcsPalletList palletData = new NotifyDataToWcsPalletList(); palletData.setPalletCode(palletId); - + List subDetailList = new ArrayList<>(); for (Map.Entry>> posEntry : groupedByPositionLayer.entrySet()) { String position = posEntry.getKey(); for (Map.Entry> layerEntry : posEntry.getValue().entrySet()) { Integer layer = layerEntry.getKey(); List serialNos = layerEntry.getValue(); - + NotifyDataToWcsPalletSubDetail subDetail = new NotifyDataToWcsPalletSubDetail(); subDetail.setPosition(Integer.parseInt(position)); subDetail.setLayer(layer); subDetail.setRfidBarcodes(serialNos); - + subDetailList.add(subDetail); } } - + palletData.setMaterials(subDetailList); palletList.add(palletData); } } - + wcsData.setMaterialRequisitions(palletList); System.out.println("构建WCS数据完成,栈板数:" + palletList.size() + " - rqrq"); - + // 6.8 先调用WCS接口(成功后再执行数据库操作)- rqrq System.out.println("开始调用WCS接口 - rqrq"); try { wcsApiService.pushNotifyToWcsApi(wcsData); System.out.println("WCS接口调用成功 - rqrq"); - + } catch (Exception e) { String errorMsg = e.getMessage(); System.err.println("WCS接口调用失败:" + errorMsg + " - rqrq"); - + // 超时错误直接抛出 - rqrq if (errorMsg != null && (errorMsg.contains("timeout") || errorMsg.contains("超时"))) { throw new RuntimeException("WCS接口调用超时:" + errorMsg); } - + // 其他错误跳过本次循环 - rqrq System.err.println("订单" + productionOrderNo + "推送失败,跳过继续处理下一个订单 - rqrq"); continue; } - + // 7.9 WCS推送成功后,执行数据库操作 - rqrq System.out.println("WCS推送成功,开始保存数据库记录 - rqrq"); - + // 7.9.1 插入wms_order_task - rqrq wcsIntegrationMapper.insertOrderTask(orderTask); System.out.println("创建wms_order_task记录成功 - rqrq"); - + // 7.9.2 批量插入wms_order_task_detail - rqrq for (com.gaotao.modules.automatedWarehouse.entity.WmsOrderTaskDetail taskDetail : taskDetailList) { wcsIntegrationMapper.insertWmsOrderTaskDetail(taskDetail); } System.out.println("创建wms_order_task_detail记录" + taskDetailList.size() + "条 - rqrq"); - + // 7.9.3 更新handling_unit的reserve标志 - rqrq newIssureMapper.updateHandlingUnitReserveFlag(site, orderSerialNos, notifyNo, itemNo, productionOrderNo); System.out.println("更新handling_unit的reserve标志完成 - rqrq"); - + // 7.9.4 更新栈板的calling_flag - rqrq newIssureMapper.updatePalletCallingFlag(site, orderPalletIds); System.out.println("更新栈板calling_flag完成 - rqrq"); - + // 7.9.5 批量插入SOIssueNotifyOrderMaterialList_detail - rqrq if (!detailList.isEmpty()) { newIssureMapper.batchInsertMaterialListDetail(detailList); System.out.println("创建SOIssueNotifyOrderMaterialList_detail记录" + detailList.size() + "条 - rqrq"); } - + // 7.9.6 更新SOIssueNotifyOrderList的push_wms_flag - rqrq newIssureMapper.updateOrderListPushWmsFlag(site, notifyNo, itemNo); System.out.println("更新push_wms_flag=Y - rqrq"); - + System.out.println("订单" + productionOrderNo + "处理完成 - rqrq"); - + // 成功推送,计数+1 - rqrq successCount++; - + } catch (RuntimeException e) { // 超时错误向上抛出 - rqrq if (e.getMessage().contains("超时") || e.getMessage().contains("timeout")) { @@ -1083,7 +1084,7 @@ public class NewIssureServiceImpl implements NewIssureService { System.err.println("处理订单" + productionOrderNo + "失败:" + e.getMessage() + " - rqrq"); } } - + // 8. 判断推送状态并更新SOIssueNotifyHeader的push_wcs_flag - rqrq // 判断逻辑: // - 如果一条都没成功(successCount == 0):不改变状态 @@ -1096,11 +1097,11 @@ public class NewIssureServiceImpl implements NewIssureService { // 使用原始订单总数判断,而不是过滤后的订单数 - rqrq String pushWcsFlag = (successCount == originalOrderCount) ? "推送完成" : "部分推送"; System.out.println("推送结果统计:传入" + originalOrderCount + "个订单,满足条件" + validOrderCount + "个,成功推送" + successCount + "个,最终状态=" + pushWcsFlag + " - rqrq"); - + newIssureMapper.updateNotifyHeaderPushWcsFlag(site, notifyNo, pushWcsFlag); System.out.println("更新申请单push_wcs_flag=" + pushWcsFlag + " - rqrq"); } - + System.out.println("推送库存预览数据至WCS完成 - rqrq"); }