From 08db0577065eef6bc6100c03b50b5c984772086e Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期一, 11 七月 2022 11:14:01 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java |  361 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 272 insertions(+), 89 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 d257470..a874c50 100644
--- a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -13,9 +13,13 @@
 import com.zy.asrs.entity.param.LocDetlAdjustParam;
 import com.zy.asrs.entity.param.StockOutParam;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.Utils;
 import com.zy.common.model.*;
+import com.zy.common.model.enums.IoWorkType;
 import com.zy.common.model.enums.WorkNoType;
+import com.zy.common.properties.SlaveProperties;
 import com.zy.common.service.CommonService;
+import com.zy.common.web.WcsController;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -65,6 +69,12 @@
     private OrderService orderService;
     @Autowired
     private OrderDetlService orderDetlService;
+    @Autowired
+    private WcsController wcsController;
+    @Autowired
+    private RowLastnoService rowLastnoService;
+    @Autowired
+    private SlaveProperties slaveProperties;
 
     @Override
     @Transactional
@@ -89,6 +99,7 @@
         wrkMast.setWrkSts(1L); // 宸ヤ綔鐘舵�侊細鐢熸垚鍏ュ簱ID
         wrkMast.setIoType(1); // 鍏ュ嚭搴撶姸鎬侊細1.鍏ュ簱
         wrkMast.setIoPri(13D); // 浼樺厛绾э細13
+        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo())?1:0);;
         wrkMast.setCrnNo(dto.getCrnNo());
         wrkMast.setSourceStaNo(dto.getSourceStaNo());
         wrkMast.setStaNo(dto.getStaNo());
@@ -165,7 +176,7 @@
 
     @Override
     @Transactional
-    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, Integer ioType, Long userId) {
+    public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, IoWorkType ioWorkType, Long userId) {
         Date now = new Date();
         // 鍚堝苟鍚岀被椤�
         Set<String> locNos = new HashSet<>();
@@ -184,13 +195,24 @@
                 dtos.add(new OutLocDto(locNo, locDetlDto));
             }
         }
-
+        Integer ioType = null;
         // 鐢熸垚宸ヤ綔妗�
         for (OutLocDto dto : dtos) {
-            // 鍒ゆ柇鍏ュ嚭搴撶被鍨嬶細101.鍏ㄦ澘鍑哄簱 or 103.鎷f枡鍑哄簱
-            if (ioType == null) {
-                ioType = dto.isAll() ? 101 : 103;
+            // 濡傛灉涓烘繁搴撲綅锛屼笖瀵瑰簲娴呭簱浣嶄负X.绂佺敤锛屽垯鐣ヨ繃姝ゅ簱浣�
+            if (Utils.isDeepLoc(slaveProperties, dto.getLocNo())) {
+                String shallowLoc = Utils.getShallowLoc(slaveProperties, dto.getLocNo());
+                if (locMastService.selectById(shallowLoc).getLocSts().equals("X")) {
+                    continue;
+                }
             }
+
+            // 鍒ゆ柇鍏ュ嚭搴撶被鍨嬶細101.鍏ㄦ澘鍑哄簱 or 103.鎷f枡鍑哄簱
+            if (ioWorkType == null) {
+                ioType = dto.isAll() ? 101 : 103;
+            } else if (ioWorkType.equals(IoWorkType.CHECK_OUT)) {
+                ioType = 107;
+            }
+            assert ioType != null;
             // 鑾峰彇搴撲綅
             LocMast locMast = locMastService.selectById(dto.getLocNo());
             // 鑾峰彇璺緞
@@ -204,6 +226,7 @@
             wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
             wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
             wrkMast.setIoPri(13D); // 浼樺厛绾э細13
+            wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo())?1:0);;
             wrkMast.setCrnNo(locMast.getCrnNo());
             wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
             wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
@@ -213,6 +236,7 @@
             wrkMast.setExitMk("N"); // 閫�鍑�
             wrkMast.setEmptyMk("N"); // 绌烘澘
             wrkMast.setLinkMis("N");
+            wrkMast.setBarcode(locMast.getBarcode());
             wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
             wrkMast.setAppeTime(now);
             wrkMast.setModiUser(userId);
@@ -225,6 +249,7 @@
                 if (detlDto.getCount()==null || detlDto.getCount() <= 0.0D) {continue;}
                 WrkDetl wrkDetl = new WrkDetl();
                 wrkDetl.sync(detlDto.getLocDetl());
+                wrkDetl.setOrderNo(""); // 鎵嬪姩鍑哄簱涓嶉渶瑕佸甫鍑哄簱瀛樹腑鐨勫崟鎹紪鍙�
                 wrkDetl.setWrkNo(workNo);
                 wrkDetl.setIoTime(now);
                 Double anfme = ioType==101?detlDto.getLocDetl().getAnfme():detlDto.getCount();
@@ -266,7 +291,7 @@
         LocMast locMast = locMastService.selectById(taskDto.getLocNo());
         // 鑾峰彇璺緞
         int ioType = taskDto.isAll() ? 101 : 103;
-        StaDesc staDesc = staDescService.queryCrnStn(ioType, locMast.getCrnNo(), staNo.getDevNo());
+        StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo());
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
         // 鐢熸垚宸ヤ綔妗�
@@ -276,6 +301,7 @@
         wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
         wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
         wrkMast.setIoPri(13D); // 浼樺厛绾э細13
+        wrkMast.setOutMost(locMastService.isOutMost(taskDto.getLocNo())?1:0);;
         wrkMast.setCrnNo(locMast.getCrnNo());
         wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
         wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
@@ -285,6 +311,7 @@
         wrkMast.setExitMk("N"); // 閫�鍑�
         wrkMast.setEmptyMk("N"); // 绌烘澘
         wrkMast.setLinkMis("N");
+        wrkMast.setBarcode(locMast.getBarcode());
         wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
         wrkMast.setAppeTime(now);
         wrkMast.setModiUser(userId);
@@ -296,8 +323,12 @@
         for (LocDto locDto : taskDto.getLocDtos()) {
             if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; }
             OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
+            if (orderDetl == null) {
+                orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
+            }
             WrkDetl wrkDetl = new WrkDetl();
             wrkDetl.sync(orderDetl);
+            wrkDetl.setZpallet(wrkMast.getBarcode());
             wrkDetl.setIoTime(now);
             wrkDetl.setWrkNo(workNo);
             wrkDetl.setBatch(locDto.getBatch());
@@ -346,6 +377,7 @@
         wrkMast.setWrkSts(1L); // 宸ヤ綔鐘舵�侊細鐢熸垚鍏ュ簱ID
         wrkMast.setIoType(10); // 鍏ュ嚭搴撶姸鎬侊細10.绌烘澘鍏ュ簱
         wrkMast.setIoPri(10D); // 浼樺厛绾э細10
+        wrkMast.setOutMost(locMastService.isOutMost(dto.getLocNo())?1:0);;
         wrkMast.setCrnNo(dto.getCrnNo());
         wrkMast.setSourceStaNo(dto.getSourceStaNo());
         wrkMast.setStaNo(dto.getStaNo());
@@ -394,6 +426,13 @@
             throw new CoolException("绔欑偣涓嶅瓨鍦�");
         }
         for (String locNo : param.getLocNos()) {
+            // 濡傛灉涓烘繁搴撲綅锛屼笖瀵瑰簲娴呭簱浣嶄负X.绂佺敤锛屽垯鐣ヨ繃姝ゅ簱浣�
+            if (Utils.isDeepLoc(slaveProperties, locNo)) {
+                String shallowLoc = Utils.getShallowLoc(slaveProperties, locNo);
+                if (locMastService.selectById(shallowLoc).getLocSts().equals("X")) {
+                    continue;
+                }
+            }
             // 鑾峰彇宸ヤ綔鍙�
             int workNo = commonService.getWorkNo(WorkNoType.PAKOUT.type);
             // 鑾峰彇搴撲綅
@@ -420,6 +459,7 @@
             wrkMast.setIoPri(10D);
             wrkMast.setSourceStaNo(sourceStaNo); // 婧愮珯
             wrkMast.setStaNo(param.getOutSite()); // 鐩爣绔�
+            wrkMast.setOutMost(locMastService.isOutMost(locNo)?1:0);;
             wrkMast.setCrnNo(locMast.getCrnNo());
             wrkMast.setSourceLocNo(locNo); // 婧愬簱浣�
             wrkMast.setFullPlt("N"); // 婊℃澘锛歒
@@ -462,7 +502,7 @@
         }
         if (!locDetlDtos.isEmpty()) {
             // 鍚姩鍑哄簱寮�濮� 107.鐩樼偣鍑哄簱
-            stockOut(staNo, locDetlDtos, 107, userId);
+            stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
         } else {
             throw new CoolException("搴撲綅鐗╂枡涓嶅瓨鍦�");
         }
@@ -472,6 +512,7 @@
     @Transactional
     public void locMove(String sourceLocNo, String locNo, Long userId) {
         LocMast sourceLoc = locMastService.selectById(sourceLocNo);
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
         if (Cools.isEmpty(sourceLoc)){
             throw new CoolException("鏈壘鍒板簱浣�");
         }
@@ -491,10 +532,11 @@
         wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
         wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
         wrkMast.setIoPri(10D);
+        wrkMast.setOutMost(locMastService.isOutMost(locNo)?1:0);;
         wrkMast.setCrnNo(sourceLoc.getCrnNo());
         wrkMast.setSourceLocNo(sourceLocNo); // 婧愬簱浣�
         wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
-        wrkMast.setFullPlt("N"); // 婊℃澘锛歒
+        wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 婊℃澘锛歒
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
         wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
@@ -509,7 +551,6 @@
             throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
         }
         // 宸ヤ綔妗f槑缁嗕繚瀛�
-        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
         for (LocDetl locDetl : locDetls) {
             WrkDetl wrkDetl = new WrkDetl();
             wrkDetl.sync(locDetl);
@@ -555,15 +596,15 @@
         if (Cools.isEmpty(wrkMast)){
             throw new CoolException(workNo+"宸ヤ綔妗d笉瀛樺湪");
         }
-        if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) {
+        if (wrkMast.getWrkSts() == 9 || wrkMast.getWrkSts() == 17) {
             throw new CoolException("褰撳墠宸ヤ綔妗e凡瀹屾垚");
         }
         // 鍏ュ簱 + 搴撲綅杞Щ
-        if (wrkMast.getWrkSts() < 4 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType()==11)) {
-            wrkMast.setWrkSts(4L);
-        // 鍑哄簱
+        if (wrkMast.getWrkSts() < 9 || (wrkMast.getWrkSts() > 10 && wrkMast.getIoType()==11)) {
+            wrkMast.setWrkSts(9L);
+            // 鍑哄簱
         } else if (wrkMast.getWrkSts() > 10) {
-            wrkMast.setWrkSts(14L);
+            wrkMast.setWrkSts(17L);
         }
         Date now = new Date();
         wrkMast.setCrnStrTime(DateUtils.calculate(now, 1L, TimeUnit.SECONDS, true));
@@ -580,83 +621,123 @@
     @Override
     @Transactional
     public void adjustLocDetl(LocDetlAdjustParam param, Long userId) {
+        param.integrate();
         LocMast locMast = locMastService.selectById(param.getLocNo());
         if (Cools.isEmpty(locMast)) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
         }
-        for (LocDetlAdjustParam.LocDetlAdjust adjust : param.getList()) {
-            if (Cools.isEmpty(adjust.getMatnr())) {
-                throw new CoolException(BaseRes.PARAM);
-            }
-            LocDetl sqlParam = new LocDetl();
-            sqlParam.setLocNo(locMast.getLocNo());
-            sqlParam.setMatnr(adjust.getMatnr());
-            LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
-            // 淇濆瓨鏂板簱瀛樻槑缁�
-            if (Cools.isEmpty(one)) {
-                if (adjust.getCount() == 0){
-                    continue;
-                }
-                Mat mat = matService.selectByMatnr(adjust.getMatnr());
-                LocDetl locDetl = new LocDetl();
-                locDetl.sync(mat);
-                locDetl.setLocNo(locMast.getLocNo());
-                locDetl.setAnfme(adjust.getCount()); // 鏁伴噺
-                locDetl.setModiUser(userId); // 鎿嶄綔浜哄憳淇℃伅
-                locDetl.setModiTime(new Date());
-                locDetl.setAppeUser(userId);
-                locDetl.setAppeTime(new Date());
-                if (!locDetlService.insert(locDetl)) {
-                    throw new CoolException("淇濆瓨搴撳瓨鏄庣粏澶辫触");
-                }
-                // 淇濆瓨璋冩暣璁板綍
-                AdjDetl adjDetl = new AdjDetl();
-                adjDetl.setLocNo(locDetl.getLocNo());
-                adjDetl.setMatNo(locDetl.getMatnr());
-                adjDetl.setOriQty(0.0D);
-                adjDetl.setAdjQty(adjust.getCount());
-                adjDetlService.save(adjDetl, userId);
-            // 淇敼鍘熷簱瀛樻槑缁�
-            } else {
-                // 濡傛灉鏁伴噺淇敼锛屽垯鏇存柊搴撳瓨鏄庣粏
-                if (!adjust.getCount().equals(one.getAnfme())) {
-                    // 褰撴暟閲忚淇敼涓� 0 鏃讹紝鐩存帴娓呴櫎搴撳瓨鏄庣粏
-                    if (adjust.getCount() == 0) {
-                        // 鍒犻櫎搴撳瓨
-                        if (!locDetlService.delete(new EntityWrapper<>(one))) {
-                            throw new CoolException("娓呴櫎搴撳瓨鏄庣粏澶辫触");
+        if (!(locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") || locMast.getLocSts().equals("O"))) {
+            throw new CoolException("褰撳墠搴撲綅涓嶅彲璋冩暣锛佸簱浣嶇姸鎬侊細" + locMast.getLocSts$());
+        }
+
+        Date now = new Date();
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", param.getLocNo()));
+
+        List<LocDetlAdjustParam.LocDetlAdjust> list = param.getList();
+
+        // 淇敼鏁伴噺
+        Iterator<LocDetl> iterator = locDetls.iterator();
+        while (iterator.hasNext()) {
+            LocDetl locDetl = iterator.next();
+
+            Iterator<LocDetlAdjustParam.LocDetlAdjust> iterator1 = list.iterator();
+            while (iterator1.hasNext()) {
+                LocDetlAdjustParam.LocDetlAdjust adjust = iterator1.next();
+                if (adjust.getCount() == 0) { continue; }
+                if (locDetl.getMatnr().equals(adjust.getMatnr()) && Cools.eq(locDetl.getBatch(), adjust.getBatch())) {
+                    if (!locDetl.getAnfme().equals(adjust.getCount())) {
+                        // todo 鐩樼偣璁板綍
+                        // 淇敼搴撳瓨
+                        if (!locDetlService.updateAnfme(adjust.getCount(), locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
+                            throw new CoolException(locDetl.getLocNo() + "搴撲綅锛�" + locDetl.getMatnr() + "鍟嗗搧锛�" + locDetl.getBatch() + "搴忓垪鐮佷慨鏀规暟閲忓け璐�");
                         }
-                    } else {
-                        LocDetl sqlParam1 = new LocDetl();
-                        sqlParam1.setAnfme(adjust.getCount());
-                        sqlParam1.setModiTime(new Date());
-                        sqlParam1.setModiUser(userId);
-                        if (!locDetlService.update(sqlParam1, new EntityWrapper<LocDetl>()
-                                .eq("loc_no", locMast.getLocNo())
-                                .eq("matnr", adjust.getMatnr()))) {
-                            throw new CoolException("淇敼搴撳瓨鏄庣粏澶辫触");
-                        }
+                        // 淇濆瓨璋冩暣璁板綍
+                        AdjDetl adjDetl = new AdjDetl();
+                        adjDetl.setLocNo(locDetl.getLocNo());
+                        adjDetl.setMatnr(locDetl.getMatnr());
+                        adjDetl.setBatch(locDetl.getBatch());
+                        adjDetl.setOriQty(locDetl.getAnfme());
+                        adjDetl.setAdjQty(adjust.getCount());
+                        adjDetl.setModiTime(now);
+                        adjDetl.setModiUser(userId);
+                        adjDetl.setAppeTime(now);
+                        adjDetl.setAppeUser(userId);
+                        adjDetlService.save(adjDetl, userId);
                     }
-                    // 淇濆瓨璋冩暣璁板綍
-                    AdjDetl adjDetl = new AdjDetl();
-                    adjDetl.setLocNo(locMast.getLocNo());
-                    adjDetl.setMatNo(adjust.getMatnr());
-                    adjDetl.setOriQty(one.getAnfme());
-                    adjDetl.setAdjQty(adjust.getCount());
-                    adjDetlService.save(adjDetl, userId);
+                    iterator.remove();
+                    iterator1.remove();
                 }
             }
         }
-        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", param.getLocNo()));
-        if (locDetls.isEmpty()) {
-            locMast.setLocSts("D");
-            locMast.setModiUser(userId);
-            locMast.setModiTime(new Date());
-            if (!locMastService.updateById(locMast)) {
-                throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐�");
+
+        // 鍒犻櫎搴撳瓨
+        for (LocDetl locDetl : locDetls) {
+            // todo 鐩樼偣璁板綍
+            if (!locDetlService.updateAnfme(-1.0D, locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
+                throw new CoolException("鍒犻櫎" + locDetl.getLocNo() + "搴撲綅锛�" + locDetl.getMatnr() + "鍟嗗搧锛�" + locDetl.getBatch() + "搴忓垪鐮佸簱瀛樻槑缁嗗け璐�");
             }
+            // 淇濆瓨璋冩暣璁板綍
+            AdjDetl adjDetl = new AdjDetl();
+            adjDetl.setLocNo(locDetl.getLocNo());
+            adjDetl.setMatnr(locDetl.getMatnr());
+            adjDetl.setBatch(locDetl.getBatch());
+            adjDetl.setOriQty(locDetl.getAnfme());
+            adjDetl.setAdjQty(0.0D);
+            adjDetl.setModiTime(now);
+            adjDetl.setModiUser(userId);
+            adjDetl.setAppeTime(now);
+            adjDetl.setAppeUser(userId);
+            adjDetlService.save(adjDetl, userId);
+        }
+
+        // 娣诲姞搴撳瓨
+        for (LocDetlAdjustParam.LocDetlAdjust adjust : list) {
+            if (adjust.getCount() == 0.0D) { continue; }
+            Mat mat = matService.selectByMatnr(adjust.getMatnr());
+            LocDetl locDetl = new LocDetl();
+            locDetl.sync(mat);
+            locDetl.setBatch(adjust.getBatch());
+            locDetl.setLocNo(locMast.getLocNo());
+            locDetl.setAnfme(adjust.getCount()); // 鏁伴噺
+            locDetl.setModiUser(userId); // 鎿嶄綔浜哄憳淇℃伅
+            locDetl.setModiTime(now);
+            locDetl.setAppeUser(userId);
+            locDetl.setAppeTime(now);
+            if (!locDetlService.insert(locDetl)) {
+                throw new CoolException("娣诲姞" + locDetl.getLocNo() + "搴撲綅锛�" + locDetl.getMatnr() + "鍟嗗搧锛�" + locDetl.getBatch() + "搴忓垪鐮佸簱瀛樻槑缁嗗け璐�");
+            }
+            // 淇濆瓨璋冩暣璁板綍
+            AdjDetl adjDetl = new AdjDetl();
+            adjDetl.setLocNo(locMast.getLocNo());
+            adjDetl.setMatnr(adjust.getMatnr());
+            adjDetl.setBatch(adjust.getBatch());
+            adjDetl.setOriQty(0.0D);
+            adjDetl.setAdjQty(adjust.getCount());
+            adjDetl.setModiTime(now);
+            adjDetl.setModiUser(userId);
+            adjDetl.setAppeTime(now);
+            adjDetl.setAppeUser(userId);
+            adjDetlService.save(adjDetl, userId);
+        }
+        // 淇敼搴撲綅鐘舵��
+        int count = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
+        if (locMast.getLocSts().equals("F")) {
+            if (count == 0) {
+                locMast.setLocSts("D");
+            }
+        }
+        if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("O")) {
+            if (count > 0) {
+                locMast.setLocSts("F");
+            }
+        }
+        locMast.setModiUser(userId);
+        locMast.setModiTime(new Date());
+        if (!locMastService.updateById(locMast)) {
+            throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐�");
         }
     }
+
 
     @Override
     @Transactional
@@ -671,11 +752,8 @@
         if (wrkMast.getWrkSts() < 4) {
             locNo = wrkMast.getLocNo();
             locSts = "O";
-            /**
-             * 搴撲綅杞Щ
-             * 鍙栨秷鍚� 婧愬簱浣� ==>> F.鍦ㄥ簱
-             *       鐩爣搴撲綅 ===>> O.绌哄簱浣�
-             **/
+
+            // 搴撲綅杞Щ
             if (wrkMast.getIoType() == 11) {
                 // 搴撲綅杞Щ锛氭簮搴撲綅
                 LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
@@ -698,7 +776,7 @@
                 locSts = "D";
             // 搴撲綅杞Щ ===>> D.绌烘《/绌烘爤鏉�
             } else if (wrkMast.getIoType() == 11) {
-                locSts = "F";
+                locSts = wrkMast.getFullPlt().equalsIgnoreCase("N")?"D":"F";
                 // 搴撲綅杞Щ锛氱洰鏍囧簱浣�
                 LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                 if (Cools.isEmpty(locMast)) {
@@ -740,7 +818,7 @@
         if (wrkMast.getIoType() != 10 && wrkMast.getIoType() != 110) {
             // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
             if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
-                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏鍘嗗彶妗eけ璐�, workNo = " + wrkMast.getWrkNo());
+//                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏鍘嗗彶妗eけ璐�, workNo = " + wrkMast.getWrkNo());
             }
             // 鍒犻櫎宸ヤ綔妗f槑缁�
             boolean wrkDetlRes = wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo));
@@ -776,9 +854,9 @@
             throw new CoolException("褰撳墠宸ヤ綔鐘舵�佹棤娉曡繘琛屾搷浣�");
         }
         // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
-        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
-            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
-        }
+//        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
+//            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
+//        }
         // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
         if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
             throw new CoolException("淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
@@ -816,4 +894,109 @@
         }
     }
 
+    @Override
+    public StartupDto createWaitPainWrkMastStart(List<WaitPakin> list, Long userId) {
+        if (Cools.isEmpty(list)) {
+            throw new CoolException("鍏ュ簱閫氱煡妗d笉鑳戒负绌�");
+        }
+        LocTypeDto locTypeDto = new LocTypeDto();
+        locTypeDto.setLocType1((short) 1);
+        return wcsController.startupFullPutStore(301, list.get(0).getZpallet(), locTypeDto, list);
+    }
+
+    @Override
+    @Transactional
+    public String dealPreHaveStart(Integer wrkNo, Long userId) {
+        WrkMast wrkMast = wrkMastService.selectById(wrkNo);
+        if (wrkMast == null) {
+            throw new CoolException("浠诲姟宸插け鏁�");
+        }
+        String locNo = wrkMast.getLocNo();
+        LocMast locMast = locMastService.selectById(locNo);
+        assert locMast != null;
+        RowLastno rowLastno = rowLastnoService.findBySection(locMast.getRow1());
+        assert rowLastno != null;
+
+        // 鐩爣搴撲綅
+        LocMast targetLoc = null;
+
+        for (int curRow = rowLastno.getsRow(); curRow<=rowLastno.geteRow(); curRow++) {
+
+            if (Utils.isShallowLoc(slaveProperties, curRow)) {
+                Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
+                targetLoc = locMastService.queryFreeLocMast(deepRow, locMast.getLocType1());
+                // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
+                if (!locMastService.checkEmptyCount(targetLoc)) {
+                    continue;
+                }
+            }
+            if (Cools.isEmpty(targetLoc)) {
+                targetLoc = locMastService.queryFreeLocMast(curRow, locMast.getLocType1());
+                // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
+                if (!locMastService.checkEmptyCount(targetLoc)) {
+                    continue;
+                }
+                // 鐩爣搴撲綅 ===>> 娴呭簱浣嶏紝 鍒欐牎楠屽叾娣卞簱浣嶆槸鍚︿负 F D X
+                if (null != targetLoc && Utils.isShallowLoc(slaveProperties, targetLoc.getLocNo())) {
+                    LocMast deepLoc = locMastService.selectById(Utils.getDeepLoc(slaveProperties, targetLoc.getLocNo()));
+                    if (!deepLoc.getLocSts().equals("F") && !deepLoc.getLocSts().equals("D") && !deepLoc.getLocSts().equals("X")) {
+                        continue;
+                    }
+                }
+                // 鐩爣搴撲綅 ===>> 娣卞簱浣嶏紝 鍒欐牎楠屽叾娴呭簱浣嶆槸鍚︿负 O
+                if (null != targetLoc && Utils.isDeepLoc(slaveProperties, targetLoc.getLocNo())) {
+                    LocMast shallowLoc = locMastService.selectById(Utils.getShallowLoc(slaveProperties, targetLoc.getLocNo()));
+                    if (!shallowLoc.getLocSts().equals("O")) {
+                        continue;
+                    }
+                }
+            }
+
+            if (!Cools.isEmpty(targetLoc)) {
+                break;
+            }
+
+        }
+
+        if (targetLoc == null) {
+            throw new CoolException("鎿嶄綔澶辫触锛屽綋鍓嶄粨搴撴壘涓嶅埌绌哄簱浣�");
+        }
+
+        Date now = new Date();
+        // 淇敼宸ヤ綔妗�
+        StaDesc staDesc = staDescService.queryCrnStn(targetLoc.getCrnNo());
+        if (Cools.isEmpty(staDesc)) {
+            throw new CoolException("鍏ュ簱璺緞涓嶅瓨鍦�");
+        }
+        wrkMast.setWrkSts(2L);
+        wrkMast.setLocNo(targetLoc.getLocNo());
+        wrkMast.setStaNo(staDesc.getCrnStn());
+        wrkMast.setCrnNo(targetLoc.getCrnNo());
+        wrkMast.setModiTime(now);
+        wrkMast.setModiUser(userId);
+        wrkMast.setPreHave("N");
+        if (!wrkMastService.updateById(wrkMast)) {
+            throw new CoolException("淇敼宸ヤ綔妗eけ璐�");
+        }
+        // 淇敼搴撲綅鐘舵�� O ===>>> S
+        if (targetLoc.getLocSts().equals("O")){
+            targetLoc.setLocSts("S"); // S.鍏ュ簱棰勭害
+            targetLoc.setModiUser(userId);
+            targetLoc.setModiTime(now);
+            if (!locMastService.updateById(targetLoc)){
+                throw new CoolException("鏀瑰彉搴撲綅鐘舵�佸け璐�");
+            }
+        } else {
+            throw new CoolException(targetLoc.getLocNo()+"鐩爣搴撲綅宸茶鍗犵敤");
+        }
+        // 绂佺敤寮傚父搴撲綅
+//        locMast.setLocSts("X"); // X.绂佺敤
+//        locMast.setModiUser(userId);
+//        locMast.setModiTime(now);
+//        if (!locMastService.updateById(locMast)){
+//            throw new CoolException("鏀瑰彉搴撲綅鐘舵�佸け璐�");
+//        }
+        return targetLoc.getLocNo();
+    }
+
 }

--
Gitblit v1.9.1