From df142079833e357624e64bd327e40e1f5f2e8fa9 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 24 三月 2021 17:01:50 +0800
Subject: [PATCH] #

---
 src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java b/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
index 2160384..a3de2b5 100644
--- a/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
+++ b/src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java
@@ -22,6 +22,7 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -50,6 +51,8 @@
     private AsrsService asrsService;
     @Autowired
     private ErpService erpService;
+    @Autowired
+    private CheckService checkService;
 
     @Override
     @Transactional
@@ -414,7 +417,117 @@
 
     @Override
     public R stockCheck(StoCheckParam param, Long userId) {
+        if (Cools.isEmpty(param.getLocNo())) {
+            return R.error("璇烽�夋嫨璐т綅");
+        }
+        Node node = nodeService.selectByUuid(param.getLocNo());
+        if (Cools.isEmpty(node)) {
+            return R.error("璐т綅寮傚父,璇疯仈绯荤鐞嗗憳");
+        }
+        // 鍑嗗鏁版嵁
+        Date now = new Date();
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("node_id", node.getId()));
+        List<String> locDetlMatnrs = new ArrayList<>();
+        locDetls.forEach(locDetl -> {
+            locDetlMatnrs.add(locDetl.getMatnr());
+        });
+        Iterator<LocDetl> detlIterator = locDetls.iterator();
+        List<PakinMatDto> dtos = param.getDtos();
 
+        // 1.鐩堜簭 淇敼鏁伴噺
+        while (detlIterator.hasNext()){
+            LocDetl locDetl = detlIterator.next();
+            for (PakinMatDto dto : dtos) {
+                if (locDetl.getMatnr().equals(dto.getMatnr())) {
+                    if (!locDetl.getAnfme().equals(dto.getCount())) {
+                        Check check = new Check(
+                                String.valueOf(snowflakeIdWorker.nextId()),    // 鐩樼偣缂栧彿
+                                node.getId(),    // 鐩樼偣璐т綅
+                                node.getUuid(),    // 璐т綅缂栧彿
+                                node.getName(),    // 璐т綅鍚嶇О
+                                locDetl.getMatnr(),    // 鍟嗗搧缂栧彿
+                                locDetl.getMaktx(),    // 鍟嗗搧鍚嶇О
+                                locDetl.getUnit(),    // 鍗曚綅
+                                null,    // 鍗曟嵁绫诲瀷
+                                null,    // 鍗曟嵁缂栧彿
+                                locDetl.getAnfme(),    // 璐﹂潰鏁伴噺
+                                dto.getCount(),    // 瀹炵洏鏁伴噺
+                                locDetl.getAnfme() < dto.getCount() ? 1 : 2,    // 鐩堜簭
+                                1,    // 鐘舵��
+                                userId,    // 娣诲姞浜哄憳
+                                now,    // 娣诲姞鏃堕棿
+                                userId,    // 淇敼浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null    // 澶囨敞
+                        );
+                        if (!checkService.insert(check)) {
+                            throw new CoolException("淇濆瓨鐩樼偣璁板綍澶辫触");
+                        }
+                    }
+                    detlIterator.remove();
+                    break;
+                }
+            }
+        }
+
+        // 2.鐩樹簭 鍒犻櫎搴撳瓨
+        for (LocDetl locDetl : locDetls) {
+            Check check = new Check(
+                    String.valueOf(snowflakeIdWorker.nextId()),    // 鐩樼偣缂栧彿
+                    node.getId(),    // 鐩樼偣璐т綅
+                    node.getUuid(),    // 璐т綅缂栧彿
+                    node.getName(),    // 璐т綅鍚嶇О
+                    locDetl.getMatnr(),    // 鍟嗗搧缂栧彿
+                    locDetl.getMaktx(),    // 鍟嗗搧鍚嶇О
+                    locDetl.getUnit(),    // 鍗曚綅
+                    null,    // 鍗曟嵁绫诲瀷
+                    null,    // 鍗曟嵁缂栧彿
+                    locDetl.getAnfme(),    // 璐﹂潰鏁伴噺
+                    0D,    // 瀹炵洏鏁伴噺
+                    2,    // 鐩堜簭
+                    1,    // 鐘舵��
+                    userId,    // 娣诲姞浜哄憳
+                    now,    // 娣诲姞鏃堕棿
+                    userId,    // 淇敼浜哄憳
+                    now,    // 淇敼鏃堕棿
+                    null    // 澶囨敞
+            );
+            if (!checkService.insert(check)) {
+                throw new CoolException("淇濆瓨鐩樼偣璁板綍澶辫触");
+            }
+
+        }
+
+        // 3.鐩樼泩 鏂板搴撳瓨
+        for (PakinMatDto dto : dtos) {
+            if (!locDetlMatnrs.contains(dto.getMatnr())) {
+                Mat mat = matService.selectByMatnr(dto.getMatnr());
+                Check check = new Check(
+                        String.valueOf(snowflakeIdWorker.nextId()),    // 鐩樼偣缂栧彿
+                        node.getId(),    // 鐩樼偣璐т綅
+                        node.getUuid(),    // 璐т綅缂栧彿
+                        node.getName(),    // 璐т綅鍚嶇О
+                        mat.getMatnr(),    // 鍟嗗搧缂栧彿
+                        mat.getMaktx(),    // 鍟嗗搧鍚嶇О
+                        mat.getUnit(),    // 鍗曚綅
+                        null,    // 鍗曟嵁绫诲瀷
+                        null,    // 鍗曟嵁缂栧彿
+                        0D,    // 璐﹂潰鏁伴噺
+                        dto.getCount(),    // 瀹炵洏鏁伴噺
+                        1,    // 鐩堜簭
+                        1,    // 鐘舵��
+                        userId,    // 娣诲姞浜哄憳
+                        now,    // 娣诲姞鏃堕棿
+                        userId,    // 淇敼浜哄憳
+                        now,    // 淇敼鏃堕棿
+                        null    // 澶囨敞
+                );
+                if (!checkService.insert(check)) {
+                    throw new CoolException("淇濆瓨鐩樼偣璁板綍澶辫触");
+                }
+
+            }
+        }
 
         return R.ok();
     }

--
Gitblit v1.9.1