diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java index d03f645e..a4bec7ce 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java @@ -291,7 +291,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { String customerName = ""; String readyDateStr = ""; String shippingMethod = ""; - + String destination = ""; // 获取发货通知单信息 (从第一行数据获取即可) Row firstDataRow = sheet.getRow(1); if (firstDataRow != null) { @@ -299,6 +299,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { if (headerMap.containsKey("客户")) customerName = getMergedCellValue(sheet, 1, headerMap.get("客户")); if (headerMap.containsKey("可提货时间")) readyDateStr = getMergedCellValue(sheet, 1, headerMap.get("可提货时间")); if (headerMap.containsKey("发运方式")) shippingMethod = getMergedCellValue(sheet, 1, headerMap.get("发运方式")); + if (headerMap.containsKey("目的地")) destination = getMergedCellValue(sheet, 1, headerMap.get("目的地")); } if (cmcInvoice == null || cmcInvoice.isEmpty()) { @@ -315,7 +316,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { header.setBuNo(data.getBuNo()); header.setDelNo(delNo); header.setCmcInvoice(cmcInvoice); - + header.setDestination(destination); // 如果有按发票号分别设置的客户信息,则使用该信息;否则使用全局信息 String customerNameKey = "customerName_" + cmcInvoice; String localShipAddressKey = "localShipAddress_" + cmcInvoice; @@ -394,7 +395,8 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { int palletSeqNo = 1; int currentPalletSeqNo = 1; - int boxItemNo = 1; + int boxSeqNo = 1; + String currentBoxItemNo = ""; int palletDetailItemNo = 1; Map boxListMap = new LinkedHashMap<>(); @@ -549,18 +551,30 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { if (netWeightStr != null && !netWeightStr.isEmpty()) { if (isFirstRowOfMergedRegion(sheet, r, headerMap.get("净重")) || !isMerged(sheet, r, headerMap.get("净重"))) { + int currentBoxCount = 1; + if (headerMap.containsKey("箱数")) { + BigDecimal boxQtyForNo = parseBigDecimal(getMergedCellValue(sheet, r, headerMap.get("箱数"))); + if (boxQtyForNo != null && boxQtyForNo.compareTo(BigDecimal.ZERO) > 0) { + currentBoxCount = boxQtyForNo.setScale(0, RoundingMode.HALF_UP).intValue(); + } + } + String boxNo = boxSeqNo + "~" + (boxSeqNo + currentBoxCount - 1); + EcssCoDelBoxListData boxList = new EcssCoDelBoxListData(); boxList.setSite(site); boxList.setBuNo(data.getBuNo()); boxList.setDelNo(delNo); boxList.setSeqNo(currentPalletSeqNo); - boxList.setItemNo(String.valueOf(boxItemNo++)); + boxList.setItemNo(boxNo); boxList.setNetWeight(parseBigDecimal(netWeightStr)); boxList.setGrossWeight(grossWeight); boxList.setCreateBy(data.getUsername()); boxList.setCreateDate(new Date()); boxList.setBoxQty(BigDecimal.ZERO); boxListMap.put(boxList.getItemNo(), boxList); + + currentBoxItemNo = boxNo; + boxSeqNo += currentBoxCount; } } @@ -570,7 +584,6 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { palletDetail.setBuNo(data.getBuNo()); palletDetail.setDelNo(delNo); // ecss_CoDelBoxList 的 item_no 是 ecss_CoDelPalletDetail 的 seq_no - String currentBoxItemNo = String.valueOf(boxItemNo - 1); palletDetail.setSeqNo(currentBoxItemNo); palletDetail.setItemNo(palletDetailItemNo++); if (headerMap.containsKey("ERP编码")) { @@ -1309,7 +1322,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { Collectors.toMap(EcssCoDelNotifyDetailData::getPartNo,e->e)); // 装箱明细 - 按发货通知单明细item_no分组(用于获取每行的重量) List palletDetailList = coDelMapper.exportCoDelPalletDetailGroupByItemNo(notifyHeader); - Map palletMap = palletDetailList.stream().collect(Collectors.toMap( o -> o.get("item_no"), o -> o)); + //Map palletMap = palletDetailList.stream().collect(Collectors.toMap( o -> o.get("item_no"), o -> o)); // 装箱数据 List palletHeaderDataList = coDelMapper.searchEcssCoDelPalletHeaderData(notifyHeader);// 总托数 Integer totalPlt = palletHeaderDataList.stream() @@ -1335,8 +1348,8 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { eorder.put("row_num", i + 1); EcssCoDelNotifyDetailData nodifyData = notifyDetailMap.get(partNo); // 根据item_no获取该明细行对应的装箱重量 - Map pm = itemNo != null ? palletMap.get(itemNo) : null; - int totalQty = pm!=null && pm.get("total_qty")!=null?Integer.parseInt(pm.get("total_qty").toString()):0; + //Map pm = itemNo != null ? palletMap.get(itemNo) : null; + //int totalQty = pm!=null && pm.get("total_qty")!=null?Integer.parseInt(pm.get("total_qty").toString()):0; String lossratio = ""; if (nodifyData!=null && nodifyData.getLossratio()!=null && !StringUtils.isBlank(nodifyData.getLossratio())) { // 关务物料属性 @@ -1374,10 +1387,10 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { allPrice = allPrice.add( ((BigDecimal)eorder.get("ttl_amount"))); if (data.getShowWeight()!=null && data.getShowWeight()) { // 根据发货通知单明细查找装箱明细,获取重量和净重,保留2位小数 - eorder.put("grossWeight", pm != null && pm.get("gross_weight") != null ? + /* eorder.put("grossWeight", pm != null && pm.get("gross_weight") != null ? new BigDecimal(pm.get("gross_weight").toString()).setScale(2, RoundingMode.HALF_UP) : ""); eorder.put("netWeight", pm != null && pm.get("net_weight") != null ? - new BigDecimal(pm.get("net_weight").toString()).setScale(2, RoundingMode.HALF_UP) : ""); + new BigDecimal(pm.get("net_weight").toString()).setScale(2, RoundingMode.HALF_UP) : "");*/ } } // RFID需要的 @@ -1481,9 +1494,14 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { boxData.setSite(data.getSite()); boxData.setBuNo(notifyHeader.getBuNo()); boxData.setDelNo(notifyHeader.getDelNo()); + List allBoxDetailList = coDelMapper.selectPalletDetailList(boxData); + Map> boxDetailMap = allBoxDetailList == null ? new HashMap<>() : + allBoxDetailList.stream() + .filter(detail -> detail.get("seq_no") != null) + .collect(Collectors.groupingBy(detail -> detail.get("seq_no").toString())); for (int m = 0; m < list.size(); m++) { - boxData.setSeqNo(Integer.valueOf(list.get(m).get("item_no")!=null?list.get(m).get("item_no").toString():"")); - List checkList = coDelMapper.selectPalletDetailList(boxData); + String boxNo = list.get(m).get("item_no") != null ? list.get(m).get("item_no").toString() : ""; + List checkList = boxDetailMap.getOrDefault(boxNo, Collections.emptyList()); // 记录当前箱子对应的exportList起始索引 int boxStartIndex = exportList.size(); // 获取box的rolls @@ -1838,25 +1856,21 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { queryParam.setSite(notifyHeader.getSite()); queryParam.setBuNo(notifyHeader.getBuNo()); queryParam.setDelNo(notifyHeader.getDelNo()); + List allDetailList = coDelMapper.selectPalletDetailList(queryParam); + if (allDetailList == null || allDetailList.isEmpty()) { + log.warn("装箱明细中未找到物料信息,发货单号: {}", notifyHeader.getDelNo()); + return BigDecimal.ZERO; + } + Map> detailListByBoxNo = allDetailList.stream() + .filter(detail -> detail.get("seq_no") != null) + .collect(Collectors.groupingBy(detail -> detail.get("seq_no").toString())); // 获取所有明细中的物料编号 Set allPns = new HashSet<>(); - for (Map box : boxList) { - Object seqNoObj = box.get("item_no"); - if (seqNoObj == null) { - continue; - } - - queryParam.setSeqNo(Integer.valueOf(seqNoObj.toString())); - List detailList = coDelMapper.selectPalletDetailList(queryParam); - - if (detailList != null && !detailList.isEmpty()) { - for (Map detail : detailList) { - String pn = (String) detail.get("pn"); - if (pn != null) { - allPns.add(pn); - } - } + for (Map detail : allDetailList) { + String pn = (String) detail.get("pn"); + if (pn != null) { + allPns.add(pn); } } @@ -1904,13 +1918,13 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { if (seqNoObj == null) { continue; } + String boxNo = seqNoObj.toString(); // 查询该箱子的明细,获取主要物料(取第一个物料) - queryParam.setSeqNo(Integer.valueOf(seqNoObj.toString())); - List detailList = coDelMapper.selectPalletDetailList(queryParam); + List detailList = detailListByBoxNo.get(boxNo); if (detailList == null || detailList.isEmpty()) { - log.warn("箱号 {} 没有装箱明细", seqNoObj); + log.warn("箱号 {} 没有装箱明细", boxNo); continue; } @@ -1924,14 +1938,14 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { // 获取包装信息 String packageNo = partNoToPackageNoMap.get(mainPn); if (packageNo == null) { - log.warn("箱号 {} 的物料 {} 未维护packageNo", seqNoObj, mainPn); + log.warn("箱号 {} 的物料 {} 未维护packageNo", boxNo, mainPn); continue; } EcssPackageData packageData = packageNoToDataMap.get(packageNo); if (packageData == null || packageData.getLength() == null || packageData.getWidth() == null || packageData.getHeight() == null) { - log.warn("箱号 {} 的包装 {} 信息不完整", seqNoObj, packageNo); + log.warn("箱号 {} 的包装 {} 信息不完整", boxNo, packageNo); continue; } @@ -1955,7 +1969,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { processedBoxCount++; log.debug("箱号 {} 物料 {} 包装 {} 单箱体积 {} m³ 箱数 {} 小计 {} m³", - seqNoObj, mainPn, packageNo, + boxNo, mainPn, packageNo, singleBoxVolume.setScale(4, RoundingMode.HALF_UP), boxQty, boxTotalVolume.setScale(4, RoundingMode.HALF_UP));