From 83c2e75757034d753d8e69a24e8713e3b84d266a Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 27 五月 2021 15:31:29 +0800
Subject: [PATCH] #

---
 src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java |  103 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 85 insertions(+), 18 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 d98e4c6..2b7e6f3 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
@@ -75,6 +75,18 @@
         if (Cools.isEmpty(param.getMats())) {
             return R.error("鍏ュ簱鐗╂枡涓嶈兘涓虹┖");
         }
+        Integer docId = Optional.ofNullable(param.getDocType()).orElse(34);
+        String docNum = String.valueOf(snowflakeIdWorker.nextId());
+        switch (docId) {
+            case 34:    // 閲囪喘鍗�
+                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+                break;
+            case 45:    // 閿�鍞��璐у崟
+                docNum = "SR-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+                break;
+            default:
+                break;
+        }
         Date now = new Date();
         for (MatnrDto dto : param.getMats()) {
             Mat mat = matService.selectByMatnr(dto.getMatnr());
@@ -90,8 +102,8 @@
                 locDetl.setZpallet("");
                 locDetl.setAnfme(dto.getCount());
                 VersionUtils.setLocDetl(locDetl, mat);
-//                locDetl.setDocId(param.getDocType().longValue());
-//                locDetl.setDocNum(docNum);
+                locDetl.setDocId(docId.longValue());
+                locDetl.setDocNum(docNum);
                 locDetl.setStatus(1);
                 locDetl.setCreateBy(userId);
                 locDetl.setCreateTime(now);
@@ -116,23 +128,67 @@
             billDto.setQty(dto.getCount());
             dtos.add(billDto);
         }
-        Integer docId = Optional.ofNullable(param.getDocType()).orElse(34);
-        String docNum = String.valueOf(snowflakeIdWorker.nextId());
-        switch (docId) {
-            case 34:    // 閲囪喘鍗�
-                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
-                break;
-            case 45:    // 閿�鍞��璐у崟
-                docNum = "SR-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
-                break;
-            default:
-                break;
-        }
         if (!erpService.uploadBill(dtos, docId, docNum)) {
             throw new CoolException("鏃犳硶涓婃姤鑷砮rp");
         }
 
         return R.ok("鍏ュ簱鎴愬姛");
+    }
+
+    @Override
+    @Transactional
+    public R stockPakout(PakoutParam param, Long userId) {
+        Mat mat = matService.selectByMatnr(param.getMatnr());
+        Node node = nodeService.selectByUuid(param.getNodeUuid());
+        LocDetl locDetl = locDetlService.getLocDetl(node.getId(), mat.getMatnr());
+        if (locDetl == null || locDetl.getAnfme() < param.getCount()) {
+            return R.error(mat.getMaktx() + "搴撳瓨涓嶈冻");
+        }
+        Pakout pakout = new Pakout(
+                String.valueOf(snowflakeIdWorker.nextId()),    // 浠诲姟鍙穂闈炵┖]
+                3L,    // 宸ヤ綔鐘舵��
+                null,    // 鎵樼洏鍙�
+                param.getCount(),    // 鍑哄簱鏁伴噺
+                node.getId(),    // 鍏宠仈璐т綅[闈炵┖]
+                node.getUuid(),    // 璐т綅[闈炵┖]
+                mat.getMatnr(),    // 鍟嗗搧缂栫爜[闈炵┖]
+                null,    // 鍟嗗搧鍚嶇О
+                null,    // 鍚嶇О
+                null,    // 灏虹爜
+                null,    // 鍨嬪彿
+                null,    // 鎵瑰彿
+                null,    // 鍗曚綅
+                null,    // SKC
+                null,    // 鍗曟嵁绫诲瀷
+                null,    // 鍗曟嵁缂栧彿
+                null,    // 瀹㈡埛鍚嶇О
+                null,    // 鍝侀」鏁�
+                null,    // 鏁伴噺
+                null,    // 閲嶉噺
+                1,    // 鐘舵��
+                userId,    // 娣诲姞浜哄憳
+                new Date(),    // 娣诲姞鏃堕棿
+                userId,    // 淇敼浜哄憳
+                new Date(),    // 淇敼鏃堕棿
+                null    // 澶囨敞
+        );
+        VersionUtils.setPakout(pakout, mat);
+        // 淇濆瓨鍑哄簱閫氱煡鍗�
+        if (!pakoutService.insert(pakout)) {
+            throw new CoolException("淇濆瓨鍑哄簱閫氱煡鍗曞け璐�");
+        }
+        if (param.getCount()>=locDetl.getAnfme()) {
+            // 鍒犻櫎搴撳瓨鏄庣粏
+            if (!locDetlService.removeStock(node.getId(), mat.getMatnr())) {
+                throw new CoolException("鍒犻櫎搴撳瓨鏄庣粏澶辫触");
+            }
+        } else {
+            // 淇敼搴撳瓨鏄庣粏鏁伴噺
+            if (!locDetlService.reduceStock(node.getId(), mat.getMatnr(), param.getCount())) {
+                throw new CoolException("淇敼搴撳瓨鏄庣粏鏁伴噺澶辫触");
+            }
+        }
+        return R.ok();
     }
 
     @Override
@@ -462,6 +518,15 @@
         Date now = new Date();
         Item item = itemService.selectByName(param.getItem());
         Cstmr cstmr = cstmrService.selectByName(param.getCstmr());
+        // 閲囪喘閫�璐у崟妫�楠�
+        if (param.getDocType() == 6) {
+            for (MatnrDto dto : param.getList()) {
+                if (locDetlService.getStockByDocType34(dto.getMatnr()) < dto.getCount()) {
+                    return R.error(dto.getMatnr() + "閲囪喘閲忎笉瓒充互鐢熸垚閫�璐у崟锛�");
+                }
+            }
+        }
+
         // 鏂板璁㈠崟琛ㄥご
         order = new Order(
                 String.valueOf(snowflakeIdWorker.nextId()),    // 缂栧彿[闈炵┖]
@@ -699,7 +764,7 @@
     @Transactional
     public R stockCheckAuditing(Long checkId, Long userId) {
         Check check = checkService.selectById(checkId);
-        if (null == check) {
+        if (null == check || check.getStatus() != 1) {
             return R.error("鐩樼偣璁板綍宸插け鏁�");
         }
         Date now = new Date();
@@ -751,9 +816,11 @@
         String docNum = null;
         Long docId = null;
         switch (check.getSettle()) {
-            case 1:    // 鐩樼泩
-                docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
-                docId = 14L; // 鎶ユ孩鍗�
+            case 1:    // 鐩樼泩 todo 鍓嶆湡鐢ㄩ噰璐崟涓婃姤
+//                docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+//                docId = 14L; // 鎶ユ孩鍗�
+                docNum = "PU-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+                docId = 34L; // 閲囪喘鍗�
                 break;
             case 2:    // 鐩樹簭
                 docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);

--
Gitblit v1.9.1