From 366ba040d2447bacd3455299425e3166f1f992bb Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 20 十一月 2025 14:38:32 +0800
Subject: [PATCH] 添加大车、大理片笼以及多设备串行/并行执行写入基础逻辑

---
 mes-processes/mes-plcSend/src/main/java/com/mes/interaction/flow/LoadVehicleInteraction.java |   76 ++++++++++++++++++++++++++++++++------
 1 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/flow/LoadVehicleInteraction.java b/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/flow/LoadVehicleInteraction.java
index 675b6ab..f9a7934 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/flow/LoadVehicleInteraction.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/flow/LoadVehicleInteraction.java
@@ -1,9 +1,12 @@
 package com.mes.interaction.flow;
 
 import com.mes.device.entity.DeviceConfig;
+import com.mes.device.service.DeviceInteractionService;
+import com.mes.device.vo.DevicePlcVO;
 import com.mes.interaction.DeviceInteraction;
 import com.mes.interaction.base.InteractionContext;
 import com.mes.interaction.base.InteractionResult;
+import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
@@ -16,7 +19,10 @@
  * 涓婂ぇ杞︿氦浜掑疄鐜�
  */
 @Component
+@RequiredArgsConstructor
 public class LoadVehicleInteraction implements DeviceInteraction {
+
+    private final DeviceInteractionService deviceInteractionService;
 
     @Override
     public String getDeviceType() {
@@ -25,19 +31,65 @@
 
     @Override
     public InteractionResult execute(InteractionContext context) {
-        List<String> glassIds = context.getParameters().getGlassIds();
-        if (CollectionUtils.isEmpty(glassIds)) {
-            return InteractionResult.waitResult("鏈彁渚涚幓鐠僆D锛岀瓑寰呰緭鍏�", null);
+        try {
+            // 鍓嶇疆鏉′欢楠岃瘉
+            if (context.getCurrentDevice() == null) {
+                return InteractionResult.fail("璁惧閰嶇疆涓嶅瓨鍦�");
+            }
+
+            List<String> glassIds = context.getParameters().getGlassIds();
+            if (CollectionUtils.isEmpty(glassIds)) {
+                return InteractionResult.waitResult("鏈彁渚涚幓鐠僆D锛岀瓑寰呰緭鍏�", null);
+            }
+
+            // 楠岃瘉鐜荤拑ID鏍煎紡
+            for (String glassId : glassIds) {
+                if (glassId == null || glassId.trim().isEmpty()) {
+                    return InteractionResult.fail("鐜荤拑ID涓嶈兘涓虹┖");
+                }
+            }
+
+            // 鏋勫缓PLC鍐欏叆鍙傛暟
+            Map<String, Object> params = new HashMap<>();
+            params.put("glassIds", glassIds);
+            params.put("positionCode", context.getParameters().getPositionCode());
+            params.put("positionValue", context.getParameters().getPositionValue());
+            params.put("triggerRequest", true);
+
+            // 鎵ц瀹為檯鐨凱LC鍐欏叆鎿嶄綔
+            DevicePlcVO.OperationResult plcResult = deviceInteractionService.executeOperation(
+                    context.getCurrentDevice().getId(), 
+                    "feedGlass", 
+                    params
+            );
+
+            // 妫�鏌LC鍐欏叆缁撴灉
+            if (plcResult == null || !Boolean.TRUE.equals(plcResult.getSuccess())) {
+                String errorMsg = plcResult != null ? plcResult.getMessage() : "PLC鍐欏叆鎿嶄綔杩斿洖绌虹粨鏋�";
+                return InteractionResult.fail("PLC鍐欏叆澶辫触: " + errorMsg);
+            }
+
+            // 鎵ц涓婂ぇ杞︽搷浣滐紙鏁版嵁娴佽浆锛�
+            List<String> copied = new ArrayList<>(glassIds);
+            context.setLoadedGlassIds(copied);
+            context.getSharedData().put("glassesFromVehicle", copied);
+            context.getSharedData().put("loadVehicleTime", System.currentTimeMillis());
+
+            // 鍚庣疆鏉′欢妫�鏌�
+            if (context.getLoadedGlassIds().isEmpty()) {
+                return InteractionResult.fail("涓婂ぇ杞︽搷浣滃け璐ワ細鐜荤拑ID鍒楄〃涓虹┖");
+            }
+
+            Map<String, Object> data = new HashMap<>();
+            data.put("loaded", copied);
+            data.put("glassCount", copied.size());
+            data.put("deviceId", context.getCurrentDevice().getId());
+            data.put("deviceCode", context.getCurrentDevice().getDeviceCode());
+            data.put("plcResult", plcResult.getMessage());
+            return InteractionResult.success(data);
+        } catch (Exception e) {
+            return InteractionResult.fail("涓婂ぇ杞︿氦浜掓墽琛屽紓甯�: " + e.getMessage());
         }
-
-        List<String> copied = new ArrayList<>(glassIds);
-        context.setLoadedGlassIds(copied);
-        context.getSharedData().put("glassesFromVehicle", copied);
-
-        Map<String, Object> data = new HashMap<>();
-        data.put("loaded", copied);
-        data.put("glassCount", copied.size());
-        return InteractionResult.success(data);
     }
 }
 

--
Gitblit v1.8.0