From 7e186ce8acbdb0690de064758563d0e58d797d5f Mon Sep 17 00:00:00 2001
From: yxFwq <1>
Date: 星期一, 28 七月 2025 08:07:35 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/JarThread.java |   65 ++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/JarThread.java b/src/main/java/com/zy/core/thread/JarThread.java
index fd92bdd..0a57129 100644
--- a/src/main/java/com/zy/core/thread/JarThread.java
+++ b/src/main/java/com/zy/core/thread/JarThread.java
@@ -121,7 +121,7 @@
                     }
                 }
             } catch (Exception e) {
-                log.error("rgv杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                log.error("jar杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                 initSte();
 //                e.printStackTrace();
             }
@@ -137,7 +137,7 @@
                 readStatus();
 
             } catch (Exception e) {
-                log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                log.error("JAR鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
 
                 initSte();
 //                e.printStackTrace();
@@ -151,34 +151,56 @@
      * 鍒濆鍖栧爢鍨涙満鐘舵��
      */
     private void initSte() {
-        if (null == jarProtocol) {
-            jarProtocol = new JarProtocol();
+        try{
+            if (null == jarProtocol) {
+                jarProtocol = new JarProtocol();
+            }
+            jarProtocol.setJarNo(slave.getId());
+            jarProtocol.setMode( 0);
+            jarProtocol.setStatus(JarStatusType.OFF_LINE);
+            jarProtocol.setJarErr(0);
+
+
+            // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
+            BasJarService service = SpringUtils.getBean(BasJarService.class);
+            if (null != service) {
+                // 鍚屾pakMk
+                BasJar basJar = service.selectById(slave.getId());
+                basJar.setJarNo(slave.getId());
+                if (!service.updateById(jarProtocol.toSqlModel(basJar))){
+                    News.error("纭寲缃恜lc鏁版嵁搴撴洿鏂板け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                }
+
+            }
+        } catch (Exception e){
+            log.error("JAR鍒濆鍖栧紓甯革紒锛侊紒 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         }
-        jarProtocol.setJarNo(slave.getId());
-        jarProtocol.setMode( 0);
-        jarProtocol.setStatus(JarStatusType.OFF_LINE);
-        jarProtocol.setJarErr(0);
     }
 
     @Override
     public boolean connect() {
         boolean result = false;
-        // 涓嶈兘鏈� 妲藉彿 鍜� 鏈烘灦鍙�
-        siemensS7Net = new SiemensS7Net(SiemensPLCS.S200Smart, slave.getIp());
+
+        try{
+            // 涓嶈兘鏈� 妲藉彿 鍜� 鏈烘灦鍙�
+            siemensS7Net = new SiemensS7Net(SiemensPLCS.S200Smart, slave.getIp());
 //        siemensS7Net.setRack(slave.getRack().byteValue());
 //        siemensS7Net.setSlot(slave.getSlot().byteValue());
-        OperateResult connect = siemensS7Net.ConnectServer();
-        if(connect.IsSuccess){
-            result = true;
-            OutputQueue.STE.offer(MessageFormat.format( "銆恵0}銆戠~鍖栫綈plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
-            News.info("纭寲缃恜lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
-        } else {
-            OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戠~鍖栫綈plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
-            News.error("纭寲缃恜lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
-            initSte();
+            OperateResult connect = siemensS7Net.ConnectServer();
+            if(connect.IsSuccess){
+                result = true;
+                OutputQueue.STE.offer(MessageFormat.format( "銆恵0}銆戠~鍖栫綈plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+                News.info("纭寲缃恜lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+            } else {
+                OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戠~鍖栫綈plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] ", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+                News.error("纭寲缃恜lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+                initSte();
+            }
+        } catch (Exception e){
+            log.error("纭寲缃恜lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
         }
-//        melsecMcNet.ConnectClose();
         return result;
+//        melsecMcNet.ConnectClose();
     }
 
     /**
@@ -325,11 +347,12 @@
                 }
             } else {
                 OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆憑1}纭寲缃恜lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
+                initSte();
                 throw new CoolException(MessageFormat.format( "纭寲缃恜lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
             }
         } catch (Exception e) {
 //            e.printStackTrace();
-            log.error(e.getMessage());
+            log.error("纭寲缃恜lc鐘舵�佷俊鎭け璐�"+e.getMessage());
             OutputQueue.STE.offer(MessageFormat.format("銆恵0}銆戣鍙栫~鍖栫綈plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
 //            News.error("璇诲彇绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
             initSte();

--
Gitblit v1.9.1