From 9c2df944ffcd3a60312ae179d347f16f2c36a0ea Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期三, 19 十一月 2025 13:13:14 +0800
Subject: [PATCH] 功能優化

---
 rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java |   84 ++++++++++++++++++++++++++++++++---------
 1 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java
index 1d89aaa..2290ddf 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java
@@ -12,16 +12,23 @@
 import com.vincent.rsf.server.manager.enums.AsnExceStatus;
 import com.vincent.rsf.server.manager.enums.TaskStsType;
 import com.vincent.rsf.server.manager.service.*;
+import com.vincent.rsf.server.manager.service.impl.StockItemServiceImpl;
+import com.vincent.rsf.server.manager.service.impl.StockServiceImpl;
+import com.vincent.rsf.server.system.constant.SerialRuleCode;
 import com.vincent.rsf.server.system.entity.Fields;
 import com.vincent.rsf.server.system.entity.FieldsItem;
 import com.vincent.rsf.server.system.service.FieldsItemService;
 import com.vincent.rsf.server.system.service.FieldsService;
 import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl;
 import com.vincent.rsf.server.system.service.impl.FieldsServiceImpl;
+import com.vincent.rsf.server.system.utils.SerialRuleUtils;
 import com.vincent.rsf.server.system.utils.SystemAuthUtils;
 import lombok.Synchronized;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -50,6 +57,10 @@
     private FieldsItemService fieldsItemService;
     @Autowired
     private FieldsService fieldsService;
+    @Autowired
+    private StockService stockService;
+    @Autowired
+    private StockItemServiceImpl stockItemService;
 
     @Override
     public R getOutStockTaskItem(String barcode) {
@@ -260,7 +271,7 @@
             }
             Double summed = items.stream().mapToDouble(TaskItem::getAnfme).sum();
             //鍔犱笂鍘嗗彶鎷f枡鏁伴噺
-            Double pickQty = Math.round((orderItem.getQty() + summed) * 10000) / 10000.0;
+            Double pickQty = Math.round((orderItem.getQty() + summed) * 100) / 100.0;
             if (pickQty.compareTo(orderItem.getAnfme()) > 0.0) {
                 throw new CoolException("鎾鏁伴噺涓嶈兘瓒呭嚭璁㈠崟闇�姹傛暟閲�");
             }
@@ -270,12 +281,41 @@
                 throw new CoolException("鍑哄簱鍗曟槑缁嗘洿鏂板け璐ワ紒锛�");
             }
 
+            Stock stock = new Stock();
+            String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
+            if (StringUtils.isBlank(ruleCode)) {
+                throw new CoolException("褰撳墠涓氬姟锛�" + SerialRuleCode.SYS_STOCK_CODE + "锛岀紪鐮佽鍒欎笉瀛樺湪锛侊紒");
+            }
+            Double sum = taskItems.stream().mapToDouble(TaskItem::getAnfme).sum();
+            stock.setCode(ruleCode)
+                    .setUpdateBy(SystemAuthUtils.getLoginUserId())
+                    .setBarcode(task.getBarcode())
+                    .setLocCode(task.getOrgLoc())
+                    .setType(order.getType())
+                    .setWkType(Short.parseShort(order.getWkType()))
+                    .setSourceId(orderItem.getOrderId())
+                    .setSourceCode(orderItem.getOrderCode())
+                    .setUpdateTime(new Date())
+                    .setAnfme(sum);
+
+            if (!stockService.save(stock)) {
+                throw new CoolException("鍑哄叆搴撳巻鍙蹭繚瀛樺け璐ワ紒锛�");
+            }
+
+           List<StockItem> stockItems = new ArrayList<>();
             items.forEach(taskItem -> {
-                taskItem.setQty(taskItem.getAnfme());
+                taskItem.setQty(taskItem.getAnfme()).setOrderId(order.getId()).setOrderItemId(orderItem.getId());
                 if (!taskItemService.updateById(taskItem)) {
                     throw new CoolException("鐘舵�佸畬鎴愬け璐ワ紒锛�");
                 }
+                StockItem stockItem = new StockItem();
+                BeanUtils.copyProperties(taskItem, stockItem);
+                stockItem.setStockId(stock.getId()).setStockCode(stock.getCode()).setSourceItemId(orderItem.getId());
+                stockItems.add(stockItem);
             });
+            if (!stockItemService.saveBatch(stockItems)) {
+                throw new CoolException("鍑哄叆搴撳巻鍙叉槑缁嗕繚瀛樺け璐ワ紒锛�");
+            }
         });
 
         List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, params.getOrderId()));
@@ -286,15 +326,15 @@
             throw new CoolException("璁㈠崟鏁伴噺鏇存柊澶辫触锛侊紒");
         }
         //妫�鏌ュ崟鎹槸鍚﹀畬鎴�
-        if (order.getAnfme().compareTo(order.getQty()) == 0) {
-            order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_DONE.val);
-            if (!asnOrderService.updateById(order)) {
-                throw new CoolException("鍑哄簱鍗曟洿鏂扮姸鎬佸け璐�");
-            }
-        }
-
+//        if (order.getAnfme().compareTo(order.getQty()) == 0) {
+//            order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_DONE.val);
+//            if (!asnOrderService.updateById(order)) {
+//                throw new CoolException("鍑哄簱鍗曟洿鏂扮姸鎬佸け璐�");
+//            }
+//        }
         return R.ok();
     }
+
 
     /**
      * @author Ryan
@@ -329,13 +369,13 @@
            }
         });
 
-        orderItems.forEach(orderItem -> {
-            try {
-                taskService.saveOutStockItem(taskItems, orderItem, null, null, SystemAuthUtils.getLoginUserId());
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        });
+//        orderItems.forEach(orderItem -> {
+//            try {
+//                taskService.saveOutStockItem(taskItems, orderItem, null, null, SystemAuthUtils.getLoginUserId());
+//            } catch (Exception e) {
+//                throw new RuntimeException(e);
+//            }
+//        });
 
 //        containerWaveParam.getOrderItems().forEach(orderItem -> {
 //
@@ -402,11 +442,17 @@
 ////            }
 //        }
 
-        task.setTaskStatus(TaskStsType.COMPLETE_OUT.id);
-        if (!taskService.updateById(task)) {
-            throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐�");
+        try {
+            taskService.pickOrCheckTask(task.getId(), "");
+        } catch (Exception e) {
+            e.printStackTrace();
         }
 
+//        task.setTaskStatus(TaskStsType.COMPLETE_OUT.id);
+//        if (!taskService.updateById(task)) {
+//            throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐�");
+//        }
+
         return R.ok();
     }
 

--
Gitblit v1.9.1