From 73aa66976e35252378be3f09be2474193ccd0bf6 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期五, 05 十二月 2025 17:15:20 +0800
Subject: [PATCH] 修改任务执行步骤状态完成检验
---
mes-processes/mes-plcSend/src/main/java/com/mes/task/service/TaskExecutionEngine.java | 1156 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 1,042 insertions(+), 114 deletions(-)
diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/task/service/TaskExecutionEngine.java b/mes-processes/mes-plcSend/src/main/java/com/mes/task/service/TaskExecutionEngine.java
index 986a06b..6d9c433 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/task/service/TaskExecutionEngine.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/task/service/TaskExecutionEngine.java
@@ -102,6 +102,8 @@
TaskExecutionContext context = new TaskExecutionContext(parameters);
runningTaskContexts.put(task.getTaskId(), context);
+ // 灏嗘湰娆′换鍔℃秹鍙婄殑璁惧鍒楄〃瀛樺叆涓婁笅鏂囷紝渚夸簬鍙栨秷浠诲姟鏃跺仛璁惧绾ф敹灏撅紙濡傚仠姝㈠ぇ杞﹀唴閮ㄧ洃鎺у畾鏃跺櫒锛�
+ context.getSharedData().put("devices", devices);
task.setTotalSteps(devices.size());
task.setStatus(MultiDeviceTask.Status.RUNNING.name());
@@ -148,7 +150,7 @@
for (DeviceConfig device : devices) {
String deviceType = device.getDeviceType();
- log.info("澶勭悊璁惧: deviceId={}, deviceType={}, deviceName={}, WORKSTATION_SCANNER甯搁噺={}, equals={}",
+ log.debug("澶勭悊璁惧: deviceId={}, deviceType={}, deviceName={}, WORKSTATION_SCANNER甯搁噺={}, equals={}",
device.getId(), deviceType, device.getDeviceName(),
DeviceConfig.DeviceType.WORKSTATION_SCANNER,
DeviceConfig.DeviceType.WORKSTATION_SCANNER.equals(deviceType));
@@ -157,19 +159,20 @@
|| (deviceType != null && (deviceType.contains("鎵爜") || deviceType.contains("SCANNER")));
boolean isLargeGlass = DeviceConfig.DeviceType.LARGE_GLASS.equals(deviceType);
boolean isTransfer = DeviceConfig.DeviceType.WORKSTATION_TRANSFER.equals(deviceType);
- log.info("璁惧绫诲瀷鍒ゆ柇: deviceId={}, isLoadVehicle={}, isScanner={}, isLargeGlass={}, isTransfer={}",
+ log.debug("璁惧绫诲瀷鍒ゆ柇: deviceId={}, isLoadVehicle={}, isScanner={}, isLargeGlass={}, isTransfer={}",
device.getId(), isLoadVehicle, isScanner, isLargeGlass, isTransfer);
// 1. 鍗ц浆绔嬫壂鐮佽澶囷細鍚姩瀹氭椂鍣ㄦ壂鎻忥紙姣�10绉掑鐞嗕竴涓幓鐠僆D锛�
if (isScanner) {
- log.info("妫�娴嬪埌鎵爜璁惧锛屽噯澶囧惎鍔ㄥ畾鏃跺櫒: deviceId={}, deviceType={}, deviceName={}",
+ log.debug("妫�娴嬪埌鎵爜璁惧锛屽噯澶囧惎鍔ㄥ畾鏃跺櫒: deviceId={}, deviceType={}, deviceName={}",
device.getId(), device.getDeviceType(), device.getDeviceName());
TaskStepDetail step = createStepRecord(task, device, currentOrder);
+
ScheduledFuture<?> scannerTask = startScannerTimer(task, step, device, context);
if (scannerTask != null) {
registerScheduledTask(task.getTaskId(), scannerTask);
stepSummaries.add(createStepSummary(device.getDeviceName(), true, "瀹氭椂鍣ㄥ凡鍚姩锛屾瘡10绉掓壂鎻忎竴娆�"));
- log.info("鎵爜璁惧瀹氭椂鍣ㄥ惎鍔ㄦ垚鍔�: deviceId={}, taskId={}", device.getId(), task.getTaskId());
+ log.debug("鎵爜璁惧瀹氭椂鍣ㄥ惎鍔ㄦ垚鍔�: deviceId={}, taskId={}", device.getId(), task.getTaskId());
} else {
log.warn("鎵爜璁惧瀹氭椂鍣ㄥ惎鍔ㄥけ璐ワ紝glassIds鍙兘涓虹┖: deviceId={}, taskId={}, contextParams={}",
device.getId(), task.getTaskId(), context.getParameters());
@@ -184,14 +187,15 @@
// 2. 鍗ц浆绔嬭澶囷細鍚姩瀹氭椂鍣ㄥ畾鏈熸鏌ュ苟澶勭悊锛堜腑杞澶囷級
if (isTransfer) {
- log.info("妫�娴嬪埌鍗ц浆绔嬭澶囷紝鍑嗗鍚姩瀹氭椂鍣�: deviceId={}, deviceType={}, deviceName={}",
+ log.debug("妫�娴嬪埌鍗ц浆绔嬭澶囷紝鍑嗗鍚姩瀹氭椂鍣�: deviceId={}, deviceType={}, deviceName={}",
device.getId(), device.getDeviceType(), device.getDeviceName());
TaskStepDetail step = createStepRecord(task, device, currentOrder);
+
ScheduledFuture<?> transferTask = startTransferTimer(task, step, device, context);
if (transferTask != null) {
registerScheduledTask(task.getTaskId(), transferTask);
stepSummaries.add(createStepSummary(device.getDeviceName(), true, "瀹氭椂鍣ㄥ凡鍚姩锛屽畾鏈熸鏌ュ苟澶勭悊鐜荤拑鎵规"));
- log.info("鍗ц浆绔嬭澶囧畾鏃跺櫒鍚姩鎴愬姛: deviceId={}, taskId={}", device.getId(), task.getTaskId());
+ log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒鍚姩鎴愬姛: deviceId={}, taskId={}", device.getId(), task.getTaskId());
} else {
log.warn("鍗ц浆绔嬭澶囧畾鏃跺櫒鍚姩澶辫触: deviceId={}, taskId={}", device.getId(), task.getTaskId());
stepSummaries.add(createStepSummary(device.getDeviceName(), false, "鍚姩瀹氭椂鍣ㄥけ璐�"));
@@ -209,6 +213,7 @@
boolean isInboundVehicle = currentLoadVehicleIndex == 1; // 绗竴涓ぇ杞︽槸杩涚墖澶ц溅
TaskStepDetail step = createStepRecord(task, device, currentOrder);
+
ScheduledFuture<?> vehicleTask;
if (isInboundVehicle) {
// 杩涚墖澶ц溅锛氱洃鎺у閲忥紝鍔ㄦ�佸垽鏂�
@@ -242,6 +247,7 @@
// 4. 澶х悊鐗囩璁惧锛氬惎鍔ㄥ畾鏃跺櫒閫昏緫澶勭悊锛堜笉娑夊強PLC浜や簰锛屽彧璐熻矗閫昏緫澶勭悊锛�
if (isLargeGlass) {
TaskStepDetail step = createStepRecord(task, device, currentOrder);
+
ScheduledFuture<?> largeGlassTask = startLargeGlassTimer(task, step, device, context);
if (largeGlassTask != null) {
registerScheduledTask(task.getTaskId(), largeGlassTask);
@@ -272,7 +278,7 @@
// 瀹氭椂鍣ㄤ細鍦ㄥ悗鍙版寔缁繍琛岋紝鐩村埌鎵嬪姩鍋滄鎴栬秴鏃�
boolean hasScheduledTasks = !CollectionUtils.isEmpty(taskScheduledTasks.get(task.getTaskId()));
if (hasScheduledTasks) {
- log.info("浠诲姟宸插惎鍔ㄦ墍鏈夊畾鏃跺櫒锛屼繚鎸佽繍琛岀姸鎬�: taskId={}, scheduledTasksCount={}",
+ log.debug("浠诲姟宸插惎鍔ㄦ墍鏈夊畾鏃跺櫒锛屼繚鎸佽繍琛岀姸鎬�: taskId={}, scheduledTasksCount={}",
task.getTaskId(), taskScheduledTasks.get(task.getTaskId()).size());
// 浠诲姟淇濇寔 RUNNING 鐘舵�侊紝瀹氭椂鍣ㄥ湪鍚庡彴杩愯
// 涓嶆洿鏂颁换鍔$姸鎬佷负 COMPLETED锛岃浠诲姟鎸佺画杩愯
@@ -336,6 +342,35 @@
if (context != null) {
context.getSharedData().put("taskCancelled", true);
log.warn("宸叉爣璁颁换鍔″彇娑�: taskId={}", taskId);
+
+ // 鍚屾椂閫氱煡鐩稿叧璁惧閫昏緫澶勭悊鍣ㄦ墽琛屽彇娑堟敹灏鹃�昏緫锛堜緥濡傚仠姝㈠ぇ杞﹀唴閮ㄧ殑鐩戞帶瀹氭椂鍣級
+ try {
+ Map<String, Object> cancelParams = new HashMap<>();
+ cancelParams.put("_taskContext", context);
+ Object devicesObj = context.getSharedData().get("devices");
+ if (devicesObj instanceof List) {
+ @SuppressWarnings("unchecked")
+ List<DeviceConfig> devices = (List<DeviceConfig>) devicesObj;
+ for (DeviceConfig device : devices) {
+ if (device == null) {
+ continue;
+ }
+ try {
+ DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
+ if (handler != null) {
+ // 鐩墠澶ц溅閫昏緫澶勭悊鍣ㄤ細鍦╮eset/clear绛夋搷浣滀腑鍋滄鍐呴儴鐩戞帶瀹氭椂鍣�
+ // 杩欓噷缁熶竴璋冪敤涓�娆♀�渞eset鈥濅綔涓轰换鍔″彇娑堟椂鐨勬敹灏惧姩浣�
+ handler.execute(device, "reset", cancelParams);
+ }
+ } catch (Exception e) {
+ log.warn("浠诲姟鍙栨秷鏃舵墽琛岃澶囨敹灏�(reset)澶辫触: taskId={}, deviceId={}, error={}",
+ taskId, device.getId(), e.getMessage());
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.warn("浠诲姟鍙栨秷鏃舵墽琛岃澶囨敹灏鹃�昏緫寮傚父: taskId={}, error={}", taskId, e.getMessage());
+ }
} else {
log.warn("璇锋眰鍙栨秷浠诲姟浣嗘湭鎵惧埌涓婁笅鏂�: taskId={}", taskId);
}
@@ -352,7 +387,7 @@
try {
TaskParameters params = context.getParameters();
List<String> glassIds = params.getGlassIds();
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鍒濆鍖�: taskId={}, deviceId={}, glassIds={}, glassIdsSize={}, isEmpty={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鍒濆鍖�: taskId={}, deviceId={}, glassIds={}, glassIdsSize={}, isEmpty={}",
task.getTaskId(), device.getId(), glassIds,
glassIds != null ? glassIds.size() : 0,
CollectionUtils.isEmpty(glassIds));
@@ -367,19 +402,25 @@
AtomicInteger successCount = new AtomicInteger(0);
AtomicInteger failCount = new AtomicInteger(0);
- final long CYCLE_INTERVAL_MS = 10_000; // 10绉掗棿闅�
+ // 浠庤澶囬厤缃腑鑾峰彇鎵爜闂撮殧锛岄粯璁�10绉�
+ Map<String, Object> logicParams = parseLogicParams(device);
+ Integer scanIntervalMs = getLogicParam(logicParams, "scanIntervalMs", 10_000);
- log.info("鍚姩鍗ц浆绔嬫壂鐮佸畾鏃跺櫒: taskId={}, deviceId={}, glassCount={}, interval={}s, glassIds={}",
- task.getTaskId(), device.getId(), glassIds.size(), CYCLE_INTERVAL_MS / 1000, glassIds);
+ log.debug("鍚姩鍗ц浆绔嬫壂鐮佸畾鏃跺櫒: taskId={}, deviceId={}, glassCount={}, interval={}ms, glassIds={}",
+ task.getTaskId(), device.getId(), glassIds.size(), scanIntervalMs, glassIds);
// 鍚姩瀹氭椂浠诲姟
ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(() -> {
try {
if (isTaskCancelled(context)) {
- log.info("浠诲姟宸插彇娑堬紝鍋滄鍗ц浆绔嬫壂鐮佸畾鏃跺櫒: taskId={}, deviceId={}",
+ log.debug("浠诲姟宸插彇娑堬紝鍋滄鍗ц浆绔嬫壂鐮佸畾鏃跺櫒: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
+ // 瀹氭椂鍣ㄧ涓�娆℃墽琛屾椂锛屽皢璁惧鐘舵�佷粠 WAITING 璁剧疆涓� RUNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ ensureStepRunning(step, task.getTaskId());
// 妫�鏌ユ槸鍚﹂渶瑕佹殏鍋�
if (shouldPauseScanner(context)) {
log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鏆傚仠: taskId={}, deviceId={}", task.getTaskId(), device.getId());
@@ -389,41 +430,69 @@
// 妫�鏌ユ槸鍚﹁繕鏈夊緟澶勭悊鐨勭幓鐠僆D
String glassId = glassIdQueue.poll();
if (glassId == null) {
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒瀹屾垚: taskId={}, deviceId={}, processed={}/{}, success={}, fail={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒瀹屾垚: taskId={}, deviceId={}, processed={}/{}, success={}, fail={}",
task.getTaskId(), device.getId(), processedCount.get(), glassIds.size(),
successCount.get(), failCount.get());
+
+ // 娓呯┖plcRequest鍜宲lcGlassId锛堢‘淇漃LC鐘舵�佹竻鐞嗭級
+ try {
+ DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
+ if (handler != null) {
+ Map<String, Object> clearParams = new HashMap<>();
+ clearParams.put("_taskContext", context);
+ handler.execute(device, "clearPlc", clearParams);
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒瀹屾垚锛屽凡娓呯┖PLC璇锋眰瀛楁: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
+ }
+ } catch (Exception e) {
+ log.warn("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒瀹屾垚鏃舵竻绌篜LC澶辫触: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 鑻ヤ箣鍓嶆湭鍑虹幇澶辫触锛屽啀灏嗙姸鎬佺疆涓哄畬鎴�
+ boolean alreadyFailed = TaskStepDetail.Status.FAILED.name().equals(step.getStatus());
+ if (!alreadyFailed) {
+ step.setStatus(TaskStepDetail.Status.COMPLETED.name());
+ step.setSuccessMessage(String.format("宸插畬鎴愭壂鎻�: 鎴愬姛=%d, 澶辫触=%d", successCount.get(), failCount.get()));
+ if (step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ // 鎵爜璁惧瀹屾垚鍚庡皾璇曡嚜鍔ㄦ敹灏炬暣涓换鍔�
+ checkAndCompleteTaskIfDone(step.getTaskId());
+ }
deviceCoordinationService.syncDeviceStatus(device,
DeviceCoordinationService.DeviceStatus.COMPLETED, context);
return;
}
int currentIndex = processedCount.incrementAndGet();
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒澶勭悊绗瑊}/{}涓幓鐠�: taskId={}, deviceId={}, glassId={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒澶勭悊绗瑊}/{}涓幓鐠�: taskId={}, deviceId={}, glassId={}",
currentIndex, glassIds.size(), task.getTaskId(), device.getId(), glassId);
// 鎵ц鍗曟鎵弿
Map<String, Object> scanParams = new HashMap<>();
scanParams.put("glassId", glassId);
scanParams.put("_taskContext", context);
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鍑嗗鎵ц: taskId={}, deviceId={}, glassId={}, scanParams={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鍑嗗鎵ц: taskId={}, deviceId={}, glassId={}, scanParams={}",
task.getTaskId(), device.getId(), glassId, scanParams);
DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
if (handler != null) {
- // 灏唋ogicParams鍚堝苟鍒皊canParams涓�
- Map<String, Object> logicParams = parseLogicParams(device);
+ // 灏唋ogicParams鍚堝苟鍒皊canParams涓紙浣跨敤宸插畾涔夌殑logicParams鍙橀噺锛�
if (logicParams != null && !logicParams.isEmpty()) {
scanParams.put("_logicParams", logicParams);
}
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒璋冪敤handler.execute: taskId={}, deviceId={}, glassId={}, operation=scanOnce, scanParamsKeys={}, scanParams={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒璋冪敤handler.execute: taskId={}, deviceId={}, glassId={}, operation=scanOnce, scanParamsKeys={}, scanParams={}",
task.getTaskId(), device.getId(), glassId, scanParams.keySet(), scanParams);
DevicePlcVO.OperationResult result = handler.execute(device, "scanOnce", scanParams);
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒handler.execute杩斿洖: taskId={}, deviceId={}, glassId={}, success={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒handler.execute杩斿洖: taskId={}, deviceId={}, glassId={}, success={}",
task.getTaskId(), device.getId(), glassId, result.getSuccess());
if (Boolean.TRUE.equals(result.getSuccess())) {
successCount.incrementAndGet();
- log.info("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒澶勭悊鎴愬姛: taskId={}, deviceId={}, glassId={}",
+ log.debug("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒澶勭悊鎴愬姛: taskId={}, deviceId={}, glassId={}",
task.getTaskId(), device.getId(), glassId);
} else {
failCount.incrementAndGet();
@@ -431,9 +500,10 @@
task.getTaskId(), device.getId(), glassId, result.getMessage());
}
- // 鏇存柊姝ラ鐘舵��
- updateStepStatus(step, result);
- // 閫氱煡姝ラ鏇存柊锛堣鍓嶇瀹炴椂鐪嬪埌姝ラ鐘舵�侊級
+ // 鏇存柊姝ラ鐘舵�侊紙鏄剧ず杩涘害锛屼繚鎸丷UNNING鐘舵�佺洿鍒版墍鏈夌幓鐠冨鐞嗗畬鎴愶級
+ updateStepStatusForScanner(step, result, currentIndex, glassIds.size(),
+ successCount.get(), failCount.get());
+ // 閫氱煡姝ラ鏇存柊锛堣鍓嶇瀹炴椂鐪嬪埌姝ラ鐘舵�佸拰杩涘害锛�
notificationService.notifyStepUpdate(task.getTaskId(), step);
boolean opSuccess = Boolean.TRUE.equals(result.getSuccess());
updateTaskProgress(task, step.getStepOrder(), opSuccess);
@@ -446,8 +516,10 @@
log.error("鍗ц浆绔嬫壂鐮佸畾鏃跺櫒鎵ц寮傚父: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
failCount.incrementAndGet();
}
- }, 0, CYCLE_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ }, 0, scanIntervalMs, TimeUnit.MILLISECONDS);
+ // 鍦ㄤ覆琛屾墽琛屾ā寮忎笅锛屾壂鐮佽澶囨槸绗竴涓紝搴旇绔嬪嵆璁剧疆涓� RUNNING
+ // 鍏朵粬璁惧淇濇寔 WAITING锛岀洿鍒板畠浠湡姝e紑濮嬪伐浣�
deviceCoordinationService.syncDeviceStatus(device,
DeviceCoordinationService.DeviceStatus.RUNNING, context);
return future;
@@ -469,17 +541,28 @@
Map<String, Object> logicParams = parseLogicParams(device);
Integer monitorIntervalMs = getLogicParam(logicParams, "monitorIntervalMs", 5_000);
- log.info("鍚姩鍗ц浆绔嬭澶囧畾鏃跺櫒: taskId={}, deviceId={}, interval={}ms",
+ log.debug("鍚姩鍗ц浆绔嬭澶囧畾鏃跺櫒: taskId={}, deviceId={}, interval={}ms",
task.getTaskId(), device.getId(), monitorIntervalMs);
// 鍚姩瀹氭椂浠诲姟
+ // 浣跨敤AtomicBoolean鏍囪鏄惁绗竴娆℃墽琛�
+ final java.util.concurrent.atomic.AtomicBoolean firstExecution = new java.util.concurrent.atomic.AtomicBoolean(true);
+
ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(() -> {
try {
if (isTaskCancelled(context)) {
- log.info("浠诲姟宸插彇娑堬紝鍋滄鍗ц浆绔嬭澶囧畾鏃跺櫒: taskId={}, deviceId={}",
+ log.debug("浠诲姟宸插彇娑堬紝鍋滄鍗ц浆绔嬭澶囧畾鏃跺櫒: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
+
+ // 濡傛灉姝ラ宸茬粡瀹屾垚锛屼笉鍐嶆墽琛屽悗缁�昏緫锛堥伩鍏嶇姸鎬佽閲嶇疆锛�
+ if (TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ log.debug("鍗ц浆绔嬭澶囨楠ゅ凡瀹屾垚锛屽仠姝㈠畾鏃跺櫒鎵ц: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
+ return;
+ }
+
// 鏋勫缓鍙傛暟
Map<String, Object> params = new HashMap<>();
params.put("_taskContext", context);
@@ -492,15 +575,63 @@
if (handler != null) {
DevicePlcVO.OperationResult result = handler.execute(device, "checkAndProcess", params);
- // 鏇存柊姝ラ鐘舵��
- updateStepStatus(step, result);
+ // 妫�鏌ユ槸鍚︽湁鏁版嵁锛氬鏋滄湁鏁版嵁鎴栨鍦ㄥ鐞嗭紝璁剧疆涓篟UNNING锛涘鏋滅紦鍐查槦鍒椾负绌轰笖鏃犲緟澶勭悊鐜荤拑锛屼繚鎸丳ENDING
+ String message = result.getMessage();
+ boolean hasData = result.getSuccess() != null && result.getSuccess()
+ && message != null && !message.contains("缂撳啿闃熷垪涓虹┖锛屾棤寰呭鐞嗙幓鐠�");
+
+ // 濡傛灉褰撳墠鏄疨ENDING鐘舵�侊紝涓旀娴嬪埌鏈夋暟鎹紝鍒欒缃负RUNNING锛堣澶囧紑濮嬪伐浣滐級
+ boolean isPending = TaskStepDetail.Status.PENDING.name().equals(step.getStatus());
+
+ if (hasData && isPending) {
+ // 妫�娴嬪埌鏁版嵁涓斿綋鍓嶆槸绛夊緟鐘舵�侊紝璁惧寮�濮嬪伐浣滐紝璁剧疆涓篟UNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒妫�娴嬪埌鏁版嵁锛屼粠PENDING杞负RUNNING: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), message);
+ } else if (!hasData) {
+ // 娌℃湁鏁版嵁锛屼繚鎸丳ENDING鐘舵�侊紝绛夊緟鎵爜璁惧杈撳嚭
+ if (firstExecution.compareAndSet(true, false)) {
+ // 绗竴娆℃墽琛岋紝纭繚鐘舵�佹槸PENDING
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟鎵爜璁惧杈撳嚭鏁版嵁");
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒绗竴娆℃墽琛岋紝鏃犳暟鎹紝淇濇寔PENDING: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), message);
+ }
+ return; // 涓嶆墽琛屽悗缁�昏緫锛岀瓑寰呬笅涓�娆″畾鏃跺櫒瑙﹀彂
+ }
+
+ // 鏇存柊姝ラ鐘舵�侊紙鍖哄垎绛夊緟涓拰鐪熸瀹屾垚锛�
+ updateStepStatusForTransfer(step, result, device, context);
// 閫氱煡姝ラ鏇存柊锛堣鍓嶇瀹炴椂鐪嬪埌姝ラ鐘舵�侊級
notificationService.notifyStepUpdate(task.getTaskId(), step);
boolean opSuccess = Boolean.TRUE.equals(result.getSuccess());
updateTaskProgress(task, step.getStepOrder(), opSuccess);
+
+ // 鏍规嵁鎵ц缁撴灉鏇存柊璁惧鐘舵��
+ // 娉ㄦ剰锛氳澶囧凡缁忓紑濮嬪伐浣滐紙瀹氭椂鍣ㄥ凡鎵ц锛夛紝鎵�浠ュ簲璇ヤ繚鎸丷UNNING鐘舵��
+ // 鍙湁鍦ㄧ湡姝e畬鎴愭椂鎵嶈缃负COMPLETED
if (opSuccess) {
- log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒鎵ц鎴愬姛: taskId={}, deviceId={}, message={}",
- task.getTaskId(), device.getId(), result.getMessage());
+ // 璁惧姝e湪宸ヤ綔锛堢瓑寰呯紦鍐层�佸鐞嗕腑绛夛級锛屼繚鎸丷UNNING鐘舵��
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ if (message != null && message.contains("鎵规宸插啓鍏LC")) {
+ log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒鎵ц鎴愬姛锛堝凡鍐欏叆PLC锛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), message);
+ } else {
+ log.debug("鍗ц浆绔嬭澶囧畾鏃跺櫒宸ヤ綔涓紙绛夊緟缂撳啿锛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), message);
+ }
} else {
log.warn("鍗ц浆绔嬭澶囧畾鏃跺櫒鎵ц澶辫触: taskId={}, deviceId={}, message={}",
task.getTaskId(), device.getId(), result.getMessage());
@@ -513,8 +644,9 @@
}
}, 0, monitorIntervalMs, TimeUnit.MILLISECONDS);
+ // 鍦ㄤ覆琛屾墽琛屾ā寮忎笅锛岃澶囧惎鍔ㄥ畾鏃跺櫒鏃跺厛璁剧疆涓� WAITING锛屽畾鏃跺櫒绗竴娆℃墽琛屾椂鍐嶈缃负 RUNNING
deviceCoordinationService.syncDeviceStatus(device,
- DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
return future;
} catch (Exception e) {
log.error("鍚姩鍗ц浆绔嬭澶囧畾鏃跺櫒澶辫触: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
@@ -533,39 +665,103 @@
final long MONITOR_INTERVAL_MS = 2_000; // 2绉掔洃鎺т竴娆�
final AtomicInteger lastProcessedCount = new AtomicInteger(0);
- log.info("鍚姩杩涚墖澶ц溅璁惧瀹氭椂鍣�: taskId={}, deviceId={}, interval={}s",
+ log.debug("鍚姩杩涚墖澶ц溅璁惧瀹氭椂鍣�: taskId={}, deviceId={}, interval={}s",
task.getTaskId(), device.getId(), MONITOR_INTERVAL_MS / 1000);
// 鍚姩瀹氭椂浠诲姟
ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(() -> {
try {
if (isTaskCancelled(context)) {
- log.info("浠诲姟宸插彇娑堬紝鍋滄杩涚墖澶ц溅瀹氭椂鍣�: taskId={}, deviceId={}",
+ log.debug("浠诲姟宸插彇娑堬紝鍋滄杩涚墖澶ц溅瀹氭椂鍣�: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
- // 妫�鏌ユ槸鍚︽湁宸叉壂鎻忕殑鐜荤拑淇℃伅
- List<String> scannedGlassIds = getScannedGlassIds(context);
- if (CollectionUtils.isEmpty(scannedGlassIds)) {
- // 娌℃湁宸叉壂鎻忕殑鐜荤拑锛岀‘淇濆崸杞珛鎵爜缁х画杩愯
- setScannerPause(context, false);
+ // 宸插畬鎴�/澶辫触鐨勬楠や笉鍐嶅洖閫�鐘舵��
+ if (TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())
+ || TaskStepDetail.Status.FAILED.name().equals(step.getStatus())) {
+ return;
+ }
+ // 杩涚墖澶ц溅璁惧锛氬彧鏈夊湪鐪熸寮�濮嬪鐞嗘椂鎵嶈缃负RUNNING
+ // 鍏堟鏌ュ崸杞珛璁惧鏄惁宸插畬鎴愶紝濡傛灉杩樺湪鎵ц涓紝涓嶅簲璇ュ紑濮嬪ぇ杞︾殑宸ヤ綔
+ boolean transferCompleted = isTransferDeviceCompleted(task.getTaskId(), context);
+ if (!transferCompleted) {
+ // 鍗ц浆绔嬭繕鍦ㄦ墽琛屼腑锛岀瓑寰呭崸杞珛瀹屾垚
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟鍗ц浆绔嬪畬鎴�");
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ log.debug("鍗ц浆绔嬭繕鍦ㄦ墽琛屼腑锛岃繘鐗囧ぇ杞︾瓑寰�: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
return;
}
- // 濡傛灉鐜荤拑ID鏁伴噺娌℃湁鍙樺寲锛岃鏄庢病鏈夋柊鐨勭幓鐠冿紝缁х画绛夊緟
- int currentCount = scannedGlassIds.size();
+ // 妫�鏌ユ槸鍚︽湁鍗ц浆绔嬩富浣撳凡杈撳嚭銆佸噯澶囦笂澶ц溅鐨勭幓鐠冧俊鎭�
+ List<String> readyGlassIds = getTransferReadyGlassIds(context);
+
+ // 濡傛灉褰撳墠娌℃湁鏂扮殑鐜荤拑锛屼絾鍗ц浆绔嬪凡瀹屾垚锛屽彲浠ヨ疆璇ES浠诲姟/纭鐘舵��
+ if (CollectionUtils.isEmpty(readyGlassIds)) {
+ // 妫�鏌ユ槸鍚︽墍鏈夊垵濮嬬幓鐠冮兘宸茶杞�
+ @SuppressWarnings("unchecked")
+ List<String> initialGlassIds = (List<String>) context.getSharedData().get("initialGlassIds");
+ List<String> loadedGlassIds = getLoadedGlassIds(context);
+
+ if (initialGlassIds != null && !initialGlassIds.isEmpty()) {
+ // 濡傛灉鎵�鏈夊垵濮嬬幓鐠冮兘宸茶杞斤紝璇存槑宸茬粡澶勭悊瀹岋紝涓嶅簲璇ュ啀鍙樺洖绛夊緟
+ if (loadedGlassIds != null && !loadedGlassIds.isEmpty()
+ && loadedGlassIds.containsAll(initialGlassIds)) {
+ // 鎵�鏈夌幓鐠冮兘宸茶杞斤紝淇濇寔RUNNING鐘舵�侊紝缁х画杞MES浠诲姟/纭
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ pollMesForVehicle(task, step, device, context);
+ return;
+ }
+ }
+
+ // 濡傛灉澶ц溅宸茬粡瑁呰浇杩囩幓鐠冿紙RUNNING鐘舵�侊級锛岃疆璇ES浠诲姟/纭鐘舵��
+ if (TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ pollMesForVehicle(task, step, device, context);
+ } else {
+ // 濡傛灉杩樻病鏈夎杞借繃鐜荤拑锛岀瓑寰呭崸杞珛杈撳嚭
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟鍗ц浆绔嬭緭鍑虹幓鐠�");
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ }
+ return;
+ }
+
+ // 濡傛灉鐜荤拑ID鏁伴噺娌℃湁鍙樺寲锛岃鏄庢病鏈夋柊鐨勭幓鐠�
+ int currentCount = readyGlassIds.size();
if (currentCount == lastProcessedCount.get()) {
+ // 鐜荤拑鏁伴噺娌℃湁鍙樺寲锛氭病鏈夋柊鐜荤拑锛屼絾浠嶉渶杞MES浠诲姟/纭锛岄伩鍏嶉敊杩嘙ES渚х殑鍙樺寲
+ pollMesForVehicle(task, step, device, context);
log.debug("澶ц溅璁惧瀹氭椂鍣細鐜荤拑ID鏁伴噺鏈彉鍖栵紝缁х画绛夊緟: taskId={}, deviceId={}, count={}",
task.getTaskId(), device.getId(), currentCount);
return;
}
- log.info("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄦ娴嬪埌鏂扮殑鐜荤拑淇℃伅: taskId={}, deviceId={}, glassCount={}",
+ log.debug("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄦ娴嬪埌鍗ц浆绔嬭緭鍑虹殑鐜荤拑淇℃伅: taskId={}, deviceId={}, glassCount={}",
task.getTaskId(), device.getId(), currentCount);
// 妫�鏌ュ閲�
Map<String, Object> checkParams = new HashMap<>();
- checkParams.put("glassIds", new ArrayList<>(scannedGlassIds));
+ checkParams.put("glassIds", new ArrayList<>(readyGlassIds));
checkParams.put("_taskContext", context);
DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
@@ -575,33 +771,126 @@
if (logicParams != null && !logicParams.isEmpty()) {
checkParams.put("_logicParams", logicParams);
}
- DevicePlcVO.OperationResult result = handler.execute(device, "feedGlass", checkParams);
+ // 绗竴姝ワ細鍐欏叆澶ц溅涓婃枡璇锋眰
+ DevicePlcVO.OperationResult feedResult = handler.execute(device, "feedGlass", checkParams);
- if (Boolean.TRUE.equals(result.getSuccess())) {
- log.info("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄦ墽琛屾垚鍔�: taskId={}, deviceId={}, glassCount={}",
- task.getTaskId(), device.getId(), scannedGlassIds.size());
+ if (Boolean.TRUE.equals(feedResult.getSuccess())) {
+ // 鐪熸寮�濮嬪鐞嗭紝璁剧疆涓篟UNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ // 姝ラ鐘舵�佷篃璁剧疆涓篟UNNING
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ log.debug("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄦ墽琛屾垚鍔�: taskId={}, deviceId={}, glassCount={}",
+ task.getTaskId(), device.getId(), readyGlassIds.size());
// 灏嗗凡瑁呰浇鐨勭幓鐠僆D淇濆瓨鍒板叡浜暟鎹腑锛堜緵澶х悊鐗囩浣跨敤锛�
- setLoadedGlassIds(context, new ArrayList<>(scannedGlassIds));
- // 娓呯┖宸叉壂鎻忕殑鐜荤拑ID鍒楄〃锛堝凡澶勭悊锛�
- clearScannedGlassIds(context);
+ setLoadedGlassIds(context, new ArrayList<>(readyGlassIds));
+ // 娓呯┖鍗ц浆绔嬭緭鍑虹殑鐜荤拑ID鍒楄〃锛堝凡澶勭悊锛�
+ clearTransferReadyGlassIds(context);
lastProcessedCount.set(0);
// 纭繚鍗ц浆绔嬫壂鐮佺户缁繍琛�
setScannerPause(context, false);
+
+ // feedGlass鎴愬姛鍚庯紝鍏堟鏌ES浠诲姟锛坈heckMesTask锛夋潵寮�濮嬫墽琛屼换鍔�
+ DevicePlcVO.OperationResult mesTaskResult = null;
+ try {
+ mesTaskResult = handler.execute(device, "checkMesTask", Collections.emptyMap());
+ if (mesTaskResult != null && Boolean.TRUE.equals(mesTaskResult.getSuccess())) {
+ log.info("杩涚墖澶ц溅璁惧宸叉鏌ES浠诲姟骞跺紑濮嬫墽琛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), mesTaskResult.getMessage());
+ }
+ } catch (Exception e) {
+ log.warn("杩涚墖澶ц溅璁惧妫�鏌ES浠诲姟寮傚父: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
} else {
- // 瑁呬笉涓嬶紝閫氱煡鍗ц浆绔嬫壂鐮佹殏鍋�
- log.warn("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄥ閲忎笉瓒�: taskId={}, deviceId={}, message={}, 宸查�氱煡鍗ц浆绔嬫壂鐮佹殏鍋�",
- task.getTaskId(), device.getId(), result.getMessage());
- setScannerPause(context, true);
+ // 瑁呬笉涓嬶紝淇濇寔WAITING鐘舵�佸拰PENDING姝ラ鐘舵��
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("瀹归噺涓嶈冻锛岀瓑寰呬腑");
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ // 瑁呬笉涓嬶紝璁板綍瀹归噺涓嶈冻锛堟槸鍚﹂渶瑕佸奖鍝嶆壂鐮佺敱宸ヨ壓鍐嶅喅瀹氾級
+ log.warn("杩涚墖澶ц溅璁惧瀹氭椂鍣ㄥ閲忎笉瓒�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), feedResult.getMessage());
lastProcessedCount.set(currentCount); // 璁板綍褰撳墠鏁伴噺锛岄伩鍏嶉噸澶嶆鏌�
}
- // 鏇存柊姝ラ鐘舵��
- updateStepStatus(step, result);
- boolean opSuccess = Boolean.TRUE.equals(result.getSuccess());
- updateTaskProgress(task, step.getStepOrder(), opSuccess);
- if (!opSuccess) {
- deviceCoordinationService.syncDeviceStatus(device,
- DeviceCoordinationService.DeviceStatus.FAILED, context);
+ // 绗簩姝ワ細妫�鏌ES纭鐘舵�侊紙濡傛灉澶ц溅澶勭悊鍣ㄦ敮鎸佺殑璇濓級
+ // 鍙湁鍦ㄤ换鍔″凡寮�濮嬫墽琛岋紙鏈変换鍔¤褰曪級鏃舵墠妫�鏌ES纭
+ DevicePlcVO.OperationResult mesResult = null;
+ try {
+ mesResult = handler.execute(device, "checkMesConfirm", Collections.emptyMap());
+ } catch (Exception e) {
+ log.warn("杩涚墖澶ц溅璁惧妫�鏌ES纭鐘舵�佸紓甯�: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 濡傛灉MES宸茬‘璁ゅ畬鎴愶紙mesConfirm=1锛夛紝妫�鏌ュ崸杞珛璁惧鐘舵�佸拰鐜荤拑淇℃伅
+ // 濡傛灉鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冮兘宸茶杞斤紝鍙互鏍囪涓哄畬鎴�
+ if (mesResult != null && mesResult.getData() != null) {
+ Object completedFlag = mesResult.getData().get("completed");
+ boolean mesConfirmed = false;
+ if (completedFlag instanceof Boolean) {
+ mesConfirmed = (Boolean) completedFlag;
+ } else if (completedFlag != null) {
+ mesConfirmed = "true".equalsIgnoreCase(String.valueOf(completedFlag));
+ }
+
+ if (mesConfirmed) {
+ // MES宸茬‘璁ゅ畬鎴愶紝妫�鏌ュ崸杞珛璁惧鏄惁宸插畬鎴�
+ boolean transferCompletedForMes = isTransferDeviceCompleted(task.getTaskId(), context);
+ if (transferCompletedForMes) {
+ // 妫�鏌ヤ换鍔′笂涓嬫枃涓殑鍒濆鐜荤拑ID鍜屽凡瑁呰浇鐨勭幓鐠僆D
+ @SuppressWarnings("unchecked")
+ List<String> initialGlassIds = (List<String>) context.getSharedData().get("initialGlassIds");
+ List<String> loadedGlassIds = getLoadedGlassIds(context);
+
+ if (initialGlassIds != null && !initialGlassIds.isEmpty()
+ && loadedGlassIds != null && !loadedGlassIds.isEmpty()) {
+ // 妫�鏌ユ槸鍚︽墍鏈夊垵濮嬬幓鐠冮兘宸茶杞�
+ boolean allGlassesLoaded = loadedGlassIds.containsAll(initialGlassIds);
+ if (allGlassesLoaded) {
+ // 鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冮兘宸茶杞斤紝鏍囪涓哄畬鎴�
+ log.info("MES宸茬‘璁や笖鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冨凡瑁呰浇锛屼换鍔¤嚜鍔ㄥ畬鎴�: taskId={}, deviceId={}, initialCount={}, loadedCount={}",
+ task.getTaskId(), device.getId(), initialGlassIds.size(), loadedGlassIds.size());
+ // mesResult宸茬粡鍖呭惈completed=true锛屼笉闇�瑕佷慨鏀�
+ }
+ }
+ } else {
+ // 鍗ц浆绔嬭繕鏈畬鎴愶紝涓嶅簲璇ユ爣璁颁负瀹屾垚
+ log.debug("MES宸茬‘璁や絾鍗ц浆绔嬫湭瀹屾垚锛岀瓑寰呭崸杞珛瀹屾垚: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
+ }
+ }
+ }
+
+ // 鏇存柊姝ラ鐘舵�侊紙澶ц溅璁惧淇濇寔RUNNING锛岀洿鍒癕ES纭瀹屾垚鎴栦换鍔″彇娑堬級
+ if (mesResult != null) {
+ updateStepStatusForVehicle(task.getTaskId(), step, mesResult);
+ boolean opSuccess = Boolean.TRUE.equals(mesResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
+ } else {
+ updateStepStatusForVehicle(task.getTaskId(), step, feedResult);
+ boolean opSuccess = Boolean.TRUE.equals(feedResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
}
}
} catch (Exception e) {
@@ -609,8 +898,9 @@
}
}, 0, MONITOR_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ // 鍦ㄤ覆琛屾墽琛屾ā寮忎笅锛岃澶囧惎鍔ㄥ畾鏃跺櫒鏃跺厛璁剧疆涓� WAITING锛屽畾鏃跺櫒绗竴娆℃墽琛屾椂鍐嶈缃负 RUNNING
deviceCoordinationService.syncDeviceStatus(device,
- DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
return future;
} catch (Exception e) {
log.error("鍚姩杩涚墖澶ц溅璁惧瀹氭椂鍣ㄥけ璐�: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
@@ -628,26 +918,79 @@
try {
final long MONITOR_INTERVAL_MS = 2_000; // 2绉掔洃鎺т竴娆�
- log.info("鍚姩鍑虹墖澶ц溅璁惧瀹氭椂鍣�: taskId={}, deviceId={}, interval={}s",
+ log.debug("鍚姩鍑虹墖澶ц溅璁惧瀹氭椂鍣�: taskId={}, deviceId={}, interval={}s",
task.getTaskId(), device.getId(), MONITOR_INTERVAL_MS / 1000);
// 鍚姩瀹氭椂浠诲姟
ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(() -> {
try {
if (isTaskCancelled(context)) {
- log.info("浠诲姟宸插彇娑堬紝鍋滄鍑虹墖澶ц溅瀹氭椂鍣�: taskId={}, deviceId={}",
+ log.debug("浠诲姟宸插彇娑堬紝鍋滄鍑虹墖澶ц溅瀹氭椂鍣�: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
+ // 鍑虹墖澶ц溅璁惧锛氬彧鏈夊湪鐪熸寮�濮嬪鐞嗘椂鎵嶈缃负RUNNING
// 妫�鏌ユ槸鍚︽湁宸插鐞嗙殑鐜荤拑淇℃伅锛堜粠澶х悊鐗囩鏉ョ殑锛�
List<String> processedGlassIds = getProcessedGlassIds(context);
+ boolean isRunning = TaskStepDetail.Status.RUNNING.name().equals(step.getStatus());
+
+ // 濡傛灉娌℃湁宸插鐞嗙幓鐠冿紝鍒欎笉搴斾富鍔ㄦ妸姝ラ鎷夊埌RUNNING锛屽彧淇濇寔宸茶繍琛岀姸鎬�
if (CollectionUtils.isEmpty(processedGlassIds)) {
- log.debug("鍑虹墖澶ц溅璁惧瀹氭椂鍣細鏆傛棤宸插鐞嗙殑鐜荤拑淇℃伅: taskId={}, deviceId={}",
- task.getTaskId(), device.getId());
+ if (isRunning) {
+ // 宸茬粡鍦ㄨ繍琛岀殑鎯呭喌涓嬶紝缁х画杞MES浠诲姟/纭锛岄伩鍏嶉敊杩囩‘璁�
+ DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
+ if (handler != null) {
+ Map<String, Object> logicParams = parseLogicParams(device);
+
+ // 鍏堟鏌ES浠诲姟锛堝鏋渕esSend=1锛屼細鍒涘缓浠诲姟骞跺紑濮嬫墽琛岋級
+ DevicePlcVO.OperationResult mesTaskResult = null;
+ try {
+ mesTaskResult = handler.execute(device, "checkMesTask", Collections.emptyMap());
+ if (mesTaskResult != null && Boolean.TRUE.equals(mesTaskResult.getSuccess())) {
+ log.info("鍑虹墖澶ц溅璁惧宸叉鏌ES浠诲姟骞跺紑濮嬫墽琛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), mesTaskResult.getMessage());
+ }
+ } catch (Exception e) {
+ log.warn("鍑虹墖澶ц溅璁惧妫�鏌ES浠诲姟寮傚父: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 鐒跺悗妫�鏌ES纭鐘舵�侊紙鍙湁鍦ㄤ换鍔″凡寮�濮嬫墽琛屾椂鎵嶆鏌ワ級
+ DevicePlcVO.OperationResult mesResult = null;
+ try {
+ mesResult = handler.execute(device, "checkMesConfirm", Collections.emptyMap());
+ } catch (Exception e) {
+ log.warn("鍑虹墖澶ц溅璁惧妫�鏌ES纭鐘舵�佸紓甯�: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 鏇存柊姝ラ鐘舵�侊紙澶ц溅璁惧淇濇寔RUNNING锛岀洿鍒癕ES纭瀹屾垚鎴栦换鍔″彇娑堬級
+ if (mesResult != null) {
+ updateStepStatusForVehicle(task.getTaskId(), step, mesResult);
+ boolean opSuccess = Boolean.TRUE.equals(mesResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
+ }
+ }
+ } else {
+ // 鏈繍琛屼笖娌℃湁宸插鐞嗙幓鐠冿紝淇濇寔PENDING
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())
+ && !TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟澶х悊鐗囩澶勭悊瀹屾垚");
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ log.debug("鍑虹墖澶ц溅璁惧瀹氭椂鍣細鏆傛棤宸插鐞嗙殑鐜荤拑淇℃伅: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
+ }
return;
}
- log.info("鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄦ娴嬪埌宸插鐞嗙殑鐜荤拑淇℃伅: taskId={}, deviceId={}, glassCount={}",
+ log.debug("鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄦ娴嬪埌宸插鐞嗙殑鐜荤拑淇℃伅: taskId={}, deviceId={}, glassCount={}",
task.getTaskId(), device.getId(), processedGlassIds.size());
// 鎵ц鍑虹墖鎿嶄綔
@@ -662,25 +1005,80 @@
if (logicParams != null && !logicParams.isEmpty()) {
checkParams.put("_logicParams", logicParams);
}
- DevicePlcVO.OperationResult result = handler.execute(device, "feedGlass", checkParams);
+ // 绗竴姝ワ細鍐欏叆澶ц溅鍑虹墖璇锋眰
+ DevicePlcVO.OperationResult feedResult = handler.execute(device, "feedGlass", checkParams);
- if (Boolean.TRUE.equals(result.getSuccess())) {
- log.info("鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄦ墽琛屾垚鍔�: taskId={}, deviceId={}, glassCount={}",
+ if (Boolean.TRUE.equals(feedResult.getSuccess())) {
+ // 鐪熸寮�濮嬪鐞嗭紝璁剧疆涓篟UNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ // 姝ラ鐘舵�佷篃璁剧疆涓篟UNNING
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
+ log.debug("鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄦ墽琛屾垚鍔�: taskId={}, deviceId={}, glassCount={}",
task.getTaskId(), device.getId(), processedGlassIds.size());
// 娓呯┖宸插鐞嗙殑鐜荤拑ID鍒楄〃锛堝凡澶勭悊锛�
clearProcessedGlassIds(context);
+
+ // feedGlass鎴愬姛鍚庯紝鍏堟鏌ES浠诲姟锛坈heckMesTask锛夋潵寮�濮嬫墽琛屼换鍔�
+ DevicePlcVO.OperationResult mesTaskResult = null;
+ try {
+ mesTaskResult = handler.execute(device, "checkMesTask", Collections.emptyMap());
+ if (mesTaskResult != null && Boolean.TRUE.equals(mesTaskResult.getSuccess())) {
+ log.info("鍑虹墖澶ц溅璁惧宸叉鏌ES浠诲姟骞跺紑濮嬫墽琛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), mesTaskResult.getMessage());
+ }
+ } catch (Exception e) {
+ log.warn("鍑虹墖澶ц溅璁惧妫�鏌ES浠诲姟寮傚父: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
} else {
+ // 娌℃湁鏁版嵁锛屼繚鎸乄AITING鐘舵�佸拰PENDING姝ラ鐘舵��
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟涓�");
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
log.debug("鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄦ墽琛屽け璐�: taskId={}, deviceId={}, message={}",
- task.getTaskId(), device.getId(), result.getMessage());
+ task.getTaskId(), device.getId(), feedResult.getMessage());
}
- // 鏇存柊姝ラ鐘舵��
- updateStepStatus(step, result);
- boolean opSuccess = Boolean.TRUE.equals(result.getSuccess());
- updateTaskProgress(task, step.getStepOrder(), opSuccess);
- if (!opSuccess) {
- deviceCoordinationService.syncDeviceStatus(device,
- DeviceCoordinationService.DeviceStatus.FAILED, context);
+ // 绗簩姝ワ細妫�鏌ES纭鐘舵�侊紙濡傛灉澶ц溅澶勭悊鍣ㄦ敮鎸佺殑璇濓級
+ // 鍙湁鍦ㄤ换鍔″凡寮�濮嬫墽琛岋紙鏈変换鍔¤褰曪級鏃舵墠妫�鏌ES纭
+ DevicePlcVO.OperationResult mesResult = null;
+ try {
+ mesResult = handler.execute(device, "checkMesConfirm", Collections.emptyMap());
+ } catch (Exception e) {
+ log.warn("鍑虹墖澶ц溅璁惧妫�鏌ES纭鐘舵�佸紓甯�: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 鏇存柊姝ラ鐘舵�侊紙澶ц溅璁惧淇濇寔RUNNING锛岀洿鍒癕ES纭瀹屾垚鎴栦换鍔″彇娑堬級
+ if (mesResult != null) {
+ updateStepStatusForVehicle(task.getTaskId(), step, mesResult);
+ boolean opSuccess = Boolean.TRUE.equals(mesResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
+ } else {
+ updateStepStatusForVehicle(task.getTaskId(), step, feedResult);
+ boolean opSuccess = Boolean.TRUE.equals(feedResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
}
}
} catch (Exception e) {
@@ -688,8 +1086,9 @@
}
}, 0, MONITOR_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ // 鍦ㄤ覆琛屾墽琛屾ā寮忎笅锛岃澶囧惎鍔ㄥ畾鏃跺櫒鏃跺厛璁剧疆涓� WAITING锛屽畾鏃跺櫒绗竴娆℃墽琛屾椂鍐嶈缃负 RUNNING
deviceCoordinationService.syncDeviceStatus(device,
- DeviceCoordinationService.DeviceStatus.RUNNING, context);
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
return future;
} catch (Exception e) {
log.error("鍚姩鍑虹墖澶ц溅璁惧瀹氭椂鍣ㄥけ璐�: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
@@ -710,31 +1109,88 @@
Integer processTimeSeconds = getLogicParam(logicParams, "processTimeSeconds", 30);
final long PROCESS_TIME_MS = processTimeSeconds * 1000;
- log.info("鍚姩澶х悊鐗囩璁惧瀹氭椂鍣�: taskId={}, deviceId={}, processTime={}s",
+ log.debug("鍚姩澶х悊鐗囩璁惧瀹氭椂鍣�: taskId={}, deviceId={}, processTime={}s",
task.getTaskId(), device.getId(), processTimeSeconds);
// 鍚姩瀹氭椂浠诲姟
ScheduledFuture<?> future = scheduledExecutor.scheduleWithFixedDelay(() -> {
try {
if (isTaskCancelled(context)) {
- log.info("浠诲姟宸插彇娑堬紝鍋滄澶х悊鐗囩瀹氭椂鍣�: taskId={}, deviceId={}",
+ log.debug("浠诲姟宸插彇娑堬紝鍋滄澶х悊鐗囩瀹氭椂鍣�: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
+ // 濡傛灉姝ラ宸茬粡瀹屾垚锛屼笉鍐嶅鐞�
+ if (TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ // 妫�鏌ユ槸鍚︽墍鏈夊垵濮嬬幓鐠冮兘宸插鐞嗗畬
+ @SuppressWarnings("unchecked")
+ List<String> initialGlassIds = (List<String>) context.getSharedData().get("initialGlassIds");
+ List<String> processedGlassIds = getProcessedGlassIds(context);
+
+ if (initialGlassIds != null && !initialGlassIds.isEmpty()
+ && processedGlassIds != null && !processedGlassIds.isEmpty()
+ && processedGlassIds.containsAll(initialGlassIds)) {
+ // 鎵�鏈夌幓鐠冮兘宸插鐞嗗畬锛屼繚鎸佸畬鎴愮姸鎬�
+ log.debug("澶х悊鐗囩璁惧宸插畬鎴愪笖鎵�鏈夌幓鐠冨凡澶勭悊: taskId={}, deviceId={}, initialCount={}, processedCount={}",
+ task.getTaskId(), device.getId(), initialGlassIds.size(), processedGlassIds.size());
+ return;
+ }
+ }
+
+ // 澶х悊鐗囩璁惧锛氬彧鏈夊湪鐪熸寮�濮嬪鐞嗘椂鎵嶈缃负RUNNING
// 妫�鏌ユ槸鍚︽湁宸茶杞界殑鐜荤拑淇℃伅锛堜粠杩涚墖澶ц溅鏉ョ殑锛�
List<String> loadedGlassIds = getLoadedGlassIds(context);
if (CollectionUtils.isEmpty(loadedGlassIds)) {
+ // 娌℃湁鏁版嵁锛屾鏌ユ槸鍚︽墍鏈夌幓鐠冮兘宸插鐞嗗畬
+ @SuppressWarnings("unchecked")
+ List<String> initialGlassIds = (List<String>) context.getSharedData().get("initialGlassIds");
+ List<String> processedGlassIds = getProcessedGlassIds(context);
+
+ if (initialGlassIds != null && !initialGlassIds.isEmpty()
+ && processedGlassIds != null && !processedGlassIds.isEmpty()
+ && processedGlassIds.containsAll(initialGlassIds)) {
+ // 鎵�鏈夌幓鐠冮兘宸插鐞嗗畬锛屾爣璁颁负瀹屾垚
+ if (!TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.COMPLETED.name());
+ step.setSuccessMessage("鎵�鏈夌幓鐠冨凡澶勭悊瀹屾垚");
+ if (step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
+ if (step.getStartTime() != null && step.getEndTime() != null) {
+ step.setDurationMs(step.getEndTime().getTime() - step.getStartTime().getTime());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ checkAndCompleteTaskIfDone(step.getTaskId());
+ }
+ return;
+ }
+
+ // 娌℃湁鏁版嵁涓旀湭瀹屾垚锛屼繚鎸乄AITING鐘舵�佸拰PENDING姝ラ鐘舵��
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
+ if (!TaskStepDetail.Status.PENDING.name().equals(step.getStatus())
+ && !TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ step.setSuccessMessage("绛夊緟杩涚墖澶ц溅瑁呰浇鐜荤拑");
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(task.getTaskId(), step);
+ }
log.debug("澶х悊鐗囩璁惧瀹氭椂鍣細鏆傛棤宸茶杞界殑鐜荤拑淇℃伅: taskId={}, deviceId={}",
task.getTaskId(), device.getId());
return;
}
+
+ // 鏈夋暟鎹紝璁剧疆涓篟UNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.RUNNING, context);
// 妫�鏌ョ幓鐠冩槸鍚﹀凡缁忓鐞嗗畬鎴愶紙閫氳繃澶勭悊鏃堕棿鍒ゆ柇锛�
Long processStartTime = getProcessStartTime(context);
if (processStartTime == null) {
// 绗竴娆℃娴嬪埌鐜荤拑锛岃褰曞紑濮嬪鐞嗘椂闂�
setProcessStartTime(context, System.currentTimeMillis());
- log.info("澶х悊鐗囩璁惧寮�濮嬪鐞�: taskId={}, deviceId={}, glassCount={}, processTime={}s",
+ log.debug("澶х悊鐗囩璁惧寮�濮嬪鐞�: taskId={}, deviceId={}, glassCount={}, processTime={}s",
task.getTaskId(), device.getId(), loadedGlassIds.size(), processTimeSeconds);
return;
}
@@ -748,7 +1204,7 @@
}
// 澶勭悊鏃堕棿宸插埌锛屽畬鎴愪换鍔℃眹鎶�
- log.info("澶х悊鐗囩璁惧澶勭悊瀹屾垚: taskId={}, deviceId={}, glassCount={}, processTime={}s",
+ log.debug("澶х悊鐗囩璁惧澶勭悊瀹屾垚: taskId={}, deviceId={}, glassCount={}, processTime={}s",
task.getTaskId(), device.getId(), loadedGlassIds.size(), processTimeSeconds);
// 灏嗗凡澶勭悊鐨勭幓鐠僆D杞Щ鍒板凡澶勭悊鍒楄〃锛堜緵鍑虹墖澶ц溅浣跨敤锛�
@@ -761,12 +1217,17 @@
step.setErrorMessage(null);
step.setOutputData(toJson(Collections.singletonMap("glassIds", loadedGlassIds)));
taskStepDetailMapper.updateById(step);
+ // 澶х悊鐗囩瀹屾垚鍚庡皾璇曡嚜鍔ㄦ敹灏炬暣涓换鍔�
+ checkAndCompleteTaskIfDone(step.getTaskId());
} catch (Exception e) {
log.error("澶х悊鐗囩璁惧瀹氭椂鍣ㄦ墽琛屽紓甯�: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
}
}, 0, 1_000, TimeUnit.MILLISECONDS); // 姣忕妫�鏌ヤ竴娆�
+ // 鍦ㄤ覆琛屾墽琛屾ā寮忎笅锛岃澶囧惎鍔ㄥ畾鏃跺櫒鏃跺厛璁剧疆涓� WAITING锛屽畾鏃跺櫒绗竴娆℃墽琛屾椂鍐嶈缃负 RUNNING
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.WAITING, context);
return future;
} catch (Exception e) {
log.error("鍚姩澶х悊鐗囩璁惧瀹氭椂鍣ㄥけ璐�: taskId={}, deviceId={}", task.getTaskId(), device.getId(), e);
@@ -813,7 +1274,14 @@
*/
private void setLoadedGlassIds(TaskExecutionContext context, List<String> glassIds) {
if (context != null) {
- context.getSharedData().put("loadedGlassIds", new ArrayList<>(glassIds));
+ // 绱姞璁板綍锛岄伩鍏嶅悗缁� containsAll 鍒ゆ柇鍥犺鐩栦涪澶卞巻鍙茬幓鐠冭�屽洖閫�涓虹瓑寰�
+ List<String> merged = new ArrayList<>(getLoadedGlassIds(context)); // 纭繚鍙彉
+ if (glassIds != null) {
+ merged.addAll(glassIds);
+ }
+ // 鍘婚噸
+ List<String> distinct = merged.stream().distinct().collect(java.util.stream.Collectors.toList());
+ context.getSharedData().put("loadedGlassIds", distinct);
}
}
@@ -942,6 +1410,30 @@
context.getSharedData().put("scannedGlassIds", new ArrayList<>());
}
}
+
+ /**
+ * 鑾峰彇鍗ц浆绔嬩富浣撳凡杈撳嚭銆佸噯澶囦笂澶ц溅鐨勭幓鐠僆D鍒楄〃
+ */
+ @SuppressWarnings("unchecked")
+ private List<String> getTransferReadyGlassIds(TaskExecutionContext context) {
+ if (context == null) {
+ return Collections.emptyList();
+ }
+ Object glassIds = context.getSharedData().get("transferReadyGlassIds");
+ if (glassIds instanceof List) {
+ return new ArrayList<>((List<String>) glassIds);
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * 娓呯┖鍗ц浆绔嬩富浣撳凡杈撳嚭鐨勭幓鐠僆D鍒楄〃
+ */
+ private void clearTransferReadyGlassIds(TaskExecutionContext context) {
+ if (context != null) {
+ context.getSharedData().put("transferReadyGlassIds", new ArrayList<>());
+ }
+ }
/**
* 娉ㄥ唽瀹氭椂鍣ㄤ换鍔�
@@ -961,7 +1453,7 @@
future.cancel(false);
}
}
- log.info("宸插仠姝换鍔$殑鎵�鏈夊畾鏃跺櫒: taskId={}, count={}", taskId, futures.size());
+ log.debug("宸插仠姝换鍔$殑鎵�鏈夊畾鏃跺櫒: taskId={}, count={}", taskId, futures.size());
}
runningTaskContexts.remove(taskId);
}
@@ -977,7 +1469,7 @@
long timeoutMs = timeoutMinutes * 60 * 1000;
long deadline = System.currentTimeMillis() + timeoutMs;
- log.info("绛夊緟瀹氭椂鍣ㄤ换鍔″畬鎴�: taskId={}, timeout={}鍒嗛挓", taskId, timeoutMinutes);
+ log.debug("绛夊緟瀹氭椂鍣ㄤ换鍔″畬鎴�: taskId={}, timeout={}鍒嗛挓", taskId, timeoutMinutes);
while (System.currentTimeMillis() < deadline) {
List<ScheduledFuture<?>> futures = taskScheduledTasks.get(taskId);
@@ -1006,7 +1498,54 @@
}
}
- log.info("瀹氭椂鍣ㄤ换鍔$瓑寰呭畬鎴�: taskId={}", taskId);
+ log.debug("瀹氭椂鍣ㄤ换鍔$瓑寰呭畬鎴�: taskId={}", taskId);
+ }
+
+ /**
+ * 褰撴煇涓楠ゅ彲鑳藉畬鎴愭椂锛屾鏌ヤ换鍔℃槸鍚︽墍鏈夋楠ら兘宸插畬鎴愶紝濡傛灉鏄垯鑷姩灏嗕换鍔℃爣璁颁负宸插畬鎴�
+ */
+ private void checkAndCompleteTaskIfDone(String taskId) {
+ if (taskId == null) {
+ return;
+ }
+ try {
+ MultiDeviceTask task = multiDeviceTaskMapper.selectOne(
+ Wrappers.<MultiDeviceTask>lambdaQuery()
+ .eq(MultiDeviceTask::getTaskId, taskId)
+ );
+ if (task == null) {
+ return;
+ }
+ // 浠呭湪浠诲姟浠嶄负RUNNING鏃舵墠灏濊瘯鑷姩鏀跺熬
+ if (!MultiDeviceTask.Status.RUNNING.name().equals(task.getStatus())) {
+ return;
+ }
+
+ int totalSteps = task.getTotalSteps() != null ? task.getTotalSteps() : 0;
+ if (totalSteps <= 0) {
+ return;
+ }
+
+ int completedSteps = countCompletedSteps(taskId);
+ if (completedSteps < totalSteps) {
+ return;
+ }
+
+ // 鎵�鏈夋楠ら兘宸插畬鎴愶紝鏀跺熬浠诲姟
+ task.setStatus(MultiDeviceTask.Status.COMPLETED.name());
+ task.setEndTime(new Date());
+ multiDeviceTaskMapper.updateById(task);
+
+ // 鍋滄鎵�鏈夊畾鏃跺櫒
+ stopScheduledTasks(taskId);
+
+ // 閫氱煡浠诲姟瀹屾垚
+ notificationService.notifyTaskStatus(task);
+
+ log.info("鎵�鏈夋楠ゅ凡瀹屾垚锛岃嚜鍔ㄥ皢浠诲姟鏍囪涓哄凡瀹屾垚: taskId={}, totalSteps={}", taskId, totalSteps);
+ } catch (Exception e) {
+ log.warn("妫�鏌ュ苟鑷姩瀹屾垚浠诲姟澶辫触: taskId={}", taskId, e);
+ }
}
/**
@@ -1025,10 +1564,357 @@
if (success) {
// 鎴愬姛鏃讹紝濡傛灉鏈夋秷鎭垯淇濆瓨锛堢敤浜庢彁绀轰俊鎭級锛屽惁鍒欐竻绌�
step.setSuccessMessage(StringUtils.hasText(message) ? message : null);
+ // 濡傛灉鐘舵�佸彉涓哄畬鎴愶紝璁剧疆缁撴潫鏃堕棿
+ if (TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus()) && step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
} else {
// 澶辫触鏃朵繚瀛橀敊璇秷鎭�
step.setErrorMessage(message);
+ // 濡傛灉鐘舵�佸彉涓哄け璐ワ紝璁剧疆缁撴潫鏃堕棿
+ if (TaskStepDetail.Status.FAILED.name().equals(step.getStatus()) && step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
}
+ step.setOutputData(toJson(result));
+ taskStepDetailMapper.updateById(step);
+ if (StringUtils.hasText(step.getTaskId())) {
+ notificationService.notifyStepUpdate(step.getTaskId(), step);
+ }
+ }
+
+ /**
+ * 纭繚姝ラ杩涘叆RUNNING鐘舵�侊紙浠呭湪绗竴娆$湡姝f墽琛屽墠璋冪敤锛�
+ */
+ private void ensureStepRunning(TaskStepDetail step, String taskId) {
+ if (step == null) {
+ return;
+ }
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ taskStepDetailMapper.updateById(step);
+ notificationService.notifyStepUpdate(taskId, step);
+ }
+ }
+
+ /**
+ * 鏇存柊鎵爜璁惧姝ラ鐘舵�侊紙鏄剧ず杩涘害锛屼繚鎸丷UNNING鐘舵�佺洿鍒版墍鏈夌幓鐠冨鐞嗗畬鎴愶級
+ */
+ private void updateStepStatusForScanner(TaskStepDetail step, DevicePlcVO.OperationResult result,
+ int currentIndex, int totalCount,
+ int successCount, int failCount) {
+ if (step == null || result == null) {
+ return;
+ }
+
+ boolean success = Boolean.TRUE.equals(result.getSuccess());
+
+ // 淇濇寔RUNNING鐘舵�侊紝鐩村埌鎵�鏈夌幓鐠冨鐞嗗畬鎴愶紙鍦ㄥ畾鏃跺櫒瀹屾垚鏃跺啀璁剧疆涓篊OMPLETED锛�
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+
+ // 鏇存柊鏃堕棿鍜岃�楁椂锛屽墠绔彲浠ュ疄鏃剁湅鍒版墽琛岃�楁椂
+ Date now = new Date();
+ if (step.getStartTime() == null) {
+ step.setStartTime(now);
+ }
+ if (step.getStartTime() != null) {
+ step.setDurationMs(now.getTime() - step.getStartTime().getTime());
+ }
+
+ // 鏇存柊杩涘害淇℃伅
+ String progressMessage = String.format("姝e湪澶勭悊 %d/%d (鎴愬姛:%d, 澶辫触:%d)",
+ currentIndex, totalCount, successCount, failCount);
+
+ if (success) {
+ // 鎴愬姛鏃舵樉绀鸿繘搴﹀拰鎴愬姛娑堟伅
+ String resultMessage = result.getMessage();
+ if (StringUtils.hasText(resultMessage)) {
+ step.setSuccessMessage(progressMessage + " - " + resultMessage);
+ } else {
+ step.setSuccessMessage(progressMessage);
+ }
+ step.setErrorMessage(null);
+ } else {
+ // 澶辫触鏃舵樉绀鸿繘搴﹀拰閿欒娑堟伅
+ String errorMessage = result.getMessage();
+ step.setErrorMessage(progressMessage + " - " + (StringUtils.hasText(errorMessage) ? errorMessage : "澶勭悊澶辫触"));
+ step.setSuccessMessage(null);
+ }
+
+ step.setOutputData(toJson(result));
+ taskStepDetailMapper.updateById(step);
+ }
+
+ /**
+ * 鏇存柊澶ц溅璁惧姝ラ鐘舵�侊紙淇濇寔RUNNING锛岀洿鍒版墜鍔ㄥ仠姝㈡垨浠诲姟鍙栨秷锛涘け璐ユ椂鏍囪涓篎AILED锛�
+ */
+ private void updateStepStatusForVehicle(String taskId, TaskStepDetail step, DevicePlcVO.OperationResult result) {
+ if (step == null || result == null) {
+ return;
+ }
+ // 濡傛灉姝ラ宸茬粡澶勪簬瀹屾垚鎴栧け璐ョ姸鎬侊紝鍒欎笉鍐嶈閲嶅鏇存柊锛堥槻姝㈢姸鎬佸弽澶嶅垏鎹級
+ if (TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())
+ || TaskStepDetail.Status.FAILED.name().equals(step.getStatus())) {
+ log.debug("姝ラ宸插畬鎴愭垨澶辫触锛屼笉鍐嶆洿鏂扮姸鎬�: stepId={}, status={}", step.getId(), step.getStatus());
+ return;
+ }
+ boolean success = Boolean.TRUE.equals(result.getSuccess());
+ boolean completed = false;
+ if (result.getData() != null && result.getData().get("completed") != null) {
+ Object flag = result.getData().get("completed");
+ if (flag instanceof Boolean) {
+ completed = (Boolean) flag;
+ } else {
+ completed = "true".equalsIgnoreCase(String.valueOf(flag));
+ }
+ }
+ Date now = new Date();
+
+ // 鍒濆鍖栧紑濮嬫椂闂�
+ if (step.getStartTime() == null) {
+ step.setStartTime(now);
+ }
+
+ boolean waiting = false;
+ String waitingReason = null;
+ if (result.getData() != null) {
+ Object waitingFlag = result.getData().get("waiting");
+ if (waitingFlag instanceof Boolean) {
+ waiting = (Boolean) waitingFlag;
+ } else if (waitingFlag != null) {
+ waiting = "true".equalsIgnoreCase(String.valueOf(waitingFlag));
+ }
+ Object reason = result.getData().get("waitingReason");
+ if (reason != null) {
+ waitingReason = String.valueOf(reason);
+ }
+ }
+
+ if (success && !completed) {
+ // 鎴愬姛浣嗘湭瀹屾垚锛氭牴鎹畐aiting鐘舵�佸喅瀹氭樉绀轰负绛夊緟杩樻槸鎵ц涓�
+ // 娉ㄦ剰锛氬鏋滄楠ゅ凡缁忔槸RUNNING鐘舵�侊紙璇存槑宸茬粡瑁呰浇杩囩幓鐠冿級锛屼笉搴旇鏀瑰洖PENDING
+ boolean isAlreadyRunning = TaskStepDetail.Status.RUNNING.name().equals(step.getStatus());
+ if (waiting && !isAlreadyRunning) {
+ // 鍙湁鍦ㄨ繕娌℃湁寮�濮嬭繍琛屾椂锛屾墠璁剧疆涓篜ENDING
+ step.setStatus(TaskStepDetail.Status.PENDING.name());
+ } else {
+ // 濡傛灉宸茬粡杩愯杩囷紝鎴栬�呬笉鏄瓑寰呯姸鎬侊紝淇濇寔鎴栬缃负RUNNING
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ }
+ String message = result.getMessage();
+ if (!StringUtils.hasText(message) && waiting) {
+ message = "澶ц溅璁惧绛夊緟涓�" + (StringUtils.hasText(waitingReason) ? "锛�" + waitingReason + "锛�" : "");
+ }
+ step.setSuccessMessage(StringUtils.hasText(message) ? message : (waiting && !isAlreadyRunning ? "澶ц溅璁惧绛夊緟涓�" : "澶ц溅璁惧杩愯涓�"));
+ step.setErrorMessage(null);
+ if (step.getStartTime() != null) {
+ step.setDurationMs(now.getTime() - step.getStartTime().getTime());
+ }
+ } else if (success && completed) {
+ // 鎴愬姛涓擬ES宸茬‘璁ゅ畬鎴愶細鏍囪涓篊OMPLETED骞惰褰曠粨鏉熸椂闂�
+ step.setStatus(TaskStepDetail.Status.COMPLETED.name());
+ String message = result.getMessage();
+ step.setSuccessMessage(StringUtils.hasText(message) ? message : "澶ц溅璁惧浠诲姟宸插畬鎴�");
+ step.setErrorMessage(null);
+ if (step.getEndTime() == null) {
+ step.setEndTime(now);
+ }
+ if (step.getStartTime() != null && step.getEndTime() != null) {
+ step.setDurationMs(step.getEndTime().getTime() - step.getStartTime().getTime());
+ }
+ // 灏濊瘯鑷姩鏀跺熬鏁翠釜浠诲姟
+ checkAndCompleteTaskIfDone(step.getTaskId());
+ } else {
+ // 澶辫触锛氭爣璁颁负FAILED骞惰褰曠粨鏉熸椂闂�
+ step.setStatus(TaskStepDetail.Status.FAILED.name());
+ String message = result.getMessage();
+ step.setErrorMessage(message);
+ if (step.getEndTime() == null) {
+ step.setEndTime(now);
+ }
+ if (step.getStartTime() != null && step.getEndTime() != null) {
+ step.setDurationMs(step.getEndTime().getTime() - step.getStartTime().getTime());
+ }
+ }
+
+ step.setOutputData(toJson(result));
+ taskStepDetailMapper.updateById(step);
+ // 閫氱煡鍓嶇姝ラ鐘舵�佸凡鏇存柊
+ notificationService.notifyStepUpdate(taskId, step);
+ }
+
+ /**
+ * 杞澶ц溅璁惧鐨凪ES浠诲姟鍜岀‘璁ょ姸鎬�
+ * 鏃犺姝ラ褰撳墠鏄惁涓篟UNNING/PENDING锛岄兘鍙互璋冪敤锛岀敤浜庨伩鍏嶉敊杩嘙ES绔悗鍐欏叆鐨勪换鍔�
+ */
+ private void pollMesForVehicle(MultiDeviceTask task,
+ TaskStepDetail step,
+ DeviceConfig device,
+ TaskExecutionContext context) {
+ try {
+ DeviceLogicHandler handler = handlerFactory.getHandler(device.getDeviceType());
+ if (handler == null) {
+ return;
+ }
+
+ Map<String, Object> logicParams = parseLogicParams(device);
+
+ // 鍏堟鏌ES浠诲姟锛堝鏋渕esSend=1锛屼細鍒涘缓浠诲姟骞跺紑濮嬫墽琛岋級
+ DevicePlcVO.OperationResult mesTaskResult = null;
+ try {
+ mesTaskResult = handler.execute(device, "checkMesTask", Collections.emptyMap());
+ if (mesTaskResult != null && Boolean.TRUE.equals(mesTaskResult.getSuccess())) {
+ log.info("澶ц溅璁惧宸叉鏌ES浠诲姟骞跺紑濮嬫墽琛�: taskId={}, deviceId={}, message={}",
+ task.getTaskId(), device.getId(), mesTaskResult.getMessage());
+ }
+ } catch (Exception e) {
+ log.warn("澶ц溅璁惧妫�鏌ES浠诲姟寮傚父: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 鐒跺悗妫�鏌ES纭鐘舵��
+ DevicePlcVO.OperationResult mesResult = null;
+ try {
+ mesResult = handler.execute(device, "checkMesConfirm", Collections.emptyMap());
+ } catch (Exception e) {
+ log.warn("澶ц溅璁惧妫�鏌ES纭鐘舵�佸紓甯�: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+
+ // 濡傛灉MES宸茬‘璁ゅ畬鎴愶紙mesConfirm=1锛夛紝妫�鏌ュ崸杞珛璁惧鐘舵�佸拰鐜荤拑淇℃伅
+ // 濡傛灉鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冮兘宸茶杞斤紝鍙互鏍囪涓哄畬鎴�
+ if (mesResult != null && mesResult.getData() != null) {
+ Object completedFlag = mesResult.getData().get("completed");
+ boolean mesConfirmed = false;
+ if (completedFlag instanceof Boolean) {
+ mesConfirmed = (Boolean) completedFlag;
+ } else if (completedFlag != null) {
+ mesConfirmed = "true".equalsIgnoreCase(String.valueOf(completedFlag));
+ }
+
+ if (mesConfirmed) {
+ // MES宸茬‘璁ゅ畬鎴愶紝妫�鏌ュ崸杞珛璁惧鏄惁宸插畬鎴�
+ boolean transferCompleted = isTransferDeviceCompleted(task.getTaskId(), context);
+ if (transferCompleted) {
+ // 妫�鏌ヤ换鍔′笂涓嬫枃涓殑鍒濆鐜荤拑ID鍜屽凡瑁呰浇鐨勭幓鐠僆D
+ @SuppressWarnings("unchecked")
+ List<String> initialGlassIds = (List<String>) context.getSharedData().get("initialGlassIds");
+ List<String> loadedGlassIds = getLoadedGlassIds(context);
+
+ if (initialGlassIds != null && !initialGlassIds.isEmpty()
+ && loadedGlassIds != null && !loadedGlassIds.isEmpty()) {
+ // 妫�鏌ユ槸鍚︽墍鏈夊垵濮嬬幓鐠冮兘宸茶杞�
+ boolean allGlassesLoaded = loadedGlassIds.containsAll(initialGlassIds);
+ if (allGlassesLoaded) {
+ // 鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冮兘宸茶杞斤紝鏍囪涓哄畬鎴�
+ log.info("MES宸茬‘璁や笖鍗ц浆绔嬪凡瀹屾垚涓旀墍鏈夌幓鐠冨凡瑁呰浇锛屼换鍔¤嚜鍔ㄥ畬鎴�: taskId={}, deviceId={}, initialCount={}, loadedCount={}",
+ task.getTaskId(), device.getId(), initialGlassIds.size(), loadedGlassIds.size());
+ // mesResult宸茬粡鍖呭惈completed=true锛屼笉闇�瑕佷慨鏀�
+ }
+ }
+ } else {
+ // 鍗ц浆绔嬭繕鏈畬鎴愶紝涓嶅簲璇ユ爣璁颁负瀹屾垚
+ log.debug("MES宸茬‘璁や絾鍗ц浆绔嬫湭瀹屾垚锛岀瓑寰呭崸杞珛瀹屾垚: taskId={}, deviceId={}",
+ task.getTaskId(), device.getId());
+ }
+ }
+ }
+
+ // 鏇存柊姝ラ鐘舵��
+ if (mesResult != null) {
+ updateStepStatusForVehicle(task.getTaskId(), step, mesResult);
+ boolean opSuccess = Boolean.TRUE.equals(mesResult.getSuccess());
+ updateTaskProgress(task, step.getStepOrder(), opSuccess);
+ if (!opSuccess) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.FAILED, context);
+ }
+ }
+ } catch (Exception e) {
+ log.warn("杞澶ц溅璁惧MES浠诲姟/纭鐘舵�佸紓甯�: taskId={}, deviceId={}, error={}",
+ task.getTaskId(), device.getId(), e.getMessage());
+ }
+ }
+
+ /**
+ * 鏇存柊鍗ц浆绔嬭澶囨楠ょ姸鎬侊紙鍖哄垎绛夊緟涓拰鐪熸瀹屾垚锛�
+ */
+ private void updateStepStatusForTransfer(TaskStepDetail step, DevicePlcVO.OperationResult result,
+ DeviceConfig device, TaskExecutionContext context) {
+ if (step == null || result == null) {
+ return;
+ }
+ boolean success = Boolean.TRUE.equals(result.getSuccess());
+ String message = result.getMessage();
+
+ // 鍒ゆ柇鏄惁鐪熸瀹屾垚锛�
+ // 1. 鍐欏叆PLC鎴愬姛涓旂紦鍐插凡娓呯┖锛堣〃绀烘墍鏈夌幓鐠冨凡澶勭悊瀹岋紝鏃犳柊鐜荤拑锛�
+ // 娉ㄦ剰锛氱紦鍐查槦鍒椾负绌轰笖鏃犲緟澶勭悊鐜荤拑锛屽湪浠诲姟鍒氬紑濮嬫椂涔熷彲鑳藉嚭鐜帮紝涓嶅簲璇ョ珛鍗虫爣璁颁负瀹屾垚
+ // 鍙湁褰撲换鍔″凡缁忚繍琛屼竴娈垫椂闂达紝涓旂‘瀹炴病鏈夌幓鐠冮渶瑕佸鐞嗘椂锛屾墠鏍囪涓哄畬鎴�
+ boolean isRealCompleted = success && message != null && (
+ (message.contains("鎵规宸插啓鍏LC") && message.contains("缂撳啿宸叉竻绌猴紝浠诲姟瀹屾垚"))
+ );
+
+ if (isRealCompleted) {
+ // 鐪熸瀹屾垚锛氳缃负瀹屾垚鐘舵�侊紝骞惰缃粨鏉熸椂闂�
+ // 娉ㄦ剰锛氫竴鏃︽爣璁颁负瀹屾垚锛岀姸鎬佷笉搴旇鍐嶈鏀瑰彉
+ if (!TaskStepDetail.Status.COMPLETED.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.COMPLETED.name());
+ step.setSuccessMessage(message);
+ if (step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
+ // 璁$畻鑰楁椂
+ if (step.getStartTime() != null && step.getEndTime() != null) {
+ step.setDurationMs(step.getEndTime().getTime() - step.getStartTime().getTime());
+ }
+ log.info("鍗ц浆绔嬭澶囨楠ゅ凡瀹屾垚: stepId={}, durationMs={}, message={}",
+ step.getId(), step.getDurationMs(), message);
+ // 鍗ц浆绔嬩富浣撳畬鎴愬悗灏濊瘯鑷姩鏀跺熬鏁翠釜浠诲姟
+ checkAndCompleteTaskIfDone(step.getTaskId());
+ // 鏇存柊璁惧鐘舵�佷负宸插畬鎴�
+ if (device != null) {
+ deviceCoordinationService.syncDeviceStatus(device,
+ DeviceCoordinationService.DeviceStatus.COMPLETED, context);
+ }
+ }
+ } else if (success && message != null && message.contains("鎵规宸插啓鍏LC")) {
+ // 鍐欏叆PLC鎴愬姛浣嗙紦鍐茶繕鏈夌幓鐠冿紙杞︽弧鎯呭喌锛夛紝缁х画杩愯
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ }
+ step.setSuccessMessage(message);
+ // 纭繚寮�濮嬫椂闂村凡璁剧疆
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ } else if (success) {
+ // 璁惧姝e湪宸ヤ綔锛堢瓑寰呯紦鍐层�佺瓑寰呮洿澶氱幓鐠冪瓑锛夛紝淇濇寔RUNNING鐘舵��
+ // 鍥犱负瀹氭椂鍣ㄥ凡缁忔墽琛岋紝璇存槑璁惧宸茬粡寮�濮嬪伐浣滀簡
+ if (!TaskStepDetail.Status.RUNNING.name().equals(step.getStatus())) {
+ step.setStatus(TaskStepDetail.Status.RUNNING.name());
+ }
+ step.setSuccessMessage(message);
+ // 纭繚寮�濮嬫椂闂村凡璁剧疆锛堣澶囧凡缁忓紑濮嬪伐浣滐級
+ if (step.getStartTime() == null) {
+ step.setStartTime(new Date());
+ }
+ } else {
+ // 澶辫触锛氳缃负澶辫触鐘舵�侊紝骞惰缃粨鏉熸椂闂�
+ step.setStatus(TaskStepDetail.Status.FAILED.name());
+ step.setErrorMessage(message);
+ if (step.getEndTime() == null) {
+ step.setEndTime(new Date());
+ }
+ // 璁$畻鑰楁椂
+ if (step.getStartTime() != null && step.getEndTime() != null) {
+ step.setDurationMs(step.getEndTime().getTime() - step.getStartTime().getTime());
+ }
+ }
+
step.setOutputData(toJson(result));
taskStepDetailMapper.updateById(step);
}
@@ -1254,7 +2140,7 @@
}
/**
- * 鍒嗘壒鎵ц澶ц溅璁惧鐜荤拑涓婃枡锛堝綋鐜荤拑ID鏁伴噺瓒呰繃6涓笖璁剧疆浜嗗崟鐗囬棿闅旀椂锛�
+ * 鍒嗘壒鎵ц澶ц溅璁惧鐜荤拑涓婃枡锛堝綋鐜荤拑ID鏁伴噺瓒呰繃6涓椂锛�
*/
private StepResult executeLoadVehicleWithBatches(MultiDeviceTask task,
DeviceConfig device,
@@ -1262,13 +2148,12 @@
TaskExecutionContext context,
List<Map<String, Object>> stepSummaries) {
List<String> allGlassIds = context.getParameters().getGlassIds();
- Integer glassIntervalMs = context.getParameters().getGlassIntervalMs();
int batchSize = 6; // 姣忔壒鏈�澶�6涓幓鐠僆D
// 鍒嗘壒澶勭悊
int totalBatches = (allGlassIds.size() + batchSize - 1) / batchSize;
- log.info("澶ц溅璁惧鍒嗘壒涓婃枡: deviceId={}, totalGlassIds={}, batchSize={}, totalBatches={}, glassIntervalMs={}",
- device.getId(), allGlassIds.size(), batchSize, totalBatches, glassIntervalMs);
+ log.debug("澶ц溅璁惧鍒嗘壒涓婃枡: deviceId={}, totalGlassIds={}, batchSize={}, totalBatches={}",
+ device.getId(), allGlassIds.size(), batchSize, totalBatches);
for (int batchIndex = 0; batchIndex < totalBatches; batchIndex++) {
int startIndex = batchIndex * batchSize;
@@ -1278,7 +2163,6 @@
// 鍒涘缓涓存椂鍙傛暟锛屽彧鍖呭惈褰撳墠鎵规鐨勭幓鐠僆D
TaskParameters batchParams = new TaskParameters();
batchParams.setGlassIds(new ArrayList<>(batchGlassIds));
- batchParams.setGlassIntervalMs(glassIntervalMs);
batchParams.setPositionCode(context.getParameters().getPositionCode());
batchParams.setPositionValue(context.getParameters().getPositionValue());
@@ -1299,20 +2183,8 @@
return stepResult;
}
- log.info("澶ц溅璁惧鍒嗘壒涓婃枡鎴愬姛: deviceId={}, batchIndex={}/{}, glassIds={}",
+ log.debug("澶ц溅璁惧鍒嗘壒涓婃枡鎴愬姛: deviceId={}, batchIndex={}/{}, glassIds={}",
device.getId(), batchIndex + 1, totalBatches, batchGlassIds);
-
- // 濡傛灉涓嶆槸鏈�鍚庝竴鎵癸紝绛夊緟闂撮殧锛堟ā鎷熺幓鐠冩瘡鐗囪繍鍔ㄧ殑鏃堕棿锛�
- // 杩欎釜绛夊緟璁╁ぇ杞︽湁鏃堕棿澶勭悊褰撳墠鎵规鐨勭幓鐠冿紝鐒跺悗鍐嶄紶閫掍笅涓�鎵�
- if (batchIndex < totalBatches - 1 && glassIntervalMs != null && glassIntervalMs > 0) {
- try {
- log.info("绛夊緟鍗曠墖闂撮殧锛堟ā鎷熺幓鐠冭繍鍔ㄦ椂闂达級: glassIntervalMs={}ms, 澶ц溅鍙湪姝ゆ湡闂寸户缁鐜荤拑", glassIntervalMs);
- Thread.sleep(glassIntervalMs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- return StepResult.failure(device.getDeviceName(), "绛夊緟鍗曠墖闂撮殧鏃惰涓柇");
- }
- }
}
// 鏇存柊涓婁笅鏂囦腑鐨勫凡鍔犺浇鐜荤拑ID
@@ -1373,7 +2245,7 @@
Map<String, Object> params = buildOperationParams(device, context);
// 灏哻ontext寮曠敤鏀惧叆params锛屼緵璁惧澶勭悊鍣ㄤ娇鐢紙鐢ㄤ簬璁惧鍗忚皟锛�
params.put("_taskContext", context);
- log.info("executeStepWithRetry鏋勫缓鍙傛暟: deviceId={}, deviceType={}, operation={}, paramsKeys={}, params={}",
+ log.debug("executeStepWithRetry鏋勫缓鍙傛暟: deviceId={}, deviceType={}, operation={}, paramsKeys={}, params={}",
device.getId(), device.getDeviceType(), determineOperation(device, params), params.keySet(), params);
step.setInputData(toJson(params));
taskStepDetailMapper.updateById(step);
@@ -1389,7 +2261,7 @@
if (retryAttempt > 0) {
// 閲嶈瘯鍓嶇瓑寰�
long waitTime = retryPolicy.calculateRetryInterval(retryAttempt);
- log.info("姝ラ鎵ц閲嶈瘯: deviceId={}, operation={}, retryAttempt={}/{}, waitTime={}ms",
+ log.debug("姝ラ鎵ц閲嶈瘯: deviceId={}, operation={}, retryAttempt={}/{}, waitTime={}ms",
device.getId(), operation, retryAttempt, retryPolicy.getMaxRetryCount(), waitTime);
Thread.sleep(waitTime);
@@ -1583,7 +2455,7 @@
try {
if (retryAttempt > 0) {
long waitTime = retryPolicy.calculateRetryInterval(retryAttempt);
- log.info("浜や簰姝ラ鎵ц閲嶈瘯: deviceId={}, retryAttempt={}/{}, waitTime={}ms",
+ log.debug("浜や簰姝ラ鎵ц閲嶈瘯: deviceId={}, retryAttempt={}/{}, waitTime={}ms",
device.getId(), retryAttempt, retryPolicy.getMaxRetryCount(), waitTime);
Thread.sleep(waitTime);
@@ -1777,6 +2649,66 @@
}
}
+ /**
+ * 妫�鏌ュ崸杞珛璁惧鏄惁宸插畬鎴�
+ * 杩斿洖true琛ㄧず鍗ц浆绔嬪凡瀹屾垚锛圕OMPLETED锛夛紝鍙互鍒ゆ柇澶ц溅鏄惁瀹屾垚
+ * 杩斿洖false琛ㄧず鍗ц浆绔嬭繕鍦ㄨ繍琛屼腑锛圧UNNING锛夋垨绛夊緟涓紙PENDING锛夛紝涓嶅簲璇ユ爣璁板ぇ杞︿负瀹屾垚
+ */
+ private boolean isTransferDeviceCompleted(String taskId, TaskExecutionContext context) {
+ if (taskId == null || context == null) {
+ return false;
+ }
+ try {
+ // 浠庝笂涓嬫枃涓幏鍙栬澶囧垪琛�
+ @SuppressWarnings("unchecked")
+ List<DeviceConfig> devices = (List<DeviceConfig>) context.getSharedData().get("devices");
+ if (devices == null || devices.isEmpty()) {
+ return false;
+ }
+
+ // 鏌ユ壘鍗ц浆绔嬭澶�
+ DeviceConfig transferDevice = null;
+ for (DeviceConfig device : devices) {
+ if (DeviceConfig.DeviceType.WORKSTATION_TRANSFER.equals(device.getDeviceType())) {
+ transferDevice = device;
+ break;
+ }
+ }
+
+ if (transferDevice == null) {
+ // 娌℃湁鍗ц浆绔嬭澶囷紝杩斿洖true锛堜笉褰卞搷鍒ゆ柇锛�
+ return true;
+ }
+
+ // 鏌ユ壘鍗ц浆绔嬭澶囩殑姝ラ锛堝簲璇ュ彧鏈変竴涓楠わ級
+ List<TaskStepDetail> transferSteps = taskStepDetailMapper.selectList(
+ Wrappers.<TaskStepDetail>lambdaQuery()
+ .eq(TaskStepDetail::getTaskId, taskId)
+ .eq(TaskStepDetail::getDeviceId, transferDevice.getId())
+ .orderByDesc(TaskStepDetail::getStepOrder)
+ .last("LIMIT 1")
+ );
+
+ if (transferSteps == null || transferSteps.isEmpty()) {
+ // 娌℃湁鎵惧埌姝ラ锛岃繑鍥瀎alse锛堝崸杞珛鍙兘杩樻病寮�濮嬶級
+ return false;
+ }
+
+ // 妫�鏌ユ楠ょ姸鎬侊細鍙湁COMPLETED鎵嶇畻瀹屾垚锛孯UNNING鎴朠ENDING閮戒笉绠楀畬鎴�
+ TaskStepDetail transferStep = transferSteps.get(0);
+ String status = transferStep.getStatus();
+ boolean isCompleted = TaskStepDetail.Status.COMPLETED.name().equals(status);
+
+ log.debug("妫�鏌ュ崸杞珛璁惧鐘舵��: taskId={}, deviceId={}, status={}, isCompleted={}",
+ taskId, transferDevice.getId(), status, isCompleted);
+
+ return isCompleted;
+ } catch (Exception e) {
+ log.warn("妫�鏌ュ崸杞珛璁惧鐘舵�佸け璐�: taskId={}", taskId, e);
+ return false;
+ }
+ }
+
private String determineOperation(DeviceConfig device, Map<String, Object> params) {
if (params != null && params.containsKey("operation")) {
Object op = params.get("operation");
@@ -1800,10 +2732,6 @@
if (taskParams.getPositionValue() != null) {
params.put("positionValue", taskParams.getPositionValue());
}
- // 浼犻�掑崟鐗囬棿闅旈厤缃紝濡傛灉浠诲姟鍙傛暟涓湁璁剧疆锛屼紭鍏堜娇鐢ㄤ换鍔″弬鏁扮殑锛屽惁鍒欎娇鐢ㄨ澶囬厤缃殑
- if (taskParams.getGlassIntervalMs() != null) {
- params.put("glassIntervalMs", taskParams.getGlassIntervalMs());
- }
params.put("triggerRequest", true);
break;
case DeviceConfig.DeviceType.LARGE_GLASS:
@@ -1821,13 +2749,13 @@
case DeviceConfig.DeviceType.WORKSTATION_SCANNER:
// 鍗ц浆绔嬫壂鐮佽澶囷細浠庝换鍔″弬鏁颁腑鑾峰彇鐜荤拑ID鍒楄〃锛屽彇绗竴涓綔涓哄綋鍓嶈娴嬭瘯鐨勭幓鐠僆D
// 娉ㄦ剰锛氭壂鐮佽澶囬�氬父閫氳繃瀹氭椂鍣ㄦ墽琛岋紝浣嗗鏋滈�氳繃executeStep鎵ц锛屼篃闇�瑕佷紶閫抔lassId
- log.info("buildOperationParams澶勭悊鎵爜璁惧: deviceId={}, taskParams.glassIds={}, isEmpty={}",
+ log.debug("buildOperationParams澶勭悊鎵爜璁惧: deviceId={}, taskParams.glassIds={}, isEmpty={}",
device.getId(), taskParams.getGlassIds(),
CollectionUtils.isEmpty(taskParams.getGlassIds()));
if (!CollectionUtils.isEmpty(taskParams.getGlassIds())) {
params.put("glassId", taskParams.getGlassIds().get(0));
params.put("glassIds", new ArrayList<>(taskParams.getGlassIds()));
- log.info("buildOperationParams涓烘壂鐮佽澶囨坊鍔爂lassId: deviceId={}, glassId={}, glassIdsSize={}",
+ log.debug("buildOperationParams涓烘壂鐮佽澶囨坊鍔爂lassId: deviceId={}, glassId={}, glassIdsSize={}",
device.getId(), taskParams.getGlassIds().get(0), taskParams.getGlassIds().size());
} else {
log.warn("buildOperationParams鎵爜璁惧glassIds涓虹┖: deviceId={}, taskParams.glassIds={}, taskParams={}",
@@ -1903,7 +2831,7 @@
if (!CollectionUtils.isEmpty(scannerGlassIds)) {
context.getParameters().setGlassIds(new ArrayList<>(scannerGlassIds));
context.setLoadedGlassIds(new ArrayList<>(scannerGlassIds));
- log.info("鍗ц浆绔嬫壂鐮佽幏鍙栧埌鐜荤拑ID: {}", scannerGlassIds);
+ log.debug("鍗ц浆绔嬫壂鐮佽幏鍙栧埌鐜荤拑ID: {}", scannerGlassIds);
} else {
log.warn("鍗ц浆绔嬫壂鐮佹湭鑾峰彇鍒扮幓鐠僆D锛屽悗缁澶囧彲鑳芥棤娉曟墽琛�");
}
--
Gitblit v1.8.0