From 14129e42408efdd6c1678f44304c0585273d7e85 Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期四, 28 八月 2025 15:59:58 +0800
Subject: [PATCH] #手动出库agv库位锁定

---
 src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java |  185 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 176 insertions(+), 9 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 64d70f8..c41d17a 100644
--- a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -23,6 +23,8 @@
 import com.zy.common.properties.SlaveProperties;
 import com.zy.common.service.CommonService;
 import com.zy.common.web.WcsController;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -74,6 +76,8 @@
     @Autowired
     private OrderDetlService orderDetlService;
     @Autowired
+    private ConfigService configService;
+    @Autowired
     private WcsController wcsController;
     @Autowired
     private RowLastnoService rowLastnoService;
@@ -106,9 +110,9 @@
         BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getDevpNo(), true);
         // 妫�绱㈠簱浣�
         LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
-        List<String> matnrs = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatnr).distinct().collect(Collectors.toList());
+//        List<String> matnrs = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatnr).distinct().collect(Collectors.toList());
 //        List<String> batchs = param.getList().stream().map(FullStoreParam.MatCodeStore::getBatch).distinct().collect(Collectors.toList());
-        FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(matnrs.get(0));
+        FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(param.getList().get(0));
         StartupDto dto = commonService.getLocNo(1, param.getDevpNo(), findLocNoAttributeVo,locTypeDto);
         if (Cools.isEmpty(dto)){
             throw new CoolException("鏌ヨ搴撲綅澶辫触锛侊紒==銆媠tartupFullPutStore ==銆� commonService.getLocNo");
@@ -307,6 +311,15 @@
                 dtos.add(new OutLocDto(locNo, locDetlDto));
             }
         }
+        Config config = configService.selectConfigByCode("AutoMPArea");
+
+        List<LocMast> list = locMastMapper.selectList(
+                new EntityWrapper<LocMast>()
+                        .eq("whs_type", 5)
+                        .eq("loc_sts", "O")
+        );
+        LocMast locMastRgv = list.isEmpty() ? null : list.get(0);
+
         Integer ioType = null;
         // 鐢熸垚宸ヤ綔妗�
         for (OutLocDto dto : dtos) {
@@ -347,6 +360,10 @@
             wrkMast.setEmptyMk("N"); // 绌烘澘
             wrkMast.setLinkMis("N");
             wrkMast.setBarcode(locMast.getBarcode());
+            if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null) {  //鑻ユ湁绌哄簱浣嶄笖閰嶇疆鍏佽鍒欑粦瀹氬叾澶囨枡搴撲綅鍙�
+                wrkMast.setLocNo(locMastRgv.getLocNo());
+                wrkMast.setTakeNone("0");  //0rgv鏈彇锛�1rgv宸插彇璐�
+            }
             wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
             wrkMast.setAppeTime(now);
             wrkMast.setModiUser(userId);
@@ -371,6 +388,18 @@
                 if (!wrkDetlService.insert(wrkDetl)) {
                     throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
                 }
+            }
+            //淇敼agv澶囨枡鍖虹姸鎬�
+            if(locMastRgv.getLocSts().equals("O")){
+                locMastRgv.setLocSts("S");
+                locMastRgv.setModiUser(userId);
+                locMastRgv.setModiTime(now);
+                if (!locMastService.updateById(locMastRgv)) {
+                    throw new CoolException("棰勭害agv澶囨枡鍖哄簱浣嶇姸鎬佸け璐ワ紝搴撲綅鍙凤細"+locMastRgv.getLocNo());
+                }
+            }else{
+                throw new CoolException(locMastRgv.getLocNo() + "澶囨枡鍖轰笉鏄┖搴撲綅鐘舵��");
+
             }
             // 淇敼搴撲綅鐘舵��:   F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
             locMast = locMastService.selectById(dto.getLocNo());
@@ -397,6 +426,8 @@
                 throw new CoolException("璁㈠崟鍑哄簱寮傚父锛岃鑱旂郴绠$悊鍛�");
             }
         }
+        Config config = configService.selectConfigByCode("AutoMPArea");
+
         // 鑾峰彇搴撲綅
         LocMast locMast = locMastService.selectById(taskDto.getLocNo());
         // 鍒ゆ柇鏄惁鏄洏鐐瑰崟
@@ -404,6 +435,16 @@
         OrderPakout orderPakout = orderPakOutService.selectByNo(orderNo);
         int ioType = orderPakout.getDocType() == 8 ? 107 : (taskDto.isAll() ? 101 : 103);
         StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo());
+        List<LocMast> list = locMastMapper.selectList(
+                new EntityWrapper<LocMast>()
+                        .eq("whs_type", 5)
+                        .eq("loc_sts", "O")
+        );
+        LocMast locMastRgv = list.isEmpty() ? null : list.get(0);
+
+
+
+
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
         // 鐢熸垚宸ヤ綔妗�
@@ -417,6 +458,10 @@
         wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
         wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
         wrkMast.setSourceLocNo(taskDto.getLocNo()); // 婧愬簱浣�
+        if (Boolean.parseBoolean(config.getValue()) && locMastRgv.getLocNo() != null) {  //鑻ユ湁绌哄簱浣嶄笖閰嶇疆鍏佽鍒欑粦瀹氬叾澶囨枡搴撲綅鍙�
+            wrkMast.setLocNo(locMastRgv.getLocNo());
+            wrkMast.setTakeNone("0");  //0rgv鏈彇锛�1rgv宸插彇璐�
+        }
         wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
@@ -466,6 +511,18 @@
                     orderDetl.getBoxType1(),orderDetl.getBoxType2(),orderDetl.getBoxType3()
                     , locDto.getAnfme());
             OrderInAndOutUtil.updateOrder(Boolean.FALSE,orderDetl.getOrderId(), 2L, userId);
+        }
+        //淇敼agv澶囨枡鍖虹姸鎬�
+        if(locMastRgv.getLocSts().equals("O")){
+            locMastRgv.setLocSts("S");
+            locMastRgv.setModiUser(userId);
+            locMastRgv.setModiTime(now);
+            if (!locMastService.updateById(locMastRgv)) {
+                throw new CoolException("棰勭害agv澶囨枡鍖哄簱浣嶇姸鎬佸け璐ワ紝搴撲綅鍙凤細"+locMastRgv.getLocNo());
+            }
+        }else{
+            throw new CoolException(locMastRgv.getLocNo() + "澶囨枡鍖轰笉鏄┖搴撲綅鐘舵��");
+
         }
         // 淇敼搴撲綅鐘舵��:   F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
         locMast = locMastService.selectById(taskDto.getLocNo());
@@ -852,6 +909,31 @@
 
         List<LocDetlAdjustParam.LocDetlAdjust> list = param.getList();
 
+        // 娣诲姞鍘嗗彶宸ヤ綔涓绘。
+        WrkMastLog wrkMast = new WrkMastLog();
+        wrkMast.setIoTime(now);
+        wrkMast.setWrkSts(5);
+        wrkMast.setIoPri(13D); // 浼樺厛绾�
+        wrkMast.setCrnNo(locMast.getCrnNo());
+        wrkMast.setSourceLocNo(locMast.getLocNo());
+        wrkMast.setLocNo(locMast.getLocNo());
+        wrkMast.setBarcode(locMast.getBarcode()); // 鎵樼洏鐮�
+        wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
+        wrkMast.setPicking("N"); // 鎷f枡
+        wrkMast.setExitMk("N"); // 閫�鍑�
+        wrkMast.setEmptyMk("N"); // 绌烘澘
+        wrkMast.setLinkMis("Y");
+        // 鎿嶄綔浜哄憳鏁版嵁
+        wrkMast.setAppeTime(now);
+        wrkMast.setModiTime(now);
+        wrkMast.setAppeUser(userId);
+        wrkMast.setModiUser(userId);
+
+        // 澧炲垹鏀瑰彧鍒涘缓涓�娆″伐浣滀富妗�
+        boolean updateFlag = true;
+        boolean deleteFlag = true;
+        boolean addFlag = true;
+
         // 淇敼鏁伴噺
         Iterator<LocDetl> iterator = locDetls.iterator();
         while (iterator.hasNext()) {
@@ -881,6 +963,30 @@
                         adjDetl.setAppeTime(now);
                         adjDetl.setAppeUser(userId);
                         adjDetlService.save(adjDetl, userId);
+
+                        if (updateFlag) {
+                            wrkMast.setWrkNo(commonService.getWorkNo(3));
+                            wrkMast.setIoType(23);
+                            boolean res = wrkMastLogService.insert(wrkMast);
+                            if (!res) {
+                                throw new CoolException("搴撳瓨璋冩暣-淇敼 淇濆瓨宸ヤ綔妗eけ璐�");
+                            }
+                            updateFlag = false;
+                        }
+
+                        // 娣诲姞鍘嗗彶宸ヤ綔鏄庣粏
+                        WrkDetlLog wrkDetl = new WrkDetlLog();
+                        wrkDetl.sync(locDetl);
+                        wrkDetl.setWrkNo(wrkMast.getWrkNo());
+                        wrkDetl.setIoTime(wrkMast.getIoTime());
+                        wrkDetl.setAnfme(adjust.getCount());
+                        wrkDetl.setAppeTime(now);
+                        wrkDetl.setModiTime(now);
+                        wrkMast.setAppeUser(userId);
+                        wrkMast.setModiUser(userId);
+                        if (!wrkDetlLogService.insert(wrkDetl)) {
+                            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触");
+                        }
                     }
                     iterator.remove();
                     iterator1.remove();
@@ -907,6 +1013,30 @@
             adjDetl.setAppeTime(now);
             adjDetl.setAppeUser(userId);
             adjDetlService.save(adjDetl, userId);
+
+            if (deleteFlag) {
+                wrkMast.setWrkNo(commonService.getWorkNo(3));
+                wrkMast.setIoType(22);
+                boolean res = wrkMastLogService.insert(wrkMast);
+                if (!res) {
+                    throw new CoolException("搴撳瓨璋冩暣-鍒犻櫎 淇濆瓨宸ヤ綔妗eけ璐�");
+                }
+                deleteFlag = false;
+            }
+
+            // 娣诲姞鍘嗗彶宸ヤ綔鏄庣粏
+            WrkDetlLog wrkDetl = new WrkDetlLog();
+            wrkDetl.sync(locDetl);
+            wrkDetl.setWrkNo(wrkMast.getWrkNo());
+            wrkDetl.setIoTime(wrkMast.getIoTime());
+            wrkDetl.setAnfme(0.0);
+            wrkDetl.setAppeTime(now);
+            wrkDetl.setModiTime(now);
+            wrkMast.setAppeUser(userId);
+            wrkMast.setModiUser(userId);
+            if (!wrkDetlLogService.insert(wrkDetl)) {
+                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触");
+            }
         }
 
         // 娣诲姞搴撳瓨
@@ -917,6 +1047,7 @@
             locDetl.sync(mat);
             locDetl.setBatch(adjust.getBatch());
             locDetl.setLocNo(locMast.getLocNo());
+            locDetl.setZpallet(locMast.getBarcode());
             locDetl.setAnfme(adjust.getCount()); // 鏁伴噺
             locDetl.setModiUser(userId); // 鎿嶄綔浜哄憳淇℃伅
             locDetl.setModiTime(now);
@@ -937,6 +1068,30 @@
             adjDetl.setAppeTime(now);
             adjDetl.setAppeUser(userId);
             adjDetlService.save(adjDetl, userId);
+
+            if (addFlag) {
+                wrkMast.setWrkNo(commonService.getWorkNo(3));
+                wrkMast.setIoType(21);
+                boolean res = wrkMastLogService.insert(wrkMast);
+                if (!res) {
+                    throw new CoolException("搴撳瓨璋冩暣-鏂板 淇濆瓨宸ヤ綔妗eけ璐�");
+                }
+                addFlag = false;
+            }
+
+            // 娣诲姞鍘嗗彶宸ヤ綔鏄庣粏
+            WrkDetlLog wrkDetl = new WrkDetlLog();
+            wrkDetl.sync(locDetl);
+            wrkDetl.setWrkNo(wrkMast.getWrkNo());
+            wrkDetl.setIoTime(wrkMast.getIoTime());
+            wrkDetl.setAnfme(adjust.getCount());
+            wrkDetl.setAppeTime(now);
+            wrkDetl.setModiTime(now);
+            wrkMast.setAppeUser(userId);
+            wrkMast.setModiUser(userId);
+            if (!wrkDetlLogService.insert(wrkDetl)) {
+                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏澶辫触");
+            }
         }
         // 淇敼搴撲綅鐘舵��
         int count = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
@@ -1030,6 +1185,16 @@
         //鍙栨秷鍑哄簱宸ヤ綔妗f椂锛屾煡璇㈠崟鎹鐞嗚〃锛屽洖婊氫綔涓氫腑鏁伴噺
         if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103) {
             List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
+            if(wrkMast.getLocNo() != null){
+                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
+                locMast.setLocSts("O");
+                locMast.setModiTime(now);
+                locMast.setModiUser(userId);
+                boolean locMastRes = locMastService.updateById(locMast);
+                if (!locMastRes) {
+                    throw new CoolException("淇濆瓨鏁版嵁澶辫触");
+                }
+            }
             for (WrkDetl wrkDetl : wrkDetls) {
                 if (!Cools.isEmpty(wrkDetl.getOrderNo())) {
 //                    if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) {
@@ -1103,15 +1268,17 @@
 
         // 淇敼搴撲綅鐘舵��
         LocMast locMast = locMastService.selectById(locNo);
-        if (Cools.isEmpty(locMast)) {
+        if (Cools.isEmpty(locMast) && wrkMast.getIoType() != 12) {
             throw new CoolException("鍙栨秷宸ヤ綔妗eけ璐ワ紝搴撲綅涓嶅瓨鍦�:"+ locNo);
         }
-        locMast.setLocSts(locSts);
-        locMast.setModiTime(now);
-        locMast.setModiUser(userId);
-        boolean locMastRes = locMastService.updateById(locMast);
-        if (!wrkMastRes || !locMastRes) {
-            throw new CoolException("淇濆瓨鏁版嵁澶辫触");
+        if(wrkMast.getIoType() != 12){
+            locMast.setLocSts(locSts);
+            locMast.setModiTime(now);
+            locMast.setModiUser(userId);
+            boolean locMastRes = locMastService.updateById(locMast);
+            if (!wrkMastRes || !locMastRes) {
+                throw new CoolException("淇濆瓨鏁版嵁澶辫触");
+            }
         }
     }
 

--
Gitblit v1.9.1