From e13518129e509aa19d76a029354535acd7570e1d Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期四, 20 十一月 2025 15:33:53 +0800
Subject: [PATCH] 1

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java |   76 +++++++++++++++++++++++---------------
 1 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
index 4fb6bc9..75aecf3 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
@@ -13,6 +13,7 @@
 import com.vincent.rsf.server.system.constant.SerialRuleCode;
 import com.vincent.rsf.server.system.utils.SerialRuleUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -59,12 +60,28 @@
         if (StringUtils.isBlank(waitPakin.getBarcode())) {
             throw new CoolException("鍙傛暟閿欒锛氭墭鐩樼爜涓虹┖锛侊紒");
         }
-//        List<Short> asList = Arrays.asList(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val), Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
         WaitPakin pakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
                 .eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
-        if (!Objects.isNull(pakin)) {
-            throw new CoolException("鎵樼洏鐮侊細" + waitPakin.getBarcode() + "宸茶缁勬墭鍗曪細" + pakin.getCode() + "浣跨敤锛侊紒");
+
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, waitPakin.getBarcode()));
+        if (!tasks.isEmpty()) {
+            throw new CoolException("褰撳墠鎵樼洏宸叉湁浠诲姟妗e湪鎵ц锛屼笉鑳藉啀娆$粍鎵橈紒锛�");
         }
+        if (!Objects.isNull(pakin)) {
+            List<WaitPakinItem> waitPakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(!Objects.isNull(pakin.getId()) ,WaitPakinItem::getPakinId, pakin.getId()));
+            waitPakinItems.forEach(item -> {
+                for (PakinItem pakinItem : waitPakin.getItems()) {
+                    WarehouseAreasItem warehouseAreasItems = warehouseAreasItemService.getById(pakinItem.getId());
+                    if (Objects.isNull(warehouseAreasItems)) {
+                        throw new CoolException("鐗╂枡鏈�佽嚦鏀惰揣鍖烘垨宸茬粍鎵樺畬鎴愮Щ鍑烘敹璐у尯锛侊紒");
+                    }
+                    if (item.getFieldsIndex().equals(warehouseAreasItems.getFieldsIndex())) {
+                        throw new CoolException("绁ㄥ彿锛�" + item.getExtendFields().get("crushNo") + "宸茬粍鎵橈紝涓嶅彲閲嶅缁勬墭锛侊紒");
+                    }
+                }
+            });
+        }
+
         List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode()));
         if (!locs.isEmpty()) {
             List<String> locCodes = locs.stream().map(Loc::getCode).collect(Collectors.toList());
@@ -74,31 +91,25 @@
         double sum = waitPakin.getItems().stream().mapToDouble(PakinItem::getReceiptQty).sum();
 
         WaitPakin waitPakin1 = new WaitPakin();
-        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAIT_PAKIN_CODE, null);
-        if (StringUtils.isBlank(ruleCode)) {
-            throw new CoolException("缂栫爜瑙勫垯閿欒锛� 缂栫爜瑙勫垯銆孲YS_WAIT_PAKIN_CODE銆嶈鍒欐槸涓嶅瓨鍦�");
+        if (Objects.isNull(pakin)) {
+            String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAIT_PAKIN_CODE, null);
+            if (StringUtils.isBlank(ruleCode)) {
+                throw new CoolException("缂栫爜瑙勫垯閿欒锛� 缂栫爜瑙勫垯銆孲YS_WAIT_PAKIN_CODE銆嶈鍒欐槸涓嶅瓨鍦�");
+            }
+            waitPakin1.setCode(ruleCode)
+                    //鐘舵�佷慨鏀逛负鍏ュ簱涓�
+                    .setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)
+                    .setAnfme(sum)
+                    .setUpdateBy(userId)
+                    .setCreateBy(userId)
+                    .setBarcode(waitPakin.getBarcode());
+            if (!this.save(waitPakin1)) {
+                throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
+            }
+        } else {
+            BeanUtils.copyProperties(pakin, waitPakin1);
         }
-        waitPakin1.setCode(ruleCode)
-                //鐘舵�佷慨鏀逛负鍏ュ簱涓�
-                .setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)
-                .setAnfme(sum)
-                .setUpdateBy(userId)
-                .setCreateBy(userId)
-                .setBarcode(waitPakin.getBarcode());
-        if (!this.save(waitPakin1)) {
-            throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
-        }
-//        /**鐗╂枡璺熻釜鐮�*/
-//        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>()
-//                .eq(WaitPakinItem::getPakinId, waitPakin1.getId()))
-//                ;
-//        if (!pakinItems.isEmpty()) {
-//            if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>()
-//                    .eq(WaitPakinItem::getPakinId, waitPakin1.getId())
-//                    )) {
-//                throw new CoolException("鍘熷崟鎹竻闄ゅけ璐ワ紒锛�");
-//            }
-//        }
+
         List<WaitPakinItem> items = new ArrayList<>();
         for (PakinItem pakinItem1 : waitPakin.getItems()) {
             //涓嶈壇鏍囩缁勬墭
@@ -144,11 +155,16 @@
             items.add(pakinItem);
         }
 
-        Double sum1 = items.stream().mapToDouble(WaitPakinItem::getAnfme).sum();
-
         if (!waitPakinItemService.saveBatch(items)) {
             throw new CoolException("缁勬墭鏄庣粏淇濆瓨澶辫触锛侊紒");
         }
+
+        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, waitPakin1.getId()));
+        Double waitSum = 0.0;
+        if (!pakinItems.isEmpty()) {
+            waitSum = pakinItems.stream().mapToDouble(WaitPakinItem::getAnfme).sum();
+        }
+//        Double total = Math.round((sum + waitSum) * 100) / 100.0;
 
         for (WaitPakinItem pakinItem : items) {
             WarehouseAreasItem one = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
@@ -167,7 +183,7 @@
             }
         }
 
-        waitPakin1.setAnfme(sum1);
+        waitPakin1.setAnfme(waitSum);
         if (!this.updateById(waitPakin1)) {
             throw new CoolException("缁勬墭鏁伴噺淇敼澶辫触锛侊紒");
         }

--
Gitblit v1.9.1