Преглед изворни кода

Merge branch 'master' of http://116.63.33.55/git/read_opc

Zt пре 2 година
родитељ
комит
280ec1a598
100 измењених фајлова са 2521 додато и 3742 уклоњено
  1. 4 4
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/Item.java
  2. 1 1
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/ItemGroup.java
  3. 1 1
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/RawData.java
  4. 2 1
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/OpcDaDriverEnum.java
  5. 5 1
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/util/ConstantStr.java
  6. 2 2
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/PermissionControlAspect.java
  7. 4 4
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/WebLogAspect.java
  8. 1 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/InterceptorConfig.java
  9. 1 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/Interceptors.java
  10. 7 3
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/WebSocket.java
  11. 1 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/ReportTableController.java
  12. 13 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/UserController.java
  13. 3 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/DataModelDao.java
  14. 2 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/ItemGroupDao.java
  15. 16 2
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java
  16. 2 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/UserDao.java
  17. 2 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/UserService.java
  18. 6 4
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataModelServiceImpl.java
  19. 0 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataSourceServiceImpl.java
  20. 115 23
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java
  21. 6 5
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/RawDataServiceImpl.java
  22. 35 2
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java
  23. 28 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/UserServiceImpl.java
  24. 224 54
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java
  25. 243 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaChangeTask.java
  26. 210 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaExceedTask.java
  27. 239 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaFrequencyTask.java
  28. 210 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaLowseTask.java
  29. 0 1844
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaTask.java
  30. 72 70
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTableTask.java
  31. 61 59
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java
  32. 1 1
      chaunyi_opc/opc_da/src/main/resources/application.yml
  33. 12 16
      chaunyi_opc/opc_da/src/main/resources/mapper/DataModelDao.xml
  34. 19 3
      chaunyi_opc/opc_da/src/main/resources/mapper/ItemGroupDao.xml
  35. 70 2
      chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml
  36. 8 5
      chaunyi_opc/opc_da/src/main/resources/mapper/ReportTableDao.xml
  37. 6 0
      chaunyi_opc/opc_da/src/main/resources/mapper/UserDao.xml
  38. 2 2
      chaunyi_opc/opc_da/src/main/resources/static/app/index.html
  39. 1 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/jquery.min.js
  40. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/chunk-vendors.35954aaa.js
  41. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/chunk-vendors.7d651a70.js
  42. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/index.8b6b38d7.js
  43. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/index.c46a03fd.js
  44. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index.921bd4fd.js
  45. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index.c7063e47.js
  46. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index~pages-user-index.44d1c315.js
  47. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index~pages-user-index.be72c672.js
  48. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index.dd1a599d.js
  49. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index.ecc7aa27.js
  50. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-message-msg-detail-index~pages-reportForm-index~pages-reportForm-report-de~7378e1f1.4b1019b3.js
  51. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-message-msg-detail-index~pages-reportForm-index~pages-reportForm-report-de~7378e1f1.ef51d87f.js
  52. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-reportForm-index.c9a4fb74.js
  53. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-reportForm-index.ec286111.js
  54. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-msg-detail-index.62eb5040.js
  55. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-msg-detail-index.a393e18c.js
  56. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-index.3bb42d0b.js
  57. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-index.6dc8493b.js
  58. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-report-detail-index.81d1b26f.js
  59. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-report-detail-index.9c7dfd89.js
  60. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-user-index.9b09c104.js
  61. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-user-index.a6f66f4d.js
  62. 1 1
      chaunyi_opc/opc_da/src/main/resources/static/page/index.html
  63. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-25fa7e82.9033d0a8.css
  64. 0 1
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-27a0e931.1783952f.css
  65. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-6fb8a920.060d547f.css
  66. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-77eaefcc.84f98409.css
  67. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-8edeae9a.dff46571.css
  68. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-f198332e.91c42cb7.css
  69. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/app.5ea0a1d2.js
  70. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/app.ed78cea1.js
  71. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-25fa7e82.5d15f594.js
  72. 0 1
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-27a0e931.c885b15b.js
  73. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-6fb8a920.eb2869a1.js
  74. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-77eaefcc.deafbd58.js
  75. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-8edeae9a.37d67e3e.js
  76. 0 0
      chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-f198332e.8e4a368f.js
  77. 16 1
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/RawDataDao.java
  78. 10 0
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/ReportTableDao.java
  79. 223 33
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcAsyncTask.java
  80. 78 468
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaChangeTask.java
  81. 63 275
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaExceedTask.java
  82. 91 449
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaFrequencyTask.java
  83. 63 283
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaLowerTask.java
  84. 3 12
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaTask.java
  85. 29 46
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/util/OpcUaUtil.java
  86. 4 1
      chaunyi_opc/opc_ua/src/main/resources/application.yml
  87. 2 2
      chaunyi_opc/opc_ua/src/main/resources/mapper/ItemGroupDao.xml
  88. 70 2
      chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml
  89. 13 0
      chaunyi_opc/opc_ua/src/main/resources/mapper/ReportTableDao.xml
  90. 8 0
      chuanyi-admin/src/api/dashboard.js
  91. 0 0
      chuanyi-admin/src/icons/svg/user-manger.svg
  92. 1 0
      chuanyi-admin/src/icons/svg/user-online.svg
  93. 1 0
      chuanyi-admin/src/icons/svg/user-role.svg
  94. 1 0
      chuanyi-admin/src/icons/svg/user-t.svg
  95. 1 0
      chuanyi-admin/src/icons/svg/user-table.svg
  96. 187 54
      chuanyi-admin/src/views/dashboard/index.vue
  97. 0 0
      chuanyi_client2/public/luckysheet/luckysheet.umd.js
  98. 21 0
      chuanyi_client2/public/plugins/echarts.min.js
  99. 0 0
      chuanyi_client2/public/plugins/element.css
  100. 0 0
      chuanyi_client2/public/plugins/element.js

+ 4 - 4
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/Item.java

@@ -38,13 +38,13 @@ public class Item implements Serializable {
     private Integer dataModelId;
 
     /**
-     * 事件驱动产生的条件
+     * 事件驱动产生的条件,0大于,1小于(0,1,值只对应数值类型),2为boolean类型
      */
     private Integer eventMode;
     /**
-     * 事件驱动设定的阀值
+     * 事件驱动设定的阀值(驱动条件为2时,这里只能传入0false或者1true)
      */
-    private Integer eventValue;
+    private Double eventValue;
     /**
      * 事件驱动生成报表需要的报表模板
      */
@@ -53,7 +53,7 @@ public class Item implements Serializable {
     /**
      * 组名称,返回给前端的
      */
-    private Integer itemGroupName;
+    private String itemGroupName;
     /**
      * 四则混合运算表达式,返回给前端的
      */

+ 1 - 1
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/ItemGroup.java

@@ -37,7 +37,7 @@ public class ItemGroup implements Serializable {
     /**
      * 模式值
      */
-    private Integer modeValue;
+    private Double modeValue;
     /**
      * 启动状态:0停用,1启用
      */

+ 1 - 1
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/RawData.java

@@ -56,7 +56,7 @@ public class RawData implements Serializable {
 
     }
 
-    public RawData(Integer dataSourceId, String itemName, String dataType, String dataValue, String dataValueTime, String valueBelongTime, Date createTime) {
+    public RawData(Integer itemGroupId, Integer dataSourceId, String itemName, String dataType, String dataValue, String dataValueTime, String valueBelongTime, Date createTime) {
         this.dataSourceId = dataSourceId;
         this.itemName = itemName;
         this.dataType = dataType;

+ 2 - 1
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/OpcDaDriverEnum.java

@@ -5,7 +5,8 @@ public enum OpcDaDriverEnum {
     OPCIFIX("3C5702A2-EB8E-11D4-83A4-00105A984CBD"),
     WINCC("75D00BBB-DDA5-11D1-B944-9E614D000000"),
     SCADA("04524449-C6B2-4D62-8471-C64FA1DDF64F"),
-    YOKOGAWA("E6C32641-F1CF-11D0-B0E4-080009CCD384");
+    YOKOGAWA("E6C32641-F1CF-11D0-B0E4-080009CCD384"),
+    PAS300("4EA2713D-CA07-11D4-BEF5-00002120DB5E");
 
     private String value;
 

+ 5 - 1
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/util/ConstantStr.java

@@ -87,9 +87,13 @@ public class ConstantStr {
     public static final Integer EXCEED_SET_VALUE = 2;
     public static final Integer LOWER_SET_VALUE = 3;
 
-    //事件驱动条件,0大于,1小于
+    //事件驱动条件,0大于,1小于(0,1,值只对应数值类型),2为boolean类型
     public static final Integer EVENT_MODEL_EXCEED=0;
     public static final Integer EVENT_MODEL_LOWER=1;
+    public static final Integer EVENT_MODEL_BOOLEAN=2;
+
+    public static final Integer BOOLEAN_FALSE=0;
+    public static final Integer BOOLEAN_TRUE=1;
 
     //取值条件
     public static final Integer AVERAGE_VALUE = 0;

+ 2 - 2
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/PermissionControlAspect.java

@@ -99,8 +99,8 @@ public class PermissionControlAspect {
                 for (int i = 0; i < keys.length; i++) {
                     params.put(keys[i], args[i]);
                 }
-                log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
-                log.info("请求的参数有: {}", params.toString());
+//                log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
+//                log.info("请求的参数有: {}", params.toString());
                 return joinPoint.proceed();
             }
         }

+ 4 - 4
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/annotation/WebLogAspect.java

@@ -77,19 +77,19 @@ public class WebLogAspect {
         }
         methodName = declaringTypeName + "." + funcName;
         requestArgs = params.toString();
-        log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
-        log.info("请求的参数有: {}", params.toString());
+//        log.info("即将执行{}包下的方法,方法名为: {}", declaringTypeName, funcName);
+//        log.info("请求的参数有: {}", params.toString());
         return joinPoint.proceed();
     }
 
     @Before(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     public void before(JoinPoint joinPoint) {
-        System.out.println("Before");
+//        System.out.println("Before");
     }
 
     @After(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)")
     public void after() {
-        System.out.println("After");
+//        System.out.println("After");
     }
 
     @AfterReturning(value = "webLog() && @annotation(com.example.opc_da.annotation.WebLog)", returning = "result")

+ 1 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/InterceptorConfig.java

@@ -43,6 +43,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
                 .excludePathPatterns("/static/**")
                 .excludePathPatterns("/page/static/**")
                 .excludePathPatterns("/app/static/**")
+                .excludePathPatterns("/favicon.ico")
 //                .excludePathPatterns("/**")
         ;
     }

+ 1 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/Interceptors.java

@@ -26,7 +26,7 @@ public class Interceptors implements HandlerInterceptor {
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
         String token = request.getHeader("token");
-//        String requestURI = request.getRequestURI();
+        String requestURI = request.getRequestURI();
         if (Blank.isEmpty(token)) {
             throw new CustomException(ResultEnum.LOGIN_EXPIRED.getRespCode(), ResultEnum.LOGIN_EXPIRED.getRespMsg());
         }

+ 7 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/WebSocket.java

@@ -41,7 +41,7 @@ public class WebSocket {
 
     //前端请求一个webSocket时
     @OnOpen
-    public void onOpen(Session session, @PathParam("token") String token)  {
+    public void onOpen(Session session, @PathParam("token") String token) {
 //        log.info("连接websocekt:并且token为:{}", token);
         if (Blank.isNotEmpty(token)) {
             this.userId = Convert.toStr(redisUtil.get(token));
@@ -55,10 +55,11 @@ public class WebSocket {
         this.token = token;
         this.session = session;
         webSocketSet.add(this);
-        if (Blank.isEmpty(token)){
+        if (Blank.isEmpty(token)) {
+//            log.info("因为传入的token为空,所以关闭websocket");
             try {
                 session.close();
-            }catch (Exception e){
+            } catch (Exception e) {
                 e.printStackTrace();
             }
         }
@@ -81,6 +82,7 @@ public class WebSocket {
         }
         Boolean flage = false;
         Object o = redisUtil.get(ConstantStr.WEBSOCKET_STRING + userId);
+//        log.info("校验5秒之后,用户是否重新登录{}",o);
         if (Blank.isNotEmpty(o)) {
             flage = (Boolean) o;
         }
@@ -88,7 +90,9 @@ public class WebSocket {
             return;
         }
         if (Blank.isNotEmpty(userId)) {
+//            log.info("超时了,清空用户信息{}",userId);
             String userLoginType = token.substring(0, 5);
+            redisUtil.del(token);
             if (userLoginType.equals(ConstantStr.FRONT_USER_String)) {
                 redisUtil.del(ConstantStr.FRONT_USER_String + userId);
             } else if (userLoginType.equals(ConstantStr.PHONE_USER_String)) {

+ 1 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/ReportTableController.java

@@ -218,7 +218,7 @@ public class ReportTableController {
      * 报表类型转换
      *
      * @param id
-     * @param isAutoReport 0手动,1自动
+     * @param isAutoReport 0手动,1自动,3事件驱动
      * @return
      */
     @PostMapping("/tableExchangeTypeById")

+ 13 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/UserController.java

@@ -432,4 +432,17 @@ public class UserController {
         return userService.queryManagerUserNum();
     }
 
+    /**
+     * 在线用户人数
+     * @param loginType
+     * @return
+     */
+    @GetMapping("/getOnlineUser")
+    public Result getOnlineUser(String loginType){
+        if (Blank.isEmpty(loginType)){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return userService.getOnlineUser(loginType);
+    }
+
 }

+ 3 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/DataModelDao.java

@@ -2,10 +2,12 @@ package com.example.opc_da.dao;
 
 import com.example.opc_common.entity.DataModel;
 import com.example.opc_common.entity.Item;
+import com.example.opc_common.entity.ItemGroup;
 import com.example.opc_common.entity.TableDataDto;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
+import java.util.Map;
 
 @Repository
 public interface DataModelDao {
@@ -24,5 +26,5 @@ public interface DataModelDao {
 
     List<DataModel> getDmListByItemList(List<Item> itemList);
 
-    List<Item> getItemByDaModel(Integer id);
+    List<Map<String,Object>> getItemGroupByDm(Integer id);
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/ItemGroupDao.java

@@ -48,4 +48,6 @@ public interface ItemGroupDao {
     Item getItemById(Integer id);
 
     String getItemDescribe(Integer itemGroupId, String itemName);
+
+    List<ItemGroup> getItemGroupListByTableId(Integer tableReportId);
 }

+ 16 - 2
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java

@@ -10,7 +10,7 @@ import java.util.Map;
 @Repository
 public interface RawDataDao {
 
-    Integer addRawData(Integer itemGroupId, Integer remainder, RawData rawData);
+    Integer addRawData(Integer remainder, RawData rawData);
 
     Integer addRawDataList(Integer itemGroupId, Integer remainder, List<RawData> rawDataList);
 
@@ -18,9 +18,23 @@ public interface RawDataDao {
 
     List<Map<String, Object>> getPieData(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<Item> itemList);
 
-    List<RawData> getTableDataEvery(Integer itemGroupId, Integer remainder, Integer dataSourceId, String itemName,String startBelongTime,String endBelongTime);
+    List<RawData> getTableDataEvery(Integer itemGroupId, Integer remainder, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
 
     List<RawData> getChartData(Integer itemGroupId, Integer remainder, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
 
     List<RawData> getPieChartData(Integer itemGroupId, Integer remainder, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
+
+    List<RawData> getTempRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
+
+    Integer delRawDataList(List<RawData> rawDataList, String valueBelongTime);
+
+    Integer addTempRawData(RawData rawData);
+
+    RawData getRawDataList(Item item, Integer remainder, Integer dataSourceId, String valueBelongTime);
+
+    List<RawData> getEventRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
+
+    Integer addEventRawData(RawData rawData);
+
+    Integer delEventRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/UserDao.java

@@ -143,4 +143,6 @@ public interface UserDao {
     Integer deleteUserDepartment(String userId, List<Department> departmentList);
 
     List<Department> getNoShareOldDepartmentList(String userId, List<Department> departmentList);
+
+    List<String> getAllUserIdByType(Integer userType);
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/UserService.java

@@ -123,4 +123,6 @@ public interface UserService {
 
 
     Result phoneUserLogin(User user);
+
+    Result getOnlineUser(String loginType);
 }

+ 6 - 4
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataModelServiceImpl.java

@@ -3,6 +3,7 @@ package com.example.opc_da.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.DataModel;
 import com.example.opc_common.entity.Item;
+import com.example.opc_common.entity.ItemGroup;
 import com.example.opc_common.enums.ResultEnum;
 import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.MathUtil;
@@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 @Service
 @Transactional
@@ -64,14 +66,14 @@ public class DataModelServiceImpl implements DataModelService {
 
     @Override
     public Result delDataModelById(Integer id) {
-        List<Item> itemList = dataModelDao.getItemByDaModel(id);
-        if (Blank.isNotEmpty(itemList)) {
+        List<Map<String, Object>> mapList = dataModelDao.getItemGroupByDm(id);
+        if (Blank.isNotEmpty(mapList)) {
             String message = "此数据模型已被配置在【";
-            for (int i = 0; i < itemList.size(); i++) {
+            for (int i = 0; i < mapList.size(); i++) {
                 if (i != 0) {
                     message += ",";
                 }
-                message += "组"+itemList.get(i).getItemGroupName() + "的标签" + itemList.get(i).getItemName();
+                message += "组" + mapList.get(i).get("item_group_name") + "-" + mapList.get(i).get("count") + "个标签";
             }
             message += "】中,无法直接删除";
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), message);

+ 0 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataSourceServiceImpl.java

@@ -10,7 +10,6 @@ import com.example.opc_common.enums.ResultEnum;
 import com.example.opc_common.exception.CustomException;
 import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
-import com.example.opc_common.util.JavaTypeUtil;
 import com.example.opc_common.util.Result;
 import com.example.opc_da.dao.DataSourceDao;
 import com.example.opc_da.dao.ItemGroupDao;

+ 115 - 23
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -14,8 +14,7 @@ import com.example.opc_da.dao.DataSourceDao;
 import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.service.ItemGroupService;
-import com.example.opc_da.task.OpcAsyncTask;
-import com.example.opc_da.task.OpcDaTask;
+import com.example.opc_da.task.*;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import com.example.opc_da.util.UserUtil;
@@ -76,8 +75,18 @@ public class ItemGroupServiceImpl implements ItemGroupService {
             }
             itemGroupDao.addItemGroup(itemGroup);
             if (Blank.isNotEmpty(itemGroup.getItemList())) {
+                List<Item> itemList = itemGroup.getItemList();
                 if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
-                    itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemGroup.getItemList()));
+                    itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemList));
+                }
+                int count = 0;
+                for (Item item : itemList) {
+                    if (Blank.isNotEmpty(item.getEventMode())) {
+                        count += 1;
+                    }
+                }
+                if (count > 1) {
+                    return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "一个数据组中,最多只能配置一个事件驱动");
                 }
                 itemGroupDao.addItem(itemGroup.getId(), itemGroup.getItemList());
             }
@@ -95,12 +104,22 @@ public class ItemGroupServiceImpl implements ItemGroupService {
             if (itemGroupDao.updateItemGroup(itemGroup) <= 0) {
                 return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改数据组失败");
             }
-            if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
-                itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemGroup.getItemList()));
-            }
             itemGroupDao.delItemByGroupId(id);
             if (Blank.isNotEmpty(itemGroup.getItemList())) {
-                itemGroupDao.addItem(id, itemGroup.getItemList());
+                List<Item> itemList = itemGroup.getItemList();
+                if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
+                    itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemList));
+                }
+                int count = 0;
+                for (Item item : itemList) {
+                    if (Blank.isNotEmpty(item.getEventMode())) {
+                        count += 1;
+                    }
+                }
+                if (count > 1) {
+                    return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "一个数据组中,最多只能配置一个事件驱动");
+                }
+                itemGroupDao.addItem(id, itemList);
             }
             return Result.ok("修改数据组成功");
         }
@@ -193,22 +212,73 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue()) ||
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.WINCC.getValue()) ||
-                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue()) ||
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue()) ||
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())
                 ) {
-                    timer.schedule(new OpcDaTask(redisUtil,
-                                    opcAsyncTask,
-                                    itemGroupDao,
-                                    messageNoticeDao,
-                                    timer,
-                                    itemGroup,
-                                    dataSource,
-                                    map,
-                                    allItemList,
-                                    timeFormat),
-                            DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
-                            ConstantStr.PERIOD_DAY);
-                    itemGroupDao.runItemGroupById(id, runState);
-                    return Result.ok("启动成功");
+                    if (itemGroup.getReadMode() == ConstantStr.ON_FREQUENCY) {
+                        timer.schedule(new OpcDaFrequencyTask(redisUtil,
+                                        opcAsyncTask,
+                                        itemGroupDao,
+                                        messageNoticeDao,
+                                        timer,
+                                        itemGroup,
+                                        dataSource,
+                                        map,
+                                        allItemList,
+                                        timeFormat),
+                                DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
+                                ConstantStr.PERIOD_DAY);
+                        itemGroupDao.runItemGroupById(id, runState);
+                        return Result.ok("启动成功");
+                    } else if (itemGroup.getReadMode() == ConstantStr.ON_CHANGE) {
+                        timer.schedule(new OpcDaChangeTask(redisUtil,
+                                        opcAsyncTask,
+                                        itemGroupDao,
+                                        messageNoticeDao,
+                                        timer,
+                                        itemGroup,
+                                        dataSource,
+                                        map,
+                                        allItemList,
+                                        timeFormat),
+                                DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
+                                ConstantStr.PERIOD_DAY);
+                        itemGroupDao.runItemGroupById(id, runState);
+                        return Result.ok("启动成功");
+                    } else if (itemGroup.getReadMode() == ConstantStr.EXCEED_SET_VALUE) {
+                        timer.schedule(new OpcDaExceedTask(redisUtil,
+                                        opcAsyncTask,
+                                        itemGroupDao,
+                                        messageNoticeDao,
+                                        timer,
+                                        itemGroup,
+                                        dataSource,
+                                        map,
+                                        allItemList,
+                                        timeFormat),
+                                DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
+                                ConstantStr.PERIOD_DAY);
+                        itemGroupDao.runItemGroupById(id, runState);
+                        return Result.ok("启动成功");
+                    } else if (itemGroup.getReadMode() == ConstantStr.LOWER_SET_VALUE) {
+                        timer.schedule(new OpcDaLowseTask(redisUtil,
+                                        opcAsyncTask,
+                                        itemGroupDao,
+                                        messageNoticeDao,
+                                        timer,
+                                        itemGroup,
+                                        dataSource,
+                                        map,
+                                        allItemList,
+                                        timeFormat),
+                                DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
+                                ConstantStr.PERIOD_DAY);
+                        itemGroupDao.runItemGroupById(id, runState);
+                        return Result.ok("启动成功");
+                    } else {
+                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配其他类型的读取模式");
+                    }
                 } else {
                     throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
                 }
@@ -287,7 +357,24 @@ public class ItemGroupServiceImpl implements ItemGroupService {
     }
 
     @Override
-    public Result updateItem(Item item) {
+    public synchronized Result updateItem(Item item) {
+        Item item1 = itemGroupDao.getItemById(item.getId());
+        ItemGroup itemGroup = itemGroupDao.getItemGroupById(item1.getItemGroupId());
+        if (itemGroup.getRunState() == ConstantStr.START_UP) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组现在处于运行中,不允许修改");
+        }
+        if (Blank.isNotEmpty(item.getEventMode())) {
+            List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroup.getId());
+            if (Blank.isNotEmpty(itemList)) {
+                for (Item item2 : itemList) {
+                    if (Blank.isNotEmpty(item2.getEventMode())) {
+                        if (item2.getId() != item.getId()) {
+                            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组中有其他项配置了事件驱动,修改失败");
+                        }
+                    }
+                }
+            }
+        }
         if (itemGroupDao.updateItem(item) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item失败");
         }
@@ -317,6 +404,11 @@ public class ItemGroupServiceImpl implements ItemGroupService {
 
     @Override
     public synchronized Result deleteItemByIdList(List<Integer> idList) {
+        Item item = itemGroupDao.getItemById(idList.get(0));
+        ItemGroup itemGroup = itemGroupDao.getItemGroupById(item.getItemGroupId());
+        if (itemGroup.getRunState() == ConstantStr.START_UP) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组现在处于运行中,不允许删除");
+        }
         if (itemGroupDao.deleteItemByIdList(idList) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
         }

+ 6 - 5
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/RawDataServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -337,7 +338,7 @@ public class RawDataServiceImpl implements RawDataService {
 
                                         }
                                     }
-                                    data = bigDecimal.divide(new BigDecimal(sum));
+                                    data = bigDecimal.divide(new BigDecimal(sum), 4, RoundingMode.HALF_EVEN);
                                 } else if (itemGroup.getValueCondition().equals(ConstantStr.MAX_VALUE)) {
                                     BigDecimal max = null;
                                     for (RawData rawData : rawDataList) {
@@ -497,11 +498,11 @@ public class RawDataServiceImpl implements RawDataService {
                                             if (Blank.isEmpty(bigDecimal)) {
                                                 bigDecimal = dataValueList[j];
                                             } else {
-                                                bigDecimal.add(dataValueList[j]);
+                                                bigDecimal = bigDecimal.add(dataValueList[j]);
                                             }
                                             sum += 1;
                                         }
-                                        data = bigDecimal.divide(new BigDecimal(sum));
+                                        data = bigDecimal.divide(new BigDecimal(sum), 4, RoundingMode.HALF_EVEN);
                                     }
                                 } else if (itemGroup.getValueCondition().equals(ConstantStr.MAX_VALUE)) {
                                     if (Blank.isNotEmpty(dataValueList)) {
@@ -509,7 +510,7 @@ public class RawDataServiceImpl implements RawDataService {
                                             if (Blank.isEmpty(data)) {
                                                 data = dataValueList[j];
                                             } else {
-                                                data.max(dataValueList[j]);
+                                                data = data.max(dataValueList[j]);
                                             }
                                         }
                                     }
@@ -519,7 +520,7 @@ public class RawDataServiceImpl implements RawDataService {
                                             if (Blank.isEmpty(data)) {
                                                 data = dataValueList[j];
                                             } else {
-                                                data.min(dataValueList[j]);
+                                                data = data.min(dataValueList[j]);
                                             }
                                         }
                                     }

+ 35 - 2
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java

@@ -7,6 +7,7 @@ import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
 import com.example.opc_common.util.Result;
 import com.example.opc_da.dao.DictDao;
+import com.example.opc_da.dao.ItemGroupDao;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.dynamicSchedule.CronTaskRegister;
 import com.example.opc_da.dynamicSchedule.SchedulingRunnable;
@@ -28,6 +29,9 @@ public class ReportTableServiceImpl implements ReportTableService {
     @Resource
     private ReportTableDao reportTableDao;
 
+    @Autowired
+    private ItemGroupDao itemGroupDao;
+
     @Resource
     private UserUtil userUtil;
 
@@ -149,6 +153,9 @@ public class ReportTableServiceImpl implements ReportTableService {
         if (reportTable.getIsAutoReport() == ConstantStr.AUTOMATIC_REPORT) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "自动报表不能够删除,需要转换为手动报表,然后进行删除");
         }
+        if (reportTable.getIsAutoReport() == ConstantStr.EVENT_DRIVEN_REPORT) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "事件驱动报表不能够直接删除,需要转换为手动报表,然后进行删除");
+        }
         if (!reportTable.getUserId().equals(userUtil.getCurrentUserId())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "这是别人分享的报表,不能删除");
         }
@@ -172,6 +179,14 @@ public class ReportTableServiceImpl implements ReportTableService {
             reportTable.setUserGroupList(userGroupList);
         }
         if (isAutoReport == ConstantStr.AUTOMATIC_REPORT) {
+            List<ItemGroup> itemGroupList = itemGroupDao.getItemGroupListByTableId(id);
+            if (Blank.isNotEmpty(itemGroupList)) {
+                for (ItemGroup itemGroup : itemGroupList) {
+                    if (itemGroup.getRunState() == ConstantStr.START_UP) {
+                        return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表作为事件驱动报表,已被配置在运行的数据组上了,请停止运行数据组后再试");
+                    }
+                }
+            }
             if (Blank.isEmpty(cron)) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "cron表达式不能为空");
             }
@@ -199,7 +214,7 @@ public class ReportTableServiceImpl implements ReportTableService {
             }
             cronTaskRegister.addCronTask(task, cronId, cron);
             return Result.ok(reportTableDao.tableExchangeAutoById(id, isAutoReport, cronId, cron));
-        } else if (isAutoReport == ConstantStr.MANUAL_REPORT || isAutoReport == ConstantStr.EVENT_DRIVEN_REPORT) {
+        } else if (isAutoReport == ConstantStr.MANUAL_REPORT) {
             if (Blank.isEmpty(reportTable)) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表不存在");
             }
@@ -209,11 +224,29 @@ public class ReportTableServiceImpl implements ReportTableService {
             if (reportTable.getIsAutoReport() == ConstantStr.MANUAL_REPORT) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经是手动报表了");
             }
+            //移除相应的定时器
+            if (Blank.isNotEmpty(reportTable.getIsAutoReport())) {
+                if (reportTable.getIsAutoReport() == ConstantStr.AUTOMATIC_REPORT) {
+                    cronTaskRegister.removeCronTask(reportTable.getCronId());
+                }
+            }
+            return Result.ok(reportTableDao.tableExchangeTypeById(id, isAutoReport));
+        } else if (isAutoReport == ConstantStr.EVENT_DRIVEN_REPORT) {
+            if (Blank.isEmpty(reportTable)) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表不存在");
+            }
+            if (Blank.isEmpty(reportTable.getIsAutoReport())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "未知报表类型,请刷新重试");
+            }
             if (reportTable.getIsAutoReport() == ConstantStr.EVENT_DRIVEN_REPORT) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此报表已经是事件驱动报表了");
             }
             //移除相应的定时器
-            cronTaskRegister.removeCronTask(reportTable.getCronId());
+            if (Blank.isNotEmpty(reportTable.getIsAutoReport())) {
+                if (reportTable.getIsAutoReport() == ConstantStr.AUTOMATIC_REPORT) {
+                    cronTaskRegister.removeCronTask(reportTable.getCronId());
+                }
+            }
             return Result.ok(reportTableDao.tableExchangeTypeById(id, isAutoReport));
         } else {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 28 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/UserServiceImpl.java

@@ -83,6 +83,10 @@ public class UserServiceImpl implements UserService {
         } catch (Exception e) {
             throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
+        Integer userName = userDao.queryUserName(user.getUserName());
+        if (userName <= 0) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "帐号不存在");
+        }
         User isExistUser = userDao.getUserByNamePass(user.getUserName(), EncryptUtils.StrToMD5(user.getPassword()));
 //        // 校验验证码
 //        String storeCode = Convert.toStr(redisUtil.get(user.getUid() + "-captcha"));
@@ -607,6 +611,10 @@ public class UserServiceImpl implements UserService {
         } catch (Exception e) {
             throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
+        Integer userName = userDao.queryUserName(user.getUserName());
+        if (userName <= 0) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "帐号不存在");
+        }
         User isExistUser = userDao.getUserByNamePass(user.getUserName(), EncryptUtils.StrToMD5(user.getPassword()));
         if (Blank.isEmpty(isExistUser)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "帐号或密码错误");
@@ -654,6 +662,26 @@ public class UserServiceImpl implements UserService {
         }
     }
 
+    @Override
+    public Result getOnlineUser(String loginType) {
+        if (loginType.equals(ConstantStr.FRONT_USER_String)) {
+            List<String> userIdList = userDao.getAllUserIdByType(ConstantStr.FRONT_USER);
+            if (Blank.isEmpty(userIdList)) {
+                return Result.ok(0);
+            } else {
+                int count = 0;
+                for (String userId : userIdList) {
+                    if (Blank.isNotEmpty(redisUtil.get(ConstantStr.FRONT_USER_String + userId))) {
+                        count += 1;
+                    }
+                }
+                return Result.ok(count);
+            }
+        } else {
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "当前只支持查看客户端在线用户人数");
+        }
+    }
+
 
     @Override
     public synchronized Result updateUser(User user) {

+ 224 - 54
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java

@@ -1,14 +1,15 @@
 package com.example.opc_da.task;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.example.opc_common.entity.DataSource;
-import com.example.opc_common.entity.RawData;
-import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.entity.*;
 import com.example.opc_common.enums.DataSourceTypeEnum;
 import com.example.opc_common.enums.OpcDaDriverEnum;
 import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_da.dao.MessageNoticeDao;
 import com.example.opc_da.dao.RawDataDao;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.util.OpcDaUtil;
@@ -27,7 +28,7 @@ import org.springframework.web.client.RestTemplate;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.util.List;
+import java.util.*;
 
 @Component
 @Async("threadPoolTaskExecutor")
@@ -48,37 +49,142 @@ public class OpcAsyncTask {
     @Autowired
     private ReportTableDao reportTableDao;
 
+    @Autowired
+    private MessageNoticeDao messageNoticeDao;
+
     @Value("${opc_ua_server.address}")
     private String opcUaUrl;
 
     /**
-     * 异步生成事件驱动报表
-     */
-    public void eventDiverReport() {
-
-    }
-
-    /**
-     * 新增一条原始数据
+     * 新增一条临时数据
      *
      * @param rawData
      */
-    public void addRawData(Integer id, RawData rawData) {
-        if (Blank.isNotEmpty(id) && Blank.isNotEmpty(rawData)) {
-            Integer remainder = id % ConstantStr.SUB_TABLE_NUM;
-            rawDataDao.addRawData(id, remainder, rawData);
+    public void addTempRawData(RawData rawData) {
+        if (Blank.isNotEmpty(rawData)) {
+            rawDataDao.addTempRawData(rawData);
         }
     }
 
     /**
-     * 新增原始数据集合
+     * 将临时数据库表中的原始数据组装为分表中的数据
      *
-     * @param rawDataList
+     * @param item
+     * @param sqlCurrentYmdh
      */
-    public void addRawDataList(Integer id, List<RawData> rawDataList) {
-        if (Blank.isNotEmpty(id) && Blank.isNotEmpty(rawDataList)) {
-            Integer remainder = id % ConstantStr.SUB_TABLE_NUM;
-            rawDataDao.addRawDataList(id, remainder, rawDataList);
+    public void packageRawData(Item item, Integer dataSourceId, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(5000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Integer itemGroupId = item.getItemGroupId();
+        Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+        if (Blank.isNotEmpty(item)) {
+            RawData oldRawData = rawDataDao.getRawDataList(item, remainder, dataSourceId, sqlCurrentYmdh);
+            List<RawData> rawDataList = rawDataDao.getTempRawDataList(item, dataSourceId, sqlCurrentYmdh);
+            if (Blank.isNotEmpty(rawDataList)) {
+                RawData rawData1 = rawDataList.get(0);
+                String itemName = rawData1.getItemName();
+                String dataType = rawData1.getDataType();
+                if (dataType.equals("boolean")) {
+                    List<Boolean> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), Boolean[].class)) : new ArrayList<>();
+                    List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                    for (RawData rawData : rawDataList) {
+                        dataList.add(JSON.parseObject(rawData.getDataValue(), Boolean.class));
+                        dataTimeList.add(rawData.getDataValueTime());
+                    }
+                    RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                            JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                    rawDataDao.addRawData(remainder, rawData);
+                } else {
+                    List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                    try {
+                        List<BigDecimal> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), BigDecimal[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            BigDecimal bigDecimal = JSON.parseObject(rawData.getDataValue(), BigDecimal.class);
+                            dataList.add(bigDecimal);
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    } catch (Exception e) {
+                        List<String> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), String[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            dataList.add(rawData.getDataValue());
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    }
+                }
+                rawDataDao.delRawDataList(rawDataList, sqlCurrentYmdh);
+            }
+        }
+    }
+
+    public void packageRawDataList(List<Item> itemList, Integer dataSourceId, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(10000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (Blank.isNotEmpty(itemList)) {
+            Item item1 = itemList.get(0);
+            Integer itemGroupId = item1.getItemGroupId();
+            Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+            for (Item item : itemList) {
+                RawData oldRawData = rawDataDao.getRawDataList(item, remainder, dataSourceId, sqlCurrentYmdh);
+                List<RawData> rawDataList = rawDataDao.getTempRawDataList(item, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(rawDataList)) {
+                    RawData rawData1 = rawDataList.get(0);
+                    String itemName = rawData1.getItemName();
+                    String dataType = rawData1.getDataType();
+                    if (dataType.equals("boolean")) {
+                        List<Boolean> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), Boolean[].class)) : new ArrayList<>();
+                        List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            dataList.add(JSON.parseObject(rawData.getDataValue(), Boolean.class));
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    } else {
+                        List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                        try {
+                            List<BigDecimal> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), BigDecimal[].class)) : new ArrayList<>();
+                            for (RawData rawData : rawDataList) {
+                                BigDecimal bigDecimal = JSON.parseObject(rawData.getDataValue(), BigDecimal.class);
+                                dataList.add(bigDecimal);
+                                dataTimeList.add(rawData.getDataValueTime());
+                            }
+                            RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                    JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                            rawDataDao.addRawData(remainder, rawData);
+                        } catch (Exception e) {
+                            List<String> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), String[].class)) : new ArrayList<>();
+                            for (RawData rawData : rawDataList) {
+                                dataList.add(rawData.getDataValue());
+                                dataTimeList.add(rawData.getDataValueTime());
+                            }
+                            RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                    JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                            rawDataDao.addRawData(remainder, rawData);
+                        }
+                    }
+                    rawDataDao.delRawDataList(rawDataList, sqlCurrentYmdh);
+                }
+            }
+        }
+    }
+
+    public void addEventRawData(RawData rawData) {
+        if (Blank.isNotEmpty(rawData)) {
+            rawDataDao.addEventRawData(rawData);
         }
     }
 
@@ -122,28 +228,19 @@ public class OpcAsyncTask {
                     List<JSONObject> jsonObjectList = OpcDaUtil.generServerTree(server);
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                 } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.WINCC.getValue()) ||
-                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())) {
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue()) ||
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
                     List<JSONObject> jsonObjectList = OpcDaUtil.generWinccTree(server);
                     redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
+                } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())) {
+                    List<JSONObject> jsonObjectList = OpcDaUtil.generPAS300Tree(server);
+                    redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(jsonObjectList));
                 } else {
                     log.info("目前未适配此种驱动类型");
                 }
             }
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("0x00000005")) {
-                log.info("账号校验不通过,账号或密码错误,本地安全策略有问题");
-            } else if (message.contains("0x8001FFFF") || message.contains("Index 16 out of bounds for length 16")) {
-                log.info("ip不存在或ip不互通");
-            } else if (message.contains("0x80040154")) {
-                log.info("clsId不存在");
-            } else if (message.contains("0x80040153")) {
-                log.info("注册表中未找到此驱动,可能是注册表未删除干净");
-            } else if (message.contains("0x80070005")) {
-                log.info("访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置");
-            } else {
-                log.info(e.getMessage());
-            }
+            log.info(OpcDaUtil.genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(server)) {
                 server.dispose();
@@ -154,28 +251,101 @@ public class OpcAsyncTask {
     /**
      * 事件驱动报表异步添加数据
      */
-    public void eventTable(Integer tableReportId, BigDecimal value, String currentDate) {
+    public void eventTable(Integer dataSourceId, List<Item> itemList, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(10000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Integer tableReportId = null;
+        if (Blank.isNotEmpty(itemList)) {
+            for (Item item : itemList) {
+                if (Blank.isNotEmpty(item.getEventMode()) && Blank.isNotEmpty(item.getEventValue()) && Blank.isNotEmpty(item.getTableReportId())) {
+                    tableReportId = item.getTableReportId();
+                    break;
+                }
+            }
+        }
+        if (Blank.isEmpty(tableReportId)) {
+            return;
+        }
         ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
         String reportTableData = reportTable.getReportTableData();
         JSONObject jsonObject = JSONObject.parseObject(reportTableData);
         JSONArray objects = jsonObject.getJSONArray("tables");
-        if (Blank.isNotEmpty(objects)) {
-            JSONObject jsonObject1 = objects.getJSONObject(0);
-            JSONArray objects1 = jsonObject1.getJSONArray("eventDataList");
-            JSONObject object = new JSONObject();
-            object.put("date", currentDate);
-            object.put("value", value);
-            objects1.add(object);
-            objects.set(0, jsonObject1);
-            jsonObject.put("tables", objects);
-            reportTable.setReportTableData(jsonObject.toJSONString());
-            //将新数据加到与那里的data里面,并更新
-            reportTableDao.updateReportTable(reportTable);
+        if (Blank.isEmpty(objects)) {
+            ReportTable reportTable1 = new ReportTable();
+            reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
+            reportTable1.setUserId(reportTable.getUserId());
+            reportTable1.setReportTableName(reportTable.getReportTableName() + "_" + DateUtil.dateChangeStr(new Date(), "yyyyMMddHHmmss"));
+            reportTable1.setReportTableData(jsonObject.toJSONString());
+            reportTable1.setReportValueFormat(reportTable.getReportValueFormat());
+            reportTable1.setIsAutoReport(ConstantStr.EVENT_GENERATE_REPORT);
+            reportTable1.setVersion(reportTable.getVersion());
+            reportTableDao.addReportTable(reportTable1);
+            TableAutoLog tableAutoLog = new TableAutoLog();
+            tableAutoLog.setAutoTableId(reportTable.getId());
+            tableAutoLog.setAutoChTableId(reportTable1.getId());
+            reportTableDao.addTableAutoLog(tableAutoLog);
+            if (Blank.isNotEmpty(reportTable.getUserGroupList())) {
+                reportTableDao.addTableUserGroup(reportTable1.getId(), reportTable.getUserGroupList());
+            }
+            return;
+        }
+        JSONObject jsonObject1 = objects.getJSONObject(0);
+        JSONArray objects1 = jsonObject1.getJSONArray("item");
+        if (Blank.isNotEmpty(itemList)) {
+            for (int i = 0; i < itemList.size(); i++) {
+                List<RawData> rawDataList = rawDataDao.getEventRawDataList(itemList.get(i), dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(rawDataList)) {
+                    JSONObject jsonObject2 = new JSONObject();
+                    RawData rawData = rawDataList.get(0);
+                    String dataType = rawData.getDataType();
+                    if (dataType.toLowerCase().equals("boolean")) {
+                        List<Boolean> dataList = new ArrayList<>();
+                        for (RawData rawData1 : rawDataList) {
+                            dataList.add(JSON.parseObject(rawData1.getDataValue(), Boolean.class));
+                        }
+                        jsonObject2.put("dataList", dataList);
+                    } else {
+                        try {
+                            List<BigDecimal> dataList = new ArrayList<>();
+                            for (RawData rawData1 : rawDataList) {
+                                dataList.add(JSON.parseObject(rawData1.getDataValue(), BigDecimal.class));
+                            }
+                            jsonObject2.put("dataList", dataList);
+                        } catch (Exception e) {
+                            List<String> dataList = new ArrayList<>();
+                            for (RawData rawData1 : rawDataList) {
+                                dataList.add(rawData1.getDataValue());
+                            }
+                            jsonObject2.put("dataList", dataList);
+                        }
+                    }
+                    jsonObject2.put("dataTimeList", JSON.parseObject(rawData.getDataValueTime(), String[].class));
+                    objects1.set(i, jsonObject2);
+                }
+                rawDataDao.delEventRawDataList(itemList.get(i), dataSourceId, sqlCurrentYmdh);
+            }
+        }
+        objects.set(0, jsonObject1);
+        jsonObject.put("tables", objects);
+        ReportTable reportTable1 = new ReportTable();
+        reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
+        reportTable1.setUserId(reportTable.getUserId());
+        reportTable1.setReportTableName(reportTable.getReportTableName() + "_" + DateUtil.dateChangeStr(new Date(), "yyyyMMddHHmmss"));
+        reportTable1.setReportTableData(jsonObject.toJSONString());
+        reportTable1.setReportValueFormat(reportTable.getReportValueFormat());
+        reportTable1.setIsAutoReport(ConstantStr.EVENT_GENERATE_REPORT);
+        reportTable1.setVersion(reportTable.getVersion());
+        reportTableDao.addReportTable(reportTable1);
+        TableAutoLog tableAutoLog = new TableAutoLog();
+        tableAutoLog.setAutoTableId(reportTable.getId());
+        tableAutoLog.setAutoChTableId(reportTable1.getId());
+        reportTableDao.addTableAutoLog(tableAutoLog);
+        if (Blank.isNotEmpty(reportTable.getUserGroupList())) {
+            reportTableDao.addTableUserGroup(reportTable1.getId(), reportTable.getUserGroupList());
         }
-    }
-
-    public void addEventTable(Integer tableReportId,List<BigDecimal> eventDataValueList, List<String> eventDataValueTimeList){
-
     }
 
 }

+ 243 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaChangeTask.java

@@ -0,0 +1,243 @@
+package com.example.opc_da.task;
+
+import com.alibaba.fastjson.JSON;
+import com.example.opc_common.entity.*;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_common.util.MathUtil;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.MessageNoticeDao;
+import com.example.opc_da.util.OpcDaUtil;
+import com.example.opc_da.util.RedisUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.openscada.opc.lib.da.Item;
+import org.openscada.opc.lib.da.*;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+@Slf4j
+public class OpcDaChangeTask extends TimerTask {
+
+    private final RedisUtil redisUtil;
+
+    private final OpcAsyncTask opcAsyncTask;
+
+    private final ItemGroupDao itemGroupDao;
+
+    private final MessageNoticeDao messageNoticeDao;
+
+    private final Timer timer;
+
+    private final ItemGroup itemGroup;
+
+    private final DataSource dataSource;
+
+    private final Map<String, DataModel> map;
+
+    private final List<com.example.opc_common.entity.Item> itemList;
+
+    private final String timeFormat;
+
+    private Boolean eventFlage = false;
+
+    public OpcDaChangeTask(RedisUtil redisUtil,
+                           OpcAsyncTask opcAsyncTask,
+                           ItemGroupDao itemGroupDao,
+                           MessageNoticeDao messageNoticeDao,
+                           Timer timer,
+                           ItemGroup itemGroup,
+                           DataSource dataSource,
+                           Map<String, DataModel> map,
+                           List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+        this.redisUtil = redisUtil;
+        this.opcAsyncTask = opcAsyncTask;
+        this.itemGroupDao = itemGroupDao;
+        this.messageNoticeDao = messageNoticeDao;
+        this.timer = timer;
+        this.itemGroup = itemGroup;
+        this.dataSource = dataSource;
+        this.map = map;
+        this.itemList = itemList;
+        this.timeFormat = timeFormat;
+    }
+
+    @Override
+    public void run() {
+        Server server = OpcDaUtil.createServer(dataSource);
+        Integer id = itemGroup.getId();
+        Integer dataSourceId = dataSource.getId();
+        try {
+            server.connect();
+            SyncAccess access = new SyncAccess(server, 1000);
+            for (com.example.opc_common.entity.Item item : itemList) {
+                String itemId = item.getItemReadName();
+                Integer eventMode = item.getEventMode();
+                Double eventValue = item.getEventValue();
+                Integer tableReportId = item.getTableReportId();
+                access.addItem(itemId, new DataCallback() {
+                    private Map<String, Object> valueMap;
+                    private String sqlCurrentYmdh = "";
+
+                    @Override
+                    public void changed(Item item1, ItemState itemState) {
+                        try {
+                            Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
+                            DataModel dm = map.get(itemId);
+                            //读取的值
+                            String javaType = String.valueOf(val.get("javaType"));
+                            Object value = val.get("value");
+                            //值对应取值的时间
+                            Date time = itemState.getTimestamp().getTime();
+                            String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                            if (Blank.isEmpty(sqlCurrentYmdh)) {
+                                sqlCurrentYmdh = currentYmdh;
+                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                            } else {
+                                if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                                    //组装相应的数据
+                                    opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                                    }
+                                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                                    sqlCurrentYmdh = currentYmdh;
+                                }
+                            }
+                            String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
+                            if (!valueMap.equals(val)) {
+                                valueMap = val;
+                                if (javaType.toLowerCase().equals("boolean")) {
+                                    Boolean dmData = JSON.parseObject(value.toString(), Boolean.class);
+                                    RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                            currentYmdhmss, currentYmdh, new Date());
+                                    opcAsyncTask.addTempRawData(rawData);
+
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_BOOLEAN)) {
+                                            if ((dmData ? ConstantStr.BOOLEAN_TRUE : ConstantStr.BOOLEAN_FALSE).equals(eventValue.intValue())) {
+                                                eventFlage = true;
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            } else {
+                                                eventFlage = false;
+                                            }
+                                        }
+                                    } else {
+                                        if (eventFlage) {
+                                            opcAsyncTask.addEventRawData(rawData);
+                                        }
+                                    }
+                                } else {
+                                    try {
+                                        BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                                        BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                                MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                                bigDecimal;
+                                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                                currentYmdhmss, currentYmdh, new Date());
+                                        opcAsyncTask.addTempRawData(rawData);
+
+                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                            BigDecimal bigEventValue = new BigDecimal(eventValue);
+                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
+                                                if (dmData.compareTo(bigEventValue) == 1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                if (dmData.compareTo(bigEventValue) == -1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            }
+                                        } else {
+                                            if (eventFlage) {
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            }
+                                        }
+                                    } catch (Exception e) {
+                                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+                                                currentYmdhmss, currentYmdh, new Date());
+                                        opcAsyncTask.addTempRawData(rawData);
+
+                                        if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+                                            if (eventFlage) {
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        } catch (Exception e) {
+                            //执行组装数据库的数据,以及生成驱动报表
+                            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                            }
+                            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                                    e.getMessage(),
+                                    ConstantStr.NO_READ));
+                            e.printStackTrace();
+                            if (Blank.isNotEmpty(server)) {
+                                server.dispose();
+                            }
+                            for (com.example.opc_common.entity.Item item_ : itemList) {
+                                redisUtil.del(ConstantStr.ITEM_GROUP + id + item_.getItemReadName());
+                            }
+                            redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                            itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                            timer.cancel();
+                        }
+                    }
+                });
+            }
+            access.bind();
+            while (true) {
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                            "请刷新检查组的运行状态",
+                            ConstantStr.NO_READ));
+                    access.unbind();
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                    itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+                    timer.cancel();
+                    break;
+                }
+            }
+        } 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();
+            }
+            redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+            itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+            timer.cancel();
+        }
+    }
+}

+ 210 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaExceedTask.java

@@ -0,0 +1,210 @@
+package com.example.opc_da.task;
+
+import com.alibaba.fastjson.JSON;
+import com.example.opc_common.entity.*;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_common.util.MathUtil;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.MessageNoticeDao;
+import com.example.opc_da.util.OpcDaUtil;
+import com.example.opc_da.util.RedisUtil;
+import org.openscada.opc.lib.da.Item;
+import org.openscada.opc.lib.da.*;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+public class OpcDaExceedTask extends TimerTask {
+
+    private final RedisUtil redisUtil;
+
+    private final OpcAsyncTask opcAsyncTask;
+
+    private final ItemGroupDao itemGroupDao;
+
+    private final MessageNoticeDao messageNoticeDao;
+
+    private final Timer timer;
+
+    private final ItemGroup itemGroup;
+
+    private final DataSource dataSource;
+
+    private final Map<String, DataModel> map;
+
+    private final List<com.example.opc_common.entity.Item> itemList;
+
+    private final String timeFormat;
+
+    private Boolean eventFlage = false;
+
+    public OpcDaExceedTask(RedisUtil redisUtil,
+                           OpcAsyncTask opcAsyncTask,
+                           ItemGroupDao itemGroupDao,
+                           MessageNoticeDao messageNoticeDao,
+                           Timer timer,
+                           ItemGroup itemGroup,
+                           DataSource dataSource,
+                           Map<String, DataModel> map,
+                           List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+        this.redisUtil = redisUtil;
+        this.opcAsyncTask = opcAsyncTask;
+        this.itemGroupDao = itemGroupDao;
+        this.messageNoticeDao = messageNoticeDao;
+        this.timer = timer;
+        this.itemGroup = itemGroup;
+        this.dataSource = dataSource;
+        this.map = map;
+        this.itemList = itemList;
+        this.timeFormat = timeFormat;
+    }
+
+    @Override
+    public void run() {
+        Server server = OpcDaUtil.createServer(dataSource);
+        Integer id = itemGroup.getId();
+        Integer dataSourceId = dataSource.getId();
+        try {
+            server.connect();
+            SyncAccess access = new SyncAccess(server, 1000);
+            for (com.example.opc_common.entity.Item item : itemList) {
+                String itemId = item.getItemReadName();
+                Integer eventMode = item.getEventMode();
+                Double eventValue = item.getEventValue();
+                Integer tableReportId = item.getTableReportId();
+                access.addItem(itemId, new DataCallback() {
+                    private String sqlCurrentYmdh = "";
+
+                    @Override
+                    public void changed(Item item1, ItemState itemState) {
+                        try {
+                            Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
+                            DataModel dm = map.get(itemId);
+                            BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
+
+                            //读取的值
+                            Object value = val.get("value");
+                            String javaType = String.valueOf(val.get("javaType"));
+                            //值对应取值的时间
+                            Date time = itemState.getTimestamp().getTime();
+                            //归属时间
+                            String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                            if (Blank.isEmpty(sqlCurrentYmdh)) {
+                                sqlCurrentYmdh = currentYmdh;
+                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                            } else {
+                                if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                                    //组装相应的数据
+                                    opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                                    }
+                                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                                    sqlCurrentYmdh = currentYmdh;
+                                }
+                            }
+                            String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
+
+                            if (!javaType.toLowerCase().equals("boolean")) {
+                                try {
+                                    BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                                    BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
+                                    if (dmData.compareTo(bigModeValue) == 1) {
+                                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                                currentYmdhmss, currentYmdh, new Date());
+                                        opcAsyncTask.addTempRawData(rawData);
+
+                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                            BigDecimal bigEventValue = new BigDecimal(eventValue);
+                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
+                                                if (dmData.compareTo(bigEventValue) == 1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                if (dmData.compareTo(bigEventValue) == -1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            }
+                                        } else {
+                                            if (eventFlage) {
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            }
+                                        }
+                                    }
+                                } catch (Exception e) {
+
+                                }
+                            }
+                        } catch (Exception e) {
+                            //执行组装数据库的数据,以及生成驱动报表
+                            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                            }
+                            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                                    e.getMessage(),
+                                    ConstantStr.NO_READ));
+                            e.printStackTrace();
+                            if (Blank.isNotEmpty(server)) {
+                                server.dispose();
+                            }
+                            redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                            itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                            timer.cancel();
+                        }
+                    }
+                });
+            }
+            access.bind();
+            while (true) {
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                            "请刷新检查组的运行状态",
+                            ConstantStr.NO_READ));
+                    access.unbind();
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                    itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+                    timer.cancel();
+                    break;
+                }
+            }
+        } 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();
+            }
+            redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+            itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+            timer.cancel();
+        }
+    }
+}

+ 239 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaFrequencyTask.java

@@ -0,0 +1,239 @@
+package com.example.opc_da.task;
+
+import com.alibaba.fastjson.JSON;
+import com.example.opc_common.entity.*;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_common.util.MathUtil;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.MessageNoticeDao;
+import com.example.opc_da.util.OpcDaUtil;
+import com.example.opc_da.util.RedisUtil;
+import org.openscada.opc.lib.da.Item;
+import org.openscada.opc.lib.da.*;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+public class OpcDaFrequencyTask extends TimerTask {
+
+    private final RedisUtil redisUtil;
+
+    private final OpcAsyncTask opcAsyncTask;
+
+    private final ItemGroupDao itemGroupDao;
+
+    private final MessageNoticeDao messageNoticeDao;
+
+    private final Timer timer;
+
+    private final ItemGroup itemGroup;
+
+    private final DataSource dataSource;
+
+    private final Map<String, DataModel> map;
+
+    private final List<com.example.opc_common.entity.Item> itemList;
+
+    private final String timeFormat;
+
+    private Boolean eventFlage = false;
+
+    public OpcDaFrequencyTask(RedisUtil redisUtil,
+                              OpcAsyncTask opcAsyncTask,
+                              ItemGroupDao itemGroupDao,
+                              MessageNoticeDao messageNoticeDao,
+                              Timer timer,
+                              ItemGroup itemGroup,
+                              DataSource dataSource,
+                              Map<String, DataModel> map,
+                              List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+        this.redisUtil = redisUtil;
+        this.opcAsyncTask = opcAsyncTask;
+        this.itemGroupDao = itemGroupDao;
+        this.messageNoticeDao = messageNoticeDao;
+        this.timer = timer;
+        this.itemGroup = itemGroup;
+        this.dataSource = dataSource;
+        this.map = map;
+        this.itemList = itemList;
+        this.timeFormat = timeFormat;
+    }
+
+    @Override
+    public void run() {
+        Server server = OpcDaUtil.createServer(dataSource);
+        Integer id = itemGroup.getId();
+        Integer dataSourceId = dataSource.getId();
+        try {
+            server.connect();
+            SyncAccess access = new SyncAccess(server, (int) (itemGroup.getModeValue() * 1000));
+//                AccessBase access = new Async20Access(server, itemGroup.getModeValue() ,true);
+            for (com.example.opc_common.entity.Item item : itemList) {
+                String itemId = item.getItemReadName();
+                Integer eventMode = item.getEventMode();
+                Double eventValue = item.getEventValue();
+                Integer tableReportId = item.getTableReportId();
+                access.addItem(itemId, new DataCallback() {
+
+                    private String sqlCurrentYmdh = "";
+
+                    @Override
+                    public void changed(Item item1, ItemState itemState) {
+                        try {
+                            Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
+                            DataModel dm = map.get(itemId);
+                            //读取的值
+                            String javaType = String.valueOf(val.get("javaType"));
+                            Object value = val.get("value");
+                            //值对应取值的时间
+                            Date time = itemState.getTimestamp().getTime();
+                            String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                            if (Blank.isEmpty(sqlCurrentYmdh)) {
+                                sqlCurrentYmdh = currentYmdh;
+                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                            } else {
+                                if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                                    //组装相应的数据
+                                    opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                                    }
+                                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                                    sqlCurrentYmdh = currentYmdh;
+                                }
+                            }
+                            //服务器读取的时间
+                            String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
+                            //如果redis中存储的年月日时的时间为空,说明还未进行数据的保存
+                            if (javaType.toLowerCase().equals("boolean")) {
+                                //存数据
+                                Boolean dmData = JSON.parseObject(value.toString(), Boolean.class);
+                                RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                        currentYmdhmss, currentYmdh, new Date());
+                                opcAsyncTask.addTempRawData(rawData);
+
+                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_BOOLEAN)) {
+                                        if ((dmData ? ConstantStr.BOOLEAN_TRUE : ConstantStr.BOOLEAN_FALSE).equals(eventValue.intValue())) {
+                                            eventFlage = true;
+                                            opcAsyncTask.addEventRawData(rawData);
+                                        } else {
+                                            eventFlage = false;
+                                        }
+                                    }
+                                } else {
+                                    if (eventFlage) {
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    }
+                                }
+                            } else {
+                                try {
+                                    BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                                    BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                            MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                            bigDecimal;
+                                    RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                            currentYmdhmss, currentYmdh, new Date());
+                                    opcAsyncTask.addTempRawData(rawData);
+
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        BigDecimal bigEventValue = new BigDecimal(eventValue);
+                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
+                                            if (dmData.compareTo(bigEventValue) == 1) {
+                                                eventFlage = true;
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            } else {
+                                                eventFlage = false;
+                                            }
+                                        } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                            if (dmData.compareTo(bigEventValue) == -1) {
+                                                eventFlage = true;
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            } else {
+                                                eventFlage = false;
+                                            }
+                                        }
+                                    } else {
+                                        if (eventFlage) {
+                                            opcAsyncTask.addEventRawData(rawData);
+                                        }
+                                    }
+                                } catch (Exception e) {
+                                    RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+                                            currentYmdhmss, currentYmdh, new Date());
+                                    opcAsyncTask.addTempRawData(rawData);
+
+                                    if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+                                        if (eventFlage) {
+                                            opcAsyncTask.addEventRawData(rawData);
+                                        }
+                                    }
+                                }
+                            }
+                        } catch (Exception e) {
+                            //执行组装数据库的数据,以及生成驱动报表
+                            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                            }
+                            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                                    e.getMessage(),
+                                    ConstantStr.NO_READ));
+                            if (Blank.isNotEmpty(server)) {
+                                server.dispose();
+                            }
+                            redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                            itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                            timer.cancel();
+                        }
+                    }
+                });
+            }
+            access.bind();
+            while (true) {
+                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);
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                            "请刷新检查组的运行状态",
+                            ConstantStr.NO_READ));
+                    access.unbind();
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+
+                    redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                    itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                    timer.cancel();
+                    break;
+                }
+            }
+        } 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();
+            }
+            redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+            itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+            timer.cancel();
+        }
+    }
+}

+ 210 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaLowseTask.java

@@ -0,0 +1,210 @@
+package com.example.opc_da.task;
+
+import com.alibaba.fastjson.JSON;
+import com.example.opc_common.entity.*;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_common.util.MathUtil;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.MessageNoticeDao;
+import com.example.opc_da.util.OpcDaUtil;
+import com.example.opc_da.util.RedisUtil;
+import org.openscada.opc.lib.da.Item;
+import org.openscada.opc.lib.da.*;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+public class OpcDaLowseTask extends TimerTask {
+
+    private final RedisUtil redisUtil;
+
+    private final OpcAsyncTask opcAsyncTask;
+
+    private final ItemGroupDao itemGroupDao;
+
+    private final MessageNoticeDao messageNoticeDao;
+
+    private final Timer timer;
+
+    private final ItemGroup itemGroup;
+
+    private final DataSource dataSource;
+
+    private final Map<String, DataModel> map;
+
+    private final List<com.example.opc_common.entity.Item> itemList;
+
+    private final String timeFormat;
+
+    private Boolean eventFlage = false;
+
+    public OpcDaLowseTask(RedisUtil redisUtil,
+                          OpcAsyncTask opcAsyncTask,
+                          ItemGroupDao itemGroupDao,
+                          MessageNoticeDao messageNoticeDao,
+                          Timer timer,
+                          ItemGroup itemGroup,
+                          DataSource dataSource,
+                          Map<String, DataModel> map,
+                          List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+        this.redisUtil = redisUtil;
+        this.opcAsyncTask = opcAsyncTask;
+        this.itemGroupDao = itemGroupDao;
+        this.messageNoticeDao = messageNoticeDao;
+        this.timer = timer;
+        this.itemGroup = itemGroup;
+        this.dataSource = dataSource;
+        this.map = map;
+        this.itemList = itemList;
+        this.timeFormat = timeFormat;
+    }
+
+    @Override
+    public void run() {
+        Server server = OpcDaUtil.createServer(dataSource);
+        Integer id = itemGroup.getId();
+        Integer dataSourceId = dataSource.getId();
+        try {
+            server.connect();
+            SyncAccess access = new SyncAccess(server, 1000);
+            for (com.example.opc_common.entity.Item item : itemList) {
+                String itemId = item.getItemReadName();
+                Integer eventMode = item.getEventMode();
+                Double eventValue = item.getEventValue();
+                Integer tableReportId = item.getTableReportId();
+                access.addItem(itemId, new DataCallback() {
+                    private String sqlCurrentYmdh = "";
+
+                    @Override
+                    public void changed(Item item1, ItemState itemState) {
+                        try {
+                            Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
+                            DataModel dm = map.get(itemId);
+                            BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
+
+                            //读取的值
+                            Object value = val.get("value");
+                            String javaType = String.valueOf(val.get("javaType"));
+                            //值对应取值的时间
+                            Date time = itemState.getTimestamp().getTime();
+                            //归属时间
+                            String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                            if (Blank.isEmpty(sqlCurrentYmdh)) {
+                                sqlCurrentYmdh = currentYmdh;
+                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                            } else {
+                                if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                                    //组装相应的数据
+                                    opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                        opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                                    }
+                                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                                    sqlCurrentYmdh = currentYmdh;
+                                }
+                            }
+                            String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
+
+                            if (!javaType.toLowerCase().equals("boolean")) {
+                                try {
+                                    BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                                    BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
+                                    if (dmData.compareTo(bigModeValue) == -1) {
+                                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                                currentYmdhmss, currentYmdh, new Date());
+                                        opcAsyncTask.addTempRawData(rawData);
+
+                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                            BigDecimal bigEventValue = new BigDecimal(eventValue);
+                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
+                                                if (dmData.compareTo(bigEventValue) == 1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                if (dmData.compareTo(bigEventValue) == -1) {
+                                                    eventFlage = true;
+                                                    opcAsyncTask.addEventRawData(rawData);
+                                                } else {
+                                                    eventFlage = false;
+                                                }
+                                            }
+                                        } else {
+                                            if (eventFlage) {
+                                                opcAsyncTask.addEventRawData(rawData);
+                                            }
+                                        }
+                                    }
+                                } catch (Exception e) {
+
+                                }
+                            }
+                        } catch (Exception e) {
+                            //执行组装数据库的数据,以及生成驱动报表
+                            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                                opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                            }
+                            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
+                                    e.getMessage(),
+                                    ConstantStr.NO_READ));
+                            e.printStackTrace();
+                            if (Blank.isNotEmpty(server)) {
+                                server.dispose();
+                            }
+                            redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                            itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                            timer.cancel();
+                        }
+                    }
+                });
+            }
+            access.bind();
+            while (true) {
+                Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                if (Blank.isEmpty(flage)) {
+                    flage = false;
+                }
+                if (!flage) {
+                    //执行组装数据库的数据,以及生成驱动报表
+                    String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+                    opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                    redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+                    messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                            itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                            "请刷新检查组的运行状态",
+                            ConstantStr.NO_READ));
+                    access.unbind();
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
+                    }
+                    redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+                    itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+                    timer.cancel();
+                    break;
+                }
+            }
+        } 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();
+            }
+            redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
+            itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
+            timer.cancel();
+        }
+    }
+}

+ 0 - 1844
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaTask.java

@@ -1,1844 +0,0 @@
-package com.example.opc_da.task;
-
-import com.alibaba.fastjson.JSON;
-import com.example.opc_common.entity.*;
-import com.example.opc_common.enums.ResultEnum;
-import com.example.opc_common.exception.CustomException;
-import com.example.opc_common.util.*;
-import com.example.opc_da.dao.ItemGroupDao;
-import com.example.opc_da.dao.MessageNoticeDao;
-import com.example.opc_da.util.OpcDaUtil;
-import com.example.opc_da.util.RedisUtil;
-import org.openscada.opc.lib.da.Item;
-import org.openscada.opc.lib.da.*;
-
-import java.math.BigDecimal;
-import java.util.*;
-
-public class OpcDaTask extends TimerTask {
-
-    private final RedisUtil redisUtil;
-
-    private final OpcAsyncTask opcAsyncTask;
-
-    private final ItemGroupDao itemGroupDao;
-
-    private final MessageNoticeDao messageNoticeDao;
-
-    private final Timer timer;
-
-    private final ItemGroup itemGroup;
-
-    private final DataSource dataSource;
-
-    private final Map<String, DataModel> map;
-
-    private final List<com.example.opc_common.entity.Item> itemList;
-
-    private final String timeFormat;
-
-    public OpcDaTask(RedisUtil redisUtil,
-                     OpcAsyncTask opcAsyncTask,
-                     ItemGroupDao itemGroupDao,
-                     MessageNoticeDao messageNoticeDao,
-                     Timer timer,
-                     ItemGroup itemGroup,
-                     DataSource dataSource,
-                     Map<String, DataModel> map,
-                     List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
-        this.redisUtil = redisUtil;
-        this.opcAsyncTask = opcAsyncTask;
-        this.itemGroupDao = itemGroupDao;
-        this.messageNoticeDao = messageNoticeDao;
-        this.timer = timer;
-        this.itemGroup = itemGroup;
-        this.dataSource = dataSource;
-        this.map = map;
-        this.itemList = itemList;
-        this.timeFormat = timeFormat;
-    }
-
-    @Override
-    public void run() {
-        Server server = OpcDaUtil.createServer(dataSource);
-        Integer id = itemGroup.getId();
-        Integer dataSourceId = dataSource.getId();
-        try {
-            if (itemGroup.getReadMode() == ConstantStr.ON_FREQUENCY) {
-                server.connect();
-                SyncAccess access = new SyncAccess(server, itemGroup.getModeValue() * 1000);
-//                AccessBase access = new Async20Access(server, itemGroup.getModeValue() ,true);
-                for (com.example.opc_common.entity.Item item : itemList) {
-                    String itemId = item.getItemReadName();
-                    Integer eventMode = item.getEventMode();
-                    Integer eventValue = item.getEventValue();
-                    Integer tableReportId = item.getTableReportId();
-                    access.addItem(itemId, new DataCallback() {
-                        private long timeLong = 0;
-
-                        @Override
-                        public void changed(Item item, ItemState itemState) {
-                            try {
-                                Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
-                                DataModel dm = map.get(itemId);
-                                //读取的值
-                                String javaType = String.valueOf(val.get("javaType"));
-                                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
-                                Object value = val.get("value");
-                                //值对应取值的时间
-                                Date time = itemState.getTimestamp().getTime();
-                                long time1 = time.getTime();
-                                if (timeLong == time1) {
-                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                                }
-                                timeLong = time1;
-                                //归属时间
-                                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-                                String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
-                                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
-                                //如果redis中存储的年月日时的时间为空,说明还未进行数据的保存
-                                if (javaType.toLowerCase().equals("boolean")) {
-                                    if (Blank.isEmpty(storageYmdh)) {
-                                        //将当前时间(归属时间)的年月日时存入redis
-                                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                        //将此时读取的数据,用集合的方式存入到redis中
-                                        List<Boolean> dataValueList = new ArrayList<>();
-                                        dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                        redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                        //将此时server中读取的时间,存入到redis中
-                                        List<String> dataValueTimeList = new ArrayList<>();
-                                        dataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else {
-                                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                            List<Boolean> dataValueList = new ArrayList<>();
-                                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueObject)) {
-                                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                            }
-                                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> dataValueTimeList = new ArrayList<>();
-                                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                            }
-                                            dataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                        } else {
-                                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                            List<Boolean> dataValueList = new ArrayList<>();
-                                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueObject)) {
-                                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                            }
-
-                                            List<String> dataValueTimeList = new ArrayList<>();
-                                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                            }
-                                            //存数据
-                                            RawData rawData = new RawData(dataSourceId,
-                                                    itemId,
-                                                    javaType,
-                                                    JSON.toJSONString(dataValueList),
-                                                    String.valueOf(dataValueTimeList),
-                                                    String.valueOf(valueBelongTime),
-                                                    new Date());
-                                            opcAsyncTask.addRawData(id, rawData);
-
-                                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                            dataValueList = new ArrayList<>();
-                                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                            dataValueTimeList = new ArrayList<>();
-                                            dataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    }
-                                } else {
-                                    if (Blank.isEmpty(storageYmdh)) {
-                                        //将当前时间(归属时间)的年月日时存入redis
-                                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                        //将此时读取的数据,用集合的方式存入到redis中
-                                        try {
-                                            List<BigDecimal> dataValueList = new ArrayList<>();
-                                            BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                    MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                    bigDecimal;
-                                            dataValueList.add(dmData);
-                                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                    if (dmData.compareTo(bigEventValue) == 1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                    if (dmData.compareTo(bigEventValue) == -1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                            }
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                        } catch (Exception e) {
-                                            List<String> dataValueList = new ArrayList<>();
-                                            dataValueList.add(value.toString());
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                        }
-
-                                        //将此时server中读取的时间,存入到redis中
-                                        List<String> dataValueTimeList = new ArrayList<>();
-                                        dataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else {
-                                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                            try {
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                }
-                                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                        bigDecimal;
-                                                dataValueList.add(dmData);
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    }
-                                                }
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            } catch (Exception e) {
-                                                List<String> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                                }
-                                                dataValueList.add(value.toString());
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            }
-
-                                            List<String> dataValueTimeList = new ArrayList<>();
-                                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                            }
-                                            dataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                        } else {
-                                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                            List<String> dataValueTimeList = new ArrayList<>();
-                                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                            }
-
-                                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                            try {
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                dataValueList = new ArrayList<>();
-                                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                        bigDecimal;
-                                                dataValueList.add(dmData);
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            } catch (Exception e) {
-                                                List<String> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                dataValueList = new ArrayList<>();
-                                                dataValueList.add(value.toString());
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            }
-
-                                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                            dataValueTimeList = new ArrayList<>();
-                                            dataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    }
-                                }
-                            } catch (Exception e) {
-                                //存入已有的数据
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                }
-
-                                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                                if (javaType.toLowerCase().equals("boolean")) {
-                                    List<Boolean> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-                                } else {
-                                    try {
-                                        List<BigDecimal> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-
-                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                            }
-                                        }
-                                    } catch (Exception e1) {
-                                        List<String> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-                                    }
-                                }
-                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                                        e.getMessage(),
-                                        ConstantStr.NO_READ));
-                                if (Blank.isNotEmpty(server)) {
-                                    server.dispose();
-                                }
-                                for (com.example.opc_common.entity.Item item_ : itemList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + item_.getItemReadName());
-                                }
-                                redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
-                                timer.cancel();
-                            }
-                        }
-                    });
-                }
-                access.bind();
-                while (true) {
-                    Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
-                    if (Blank.isEmpty(flage)) {
-                        flage = false;
-                    }
-                    if (!flage) {
-                        //存已经存入redis中的数据
-                        for (com.example.opc_common.entity.Item item : itemList) {
-                            String itemId = item.getItemReadName();
-                            Integer eventMode = item.getEventMode();
-                            Integer eventValue = item.getEventValue();
-                            Integer tableReportId = item.getTableReportId();
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-
-                            String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                            if (javaType.toLowerCase().equals("boolean")) {
-                                List<Boolean> dataValueList = new ArrayList<>();
-                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-                            } else {
-                                try {
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-
-                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        }
-                                    }
-                                } catch (Exception e1) {
-                                    List<String> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-                                }
-                            }
-                            redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-                        }
-
-                        messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
-                                "请刷新检查组的运行状态",
-                                ConstantStr.NO_READ));
-                        access.unbind();
-                        if (Blank.isNotEmpty(server)) {
-                            server.dispose();
-                        }
-
-                        redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                        itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
-                        timer.cancel();
-                        break;
-                    }
-                }
-            } else if (itemGroup.getReadMode() == ConstantStr.ON_CHANGE) {
-                server.connect();
-                SyncAccess access = new SyncAccess(server, 1000);
-                for (com.example.opc_common.entity.Item item : itemList) {
-                    String itemId = item.getItemReadName();
-                    Integer eventMode = item.getEventMode();
-                    Integer eventValue = item.getEventValue();
-                    Integer tableReportId = item.getTableReportId();
-                    access.addItem(itemId, new DataCallback() {
-                        private Map<String, Object> valueMap;
-                        private long timeLong = 0;
-
-                        @Override
-                        public void changed(Item item, ItemState itemState) {
-                            try {
-                                Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
-                                DataModel dm = map.get(itemId);
-                                //读取的值
-                                String javaType = String.valueOf(val.get("javaType"));
-                                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
-                                Object value = val.get("value");
-                                //值对应取值的时间
-                                Date time = itemState.getTimestamp().getTime();
-                                long time1 = time.getTime();
-                                if (timeLong == time1) {
-                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                                }
-                                timeLong = time1;
-                                //归属时间
-                                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-                                String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
-                                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
-                                //最开始读值的时候,没得数据,则将读取出来的数据赋值给valueMap
-                                if (Blank.isEmpty(valueMap)) {
-                                    valueMap = val;
-
-                                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh);
-
-                                    if (javaType.toLowerCase().equals("boolean")) {
-                                        List<Boolean> dataValueList = new ArrayList<>();
-                                        dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                        redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                    } else {
-                                        try {
-                                            List<BigDecimal> dataValueList = new ArrayList<>();
-                                            BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                    MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                    bigDecimal;
-                                            dataValueList.add(dmData);
-                                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                    if (dmData.compareTo(bigEventValue) == 1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                    if (dmData.compareTo(bigEventValue) == -1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                            }
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                        } catch (Exception e) {
-                                            List<String> dataValueList = new ArrayList<>();
-                                            dataValueList.add(value.toString());
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                        }
-                                    }
-                                    List<String> dataValueTimeList = new ArrayList<>();
-                                    dataValueTimeList.add(currentYmdhmss);
-                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                } else {
-                                    //如果时间相等,时间还在同一个小时中
-                                    if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                        //如果上次的值和这次读的值不等,则将数据存入到redis中
-                                        if (!valueMap.equals(val)) {
-                                            if (javaType.toLowerCase().equals("boolean")) {
-                                                List<Boolean> dataValueList = new ArrayList<>();
-                                                dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            } else {
-                                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                                try {
-                                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                    }
-                                                    BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                    BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                            MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                            bigDecimal;
-                                                    dataValueList.add(dmData);
-                                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                        BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                            if (dmData.compareTo(bigEventValue) == 1) {
-                                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                                }
-                                                                eventDataValueList.add(dmData);
-                                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                                }
-                                                                eventDataValueTimeList.add(currentYmdhmss);
-                                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                            }
-                                                        } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                            if (dmData.compareTo(bigEventValue) == -1) {
-                                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                                }
-                                                                eventDataValueList.add(dmData);
-                                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                                }
-                                                                eventDataValueTimeList.add(currentYmdhmss);
-                                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                            }
-                                                        }
-                                                    }
-                                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                                } catch (Exception e) {
-                                                    List<String> dataValueList = new ArrayList<>();
-                                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                                        dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                                    }
-                                                    dataValueList.add(value.toString());
-                                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                                }
-                                            }
-                                            List<String> dataValueTimeList = new ArrayList<>();
-                                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                            }
-                                            dataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-
-                                            valueMap = val;
-                                        }
-                                    } else {
-                                        //如果时间不在同一个小时中了,将redis中已经存在的值保存到数据库,新的重新存入到redis中
-                                        String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                        List<String> dataValueTimeList = new ArrayList<>();
-                                        Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                            dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                        }
-
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (javaType.toLowerCase().equals("boolean")) {
-                                            List<Boolean> dataValueList = new ArrayList<>();
-                                            if (Blank.isNotEmpty(dataValueObject)) {
-                                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                            }
-                                            //存数据
-                                            RawData rawData = new RawData(dataSourceId,
-                                                    itemId,
-                                                    javaType,
-                                                    JSON.toJSONString(dataValueList),
-                                                    String.valueOf(dataValueTimeList),
-                                                    String.valueOf(valueBelongTime),
-                                                    new Date());
-                                            opcAsyncTask.addRawData(id, rawData);
-
-                                            dataValueList = new ArrayList<>();
-                                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                        } else {
-                                            try {
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                dataValueList = new ArrayList<>();
-                                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                        bigDecimal;
-                                                dataValueList.add(dmData);
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            } catch (Exception e) {
-                                                List<String> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                dataValueList = new ArrayList<>();
-                                                dataValueList.add(value.toString());
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                            }
-                                        }
-                                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                        dataValueTimeList = new ArrayList<>();
-                                        dataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-                            } catch (Exception e) {
-                                //存入已有的数据
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                }
-
-                                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                                if (javaType.toLowerCase().equals("boolean")) {
-                                    List<Boolean> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-                                } else {
-                                    try {
-                                        List<BigDecimal> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-
-                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                            }
-                                        }
-                                    } catch (Exception e1) {
-                                        List<String> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-                                    }
-                                }
-
-                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                                        e.getMessage(),
-                                        ConstantStr.NO_READ));
-                                e.printStackTrace();
-                                if (Blank.isNotEmpty(server)) {
-                                    server.dispose();
-                                }
-                                for (com.example.opc_common.entity.Item item_ : itemList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + item_.getItemReadName());
-                                }
-                                redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
-                                timer.cancel();
-                            }
-                        }
-                    });
-                }
-                access.bind();
-                while (true) {
-                    Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                    if (Blank.isEmpty(flage)) {
-                        flage = false;
-                    }
-                    if (!flage) {
-                        //存已经存入redis中的数据
-                        for (com.example.opc_common.entity.Item item : itemList) {
-                            String itemId = item.getItemReadName();
-                            Integer eventMode = item.getEventMode();
-                            Integer eventValue = item.getEventValue();
-                            Integer tableReportId = item.getTableReportId();
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-
-                            String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                            if (javaType.toLowerCase().equals("boolean")) {
-                                List<Boolean> dataValueList = new ArrayList<>();
-                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-                            } else {
-                                try {
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-
-                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        }
-                                    }
-                                } catch (Exception e1) {
-                                    List<String> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-                                }
-                            }
-                            redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-                        }
-
-                        messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
-                                "请刷新检查组的运行状态",
-                                ConstantStr.NO_READ));
-                        access.unbind();
-                        if (Blank.isNotEmpty(server)) {
-                            server.dispose();
-                        }
-                        redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                        itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
-                        timer.cancel();
-                        break;
-                    }
-                }
-            } else if (itemGroup.getReadMode() == ConstantStr.EXCEED_SET_VALUE) {
-                server.connect();
-                SyncAccess access = new SyncAccess(server, 1000);
-                for (com.example.opc_common.entity.Item item : itemList) {
-                    String itemId = item.getItemReadName();
-                    Integer eventMode = item.getEventMode();
-                    Integer eventValue = item.getEventValue();
-                    Integer tableReportId = item.getTableReportId();
-                    access.addItem(itemId, new DataCallback() {
-                        private long timeLong = 0;
-
-                        @Override
-                        public void changed(Item item, ItemState itemState) {
-                            try {
-                                Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
-                                DataModel dm = map.get(itemId);
-                                BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
-
-                                //读取的值
-                                Object value = val.get("value");
-                                String javaType = String.valueOf(val.get("javaType"));
-                                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
-                                //值对应取值的时间
-                                Date time = itemState.getTimestamp().getTime();
-                                long time1 = time.getTime();
-                                if (timeLong == time1) {
-                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                                }
-                                timeLong = time1;
-                                //归属时间
-                                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-                                String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
-                                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
-                                //只判断能转换为BigDecimal类型的
-                                if (!javaType.toLowerCase().equals("boolean")) {
-                                    try {
-                                        BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                        BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
-                                        if (Blank.isEmpty(storageYmdh)) {
-                                            if (dmData.compareTo(bigModeValue) == 1) {
-                                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                dataValueList.add(dmData);
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                                List<String> dataValueTimeList = new ArrayList<>();
-                                                dataValueTimeList.add(currentYmdhmss);
-                                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                    if (dmData.compareTo(bigEventValue) == 1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                    if (dmData.compareTo(bigEventValue) == -1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                            }
-                                        } else {
-                                            if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                                if (dmData.compareTo(bigModeValue) == 1) {
-                                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                    }
-                                                    dataValueList.add(dmData);
-                                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                                    List<String> dataValueTimeList = new ArrayList<>();
-                                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                                    }
-                                                    dataValueTimeList.add(currentYmdhmss);
-                                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                                }
-
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    }
-                                                }
-                                            } else {
-                                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                                List<String> dataValueTimeList = new ArrayList<>();
-                                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                                }
-
-                                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-
-                                                dataValueList = new ArrayList<>();
-                                                dataValueTimeList = new ArrayList<>();
-                                                if (dmData.compareTo(bigModeValue) == 1) {
-                                                    dataValueList.add(dmData);
-                                                    dataValueTimeList.add(currentYmdhmss);
-                                                }
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-                                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                        }
-                                    } catch (Exception e) {
-
-                                    }
-                                }
-                            } catch (Exception e) {
-                                //存入已有的数据
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                }
-
-                                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                                if (!javaType.toLowerCase().equals("boolean")) {
-                                    try {
-                                        List<BigDecimal> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-
-                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                            }
-                                        }
-                                    } catch (Exception e1) {
-
-                                    }
-                                }
-
-                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                                        e.getMessage(),
-                                        ConstantStr.NO_READ));
-                                e.printStackTrace();
-                                if (Blank.isNotEmpty(server)) {
-                                    server.dispose();
-                                }
-                                for (com.example.opc_common.entity.Item item_ : itemList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + item_.getItemReadName());
-                                }
-                                redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
-                                timer.cancel();
-                            }
-                        }
-                    });
-                }
-                access.bind();
-                while (true) {
-                    Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                    if (Blank.isEmpty(flage)) {
-                        flage = false;
-                    }
-                    if (!flage) {
-                        //存已经存入redis中的数据
-                        for (com.example.opc_common.entity.Item item : itemList) {
-                            String itemId = item.getItemReadName();
-                            Integer eventMode = item.getEventMode();
-                            Integer eventValue = item.getEventValue();
-                            Integer tableReportId = item.getTableReportId();
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-
-                            String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                            if (!javaType.toLowerCase().equals("boolean")) {
-                                try {
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-
-                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                                eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        }
-                                    }
-                                } catch (Exception e1) {
-
-                                }
-                            }
-                            redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-                        }
-
-                        messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
-                                "请刷新检查组的运行状态",
-                                ConstantStr.NO_READ));
-                        access.unbind();
-                        if (Blank.isNotEmpty(server)) {
-                            server.dispose();
-                        }
-                        redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                        itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
-                        timer.cancel();
-                        break;
-                    }
-                }
-            } else if (itemGroup.getReadMode() == ConstantStr.LOWER_SET_VALUE) {
-                server.connect();
-                SyncAccess access = new SyncAccess(server, 1000);
-                for (com.example.opc_common.entity.Item item : itemList) {
-                    String itemId = item.getItemReadName();
-                    Integer eventMode = item.getEventMode();
-                    Integer eventValue = item.getEventValue();
-                    Integer tableReportId = item.getTableReportId();
-                    access.addItem(itemId, new DataCallback() {
-                        private long timeLong = 0;
-
-                        @Override
-                        public void changed(Item item, ItemState itemState) {
-                            try {
-                                Map<String, Object> val = OpcDaUtil.getVal(itemState.getValue());
-                                DataModel dm = map.get(itemId);
-                                BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
-
-                                //读取的值
-                                Object value = val.get("value");
-                                String javaType = String.valueOf(val.get("javaType"));
-                                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
-                                //值对应取值的时间
-                                Date time = itemState.getTimestamp().getTime();
-                                long time1 = time.getTime();
-                                if (timeLong == time1) {
-                                    redisUtil.set(ConstantStr.ITEM_GROUP + id, false, ConstantStr.TWO_HOUR);
-                                }
-                                timeLong = time1;
-                                //归属时间
-                                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-                                String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
-                                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
-                                //只判断能转换为BigDecimal类型的
-                                if (!javaType.toLowerCase().equals("boolean")) {
-                                    try {
-                                        BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                        BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
-                                        if (Blank.isEmpty(storageYmdh)) {
-                                            if (dmData.compareTo(bigModeValue) == -1) {
-                                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                dataValueList.add(dmData);
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                                List<String> dataValueTimeList = new ArrayList<>();
-                                                dataValueTimeList.add(currentYmdhmss);
-                                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                    if (dmData.compareTo(bigEventValue) == 1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                    if (dmData.compareTo(bigEventValue) == -1) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        eventDataValueList.add(dmData);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        eventDataValueTimeList.add(currentYmdhmss);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-                                            }
-                                        } else {
-                                            if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                                if (dmData.compareTo(bigModeValue) == -1) {
-                                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                    }
-                                                    dataValueList.add(dmData);
-                                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                                    List<String> dataValueTimeList = new ArrayList<>();
-                                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                                    }
-                                                    dataValueTimeList.add(currentYmdhmss);
-                                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                                }
-
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                            }
-                                                            eventDataValueList.add(dmData);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                            }
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                        }
-                                                    }
-                                                }
-                                            } else {
-                                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                                List<String> dataValueTimeList = new ArrayList<>();
-                                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                                }
-
-                                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                                if (Blank.isNotEmpty(dataValueObject)) {
-                                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                                }
-                                                //存数据
-                                                RawData rawData = new RawData(dataSourceId,
-                                                        itemId,
-                                                        javaType,
-                                                        JSON.toJSONString(dataValueList),
-                                                        String.valueOf(dataValueTimeList),
-                                                        String.valueOf(valueBelongTime),
-                                                        new Date());
-                                                opcAsyncTask.addRawData(id, rawData);
-
-                                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                        }
-
-                                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                        }
-                                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                                        eventDataValueList = new ArrayList<>();
-                                                        eventDataValueTimeList = new ArrayList<>();
-                                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                                            eventDataValueList.add(dmData);
-                                                            eventDataValueTimeList.add(currentYmdhmss);
-                                                        }
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                                    }
-                                                }
-
-                                                dataValueList = new ArrayList<>();
-                                                dataValueTimeList = new ArrayList<>();
-                                                if (dmData.compareTo(bigModeValue) == -1) {
-                                                    dataValueList.add(dmData);
-                                                    dataValueTimeList.add(currentYmdhmss);
-                                                }
-                                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-                                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                        }
-                                    } catch (Exception e) {
-
-                                    }
-                                }
-                            } catch (Exception e) {
-                                //存入已有的数据
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                }
-
-                                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                                if (!javaType.toLowerCase().equals("boolean")) {
-                                    try {
-                                        List<BigDecimal> dataValueList = new ArrayList<>();
-                                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(dataValueObject)) {
-                                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                        }
-                                        //存数据
-                                        RawData rawData = new RawData(dataSourceId,
-                                                itemId,
-                                                javaType,
-                                                JSON.toJSONString(dataValueList),
-                                                String.valueOf(dataValueTimeList),
-                                                String.valueOf(valueBelongTime),
-                                                new Date());
-                                        opcAsyncTask.addRawData(id, rawData);
-
-                                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                            BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)||
-                                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                            }
-                                        }
-                                    } catch (Exception e1) {
-
-                                    }
-                                }
-
-                                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                                        e.getMessage(),
-                                        ConstantStr.NO_READ));
-                                e.printStackTrace();
-                                if (Blank.isNotEmpty(server)) {
-                                    server.dispose();
-                                }
-                                for (com.example.opc_common.entity.Item item_ : itemList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + item_.getItemReadName());
-                                }
-                                redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
-                                timer.cancel();
-                            }
-                        }
-                    });
-                }
-                access.bind();
-                while (true) {
-                    Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                    if (Blank.isEmpty(flage)) {
-                        flage = false;
-                    }
-                    if (!flage) {
-                        //存已经存入redis中的数据
-                        for (com.example.opc_common.entity.Item item : itemList) {
-                            String itemId = item.getItemReadName();
-                            Integer eventMode = item.getEventMode();
-                            Integer eventValue = item.getEventValue();
-                            Integer tableReportId = item.getTableReportId();
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-
-                            String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                            if (!javaType.toLowerCase().equals("boolean")) {
-                                try {
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    //存数据
-                                    RawData rawData = new RawData(dataSourceId,
-                                            itemId,
-                                            javaType,
-                                            JSON.toJSONString(dataValueList),
-                                            String.valueOf(dataValueTimeList),
-                                            String.valueOf(valueBelongTime),
-                                            new Date());
-                                    opcAsyncTask.addRawData(id, rawData);
-
-                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                        BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)||
-                                                eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        }
-                                    }
-                                } catch (Exception e1) {
-
-                                }
-                            }
-                            redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-                        }
-
-                        messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                                itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
-                                "请刷新检查组的运行状态",
-                                ConstantStr.NO_READ));
-                        access.unbind();
-                        if (Blank.isNotEmpty(server)) {
-                            server.dispose();
-                        }
-                        redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
-                        itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
-                        timer.cancel();
-                        break;
-                    }
-                }
-            } else {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配其他类型的读取模式");
-            }
-        } catch (Exception e) {
-            String message = e.getMessage();
-            String messageContent = "";
-            if (message.contains("0x00000005")) {
-                messageContent = "账号或密码错误";
-            } else if (message.contains("0x8001FFFF") || message.contains("Index 16 out of bounds for length 16")) {
-                messageContent = "ip连接不可用";
-            } else {
-                messageContent = e.getMessage();
-            }
-            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                    messageContent,
-                    ConstantStr.NO_READ));
-            redisUtil.convertAndSend(ConstantStr.ITEM_GROUP, Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "组" + itemGroup.getGroupName() + "运行异常,错误信息为:" + messageContent));
-            if (Blank.isNotEmpty(server)) {
-                server.dispose();
-            }
-            redisUtil.del(ConstantStr.ITEM_GROUP + itemGroup.getId());
-            itemGroupDao.runItemGroupById(itemGroup.getId(), ConstantStr.STOP_IT);
-            timer.cancel();
-        }
-
-    }
-}

+ 72 - 70
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTableTask.java

@@ -68,60 +68,36 @@ public class ReportTableTask {
             log.info("动态报表,{},执行结束,执行时间为{}", reportTable, DateUtil.dateChangeStrYmdhmss(new Date()));
             return;
         }
-        JSONObject jsonObject1 = objects.getJSONObject(0);
-        JSONArray objects1 = jsonObject1.getJSONArray("item");
-        if (Blank.isNotEmpty(objects1)) {
-            for (int i = 0; i < objects1.size(); i++) {
-                JSONObject jsonObject2 = objects1.getJSONObject(i);
-                Integer itemGroupId = jsonObject2.getInteger("itemGroupId");
-                Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
-                ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
-                String itemName = jsonObject2.getString("itemName");
-                if (reportTable.getReportValueFormat() == ConstantStr.EVERY_DAY_ES) {
-                    String startBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(-1, 8)).substring(0, timeFormat.length());
-                    //获取当前时间,并转为yyyy-MM-dd HH
-                    String endBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(0, 7)).substring(0, timeFormat.length());
-                    List<RawData> rawDataList = rawDataDao.getTableDataEvery(itemGroupId, remainder, itemGroup.getDataSourceId(), itemName, startBelongTime, endBelongTime);
-                    if (Blank.isNotEmpty(rawDataList)) {
-                        String dataType = rawDataList.get(0).getDataType();
-                        List<String> dataTimeList = new ArrayList();
-                        if (dataType.equals("boolean")) {
-                            List<Boolean> booleanList = new ArrayList<>();
-                            for (int j = 0; j < rawDataList.size(); j++) {
-                                String dataValue = rawDataList.get(j).getDataValue();
-                                Boolean[] dataValueList = JSON.parseObject(dataValue, Boolean[].class);
-                                Boolean avg;
-                                if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
-                                    avg = MathUtil.getAvgBoolean(dataValueList);
-                                } else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
-                                    avg = MathUtil.getMaxBoolean(dataValueList);
-                                } else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
-                                    avg = MathUtil.getMinBoolean(dataValueList);
-                                } else {
-                                    messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
-                                            reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
-                                            "目前还未适配此种类型数据组的取值条件",
-                                            ConstantStr.NO_READ));
-                                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
-                                }
-                                booleanList.add(avg);
-                                String valueBelongTime = rawDataList.get(j).getValueBelongTime();
-                                dataTimeList.add(valueBelongTime);
-                            }
-                            jsonObject2.put("dataList", booleanList);
-                        } else {
-                            List<Object> dataList = new ArrayList();
-                            for (int j = 0; j < rawDataList.size(); j++) {
-                                String dataValue = rawDataList.get(j).getDataValue();
-                                try {
-                                    BigDecimal[] dataValueList = JSON.parseObject(dataValue, BigDecimal[].class);
-                                    BigDecimal avg;
+        for (int i = 0; i < objects.size(); i++) {
+            JSONObject jsonObject1 = objects.getJSONObject(i);
+            JSONArray objects1 = jsonObject1.getJSONArray("item");
+            if (Blank.isNotEmpty(objects1)) {
+                for (int j = 0; j < objects1.size(); j++) {
+                    JSONObject jsonObject2 = objects1.getJSONObject(j);
+                    Integer itemGroupId = jsonObject2.getInteger("itemGroupId");
+                    Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+                    ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
+                    String itemName = jsonObject2.getString("itemName");
+                    if (reportTable.getReportValueFormat() == ConstantStr.EVERY_DAY_ES) {
+                        String startBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(-1, 8)).substring(0, timeFormat.length());
+                        //获取当前时间,并转为yyyy-MM-dd HH
+                        String endBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(0, 7)).substring(0, timeFormat.length());
+                        List<RawData> rawDataList = rawDataDao.getTableDataEvery(itemGroupId, remainder, itemGroup.getDataSourceId(), itemName, startBelongTime, endBelongTime);
+                        if (Blank.isNotEmpty(rawDataList)) {
+                            String dataType = rawDataList.get(0).getDataType();
+                            List<String> dataTimeList = new ArrayList();
+                            if (dataType.equals("boolean")) {
+                                List<Boolean> booleanList = new ArrayList<>();
+                                for (int k = 0; k < rawDataList.size(); k++) {
+                                    String dataValue = rawDataList.get(k).getDataValue();
+                                    Boolean[] dataValueList = JSON.parseObject(dataValue, Boolean[].class);
+                                    Boolean avg;
                                     if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
-                                        avg = MathUtil.getAvg(dataValueList);
+                                        avg = MathUtil.getAvgBoolean(dataValueList);
                                     } else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
-                                        avg = MathUtil.getMax(dataValueList);
+                                        avg = MathUtil.getMaxBoolean(dataValueList);
                                     } else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
-                                        avg = MathUtil.getMin(dataValueList);
+                                        avg = MathUtil.getMinBoolean(dataValueList);
                                     } else {
                                         messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
                                                 reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
@@ -129,34 +105,60 @@ public class ReportTableTask {
                                                 ConstantStr.NO_READ));
                                         throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
                                     }
-                                    dataList.add(avg);
-                                } catch (Exception e) {
-                                    String[] dataValueList = JSON.parseObject(dataValue, String[].class);
-                                    if (Blank.isNotEmpty(dataValueList)) {
-                                        dataList.add(dataValueList[0]);
-                                    } else {
-                                        dataList.add("");
+                                    booleanList.add(avg);
+                                    String valueBelongTime = rawDataList.get(k).getValueBelongTime();
+                                    dataTimeList.add(valueBelongTime);
+                                }
+                                jsonObject2.put("dataList", booleanList);
+                            } else {
+                                List<Object> dataList = new ArrayList();
+                                for (int k = 0; k < rawDataList.size(); k++) {
+                                    String dataValue = rawDataList.get(k).getDataValue();
+                                    try {
+                                        BigDecimal[] dataValueList = JSON.parseObject(dataValue, BigDecimal[].class);
+                                        BigDecimal avg;
+                                        if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
+                                            avg = MathUtil.getAvg(dataValueList);
+                                        } else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
+                                            avg = MathUtil.getMax(dataValueList);
+                                        } else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
+                                            avg = MathUtil.getMin(dataValueList);
+                                        } else {
+                                            messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
+                                                    reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
+                                                    "目前还未适配此种类型数据组的取值条件",
+                                                    ConstantStr.NO_READ));
+                                            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
+                                        }
+                                        dataList.add(avg);
+                                    } catch (Exception e) {
+                                        String[] dataValueList = JSON.parseObject(dataValue, String[].class);
+                                        if (Blank.isNotEmpty(dataValueList)) {
+                                            dataList.add(dataValueList[0]);
+                                        } else {
+                                            dataList.add("");
+                                        }
                                     }
+                                    String valueBelongTime = rawDataList.get(j).getValueBelongTime();
+                                    dataTimeList.add(valueBelongTime);
                                 }
-                                String valueBelongTime = rawDataList.get(i).getValueBelongTime();
-                                dataTimeList.add(valueBelongTime);
+                                jsonObject2.put("dataList", dataList);
                             }
-                            jsonObject2.put("dataList", dataList);
+                        } else {
+                            jsonObject2.put("dataList", new ArrayList<>());
                         }
                     } else {
-                        jsonObject2.put("dataList", new ArrayList<>());
+                        messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
+                                reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
+                                "目前还未适配此种类型数据组的取值条件",
+                                ConstantStr.NO_READ));
+                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
                     }
-                } else {
-                    messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
-                            reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
-                            "目前还未适配此种类型数据组的取值条件",
-                            ConstantStr.NO_READ));
-                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
+                    objects1.set(j, jsonObject2);
                 }
-                objects1.set(i, jsonObject2);
             }
+            objects.set(i, jsonObject1);
         }
-        objects.set(0, jsonObject1);
         jsonObject.put("tables", objects);
         ReportTable reportTable1 = new ReportTable();
         reportTable1.setTableTemplateId(reportTable.getTableTemplateId());

+ 61 - 59
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -31,6 +31,7 @@ import java.math.BigDecimal;
 import java.net.UnknownHostException;
 import java.util.*;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 @Slf4j
 public class OpcDaUtil {
@@ -71,20 +72,7 @@ public class OpcDaUtil {
             log.info("连接耗费时间为:" + (finish - start) + "毫秒");
             return Result.ok("测试连接成功");
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("0x00000005")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "账号校验不通过,账号或密码错误,本地安全策略有问题");
-            } else if (message.contains("0x8001FFFF") || message.contains("Index 16 out of bounds for length 16")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "ip不存在或ip不互通");
-            } else if (message.contains("0x80040154")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "clsId不存在");
-            } else if (message.contains("0x80040153")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "注册表中未找到此驱动,可能是注册表未删除干净");
-            }
-            if (message.contains("0x80070005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置");
-            }
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(server)) {
                 server.dispose();
@@ -108,7 +96,7 @@ public class OpcDaUtil {
             }
             if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
                 if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
-                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue())||
+                        dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue()) ||
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
                     List<JSONObject> jsonObjectList = generServerTree(server);
                     return Result.ok(jsonObjectList);
@@ -116,25 +104,15 @@ public class OpcDaUtil {
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())) {
                     List<JSONObject> jsonObjectList = generWinccTree(server);
                     return Result.ok(jsonObjectList);
+                } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())) {
+                    List<JSONObject> jsonObjectList = generPAS300Tree(server);
+                    return Result.ok(jsonObjectList);
                 } else {
                     throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
                 }
             }
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("0x00000005")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "账号校验不通过,账号或密码错误,本地安全策略有问题");
-            } else if (message.contains("0x8001FFFF")|| message.contains("Index 16 out of bounds for length 16")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "ip不存在或ip不互通");
-            } else if (message.contains("0x80040154")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "clsId不存在");
-            } else if (message.contains("0x80040153")) {
-                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "注册表中未找到此驱动,可能是注册表未删除干净");
-            }
-            if (message.contains("0x80070005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置");
-            }
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(server)) {
                 server.dispose();
@@ -213,6 +191,25 @@ public class OpcDaUtil {
         return jsonList;
     }
 
+    public static List<JSONObject> generPAS300Tree(Server server) throws JIException, UnknownHostException {
+        List<JSONObject> jsonList = new ArrayList<>();
+        //获取服务器下所有ITEM列表,树形展示
+        TreeBrowser treeBrowser = server.getTreeBrowser();
+        Branch browse = treeBrowser.browse();
+        if (Blank.isEmpty(browse)) {
+            return null;
+        }
+        Collection<Leaf> leaves = browse.getLeaves();
+        if (Blank.isNotEmpty(leaves)) {
+            for (Leaf leaf : leaves) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("label", leaf.getName());
+                jsonList.add(jsonObject);
+            }
+        }
+        return jsonList;
+    }
+
     public static List<JSONObject> recursionServerChildren(Collection<Branch> branchCollection) {
         List<JSONObject> jsonList = new ArrayList<>();
         for (Branch branch : branchCollection) {
@@ -286,27 +283,23 @@ public class OpcDaUtil {
             }
             return jsonObjectList;
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("0x00000005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "账号或密码错误");
-            }
-            if (message.contains("0x8001FFFF")|| message.contains("Index 16 out of bounds for length 16")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "ip地址不存在");
-            }
-            if (message.contains("0x80070005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置");
-            }
-            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), genException(e.getMessage()));
         }
     }
 
     public static List<Item> genReadNameDa(DataSource dataSource, List<Item> itemList) {
         if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
-                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue())
+                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.SCADA.getValue()) ||
+                dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.PAS300.getValue())
         ) {
             for (int i = 0; i < itemList.size(); i++) {
                 itemList.get(i).setItemReadName(itemList.get(i).getItemName());
             }
+        } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
+            for (int i = 0; i < itemList.size(); i++) {
+                int n = itemList.get(i).getItemName().indexOf(".");
+                itemList.get(i).setItemReadName(itemList.get(i).getItemName().replaceFirst("\\.", "!"));
+            }
         } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
             for (int i = 0; i < itemList.size(); i++) {
                 String itemName = itemList.get(i).getItemName();
@@ -433,6 +426,7 @@ public class OpcDaUtil {
                             jsonObject.put("dataSourceName", dataSource.getDataSourceName());
                             jsonObject.put("itemName", item.getItemName());
                             jsonObject.put("dataType", javaType);
+                            jsonObject.put("eventMode", item.getEventMode());
                             jsonObject.put("dataOrgValue", value);
                             if (javaType.toLowerCase().equals("boolean")) {
                                 jsonObject.put("dataValue", value);
@@ -452,28 +446,15 @@ public class OpcDaUtil {
                         }
                     }
                 }
-
-                jsonObjectList.sort(new Comparator<JSONObject>() {
-                    @Override
-                    public int compare(JSONObject o1, JSONObject o2) {
-                        return o1.getString("itemName").compareTo(o2.getString("itemName"));
-                    }
-                });
+                jsonObjectList.stream()
+                        .sorted(Comparator.comparing((JSONObject jsonObject) -> jsonObject.getInteger("eventMode")).reversed()
+                                .thenComparing(jsonObject -> jsonObject.getString("itemName")
+                                )).collect(Collectors.toList());
                 return jsonObjectList;
             }
         } catch (Exception e) {
             e.printStackTrace();
-            String message = e.getMessage();
-            if (message.contains("0x00000005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "账号或密码错误");
-            }
-            if (message.contains("0x8001FFFF")|| message.contains("Index 16 out of bounds for length 16")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "ip地址不存在");
-            }
-            if (message.contains("0x80070005")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置");
-            }
-            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(server)) {
                 server.dispose();
@@ -481,4 +462,25 @@ public class OpcDaUtil {
         }
         return null;
     }
+
+    public static String genException(String message) {
+        if (Blank.isEmpty(message)) {
+            return "";
+        }
+        if (message.contains("0x00000005")) {
+            return "账号或密码错误";
+        } else if (message.contains("0x8001FFFF")) {
+            return "ip连接不可用";
+        } else if (message.contains("Index 16 out of bounds for length 16") ||
+                message.contains("java.lang.ArrayIndexOutOfBoundsException: 16")) {
+            return "服务未启动";
+        } else if (message.contains("0x80070005")) {
+            return "访问被拒绝,可能是权限未配置,配置可在组件服务中进行配置";
+        } else if (message.contains("0x80040154")) {
+            return "驱动(clsId)不存在";
+        } else if (message.contains("0x80040153")) {
+            return "注册表中未找到此驱动,可能是注册表未删除干净";
+        }
+        return message;
+    }
 }

+ 1 - 1
chaunyi_opc/opc_da/src/main/resources/application.yml

@@ -1,6 +1,6 @@
 spring:
   profiles:
-    active: dev
+    active: @spring.profiles.active@
   jackson:
     date-format: yyyy-MM-dd HH:mm:ss
     time-zone: GMT+8

+ 12 - 16
chaunyi_opc/opc_da/src/main/resources/mapper/DataModelDao.xml

@@ -69,22 +69,18 @@
         </foreach>
     </select>
 
-    <select id="getItemByDaModel" resultType="com.example.opc_common.entity.Item">
-        select ti.id
-             , ti.item_group_id
-             , ti.item_name
-             , ti.item_read_name
-             , ti.node_index
-             , ti.data_type
-             , ti.`describe`
-             , ti.data_model_id
-             , ti.event_mode
-             , ti.event_value
-             , ti.table_report_id
-             , tig.group_name as item_group_name
-        from t_item ti
-                 left join t_item_group tig on ti.item_group_id = tig.id
-        where data_model_id = #{id}
+    <select id="getItemGroupByDm" resultType="java.util.Map">
+        SELECT ti.item_group_id,
+               tig.group_name AS item_group_name,
+               count(ti.id) AS count
+        FROM
+            t_item ti
+            LEFT JOIN t_item_group tig
+        ON ti.item_group_id = tig.id
+        WHERE
+            ti.data_model_id = #{id}
+        GROUP BY
+            ti.item_group_id;
     </select>
 
 </mapper>

+ 19 - 3
chaunyi_opc/opc_da/src/main/resources/mapper/ItemGroupDao.xml

@@ -55,7 +55,8 @@
         set data_model_id=#{dataModelId},
             event_mode=#{eventMode},
             event_value=#{eventValue},
-            table_report_id=#{tableReportId}, `describe`=#{describe}
+            table_report_id=#{tableReportId},
+            `describe`=#{describe}
         where id = #{id}
     </update>
 
@@ -138,7 +139,7 @@
         FROM t_item ti
                  LEFT JOIN t_data_model tdm ON ti.data_model_id = tdm.id
         where item_group_id = #{itemGroupId}
-        order by item_name
+        order by event_mode DESC,item_name
     </select>
 
     <select id="getPublicItemList" resultType="com.example.opc_common.entity.Item">
@@ -185,4 +186,19 @@
         where item_group_id = #{itemGroupId}
           AND item_name = #{itemName}
     </select>
-</mapper>
+
+    <select id="getItemGroupListByTableId" resultType="com.example.opc_common.entity.ItemGroup">
+        SELECT
+        <include refid="itemGroup"/>
+        FROM
+        t_item_group
+        WHERE
+        id IN (
+        SELECT DISTINCT
+        ( item_group_id )
+        FROM
+        t_item
+        WHERE
+        table_report_id = #{tableReportId})
+    </select>
+</mapper>

+ 70 - 2
chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml

@@ -10,7 +10,8 @@
         insert into t_raw_data${remainder}
         (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
          create_time)
-        VALUES (#{itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType}, #{rawData.dataValue},
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
                 #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
     </insert>
 
@@ -26,6 +27,43 @@
         </foreach>
     </insert>
 
+    <insert id="addTempRawData">
+        insert into t_raw_data
+        (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
+         create_time)
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
+                #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
+    </insert>
+
+    <insert id="addEventRawData">
+        insert into t_event_raw_data
+        (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
+         create_time)
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
+                #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
+    </insert>
+
+    <delete id="delRawDataList">
+        delete
+        from t_raw_data
+        where value_belong_time = #{valueBelongTime}
+        and
+        <foreach collection="rawDataList" item="rawData" index="index" separator=",">
+            (#{rawData.id})
+        </foreach>
+    </delete>
+
+    <delete id="delEventRawDataList">
+        delete
+        from t_evnet_raw_data
+        where item_group_id = #{item.itemGroupId}
+          and data_souerce_id = #{dataSourceId}
+          and item_name = #{item.itemReadName}
+          and value_belong_time = #{valueBelongTime}
+    </delete>
+
     <select id="getLineOrBarData" resultType="com.example.opc_common.entity.RawData">
         SELECT id, data_source_id, item_name, data_type, data_value, create_time
         FROM t_raw_data${remainder}
@@ -80,4 +118,34 @@
         AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY value_belong_time
     </select>
-</mapper>
+
+    <select id="getTempRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select data_type, data_value
+        from t_raw_data
+        where item_group_id = #{item.itemGroupId}
+          and data_souerce_id = #{dataSourceId}
+          and item_name = #{item.itemReadName}
+          and value_belong_time = #{valueBelongTime}
+        order by data_value_time desc
+    </select>
+
+    <select id="getRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select
+        <include refid="rawData"/>
+        from t_raw_data${remainder}
+        where item_group_id = #{item.itemGroupId}
+        and data_souerce_id = #{dataSourceId}
+        and item_name = #{item.itemReadName}
+        and value_belong_time = #{valueBelongTime}
+    </select>
+
+    <select id="getEventRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select
+        <include refid="rawData"/>
+        from t_evnet_raw_data
+        where item_group_id = #{item.itemGroupId}
+        and data_souerce_id = #{dataSourceId}
+        and item_name = #{item.itemReadName}
+        and value_belong_time = #{valueBelongTime}
+    </select>
+</mapper>

+ 8 - 5
chaunyi_opc/opc_da/src/main/resources/mapper/ReportTableDao.xml

@@ -280,9 +280,10 @@
     </select>
 
     <select id="getTableUserGroup" resultType="com.example.opc_common.entity.UserGroup">
-        select user_group_id as id
-        from t_table_user_group
-        where table_id = #{templateName}
+        select ttug.user_group_id as id,
+        tug.user_group_name as userGroupName
+        from t_table_user_group ttug left join t_user_group tug on ttug.user_group_id=tug.id
+        where table_id = #{reportTableId}
     </select>
 
     <select id="getAllOkReportTableCount" resultType="java.lang.Integer">
@@ -340,12 +341,14 @@
         <collection column="id" property="userGroupList"
                     ofType="com.example.opc_common.entity.UserGroup" select="getUserGroupById">
             <id column="id" property="id"/>
+            <id column="user_group_name" property="userGroupName"/>
         </collection>
     </resultMap>
 
     <select id="getUserGroupById" parameterType="INTEGER" resultType="com.example.opc_common.entity.UserGroup">
-        SELECT user_group_id as id
-        FROM t_table_user_group
+        select ttug.user_group_id as id,
+        tug.user_group_name as userGroupName
+        from t_table_user_group ttug left join t_user_group tug on ttug.user_group_id=tug.id
         where table_id = #{id}
     </select>
 

+ 6 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/UserDao.xml

@@ -444,5 +444,11 @@
         )) sur on sr.id=sur.department_id
     </select>
 
+    <select id="getAllUserIdByType" resultType="java.lang.String">
+        select user_id
+        from sys_user
+        where user_type = #{userType}
+    </select>
+
 
 </mapper>

+ 2 - 2
chaunyi_opc/opc_da/src/main/resources/static/app/index.html

@@ -1,5 +1,5 @@
-<!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>reado-app</title><script src=https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js></script><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS
+<!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>reado-app</title><script src=./static/jquery.min.js></script><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS
 				.supports('top: constant(a)'))
 			document.write(
 				'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
-				(coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=./static/index.63b34199.css><link rel=stylesheet href=./static/luckysheet/dist/plugins/plugins.css><link rel=stylesheet href=./static/luckysheet/dist/plugins/css/pluginsCss.css><link rel=stylesheet href=./static/luckysheet/dist/css/luckysheet.css><link rel=stylesheet href=./static/luckysheet/dist/assets/iconfont/iconfont.css><script src=./static/luckysheet/dist/luckysheet.umd.js></script><script src=./static/luckysheet/dist/plugins/js/plugin.js></script></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=./static/js/chunk-vendors.7d651a70.js></script><script src=./static/js/index.8b6b38d7.js></script></body></html>
+				(coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=./static/index.63b34199.css><link rel=stylesheet href=./static/luckysheet/dist/plugins/plugins.css><link rel=stylesheet href=./static/luckysheet/dist/plugins/css/pluginsCss.css><link rel=stylesheet href=./static/luckysheet/dist/css/luckysheet.css><link rel=stylesheet href=./static/luckysheet/dist/assets/iconfont/iconfont.css><script src=./static/luckysheet/dist/luckysheet.umd.js></script><script src=./static/luckysheet/dist/plugins/js/plugin.js></script></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=./static/js/chunk-vendors.35954aaa.js></script><script src=./static/js/index.c46a03fd.js></script></body></html>

Разлика између датотеке није приказан због своје велике величине
+ 1 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/jquery.min.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/chunk-vendors.35954aaa.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/chunk-vendors.7d651a70.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/index.8b6b38d7.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/index.c46a03fd.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index.921bd4fd.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index.c7063e47.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index~pages-user-index.44d1c315.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-login-index~pages-user-index.be72c672.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index.dd1a599d.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index.ecc7aa27.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-message-msg-detail-index~pages-reportForm-index~pages-reportForm-report-de~7378e1f1.4b1019b3.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-message-msg-detail-index~pages-reportForm-index~pages-reportForm-report-de~7378e1f1.ef51d87f.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-reportForm-index.c9a4fb74.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-index~pages-reportForm-index.ec286111.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-msg-detail-index.62eb5040.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-message-msg-detail-index.a393e18c.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-index.3bb42d0b.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-index.6dc8493b.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-report-detail-index.81d1b26f.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-reportForm-report-detail-index.9c7dfd89.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-user-index.9b09c104.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/app/static/js/pages-user-index.a6f66f4d.js


Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
chaunyi_opc/opc_da/src/main/resources/static/page/index.html


+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-06d702f0.9033d0a8.css → chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-25fa7e82.9033d0a8.css


+ 0 - 1
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-27a0e931.1783952f.css

@@ -1 +0,0 @@
-.statistics[data-v-7e4cc8c4]{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between;margin:30px auto;width:50%}.statistics .stat-item[data-v-7e4cc8c4]{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;text-align:center}.statistics .stat-item .stat-top[data-v-7e4cc8c4]{color:#676666}.statistics .stat-item .stat-bottom[data-v-7e4cc8c4]{font-size:20px;color:#000;margin-top:6px}

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-6fb8a920.060d547f.css


+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-33108a30.84f98409.css → chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-77eaefcc.84f98409.css


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-8edeae9a.dff46571.css


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/css/chunk-f198332e.91c42cb7.css


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/app.5ea0a1d2.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/app.ed78cea1.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-25fa7e82.5d15f594.js


+ 0 - 1
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-27a0e931.c885b15b.js

@@ -1 +0,0 @@
-(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-27a0e931"],{9406:function(t,e,n){"use strict";n.r(e);var a=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"sy-content"},[n("div",{staticClass:"statistics"},t._l(t.statData,(function(e,a){return n("div",{key:a,staticClass:"stat-item"},[n("span",{staticClass:"stat-top"},[t._v(t._s(e.title))]),n("span",{staticClass:"stat-bottom"},[t._v(t._s(e.num))])])})),0)])},s=[],c=n("3835"),u=n("5530"),i=(n("d3b7"),n("3ca3"),n("ddb0"),n("2f62")),o=n("b775");function r(){return Object(o["a"])({url:"/user/queryManagerUserNum",method:"get"})}function d(){return Object(o["a"])({url:"/user/queryCustomerUserNum",method:"get"})}function l(){return Object(o["a"])({url:"/role/queryRoleNum",method:"get"})}function f(){return Object(o["a"])({url:"/reportTable/queryTableNum",method:"get"})}var m={name:"Dashboard",data:function(){return{statData:[]}},computed:Object(u["a"])({},Object(i["b"])(["roles"])),created:function(){this.statistics()},methods:{statistics:function(){var t=this,e=new Promise((function(t,e){r().then((function(e){200===e.code&&t(e.data)}))})),n=new Promise((function(t,e){d().then((function(e){200===e.code&&t(e.data)}))})),a=new Promise((function(t,e){l().then((function(e){200===e.code&&t(e.data)}))})),s=new Promise((function(t,e){f().then((function(e){200===e.code&&t(e.data)}))}));Promise.all([e,n,a,s]).then((function(e){var n=Object(c["a"])(e,4),a=n[0],s=n[1],u=n[2],i=n[3];t.statData=[{title:"管理端用户数量",num:a},{title:"客户端用户数量",num:s},{title:"角色数量",num:u},{title:"报表数量",num:i}]}))}}},b=m,h=(n("df05"),n("2877")),p=Object(h["a"])(b,a,s,!1,null,"7e4cc8c4",null);e["default"]=p.exports},dcd5:function(t,e,n){},df05:function(t,e,n){"use strict";n("dcd5")}}]);

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-6fb8a920.eb2869a1.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-77eaefcc.deafbd58.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-8edeae9a.37d67e3e.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chaunyi_opc/opc_da/src/main/resources/static/page/static/js/chunk-f198332e.8e4a368f.js


+ 16 - 1
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/RawDataDao.java

@@ -1,5 +1,6 @@
 package com.example.opc_ua.dao;
 
+import com.example.opc_common.entity.Item;
 import com.example.opc_common.entity.RawData;
 import org.springframework.stereotype.Repository;
 
@@ -8,7 +9,21 @@ import java.util.List;
 @Repository
 public interface RawDataDao {
 
-    Integer addRawData(Integer itemGroupId, Integer remainder, RawData rawData);
+    Integer addRawData(Integer remainder, RawData rawData);
 
     Integer addRawDataList(Integer itemGroupId, Integer remainder, List<RawData> rawDataList);
+
+    Integer addTempRawData(RawData rawData);
+
+    RawData getRawDataList(Item item, Integer remainder, Integer dataSourceId, String valueBelongTime);
+
+    List<RawData> getTempRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
+
+    Integer delRawDataList(List<RawData> rawDataList, String valueBelongTime);
+
+    Integer addEventRawData(RawData rawData);
+
+    List<RawData> getEventRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
+
+    Integer delEventRawDataList(Item item, Integer dataSourceId, String valueBelongTime);
 }

+ 10 - 0
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/ReportTableDao.java

@@ -1,9 +1,19 @@
 package com.example.opc_ua.dao;
 
 import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.entity.TableAutoLog;
+import com.example.opc_common.entity.UserGroup;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 @Repository
 public interface ReportTableDao {
     ReportTable getReportTableById(Integer id);
+
+    Integer addReportTable(ReportTable reportTable);
+
+    Integer addTableAutoLog(TableAutoLog tableAutoLog);
+
+    Integer addTableUserGroup(Integer reportTableId, List<UserGroup> userGroupList);
 }

+ 223 - 33
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcAsyncTask.java

@@ -1,10 +1,12 @@
 package com.example.opc_ua.task;
 
-import com.example.opc_common.entity.DataSource;
-import com.example.opc_common.entity.RawData;
-import com.example.opc_common.entity.ReportTable;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.entity.*;
 import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
 import com.example.opc_ua.dao.RawDataDao;
 import com.example.opc_ua.dao.ReportTableDao;
 import com.example.opc_ua.util.OpcUaUtil;
@@ -18,6 +20,9 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 @Component
@@ -36,29 +41,136 @@ public class OpcAsyncTask {
     @Autowired
     private ReportTableDao reportTableDao;
 
+    public void addEventRawData(RawData rawData) {
+        if (Blank.isNotEmpty(rawData)) {
+            rawDataDao.addEventRawData(rawData);
+        }
+    }
+
     /**
-     * 新增一条原始数据
+     * 新增一条临时数据
      *
      * @param rawData
      */
-    public void addRawData(Integer id, RawData rawData) {
-        if (Blank.isNotEmpty(id) && Blank.isNotEmpty(rawData)) {
-            if (Blank.isNotEmpty(rawData.getValueBelongTime())) {
-                Integer remainder = id % ConstantStr.SUB_TABLE_NUM;
-                rawDataDao.addRawData(id, remainder, rawData);
-            }
+    public void addTempRawData(RawData rawData) {
+        if (Blank.isNotEmpty(rawData)) {
+            rawDataDao.addTempRawData(rawData);
         }
     }
 
     /**
-     * 新增原始数据集合
+     * 将临时数据库表中的原始数据组装为分表中的数据
      *
-     * @param rawDataList
+     * @param item
+     * @param sqlCurrentYmdh
      */
-    public void addRawDataList(Integer id, List<RawData> rawDataList) {
-        if (Blank.isNotEmpty(id) && Blank.isNotEmpty(rawDataList)) {
-            Integer remainder = id % ConstantStr.SUB_TABLE_NUM;
-            rawDataDao.addRawDataList(id, remainder, rawDataList);
+    public void packageRawData(Item item, Integer dataSourceId, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(5000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Integer itemGroupId = item.getItemGroupId();
+        Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+        if (Blank.isNotEmpty(item)) {
+            RawData oldRawData = rawDataDao.getRawDataList(item, remainder, dataSourceId, sqlCurrentYmdh);
+            List<RawData> rawDataList = rawDataDao.getTempRawDataList(item, dataSourceId, sqlCurrentYmdh);
+            if (Blank.isNotEmpty(rawDataList)) {
+                RawData rawData1 = rawDataList.get(0);
+                String itemName = rawData1.getItemName();
+                String dataType = rawData1.getDataType();
+                if (dataType.equals("boolean")) {
+                    List<Boolean> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), Boolean[].class)) : new ArrayList<>();
+                    List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                    for (RawData rawData : rawDataList) {
+                        dataList.add(JSON.parseObject(rawData.getDataValue(), Boolean.class));
+                        dataTimeList.add(rawData.getDataValueTime());
+                    }
+                    RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                            JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                    rawDataDao.addRawData(remainder, rawData);
+                } else {
+                    List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                    try {
+                        List<BigDecimal> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), BigDecimal[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            BigDecimal bigDecimal = JSON.parseObject(rawData.getDataValue(), BigDecimal.class);
+                            dataList.add(bigDecimal);
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    } catch (Exception e) {
+                        List<String> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), String[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            dataList.add(rawData.getDataValue());
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    }
+                }
+                rawDataDao.delRawDataList(rawDataList, sqlCurrentYmdh);
+            }
+        }
+    }
+
+    public void packageRawDataList(List<Item> itemList, Integer dataSourceId, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(10000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (Blank.isNotEmpty(itemList)) {
+            Item item1 = itemList.get(0);
+            Integer itemGroupId = item1.getItemGroupId();
+            Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+            for (Item item : itemList) {
+                RawData oldRawData = rawDataDao.getRawDataList(item, remainder, dataSourceId, sqlCurrentYmdh);
+                List<RawData> rawDataList = rawDataDao.getTempRawDataList(item, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(rawDataList)) {
+                    RawData rawData1 = rawDataList.get(0);
+                    String itemName = rawData1.getItemName();
+                    String dataType = rawData1.getDataType();
+                    if (dataType.equals("boolean")) {
+                        List<Boolean> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), Boolean[].class)) : new ArrayList<>();
+                        List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                        for (RawData rawData : rawDataList) {
+                            dataList.add(JSON.parseObject(rawData.getDataValue(), Boolean.class));
+                            dataTimeList.add(rawData.getDataValueTime());
+                        }
+                        RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                        rawDataDao.addRawData(remainder, rawData);
+                    } else {
+                        List<String> dataTimeList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValueTime(), String[].class)) : new ArrayList<>();
+                        try {
+                            List<BigDecimal> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), BigDecimal[].class)) : new ArrayList<>();
+                            for (RawData rawData : rawDataList) {
+                                BigDecimal bigDecimal = JSON.parseObject(rawData.getDataValue(), BigDecimal.class);
+                                dataList.add(bigDecimal);
+                                dataTimeList.add(rawData.getDataValueTime());
+                            }
+                            RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                    JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                            rawDataDao.addRawData(remainder, rawData);
+                        } catch (Exception e) {
+                            List<String> dataList = Blank.isNotEmpty(oldRawData) ? Arrays.asList(JSON.parseObject(oldRawData.getDataValue(), String[].class)) : new ArrayList<>();
+                            for (RawData rawData : rawDataList) {
+                                dataList.add(rawData.getDataValue());
+                                dataTimeList.add(rawData.getDataValueTime());
+                            }
+                            RawData rawData = new RawData(itemGroupId, dataSourceId, itemName, dataType, JSON.toJSONString(dataList),
+                                    JSON.toJSONString(dataTimeList), sqlCurrentYmdh, new Date());
+                            rawDataDao.addRawData(remainder, rawData);
+                        }
+                    }
+                    rawDataDao.delRawDataList(rawDataList, sqlCurrentYmdh);
+                }
+            }
         }
     }
 
@@ -72,18 +184,7 @@ public class OpcAsyncTask {
             opcUaClient.connect().get();
             redisUtil.set(ConstantStr.DATA_SOURCE_TREE + dataSource.getId(), String.valueOf(OpcUaUtil.generOpcUaTree(opcUaClient, null)));
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("Bad_ConnectionRejected")) {
-                log.info("ip连接不可用");
-            } else if (message.contains("Bad_UserAccessDenied")) {
-                log.info("用户无权执行请求的操作");
-            } else if (message.contains("cannot create signer")) {
-                log.info("证书创建失败,无法创建签名者");
-            } else if (message.contains("Bad_Timeout")) {
-                log.info("连接超时");
-            } else {
-                log.info(e.getMessage());
-            }
+            log.info(OpcUaUtil.genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();
@@ -94,11 +195,100 @@ public class OpcAsyncTask {
     /**
      * 事件驱动报表异步添加数据
      */
-    public void eventTable(Integer tableReportId, BigDecimal value, String currentDate) {
+    public void eventTable(Integer dataSourceId, List<Item> itemList, String sqlCurrentYmdh) {
+        try {
+            Thread.sleep(10000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Integer tableReportId = null;
+        if (Blank.isNotEmpty(itemList)) {
+            for (Item item : itemList) {
+                if (Blank.isNotEmpty(item.getEventMode()) && Blank.isNotEmpty(item.getEventValue()) && Blank.isNotEmpty(item.getTableReportId())) {
+                    tableReportId = item.getTableReportId();
+                    break;
+                }
+            }
+        }
+        if (Blank.isEmpty(tableReportId)) {
+            return;
+        }
         ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
-    }
-
-    public void addEventTable(Integer tableReportId,List<BigDecimal> eventDataValueList, List<String> eventDataValueTimeList){
-
+        String reportTableData = reportTable.getReportTableData();
+        JSONObject jsonObject = JSONObject.parseObject(reportTableData);
+        JSONArray objects = jsonObject.getJSONArray("tables");
+        if (Blank.isEmpty(objects)) {
+            ReportTable reportTable1 = new ReportTable();
+            reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
+            reportTable1.setUserId(reportTable.getUserId());
+            reportTable1.setReportTableName(reportTable.getReportTableName() + "_" + DateUtil.dateChangeStr(new Date(), "yyyyMMddHHmmss"));
+            reportTable1.setReportTableData(jsonObject.toJSONString());
+            reportTable1.setReportValueFormat(reportTable.getReportValueFormat());
+            reportTable1.setIsAutoReport(ConstantStr.EVENT_GENERATE_REPORT);
+            reportTable1.setVersion(reportTable.getVersion());
+            reportTableDao.addReportTable(reportTable1);
+            TableAutoLog tableAutoLog = new TableAutoLog();
+            tableAutoLog.setAutoTableId(reportTable.getId());
+            tableAutoLog.setAutoChTableId(reportTable1.getId());
+            reportTableDao.addTableAutoLog(tableAutoLog);
+            if (Blank.isNotEmpty(reportTable.getUserGroupList())) {
+                reportTableDao.addTableUserGroup(reportTable1.getId(), reportTable.getUserGroupList());
+            }
+            return;
+        }
+        JSONObject jsonObject1 = objects.getJSONObject(0);
+        JSONArray objects1 = jsonObject1.getJSONArray("item");
+        if (Blank.isNotEmpty(itemList)) {
+            for (int i = 0; i < itemList.size(); i++) {
+                List<RawData> rawDataList = rawDataDao.getEventRawDataList(itemList.get(i), dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(rawDataList)) {
+                    JSONObject jsonObject2 = new JSONObject();
+                    RawData rawData = rawDataList.get(0);
+                    String dataType = rawData.getDataType();
+                    if (dataType.toLowerCase().equals("boolean")) {
+                        List<Boolean> dataList = new ArrayList<>();
+                        for (RawData rawData1 : rawDataList) {
+                            dataList.add(JSON.parseObject(rawData1.getDataValue(), Boolean.class));
+                        }
+                        jsonObject2.put("dataList", dataList);
+                    } else {
+                        try {
+                            List<BigDecimal> dataList = new ArrayList<>();
+                            for (RawData rawData1 : rawDataList) {
+                                dataList.add(JSON.parseObject(rawData1.getDataValue(), BigDecimal.class));
+                            }
+                            jsonObject2.put("dataList", dataList);
+                        } catch (Exception e) {
+                            List<String> dataList = new ArrayList<>();
+                            for (RawData rawData1 : rawDataList) {
+                                dataList.add(rawData1.getDataValue());
+                            }
+                            jsonObject2.put("dataList", dataList);
+                        }
+                    }
+                    jsonObject2.put("dataTimeList", JSON.parseObject(rawData.getDataValueTime(), String[].class));
+                    objects1.set(i, jsonObject2);
+                }
+                rawDataDao.delEventRawDataList(itemList.get(i), dataSourceId, sqlCurrentYmdh);
+            }
+        }
+        objects.set(0, jsonObject1);
+        jsonObject.put("tables", objects);
+        ReportTable reportTable1 = new ReportTable();
+        reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
+        reportTable1.setUserId(reportTable.getUserId());
+        reportTable1.setReportTableName(reportTable.getReportTableName() + "_" + DateUtil.dateChangeStr(new Date(), "yyyyMMddHHmmss"));
+        reportTable1.setReportTableData(jsonObject.toJSONString());
+        reportTable1.setReportValueFormat(reportTable.getReportValueFormat());
+        reportTable1.setIsAutoReport(ConstantStr.EVENT_GENERATE_REPORT);
+        reportTable1.setVersion(reportTable.getVersion());
+        reportTableDao.addReportTable(reportTable1);
+        TableAutoLog tableAutoLog = new TableAutoLog();
+        tableAutoLog.setAutoTableId(reportTable.getId());
+        tableAutoLog.setAutoChTableId(reportTable1.getId());
+        reportTableDao.addTableAutoLog(tableAutoLog);
+        if (Blank.isNotEmpty(reportTable.getUserGroupList())) {
+            reportTableDao.addTableUserGroup(reportTable1.getId(), reportTable.getUserGroupList());
+        }
     }
 }

+ 78 - 468
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaChangeTask.java

@@ -39,6 +39,8 @@ public class OpcUaChangeTask extends TimerTask {
 
     private final String timeFormat;
 
+    private Boolean eventFlage = false;
+
     public OpcUaChangeTask(RedisUtil redisUtil,
                            OpcAsyncTask opcAsyncTask,
                            ItemGroupDao itemGroupDao,
@@ -70,11 +72,12 @@ public class OpcUaChangeTask extends TimerTask {
         for (Item item : itemList) {
             String itemId = item.getItemReadName();
             Integer eventMode = item.getEventMode();
-            Integer eventValue = item.getEventValue();
+            Double eventValue = item.getEventValue();
             Integer tableReportId = item.getTableReportId();
             NodeId n = new NodeId(item.getNodeIndex(), itemId);
             DataModel dm = map.get(itemId);
             Object redisValue = redisUtil.get(ConstantStr.VALUE + id + itemId);
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
             try {
                 DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
                 if (!dataValue.getStatusCode().isGood()) {
@@ -82,425 +85,113 @@ public class OpcUaChangeTask extends TimerTask {
                 }
                 Object value = dataValue.getValue().getValue();
                 String javaType = OpcUaUtil.getValType(dataValue);
-                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
                 Date time = dataValue.getServerTime().getJavaDate();
 
                 //归属时间
-                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                 String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                if (Blank.isEmpty(sqlCurrentYmdh)) {
+                    sqlCurrentYmdh = currentYmdh;
+                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                } else {
+                    if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                        //组装相应的数据
+                        opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                        }
+                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                        sqlCurrentYmdh = currentYmdh;
+                    }
+                }
                 String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
                 if (javaType.toLowerCase().equals("boolean")) {
-                    if (Blank.isEmpty(storageYmdh)) {
+                    if (JSON.parseObject(redisValue.toString(), Boolean.class) != JSON.parseObject(value.toString(), Boolean.class)) {
                         redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), Boolean.class), ConstantStr.TWO_HOUR);
-                        //将当前时间(归属时间)的年月日时存入redis
-                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
+                        Boolean dmData = JSON.parseObject(value.toString(), Boolean.class);
+                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                currentYmdhmss, currentYmdh, new Date());
+                        opcAsyncTask.addTempRawData(rawData);
 
-                        //将此时读取的数据,用集合的方式存入到redis中
-                        List<Boolean> dataValueList = new ArrayList<>();
-                        dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                        redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                        //将此时server中读取的时间,存入到redis中
-                        List<String> dataValueTimeList = new ArrayList<>();
-                        dataValueTimeList.add(currentYmdhmss);
-                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList);
-                    } else {
-                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                            if (JSON.parseObject(redisValue.toString(), Boolean.class) != JSON.parseObject(value.toString(), Boolean.class)) {
-                                redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), Boolean.class), ConstantStr.TWO_HOUR);
-
-                                List<Boolean> dataValueList = new ArrayList<>();
-                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                                }
-                                dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
+                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                            if (eventMode.equals(ConstantStr.EVENT_MODEL_BOOLEAN)) {
+                                if ((dmData ? ConstantStr.BOOLEAN_TRUE : ConstantStr.BOOLEAN_FALSE).equals(eventValue.intValue())) {
+                                    eventFlage = true;
+                                    opcAsyncTask.addEventRawData(rawData);
+                                } else {
+                                    eventFlage = false;
                                 }
-                                dataValueTimeList.add(currentYmdhmss);
-                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                             }
                         } else {
-                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<Boolean> dataValueList = new ArrayList<>();
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            if (Blank.isNotEmpty(dataValueObject)) {
-                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
+                            if (eventFlage) {
+                                opcAsyncTask.addEventRawData(rawData);
                             }
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-                            //存数据
-                            RawData rawData = new RawData(dataSourceId,
-                                    itemId,
-                                    javaType,
-                                    JSON.toJSONString(dataValueList),
-                                    String.valueOf(dataValueTimeList),
-                                    String.valueOf(valueBelongTime),
-                                    new Date());
-                            opcAsyncTask.addRawData(id, rawData);
-
-                            redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), Boolean.class), ConstantStr.TWO_HOUR);
-
-                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                            dataValueList = new ArrayList<>();
-                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                            dataValueTimeList = new ArrayList<>();
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                         }
                     }
                 } else {
-                    if (Blank.isEmpty(storageYmdh)) {
-                        //将当前时间(归属时间)的年月日时存入redis
-                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                        //将此时读取的数据,用集合的方式存入到redis中
-                        try {
-                            redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), BigDecimal.class), ConstantStr.TWO_HOUR);
+                    try {
+                        BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                        BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                bigDecimal;
+                        if (JSON.parseObject(redisValue.toString(), BigDecimal.class).compareTo(dmData) != 0) {
+                            RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                    currentYmdhmss, currentYmdh, new Date());
+                            opcAsyncTask.addTempRawData(rawData);
 
-                            List<BigDecimal> dataValueList = new ArrayList<>();
-                            BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                    MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                    bigDecimal;
-                            dataValueList.add(dmData);
                             if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
                                 BigDecimal bigEventValue = new BigDecimal(eventValue);
                                 if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
                                     if (dmData.compareTo(bigEventValue) == 1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
                                     if (dmData.compareTo(bigEventValue) == -1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 }
-                            }
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                        } catch (Exception e) {
-                            redisUtil.set(ConstantStr.VALUE + id + itemId, value.toString(), ConstantStr.TWO_HOUR);
-
-                            List<String> dataValueList = new ArrayList<>();
-                            dataValueList.add(value.toString());
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                        }
-
-                        //将此时server中读取的时间,存入到redis中
-                        List<String> dataValueTimeList = new ArrayList<>();
-                        dataValueTimeList.add(currentYmdhmss);
-                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                    } else {
-                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            try {
-                                if (JSON.parseObject(redisValue.toString(), Boolean.class) != JSON.parseObject(value.toString(), Boolean.class)) {
-                                    redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), BigDecimal.class), ConstantStr.TWO_HOUR);
-
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                    BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                            MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                            bigDecimal;
-                                    dataValueList.add(dmData);
-                                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                        BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                        if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                            if (dmData.compareTo(bigEventValue) == 1) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-                                                eventDataValueList.add(dmData);
-                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                eventDataValueTimeList.add(currentYmdhmss);
-                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                        } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                            if (dmData.compareTo(bigEventValue) == -1) {
-                                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                                }
-                                                eventDataValueList.add(dmData);
-                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                                }
-                                                eventDataValueTimeList.add(currentYmdhmss);
-                                                redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                            }
-                                        }
-                                    }
-                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                    List<String> dataValueTimeList = new ArrayList<>();
-                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                    }
-                                    dataValueTimeList.add(currentYmdhmss);
-                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
+                            } else {
+                                if (eventFlage) {
+                                    opcAsyncTask.addEventRawData(rawData);
                                 }
-                            } catch (Exception e) {
-                                if (!redisValue.toString().equals(value.toString())) {
-                                    redisUtil.set(ConstantStr.VALUE + id + itemId, value.toString(), ConstantStr.TWO_HOUR);
-
-                                    List<String> dataValueList = new ArrayList<>();
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                    }
-                                    dataValueList.add(value.toString());
-                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                    List<String> dataValueTimeList = new ArrayList<>();
-                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                    }
-                                    dataValueTimeList.add(currentYmdhmss);
-                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                }
-                            }
-                        } else {
-                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
                             }
-
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            try {
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                dataValueList = new ArrayList<>();
-                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                        bigDecimal;
-                                dataValueList.add(dmData);
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                redisUtil.set(ConstantStr.VALUE + id + itemId, JSON.parseObject(value.toString(), BigDecimal.class), ConstantStr.TWO_HOUR);
-                            } catch (Exception e) {
-                                List<String> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                dataValueList = new ArrayList<>();
-                                dataValueList.add(value.toString());
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                redisUtil.set(ConstantStr.VALUE + id + itemId, value.toString(), ConstantStr.TWO_HOUR);
+                        }
+                    } catch (Exception e) {
+                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+                                currentYmdhmss, currentYmdh, new Date());
+                        opcAsyncTask.addTempRawData(rawData);
+
+                        if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+                            if (eventFlage) {
+                                opcAsyncTask.addEventRawData(rawData);
                             }
-                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                            dataValueTimeList = new ArrayList<>();
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                         }
                     }
                 }
             } catch (Exception e) {
-                //存入已有的数据
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (javaType.toLowerCase().equals("boolean")) {
-                    List<Boolean> dataValueList = new ArrayList<>();
-                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                    if (Blank.isNotEmpty(dataValueObject)) {
-                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                    }
-                    //存数据
-                    RawData rawData = new RawData(dataSourceId,
-                            itemId,
-                            javaType,
-                            JSON.toJSONString(dataValueList),
-                            String.valueOf(dataValueTimeList),
-                            String.valueOf(valueBelongTime),
-                            new Date());
-                    opcAsyncTask.addRawData(id, rawData);
-                } else {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-                        List<String> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-                    }
+                //执行组装数据库的数据,以及生成驱动报表
+                opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
                 }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
                 messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
                         itemGroup.getGroupName() + "-" + itemId + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                         e.getMessage(),
                         ConstantStr.NO_READ));
-                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
+                }
+
+                redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                timer.cancel();
             }
         }
         Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
@@ -508,92 +199,11 @@ public class OpcUaChangeTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (Item item : itemList) {
-                String itemId = item.getItemReadName();
-                Integer eventMode = item.getEventMode();
-                Integer eventValue = item.getEventValue();
-                Integer tableReportId = item.getTableReportId();
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (javaType.toLowerCase().equals("boolean")) {
-                    List<Boolean> dataValueList = new ArrayList<>();
-                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                    if (Blank.isNotEmpty(dataValueObject)) {
-                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                    }
-                    //存数据
-                    RawData rawData = new RawData(dataSourceId,
-                            itemId,
-                            javaType,
-                            JSON.toJSONString(dataValueList),
-                            String.valueOf(dataValueTimeList),
-                            String.valueOf(valueBelongTime),
-                            new Date());
-                    opcAsyncTask.addRawData(id, rawData);
-                } else {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-                        List<String> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-            }
+            //执行组装数据库的数据,以及生成驱动报表
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();

+ 63 - 275
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaExceedTask.java

@@ -39,6 +39,8 @@ public class OpcUaExceedTask extends TimerTask {
 
     private final String timeFormat;
 
+    private Boolean eventFlage = false;
+
     public OpcUaExceedTask(RedisUtil redisUtil,
                            OpcAsyncTask opcAsyncTask,
                            ItemGroupDao itemGroupDao,
@@ -70,11 +72,12 @@ public class OpcUaExceedTask extends TimerTask {
         for (Item item : itemList) {
             String itemId = item.getItemReadName();
             Integer eventMode = item.getEventMode();
-            Integer eventValue = item.getEventValue();
+            Double eventValue = item.getEventValue();
             Integer tableReportId = item.getTableReportId();
             NodeId n = new NodeId(item.getNodeIndex(), itemId);
             DataModel dm = map.get(itemId);
             BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
             try {
                 DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
                 if (!dataValue.getStatusCode().isGood()) {
@@ -82,12 +85,23 @@ public class OpcUaExceedTask extends TimerTask {
                 }
                 Object value = dataValue.getValue().getValue();
                 String javaType = OpcUaUtil.getValType(dataValue);
-                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
                 Date time = dataValue.getServerTime().getJavaDate();
 
-                //归属时间
-                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                 String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                if (Blank.isEmpty(sqlCurrentYmdh)) {
+                    sqlCurrentYmdh = currentYmdh;
+                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                } else {
+                    if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                        //组装相应的数据
+                        opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                        }
+                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                        sqlCurrentYmdh = currentYmdh;
+                    }
+                }
                 String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
                 if (!javaType.toLowerCase().equals("boolean")) {
                     try {
@@ -95,244 +109,66 @@ public class OpcUaExceedTask extends TimerTask {
                         BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                 MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
                                 bigDecimal;
-                        if (Blank.isEmpty(storageYmdh)) {
-                            if (dmData.compareTo(bigModeValue) == 1) {
-                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
+                        if (dmData.compareTo(bigModeValue) == 1) {
+                            RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                    currentYmdhmss, currentYmdh, new Date());
+                            opcAsyncTask.addTempRawData(rawData);
 
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                dataValueList.add(dmData);
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                dataValueTimeList.add(currentYmdhmss);
-                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                            }
                             if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
                                 BigDecimal bigEventValue = new BigDecimal(eventValue);
                                 if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
                                     if (dmData.compareTo(bigEventValue) == 1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
                                     if (dmData.compareTo(bigEventValue) == -1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-                            }
-                        } else {
-                            if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                if (dmData.compareTo(bigModeValue) == 1) {
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    dataValueList.add(dmData);
-                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                    List<String> dataValueTimeList = new ArrayList<>();
-                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                    }
-                                    dataValueTimeList.add(currentYmdhmss);
-                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                }
-
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 }
                             } else {
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                }
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
+                                if (eventFlage) {
+                                    opcAsyncTask.addEventRawData(rawData);
                                 }
-
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId, itemId, javaType, JSON.toJSONString(dataValueList), String.valueOf(dataValueTimeList), String.valueOf(valueBelongTime), new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-
-                                dataValueList = new ArrayList<>();
-                                dataValueTimeList = new ArrayList<>();
-                                if (dmData.compareTo(bigModeValue) == 1) {
-                                    dataValueList.add(dmData);
-                                    dataValueTimeList.add(currentYmdhmss);
-                                }
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                             }
                         }
                     } catch (Exception e) {
-
+//                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+//                                currentYmdhmss, currentYmdh, new Date());
+//                        opcAsyncTask.addTempRawData(rawData);
+//
+//                        if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+//                            if (eventFlage) {
+//                                opcAsyncTask.addEventRawData(rawData);
+//                            }
+//                        }
                     }
                 }
             } catch (Exception e) {
-                //存入已有的数据
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
+                //执行组装数据库的数据,以及生成驱动报表
+                opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
                 }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (!javaType.toLowerCase().equals("boolean")) {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
                 messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
                         itemGroup.getGroupName() + "-" + itemId + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                         e.getMessage(),
                         ConstantStr.NO_READ));
 
-                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
+                }
+
+                redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                timer.cancel();
             }
         }
         Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
@@ -340,64 +176,16 @@ public class OpcUaExceedTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (Item item : itemList) {
-                String itemId = item.getItemReadName();
-                Integer eventMode = item.getEventMode();
-                Integer eventValue = item.getEventValue();
-                Integer tableReportId = item.getTableReportId();
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (!javaType.toLowerCase().equals("boolean")) {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-            }
+            //执行组装数据库的数据,以及生成驱动报表
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                    "请刷新检查组的运行状态",
+                    ConstantStr.NO_READ));
 
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();

+ 91 - 449
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaFrequencyTask.java

@@ -41,6 +41,8 @@ public class OpcUaFrequencyTask extends TimerTask {
 
     private final String timeFormat;
 
+    private Boolean eventFlage = false;
+
     public OpcUaFrequencyTask(RedisUtil redisUtil,
                               OpcAsyncTask opcAsyncTask,
                               ItemGroupDao itemGroupDao,
@@ -72,10 +74,11 @@ public class OpcUaFrequencyTask extends TimerTask {
         for (Item item : itemList) {
             String itemId = item.getItemReadName();
             Integer eventMode = item.getEventMode();
-            Integer eventValue = item.getEventValue();
+            Double eventValue = item.getEventValue();
             Integer tableReportId = item.getTableReportId();
             NodeId n = new NodeId(item.getNodeIndex(), itemId);
             DataModel dm = map.get(itemId);
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
             try {
                 DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
                 if (!dataValue.getStatusCode().isGood()) {
@@ -83,394 +86,109 @@ public class OpcUaFrequencyTask extends TimerTask {
                 }
                 Object value = dataValue.getValue().getValue();
                 String javaType = OpcUaUtil.getValType(dataValue);
-                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
                 Date time = dataValue.getServerTime().getJavaDate();
 
-                //归属时间
-                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                 String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
-                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
-                if (javaType.toLowerCase().equals("boolean")) {
-                    if (Blank.isEmpty(storageYmdh)) {
-                        //将当前时间(归属时间)的年月日时存入redis
-                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                        //将此时读取的数据,用集合的方式存入到redis中
-                        List<Boolean> dataValueList = new ArrayList<>();
-                        dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                        redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                        //将此时server中读取的时间,存入到redis中
-                        List<String> dataValueTimeList = new ArrayList<>();
-                        dataValueTimeList.add(currentYmdhmss);
-                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                    } else {
-                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                            List<Boolean> dataValueList = new ArrayList<>();
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            if (Blank.isNotEmpty(dataValueObject)) {
-                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                            }
-                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                        } else {
-                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<Boolean> dataValueList = new ArrayList<>();
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            if (Blank.isNotEmpty(dataValueObject)) {
-                                dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                            }
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-                            //存数据
-                            RawData rawData = new RawData(dataSourceId,
-                                    itemId,
-                                    javaType,
-                                    JSON.toJSONString(dataValueList),
-                                    String.valueOf(dataValueTimeList),
-                                    String.valueOf(valueBelongTime),
-                                    new Date());
-                            opcAsyncTask.addRawData(id, rawData);
-
-                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                            dataValueList = new ArrayList<>();
-                            dataValueList.add(JSON.parseObject(value.toString(), Boolean.class));
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                            dataValueTimeList = new ArrayList<>();
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
+                if (Blank.isEmpty(sqlCurrentYmdh)) {
+                    sqlCurrentYmdh = currentYmdh;
+                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                } else {
+                    if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                        //组装相应的数据
+                        opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
                         }
+                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                        sqlCurrentYmdh = currentYmdh;
                     }
-                } else {
-                    if (Blank.isEmpty(storageYmdh)) {
-                        //将当前时间(归属时间)的年月日时存入redis
-                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                        //将此时读取的数据,用集合的方式存入到redis中
-                        try {
-                            List<BigDecimal> dataValueList = new ArrayList<>();
-                            BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                    MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                    bigDecimal;
-                            dataValueList.add(dmData);
-                            if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                    if (dmData.compareTo(bigEventValue) == 1) {
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                    if (dmData.compareTo(bigEventValue) == -1) {
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
+                }
+                String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
+                if (javaType.toLowerCase().equals("boolean")) {
+                    //存数据
+                    Boolean dmData = JSON.parseObject(value.toString(), Boolean.class);
+                    RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                            currentYmdhmss, currentYmdh, new Date());
+                    opcAsyncTask.addTempRawData(rawData);
+
+                    if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                        if (eventMode.equals(ConstantStr.EVENT_MODEL_BOOLEAN)) {
+                            if ((dmData ? ConstantStr.BOOLEAN_TRUE : ConstantStr.BOOLEAN_FALSE).equals(eventValue.intValue())) {
+                                eventFlage = true;
+                                opcAsyncTask.addEventRawData(rawData);
+                            } else {
+                                eventFlage = false;
                             }
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                        } catch (Exception e) {
-                            List<String> dataValueList = new ArrayList<>();
-                            dataValueList.add(value.toString());
-                            redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                         }
-
-                        //将此时server中读取的时间,存入到redis中
-                        List<String> dataValueTimeList = new ArrayList<>();
-                        dataValueTimeList.add(currentYmdhmss);
-                        redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                     } else {
-                        //如果redis中存入的归属时间不为空,进行判断,如果现在获取的时间==redis中存入的归属时间,则认定此时的数据,为同一小时的数据,将原来的数据取出,并添加
-                        if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            try {
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                }
-                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                        bigDecimal;
-                                dataValueList.add(dmData);
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    }
-                                }
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                            } catch (Exception e) {
-                                List<String> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                }
-                                dataValueList.add(value.toString());
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                            }
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                        } else {
-                            //如果当时获取的时间!=redis中存入的归属时间,则将redis中存入的归属时间和数据存入到数据库,redis中存入新的一个小时的数据
-                            String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                            List<String> dataValueTimeList = new ArrayList<>();
-                            Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                            if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                            }
-
-                            Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                            try {
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                dataValueList = new ArrayList<>();
-                                BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
-                                        MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                        bigDecimal;
-                                dataValueList.add(dmData);
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                            } catch (Exception e) {
-                                List<String> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                                }
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                dataValueList = new ArrayList<>();
-                                dataValueList.add(value.toString());
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                            }
-
-                            redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-
-                            dataValueTimeList = new ArrayList<>();
-                            dataValueTimeList.add(currentYmdhmss);
-                            redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
+                        if (eventFlage) {
+                            opcAsyncTask.addEventRawData(rawData);
                         }
                     }
-                }
-
-            } catch (Exception e) {
-                //存入已有的数据
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (javaType.toLowerCase().equals("boolean")) {
-                    List<Boolean> dataValueList = new ArrayList<>();
-                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                    if (Blank.isNotEmpty(dataValueObject)) {
-                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                    }
-                    //存数据
-                    RawData rawData = new RawData(dataSourceId,
-                            itemId,
-                            javaType,
-                            JSON.toJSONString(dataValueList),
-                            String.valueOf(dataValueTimeList),
-                            String.valueOf(valueBelongTime),
-                            new Date());
-                    opcAsyncTask.addRawData(id, rawData);
                 } else {
                     try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
+                        BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                        BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                bigDecimal;
+                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                currentYmdhmss, currentYmdh, new Date());
+                        opcAsyncTask.addTempRawData(rawData);
 
                         if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
+                            BigDecimal bigEventValue = new BigDecimal(eventValue);
+                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
+                                if (dmData.compareTo(bigEventValue) == 1) {
+                                    eventFlage = true;
+                                    opcAsyncTask.addEventRawData(rawData);
+                                } else {
+                                    eventFlage = false;
                                 }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
+                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                if (dmData.compareTo(bigEventValue) == -1) {
+                                    eventFlage = true;
+                                    opcAsyncTask.addEventRawData(rawData);
+                                } else {
+                                    eventFlage = false;
                                 }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
+                            }
+                        } else {
+                            if (eventFlage) {
+                                opcAsyncTask.addEventRawData(rawData);
                             }
                         }
-                    } catch (Exception e1) {
-                        List<String> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
+                    } catch (Exception e) {
+                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+                                currentYmdhmss, currentYmdh, new Date());
+                        opcAsyncTask.addTempRawData(rawData);
+
+                        if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+                            if (eventFlage) {
+                                opcAsyncTask.addEventRawData(rawData);
+                            }
                         }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
                     }
                 }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+            } catch (Exception e) {
+                //执行组装数据库的数据,以及生成驱动报表
+                opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                }
+                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
                 messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
                         itemGroup.getGroupName() + "-" + itemId + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                         e.getMessage(),
                         ConstantStr.NO_READ));
-                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
+                }
+
+                redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                timer.cancel();
             }
         }
         Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
@@ -478,92 +196,16 @@ public class OpcUaFrequencyTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (Item item : itemList) {
-                String itemId = item.getItemReadName();
-                Integer eventMode = item.getEventMode();
-                Integer eventValue = item.getEventValue();
-                Integer tableReportId = item.getTableReportId();
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (javaType.toLowerCase().equals("boolean")) {
-                    List<Boolean> dataValueList = new ArrayList<>();
-                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                    if (Blank.isNotEmpty(dataValueObject)) {
-                        dataValueList = JavaTypeUtil.objChangeListBool(dataValueObject);
-                    }
-                    //存数据
-                    RawData rawData = new RawData(dataSourceId,
-                            itemId,
-                            javaType,
-                            JSON.toJSONString(dataValueList),
-                            String.valueOf(dataValueTimeList),
-                            String.valueOf(valueBelongTime),
-                            new Date());
-                    opcAsyncTask.addRawData(id, rawData);
-                } else {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED) ||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-                        List<String> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListStr(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-            }
+            //执行组装数据库的数据,以及生成驱动报表
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                    "请刷新检查组的运行状态",
+                    ConstantStr.NO_READ));
 
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();

+ 63 - 283
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaLowerTask.java

@@ -38,6 +38,8 @@ public class OpcUaLowerTask extends TimerTask {
 
     private final String timeFormat;
 
+    private Boolean eventFlage = false;
+
     public OpcUaLowerTask(RedisUtil redisUtil,
                           OpcAsyncTask opcAsyncTask,
                           ItemGroupDao itemGroupDao,
@@ -69,11 +71,12 @@ public class OpcUaLowerTask extends TimerTask {
         for (Item item : itemList) {
             String itemId = item.getItemReadName();
             Integer eventMode = item.getEventMode();
-            Integer eventValue = item.getEventValue();
+            Double eventValue = item.getEventValue();
             Integer tableReportId = item.getTableReportId();
             NodeId n = new NodeId(item.getNodeIndex(), itemId);
             DataModel dm = map.get(itemId);
             BigDecimal bigModeValue = new BigDecimal(itemGroup.getModeValue());
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
             try {
                 DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
                 if (!dataValue.getStatusCode().isGood()) {
@@ -81,12 +84,23 @@ public class OpcUaLowerTask extends TimerTask {
                 }
                 Object value = dataValue.getValue().getValue();
                 String javaType = OpcUaUtil.getValType(dataValue);
-                redisUtil.set(ConstantStr.JAVA_TYPE + id + itemId, javaType, ConstantStr.TWO_HOUR);
                 Date time = dataValue.getServerTime().getJavaDate();
 
-                //归属时间
-                String storageYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
                 String currentYmdh = DateUtil.dateChangeStr(time, timeFormat);
+                if (Blank.isEmpty(sqlCurrentYmdh)) {
+                    sqlCurrentYmdh = currentYmdh;
+                    redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                } else {
+                    if (!sqlCurrentYmdh.equals(currentYmdh)) {
+                        //组装相应的数据
+                        opcAsyncTask.packageRawData(item, dataSourceId, sqlCurrentYmdh);
+                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+                        }
+                        redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id, currentYmdh, ConstantStr.TWO_HOUR);
+                        sqlCurrentYmdh = currentYmdh;
+                    }
+                }
                 String currentYmdhmss = DateUtil.dateChangeStrYmdhmss(time);
                 if (!javaType.toLowerCase().equals("boolean")) {
                     try {
@@ -94,251 +108,66 @@ public class OpcUaLowerTask extends TimerTask {
                         BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                 MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
                                 bigDecimal;
-                        if (Blank.isEmpty(storageYmdh)) {
-                            if (dmData.compareTo(bigModeValue) == -1) {
-                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
+                        if (dmData.compareTo(bigModeValue) == -1) {
+                            RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(dmData),
+                                    currentYmdhmss, currentYmdh, new Date());
+                            opcAsyncTask.addTempRawData(rawData);
 
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                dataValueList.add(dmData);
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                dataValueTimeList.add(currentYmdhmss);
-                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                            }
                             if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
                                 BigDecimal bigEventValue = new BigDecimal(eventValue);
                                 if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
                                     if (dmData.compareTo(bigEventValue) == 1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
                                     if (dmData.compareTo(bigEventValue) == -1) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        eventDataValueList.add(dmData);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        eventDataValueTimeList.add(currentYmdhmss);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-                            }
-                        } else {
-                            if (DateUtil.strChangeDate(storageYmdh, timeFormat).getTime() == DateUtil.strChangeDate(currentYmdh, timeFormat).getTime()) {
-                                if (dmData.compareTo(bigModeValue) == -1) {
-                                    Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                    List<BigDecimal> dataValueList = new ArrayList<>();
-                                    if (Blank.isNotEmpty(dataValueObject)) {
-                                        dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                    }
-                                    dataValueList.add(dmData);
-                                    redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-
-                                    List<String> dataValueTimeList = new ArrayList<>();
-                                    Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                    if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                        dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                                    }
-                                    dataValueTimeList.add(currentYmdhmss);
-                                    redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
-                                }
-
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                            List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                            Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueObject)) {
-                                                eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                            }
-                                            eventDataValueList.add(dmData);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-
-                                            List<String> eventDataValueTimeList = new ArrayList<>();
-                                            Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                            if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                                eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                            }
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                            redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                        }
+                                        eventFlage = true;
+                                        opcAsyncTask.addEventRawData(rawData);
+                                    } else {
+                                        eventFlage = false;
                                     }
                                 }
                             } else {
-                                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                                Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                                List<BigDecimal> dataValueList = new ArrayList<>();
-                                if (Blank.isNotEmpty(dataValueObject)) {
-                                    dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                                }
-
-                                List<String> dataValueTimeList = new ArrayList<>();
-                                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
+                                if (eventFlage) {
+                                    opcAsyncTask.addEventRawData(rawData);
                                 }
-
-                                //存数据
-                                RawData rawData = new RawData(dataSourceId,
-                                        itemId,
-                                        javaType,
-                                        JSON.toJSONString(dataValueList),
-                                        String.valueOf(dataValueTimeList),
-                                        String.valueOf(valueBelongTime),
-                                        new Date());
-                                opcAsyncTask.addRawData(id, rawData);
-
-                                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                                    BigDecimal bigEventValue = new BigDecimal(eventValue);
-                                    if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == 1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                        List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                        Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueObject)) {
-                                            eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                        }
-
-                                        List<String> eventDataValueTimeList = new ArrayList<>();
-                                        Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                        if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                            eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                        }
-                                        opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                                        eventDataValueList = new ArrayList<>();
-                                        eventDataValueTimeList = new ArrayList<>();
-                                        if (dmData.compareTo(bigEventValue) == -1) {
-                                            eventDataValueList.add(dmData);
-                                            eventDataValueTimeList.add(currentYmdhmss);
-                                        }
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE + id + itemId, eventDataValueList, ConstantStr.TWO_HOUR);
-                                        redisUtil.set(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId, eventDataValueTimeList, ConstantStr.TWO_HOUR);
-                                    }
-                                }
-
-                                dataValueList = new ArrayList<>();
-                                dataValueTimeList = new ArrayList<>();
-                                if (dmData.compareTo(bigModeValue) == -1) {
-                                    dataValueList.add(dmData);
-                                    dataValueTimeList.add(currentYmdhmss);
-                                }
-                                redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
-                                redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
-                                redisUtil.set(ConstantStr.DATA_VALUE_TIME + id + itemId, dataValueTimeList, ConstantStr.TWO_HOUR);
                             }
                         }
                     } catch (Exception e) {
-
+//                        RawData rawData = new RawData(id, dataSourceId, itemId, javaType, JSON.toJSONString(value.toString()),
+//                                currentYmdhmss, currentYmdh, new Date());
+//                        opcAsyncTask.addTempRawData(rawData);
+//
+//                        if (Blank.isEmpty(eventMode, eventValue, tableReportId)) {
+//                            if (eventFlage) {
+//                                opcAsyncTask.addEventRawData(rawData);
+//                            }
+//                        }
                     }
                 }
             } catch (Exception e) {
-                //存入已有的数据
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
+                //执行组装数据库的数据,以及生成驱动报表
+                opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+                if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
+                    opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
                 }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (!javaType.toLowerCase().equals("boolean")) {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            BigDecimal bigEventValue = new BigDecimal(eventValue);
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
 
                 messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
                         itemGroup.getGroupName() + "-" + itemId + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
                         e.getMessage(),
                         ConstantStr.NO_READ));
 
-                redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
+                }
+
+                redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                itemGroupDao.runItemGroupById(id, ConstantStr.STOP_IT);
+                timer.cancel();
             }
         }
         Boolean flage = (Boolean) redisUtil.get(ConstantStr.ITEM_GROUP + id);
@@ -346,65 +175,16 @@ public class OpcUaLowerTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (Item item : itemList) {
-                String itemId = item.getItemReadName();
-                Integer eventMode = item.getEventMode();
-                Integer eventValue = item.getEventValue();
-                Integer tableReportId = item.getTableReportId();
-                String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
-
-                List<String> dataValueTimeList = new ArrayList<>();
-                Object dataValueTimeObject = redisUtil.get(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                if (Blank.isNotEmpty(dataValueTimeObject)) {
-                    dataValueTimeList = JavaTypeUtil.objChangeListStr(dataValueTimeObject);
-                }
-
-                String javaType = String.valueOf(redisUtil.get(ConstantStr.JAVA_TYPE + id + itemId));
-                if (!javaType.toLowerCase().equals("boolean")) {
-                    try {
-                        List<BigDecimal> dataValueList = new ArrayList<>();
-                        Object dataValueObject = redisUtil.get(ConstantStr.DATA_VALUE + id + itemId);
-                        if (Blank.isNotEmpty(dataValueObject)) {
-                            dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
-                        }
-                        //存数据
-                        RawData rawData = new RawData(dataSourceId,
-                                itemId,
-                                javaType,
-                                JSON.toJSONString(dataValueList),
-                                String.valueOf(dataValueTimeList),
-                                String.valueOf(valueBelongTime),
-                                new Date());
-                        opcAsyncTask.addRawData(id, rawData);
-
-                        if (Blank.isNotEmpty(eventMode) && Blank.isNotEmpty(eventValue) && Blank.isNotEmpty(tableReportId)) {
-                            BigDecimal bigEventValue = new BigDecimal(eventValue);
-                            if (eventMode.equals(ConstantStr.EVENT_MODEL_EXCEED)||
-                                    eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
-                                List<BigDecimal> eventDataValueList = new ArrayList<>();
-                                Object eventDataValueObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueObject)) {
-                                    eventDataValueList = JavaTypeUtil.objChangeListBig(eventDataValueObject);
-                                }
-
-                                List<String> eventDataValueTimeList = new ArrayList<>();
-                                Object eventDataValueTimeObject = redisUtil.get(ConstantStr.EVENT_DATA_VALUE_TIME + id + itemId);
-                                if (Blank.isNotEmpty(eventDataValueTimeObject)) {
-                                    eventDataValueTimeList = JavaTypeUtil.objChangeListStr(eventDataValueTimeObject);
-                                }
-                                opcAsyncTask.addEventTable(tableReportId, eventDataValueList, eventDataValueTimeList);
-                            }
-                        }
-                    } catch (Exception e1) {
-
-                    }
-                }
-                redisUtil.del(ConstantStr.DATA_VALUE + id + itemId);
-                redisUtil.del(ConstantStr.DATA_VALUE_TIME + id + itemId);
-                redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id + itemId);
-
-                redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
-            }
+            //执行组装数据库的数据,以及生成驱动报表
+            String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));
+            opcAsyncTask.packageRawDataList(itemList, dataSourceId, sqlCurrentYmdh);
+            opcAsyncTask.eventTable(dataSourceId, itemList, sqlCurrentYmdh);
+            redisUtil.del(ConstantStr.VALUE_BELONG_TIME + id);
+
+            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                    "请刷新检查组的运行状态",
+                    ConstantStr.NO_READ));
 
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();

+ 3 - 12
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaTask.java

@@ -80,7 +80,7 @@ public class OpcUaTask extends TimerTask {
                                 dataSource,
                                 timer,
                                 timeFormat),
-                        0, itemGroup.getModeValue() * 1000);
+                        0, (int)(itemGroup.getModeValue() * 1000));
             } else if (itemGroup.getReadMode() == ConstantStr.ON_CHANGE) {
                 timer.schedule(new OpcUaChangeTask(redisUtil,
                                 opcAsyncTask,
@@ -122,20 +122,11 @@ public class OpcUaTask extends TimerTask {
                         0, 1000);
             }
         } catch (Exception e) {
-            String message = e.getMessage();
-            String messageContent = "";
-            if (message.contains("0x00000005")) {
-                messageContent = "账号或密码错误";
-            } else if (message.contains("0x8001FFFF")) {
-                messageContent = "ip连接不可用";
-            } else {
-                messageContent = e.getMessage();
-            }
+            String message = OpcUaUtil.genException(e.getMessage());
             messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
                     itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行失败",
-                    messageContent,
+                    message,
                     ConstantStr.NO_READ));
-            redisUtil.convertAndSend(ConstantStr.ITEM_GROUP, Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "组" + itemGroup.getGroupName() + "运行异常,错误信息为:" + messageContent));
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();
             }

+ 29 - 46
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/util/OpcUaUtil.java

@@ -36,6 +36,7 @@ import java.nio.file.Paths;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 @Slf4j
 public class OpcUaUtil {
@@ -115,24 +116,7 @@ public class OpcUaUtil {
             log.info("连接耗费时间为:" + (finish - start) + "毫秒");
             return Result.ok("测试连接成功");
         } catch (Exception e) {
-            e.printStackTrace();
-            String message = e.getMessage();
-            if (message.contains("Bad_ConnectionRejected")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "ip连接不可用");
-            }
-            if (message.contains("Bad_UserAccessDenied")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "用户无权执行请求的操作");
-            }
-            if (message.contains("cannot create signer")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "证书创建失败,无法创建签名者");
-            }
-            if (message.contains("Bad_Timeout")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "连接超时");
-            }
-            if (message.contains("UnknownHostException")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "未知主机异常");
-            }
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();
@@ -150,20 +134,7 @@ public class OpcUaUtil {
             opcUaClient.connect().get();
             return Result.ok(generOpcUaTree(opcUaClient, null));
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("Bad_ConnectionRejected")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "ip连接不可用");
-            }
-            if (message.contains("Bad_UserAccessDenied")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "用户无权执行请求的操作");
-            }
-            if (message.contains("cannot create signer")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "证书创建失败,无法创建签名者");
-            }
-            if (message.contains("Bad_Timeout")) {
-                return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "连接超时");
-            }
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(opcUaClient)) {
                 opcUaClient.disconnect();
@@ -262,9 +233,11 @@ public class OpcUaUtil {
             client.connect().get();
             Map<String, Object> map = new HashMap<>();
             Map<String, String> mapName = new HashMap<>();
+            Map<String, Integer> mapEventMode = new HashMap<>();
             for (Item item : itemList) {
                 map.put(item.getItemReadName(), item.getDescribe());
                 mapName.put(item.getItemReadName(), item.getItemName());
+                mapEventMode.put(item.getItemReadName(), item.getEventMode());
             }
             List<NodeId> nodeIdList = OpcUaUtil.genNodeId(itemList);
             List<JSONObject> jsonObjectList = new ArrayList<>();
@@ -283,6 +256,7 @@ public class OpcUaUtil {
                         ExpandedNodeId expandedNodeId = value.getDataType().get();
                         String javaType = OpcUaUtil.getValType(dataValue);
                         jsonObject.put("dataType", javaType);
+                        jsonObject.put("eventMode", mapEventMode.get(itemName));
                         jsonObject.put("dataOrgValue", value.getValue());
                         if (javaType.toLowerCase().equals("boolean")) {
                             jsonObject.put("dataValue", value.getValue());
@@ -305,27 +279,18 @@ public class OpcUaUtil {
                 jsonObject.put("createTime", date);
                 jsonObjectList.add(jsonObject);
             }
-            jsonObjectList.sort(new Comparator<JSONObject>() {
-                @Override
-                public int compare(JSONObject o1, JSONObject o2) {
-                    return o1.getString("itemName").compareTo(o2.getString("itemName"));
-                }
-            });
+            jsonObjectList.stream()
+                    .sorted(Comparator.comparing((JSONObject jsonObject) -> jsonObject.getInteger("eventMode")).reversed()
+                            .thenComparing(jsonObject -> jsonObject.getString("itemName")
+                            )).collect(Collectors.toList());
             return jsonObjectList;
         } catch (Exception e) {
-            String message = e.getMessage();
-            if (message.contains("Bad_ConnectionRejected")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "ip连接不可用");
-            }
-            if (message.contains("Bad_UserAccessDenied")) {
-                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "用户无权执行请求的操作");
-            }
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
         } finally {
             if (Blank.isNotEmpty(client)) {
                 client.disconnect();
             }
         }
-        return null;
     }
 
     /**
@@ -364,4 +329,22 @@ public class OpcUaUtil {
                 return "";
         }
     }
+
+    public static String genException(String message) {
+        if (Blank.isEmpty(message)) {
+            return "";
+        }
+        if (message.contains("Bad_ConnectionRejected")) {
+            return "ip连接不可用";
+        } else if (message.contains("Bad_UserAccessDenied")) {
+            return "用户无权执行请求的操作";
+        } else if (message.contains("cannot create signer")) {
+            return "证书创建失败,无法创建签名者";
+        } else if (message.contains("Bad_Timeout")) {
+            return "连接超时";
+        } else if (message.contains("UnknownHostException")) {
+            return "未知主机异常";
+        }
+        return message;
+    }
 }

+ 4 - 1
chaunyi_opc/opc_ua/src/main/resources/application.yml

@@ -1,6 +1,9 @@
 spring:
   profiles:
-    active: dev
+    active: @spring.profiles.active@
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
+    time-zone: GMT+8
 
 mybatis:
   mapper-locations: classpath:mapper/*.xml

+ 2 - 2
chaunyi_opc/opc_ua/src/main/resources/mapper/ItemGroupDao.xml

@@ -26,7 +26,7 @@
         <include refid="item"/>
         from t_item
         where item_group_id = #{itemGroupId}
-        order by item_name
+        order by event_mode DESC,item_name
     </select>
 
     <update id="runItemGroupById">
@@ -35,4 +35,4 @@
         where id = #{id}
     </update>
 
-</mapper>
+</mapper>

+ 70 - 2
chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml

@@ -10,7 +10,8 @@
         insert into t_raw_data${remainder}
         (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
          create_time)
-        VALUES (#{itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType}, #{rawData.dataValue},
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
                 #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
     </insert>
 
@@ -26,4 +27,71 @@
         </foreach>
     </insert>
 
-</mapper>
+    <insert id="addTempRawData">
+        insert into t_raw_data
+        (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
+         create_time)
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
+                #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
+    </insert>
+
+    <insert id="addEventRawData">
+        insert into t_event_raw_data
+        (item_group_id, data_source_id, item_name, data_type, data_value, data_value_time, value_belong_time,
+         create_time)
+        VALUES (#{rawData.itemGroupId}, #{rawData.dataSourceId}, #{rawData.itemName}, #{rawData.dataType},
+                #{rawData.dataValue},
+                #{rawData.dataValueTime}, #{rawData.valueBelongTime}, #{rawData.createTime})
+    </insert>
+
+    <delete id="delRawDataList">
+        delete
+        from t_raw_data
+        where value_belong_time = #{valueBelongTime}
+        and
+        <foreach collection="rawDataList" item="rawData" index="index" separator=",">
+            (#{rawData.id})
+        </foreach>
+    </delete>
+
+    <delete id="delEventRawDataList">
+        delete
+        from t_evnet_raw_data
+        where item_group_id = #{item.itemGroupId}
+          and data_souerce_id = #{dataSourceId}
+          and item_name = #{item.itemReadName}
+          and value_belong_time = #{valueBelongTime}
+    </delete>
+
+    <select id="getRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select
+        <include refid="rawData"/>
+        from t_raw_data${remainder}
+        where item_group_id = #{item.itemGroupId}
+        and data_souerce_id = #{dataSourceId}
+        and item_name = #{item.itemReadName}
+        and value_belong_time = #{valueBelongTime}
+    </select>
+
+    <select id="getTempRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select data_type, data_value
+        from t_raw_data
+        where item_group_id = #{item.itemGroupId}
+          and data_souerce_id = #{dataSourceId}
+          and item_name = #{item.itemReadName}
+          and value_belong_time = #{valueBelongTime}
+        order by data_value_time desc
+    </select>
+
+    <select id="getEventRawDataList" resultType="com.example.opc_common.entity.RawData">
+        select
+        <include refid="rawData"/>
+        from t_evnet_raw_data
+        where item_group_id = #{item.itemGroupId}
+        and data_souerce_id = #{dataSourceId}
+        and item_name = #{item.itemReadName}
+        and value_belong_time = #{valueBelongTime}
+    </select>
+
+</mapper>

+ 13 - 0
chaunyi_opc/opc_ua/src/main/resources/mapper/ReportTableDao.xml

@@ -30,6 +30,19 @@
             (#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{reportValueFormat}, #{isAutoReport}, #{version}, now())
     </insert>
 
+    <insert id="addTableAutoLog">
+        insert into t_table_auto_log (auto_table_id, auto_ch_table_id)
+                    value (#{autoTableId},#{autoChTableId})
+    </insert>
+
+    <insert id="addTableUserGroup">
+        insert into t_table_user_group (table_id, user_group_id)
+        values
+        <foreach collection="userGroupList" item="userGroup" index="index" separator=",">
+            (#{reportTableId}, #{userGroup.id})
+        </foreach>
+    </insert>
+
     <update id="updateReportTable">
         update t_report_table
         set report_table_name=#{reportTableName},

+ 8 - 0
chuanyi-admin/src/api/dashboard.js

@@ -16,6 +16,14 @@ export function getCustomerUserNum() {
   })
 }
 
+/** 查询客户端在线用户数量 */
+export function getOnlineUser(loginType) {
+  return request({
+    url: '/user/getOnlineUser?loginType=' + loginType,
+    method: 'get'
+  })
+}
+
 /** 查询角色数量 */
 export function getRoleNum() {
   return request({

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chuanyi-admin/src/icons/svg/user-manger.svg


+ 1 - 0
chuanyi-admin/src/icons/svg/user-online.svg

@@ -0,0 +1 @@
+<svg t="1680592211773" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="21929" width="64" height="64"><path d="M697.856 322.56A185.856 185.856 0 1 0 386.048 460.8a279.552 279.552 0 0 0-191.488 256 35.328 35.328 0 1 0 71.168 0c0-110.592 102.4-200.192 235.52-204.8h25.6a229.888 229.888 0 0 1 124.416 34.816l8.192 5.632a198.656 198.656 0 0 1 99.328 165.376 35.328 35.328 0 0 0 71.168 0 269.312 269.312 0 0 0-134.144-231.424h-2.56a227.328 227.328 0 0 0-51.2-27.648 184.832 184.832 0 0 0 55.808-136.192zM512 226.304A96.256 96.256 0 1 1 415.744 322.56 96.256 96.256 0 0 1 512 226.304z" fill="#438CFF" p-id="21930"></path><path d="M884.224 16.384H824.32a38.4 38.4 0 0 0 0 76.8h59.904a64 64 0 0 1 64 63.488v581.12a64 64 0 0 1-64 63.488H139.776a64 64 0 0 1-64-63.488V156.672a64 64 0 0 1 64-63.488h488.448a38.4 38.4 0 0 0 0-76.8H139.776A140.8 140.8 0 0 0 0 156.672v581.12a140.8 140.8 0 0 0 140.8 140.288h332.8v51.2H303.616a38.4 38.4 0 0 0 0 76.8h417.792a38.4 38.4 0 1 0 0-76.8h-171.008v-51.2h333.824A140.8 140.8 0 0 0 1024 737.792V156.672A140.8 140.8 0 0 0 884.224 16.384z" fill="#438CFF" p-id="21931"></path></svg>

+ 1 - 0
chuanyi-admin/src/icons/svg/user-role.svg

@@ -0,0 +1 @@
+<svg t="1680592022584" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="14645" width="64" height="64"><path d="M492.5 384H318.1c-10.8 0-19.5-8.7-19.5-19.5v-3.7c0-10.8 8.7-19.5 19.5-19.5h174.4c10.8 0 19.5 8.7 19.5 19.5v3.7c0 10.8-8.7 19.5-19.5 19.5zM492.5 512H318.1c-10.8 0-19.5-8.7-19.5-19.5v-3.7c0-10.8 8.7-19.5 19.5-19.5h174.4c10.8 0 19.5 8.7 19.5 19.5v3.7c0 10.8-8.7 19.5-19.5 19.5zM492.5 640H318.1c-10.8 0-19.5-8.7-19.5-19.5v-3.7c0-10.8 8.7-19.5 19.5-19.5h174.4c10.8 0 19.5 8.7 19.5 19.5v3.7c0 10.8-8.7 19.5-19.5 19.5z" fill="#A9D8FF" p-id="14646"></path><path d="M704 429m-83 0a83 83 0 1 0 166 0 83 83 0 1 0-166 0Z" fill="#298DF7" p-id="14647"></path><path d="M806.1 677.9H601.9c-26 0-47.2-21.2-47.2-47.2 0-47 38.5-85.5 85.5-85.5h127.6c47 0 85.5 38.5 85.5 85.5 0 26-21.2 47.2-47.2 47.2z" fill="#298DF7" p-id="14648"></path><path d="M704 256c11.9 0 21.3-9.4 21.3-21.3v-21.3c0-46.9-38.4-85.3-85.3-85.3H256c-46.9 0-85.3 38.4-85.3 85.3v597.3c0 46.9 38.4 85.3 85.3 85.3h384c46.9 0 85.3-38.4 85.3-85.3v-21.3c0-11.9-9.4-21.3-21.3-21.3s-21.3 9.4-21.3 21.3v21.3c0 23.5-19.2 42.7-42.7 42.7H256c-23.5 0-42.7-19.2-42.7-42.7V213.3c0-23.5 19.2-42.7 42.7-42.7h384c23.5 0 42.7 19.2 42.7 42.7v21.3c0 12 9.4 21.4 21.3 21.4z" fill="#3C99FE" p-id="14649"></path><path d="M704 213.3c-11.9 0-21.3 9.4-21.3 21.3s9.4 21.3 21.3 21.3 21.3-9.4 21.3-21.3-9.4-21.3-21.3-21.3z" fill="#3C99FE" p-id="14650"></path></svg>

+ 1 - 0
chuanyi-admin/src/icons/svg/user-t.svg

@@ -0,0 +1 @@
+<svg t="1680591971888" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="12617" width="64" height="64"><path d="M481.1 190c30.3 0 58.8 11.8 80.3 33.3 21.4 21.4 33.3 50 33.3 80.3v15c0 30.3-11.8 58.8-33.3 80.3-21.4 21.4-50 33.3-80.3 33.3-30.3 0-58.8-11.8-80.3-33.3-21.4-21.4-33.3-50-33.3-80.3v-15c0-30.3 11.8-58.8 33.3-80.3 21.5-21.5 50-33.3 80.3-33.3m0-60c-95.8 0-173.5 77.7-173.5 173.5v15c0 95.8 77.7 173.5 173.5 173.5s173.5-77.7 173.5-173.5v-15C654.7 207.6 577 130 481.1 130z" fill="#3FA9F5" p-id="12618"></path><path d="M515.2 516.3c48.3 0 93.8 18.8 127.9 53 34.2 34.2 53 79.6 53 127.9 0 40.1-32.6 72.7-72.7 72.7H338.8c-40.1 0-72.7-32.6-72.7-72.7 0-48.3 18.8-93.8 53-127.9 34.2-34.2 79.6-53 127.9-53h68.2m0-60h-68.1c-133.1 0-240.9 107.9-240.9 240.9 0 73.3 59.4 132.7 132.7 132.7h284.7c73.3 0 132.7-59.4 132.7-132.7-0.2-133-108-240.9-241.1-240.9z" fill="#3FA9F5" p-id="12619"></path></svg>

+ 1 - 0
chuanyi-admin/src/icons/svg/user-table.svg

@@ -0,0 +1 @@
+<svg t="1680592180287" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="20709" width="64" height="64"><path d="M939.008 913.408H105.472V90.112c0-11.264-9.216-20.48-20.48-20.48s-20.48 9.216-20.48 20.48v843.776c0 11.264 9.216 20.48 20.48 20.48h854.016c11.264 0 20.48-9.216 20.48-20.48s-9.216-20.48-20.48-20.48z" fill="#1296DB" p-id="20710"></path><path d="M203.776 863.232h71.68c22.528 0 40.96-18.432 40.96-40.96v-230.4c0-22.528-18.432-40.96-40.96-40.96h-71.68c-22.528 0-40.96 18.432-40.96 40.96v230.4c0 22.528 18.432 40.96 40.96 40.96z m71.68-40.96v20.48-20.48z m-71.68-230.4h71.68v230.4h-71.68v-230.4z m199.68 271.36h71.68c22.528 0 40.96-18.432 40.96-40.96V355.328c0-22.528-18.432-40.96-40.96-40.96h-71.68c-22.528 0-40.96 18.432-40.96 40.96v466.944c0 22.528 18.432 40.96 40.96 40.96z m71.68-40.96v20.48-20.48z m-71.68-466.944h71.68v466.944h-71.68V355.328zM604.16 863.232h71.68c22.528 0 40.96-18.432 40.96-40.96v-384c0-22.528-18.432-40.96-40.96-40.96h-71.68c-22.528 0-40.96 18.432-40.96 40.96v384c0 22.528 18.432 40.96 40.96 40.96z m0-424.96h71.68v384h-71.68v-384z m199.68 424.96h71.68c22.528 0 40.96-18.432 40.96-40.96V133.12c0-22.528-18.432-40.96-40.96-40.96h-71.68c-22.528 0-40.96 18.432-40.96 40.96v689.152c0 22.528 18.432 40.96 40.96 40.96z m0-730.112h71.68v689.152h-71.68V133.12z" fill="#1296DB" p-id="20711"></path></svg>

+ 187 - 54
chuanyi-admin/src/views/dashboard/index.vue

@@ -1,86 +1,132 @@
 <template>
   <div class="sy-content">
-    <div class="statistics">
-      <div v-for="(item, index) in statData" :key="index" class="stat-item">
-        <span class="stat-top">{{ item.title }}</span>
-        <span class="stat-bottom">{{ item.num }}</span>
-      </div>
-    </div>
+<!--    <div class="statistics">-->
+<!--      <div v-for="(item, index) in statData" :key="index" class="stat-item">-->
+<!--        <span class="stat-top">{{ item.title }}</span>-->
+<!--        <span class="stat-bottom">{{ item.num }}</span>-->
+<!--      </div>-->
+<!--    </div>-->
+    <el-row :gutter="40" class="panel-group">
+      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
+        <div class="card-panel">
+          <div class="card-panel-icon-wrapper icon-people">
+            <svg-icon icon-class="user-manger" class-name="card-panel-icon" />
+          </div>
+          <div class="card-panel-description">
+            <div class="card-panel-text">管理端用户数量</div>
+            <count-to :start-val="startVal" :end-val="statistics.managerUserNum" :duration="countDuration" class="card-panel-num" />
+          </div>
+        </div>
+      </el-col>
+      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
+        <div class="card-panel">
+          <div class="card-panel-icon-wrapper icon-message">
+            <svg-icon icon-class="user-t" class-name="card-panel-icon" />
+          </div>
+          <div class="card-panel-description">
+            <div class="card-panel-text">客户端用户数量</div>
+            <count-to :start-val="startVal" :end-val="statistics.clientUserNum" :duration="countDuration" class="card-panel-num" />
+          </div>
+        </div>
+      </el-col>
+      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
+        <div class="card-panel">
+          <div class="card-panel-icon-wrapper icon-money">
+            <svg-icon icon-class="user-role" class-name="card-panel-icon" />
+          </div>
+          <div class="card-panel-description">
+            <div class="card-panel-text">角色数量</div>
+            <count-to :start-val="startVal" :end-val="statistics.roleNum" :duration="countDuration" class="card-panel-num" />
+          </div>
+        </div>
+      </el-col>
+      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
+        <div class="card-panel">
+          <div class="card-panel-icon-wrapper icon-shopping">
+            <svg-icon icon-class="user-table" class-name="card-panel-icon" />
+          </div>
+          <div class="card-panel-description">
+            <div class="card-panel-text">报表数量</div>
+            <count-to :start-val="startVal" :end-val="statistics.reportNum" :duration="countDuration" class="card-panel-num" />
+          </div>
+        </div>
+      </el-col>
+      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
+        <div class="card-panel">
+          <div class="card-panel-icon-wrapper icon-money">
+            <svg-icon icon-class="user-online" class-name="card-panel-icon" />
+          </div>
+          <div class="card-panel-description">
+            <div class="card-panel-text">客户端在线用户数</div>
+            <count-to :start-val="startVal" :end-val="statistics.onlineClientUserNum" :duration="countDuration" class="card-panel-num" />
+          </div>
+        </div>
+      </el-col>
+    </el-row>
   </div>
 </template>
 
 <script>
 import { mapGetters } from 'vuex'
+import CountTo from 'vue-count-to'
 import {
   getManagerUserNum,
   getCustomerUserNum,
   getRoleNum,
-  getReportFormrNum
+  getReportFormrNum, getOnlineUser
 } from '@/api/dashboard'
 
 export default {
   name: 'Dashboard',
+  components: {
+    CountTo
+  },
   data() {
     return {
-      statData: []
+      statData: [],
+      countDuration: 1000,
+      startVal: 0,
+      statistics: {
+        roleNum: 0,
+        managerUserNum: 0,
+        clientUserNum: 0,
+        onlineClientUserNum: 0,
+        reportNum: 0
+      }
     }
   },
   computed: {
     ...mapGetters(['roles'])
   },
   created() {
-    this.statistics()
+    this.statisticsNum()
   },
   methods: {
-    statistics() {
-      const p1 = new Promise((resolve, reject) => {
-        getManagerUserNum().then((res) => {
-          if (res.code === 200) {
-            resolve(res.data)
-          }
-        })
+    statisticsNum() {
+      getManagerUserNum().then((res) => {
+        if (res.code === 200) {
+          this.statistics.managerUserNum = res.data
+        }
       })
-      const p2 = new Promise((resolve, reject) => {
-        getCustomerUserNum().then((res) => {
-          if (res.code === 200) {
-            resolve(res.data)
-          }
-        })
+      getCustomerUserNum().then((res) => {
+        if (res.code === 200) {
+          this.statistics.clientUserNum = res.data
+        }
       })
-      const p3 = new Promise((resolve, reject) => {
-        getRoleNum().then((res) => {
-          if (res.code === 200) {
-            resolve(res.data)
-          }
-        })
+      getRoleNum().then((res) => {
+        if (res.code === 200) {
+          this.statistics.roleNum = res.data
+        }
       })
-      const p4 = new Promise((resolve, reject) => {
-        getReportFormrNum().then((res) => {
-          if (res.code === 200) {
-            resolve(res.data)
-          }
-        })
+      getReportFormrNum().then((res) => {
+        if (res.code === 200) {
+          this.statistics.reportNum = res.data
+        }
       })
-      Promise.all([p1, p2, p3, p4]).then((res) => {
-        const [a, b, c, d] = res
-        this.statData = [
-          {
-            title: '管理端用户数量',
-            num: a
-          },
-          {
-            title: '客户端用户数量',
-            num: b
-          },
-          {
-            title: '角色数量',
-            num: c
-          },
-          {
-            title: '报表数量',
-            num: d
-          }
-        ]
+      getOnlineUser('front').then((res) => {
+        if (res.code === 200) {
+          this.statistics.onlineClientUserNum = res.data
+        }
       })
     }
   }
@@ -93,6 +139,7 @@ export default {
   justify-content: space-between;
   margin: 30px auto;
   width: 50%;
+  flex-wrap: wrap;
   .stat-item {
     display: flex;
     flex-direction: column;
@@ -107,4 +154,90 @@ export default {
     }
   }
 }
+.panel-group {
+  margin-top: 18px;
+
+  .card-panel-col {
+    margin-bottom: 32px;
+  }
+
+  .card-panel {
+    height: 108px;
+    //cursor: pointer;
+    font-size: 12px;
+    position: relative;
+    overflow: hidden;
+    color: #666;
+    background: #fff;
+    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
+    border-color: rgba(0, 0, 0, .05);
+
+    .icon-people {
+      color: #40c9c6;
+    }
+
+    .icon-message {
+      color: #36a3f7;
+    }
+
+    .icon-money {
+      color: #f4516c;
+    }
+
+    .icon-shopping {
+      color: #34bfa3
+    }
+
+    .card-panel-icon-wrapper {
+      float: left;
+      margin: 14px 0 0 14px;
+      padding: 16px;
+      transition: all 0.38s ease-out;
+      border-radius: 6px;
+    }
+
+    .card-panel-icon {
+      float: left;
+      font-size: 48px;
+    }
+
+    .card-panel-description {
+      float: right;
+      font-weight: bold;
+      margin: 26px;
+      margin-left: 0px;
+
+      .card-panel-text {
+        line-height: 18px;
+        color: rgba(0, 0, 0, 0.45);
+        font-size: 16px;
+        margin-bottom: 12px;
+      }
+
+      .card-panel-num {
+        font-size: 20px;
+        float: right;
+      }
+    }
+  }
+}
+
+@media (max-width:550px) {
+  .card-panel-description {
+    display: none;
+  }
+
+  .card-panel-icon-wrapper {
+    float: none !important;
+    width: 100%;
+    height: 100%;
+    margin: 0 !important;
+
+    .svg-icon {
+      display: block;
+      margin: 14px auto !important;
+      float: none !important;
+    }
+  }
+}
 </style>

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chuanyi_client2/public/luckysheet/luckysheet.umd.js


Разлика између датотеке није приказан због своје велике величине
+ 21 - 0
chuanyi_client2/public/plugins/echarts.min.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chuanyi_client2/public/plugins/element.css


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
chuanyi_client2/public/plugins/element.js


Неке датотеке нису приказане због велике количине промена