From af73582c1bd3c20e2e805d4df56c111073d3fd6f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 25 三月 2021 13:02:35 +0800
Subject: [PATCH] #

---
 src/main/java/zy/cloud/wms/manager/service/impl/WorkServiceImpl.java |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 268 insertions(+), 11 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 74ca754..c610d49 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
@@ -9,9 +9,11 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import zy.cloud.wms.common.model.BillDto;
 import zy.cloud.wms.common.model.OrderStoDto;
 import zy.cloud.wms.common.service.MainService;
 import zy.cloud.wms.common.service.asrs.AsrsService;
+import zy.cloud.wms.common.service.erp.ErpService;
 import zy.cloud.wms.common.utils.VersionUtils;
 import zy.cloud.wms.manager.entity.*;
 import zy.cloud.wms.manager.entity.param.*;
@@ -20,6 +22,7 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -46,6 +49,10 @@
     private MatService matService;
     @Autowired
     private AsrsService asrsService;
+    @Autowired
+    private ErpService erpService;
+    @Autowired
+    private CheckService checkService;
 
     @Override
     @Transactional
@@ -59,6 +66,17 @@
             return R.error("鐗╂枡涓嶅瓨鍦�");
         }
         Date now = new Date();
+        String docNum = String.valueOf(snowflakeIdWorker.nextId());
+        switch (param.getDocType()) {
+            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;
+        }
         for (Comb comb : combs) {
             // 鏀瑰彉缁勬墭妗g姸鎬�
             comb.setIoStatus(4);
@@ -77,6 +95,8 @@
                 locDetl.setZpallet(param.getZpallet());
                 locDetl.setAnfme(comb.getAnfme());
                 VersionUtils.setLocDetl(locDetl, comb);
+                locDetl.setDocId(param.getDocType().longValue());
+                locDetl.setDocNum(docNum);
                 locDetl.setStatus(1);
                 locDetl.setCreateBy(userId);
                 locDetl.setCreateTime(now);
@@ -94,6 +114,19 @@
             }
 
         }
+
+        // 涓婃姤缁檈rp
+        List<BillDto> dtos = new ArrayList<>();
+        for (Comb comb : combs) {
+            BillDto billDto = new BillDto();
+            billDto.setMatnr(comb.getMatnr());
+            billDto.setQty(comb.getAnfme());
+            dtos.add(billDto);
+        }
+        if (!erpService.uploadBill(dtos, param.getDocType(), docNum)) {
+            throw new CoolException("鏃犳硶涓婃姤鑷砮rp");
+        }
+
         return R.ok();
     }
 
@@ -175,6 +208,24 @@
         if (!custOrderService.updateStatus(param.getNumber(), 4)) {
             throw new CoolException("淇敼鍗曟嵁鐘舵�佸け璐�");
         }
+        // 閲囪喘閫�璐у崟
+//        if (param.getNumber().startsWith("PR-")) {
+            // erp鍗曟嵁涓婁紶
+            Long docId = pakouts.get(0).getDocId();
+            if (null != docId) {
+                List<BillDto> dtos = new ArrayList<>();
+                for (Pakout pakout : pakouts) {
+                    BillDto billDto = new BillDto();
+                    billDto.setMatnr(pakout.getMatnr());
+                    billDto.setQty(pakout.getAnfme());
+                    dtos.add(billDto);
+                }
+                if (!erpService.uploadBill(dtos, docId.intValue() , pakouts.get(0).getDocNum())) {
+                    throw new CoolException("鏃犳硶涓婃姤鑷砮rp");
+                }
+            }
+
+//        }
         return R.ok();
     }
 
@@ -352,19 +403,225 @@
             }
         }
         if (asrs) {
-            if (asrsService.stockTransfer(params)) {
-                for (StockTransferParam param : params) {
-                    // 淇敼閿�鍞鍗曞緟鍑烘暟閲�
-                    if (!custOrderService.updateQty(number, param.getMatnr(), param.getAnfme())) {
-                        throw new CoolException("淇敼閿�鍞鍗曞緟鍑烘暟閲忓け璐�");
-                    }
-                }
-                return R.ok("搴撳瓨璋冩嫧鎴愬姛");
-            } else {
-                return R.error("绔嬪簱璋冩嫧澶辫触锛岃鑱旂郴绠$悊鍛�");
-            }
+//            if (asrsService.stockTransfer(params)) {
+//                for (StockTransferParam param : params) {
+//                    // 淇敼閿�鍞鍗曞緟鍑烘暟閲�
+//                    if (!custOrderService.updateQty(number, param.getMatnr(), param.getAnfme())) {
+//                        throw new CoolException("淇敼閿�鍞鍗曞緟鍑烘暟閲忓け璐�");
+//                    }
+//                }
+//                return R.ok("搴撳瓨璋冩嫧鎴愬姛");
+//            } else {
+//                return R.error("绔嬪簱璋冩嫧澶辫触锛岃鑱旂郴绠$悊鍛�");
+//            }
         }
         return R.error("鏆備笉缂鸿揣锛屼笉闇�瑕佺珛搴撹皟鎷�");
     }
 
+    @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(),    // 瀹炵洏鏁伴噺
+                                dto.getCount() - locDetl.getAnfme(), // 宸��
+                                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,    // 瀹炵洏鏁伴噺
+                    0D - locDetl.getAnfme(), // 宸��
+                    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(),    // 瀹炵洏鏁伴噺
+                        dto.getCount() - 0D, // 宸��
+                        1,    // 鐩堜簭
+                        1,    // 鐘舵��
+                        userId,    // 娣诲姞浜哄憳
+                        now,    // 娣诲姞鏃堕棿
+                        userId,    // 淇敼浜哄憳
+                        now,    // 淇敼鏃堕棿
+                        null    // 澶囨敞
+                );
+                if (!checkService.insert(check)) {
+                    throw new CoolException("淇濆瓨鐩樼偣璁板綍澶辫触");
+                }
+
+            }
+        }
+        return R.ok();
+    }
+
+    @Override
+    @Transactional
+    public R stockCheckAuditing(Long checkId, Long userId) {
+        Check check = checkService.selectById(checkId);
+        if (null == check) {
+            return R.error("鐩樼偣璁板綍宸插け鏁�");
+        }
+        Date now = new Date();
+        // 1.淇敼搴撳瓨鏁伴噺
+        if (check.getOriQty() != 0 && check.getCekQty() != 0) {
+            // 鏇存柊搴撳瓨鏄庣粏
+            if (check.getSettle() == 1) {
+                if (!locDetlService.incrementStock(check.getNodeId(), check.getMatnr(), Math.abs(check.getDiffQty()))) {
+                    throw new CoolException("淇敼搴撳瓨鏄庣粏鏁伴噺澶辫触");
+                }
+            } else if (check.getSettle() == 2) {
+                if (!locDetlService.reduceStock(check.getNodeId(), check.getMatnr(), Math.abs(check.getDiffQty()))) {
+                    throw new CoolException("淇敼搴撳瓨鏄庣粏鏁伴噺澶辫触");
+                }
+            }
+        }
+
+        // 2.鍒犻櫎搴撳瓨
+        if (check.getOriQty() != 0 && check.getCekQty() == 0) {
+            if (!locDetlService.delete(new EntityWrapper<LocDetl>().eq("node_id", check.getNodeId()).eq("matnr", check.getMatnr()))) {
+                throw new CoolException("鍒犻櫎搴撳瓨鏄庣粏鏁伴噺澶辫触");
+            }
+        }
+
+        // 3.鏂板搴撳瓨
+        if (check.getOriQty() == 0 && check.getCekQty() != 0) {
+            Mat mat = matService.selectByMatnr(check.getMatnr());
+            if (mat == null) {
+                throw new CoolException("鍟嗗搧鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
+            }
+            // 鏇存柊璐т綅搴撳瓨鏄庣粏
+            LocDetl locDetl = new LocDetl();
+            locDetl.setLocNo(check.getLocNo());
+            locDetl.setNodeId(check.getNodeId());
+//            locDetl.setZpallet(param.getZpallet());
+            locDetl.setAnfme(check.getCekQty());
+            VersionUtils.setLocDetl(locDetl, mat);
+            locDetl.setStatus(1);
+            locDetl.setCreateBy(userId);
+            locDetl.setCreateTime(now);
+            locDetl.setUpdateBy(userId);
+            locDetl.setUpdateTime(now);
+            if (!locDetlService.insert(locDetl)) {
+                throw new CoolException("鏂板搴撳瓨鏄庣粏澶辫触");
+            }
+        }
+
+        // 淇敼鐩樼偣璁板綍
+        String docNum = null;
+        Long docId = null;
+        switch (check.getSettle()) {
+            case 1:    // 鐩樼泩
+                docNum = "CS-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+                docId = 14L; // 鎶ユ孩鍗�
+                break;
+            case 2:    // 鐩樹簭
+                docNum = "CD-" + String.valueOf(snowflakeIdWorker.nextId()).substring(0, 15);
+                docId = 9L;  // 鎶ユ崯鍗�
+                break;
+            default:
+                throw new CoolException("鐩樼偣璁板綍鐩堜簭鎯呭喌寮傚父");
+        }
+        check.setStatus(2);
+        check.setDocId(docId);
+        check.setDocNum(docNum);
+        check.setUpdateBy(userId);
+        check.setUpdateTime(now);
+        if (!checkService.updateById(check)) {
+            throw new CoolException("淇敼鐩樼偣璁板綍鐘舵�佸け璐�");
+        }
+
+        // 涓婃姤缁檈rp
+        List<BillDto> dtos = new ArrayList<>();
+        BillDto billDto = new BillDto();
+        billDto.setMatnr(check.getMatnr());
+        billDto.setQty(Math.abs(check.getDiffQty()));
+        dtos.add(billDto);
+        if (!erpService.uploadBill(dtos, docId.intValue(), docNum)) {
+            throw new CoolException("鏃犳硶涓婃姤鑷砮rp");
+        }
+
+        return R.ok();
+    }
+
 }

--
Gitblit v1.9.1