浏览代码

初步完成事件驱动报表的任务

zhoupeng 2 年之前
父节点
当前提交
3611cf710e

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

@@ -40,12 +40,19 @@ public class Item implements Serializable {
     /**
      * 事件驱动产生的条件
      */
-    private String eventCondition;
+    private Integer eventMode;
+    /**
+     * 事件驱动设定的阀值
+     */
+    private Integer eventValue;
     /**
      * 事件驱动生成报表需要的报表模板
      */
     private Integer tableReportId;
 
+    /**
+     * 四则混合运算表达式,返回给前端的
+     */
     private String operationRule;
 
     /**

+ 4 - 0
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/util/ConstantStr.java

@@ -81,6 +81,10 @@ public class ConstantStr {
     public static final Integer EXCEED_SET_VALUE = 2;
     public static final Integer LOWER_SET_VALUE = 3;
 
+    //事件驱动条件,0大于,1小于
+    public static final Integer EVENT_MODEL_EXCEED=0;
+    public static final Integer EVENT_MODEL_LOWER=1;
+
     //取值条件
     public static final Integer AVERAGE_VALUE = 0;
     public static final Integer MAX_VALUE = 1;

+ 1 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -189,8 +189,6 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 }
                 //读取数据并保存
                 Timer timer = new Timer();
-                //获取读取使用的itemName
-                List<String> itemList = itemGroupDao.getItemReadNameById(id);
                 if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.KEPSERVER.getValue()) ||
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue()) ||
                         dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.WINCC.getValue()) ||
@@ -204,7 +202,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                                     itemGroup,
                                     dataSource,
                                     map,
-                                    itemList,
+                                    allItemList,
                                     timeFormat),
                             DateUtil.strYmdhmsChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()),
                             ConstantStr.PERIOD_DAY);

+ 13 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java

@@ -3,11 +3,13 @@ package com.example.opc_da.task;
 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.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_da.dao.RawDataDao;
+import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -22,6 +24,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.List;
 
@@ -41,6 +44,9 @@ public class OpcAsyncTask {
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private ReportTableDao reportTableDao;
+
     @Value("${opc_ua_server.address}")
     private String opcUaUrl;
 
@@ -143,4 +149,11 @@ public class OpcAsyncTask {
             }
         }
     }
+
+    /**
+     * 事件驱动报表异步添加数据
+     */
+    public void eventTable(Integer tableReportId, BigDecimal value,String currentDate) {
+        ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
+    }
 }

+ 162 - 28
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaTask.java

@@ -33,7 +33,7 @@ public class OpcDaTask extends TimerTask {
 
     private final Map<String, DataModel> map;
 
-    private final List<String> itemIdList;
+    private final List<com.example.opc_common.entity.Item> itemList;
 
     private final String timeFormat;
 
@@ -45,7 +45,7 @@ public class OpcDaTask extends TimerTask {
                      ItemGroup itemGroup,
                      DataSource dataSource,
                      Map<String, DataModel> map,
-                     List<String> itemIdList,String timeFormat) {
+                     List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
         this.redisUtil = redisUtil;
         this.opcAsyncTask = opcAsyncTask;
         this.itemGroupDao = itemGroupDao;
@@ -54,7 +54,7 @@ public class OpcDaTask extends TimerTask {
         this.itemGroup = itemGroup;
         this.dataSource = dataSource;
         this.map = map;
-        this.itemIdList = itemIdList;
+        this.itemList = itemList;
         this.timeFormat = timeFormat;
     }
 
@@ -68,9 +68,14 @@ public class OpcDaTask extends TimerTask {
                 server.connect();
                 SyncAccess access = new SyncAccess(server, itemGroup.getModeValue() * 1000);
 //                AccessBase access = new Async20Access(server, itemGroup.getModeValue() ,true);
-                for (String itemId : itemIdList) {
+                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 {
@@ -169,9 +174,22 @@ public class OpcDaTask extends TimerTask {
                                         try {
                                             List<BigDecimal> dataValueList = new ArrayList<>();
                                             BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                            dataValueList.add(Blank.isNotEmpty(dm) ?
+                                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                                     MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                    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) {
+                                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                    }
+                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                    if (dmData.compareTo(bigEventValue) == -1) {
+                                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                    }
+                                                }
+                                            }
                                             redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                         } catch (Exception e) {
                                             List<String> dataValueList = new ArrayList<>();
@@ -193,7 +211,22 @@ public class OpcDaTask extends TimerTask {
                                                     dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
                                                 }
                                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                                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) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    }
+                                                }
                                                 redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                             } catch (Exception e) {
                                                 List<String> dataValueList = new ArrayList<>();
@@ -239,9 +272,22 @@ public class OpcDaTask extends TimerTask {
 
                                                 dataValueList = new ArrayList<>();
                                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                dataValueList.add(Blank.isNotEmpty(dm) ?
+                                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                                         MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                                        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) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    }
+                                                }
                                                 redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                             } catch (Exception e) {
                                                 List<String> dataValueList = new ArrayList<>();
@@ -337,8 +383,8 @@ public class OpcDaTask extends TimerTask {
                                 if (Blank.isNotEmpty(server)) {
                                     server.dispose();
                                 }
-                                for (String itemId : itemIdList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                                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);
@@ -355,7 +401,8 @@ public class OpcDaTask extends TimerTask {
                     }
                     if (!flage) {
                         //存已经存入redis中的数据
-                        for (String itemId : itemIdList) {
+                        for (com.example.opc_common.entity.Item item : itemList) {
+                            String itemId = item.getItemReadName();
                             String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                             List<String> dataValueTimeList = new ArrayList<>();
@@ -434,10 +481,15 @@ public class OpcDaTask extends TimerTask {
             } else if (itemGroup.getReadMode() == ConstantStr.ON_CHANGE) {
                 server.connect();
                 SyncAccess access = new SyncAccess(server, 1000);
-                for (String itemId : itemIdList) {
+                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 {
@@ -472,7 +524,22 @@ public class OpcDaTask extends TimerTask {
                                         try {
                                             List<BigDecimal> dataValueList = new ArrayList<>();
                                             BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                            dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                            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) {
+                                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                    }
+                                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                    if (dmData.compareTo(bigEventValue) == -1) {
+                                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                    }
+                                                }
+                                            }
                                             redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                         } catch (Exception e) {
                                             List<String> dataValueList = new ArrayList<>();
@@ -500,7 +567,22 @@ public class OpcDaTask extends TimerTask {
                                                         dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
                                                     }
                                                     BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                    dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                                    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) {
+                                                                opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                            }
+                                                        } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                            if (dmData.compareTo(bigEventValue) == -1) {
+                                                                opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                            }
+                                                        }
+                                                    }
                                                     redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                                 } catch (Exception e) {
                                                     List<String> dataValueList = new ArrayList<>();
@@ -568,7 +650,22 @@ public class OpcDaTask extends TimerTask {
 
                                                 dataValueList = new ArrayList<>();
                                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                                dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                                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) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                        }
+                                                    }
+                                                }
                                                 redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                                             } catch (Exception e) {
                                                 List<String> dataValueList = new ArrayList<>();
@@ -665,8 +762,8 @@ public class OpcDaTask extends TimerTask {
                                 if (Blank.isNotEmpty(server)) {
                                     server.dispose();
                                 }
-                                for (String itemId : itemIdList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                                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);
@@ -683,7 +780,8 @@ public class OpcDaTask extends TimerTask {
                     }
                     if (!flage) {
                         //存已经存入redis中的数据
-                        for (String itemId : itemIdList) {
+                        for (com.example.opc_common.entity.Item item : itemList) {
+                            String itemId = item.getItemReadName();
                             String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                             List<String> dataValueTimeList = new ArrayList<>();
@@ -761,9 +859,14 @@ public class OpcDaTask extends TimerTask {
             } else if (itemGroup.getReadMode() == ConstantStr.EXCEED_SET_VALUE) {
                 server.connect();
                 SyncAccess access = new SyncAccess(server, 1000);
-                for (String itemId : itemIdList) {
+                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 {
@@ -791,6 +894,18 @@ public class OpcDaTask extends TimerTask {
                                     try {
                                         BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
                                         BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
+                                        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) {
+                                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                }
+                                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                if (dmData.compareTo(bigEventValue) == -1) {
+                                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                }
+                                            }
+                                        }
                                         if (Blank.isEmpty(storageYmdh)) {
                                             if (dmData.compareTo(bigModeValue) == 1) {
                                                 redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
@@ -901,8 +1016,8 @@ public class OpcDaTask extends TimerTask {
                                 if (Blank.isNotEmpty(server)) {
                                     server.dispose();
                                 }
-                                for (String itemId : itemIdList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                                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);
@@ -919,7 +1034,8 @@ public class OpcDaTask extends TimerTask {
                     }
                     if (!flage) {
                         //存已经存入redis中的数据
-                        for (String itemId : itemIdList) {
+                        for (com.example.opc_common.entity.Item item : itemList) {
+                            String itemId = item.getItemReadName();
                             String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                             List<String> dataValueTimeList = new ArrayList<>();
@@ -968,10 +1084,15 @@ public class OpcDaTask extends TimerTask {
                 }
             } else if (itemGroup.getReadMode() == ConstantStr.LOWER_SET_VALUE) {
                 server.connect();
-                SyncAccess access = new SyncAccess(server, 500);
-                for (String itemId : itemIdList) {
+                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 {
@@ -999,6 +1120,18 @@ public class OpcDaTask extends TimerTask {
                                     try {
                                         BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
                                         BigDecimal dmData = Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal;
+                                        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) {
+                                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                }
+                                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                                if (dmData.compareTo(bigEventValue) == -1) {
+                                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                                }
+                                            }
+                                        }
                                         if (Blank.isEmpty(storageYmdh)) {
                                             if (dmData.compareTo(bigModeValue) == -1) {
                                                 redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
@@ -1109,8 +1242,8 @@ public class OpcDaTask extends TimerTask {
                                 if (Blank.isNotEmpty(server)) {
                                     server.dispose();
                                 }
-                                for (String itemId : itemIdList) {
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id + itemId);
+                                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);
@@ -1127,7 +1260,8 @@ public class OpcDaTask extends TimerTask {
                     }
                     if (!flage) {
                         //存已经存入redis中的数据
-                        for (String itemId : itemIdList) {
+                        for (com.example.opc_common.entity.Item item : itemList) {
+                            String itemId = item.getItemReadName();
                             String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                             List<String> dataValueTimeList = new ArrayList<>();

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

@@ -12,7 +12,7 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
-    password: 123456
+    password: root
   resources:
     static-locations: classpath:/static/,,file:${file.path},file:${file.location}
   redis:

+ 8 - 6
chaunyi_opc/opc_da/src/main/resources/mapper/ItemGroupDao.xml

@@ -10,7 +10,7 @@
 
     <sql id="item">
         id
-        , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id, event_condition, table_report_id
+        , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id, event_mode, event_value, table_report_id
     </sql>
 
     <insert id="addItemGroup" parameterType="com.example.opc_common.entity.ItemGroup" useGeneratedKeys="true"
@@ -23,11 +23,11 @@
 
     <insert id="addItem">
         insert into t_item (item_group_id, item_name,
-        item_read_name,node_index ,data_type,`describe`,data_model_id ,event_condition ,table_report_id)
+        item_read_name,node_index ,data_type,`describe`,data_model_id,event_mode,event_value,table_report_id)
         VALUES
         <foreach collection="itemList" item="item" index="index" separator=",">
             (#{itemGroupId},#{item.itemName},#{item.itemReadName},#{item.nodeIndex},#{item.dataType},
-            #{item.describe},#{item.dataModelId},#{item.eventCondition},#{item.tableReportId})
+            #{item.describe},#{item.dataModelId},#{item.eventMode},#{item.eventValue},#{item.tableReportId})
         </foreach>
     </insert>
 
@@ -40,7 +40,8 @@
             mode_value=#{modeValue},
             start_read_time=#{startReadTime},
             end_read_time=#{endReadTime},
-            value_condition=#{valueCondition}
+            event_mode=#{eventMode},
+            event_value=#{eventValue}
         where id = #{id}
     </update>
 
@@ -129,7 +130,8 @@
                ti.data_type,
                ti.`describe`,
                ti.data_model_id,
-               ti.event_condition,
+               ti.event_mode,
+               ti.event_value,
                ti.table_report_id,
                tdm.operation_rule
         FROM t_item ti
@@ -177,7 +179,7 @@
     </select>
 
     <select id="getItemDescribe" resultType="java.lang.String">
-        select IFNULL(`describe`,item_name) as item_name
+        select IFNULL(`describe`, item_name) as item_name
         from t_item
         where item_group_id = #{itemGroupId}
           AND item_name = #{itemName}

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

@@ -0,0 +1,9 @@
+package com.example.opc_ua.dao;
+
+import com.example.opc_common.entity.ReportTable;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ReportTableDao {
+    ReportTable getReportTableById(Integer id);
+}

+ 13 - 0
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcAsyncTask.java

@@ -2,9 +2,11 @@ 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.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
 import com.example.opc_ua.dao.RawDataDao;
+import com.example.opc_ua.dao.ReportTableDao;
 import com.example.opc_ua.util.OpcUaUtil;
 import com.example.opc_ua.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -14,6 +16,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.List;
 
@@ -30,6 +33,9 @@ public class OpcAsyncTask {
     @Autowired
     private RedisUtil redisUtil;
 
+    @Autowired
+    private ReportTableDao reportTableDao;
+
     /**
      * 新增一条原始数据
      *
@@ -84,4 +90,11 @@ public class OpcAsyncTask {
             }
         }
     }
+
+    /**
+     * 事件驱动报表异步添加数据
+     */
+    public void eventTable(Integer tableReportId, BigDecimal value, String currentDate) {
+        ReportTable reportTable = reportTableDao.getReportTableById(tableReportId);
+    }
 }

+ 57 - 12
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaChangeTask.java

@@ -27,7 +27,7 @@ public class OpcUaChangeTask extends TimerTask {
 
     private final OpcUaClient opcUaClient;
 
-    private final List<NodeId> nodeIdList;
+    private final List<Item> itemList;
 
     private final Map<String, DataModel> map;
 
@@ -44,7 +44,7 @@ public class OpcUaChangeTask extends TimerTask {
                            ItemGroupDao itemGroupDao,
                            MessageNoticeDao messageNoticeDao,
                            OpcUaClient opcUaClient,
-                           List<NodeId> nodeIdList,
+                           List<Item> itemList,
                            Map<String, DataModel> map,
                            ItemGroup itemGroup,
                            DataSource dataSource,
@@ -55,7 +55,7 @@ public class OpcUaChangeTask extends TimerTask {
         this.itemGroupDao = itemGroupDao;
         this.messageNoticeDao = messageNoticeDao;
         this.opcUaClient = opcUaClient;
-        this.nodeIdList = nodeIdList;
+        this.itemList = itemList;
         this.map = map;
         this.itemGroup = itemGroup;
         this.dataSource = dataSource;
@@ -67,8 +67,12 @@ public class OpcUaChangeTask extends TimerTask {
     public void run() {
         Integer id = itemGroup.getId();
         Integer dataSourceId = dataSource.getId();
-        for (NodeId n : nodeIdList) {
-            String itemId = n.getIdentifier().toString();
+        for (Item item : itemList) {
+            String itemId = item.getItemReadName();
+            Integer eventMode = item.getEventMode();
+            Integer 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);
             try {
@@ -171,9 +175,22 @@ public class OpcUaChangeTask extends TimerTask {
 
                             List<BigDecimal> dataValueList = new ArrayList<>();
                             BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                            dataValueList.add(Blank.isNotEmpty(dm) ?
+                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                     MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                    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) {
+                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                    }
+                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                    if (dmData.compareTo(bigEventValue) == -1) {
+                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                    }
+                                }
+                            }
                             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);
@@ -200,7 +217,22 @@ public class OpcUaChangeTask extends TimerTask {
                                         dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
                                     }
                                     BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                    dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                    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) {
+                                                opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                            }
+                                        } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                            if (dmData.compareTo(bigEventValue) == -1) {
+                                                opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                            }
+                                        }
+                                    }
                                     redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
 
                                     List<String> dataValueTimeList = new ArrayList<>();
@@ -259,9 +291,22 @@ public class OpcUaChangeTask extends TimerTask {
 
                                 dataValueList = new ArrayList<>();
                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                dataValueList.add(Blank.isNotEmpty(dm) ?
+                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                         MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                        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) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    }
+                                }
                                 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);
@@ -371,8 +416,8 @@ public class OpcUaChangeTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (NodeId n : nodeIdList) {
-                String itemId = n.getIdentifier().toString();
+            for (Item item : itemList) {
+                String itemId = item.getItemReadName();
                 String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                 List<String> dataValueTimeList = new ArrayList<>();

+ 26 - 8
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaExceedTask.java

@@ -27,7 +27,7 @@ public class OpcUaExceedTask extends TimerTask {
 
     private final OpcUaClient opcUaClient;
 
-    private final List<NodeId> nodeIdList;
+    private final List<Item> itemList;
 
     private final Map<String, DataModel> map;
 
@@ -44,7 +44,7 @@ public class OpcUaExceedTask extends TimerTask {
                            ItemGroupDao itemGroupDao,
                            MessageNoticeDao messageNoticeDao,
                            OpcUaClient opcUaClient,
-                           List<NodeId> nodeIdList,
+                           List<Item> itemList,
                            Map<String, DataModel> map,
                            ItemGroup itemGroup,
                            DataSource dataSource,
@@ -55,7 +55,7 @@ public class OpcUaExceedTask extends TimerTask {
         this.itemGroupDao = itemGroupDao;
         this.messageNoticeDao = messageNoticeDao;
         this.opcUaClient = opcUaClient;
-        this.nodeIdList = nodeIdList;
+        this.itemList = itemList;
         this.map = map;
         this.itemGroup = itemGroup;
         this.dataSource = dataSource;
@@ -67,8 +67,12 @@ public class OpcUaExceedTask extends TimerTask {
     public void run() {
         Integer id = itemGroup.getId();
         Integer dataSourceId = dataSource.getId();
-        for (NodeId n : nodeIdList) {
-            String itemId = n.getIdentifier().toString();
+        for (Item item : itemList) {
+            String itemId = item.getItemReadName();
+            Integer eventMode = item.getEventMode();
+            Integer 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());
             try {
@@ -88,7 +92,21 @@ public class OpcUaExceedTask extends TimerTask {
                 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;
+                        BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                bigDecimal;
+                        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) {
+                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                }
+                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                if (dmData.compareTo(bigEventValue) == -1) {
+                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                }
+                            }
+                        }
                         if (Blank.isEmpty(storageYmdh)) {
                             if (dmData.compareTo(bigModeValue) == 1) {
                                 redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
@@ -204,8 +222,8 @@ public class OpcUaExceedTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (NodeId n : nodeIdList) {
-                String itemId = n.getIdentifier().toString();
+            for (Item item : itemList) {
+                String itemId = item.getItemReadName();
                 String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                 List<String> dataValueTimeList = new ArrayList<>();

+ 57 - 12
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaFrequencyTask.java

@@ -29,7 +29,7 @@ public class OpcUaFrequencyTask extends TimerTask {
 
     private final OpcUaClient opcUaClient;
 
-    private final List<NodeId> nodeIdList;
+    private final List<Item> itemList;
 
     private final Map<String, DataModel> map;
 
@@ -46,7 +46,7 @@ public class OpcUaFrequencyTask extends TimerTask {
                               ItemGroupDao itemGroupDao,
                               MessageNoticeDao messageNoticeDao,
                               OpcUaClient opcUaClient,
-                              List<NodeId> nodeIdList,
+                              List<Item> itemList,
                               Map<String, DataModel> map,
                               ItemGroup itemGroup,
                               DataSource dataSource,
@@ -57,7 +57,7 @@ public class OpcUaFrequencyTask extends TimerTask {
         this.itemGroupDao = itemGroupDao;
         this.messageNoticeDao = messageNoticeDao;
         this.opcUaClient = opcUaClient;
-        this.nodeIdList = nodeIdList;
+        this.itemList = itemList;
         this.map = map;
         this.itemGroup = itemGroup;
         this.dataSource = dataSource;
@@ -69,8 +69,12 @@ public class OpcUaFrequencyTask extends TimerTask {
     public void run() {
         Integer id = itemGroup.getId();
         Integer dataSourceId = dataSource.getId();
-        for (NodeId n : nodeIdList) {
-            String itemId = n.getIdentifier().toString();
+        for (Item item : itemList) {
+            String itemId = item.getItemReadName();
+            Integer eventMode = item.getEventMode();
+            Integer eventValue = item.getEventValue();
+            Integer tableReportId = item.getTableReportId();
+            NodeId n = new NodeId(item.getNodeIndex(), itemId);
             DataModel dm = map.get(itemId);
             try {
                 DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
@@ -163,9 +167,22 @@ public class OpcUaFrequencyTask extends TimerTask {
                         try {
                             List<BigDecimal> dataValueList = new ArrayList<>();
                             BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                            dataValueList.add(Blank.isNotEmpty(dm) ?
+                            BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                     MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                    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) {
+                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                    }
+                                } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                    if (dmData.compareTo(bigEventValue) == -1) {
+                                        opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                    }
+                                }
+                            }
                             redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                         } catch (Exception e) {
                             List<String> dataValueList = new ArrayList<>();
@@ -187,7 +204,22 @@ public class OpcUaFrequencyTask extends TimerTask {
                                     dataValueList = JavaTypeUtil.objChangeListBig(dataValueObject);
                                 }
                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                dataValueList.add(Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal);
+                                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) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    }
+                                }
                                 redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
                             } catch (Exception e) {
                                 List<String> dataValueList = new ArrayList<>();
@@ -233,9 +265,22 @@ public class OpcUaFrequencyTask extends TimerTask {
 
                                 dataValueList = new ArrayList<>();
                                 BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
-                                dataValueList.add(Blank.isNotEmpty(dm) ?
+                                BigDecimal dmData = Blank.isNotEmpty(dm) ?
                                         MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
-                                        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) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                        if (dmData.compareTo(bigEventValue) == -1) {
+                                            opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                        }
+                                    }
+                                }
                                 redisUtil.set(ConstantStr.DATA_VALUE + id + itemId, dataValueList, ConstantStr.TWO_HOUR);
 
                             } catch (Exception e) {
@@ -344,8 +389,8 @@ public class OpcUaFrequencyTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (NodeId n : nodeIdList) {
-                String itemId = n.getIdentifier().toString();
+            for (Item item : itemList) {
+                String itemId = item.getItemReadName();
                 String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                 List<String> dataValueTimeList = new ArrayList<>();

+ 26 - 8
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaLowerTask.java

@@ -26,7 +26,7 @@ public class OpcUaLowerTask extends TimerTask {
 
     private final OpcUaClient opcUaClient;
 
-    private final List<NodeId> nodeIdList;
+    private final List<Item> itemList;
 
     private final Map<String, DataModel> map;
 
@@ -43,7 +43,7 @@ public class OpcUaLowerTask extends TimerTask {
                           ItemGroupDao itemGroupDao,
                           MessageNoticeDao messageNoticeDao,
                           OpcUaClient opcUaClient,
-                          List<NodeId> nodeIdList,
+                          List<Item> itemList,
                           Map<String, DataModel> map,
                           ItemGroup itemGroup,
                           DataSource dataSource,
@@ -54,7 +54,7 @@ public class OpcUaLowerTask extends TimerTask {
         this.itemGroupDao = itemGroupDao;
         this.messageNoticeDao = messageNoticeDao;
         this.opcUaClient = opcUaClient;
-        this.nodeIdList = nodeIdList;
+        this.itemList = itemList;
         this.map = map;
         this.itemGroup = itemGroup;
         this.dataSource = dataSource;
@@ -66,8 +66,12 @@ public class OpcUaLowerTask extends TimerTask {
     public void run() {
         Integer id = itemGroup.getId();
         Integer dataSourceId = dataSource.getId();
-        for (NodeId n : nodeIdList) {
-            String itemId = n.getIdentifier().toString();
+        for (Item item : itemList) {
+            String itemId = item.getItemReadName();
+            Integer eventMode = item.getEventMode();
+            Integer 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());
             try {
@@ -87,7 +91,21 @@ public class OpcUaLowerTask extends TimerTask {
                 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;
+                        BigDecimal dmData = Blank.isNotEmpty(dm) ?
+                                MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) :
+                                bigDecimal;
+                        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) {
+                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                }
+                            } else if (eventMode.equals(ConstantStr.EVENT_MODEL_LOWER)) {
+                                if (dmData.compareTo(bigEventValue) == -1) {
+                                    opcAsyncTask.eventTable(tableReportId, dmData, currentYmdhmss);
+                                }
+                            }
+                        }
                         if (Blank.isEmpty(storageYmdh)) {
                             if (dmData.compareTo(bigModeValue) == -1) {
                                 redisUtil.set(ConstantStr.VALUE_BELONG_TIME + id + itemId, currentYmdh, ConstantStr.TWO_HOUR);
@@ -209,8 +227,8 @@ public class OpcUaLowerTask extends TimerTask {
             flage = false;
         }
         if (!flage) {
-            for (NodeId n : nodeIdList) {
-                String itemId = n.getIdentifier().toString();
+            for (Item item : itemList) {
+                String itemId = item.getItemReadName();
                 String valueBelongTime = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id + itemId));
 
                 List<String> dataValueTimeList = new ArrayList<>();

+ 4 - 5
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaTask.java

@@ -66,7 +66,6 @@ public class OpcUaTask extends TimerTask {
         OpcUaClient opcUaClient = null;
         try {
             opcUaClient = OpcUaUtil.createClient(dataSource);
-            List<NodeId> nodeIdList = OpcUaUtil.genNodeId(itemList);
             Timer timer = new Timer();
             if (itemGroup.getReadMode() == ConstantStr.ON_FREQUENCY) {
                 opcUaClient.connect().get();
@@ -75,7 +74,7 @@ public class OpcUaTask extends TimerTask {
                                 itemGroupDao,
                                 messageNoticeDao,
                                 opcUaClient,
-                                nodeIdList,
+                                itemList,
                                 map,
                                 itemGroup,
                                 dataSource,
@@ -88,7 +87,7 @@ public class OpcUaTask extends TimerTask {
                                 itemGroupDao,
                                 messageNoticeDao,
                                 opcUaClient,
-                                nodeIdList,
+                                itemList,
                                 map,
                                 itemGroup,
                                 dataSource,
@@ -101,7 +100,7 @@ public class OpcUaTask extends TimerTask {
                                 itemGroupDao,
                                 messageNoticeDao,
                                 opcUaClient,
-                                nodeIdList,
+                                itemList,
                                 map,
                                 itemGroup,
                                 dataSource,
@@ -114,7 +113,7 @@ public class OpcUaTask extends TimerTask {
                                 itemGroupDao,
                                 messageNoticeDao,
                                 opcUaClient,
-                                nodeIdList,
+                                itemList,
                                 map,
                                 itemGroup,
                                 dataSource,

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

@@ -13,7 +13,7 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
-    password: 123456
+    password: root
   resources:
     static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.path},file:${file.location}
   redis:

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

@@ -10,7 +10,7 @@
 
     <sql id="item">
         id
-        , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id
+        , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id, event_mode, event_value, table_report_id
     </sql>
 
 

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

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.opc_ua.dao.ReportTableDao">
+
+    <sql id="reportTable">
+        id
+        , user_id, report_table_name, report_table_data, report_value_format, is_auto_report , version, create_time
+    </sql>
+
+    <sql id="reportTableNoData">
+        id
+        ,table_template_id, user_id, report_table_name, report_value_format, is_auto_report , version, create_time
+    </sql>
+
+    <sql id="reportTableCron">
+        id
+        ,table_template_id, user_id, report_table_name, report_table_data, report_value_format, is_auto_report, version, cron_id, cron , create_time
+    </sql>
+
+    <sql id="reportTableCronNoData">
+        id
+        ,table_template_id, user_id, report_table_name, report_value_format, is_auto_report, version,cron_id, cron , create_time
+    </sql>
+
+    <insert id="addReportTable" parameterType="com.example.opc_common.entity.ReportTable" useGeneratedKeys="true"
+            keyProperty="id">
+        insert into t_report_table(table_template_id, user_id, report_table_name, report_table_data,
+                                   report_value_format, is_auto_report, version,
+                                   create_time) VALUE
+            (#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{reportValueFormat}, #{isAutoReport}, #{version}, now())
+    </insert>
+
+    <update id="updateReportTable">
+        update t_report_table
+        set report_table_name=#{reportTableName},
+            report_table_data=#{reportTableData},
+            report_value_format=#{reportValueFormat},
+            version=#{version}
+        where id = #{id}
+    </update>
+
+    <select id="getReportTableById" resultType="com.example.opc_common.entity.ReportTable">
+        select
+        <include refid="reportTableCron"/>
+        from t_report_table
+        where id = #{id}
+    </select>
+
+</mapper>