From 171206ad10f56e8ee795cc3d5ee7c5ad3980a105 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 13 十月 2023 17:34:20 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java |   98 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 79 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java b/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
index 3d84c4f..5747ee5 100644
--- a/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
@@ -1,12 +1,17 @@
 package com.zy.common.utils;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.WrkCharge;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.mapper.WrkChargeMapper;
 import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.BasDevpService;
+import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.model.NavigateNode;
@@ -24,6 +29,8 @@
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.LiftThread;
 import com.zy.core.thread.NyShuttleThread;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -87,6 +94,7 @@
                 if (wrkMast1 != null) {
                     wrkMast1.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());
                     wrkMastMapper.updateById(wrkMast1);
+                    return true;
                 }
                 break;
             }
@@ -123,29 +131,39 @@
             }
         }else {
             //鍚屼竴妤煎眰锛屾病鏈夌┖闂茬┛姊溅锛屽彧鑳戒粠鍏朵粬妤煎眰璋冨害
-            //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞�
-            for (NyShuttleThread shuttleThread : diffLev) {
+            //瀵绘壘绂讳换鍔℃ゼ灞傛渶杩戠殑绌挎杞�(涓嶈�冭檻璺ㄦゼ灞傚皬杞︾Щ鍔ㄨ窛绂�)
 
-                //褰撳墠绌挎杞﹀簱浣嶅彿
-                String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
-                int currentLev = Utils.getLev(currentLocNo);
-                List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞�
-                if (wrkMasts1.size() > 0) {
-                    //瀛樺湪鍏朵粬浠诲姟锛岃烦杩囪繖杈嗚溅
-                    continue;
+            //鑾峰彇浠诲姟
+            WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo);
+
+            if (wrkMast1 != null) {
+                String locNO=wrkMast1.getIoType()<100?wrkMast1.getLocNo():wrkMast1.getSourceLocNo();
+                int lev = Utils.getLev(locNO);//鐩爣妤煎眰
+
+                //妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
+                boolean checkDispatchMaxNum = checkDispatchMaxNum(lev);
+                if (!checkDispatchMaxNum) {
+                    return false;
                 }
 
-                //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈
-                List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
-                if (currentShuttlePath == null) {
-                    continue;
-                }
+                int recentValue = 99999;//鏈�灏忓樊鍊�
+                for (NyShuttleThread shuttleThread : diffLev) {
+                    //褰撳墠绌挎杞﹀簱浣嶅彿
+                    String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
+                    int currentLev = Utils.getLev(currentLocNo);
+                    List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞�
+                    if (wrkMasts1.size() > 0) {
+                        //瀛樺湪鍏朵粬浠诲姟锛岃烦杩囪繖杈嗚溅
+                        continue;
+                    }
 
-                Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-                if (currentAllDistance < recentAllDistance) {
-                    //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
-                    recentShuttle = shuttleThread;
-                    recentAllDistance = currentAllDistance;
+                    //ABS(鐩爣妤煎眰 - 褰撳墠妤煎眰) 寰楀埌宸窛锛屽彇鏈�灏忓樊鍊�
+                    int currentValue = Math.abs(lev - currentLev);
+                    if (currentValue < recentValue) {
+                        //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
+                        recentShuttle = shuttleThread;
+                        recentValue = currentValue;
+                    }
                 }
             }
         }
@@ -263,6 +281,48 @@
     }
 
     /**
+     * 妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
+     * true: 灏忎簬鏈�澶ф暟閲�  false: 澶т簬鎴栫瓑浜庢渶澶ф暟閲�
+     */
+    public boolean checkDispatchMaxNum(Integer lev) {
+        BasShuttleService basShuttleService = SpringUtils.getBean(BasShuttleService.class);
+        ConfigService configService = SpringUtils.getBean(ConfigService.class);
+        EntityWrapper<Config> wrapper = new EntityWrapper<>();
+        wrapper.eq("code", "dispatchShuttleMaxNum");
+        Config config = configService.selectOne(wrapper);
+        if (config == null) {
+            return false;
+        }
+
+        int levCount = 0;//鐩爣妤煎眰杞﹁締鏁伴噺
+        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
+
+            NyShuttleProtocol.NyShuttlePointClass point = null;
+            if (shuttleProtocol.getPoint() == null) {
+                BasShuttle basShuttle = basShuttleService.selectById(shuttle.getId());//灏忚溅濡傛灉娌℃湁鏁版嵁锛屼粠鏁版嵁搴撳彇鏁版嵁
+                if (basShuttle == null || basShuttle.getPoint() == null) {
+                    continue;
+                }
+                point = JSON.parseObject(basShuttle.getPoint(), NyShuttleProtocol.NyShuttlePointClass.class);
+            }else {
+                point = shuttleProtocol.getPoint();
+            }
+
+            if (point.getZ().equals(lev)) {
+                levCount++;//鐩爣妤煎眰鏈夎溅锛屾暟閲忓鍔�
+            }
+        }
+
+        return levCount < Integer.parseInt(config.getValue());
+    }
+
+    /**
      * 鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
      */
     public LiftStaProtocol getRecentLiftSta(Integer shuttleNo) {

--
Gitblit v1.9.1