From 1615f8228191168e3ea4a10a6ea80ad180e21f87 Mon Sep 17 00:00:00 2001 From: shenzhouyu Date: Thu, 3 Sep 2026 13:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95=E9=A2=86?= =?UTF-8?q?=E6=96=99=E6=B5=B7=E5=AE=89=E5=B7=A5=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/HaiAnIssureNotifyServiceImpl.java | 74 +++++++++++++++++-- .../service/impl/TransHeaderServiceImpl.java | 17 +++-- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gaotao/modules/autoWareHourceHaian/service/impl/HaiAnIssureNotifyServiceImpl.java b/src/main/java/com/gaotao/modules/autoWareHourceHaian/service/impl/HaiAnIssureNotifyServiceImpl.java index 98b1241e..b847fcfb 100644 --- a/src/main/java/com/gaotao/modules/autoWareHourceHaian/service/impl/HaiAnIssureNotifyServiceImpl.java +++ b/src/main/java/com/gaotao/modules/autoWareHourceHaian/service/impl/HaiAnIssureNotifyServiceImpl.java @@ -33,10 +33,12 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -212,7 +214,7 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { /** * @author rqrq - * @Description 保存海安工单与物料(仅申请数据,删除后重建)并落到haian表 - rqrq + * @Description 追加保存海安工单与物料:同一领料单下允许多工单共存,不清理既有父子行 - rqrq */ @Override @Transactional(rollbackFor = Exception.class) @@ -241,10 +243,6 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { } } - // 编辑场景统一删后重存:直接清理父子后按新数据重建 - rqrq - haiAnIssureNotifyMapper.haiAnDeleteMaterialRowsByNotifyNo(data.getSite(), data.getNotifyNo()); - haiAnIssureNotifyMapper.haiAnDeleteOrderRowsByNotifyNo(data.getSite(), data.getNotifyNo()); - // 以工单三元组+subsite聚合,避免同单跨子站点明细被错误合并到同一父行 - rqrq Map> groupedMap = materialRows.stream() .collect(Collectors.groupingBy( @@ -253,11 +251,18 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { Collectors.toList() )); + // 工单重复校验:同一领料单下 orderNo+releaseNo+sequenceNo 不可重复 - rqrq + validateDuplicateShopOrders(data.getSite(), data.getNotifyNo(), groupedMap.keySet()); + + // 从当前最大itemNo续号追加,保留领料单下已有工单数据 - rqrq BigDecimal nextItem = haiAnIssureNotifyMapper.haiAnGetNextItemForSOIssueNotifyOrderList(buildParentSeed(data)); - if (nextItem == null) { + if (nextItem == null || nextItem.compareTo(BigDecimal.ONE) < 0) { nextItem = BigDecimal.ONE; } + List newItemNos = new ArrayList<>(); + List allChildren = new ArrayList<>(); + for (Map.Entry> entry : groupedMap.entrySet()) { HaiAnGroupKey groupKey = entry.getKey(); List groupDtos = entry.getValue(); @@ -271,10 +276,18 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { fillOrderDefaultValues(parent); haiAnIssureNotifyMapper.haiAnSaveSOIssueNotifyOrderList(parent); - List children = buildChildren(data.getNotifyNo(), data.getSite(), subSite, groupDtos, nextItem, parent.getOrderType()); - haiAnIssureNotifyMapper.haiAnBatchSaveSOIssueNotifyOrderMaterialList(children); + newItemNos.add(nextItem.toPlainString()); + allChildren.addAll(buildChildren(data.getNotifyNo(), data.getSite(), subSite, groupDtos, nextItem, parent.getOrderType())); nextItem = nextItem.add(BigDecimal.ONE); } + + // 仅清理本次新增item下的子行后重插,不影响既有工单明细 - rqrq + if (!newItemNos.isEmpty()) { + haiAnIssureNotifyMapper.haiAnDeleteSOIssueNotifyOrderMaterialInList(data.getNotifyNo(), data.getSite(), newItemNos); + } + if (!allChildren.isEmpty()) { + haiAnIssureNotifyMapper.haiAnBatchSaveSOIssueNotifyOrderMaterialList(allChildren); + } return "200"; } @@ -595,6 +608,51 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { return seed; } + /** + * @author rqrq + * @Description 校验领料单内工单是否重复:按orderNo+releaseNo+sequenceNo判重,含库内已有与本次请求内部重复 - rqrq + */ + private void validateDuplicateShopOrders(String site, String notifyNo, Set requestGroups) { + HaiAnSOIssueNotifyHeaderData query = new HaiAnSOIssueNotifyHeaderData(); + query.setSite(site); + query.setNotifyNo(notifyNo); + List existingOrders = haiAnIssureNotifyMapper.haiAnGetNotifyNoDetail(query); + + Set existingKeys = new HashSet<>(); + if (existingOrders != null) { + for (HaiAnSOIssueNotifyOrderListData order : existingOrders) { + if (order == null) { + continue; + } + existingKeys.add(buildShopOrderUniqueKey(order.getSoorderNo(), order.getReleaseNo(), order.getSequenceNo())); + } + } + + Set requestKeys = new HashSet<>(); + List duplicateMsgs = new ArrayList<>(); + for (HaiAnGroupKey groupKey : requestGroups) { + if (groupKey == null) { + continue; + } + String key = buildShopOrderUniqueKey(groupKey.getOrderNo(), groupKey.getReleaseNo(), groupKey.getSequenceNo()); + String display = groupKey.getOrderNo() + "/" + groupKey.getReleaseNo() + "/" + groupKey.getSequenceNo(); + if (existingKeys.contains(key)) { + duplicateMsgs.add(display + "(已存在于当前领料单)"); + } else if (!requestKeys.add(key)) { + duplicateMsgs.add(display + "(本次提交重复)"); + } + } + if (!duplicateMsgs.isEmpty()) { + throw new RuntimeException("工单重复,无法保存:" + String.join(";", duplicateMsgs)); + } + } + + private String buildShopOrderUniqueKey(String orderNo, String releaseNo, String sequenceNo) { + return StringUtils.defaultString(orderNo) + "|" + + StringUtils.defaultString(releaseNo) + "|" + + StringUtils.defaultString(sequenceNo); + } + private void fillOrderDefaultValues(HaiAnSOIssueNotifyOrderList parentItem) { String normalizedOrderType = resolveHeaderOrderType(parentItem.getOrderType()); String productionArea; diff --git a/src/main/java/com/gaotao/modules/trans/service/impl/TransHeaderServiceImpl.java b/src/main/java/com/gaotao/modules/trans/service/impl/TransHeaderServiceImpl.java index e715c6a3..11c67246 100644 --- a/src/main/java/com/gaotao/modules/trans/service/impl/TransHeaderServiceImpl.java +++ b/src/main/java/com/gaotao/modules/trans/service/impl/TransHeaderServiceImpl.java @@ -13,7 +13,7 @@ import com.gaotao.modules.trans.service.TransDetailService; import com.gaotao.modules.trans.service.TransDetailSubService; import com.gaotao.modules.trans.service.TransHeaderService; import com.gaotao.modules.trans.service.TransNoControlService; -import com.gaotao.modules.warehouse.service.InventoryStockService; +// import com.gaotao.modules.warehouse.service.InventoryStockService; import jakarta.transaction.Transactional; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -31,8 +31,8 @@ public class TransHeaderServiceImpl extends ServiceImpl