From b71ca6faa130dbd9baed68d1402365ccc63e79c2 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 15 四月 2026 16:38:26 +0800
Subject: [PATCH] lsh#

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java |  111 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 74 insertions(+), 37 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
index b3ad570..2629327 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
@@ -66,8 +66,9 @@
         if (Objects.isNull(itemParams) || itemParams.isEmpty()) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
-        String waveId = map.get("wave").toString();
-        Wave waves = this.getById(Long.parseLong(waveId));
+//        Wave waveId = (Wave) map.get("wave");
+        Wave wave = JSON.parseObject(JSON.toJSONString(map.get("wave")), Wave.class);
+        Wave waves = this.getById(wave.getId());
         if (Objects.isNull(waves)) {
             throw new CoolException("娉㈡鏁版嵁涓嶅瓨鍦紒锛�");
         }
@@ -96,11 +97,7 @@
         }
         List<Long> orderIds = waveItems.stream().map(WaveItem::getOrderId).collect(Collectors.toList());
         /**淇敼鍑哄簱鍗曠姸鎬�*/
-        if (!asnOrderService.update(new LambdaUpdateWrapper<WkOrder>()
-                .set(WkOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val)
-                .in(WkOrder::getId, orderIds))) {
-            throw new CoolException("鍑哄簱鍗曟嵁鐘舵�佷慨鏀瑰け璐ワ紒锛�");
-        }
+        updateAsnOrders(orderIds, null, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val, null, "鍑哄簱鍗曟嵁鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         return R.ok();
     }
 
@@ -203,25 +200,9 @@
             Double sum = taskItems.stream().mapToDouble(TaskItem::getAnfme).sum();
             Double v = Math.round((wave.getWorkQty() + sum) * 1000000) / 1000000.0;
             if (wave.getAnfme().compareTo(v) == 0) {
-                if (!this.update(new LambdaUpdateWrapper<Wave>()
-                        .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK.val)
-                        .set(Wave::getWorkQty, v)
-                        .set(Wave::getUpdateBy, loginUserId)
-                        .set(Wave::getMemo, null)
-                        .set(Wave::getUpdateTime, new Date())
-                        .eq(Wave::getId, wave.getId()))) {
-                    throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
-                }
+                updateWaveSnapshot(wave, WaveExceStatus.WAVE_EXCE_STATUS_TASK.val, v, loginUserId, null, "娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
             } else {
-                if (!this.update(new LambdaUpdateWrapper<Wave>()
-                        .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val)
-                        .set(Wave::getWorkQty, v)
-                        .set(Wave::getUpdateBy, loginUserId)
-                        .set(Wave::getMemo, null)
-                        .set(Wave::getUpdateTime, new Date())
-                        .eq(Wave::getId, wave.getId()))) {
-                    throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
-                }
+                updateWaveSnapshot(wave, WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val, v, loginUserId, null, "娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
             }
         }
 
@@ -263,18 +244,69 @@
         });
 
         List<Long> orders = orderRelas.stream().map(WaveOrderRela::getOrderId).collect(Collectors.toList());
-        if (!asnOrderService.update(new LambdaUpdateWrapper<WkOrder>()
-                .set(WkOrder::getWorkQty, 0.0)
-                .set(WkOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)
-                .in(WkOrder::getId, orders))) {
-            throw new CoolException("鍗曟嵁鏇存柊澶辫触锛�!");
-        }
+        updateAsnOrders(orders, 0.0, AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val, null, "鍗曟嵁鏇存柊澶辫触锛侊紒");
 
-        this.update(new LambdaUpdateWrapper<Wave>()
-                .eq(Wave::getId, id)
-                .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK.val));
+        updateWaveSnapshot(wave, WaveExceStatus.WAVE_EXCE_STATUS_TASK.val, null, null, null, "娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
 
         return R.ok();
+    }
+
+    private void updateWaveSnapshot(Wave wave, Short exceStatus, Double workQty, Long loginUserId, String memo, String errorMessage) {
+        Wave update = new Wave();
+        update.setId(wave.getId());
+        update.setVersion(wave.getVersion());
+        update.setExceStatus(exceStatus);
+        update.setWorkQty(workQty);
+        update.setUpdateBy(loginUserId);
+        update.setMemo(memo);
+        update.setUpdateTime(loginUserId == null ? null : new Date());
+        if (!this.updateById(update)) {
+            throw new CoolException(errorMessage);
+        }
+        wave.setExceStatus(exceStatus);
+        wave.setWorkQty(workQty);
+        wave.setUpdateBy(loginUserId);
+        if (loginUserId != null) {
+            wave.setUpdateTime(update.getUpdateTime());
+        }
+        wave.setMemo(memo);
+        if (update.getVersion() != null) {
+            wave.setVersion(update.getVersion());
+        }
+    }
+
+    private void updateAsnOrders(List<Long> orderIds, Double workQty, Short exceStatus, Long loginUserId, String errorMessage) {
+        if (Cools.isEmpty(orderIds)) {
+            return;
+        }
+        List<WkOrder> orders = asnOrderService.listByIds(orderIds.stream().distinct().collect(Collectors.toList()));
+        for (WkOrder order : orders) {
+            WkOrder update = new WkOrder();
+            update.setId(order.getId());
+            update.setVersion(order.getVersion());
+            if (workQty != null) {
+                update.setWorkQty(workQty);
+            }
+            update.setExceStatus(exceStatus);
+            if (loginUserId != null) {
+                update.setUpdateBy(loginUserId);
+                update.setUpdateTime(new Date());
+            }
+            if (!asnOrderService.updateById(update)) {
+                throw new CoolException(errorMessage);
+            }
+            if (workQty != null) {
+                order.setWorkQty(workQty);
+            }
+            order.setExceStatus(exceStatus);
+            if (loginUserId != null) {
+                order.setUpdateBy(loginUserId);
+                order.setUpdateTime(update.getUpdateTime());
+            }
+            if (update.getVersion() != null) {
+                order.setVersion(update.getVersion());
+            }
+        }
     }
 
     /**
@@ -359,13 +391,18 @@
     private List<WaveItem> getLocs(List<WaveItem> waveItems) throws Exception {
         //TODO  鏍规嵁鐗╂枡缂栫爜锛屾壒娆★紝鍔ㄦ�佸瓧娈� 鏌ヨ绗﹀悎鐨勫簱浣嶏紝鍐嶆牴鎹簱浣嶄腑鐗╂枡鐨勬暟閲忛�夋嫨鏈�閫傚悎鐨勫簱浣�
         waveItems.forEach(waveItem -> {
-            List<LocItem> locItems = locItemService.list(new QueryWrapper<LocItem>()
+            LambdaQueryWrapper<LocItem> locItemLambdaQueryWrapper = new QueryWrapper<LocItem>()
                     .select("id", "loc_id", "loc_code", "order_id", "SUM(anfme) anfme", "SUM(qty) qty", "SUM(work_qty) work_qty", "splr_batch", "fields_index", "matnr_code")
                     .lambda()
                     .eq(LocItem::getMatnrCode, waveItem.getMatnrCode())
                     .eq(LocItem::getSplrBatch, waveItem.getSplrBatch())
-                    .eq(StringUtils.isNotBlank(waveItem.getFieldsIndex()), LocItem::getFieldsIndex, waveItem.getFieldsIndex())
-                    .groupBy(LocItem::getMatnrCode, LocItem::getSplrBatch, LocItem::getFieldsIndex, LocItem::getId));
+                    .eq(StringUtils.isNotBlank(waveItem.getFieldsIndex()), LocItem::getFieldsIndex, waveItem.getFieldsIndex());
+            Wave wave = this.getById(waveItem.getWaveId());
+            if (!Cools.isEmpty(wave.getLocCode())) {
+                locItemLambdaQueryWrapper.eq(LocItem::getLocCode, wave.getLocCode());
+            }
+            locItemLambdaQueryWrapper.groupBy(LocItem::getMatnrCode, LocItem::getSplrBatch, LocItem::getFieldsIndex, LocItem::getId);
+            List<LocItem> locItems = locItemService.list(locItemLambdaQueryWrapper);
             List<Double> doubles1 = locItems.stream().map(LocItem::getAnfme).collect(Collectors.toList());
             double[] doubles = doubles1.stream().mapToDouble(Double::doubleValue).toArray();
 

--
Gitblit v1.9.1