From 29cfbeea17c6d124a00864d1e8f0f79983059530 Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期一, 09 三月 2026 15:27:39 +0800
Subject: [PATCH] 下发任务工位调整

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |   87 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 4c90ae8..3a910f6 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -920,62 +920,70 @@
                     // 鍫嗗灈鏈哄伐浣�1鏈夌墿鏂�
                     WrkMast wrkMast = wrkMastMapper.selectByPltType(crn.getId(), 1);
                     if (wrkMast != null) {
-                        //鍏堝垽鏂槸鍑哄簱杩樻槸鍏ュ簱
-                        //鍐嶅垽鏂槸杩樻湁娌℃湁鍚岀被鍨嬬殑宸ヤ綔妗�
+                        // determine outbound or inbound
+                        // check whether same-type work remains
                         if (wrkMast.getIoType() >= 100) {
                             WrkMast wrkMast1 = wrkMastMapper.selectPakOutStep1(crn.getId(), wrkMast.getSourceStaNo());
                             if (wrkMast1 != null) {
-                                if (Integer.parseInt(wrkMast1.getSourceLocNo().substring(3,5)) == 1 || (staProtocol.isAutoing() && staProtocol.isLoading())){
+                                if (shouldPrioritizePut(crn.getId(), wrkMast1.getSourceLocNo(), 1) || (staProtocol.isAutoing() && staProtocol.isLoading())){
                                     this.outPut(crn, crnProtocol, mark);
                                     //continue;
                                 }else {
-                                    this.outTake(crn, crnProtocol, 2, mark);
+                                    this.outTake(crn, crnProtocol, 0, mark);
                                 }
-                                //this.outTake(crn, crnProtocol, 2, mark);
+                                //this.outTake(crn, crnProtocol, 0, mark);
                             } else {
                                 this.outPut(crn, crnProtocol, mark);
                             }
                         } else {
                             WrkMast wrkMast1 = wrkMastMapper.selectPakInStep1All(wrkMast.getSourceStaNo(), crn.getId());
                             if (wrkMast1 != null) {
-                                this.inTake(crn, crnProtocol, 2, mark);
+                                if (shouldPrioritizePut(crn.getId(), wrkMast1.getLocNo(), 1)) {
+                                    this.inPut(crn, crnProtocol, mark);
+                                } else {
+                                    this.inTake(crn, crnProtocol, 0, mark);
+                                }
                             } else {
                                 this.inPut(crn, crnProtocol, mark);
                             }
                         }
                     } else {
-                        log.error("" + mark + " - 1" + " - 鏈夌墿鏂欐棤宸ヤ綔妗�  ===銆嬪紓甯�");
+                        log.error("" + mark + " - 1" + " - loaded station without work record");
                     }
                 } else if (crnProtocol.getLoaded() == 0 && crnProtocol.getLoadedTwo() == 1) {
-                    //News.error("宸ヤ綅1鏃犵墿锛屽伐浣�2鏈夌墿");
-                    // 鍫嗗灈鏈哄伐浣�2鏈夌墿鏂�
+                    //News.error("station 1 empty, station 2 loaded");
+                    // stacker station 2 has load
                     WrkMast wrkMast = wrkMastMapper.selectByPltType(crn.getId(), 2);
                     if (wrkMast != null) {
-                        //鍏堝垽鏂槸鍑哄簱杩樻槸鍏ュ簱
-                        //鍐嶅垽鏂槸杩樻湁娌℃湁鍚岀被鍨嬬殑宸ヤ綔妗�
+                        // determine outbound or inbound
+                        // check whether same-type work remains
                         if (wrkMast.getIoType() >= 100) {
                             WrkMast wrkMast1 = wrkMastMapper.selectPakOutStep1(crn.getId(), wrkMast.getSourceStaNo());
                             if (wrkMast1 != null) {
-                                if (Integer.parseInt(wrkMast1.getSourceLocNo().substring(3,5)) == 29 || (staProtocol.isAutoing() && staProtocol.isLoading())){
+                                if (shouldPrioritizePut(crn.getId(), wrkMast1.getSourceLocNo(), 2) || (staProtocol.isAutoing() && staProtocol.isLoading())){
                                     this.outPut(crn, crnProtocol, mark);
                                     //continue;
                                 }else {
-                                    this.outTake(crn, crnProtocol, 1, mark);
+                                    this.outTake(crn, crnProtocol, 0, mark);
                                 }
-                                //this.outTake(crn, crnProtocol, 1, mark);
+                                //this.outTake(crn, crnProtocol, 0, mark);
                             } else {
                                 this.outPut(crn, crnProtocol, mark);
                             }
                         } else {
                             WrkMast wrkMast1 = wrkMastMapper.selectPakInStep1All(wrkMast.getSourceStaNo(), crn.getId());
                             if (wrkMast1 != null) {
-                                this.inTake(crn, crnProtocol, 1, mark);
+                                if (shouldPrioritizePut(crn.getId(), wrkMast1.getLocNo(), 2)) {
+                                    this.inPut(crn, crnProtocol, mark);
+                                } else {
+                                    this.inTake(crn, crnProtocol, 0, mark);
+                                }
                             } else {
                                 this.inPut(crn, crnProtocol, mark);
                             }
                         }
                     } else {
-                        log.error("" + mark + " - 1" + " - 鏈夌墿鏂欐棤宸ヤ綔妗�  ===銆嬪紓甯�");
+                        log.error("" + mark + " - 1" + " - loaded station without work record");
                     }
                 }
             }
@@ -1008,6 +1016,27 @@
             return 1;
         }
     }
+
+    private int getLocBay(String locNo) {
+        return Integer.parseInt(locNo.substring(2, 5));
+    }
+
+    private boolean canFallbackStation(String locNo) {
+        int bay = getLocBay(locNo);
+        return bay != 1 && bay != 29;
+    }
+
+    private boolean shouldPrioritizePut(Integer crnId, String locNo, int loadedStation) {
+        int preferredStation = getCrnStation(locNo);
+        if (preferredStation == loadedStation) {
+            return true;
+        }
+        if (!canFallbackStation(locNo)) {
+            return false;
+        }
+        return wrkMastMapper.selectByPltType(crnId, preferredStation) != null;
+    }
+
 
 
     /**
@@ -1072,11 +1101,17 @@
                 crnStation = getCrnStation(wrkMast.getLocNo());
             }
             if (wrkMastMapper.selectByPltType(slave.getId(), crnStation) != null) {
-                News.error("" + mark + " - 1" + " - 9" + " - 鍫嗗灈鏈烘敼宸ヤ綅瀛樺湪宸ヤ綔妗�,宸ヤ綅={}", crnStation);
-                break;
+                if (!canFallbackStation(wrkMast.getLocNo())) {
+                    log.warn("CRN station fixed for bay={}, workNo={}, station={}", getLocBay(wrkMast.getLocNo()), wrkMast.getWrkNo(), crnStation);
+                    continue;
+                }
+                int alternateStation = crnStation == 1 ? 2 : 1;
+                if (wrkMastMapper.selectByPltType(slave.getId(), alternateStation) != null) {
+                    log.warn("CRN station busy for workNo={}, preferredStation={}", wrkMast.getWrkNo(), crnStation);
+                    continue;
+                }
+                crnStation = alternateStation;
             }
-
-            // 宸茬粡瀛樺湪鍚婅溅鎵ц浠诲姟鏃讹紝鍒欒繃婊�
             if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                 continue;
             }
@@ -1311,8 +1346,16 @@
                         crnStation = getCrnStation(wrkMast.getSourceLocNo());
                     }
                     if (wrkMastMapper.selectByPltType(slave.getId(), crnStation) != null) {
-                        News.error("" + mark + " - 1" + " - 9" + " - 鍫嗗灈鏈烘敼宸ヤ綅瀛樺湪宸ヤ綔妗�,宸ヤ綅={}", crnStation);
-                        break;
+                        if (!canFallbackStation(wrkMast.getSourceLocNo())) {
+                            log.warn("CRN station fixed for bay={}, workNo={}, station={}", getLocBay(wrkMast.getSourceLocNo()), wrkMast.getWrkNo(), crnStation);
+                            continue;
+                        }
+                        int alternateStation = crnStation == 1 ? 2 : 1;
+                        if (wrkMastMapper.selectByPltType(slave.getId(), alternateStation) != null) {
+                            log.warn("CRN station busy for workNo={}, preferredStation={}", wrkMast.getWrkNo(), crnStation);
+                            continue;
+                        }
+                        crnStation = alternateStation;
                     }
 
                     // 宸茬粡瀛樺湪鍚婅溅鎵ц浠诲姟鏃讹紝鍒欒繃婊�

--
Gitblit v1.9.1