From 82bcd0328dddbaad65933e2fada22bc68e82b3d5 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期六, 26 八月 2023 10:07:46 +0800
Subject: [PATCH] # 导入订单增加单据类型

---
 src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java |  277 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 196 insertions(+), 81 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
index 6574575..239acd3 100644
--- a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -1,6 +1,7 @@
 package com.zy.asrs.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.BaseRes;
@@ -166,46 +167,70 @@
         for(StockOutParam.LocDetl one : param.getLocDetls()){
             locs.add(one.getLocNo());
         }
-
-        //鍑哄簱鏃讹紝濡傛灉褰撳墠搴撲綅缁勬湁鐩稿悓鐨勭墿鏂欙紝鍒欏厛鍑哄渚х墿鏂�
         for (StockOutParam.LocDetl locDetl : param.getLocDetls()) {
-            List<String> outerSingleLoc = Utils.getGroupOuterSingleLoc(locDetl.getLocNo());
-            boolean flag = false;
-            Double useCount = 0D;
-            for (String locNo : outerSingleLoc) {
+            //鑾峰彇鍚屼竴搴撲綅缁勭殑澶栦晶搴撲綅鍙�
+            List<String> groupOuterSingleLoc = Utils.getGroupOuterSingleLoc(locDetl.getLocNo());
+            if (Utils.getBay(locDetl.getLocNo())>=21){
+                groupOuterSingleLoc = Utils.getGroupOuterSingleLocLowFrequency(locDetl.getLocNo());
+            }
+
+            for (String locNo : groupOuterSingleLoc) {
+                //姣忎釜搴撲綅鐨勫簱浣嶆槑缁�
                 if(locs.contains(locNo)) continue;
-                for (LocDetl locDetl0 : locDetlService.selectByLocNo(locNo)) {
-                    if (!locDetl0.getMatnr().equals(locDetl.getMatnr())) {
+                for (LocDetl detl : locDetlService.selectByLocNo(locNo)) {
+                    if (!detl.getMatnr().equals(locDetl.getMatnr())) {
                         //涓嶆槸鐩稿悓鐗╂枡
+                        if (Utils.getBay(locDetl.getLocNo())>=21){
+                            locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), detl.getMatnr(), detl.getBatch(), detl.getAnfme()));
+                        }
                         continue;
                     }
-                    double lastCount = locDetl.getCount() - useCount;//鍓╀綑鎵�闇�鏁伴噺
-                    double realCount = 0;//瀹為檯鎻愪緵鏁伴噺
-                    if (lastCount==0){
-                        continue;
-                    }
-                    if (locDetl0.getAnfme() >= lastCount) {//瀹為檯鏁伴噺澶т簬鎵�闇�鏁伴噺锛屾寜鎵�闇�鏁伴噺鎻愪緵
-                        realCount = lastCount;
-                    } else {
-                        //瀹為檯灏忎簬鎵�闇�鏁伴噺锛屾寜瀹為檯鏁伴噺鎻愪緵
-                        realCount = locDetl0.getAnfme();
-                    }
-                    useCount += realCount;//宸蹭娇鐢ㄧ殑鏁伴噺
-
-                    locDetls.add(new StockOutParam.LocDetl(locDetl0.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), realCount));
-                    flag = true;
-                    if (useCount >= locDetl.getCount()) {
-                        //鎵惧埌鐨勫簱瀛� >= 鎵�闇�搴撳瓨锛屾弧瓒虫潯浠�
-                        break;
-                    }
+                    locDetls.add(new StockOutParam.LocDetl(detl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), detl.getAnfme()));
                 }
-            }
 
-            if (!flag) {
-                locDetls.add(locDetl);
             }
-
+            locDetls.add(locDetl);
         }
+        //鍑哄簱鏃讹紝濡傛灉褰撳墠搴撲綅缁勬湁鐩稿悓鐨勭墿鏂欙紝鍒欏厛鍑哄渚х墿鏂� 6.30鏃� 娉ㄩ噴
+        //for (StockOutParam.LocDetl locDetl : param.getLocDetls()) {
+        //    List<String> outerSingleLoc = Utils.getGroupOuterSingleLoc(locDetl.getLocNo());
+        //    boolean flag = false;
+        //    Double useCount = 0D;
+        //    for (String locNo : outerSingleLoc) {
+        //        if(locs.contains(locNo)) continue;
+        //        for (LocDetl locDetl0 : locDetlService.selectByLocNo(locNo)) {
+        //            if (!locDetl0.getMatnr().equals(locDetl.getMatnr())) {
+        //                //涓嶆槸鐩稿悓鐗╂枡
+        //                continue;
+        //            }
+        //            double lastCount = locDetl.getCount() - useCount;//鍓╀綑鎵�闇�鏁伴噺
+        //            double realCount = 0;//瀹為檯鎻愪緵鏁伴噺
+        //            if (lastCount==0){
+        //                continue;
+        //            }
+        //            if (locDetl0.getAnfme() >= lastCount) {//瀹為檯鏁伴噺澶т簬鎵�闇�鏁伴噺锛屾寜鎵�闇�鏁伴噺鎻愪緵
+        //                realCount = lastCount;
+        //            } else {
+        //                //瀹為檯灏忎簬鎵�闇�鏁伴噺锛屾寜瀹為檯鏁伴噺鎻愪緵
+        //                realCount = locDetl0.getAnfme();
+        //            }
+        //            useCount += realCount;//宸蹭娇鐢ㄧ殑鏁伴噺
+        //
+        //            locDetls.add(new StockOutParam.LocDetl(locDetl0.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), realCount));
+        //            flag = true;
+        //            if (useCount >= locDetl.getCount()) {
+        //                //鎵惧埌鐨勫簱瀛� >= 鎵�闇�搴撳瓨锛屾弧瓒虫潯浠�
+        //                break;
+        //            }
+        //        }
+        //    }
+        //
+        //    if (!flag) {
+        //        locDetls.add(locDetl);
+        //    }
+        //
+        //}
+
         // TODO: 2023/6/28 绛夋潕钖囩‘璁ゆ槸鍚︿娇鐢�
         // ----------------------------------------------
         //for(StockOutParam.LocDetl one : param.getLocDetls()){
@@ -430,6 +455,7 @@
     @Override
     @Transactional
     public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, IoWorkType ioWorkType, Long userId) {
+        Integer basDevp = staNo.getDevNo();
         Date now = new Date();
         // 鍚堝苟鍚岀被椤�
         Set<String> locNos = new HashSet<>();
@@ -483,9 +509,9 @@
                 if (!locMast.getLocSts().equals("F")) {
                     continue;
                 }
-                if (locMast.getLocSts().equals("F")) {
-                    throw new CoolException("娴呭簱浣嶅湪搴撲笉鏀寔姝や换鍔�");
-                }
+                //if (locMast.getLocSts().equals("F")) {
+                //    throw new CoolException("娴呭簱浣嶅湪搴撲笉鏀寔姝や换鍔�");
+                //}
                 boolean flag = false;
                 for (LocDetl locDetl : locDetlService.selectByLocNo(locMast.getLocNo())) {
                     if (!locDetl.getMatnr().equals(matnr)) {
@@ -556,6 +582,10 @@
                         if (Cools.isEmpty(mat)) {
                             throw new CoolException(locDetl.getMatnr() + "鍟嗗搧妗f涓嶅瓨鍦�");
                         }
+                        int zpallet = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", locDetl.getZpallet()).ne("loc_no",locDetl.getLocNo()));
+                        if (zpallet>0) {
+                            throw new CoolException(locDetl.getZpallet() + "鍏ュ簱閫氱煡妗d腑宸插瓨鍦�");
+                        }
                         WaitPakin waitPakin = new WaitPakin();
                         waitPakin.sync(mat);
                         waitPakin.setBatch("");
@@ -607,13 +637,27 @@
             //-----------------2023.6.2鍑哄簱鍏煎浠g爜-----------------------
             if (ioType!=107){
                 List<LocDetl> locDetls = locDetlService.selectByLocNo(locMast.getLocNo());
-                if (locMast.getLocType2() == 1 && locDetls.size() > 1) {
-                    //鍗曞搧鍖哄煙鍑哄簱鐗╂枡澶т簬1绉嶏紝寮哄埗鍙樻垚101鍏ㄦ澘鍑哄簱
-                    ioType = 101;
+                //if (locMast.getLocType2() == 1 && locDetls.size() > 1) {
+                //    //鍗曞搧鍖哄煙鍑哄簱鐗╂枡澶т簬1绉嶏紝寮哄埗鍙樻垚101鍏ㄦ澘鍑哄簱
+                //    ioType = 101;
+                //    if (staNo.getDevNo()==300){
+                //        staNo.setDevNo(200);
+                //    }
+                //}
+                if (ioType == 101) {
                     if (staNo.getDevNo()==300){
-                        staNo.setDevNo(200);
+                        if(locMast.getCrnNo() == 1) {
+                            staNo.setDevNo(100);
+                        } else {
+                            staNo.setDevNo(200);
+                        }
+
                     }
+                } else {
+                    staNo.setDevNo(basDevp);
                 }
+
+
             }
             //-----------------2023.6.2鍑哄簱鍏煎浠g爜end-----------------------
 
@@ -694,6 +738,54 @@
     @Transactional
     public void stockOut(BasDevp staNo, TaskDto taskDto, Long userId) {
         Date now = new Date();
+        if (Cools.isEmpty(taskDto.getLocDtos()) || taskDto.getLocDtos().size()==0){
+            // 鑾峰彇搴撲綅
+            LocMast locMast = locMastService.selectById(taskDto.getLocNo());
+            // 鑾峰彇璺緞
+            int ioType = locMast.getLocSts().equals("D") ? 110 : 101;
+            StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo());
+            // 鐢熸垚宸ヤ綔鍙�
+            int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
+            // 鐢熸垚宸ヤ綔妗�
+            WrkMast wrkMast = new WrkMast();
+            wrkMast.setWrkNo(workNo);
+            wrkMast.setIoTime(now);
+            wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+            wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
+            Double ioPri = wrkMastService.getIoPri(ioType, taskDto.getLocNo());
+            wrkMast.setIoPri(ioPri); // 浼樺厛绾э細13
+            wrkMast.setOutMost(locMastService.isOutMost(taskDto.getLocNo(), false) ? 1 : 0);
+            wrkMast.setCrnNo(locMast.getCrnNo());
+            wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
+            wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
+            wrkMast.setSourceLocNo(taskDto.getLocNo()); // 婧愬簱浣�
+            wrkMast.setFullPlt(ioType==110? "N":"Y"); // 婊℃澘锛歒
+            wrkMast.setPicking("N"); // 鎷f枡
+            wrkMast.setExitMk("N"); // 閫�鍑�
+            wrkMast.setEmptyMk(ioType==110? "Y":"N"); // 绌烘澘
+            wrkMast.setLinkMis("N");
+            wrkMast.setBarcode(locMast.getBarcode());
+            wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
+            wrkMast.setAppeTime(now);
+            wrkMast.setModiUser(userId);
+            wrkMast.setModiTime(now);
+            if (!wrkMastService.insert(wrkMast)) {
+                throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鍑哄簱搴撲綅鍙凤細" + taskDto.getLocNo());
+            }
+            // 淇敼搴撲綅鐘舵��:   F銆丏.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
+            locMast = locMastService.selectById(taskDto.getLocNo());
+            if (locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") ) {
+                locMast.setLocSts("R");
+                locMast.setModiUser(userId);
+                locMast.setModiTime(now);
+                if (!locMastService.updateById(locMast)) {
+                    throw new CoolException("棰勭害搴撲綅鐘舵�佸け璐ワ紝搴撲綅鍙凤細" + taskDto.getLocNo());
+                }
+            } else {
+                throw new CoolException(taskDto.getLocNo() + "搴撲綅涓嶆槸鍦ㄥ簱鐘舵��");
+            }
+            return;
+        }
         List<LocDto> locDtos = taskDto.getLocDtos();
         for (LocDto locDto : locDtos) {
             if (!taskDto.getLocNo().equals(locDto.getLocNo()) && !taskDto.getStaNo().equals(locDto.getStaNo())) {
@@ -760,51 +852,72 @@
             if (!wrkDetlService.insert(wrkDetl)) {
                 throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
             }
-            // 淇敼璁㈠崟鏄庣粏
-            if (!BaseController.isJSON(locDto.getOrderNo())) {
-                String[] orderNos = GetOrderNo(locDto.getOrderNo());
-                if (!Cools.isEmpty(orderNos)){
-                    Double anfme = locDto.getAnfme();
-                    for (String orderNo : orderNos) {
-                        OrderDetl orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), locDto.getBatch());
-                        if (orderDetl == null) {
-                            orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), null);
+            if (!wrkDetl.getOrderNo().equals("浼寸敓鍑哄簱")){
+                // 淇敼璁㈠崟鏄庣粏
+                if (!BaseController.isJSON(locDto.getOrderNo())) {
+                    String[] orderNos = GetOrderNo(locDto.getOrderNo());
+                    if (!Cools.isEmpty(orderNos) && orderNos.length!=0){
+                        Double anfme = locDto.getAnfme();
+                        for (String orderNo : orderNos) {
+                            OrderDetl orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), locDto.getBatch());
+                            if (orderDetl == null) {
+                                orderDetl = orderDetlService.selectItem(orderNo, locDto.getMatnr(), null);
+                            }
+                            if (orderDetl.getAnfme() <= anfme) {
+                                if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getAnfme())) {
+                                    throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
+                                }
+                                anfme = anfme - orderDetl.getAnfme();
+                            } else {
+                                if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), anfme)) {
+                                    throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
+                                }
+                            }
+                            orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
                         }
-                        if (orderDetl.getAnfme() <= anfme) {
-                            if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getAnfme())) {
-                                throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
-                            }
-                            anfme = anfme - orderDetl.getAnfme();
-                        } else {
-                            if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), anfme)) {
-                                throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
-                            }
+                    }else {
+                        OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
+                        if (orderDetl == null) {
+                            orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
+                        }
+                        if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) {
+                            throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
                         }
                         orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
                     }
-                }else {
-                    OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
-                    if (orderDetl == null) {
-                        orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
-                    }
-                    if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) {
-                        throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
-                    }
-                    orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
-                }
-            } else {
-                // 璁㈠崟鍚堝苟鍑哄簱
-                List<OrderDto> orderDtoList = JSON.parseArray(locDto.getOrderNo(), OrderDto.class);
+                } else {
+                    // 璁㈠崟鍚堝苟鍑哄簱
+                    List<OrderDto> orderDtoList = JSON.parseArray(locDto.getOrderNo(), OrderDto.class);
 
-                for (OrderDto orderDto : orderDtoList) {
-                    OrderDetl orderDetl = orderDetlService.selectItem(orderDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
-                    if (orderDetl == null) {
-                        orderDetl = orderDetlService.selectItem(orderDto.getOrderNo(), locDto.getMatnr(), null);
+                    for (OrderDto orderDto : orderDtoList) {
+                        OrderDetl orderDetl = orderDetlService.selectItem(orderDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
+                        if (orderDetl == null) {
+                            orderDetl = orderDetlService.selectItem(orderDto.getOrderNo(), locDto.getMatnr(), null);
+                        }
+                        if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDto.getAnfme())) {
+                            throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
+                        }
+                        orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
                     }
-                    if (!orderDetlService.increase(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDto.getAnfme())) {
-                        throw new CoolException("淇敼璁㈠崟鏄庣粏鏁伴噺澶辫触");
-                    }
-                    orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
+                }
+            }else {//鑷姩缁勬墭
+                WaitPakin waitPakin = new WaitPakin();
+                waitPakin.sync(mat);
+                waitPakin.setBatch(wrkDetl.getBatch());
+                waitPakin.setZpallet(wrkDetl.getZpallet());   // 鎵樼洏鐮�
+                waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
+                waitPakin.setAnfme(wrkDetl.getAnfme());  // 鏁伴噺
+                waitPakin.setStatus("Y");    // 鐘舵��
+                waitPakin.setAppeUser(userId);
+                waitPakin.setAppeTime(now);
+                waitPakin.setModiUser(userId);
+                waitPakin.setModiTime(now);
+                waitPakin.setMemo(wrkDetl.getMemo());
+                waitPakin.setFrozen(wrkDetl.getFrozen()); // 鏄惁鍐荤粨
+                waitPakin.setManu(wrkDetl.getManu());
+                waitPakin.setMatType(mat.getMatType());//鐗╂枡绫诲瀷
+                if (!waitPakinService.insert(waitPakin)) {
+                    throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
                 }
             }
         }
@@ -995,9 +1108,9 @@
     @Override
     @Transactional
     public void locCheckOut(StockOutParam param, Long userId) {
-        // if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
-        //     throw new CoolException("鍙兘瀛樺湪涓�绗旂洏鐐逛换鍔�");
-        // }
+//         if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 107)) > 0) {
+//             throw new CoolException("鍙兘瀛樺湪涓�绗旂洏鐐逛换鍔�");
+//         }
         // 鐩爣绔欑偣鐘舵�佹娴�
         BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
         // 鑾峰彇搴撲綅鏄庣粏
@@ -1304,7 +1417,7 @@
             } else if (wrkMast.getIoType() == 110) {
                 locSts = "D";
                 // 搴撲綅杞Щ ===>> D.绌烘《/绌烘爤鏉�
-            } else if (wrkMast.getIoType() == 11) {
+            } else if (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111) {
                 if (wrkMast.getWrkSts() > 11){
                     throw new CoolException("绉诲簱浠诲姟宸插湪鎵ц涓紝涓嶈兘鍙栨秷");
                 }
@@ -1401,6 +1514,8 @@
         if (!wrkMastRes || !locMastRes) {
             throw new CoolException("淇濆瓨鏁版嵁澶辫触");
         }
+        WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("zpallet", wrkMast.getBarcode()));
+        waitPakinService.delete(new EntityWrapper<>(waitPakin));
     }
 
     @Override

--
Gitblit v1.9.1