From 1c8455e647bfb059d52788afaa845c52e7d6213f Mon Sep 17 00:00:00 2001
From: Administrator <XS@163.COM>
Date: 星期三, 06 五月 2026 19:25:39 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 206 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index 837c7a8..78d5cd9 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -66,6 +66,20 @@
}
public void submitStationEnableInTasks(MainProcessLane lane, long minIntervalMs) {
+ mainProcessTaskSubmitter.submitSerialTask(
+ MainProcessLane.STATION_SCAN,
+ "submitStationEnableInTasks",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ submitStationEnableInTasksInternal(lane, minIntervalMs);
+ }
+ }
+ );
+ }
+
+ private void submitStationEnableInTasksInternal(MainProcessLane lane, long minIntervalMs) {
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
for (final BasDevp basDevp : basDevps) {
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
@@ -103,18 +117,50 @@
}
public void submitStationInTasks(MainProcessLane lane, long minIntervalMs) {
- // 鍏ュ簱涓嬪彂渚濊禆鍗曡疆鍏变韩鐨勬壙杞介鍗犵姸鎬侊紝蹇呴』鏁翠綋涓茶锛岄伩鍏嶅涓珯鐐瑰苟鍙戞椂鍚屾椂閫氳繃瀹归噺妫�鏌ャ��
mainProcessTaskSubmitter.submitSerialTask(
- MainProcessLane.STATION,
- "stationInExecute",
+ MainProcessLane.STATION_SCAN,
+ "submitStationInTasks",
minIntervalMs,
new Runnable() {
@Override
public void run() {
- stationInExecute();
+ submitStationInTasksInternal(lane, minIntervalMs);
}
}
);
+ }
+
+ private void submitStationInTasksInternal(MainProcessLane lane, long minIntervalMs) {
+ List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
+ for (final BasDevp basDevp : basDevps) {
+ StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+ if (stationThread == null) {
+ continue;
+ }
+ Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+ if (stationMap == null || stationMap.isEmpty()) {
+ continue;
+ }
+ List<StationObjModel> list = basDevp.getBarcodeStationList$();
+ for (final StationObjModel stationObjModel : list) {
+ Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId();
+ if (stationId == null || !stationMap.containsKey(stationId)) {
+ continue;
+ }
+ mainProcessTaskSubmitter.submitKeyedSerialTask(
+ lane,
+ stationId,
+ "stationInExecute",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ stationInExecute(basDevp, stationObjModel);
+ }
+ }
+ );
+ }
+ }
}
public void submitCrnStationOutTasks(long minIntervalMs) {
@@ -122,18 +168,39 @@
}
public void submitCrnStationOutTasks(MainProcessLane lane, long minIntervalMs) {
- // 鍑哄簱绔欑偣涓嬪彂鍚屾牱浼氶鍗犺緭閫佺嚎/鐜嚎瀹归噺锛屼笌 stationInExecute 鍏辩敤 STATION lane 涓茶銆�
mainProcessTaskSubmitter.submitSerialTask(
- MainProcessLane.STATION,
- "crnStationOutExecute",
+ MainProcessLane.STATION_SCAN,
+ "submitCrnStationOutTasks",
minIntervalMs,
new Runnable() {
@Override
public void run() {
- crnStationOutExecute();
+ submitCrnStationOutTasksInternal(lane, minIntervalMs);
}
}
);
+ }
+
+ private void submitCrnStationOutTasksInternal(MainProcessLane lane, long minIntervalMs) {
+ List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+ .eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)
+ .isNotNull("crn_no")
+ );
+ for (final WrkMast wrkMast : wrkMasts) {
+ Integer laneKey = getCrnStationOutLaneKey(wrkMast);
+ mainProcessTaskSubmitter.submitKeyedSerialTask(
+ lane,
+ laneKey,
+ "crnStationOutExecute",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ crnStationOutExecute(wrkMast);
+ }
+ }
+ );
+ }
}
public void submitDualCrnStationOutTasks(long minIntervalMs) {
@@ -141,6 +208,20 @@
}
public void submitDualCrnStationOutTasks(MainProcessLane lane, long minIntervalMs) {
+ mainProcessTaskSubmitter.submitSerialTask(
+ MainProcessLane.STATION_SCAN,
+ "submitDualCrnStationOutTasks",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ submitDualCrnStationOutTasksInternal(lane, minIntervalMs);
+ }
+ }
+ );
+ }
+
+ private void submitDualCrnStationOutTasksInternal(MainProcessLane lane, long minIntervalMs) {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
.eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)
.isNotNull("dual_crn_no")
@@ -170,12 +251,23 @@
}
public void submitStationOutExecuteFinishTasks(MainProcessLane lane, long minIntervalMs) {
+ mainProcessTaskSubmitter.submitSerialTask(
+ MainProcessLane.STATION_SCAN,
+ "submitStationOutExecuteFinishTasks",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ submitStationOutExecuteFinishTasksInternal(lane, minIntervalMs);
+ }
+ }
+ );
+ }
+
+ private void submitStationOutExecuteFinishTasksInternal(MainProcessLane lane, long minIntervalMs) {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
for (final WrkMast wrkMast : wrkMasts) {
- Integer laneKey = wrkMast == null ? null : wrkMast.getStaNo();
- if (laneKey == null) {
- laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
- }
+ Integer laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
mainProcessTaskSubmitter.submitKeyedSerialTask(
lane,
laneKey,
@@ -196,12 +288,23 @@
}
public void submitCheckTaskToCompleteTasks(MainProcessLane lane, long minIntervalMs) {
+ mainProcessTaskSubmitter.submitSerialTask(
+ MainProcessLane.STATION_SCAN,
+ "submitCheckTaskToCompleteTasks",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ submitCheckTaskToCompleteTasksInternal(lane, minIntervalMs);
+ }
+ }
+ );
+ }
+
+ private void submitCheckTaskToCompleteTasksInternal(MainProcessLane lane, long minIntervalMs) {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
for (final WrkMast wrkMast : wrkMasts) {
- Integer laneKey = wrkMast == null ? null : wrkMast.getStaNo();
- if (laneKey == null) {
- laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
- }
+ Integer laneKey = wrkMast == null ? null : wrkMast.getWrkNo();
mainProcessTaskSubmitter.submitKeyedSerialTask(
lane,
laneKey,
@@ -222,6 +325,20 @@
}
public void submitCheckStationRunBlockTasks(MainProcessLane lane, long minIntervalMs) {
+ mainProcessTaskSubmitter.submitSerialTask(
+ MainProcessLane.STATION_SCAN,
+ "submitCheckStationRunBlockTasks",
+ minIntervalMs,
+ new Runnable() {
+ @Override
+ public void run() {
+ submitCheckStationRunBlockTasksInternal(lane, minIntervalMs);
+ }
+ }
+ );
+ }
+
+ private void submitCheckStationRunBlockTasksInternal(MainProcessLane lane, long minIntervalMs) {
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
for (final BasDevp basDevp : basDevps) {
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
@@ -257,7 +374,7 @@
}
//鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
- public synchronized void stationInExecute() {
+ public void stationInExecute() {
try {
DispatchLimitConfig limitConfig = getDispatchLimitConfig();
int[] currentStationTaskCountRef = new int[]{countCurrentStationTask()};
@@ -385,16 +502,30 @@
&& stationProtocol.getTaskNo() > 0
) {
//妫�娴嬩换鍔℃槸鍚︾敓鎴�
- WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+ WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
+ .eq("barcode", stationProtocol.getBarcode())
+ .eq("io_type", WrkIoType.IN.id)
+ );
if (wrkMast == null) {
+ logDebugLimited("station_in_wait_wrk_" + stationId + "_" + stationProtocol.getTaskNo(), 3,
+ "[WCS Debug][鏉$爜绔欏叆搴揮 鏉$爜绔欏凡鏈夌珯鐐逛换鍔″彿浣嗘湭鎵惧埌鍏ュ簱宸ヤ綔妗o紝绛夊緟浠诲姟鐢熸垚銆俿tationId={}锛宻tationTaskNo={}锛宐arcode={}锛宨sLoading={}锛宨sAutoing={}",
+ stationId, stationProtocol.getTaskNo(), stationProtocol.getBarcode(),
+ stationProtocol.isLoading(), stationProtocol.isAutoing());
return false;
}
if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) {
+ logDebugLimited("station_in_already_run_" + wrkMast.getWrkNo(), 5,
+ "[WCS Debug][鏉$爜绔欏叆搴揮 鍏ュ簱宸ヤ綔妗e凡澶勪簬璁惧涓婅蛋鐘舵�侊紝绛夊緟杈撻�佺嚎/PLC鐘舵�佹帹杩涖�俿tationId={}锛寃rkNo={}锛宐arcode={}锛宭ocNo={}锛寃rkSts={}",
+ stationId, wrkMast.getWrkNo(), stationProtocol.getBarcode(),
+ wrkMast.getLocNo(), wrkMast.getWrkSts());
return false;
}
String locNo = wrkMast.getLocNo();
+ News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鍑嗗鍖归厤鍏ュ簱鐩爣绔欍�俿tationId={}锛宻tationTaskNo={}锛寃rkNo={}锛宐arcode={}锛宭ocNo={}锛寃rkSts={}",
+ stationId, stationProtocol.getTaskNo(), wrkMast.getWrkNo(),
+ stationProtocol.getBarcode(), locNo, wrkMast.getWrkSts());
FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
if (findCrnNoResult == null) {
News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鏈尮閰嶅埌鍫嗗灈鏈�", wrkMast.getWrkNo());
@@ -410,10 +541,18 @@
LoopHitResult loopHitResult = findPathLoopHit(limitConfig, stationProtocol.getStationId(), targetStationId, loadGuardState);
if (isDispatchBlocked(limitConfig, currentStationTaskCountRef[0], loadGuardState, loopHitResult.isThroughLoop())) {
+ logDebugLimited("station_in_dispatch_blocked_" + wrkMast.getWrkNo(), 3,
+ "[WCS Debug][鏉$爜绔欏叆搴揮 鍏ュ簱杈撻�佸懡浠ゆ殏缂擄紝涓嬪彂瀹归噺/鐜嚎璐熻浇鍙楅檺銆俿tationId={}锛宼argetStationId={}锛寃rkNo={}锛宑urrentStationTaskCount={}锛宼hroughLoop={}锛宭oopNo={}锛宧itStationId={}",
+ stationId, targetStationId, wrkMast.getWrkNo(), currentStationTaskCountRef[0],
+ loopHitResult.isThroughLoop(), loopHitResult.getLoopNo(), loopHitResult.getHitStationId());
return true;
}
+ long commandStartMs = System.currentTimeMillis();
StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
+ News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鑾峰彇鍏ュ簱杈撻�佸懡浠ゅ畬鎴愩�俿tationId={}锛宼argetStationId={}锛寃rkNo={}锛宑ostMs={}锛宑ommand={}",
+ stationId, targetStationId, wrkMast.getWrkNo(),
+ System.currentTimeMillis() - commandStartMs, JSON.toJSONString(command));
if (command == null) {
News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", wrkMast.getWrkNo());
return false;
@@ -427,6 +566,9 @@
if (wrkMastService.updateById(wrkMast)) {
MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
News.info("杈撻�佺珯鐐瑰叆搴撳懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command));
+ News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鍏ュ簱杈撻�佸懡浠ゅ凡鍏ラ槦銆俿tationId={}锛宼argetStationId={}锛寃rkNo={}锛宐arcode={}锛宭ocNo={}锛宒eviceNo={}",
+ stationId, targetStationId, wrkMast.getWrkNo(), stationProtocol.getBarcode(),
+ locNo, basDevp.getDevpNo());
redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5);
loadGuardState.reserveLoopTask(loopHitResult.getLoopNo());
saveLoopLoadReserve(wrkMast.getWrkNo(), loopHitResult);
@@ -436,7 +578,7 @@
}
//鎵ц鍫嗗灈鏈鸿緭閫佺珯鐐瑰嚭搴撲换鍔�
- public synchronized void crnStationOutExecute() {
+ public void crnStationOutExecute() {
try {
DispatchLimitConfig limitConfig = getDispatchLimitConfig();
int[] currentStationTaskCountRef = new int[]{countCurrentStationTask()};
@@ -456,6 +598,30 @@
} catch (Exception e) {
e.printStackTrace();
}
+ }
+
+ private Integer getCrnStationOutLaneKey(WrkMast wrkMast) {
+ if (wrkMast == null) {
+ return null;
+ }
+ Object infoObj = redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + wrkMast.getWrkNo());
+ if (infoObj != null) {
+ try {
+ StationObjModel stationObjModel = JSON.parseObject(infoObj.toString(), StationObjModel.class);
+ if (stationObjModel != null && stationObjModel.getStationId() != null) {
+ return stationObjModel.getStationId();
+ }
+ } catch (Exception e) {
+ News.error("[WCS Debug][绔欑偣鍑哄簱] 瑙f瀽鍑哄簱缂撳瓨绔欑偣澶辫触锛屽伐浣滃彿={}锛宑ache={}", wrkMast.getWrkNo(), infoObj);
+ }
+ }
+ if (wrkMast.getSourceStaNo() != null) {
+ return wrkMast.getSourceStaNo();
+ }
+ if (wrkMast.getStaNo() != null) {
+ return wrkMast.getStaNo();
+ }
+ return wrkMast.getWrkNo();
}
public void crnStationOutExecute(WrkMast wrkMast) {
@@ -556,7 +722,7 @@
}
//鎵ц鍙屽伐浣嶅爢鍨涙満杈撻�佺珯鐐瑰嚭搴撲换鍔�
- public synchronized void dualCrnStationOutExecute() {
+ public void dualCrnStationOutExecute() {
try {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
.eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)
@@ -630,7 +796,7 @@
}
//妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
- public synchronized void stationOutExecuteFinish() {
+ public void stationOutExecuteFinish() {
try {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
for (WrkMast wrkMast : wrkMasts) {
@@ -683,7 +849,7 @@
}
// 妫�娴嬩换鍔¤浆瀹屾垚
- public synchronized void checkTaskToComplete() {
+ public void checkTaskToComplete() {
try {
List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN_COMPLETE.sts));
for (WrkMast wrkMast : wrkMasts) {
@@ -739,7 +905,7 @@
}
//妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
- public synchronized void checkStationRunBlock() {
+ public void checkStationRunBlock() {
try {
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
for (BasDevp basDevp : basDevps) {
@@ -1017,12 +1183,12 @@
}
//鑾峰彇杈撻�佺嚎浠诲姟鏁伴噺
- public synchronized int getCurrentStationTaskCount() {
+ public int getCurrentStationTaskCount() {
return countCurrentStationTask();
}
// 妫�娴嬪嚭搴撴帓搴�
- public synchronized void checkStationOutOrder() {
+ public void checkStationOutOrder() {
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
for (BasDevp basDevp : basDevps) {
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getId());
@@ -1142,7 +1308,7 @@
}
// 鐩戞帶缁曞湀绔欑偣
- public synchronized void watchCircleStation() {
+ public void watchCircleStation() {
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
for (BasDevp basDevp : basDevps) {
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getId());
@@ -1409,6 +1575,20 @@
redisUtil.expire(RedisKeyType.STATION_CYCLE_LOAD_RESERVE.key, LOOP_LOAD_RESERVE_EXPIRE_SECONDS);
}
+ private void logDebugLimited(String lockKey, int seconds, String format, Object... arguments) {
+ String redisKey = RedisKeyType.LOG_LIMIT.key + "wcs_debug_" + lockKey;
+ try {
+ Object lock = redisUtil.get(redisKey);
+ if (lock != null) {
+ return;
+ }
+ redisUtil.set(redisKey, "lock", seconds);
+ } catch (Exception e) {
+ // 璇婃柇鏃ュ織涓嶈兘褰卞搷涓绘祦绋嬨��
+ }
+ News.info(format, arguments);
+ }
+
private DispatchLimitConfig getDispatchLimitConfig() {
DispatchLimitConfig config = new DispatchLimitConfig();
Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
--
Gitblit v1.9.1