Selaa lähdekoodia

opcda读取数据,添加服务断开连接,系统自动重连3次,如果再次失败,则停止。opc实时数据接口,返回质量值,增加查看系统磁盘空间接口

zhoupeng 1 vuosi sitten
vanhempi
commit
00a2e92966

+ 28 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/SystemController.java

@@ -0,0 +1,28 @@
+package com.example.opc_da.controller;
+
+import com.example.opc_common.util.Result;
+import com.example.opc_da.service.SystemService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("system")
+@Slf4j
+public class SystemController {
+
+    @Autowired
+    private SystemService systemService;
+
+    /**
+     * 获取系统磁盘空间大小,以及数据库占用空间大小
+     * @return
+     */
+    @GetMapping("/getSystemMemory")
+    public Result getSystemMemory(){
+        return systemService.getSystemMemory();
+    }
+
+}

+ 9 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/SystemService.java

@@ -0,0 +1,9 @@
+package com.example.opc_da.service;
+
+import com.example.opc_common.util.Result;
+
+public interface SystemService {
+
+    Result getSystemMemory();
+
+}

+ 81 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/SystemServiceImpl.java

@@ -0,0 +1,81 @@
+package com.example.opc_da.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.util.Result;
+import com.example.opc_da.service.SystemService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+@Transactional
+@Service
+public class SystemServiceImpl implements SystemService {
+
+    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
+    static final String DB_URL = "jdbc:mysql://localhost:3306/information_schema?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8";
+    static final String USER = "root";
+    static final String PASS = "root";
+
+    @Override
+    public Result getSystemMemory() {
+        Connection connection = null;
+        Statement statement = null;
+        JSONObject jsonObject = new JSONObject();
+        try {
+            //注册驱动
+            Class.forName(JDBC_DRIVER);
+            connection = DriverManager.getConnection(DB_URL, USER, PASS);
+            statement = connection.createStatement();
+            //查看mysql占用磁盘内存
+//            String sql = "SELECT concat( round( sum( ( data_length + index_length + data_free ) / 1024 / 1024 ), 2 ), 'MB' )  AS DATA FROM TABLES";
+            String sql = "SELECT round( sum( ( data_length + index_length + data_free ) / 1024 / 1024 ), 2 )  AS DATA FROM TABLES";
+            ResultSet resultSet = statement.executeQuery(sql);
+            while (resultSet.next()) {
+                jsonObject.put("databaseSpace", resultSet.getBigDecimal("data"));
+                break;
+            }
+            String sql1 = "SHOW VARIABLES LIKE '%datadir%'";
+            ResultSet resultSet1 = statement.executeQuery(sql1);
+            String path = "";
+            while ((resultSet1.next())) {
+                String value = resultSet1.getString("value");
+                jsonObject.put("path", value);
+                path = value.split("\\\\")[0];
+                jsonObject.put("tray", path);
+                break;
+            }
+            resultSet.close();
+            statement.close();
+            connection.close();
+            File[] files = File.listRoots();
+            for (File file : files) {
+                if (path.equals(file.getAbsolutePath().split("\\\\")[0])) {
+                    jsonObject.put("totalSpace", file.getTotalSpace() / 1024 / 1024);
+                    jsonObject.put("usableSpace", file.getUsableSpace() / 1024 / 1024);
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭资源
+            try {
+                if (statement != null) statement.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            try {
+                if (connection != null) connection.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return Result.ok(jsonObject);
+    }
+
+}

+ 92 - 13
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaChangeTask.java

@@ -12,6 +12,7 @@ import com.example.opc_da.dynamicSchedule.CronTaskRegister;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.da.Item;
 import org.openscada.opc.lib.da.*;
 
@@ -82,9 +83,67 @@ public class OpcDaChangeTask extends TimerTask {
         Integer readModeType = itemGroup.getReadModeType();
         Double modeValue = itemGroup.getModeValue();
         Integer dataSourceId = dataSource.getId();
+        SyncAccess access = null;
         try {
             server.connect();
-            SyncAccess access = new SyncAccess(server, 500);
+            server.addStateListener(connected -> {
+                if (!connected) {
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务断开",
+                            "服务断开,马山进行重新连接",
+                            ConstantStr.NO_READ));
+                    Timer listenerTimer = new Timer();
+                    listenerTimer.schedule(new TimerTask() {
+                        private int sum = 0;
+
+                        @Override
+                        public void run() {
+                            try {
+                                sum++;
+                                if (sum > 3) {
+                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                            "3次服务重新连接失败",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                                server.connect();
+                                if (Blank.isNotEmpty(server.getServerState()) && server.getServerState().getServerState() == OPCSERVERSTATE.OPC_STATUS_RUNNING) {
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接成功",
+                                            "服务重新连接成功",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                            } catch (Exception e) {
+                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                String message = OpcDaUtil.genException(e.getMessage());
+                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                        message,
+                                        ConstantStr.NO_READ));
+                                listenerTimer.cancel();
+                            }
+                        }
+                    }, 10000);
+                }
+            });
+        } catch (Exception e) {
+            String message = OpcDaUtil.genException(e.getMessage());
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                    message,
+                    ConstantStr.NO_READ));
+            if (Blank.isNotEmpty(server)) {
+                server.dispose();
+            }
+            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+            cronTaskRegister.removeCronTask(cronId);
+            timer.cancel();
+        }
+        try {
+            access = new SyncAccess(server, 500);
             for (com.example.opc_common.entity.Item item : itemList) {
                 String itemId = item.getItemReadName();
                 access.addItem(itemId, new DataCallback() {
@@ -174,6 +233,9 @@ public class OpcDaChangeTask extends TimerTask {
                             itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                             "服务异常停止了",
                             ConstantStr.NO_READ));
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -188,7 +250,9 @@ public class OpcDaChangeTask extends TimerTask {
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
                     opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
                     redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -203,7 +267,9 @@ public class OpcDaChangeTask extends TimerTask {
                     opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
                     redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -212,17 +278,30 @@ public class OpcDaChangeTask extends TimerTask {
                 }
             }
         } catch (Exception e) {
-            String message = OpcDaUtil.genException(e.getMessage());
-            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                    message,
-                    ConstantStr.NO_READ));
-            if (Blank.isNotEmpty(server)) {
-                server.dispose();
+            try {
+                Thread.sleep(30000);
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+                    cronTaskRegister.removeCronTask(cronId);
+                    timer.cancel();
+                }
+            } catch (Exception ex) {
+                ex.printStackTrace();
             }
-            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
-            cronTaskRegister.removeCronTask(cronId);
-            timer.cancel();
         }
     }
 }

+ 92 - 13
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaExceedTask.java

@@ -11,6 +11,7 @@ import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.dynamicSchedule.CronTaskRegister;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
+import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.da.Item;
 import org.openscada.opc.lib.da.*;
 
@@ -80,9 +81,67 @@ public class OpcDaExceedTask extends TimerTask {
         Integer eventMode = itemGroup.getEventMode();
         Double modeValue = itemGroup.getModeValue();
         Integer dataSourceId = dataSource.getId();
+        SyncAccess access = null;
         try {
             server.connect();
-            SyncAccess access = new SyncAccess(server, 500);
+            server.addStateListener(connected -> {
+                if (!connected) {
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务断开",
+                            "服务断开,马山进行重新连接",
+                            ConstantStr.NO_READ));
+                    Timer listenerTimer = new Timer();
+                    listenerTimer.schedule(new TimerTask() {
+                        private int sum = 0;
+
+                        @Override
+                        public void run() {
+                            try {
+                                sum++;
+                                if (sum > 3) {
+                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                            "3次服务重新连接失败",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                                server.connect();
+                                if (Blank.isNotEmpty(server.getServerState()) && server.getServerState().getServerState() == OPCSERVERSTATE.OPC_STATUS_RUNNING) {
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接成功",
+                                            "服务重新连接成功",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                            } catch (Exception e) {
+                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                String message = OpcDaUtil.genException(e.getMessage());
+                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                        message,
+                                        ConstantStr.NO_READ));
+                                listenerTimer.cancel();
+                            }
+                        }
+                    }, 10000);
+                }
+            });
+        } catch (Exception e) {
+            String message = OpcDaUtil.genException(e.getMessage());
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                    message,
+                    ConstantStr.NO_READ));
+            if (Blank.isNotEmpty(server)) {
+                server.dispose();
+            }
+            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+            cronTaskRegister.removeCronTask(cronId);
+            timer.cancel();
+        }
+        try {
+            access = new SyncAccess(server, 500);
             for (com.example.opc_common.entity.Item item : itemList) {
                 String itemId = item.getItemReadName();
                 Integer isDriverItem = item.getIsDriverItem();
@@ -200,6 +259,9 @@ public class OpcDaExceedTask extends TimerTask {
                             itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                             "服务异常停止了",
                             ConstantStr.NO_READ));
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -214,7 +276,9 @@ public class OpcDaExceedTask extends TimerTask {
                     opcAsyncTask.packageEventTable(itemList, dataSourceId, index);
                     redisUtil.del(ConstantStr.INDEX + id);
 
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -228,7 +292,9 @@ public class OpcDaExceedTask extends TimerTask {
                     opcAsyncTask.packageEventTable(itemList, dataSourceId, index);
                     redisUtil.del(ConstantStr.INDEX + id);
 
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -237,17 +303,30 @@ public class OpcDaExceedTask extends TimerTask {
                 }
             }
         } catch (Exception e) {
-            String message = OpcDaUtil.genException(e.getMessage());
-            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                    message,
-                    ConstantStr.NO_READ));
-            if (Blank.isNotEmpty(server)) {
-                server.dispose();
+            try {
+                Thread.sleep(30000);
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+                    cronTaskRegister.removeCronTask(cronId);
+                    timer.cancel();
+                }
+            } catch (Exception ex) {
+                ex.printStackTrace();
             }
-            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
-            cronTaskRegister.removeCronTask(cronId);
-            timer.cancel();
         }
     }
 }

+ 92 - 14
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaFrequencyTask.java

@@ -12,6 +12,7 @@ import com.example.opc_da.dynamicSchedule.CronTaskRegister;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.da.Item;
 import org.openscada.opc.lib.da.*;
 
@@ -80,9 +81,67 @@ public class OpcDaFrequencyTask extends TimerTask {
         Server server = OpcDaUtil.createServer(dataSource);
         Integer id = itemGroup.getId();
         Integer dataSourceId = dataSource.getId();
+        SyncAccess access = null;
         try {
             server.connect();
-            SyncAccess access = new SyncAccess(server, (int) (Math.round(itemGroup.getModeValue() * 1000)));
+            server.addStateListener(connected -> {
+                if (!connected) {
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务断开",
+                            "服务断开,马山进行重新连接",
+                            ConstantStr.NO_READ));
+                    Timer listenerTimer = new Timer();
+                    listenerTimer.schedule(new TimerTask() {
+                        private int sum = 0;
+
+                        @Override
+                        public void run() {
+                            try {
+                                sum++;
+                                if (sum > 3) {
+                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                            "3次服务重新连接失败",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                                server.connect();
+                                if (Blank.isNotEmpty(server.getServerState()) && server.getServerState().getServerState() == OPCSERVERSTATE.OPC_STATUS_RUNNING) {
+                                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接成功",
+                                            "服务重新连接成功",
+                                            ConstantStr.NO_READ));
+                                    listenerTimer.cancel();
+                                }
+                            } catch (Exception e) {
+                                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                                String message = OpcDaUtil.genException(e.getMessage());
+                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "服务重新连接失败",
+                                        message,
+                                        ConstantStr.NO_READ));
+                                listenerTimer.cancel();
+                            }
+                        }
+                    }, 10000);
+                }
+            });
+        } catch (Exception e) {
+            String message = OpcDaUtil.genException(e.getMessage());
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                    message,
+                    ConstantStr.NO_READ));
+            if (Blank.isNotEmpty(server)) {
+                server.dispose();
+            }
+            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+            cronTaskRegister.removeCronTask(cronId);
+            timer.cancel();
+        }
+        try {
+            access = new SyncAccess(server, (int) (Math.round(itemGroup.getModeValue() * 1000)));
 //            AccessBase access = new Async20Access(server, (int) (itemGroup.getModeValue() * 1000), true);
             for (com.example.opc_common.entity.Item item : itemList) {
                 String itemId = item.getItemReadName();
@@ -172,6 +231,9 @@ public class OpcDaFrequencyTask extends TimerTask {
                             itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                             "服务异常停止了",
                             ConstantStr.NO_READ));
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -186,7 +248,9 @@ public class OpcDaFrequencyTask extends TimerTask {
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
                     opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
                     redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -201,7 +265,9 @@ public class OpcDaFrequencyTask extends TimerTask {
                     opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
                     redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
-                    access.unbind();
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
                     if (Blank.isNotEmpty(server)) {
                         server.dispose();
                     }
@@ -210,18 +276,30 @@ public class OpcDaFrequencyTask extends TimerTask {
                 }
             }
         } catch (Exception e) {
-            String message = OpcDaUtil.genException(e.getMessage());
-            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                    message,
-                    ConstantStr.NO_READ));
-            if (Blank.isNotEmpty(server)) {
-                server.dispose();
+            try {
+                Thread.sleep(30000);
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+                    if (Blank.isNotEmpty(access)) {
+                        access.clear();
+                    }
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
+                    cronTaskRegister.removeCronTask(cronId);
+                    timer.cancel();
+                }
+            } catch (Exception ex) {
+                ex.printStackTrace();
             }
-            itemGroupDao.stopItemGroupById(itemGroup.getId(), ConstantStr.EXCEPT_STOP_UP);
-            cronTaskRegister.removeCronTask(cronId);
-            redisUtil.del(ConstantStr.ITEM_GROUP + id);
-            timer.cancel();
         }
     }
 }

+ 8 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -430,6 +430,7 @@ public class OpcDaUtil {
                             jsonObject.put("dataSourceName", dataSource.getDataSourceName());
                             jsonObject.put("itemName", item.getItemName());
                             jsonObject.put("dataType", javaType);
+                            jsonObject.put("quality", isGood(itemMap.getQuality()));
 //                            jsonObject.put("eventMode", item.getEventMode());
                             jsonObject.put("dataOrgValue", value);
                             if (javaType.toLowerCase().equals("boolean")) {
@@ -471,6 +472,13 @@ public class OpcDaUtil {
         return null;
     }
 
+    public static Boolean isGood(Short quality) {
+        if (quality == 192) {
+            return true;
+        }
+        return false;
+    }
+
     public static String genException(String message) {
         if (Blank.isEmpty(message)) {
             return "通信异常,请联系管理员";

+ 1 - 0
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/util/OpcUaUtil.java

@@ -250,6 +250,7 @@ public class OpcUaUtil {
                 jsonObject.put("dataSourceName", dataSource.getDataSourceName());
                 jsonObject.put("itemName", mapName.get(itemName));
                 StatusCode statusCode = dataValue.getStatusCode();
+                jsonObject.put("quality", statusCode.isGood());
                 Variant value = dataValue.getValue();
                 ExpandedNodeId expandedNodeId = value.getDataType().get();
                 String javaType = OpcUaUtil.getValType(dataValue);