From c4d9e1eb799a4da88cd4d7ba6053556415f8d8f8 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期一, 06 二月 2023 11:04:03 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/service/CommonService.java |  164 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 118 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 81787fd..d9a2a71 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -210,8 +210,29 @@
             }
         }
 
-        // 濡傛灉娌℃湁鐩歌繎鐗╂枡锛屽垯鎸夎鍒欒疆璇㈣揣鏋�
+        // 搴撳尯閿佸畾
+        LocRule locRule = locRuleService.find(Cools.isEmpty(matNos) ? null : matNos.get(0), null, start, end);
+        if (!Cools.isEmpty(locRule)) {
+            List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1()
+                    , locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd());
+            for (LocMast one : locMasts) {
+                List<String> groupLoc = Utils.getGroupLoc(one.getLocNo());
+                LocMast locMast0 = locMastService.findOutMost(groupLoc);
+                if (null != locMast0) {
+                    // 娴呭簱浣嶇鍚堝昂瀵告娴�
+                    if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
+                        // 娴呭簱浣嶅搴斿爢鍨涙満蹇呴』鍙敤涓旀棤寮傚父
+                        if (basCrnpService.checkSiteError(locMast0.getCrnNo(), true)) {
+                            crnNo = locMast0.getCrnNo();
+                            locMast = locMast0;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
 
+        // 濡傛灉娌℃湁鐩歌繎鐗╂枡锛屽垯鎸夎鍒欒疆璇㈣揣鏋�
         int currentRow = 1;
         if (null == locMast) {
             Shelves shelves = new Shelves(rowCount, crn_qty);
@@ -312,41 +333,18 @@
 
         // 1.褰撴绱㈠簱鎺掍负娴呭簱浣嶆帓鏃讹紝浼樺厛瀵绘壘褰撳墠搴撴帓鐨勬繁搴撲綅鎺�
         if (locMast == null) {
-
-            // 搴撳尯閿佸畾
-            LocRule locRule = locRuleService.find(Cools.isEmpty(matNos) ? null : matNos.get(0), null);
-            if (!Cools.isEmpty(locRule)) {
-                List<Integer> rows = Utils.getGroupLoc(locRule.getRowBeg());
-                List<LocMast> locMasts = locMastService.queryFreeLocMast1(rows, rows.size(), locTypeDto.getLocType1(), inoutEveryday
-                        , locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd());
-                if (!Cools.isEmpty(locMasts)) {
-                    Integer innermostRow = Utils.getInnermostRow(locMasts.get(0).getLocNo());
-                    for (LocMast one : locMasts) {
-                        if (one.getRow1().equals(innermostRow)) {
-                            locMast = one;
-                            break;
-                        }
+            List<Integer> rows = Utils.getGroupLoc(curRow);
+            List<LocMast> locMasts = locMastService.queryFreeLocMast0(rows, rows.size(), locTypeDto.getLocType1(), inoutEveryday);
+            if (!Cools.isEmpty(locMasts)) {
+                Integer innermostRow = Utils.getInnermostRow(locMasts.get(0).getLocNo());
+                for (LocMast one : locMasts) {
+                    if (one.getRow1().equals(innermostRow)) {
+                        locMast = one;
+                        break;
                     }
                 }
             }
 
-            if (locMast == null) {
-                List<Integer> rows = Utils.getGroupLoc(curRow);
-                List<LocMast> locMasts = locMastService.queryFreeLocMast0(rows, rows.size(), locTypeDto.getLocType1(), inoutEveryday);
-                if (!Cools.isEmpty(locMasts)) {
-                    Integer innermostRow = Utils.getInnermostRow(locMasts.get(0).getLocNo());
-                    for (LocMast one : locMasts) {
-                        if (one.getRow1().equals(innermostRow)) {
-                            locMast = one;
-                            break;
-                        }
-                    }
-                }
-            }
-//            LocMast locMast0 = locMastService.findOutMost(locMasts.stream().map(LocMast::getLocNo).distinct().collect(Collectors.toList()));
-//            if (!Cools.isEmpty(locMast0)) {
-//                locMast = locMast0;
-//            }
             // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣� todo:luxiaotao
 //            if (!locMastService.checkEmptyCount(locMast)) {
 //                locMast = null;
@@ -354,26 +352,76 @@
         }
 
         // 2.鏃犲簱浣嶆椂锛屾棤瑙嗗尯鍩熼攣瀹氾紝閲嶆柊鏌ユ壘搴撲綅
-        if (Cools.isEmpty(locMast)){
-            List<LocMast> locMasts = locMastService.queryFreeLocMastEnd(curRow);
-            for (LocMast locMast1 : locMasts){
-                List<LocMast> locMasts1 = locMastService.queryFreeLocMastEnd0(locMast1.getBay1(), locMast1.getLev1(),locMast1.getRow1());
-                Integer innermostRow = Utils.getInnermostRow(locMasts1.get(0).getLocNo());
-                for (LocMast locMast2:locMasts1){
-                    if (locMast2.getLocSts().equals("O")){
-                        if (locMast2.getRow1().equals(innermostRow)) {
-                            locMast = locMast2;
-                            break;
+        if (Cools.isEmpty(locMast)) {
+            int sign = curRow;
+            while (sign != 0 && Cools.isEmpty(locMast)) {
+                List<LocMast> locMasts = locMastService.queryFreeLocMastEnd(sign, locTypeDto.getLocType1());
+                for (LocMast loc : locMasts) {
+                    // 鍚屽簱浣嶇粍瀵瑰簲鍏堕挶搴撲綅鏄惁涓� O.绌哄簱浣�
+                    boolean success = true;
+                    // 娴呭簱浣�
+                    List<String> outerLocList = Utils.getGroupOuterLoc(loc.getLocNo());
+                    for (String outerLocNo : outerLocList) {
+                        LocMast outerLoc = locMastService.selectById(outerLocNo);
+                        if (Cools.isEmpty(outerLoc)) {
+                            continue;
                         }
-                    }else if (!locMast2.getLocSts().equals("F")){
+                        if (!outerLoc.getLocSts().equals("O")) {
+                            success = false; break;
+                        }
+                    }
+                    // 娣卞簱浣�
+                    List<String> insideLocList = Utils.getGroupInsideLoc(loc.getLocNo());
+                    for (String insideLocNo : insideLocList) {
+                        LocMast insideLoc = locMastService.selectById(insideLocNo);
+                        if (Cools.isEmpty(insideLoc)) {
+                            continue;
+                        }
+                        if (insideLoc.getLocSts().equals("R") || insideLoc.getLocSts().equals("P")) {
+                            success = false; break;
+                        }
+                    }
+                    if (success) {
+                        locMast = loc;
                         break;
                     }
                 }
-                if (!Cools.isEmpty(locMast)){
-                    break;
-                }
+                sign = getCurRow(sign);
             }
         }
+
+
+//        if (Cools.isEmpty(locMast)){
+//            List<LocMast> locMasts = locMastService.queryFreeLocMastEnd(curRow, locTypeDto.getLocType1());
+//            int sign=curRow;
+//            while (true){
+//                if (locMasts.size()==0){
+//                    sign = getCurRow(sign);
+//                    if (sign != 0){
+//                        locMasts = locMastService.queryFreeLocMastEnd(sign, locTypeDto.getLocType1());
+//                    }else {
+//                        break;
+//                    }
+//                }else {
+//                    break;
+//                }
+//            }
+//            for (LocMast locMast1 : locMasts){
+//                List<LocMast> locMasts1 = locMastService.queryFreeLocMastEnd0(locMast1.getBay1(), locMast1.getLev1(),locMast1.getRow1(), locTypeDto.getLocType1());
+//                Integer innermostRow = Utils.getInnermostRow(locMasts1.get(0).getLocNo());
+//                for (LocMast locMast2:locMasts1){
+//                    if (locMast2.getLocSts().equals("O")){
+//                        locMast = locMast2;
+//                        break;
+//                    }else if (!locMast2.getLocSts().equals("F")){
+//                        break;
+//                    }
+//                }
+//                if (!Cools.isEmpty(locMast)){
+//                    break;
+//                }
+//            }
+//        }
 
         // 3.搴撲綅褰撳墠鎵�灞炲昂瀵告棤绌哄簱浣嶆椂锛岃皟鏁村昂瀵稿弬鏁帮紝鍚戜笂鍏煎妫�绱㈠簱浣�
         if (Cools.isEmpty(locMast)) {
@@ -417,4 +465,28 @@
         }
     }
 
+    public int getCurRow(int curRow){
+        switch (curRow){
+            case 1:
+            case 2:
+            case 8:
+            case 9:
+            case 10:
+            case 15:
+            case 16:
+            case 17:
+                return curRow+1;
+            case 5:
+            case 6:
+            case 7:
+            case 13:
+            case 14:
+            case 20:
+            case 21:
+                return curRow-1;
+            default:
+                return 0;
+        }
+    }
+
 }

--
Gitblit v1.9.1