From c0d2dc7614b173e0ea4c78c6f899ab732542127a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 13 七月 2025 19:54:28 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java | 187 ++++++++++++++++++++++++++++++++++++----------
1 files changed, 145 insertions(+), 42 deletions(-)
diff --git a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
index 72f341a..9062069 100644
--- a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -1,8 +1,17 @@
package com.zy.core.dispatcher;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.core.common.Cools;
import com.core.exception.CoolException;
+import com.zy.asrs.domain.ShuttleGatherResult;
+import com.zy.asrs.domain.param.ShuttleDemoParam;
+import com.zy.asrs.domain.param.ShuttleGatherParam;
+import com.zy.asrs.entity.BasShuttle;
+import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.BasShuttleService;
+import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
@@ -13,11 +22,11 @@
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.ForkLiftSlave;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.protocol.*;
-import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.ForkLiftThread;
import com.zy.core.thread.ShuttleThread;
import com.zy.system.entity.Config;
@@ -35,8 +44,6 @@
public class ShuttleDispatchUtils {
@Autowired
- private SlaveProperties slaveProperties;
- @Autowired
private WrkMastService wrkMastService;
@Autowired
private CommonService commonService;
@@ -44,47 +51,48 @@
private NavigateUtils navigateUtils;
@Autowired
private ConfigService configService;
+ @Autowired
+ private BasShuttleService basShuttleService;
+ @Autowired
+ private DeviceConfigService deviceConfigService;
/**
* 璋冨害杞﹁締-璋冨害鎸囧畾绌挎杞�
*/
- public boolean dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) {
+ public synchronized boolean dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) {
return shuttleMoveGenerate(wrkNo, locNo, shuttleNo);
}
/**
* 璋冨害杞﹁締
*/
- public boolean dispatchShuttle(Integer wrkNo, String locNo) {
- //妫�娴嬬洰鏍囧簱浣嶇粍鏄惁瀛樺湪灏忚溅锛屽瀛樺湪灏忚溅鍒欑洿鎺ユ寚瀹氳杞�
- WrkMast wrkMast = wrkMastService.selectByWorkNo(wrkNo);
- if (wrkMast != null) {
- String targetLocNo = wrkMast.getIoType() < 100 ? wrkMast.getLocNo() : wrkMast.getSourceLocNo();
- List<String> groupLoc = Utils.getGroupLoc(targetLocNo);
- Integer groupShuttleNo = Utils.checkGroupLocHasShuttle(groupLoc);
- if (groupShuttleNo != null) {
- //瀛樺湪灏忚溅锛岀洿鎺ヨ皟搴﹁杞�
- return shuttleMoveGenerate(wrkNo, locNo, groupShuttleNo);
- }
- }
-
+ public synchronized boolean dispatchShuttle(Integer wrkNo, String locNo) {
ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
- for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+ List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+ for (DeviceConfig device : shuttleList) {
//鑾峰彇鍥涘悜绌挎杞︾嚎绋�
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
continue;
}
- if (checkChargeWrk(shuttle.getId())) {
+ if (checkChargeWrk(device.getDeviceNo())) {
continue;//瀛樺湪鍏呯數浠诲姟锛岃繃婊ゅ皬杞�
}
if (!shuttleThread.isIdle()) {
continue;//灏忚溅蹇欑涓�
+ }
+
+ BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", device.getDeviceNo()));
+ if (basShuttle != null) {
+ if (basShuttle.getStatus() == 0) {
+ continue;//灏忚溅琚鐢�
+ }
}
int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
@@ -164,7 +172,8 @@
//褰撳墠绌挎杞﹀簱浣嶅彿
String currentLocNo = shuttleProtocol.getCurrentLocNo();
int currentLev = Utils.getLev(currentLocNo);
- List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞�
+ //鍒ゆ柇褰撳墠妤煎眰鏄惁鏈変换鍔★紝濡傛灉鏈夊垯涓嶅垎閰嶈繖杈嗚溅
+ List<WrkMast> wrkMasts1 = wrkMastService.selectWrkByLev(currentLev);
int shuttleCount = this.getShuttleCountByLev(currentLev);//鑾峰彇绌挎杞︽ゼ灞傝溅杈嗘暟閲�
if (!wrkMasts1.isEmpty() && shuttleCount <= 1) {
//瀛樺湪鍏朵粬浠诲姟涓斿彲鐢ㄥ皬杞︽暟閲忓皬浜庣瓑浜�1锛岃烦杩囪繖杈嗚溅
@@ -198,7 +207,7 @@
* 灏忚溅杩佺Щ浠诲姟鐢熸垚
*/
@Transactional
- public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
+ public synchronized boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
Date now = new Date();
//鑾峰彇鍥涘悜绌挎杞︾嚎绋�
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -225,11 +234,21 @@
return false;
}
+ //鑾峰彇涓诲伐浣滄。淇℃伅
+ WrkMast mainWrkMast = wrkMastService.selectByWorkNo(wrkNo);
+
//鍒ゆ柇鏄惁鏈夊叾浠栦换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅
WrkMast wrkMast2 = wrkMastService.selectShuttleWorking(shuttleNo);
if (wrkMast2 != null) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟
- News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
- return false;
+ if (mainWrkMast == null) {
+ News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
+ return false;
+ }else {
+ if (!shuttleNo.equals(mainWrkMast.getShuttleNo())) {
+ News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
+ return false;
+ }
+ }
}
Integer sourceStaNo = null;//灏忚溅鎹㈠眰婧愮珯鐐�
@@ -243,19 +262,25 @@
return false;//娌℃湁鍙敤涓旂┖闂茬殑杈撻�佺珯鐐�
}
sourceStaNo = liftSta.getStaNo();//婧愮珯鐐�
- //鎻愬崌鏈哄彿*100+鐩爣妤煎眰=鐩爣绔欑偣
- staNo = liftSta.getLiftNo() * 100 + Utils.getLev(locNo);//鐩爣绔�
+
+ ForkLiftStaProtocol targetLiftSta = ForkLiftUtils.getLiftStaByLev(liftSta.getLiftNo(), Utils.getLev(locNo));
+ if (targetLiftSta == null) {
+ News.info("{}鍙峰皬杞︼紝{}鐩爣搴撲綅锛屾病鏈夌洰鏍囩珯鐐�", shuttleNo, locNo);
+ return false;//娌℃湁鎵惧埌鐩爣绔欑偣
+ }
+ //鐩爣绔欑偣
+ staNo = targetLiftSta.getStaNo();//鐩爣绔�
}
// 鑾峰彇宸ヤ綔鍙�
- int workNo = commonService.getWorkNo(0);
+ int workNo = commonService.getWorkNo(WrkIoType.SHUTTLE_MOVE.id);
// 淇濆瓨宸ヤ綔妗�
WrkMast wrkMast = new WrkMast();
wrkMast.setWrkNo(workNo);
wrkMast.setIoTime(now);
wrkMast.setWrkSts(WrkStsType.NEW_MOVE.sts); // 宸ヤ綔鐘舵�侊細301.鐢熸垚杩佺Щ浠诲姟
- wrkMast.setIoType(200); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅杩佺Щ
- wrkMast.setIoPri(20D);
+ wrkMast.setIoType(WrkIoType.SHUTTLE_MOVE.id); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅杩佺Щ
+ wrkMast.setIoPri(800D);
wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿
wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙�
wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
@@ -270,13 +295,61 @@
}
//缁欏伐浣滄。缁戝畾灏忚溅鍙�
- WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
- if (wrkMast1 != null) {
- wrkMast1.setShuttleNo(shuttleNo);
- wrkMastService.updateById(wrkMast1);
+ if (mainWrkMast != null) {
+ mainWrkMast.setShuttleNo(shuttleNo);
+ wrkMastService.updateById(mainWrkMast);
}
return true;
+ }
+
+ /**
+ * 灏忚溅闆嗗悎
+ */
+ public List<ShuttleGatherResult> shuttleGather(ShuttleGatherParam param) {
+ Wrapper<BasShuttle> wrapper = new EntityWrapper<BasShuttle>().eq("status", 1);
+ if (param != null) {
+ if (!param.getShuttleNos().isEmpty()) {
+ wrapper.in("shuttle_no", param.getShuttleNos());
+ }
+ }
+
+ List<BasShuttle> basShuttles = basShuttleService.selectList(wrapper);
+ List<ShuttleGatherResult> list = new ArrayList<>();
+ for (BasShuttle basShuttle : basShuttles) {
+ String idleLoc = basShuttle.getIdleLoc();
+ if(Cools.isEmpty(idleLoc)) {
+ continue;
+ }
+
+ boolean result = shuttleMoveGenerate(null, idleLoc, basShuttle.getShuttleNo());
+
+ ShuttleGatherResult gatherResult = new ShuttleGatherResult();
+ gatherResult.setShuttleNo(basShuttle.getShuttleNo());
+ gatherResult.setIdleLoc(idleLoc);
+ gatherResult.setResult(result);
+ list.add(gatherResult);
+ }
+ return list;
+ }
+
+ /**
+ * 灏忚溅婕旂ず
+ */
+ public void shuttleDemo(ShuttleDemoParam param) {
+ List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.Shuttle))
+ .in("device_no", param.getShuttleNos())
+ );
+
+ for (DeviceConfig device : shuttleList) {
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
+ if (shuttleThread == null) {
+ continue;
+ }
+
+ shuttleThread.enableDemo(param.getStatus() == 1);
+ }
}
/**
@@ -291,12 +364,24 @@
return false;
}
+ List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.Shuttle)));
int levCount = 0;//鐩爣妤煎眰杞﹁締鏁伴噺
- for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+ for (DeviceConfig device : shuttleList) {
//鑾峰彇鍥涘悜绌挎杞︾嚎绋�
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+ continue;
+ }
+
+ //灏忚溅鏈夊厖鐢典换鍔�
+ if (shuttleThread.isCharging()) {
+ continue;
+ }
+
+ //灏忚溅鏁呴殰璺宠繃
+ if (shuttleThread.isFault()) {
continue;
}
@@ -350,11 +435,14 @@
return null;
}
+ List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.ForkLift)));
+
//鑾峰彇灏忚溅鍚屼竴妤煎眰鐨勭珯鐐�
ArrayList<ForkLiftStaProtocol> list = new ArrayList<>();
int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅妤煎眰
- for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
- ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId());
+ for (DeviceConfig device : forkliftList) {
+ ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
if (forkLiftThread == null) {
continue;
}
@@ -366,19 +454,32 @@
continue;
}
- ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), lev);
+ ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(device.getDeviceNo(), lev);
if (forkLiftStaProtocol == null) {
continue;
}
+ //鍒ゆ柇褰撳墠灞傛槸鍚︽棤鎵樼洏
+ if (forkLiftStaProtocol.getHasTray()) {
+ continue;
+ }
+
+ if (forkLiftStaProtocol.getHasCar()) {
+ continue;
+ }
+
//鍒ゆ柇鐩爣妤煎眰绔欑偣鏄惁鏃犳墭鐩�
- ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), targetLev);
+ ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(device.getDeviceNo(), targetLev);
if (targetLiftStaProtocol == null) {
continue;
}
if (targetLiftStaProtocol.getHasTray()) {
continue;//鏈夋墭鐩樿烦杩�
+ }
+
+ if (targetLiftStaProtocol.getHasCar()) {
+ continue;
}
list.add(forkLiftStaProtocol);
@@ -428,10 +529,12 @@
* 鑾峰彇妤煎眰鍙敤灏忚溅鏁伴噺
*/
public int getShuttleCountByLev(int lev) {
+ List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.Shuttle)));
int count = 0;
- for (ShuttleSlave slave : slaveProperties.getShuttle()) {
+ for (DeviceConfig device : shuttleList) {
//鑾峰彇鍥涘悜绌挎杞︾嚎绋�
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
if (shuttleThread == null) {
continue;
}
@@ -441,7 +544,7 @@
continue;
}
- if (checkChargeWrk(slave.getId())) {
+ if (checkChargeWrk(device.getDeviceNo())) {
continue;//瀛樺湪鍏呯數浠诲姟锛岃繃婊ゅ皬杞�
}
--
Gitblit v1.9.1