From 040c966720e66bfa400181bb26d46ca59ac44e6c Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期二, 16 八月 2022 16:07:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/service/CommonService.java |  113 ++++++++++++++++++++++----------------------------------
 1 files changed, 44 insertions(+), 69 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index d1d6a72..0989bf9 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -10,12 +10,14 @@
 import com.zy.asrs.utils.Utils;
 import com.zy.asrs.utils.VersionUtils;
 import com.zy.common.model.LocTypeDto;
+import com.zy.common.model.Shelves;
 import com.zy.common.model.StartupDto;
 import com.zy.common.properties.SlaveProperties;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -25,6 +27,15 @@
 @Slf4j
 @Service
 public class CommonService {
+
+    public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
+        add(11);add(12);add(13);add(14);add(15);add(16);add(17);
+    }};
+    public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{
+        add(18);add(19);add(20);
+        add(21);add(22);add(23);add(24);add(25);add(26);add(27);add(28);add(29);add(30);
+    }};
 
     @Autowired
     private WrkMastService wrkMastService;
@@ -102,11 +113,7 @@
      */
     public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, LocTypeDto oldLocType, int times) {
         StartupDto startupDto = new StartupDto();
-        if (sourceStaNo == 100) { // 杞昏揣淇″彿
-            whsType = 1;    // 1 - 11 宸�
-        } else if (sourceStaNo == 200) { // 閲嶈揣淇″彿
-            whsType = 2;    // 12 - 21 鍙�
-        }
+        whsType = 1;
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = getWorkNo(0);
         RowLastno rowLastno = rowLastnoService.selectById(whsType);
@@ -165,62 +172,16 @@
 
         // 濡傛灉娌℃湁鐩歌繎鐗╂枡锛屽垯鎸夎鍒欒疆璇㈣揣鏋�
         if (null == locMast) {
-            int t = 0;
-            boolean execute = true;
-            int crnNo1;
-            // 1 - 11鎺�
-            if (whsType == 1) {
-                while (execute && t < 4) {
-                    t++;
-                    switch (curRow) {
-                        case 3:
-                            curRow = 11;
-                            crnNo1 = 2;
-                            break;
-                        case 11:
-                            curRow = 4;
-                            crnNo1 = 1;
-                            break;
-                        case 4:
-                            curRow = 12;
-                            crnNo1 = 2;
-                            break;
-                        default:
-                            curRow = 3;
-                            crnNo1 = 1;
-                            break;
-                    }
-                    if (basCrnpService.checkSiteError(crnNo1, true)) {
-                        crnNo = crnNo1;
-                        execute = false;
-                    }
+            Shelves shelves = new Shelves(rowCount, crn_qty);
+            for (int i = 0; i < shelves.group; i ++) {
+                curRow = shelves.start(curRow);
+                if (curRow < 0) {
+                    throw new CoolException("妫�绱㈠簱浣嶅け璐ワ紝璇疯仈绯荤鐞嗗憳");
                 }
-                // 12 - 21鎺�
-            } else {
-                while (execute && t < 4) {
-                    t++;
-                    switch (curRow) {
-                        case 11:
-                            curRow = 18;
-                            crnNo1 = 3;
-                            break;
-                        case 18:
-                            curRow = 12;
-                            crnNo1 = 2;
-                            break;
-                        case 12:
-                            curRow = 19;
-                            crnNo1 = 3;
-                            break;
-                        default:
-                            curRow = 11;
-                            crnNo1 = 2;
-                            break;
-                    }
-                    if (basCrnpService.checkSiteError(crnNo1, true)) {
-                        crnNo = crnNo1;
-                        execute = false;
-                    }
+                Integer crnNo1 = shelves.get(curRow);
+                if (basCrnpService.checkSiteError(crnNo1, true)) {
+                    crnNo = crnNo1;
+                    break;
                 }
             }
         }
@@ -253,11 +214,23 @@
 
         // 1.褰撴绱㈠簱鎺掍负娴呭簱浣嶆帓鏃讹紝浼樺厛瀵绘壘褰撳墠搴撴帓鐨勬繁搴撲綅鎺�
         if (locMast == null) {
-            locMast = locMastService.queryFreeLocMast(curRow, locTypeDto.getLocType1());
-            // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
-            if (!locMastService.checkEmptyCount(locMast)) {
-                locMast = null;
+            List<Integer> rows;
+            switch (curRow) {
+                case 1:
+                    rows = FIRST_GROUP_ROW_LIST;
+                    break;
+                case 2:
+                    rows = SECOND_GROUP_ROW_LIST;
+                    break;
+                default:
+                    throw new CoolException("鍏ュ簱閫昏緫鏁呴殰銆�" + curRow + "銆�");
             }
+
+            locMast = locMastService.queryFreeLocMast(curRow, rows, locTypeDto.getLocType1());
+            // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
+//            if (!locMastService.checkEmptyCount(locMast)) {
+//                locMast = null;
+//            }
         }
 
         // 2.搴撲綅褰撳墠鎵�灞炲昂瀵告棤绌哄簱浣嶆椂锛岃皟鏁村昂瀵稿弬鏁帮紝鍚戜笂鍏煎妫�绱㈠簱浣�
@@ -266,12 +239,14 @@
             if (times < rowCount) {
                 times = times + 1;
                 return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
+            } else {
+                times = 0;
             }
-//            // 璐х墿妫�绱綆搴撲綅浠撳け璐ワ紝鍏煎楂樺簱浣嶄粨鍚庣户缁墽琛�
-//            if (locTypeDto.getLocType1() == 1) {
-//                locTypeDto.setLocType1((short) 2);
-//                return getLocNo(1, staDescId, sourceStaNo, emptyMk, matNos, locTypeDto, oldLocType, times);
-//            }
+            // 璐х墿妫�绱綆搴撲綅浠撳け璐ワ紝鍏煎楂樺簱浣嶄粨鍚庣户缁墽琛�
+            if (locTypeDto.getLocType1() == 1) {
+                locTypeDto.setLocType1((short) 2);
+                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
+            }
             log.error("绯荤粺娌℃湁绌哄簱浣嶏紒锛侊紒 灏哄瑙勬牸锛� {}锛� 杞娆℃暟锛歿}", JSON.toJSONString(locTypeDto), times);
             throw new CoolException("娌℃湁绌哄簱浣�");
         }

--
Gitblit v1.9.1