From fc4e5c458094c6bf5238d7d21291325f19a57adb Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期一, 22 十二月 2025 16:57:21 +0800
Subject: [PATCH] 修改:逻辑交互写入使用plc通讯工厂统一接口

---
 mes-processes/mes-plcSend/src/main/java/com/mes/interaction/BaseDeviceLogicHandler.java |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/BaseDeviceLogicHandler.java b/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/BaseDeviceLogicHandler.java
index d07dc8f..b00a238 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/BaseDeviceLogicHandler.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/BaseDeviceLogicHandler.java
@@ -5,6 +5,8 @@
 import com.mes.device.entity.DeviceConfig;
 import com.mes.device.service.DevicePlcOperationService;
 import com.mes.device.vo.DevicePlcVO;
+import com.mes.plc.client.PlcClient;
+import com.mes.plc.factory.PlcClientFactory;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 
@@ -24,6 +26,39 @@
 
     protected final DevicePlcOperationService devicePlcOperationService;
     protected final ObjectMapper objectMapper = new ObjectMapper();
+    
+    // PlcClientFactory 鍙�夋敞鍏ワ紝濡傛灉瀛愮被闇�瑕佺洿鎺ヤ娇鐢� PlcClient
+    protected PlcClientFactory plcClientFactory;
+    
+    /**
+     * 璁剧疆 PlcClientFactory锛堢敤浜庡瓙绫绘敞鍏ワ級
+     */
+    public void setPlcClientFactory(PlcClientFactory plcClientFactory) {
+        this.plcClientFactory = plcClientFactory;
+    }
+    
+    /**
+     * 鑾峰彇 PLC 瀹㈡埛绔�
+     * 
+     * @param deviceConfig 璁惧閰嶇疆
+     * @return PLC瀹㈡埛绔疄渚嬶紝濡傛灉鑾峰彇澶辫触杩斿洖null
+     */
+    protected PlcClient getPlcClient(DeviceConfig deviceConfig) {
+        if (plcClientFactory == null) {
+            log.warn("PlcClientFactory鏈敞鍏ワ紝鏃犳硶鑾峰彇PLC瀹㈡埛绔�: deviceId={}", deviceConfig.getId());
+            return null;
+        }
+        try {
+            PlcClient client = plcClientFactory.getClient(deviceConfig);
+            if (client == null) {
+                log.error("鑾峰彇PLC瀹㈡埛绔け璐�: deviceId={}", deviceConfig.getId());
+            }
+            return client;
+        } catch (Exception e) {
+            log.error("鑾峰彇PLC瀹㈡埛绔紓甯�: deviceId={}", deviceConfig.getId(), e);
+            return null;
+        }
+    }
 
     @Override
     public DevicePlcVO.OperationResult execute(DeviceConfig deviceConfig, String operation, Map<String, Object> params) {

--
Gitblit v1.8.0