From 6efbf154b3ed88d376763b9d9807256c7bd5eaeb Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期一, 09 三月 2026 20:23:38 +0800
Subject: [PATCH] no message

---
 src/main/java/com/zy/common/service/CommonService.java |  268 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 205 insertions(+), 63 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 73a65f0..425e95a 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -122,40 +122,112 @@
     public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, Integer whsType, FindLocNoAttributeVo findLocNoAttributeVo,
                                LocTypeDto locTypeDto) {
         try {
-//            Integer whsType = Utils.GetWhsType(sourceStaNo);
-//            RowLastno rowLastno = rowLastnoService.selectById(whsType);
-//            RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
-            /**
-             * 搴撳瀷 1: 鏍囧噯鍫嗗灈鏈哄簱 2: 骞冲簱 3: 绌挎鏉� 4: 鍥涘悜杞� 5: AGV 0: 鏈煡
-             */
-            return getLocNoRun(staDescId, whsType,  sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0);
-
-            // switch (rowLastnoType.getType()) {
-            // case 1:
-            // return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0,
-            // locTypeDto, 0);
-            //// case 2:
-            //// log.error("绔欑偣={} 鏈煡璇㈠埌瀵瑰簲鐨勮鍒�", sourceStaNo);
-            //// break;
-            //// case 3:
-            //// log.error("绔欑偣={} 鏈煡璇㈠埌瀵瑰簲鐨勮鍒�", sourceStaNo);
-            //// break;
-            //// case 4:
-            //// return getLocNoRun4(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
-            // 4, locTypeDto, 0);
-            //// case 5:
-            //// return getLocNoRun5(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
-            // 0, locTypeDto, 0);
-            //// default:
-            //// log.error("绔欑偣={} 鏈煡璇㈠埌瀵瑰簲鐨勮鍒�", sourceStaNo);
-            //// break;
-            // }
-
+            RowLastno rowLastno = rowLastnoService.selectById(whsType);
+            RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
+//            /**
+//             * 搴撳瀷 1: 鏍囧噯鍫嗗灈鏈哄簱 2: 骞冲簱 3: 绌挎鏉� 4: 鍥涘悜杞� 5: AGV 0: 鏈煡
+//             */
+//            if (rowLastnoType.getType() == 3) {
+//                return getDoubleLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
+//                        4, locTypeDto, 0);
+//            } else {
+//
+//            }
+            return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0);
         } catch (Exception e) {
             log.error("绔欑偣={} 鏈煡璇㈠埌瀵瑰簲鐨勮鍒�", sourceStaNo);
         }
         return null;
     }
+
+    /**
+     * 妫�绱㈠簱浣嶅彿
+     *
+     * @param whsType              绫诲瀷 1:鍗曚几寮忚揣鏋�
+     * @param staDescId            璺緞ID
+     * @param sourceStaNo          婧愮珯
+     * @param findLocNoAttributeVo 灞炴��
+     * @param moveCrnNo            婧�
+     * @param locTypeDto           绫诲瀷
+     * @param times                杞娆℃暟
+     * @return locNo 妫�绱㈠埌鐨勫簱浣嶅彿
+     */
+    @Transactional
+    public StartupDto getLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo,
+                                  FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
+        staDescId = 1;
+        // 鍒濆鍖栧弬鏁�
+        int crnNo = 0; // 鍫嗗灈鏈哄彿
+        int nearRow = 0; // 鏈�娴呭簱浣嶆帓
+        LocMast locMast = null; // 鐩爣搴撲綅
+
+        RowLastno rowLastno = rowLastnoService.selectById(whsType);
+        if (Cools.isEmpty(rowLastno)) {
+            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�===>搴撲綅瑙勫垯鏈煡");
+        }
+
+        int minCount = Integer.MAX_VALUE;
+        if (whsType == 2) {
+            if (locTypeDto.getLocType1() == 2) {
+                // 鍧囪 鍒嗗竷鍫嗗灈鏈�
+                for (int i = 4; i <= 5; i++) {
+                    int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
+                    if (count < minCount) {
+                        minCount = count;
+                        crnNo = i;
+                    }
+                }
+            } else {
+                for (int i = 4; i <= 6; i++) {
+                    int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
+                    if (count < minCount) {
+                        minCount = count;
+                        crnNo = 6;
+                    }
+                }
+
+                if (crnNo == 6) {
+                    return getDoubleLocNoRun(3, 1, sourceStaNo, findLocNoAttributeVo, null, locTypeDto, times);
+                }
+            }
+        } else {
+            // 鍧囪 鍒嗗竷鍫嗗灈鏈�
+            for (int i = rowLastno.getsCrnNo(); i <= rowLastno.geteCrnNo(); i++) {
+                int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
+                if (count < minCount) {
+                    minCount = count;
+                    crnNo = i;
+                }
+            }
+        }
+
+        StartupDto startupDto = new StartupDto();
+        locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                .ge("row1", rowLastno.getsRow())
+                .le("row1", rowLastno.geteRow())
+                .eq("crn_no", crnNo)
+                .eq("loc_type1", locTypeDto.getLocType1())
+                .eq("loc_sts", "O")
+                .orderAsc(Arrays.asList("lev1", "row1", "bay1")));
+        // int crnCountO = wrkMastService.selectCount(new
+        // EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100));
+        // 鐢熸垚宸ヤ綔鍙�
+        int workNo;
+        if (whsType == 2) {
+            // 鐢熸垚宸ヤ綔鍙�
+            workNo = getWorkNo(3);
+        } else {
+            // 鐢熸垚宸ヤ綔鍙�
+            workNo = getWorkNo(0);
+        }
+        // 杩斿洖dto
+        startupDto.setWorkNo(workNo);
+        startupDto.setCrnNo(locMast.getCrnNo());
+        startupDto.setSourceStaNo(sourceStaNo);
+        startupDto.setLocNo(locMast.getLocNo());
+        return startupDto;
+    }
+
 
     /**
      * 妫�绱㈠簱浣嶅彿
@@ -169,51 +241,121 @@
      * @param times                杞娆℃暟
      * @return locNo 妫�绱㈠埌鐨勫簱浣嶅彿
      */
-    @Transactional
-    public StartupDto getLocNoRun( Integer staDescId, Integer whsType, Integer sourceStaNo,
-            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
-        staDescId = 1;
-        // 鍒濆鍖栧弬鏁�
-        int crnNo = 0; // 鍫嗗灈鏈哄彿
-        int nearRow = 0; // 鏈�娴呭簱浣嶆帓
-        LocMast locMast = null; // 鐩爣搴撲綅
+    public StartupDto getDoubleLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
+        // 1. 鍒濆鍖栧弬鏁�
+        int crnNo = 6;      // 鍫嗗灈鏈哄彿
+        int deepRow, shallowRow;
+        int rowCount = 2;   // 杞涓ょ粍璐ф灦 (11/12 瀵� 鍜� 14/13 瀵�)
 
+        // 鏍规嵁杞娆℃暟鍒囨崲鎺掞紝涓ユ牸淇濊瘉娣变綅浼樺厛
+        if (times % 2 == 0) {
+            deepRow = 11;
+            shallowRow = 12;
+        } else {
+            deepRow = 14;
+            shallowRow = 13;
+        }
+
+        StartupDto startupDto = new StartupDto();
         RowLastno rowLastno = rowLastnoService.selectById(whsType);
         if (Cools.isEmpty(rowLastno)) {
             throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�===>搴撲綅瑙勫垯鏈煡");
         }
+        RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
+        if (Cools.isEmpty(rowLastnoType)) {
+            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�===銆嬪簱浣嶈鍒欑被鍨嬫湭鐭�");
+        }
 
-        // 鍧囪 鍒嗗竷鍫嗗灈鏈�
-        int minCount = Integer.MAX_VALUE;
-        for (int i = rowLastno.getsCrnNo(); i <= rowLastno.geteCrnNo(); i++) {
-            int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
-            if (count < minCount) {
-                minCount = count;
-                crnNo = i;
+        LocMast locMast = null;
+
+        // 2. 寮�濮嬫绱� (浼樺厛绾э細娣变綅鍫嗗彔 > 娣变綅绌轰綅 > 娴呬綅绌轰綅)
+
+        // A. 浼樺厛灏濊瘯锛氭繁浣嶄负绌猴紝涓斿叾瀵瑰簲鐨勬祬浣嶅凡缁忓瓨鏀句簡鐩稿悓鐗╂枡 (瀹炵幇 signRule1 鐨勬牳蹇冮�昏緫)
+        if (Utils.BooleanWhsTypeStaIoType(rowLastno) && !Cools.isEmpty(findLocNoAttributeVo.getMatnr())) {
+            List<LocMast> shallowMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                    .eq("row1", shallowRow)
+                    .eq("loc_sts", "F")
+                    .eq("crn_no", crnNo));
+
+            for (LocMast sLoc : shallowMasts) {
+                LocDetl detl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", sLoc.getLocNo()));
+                if (detl != null && detl.getMatnr().equals(findLocNoAttributeVo.getMatnr())
+                        && detl.getBatch().equals(findLocNoAttributeVo.getBatch())) {
+
+                    String dLocNo = Utils.getDeepLoc(slaveProperties, sLoc.getLocNo());
+                    LocMast dLoc = locMastService.selectOne(new EntityWrapper<LocMast>()
+                            .eq("loc_no", dLocNo)
+                            .eq("loc_sts", "O"));
+
+                    if (dLoc != null && VersionUtils.locMoveCheckLocTypeComplete(dLoc, locTypeDto)) {
+                        locMast = dLoc;
+                        break;
+                    }
+                }
             }
         }
-        StartupDto startupDto = new StartupDto();
-        locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
-                .ge("row1", rowLastno.getsRow())
-                .le("row1", rowLastno.geteRow())
-                .eq("crn_no", crnNo)
-                .eq("loc_sts", "O")
-                .orderAsc(Arrays.asList("lev1", "row1", "bay1")));
-        // int crnCountO = wrkMastService.selectCount(new
-        // EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100));
 
-        // 鐢熸垚宸ヤ綔鍙�
+        // B. 娆′紭鍏堬細娣变綅涓虹┖锛屼笖娴呬綅涔熶负绌� (鍏ユ繁浣�)
+        if (locMast == null) {
+            List<LocMast> deepMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                    .eq("row1", deepRow)
+                    .eq("loc_sts", "O")
+                    .eq("crn_no", crnNo)
+                    .orderBy("lev1", true).orderBy("bay1", true));
+
+            for (LocMast dLoc : deepMasts) {
+                String sLocNo = Utils.getShallowLoc(slaveProperties, dLoc.getLocNo());
+                LocMast sLoc = locMastService.selectOne(new EntityWrapper<LocMast>()
+                        .eq("loc_no", sLocNo)
+                        .eq("loc_sts", "O"));
+
+                if (sLoc != null && VersionUtils.locMoveCheckLocTypeComplete(dLoc, locTypeDto)) {
+                    locMast = dLoc;
+                    break;
+                }
+            }
+        }
+
+        // C. 鏈�鍚庯細濡傛灉娣变綅瀹炲湪娌℃硶鏀撅紙娣变綅宸叉弧鎴栨祬浣嶆尅璺笖鐗╂枡涓嶅悓锛夛紝鍐嶈�冭檻娴呬綅涓虹┖
+        if (locMast == null) {
+            List<LocMast> shallowMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                    .eq("row1", shallowRow)
+                    .eq("loc_sts", "O")
+                    .eq("crn_no", crnNo)
+                    .orderBy("lev1", true).orderBy("bay1", true));
+
+            for (LocMast sLoc : shallowMasts) {
+                if (VersionUtils.locMoveCheckLocTypeComplete(sLoc, locTypeDto)) {
+                    locMast = sLoc;
+                    break;
+                }
+            }
+        }
+
+        // 3. 閫掑綊涓庡紓甯稿鐞�
+        if (Cools.isEmpty(locMast)) {
+            // 褰撳墠杩欑粍璐ф灦鎵惧畬浜嗭紝閫掑綊灏濊瘯涓嬩竴缁�
+            if (times < rowCount * 2) {
+                return getDoubleLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times + 1);
+            }
+            log.error("绯荤粺娌℃湁绌哄簱浣嶏紒锛侊紒 灏哄瑙勬牸锛� {}锛� 杞娆℃暟锛歿}", JSON.toJSONString(locTypeDto), times);
+            throw new CoolException("娌℃湁绌哄簱浣�");
+        }
+
+        // 4. 杩斿洖缁撴灉
+        String locNo = locMast.getLocNo();
         int workNo = getWorkNo(0);
-        // 杩斿洖dto
         startupDto.setWorkNo(workNo);
-        startupDto.setCrnNo(locMast.getCrnNo());
+        startupDto.setCrnNo(crnNo);
         startupDto.setSourceStaNo(sourceStaNo);
-        startupDto.setLocNo(locMast.getLocNo());
+        startupDto.setLocNo(locNo);
+
         return startupDto;
     }
 
+
     public StartupDto getLocNoRun4(Integer whsType, Integer staDescId, Integer sourceStaNo,
-            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
+                                   FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
 
         // 鍒濆鍖栧弬鏁�
         int crnNo = 0; // 鍫嗗灈鏈哄彿
@@ -306,7 +448,7 @@
                     if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                             && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                             && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
-                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
+                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                         int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                         curRowW = locNecessaryParameters[1];
                         nearRowW = locNecessaryParameters[3];
@@ -379,7 +521,7 @@
                     if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                             && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                             && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
-                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
+                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                         int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                         curRowW = locNecessaryParameters[1];
                         nearRowW = locNecessaryParameters[3];
@@ -478,7 +620,7 @@
                     if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                             && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                             && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
-                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
+                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                         int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                         curRowW = locNecessaryParameters[1];
                         nearRowW = locNecessaryParameters[3];
@@ -559,7 +701,7 @@
                     if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                             && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                             && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
-                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
+                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                         int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                         curRowW = locNecessaryParameters[1];
                         nearRowW = locNecessaryParameters[3];
@@ -704,7 +846,7 @@
     }
 
     public StartupDto getLocNoRun5(Integer whsType, Integer staDescId, Integer sourceStaNo,
-            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
+                                   FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
 
         // 鍒濆鍖栧弬鏁�
         int crnNo = 0; // 鍫嗗灈鏈哄彿

--
Gitblit v1.9.1