Browse Source

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

MS-FUUVYHVOEAYJ\Administrator 1 year ago
parent
commit
9e55ad5e5d
23 changed files with 1124 additions and 127 deletions
  1. 68 0
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/Chart.java
  2. 35 0
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/ChartItem.java
  3. 1 0
      chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/ModelEnum.java
  4. 3 3
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/InitRunner.java
  5. 135 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/ChartController.java
  6. 1 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/ReportTableController.java
  7. 39 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/ChartDao.java
  8. 7 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java
  9. 21 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/ChartService.java
  10. 212 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ChartServiceImpl.java
  11. 16 4
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java
  12. 11 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/UserGroupServiceImpl.java
  13. 96 3
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java
  14. 14 10
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTableTask.java
  15. 0 3
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTask.java
  16. 218 0
      chaunyi_opc/opc_da/src/main/resources/mapper/ChartDao.xml
  17. 44 8
      chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml
  18. 2 0
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/ItemGroupDao.java
  19. 7 0
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/dao/RawDataDao.java
  20. 11 0
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcAsyncTask.java
  21. 130 94
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaTask.java
  22. 19 0
      chaunyi_opc/opc_ua/src/main/resources/mapper/ItemGroupDao.xml
  23. 34 0
      chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml

+ 68 - 0
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/Chart.java

@@ -0,0 +1,68 @@
+package com.example.opc_common.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class Chart implements Serializable {
+
+    /**
+     * id
+     */
+    private Integer id;
+    /**
+     * 用户id
+     */
+    private String userId;
+    /**
+     * 用户名,虚拟的,用于返回
+     */
+    private String userName;
+    /**
+     * 0取原始值,1取计算值
+     */
+    private Integer valueType;
+    /**
+     * 统计图类型,line折线图,bar柱状图,pie饼状图
+     */
+    private String chartType;
+    /**
+     * 统计图名称
+     */
+    private String chartName;
+    /**
+     * 取值模式0平均值,1最大值,2最小值,3瞬时值(必填)
+     */
+    private Integer valueTakingMode;
+    /**
+     * 时段类型0天,1时,2分,3秒(折线图,柱状图必填)
+     */
+    private Integer bucketType;
+    /**
+     * 时段值(折线图,柱状图必填)
+     */
+    private Integer bucketValue;
+    /**
+     * 取值开始时间
+     */
+    private Date startTime;
+    /**
+     * 取值结束时间
+     */
+    private Date endTime;
+    /**
+     * 备用字段
+     */
+    private String standby;
+
+    private List<ChartItem> chartItemList = new ArrayList<>();
+    /**
+     * 用户组id集合
+     */
+    private List<UserGroup> userGroupList = new ArrayList<>();
+    ;
+}

+ 35 - 0
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/entity/ChartItem.java

@@ -0,0 +1,35 @@
+package com.example.opc_common.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ChartItem implements Serializable {
+
+    /**
+     * id
+     */
+    private Integer id;
+    /**
+     * 统计图id
+     */
+    private Integer chartId;
+    /**
+     * 数据项id
+     */
+    private Integer itemId;
+    /**
+     * 结果集
+     */
+    private String valueList;
+    /**
+     * 结果集对应的时间
+     */
+    private String valueTimeList;
+    /**
+     * 结果集对应的索引
+     */
+    private String valueIndexList;
+
+}

+ 1 - 0
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/ModelEnum.java

@@ -14,6 +14,7 @@ public enum ModelEnum {
     DATAGROUP("数据组配置", "DATAGROUP"),
     DATAMODEL("数据模型", "DATAMODEL"),
     RUNSETUP("运行配置", "RUNSETUP"),
+    MAINCHART("首页统计图", "MAINCHART"),
     USERGROUP("用户组", "USERGROUP"),
     MESSAGENOTICE("消息通知", "MESSAGENOTICE"),
 

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

@@ -56,10 +56,10 @@ public class InitRunner {
         if (Blank.isNotEmpty(itemGroupIdList)) {
             for (Integer itemGroupId : itemGroupIdList) {
                 ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
-                if(Blank.isNotEmpty(itemGroup)){
+                if (Blank.isNotEmpty(itemGroup)) {
                     if (itemGroup.getReadMode().equals(ConstantStr.EXCEED_SET_VALUE)) {
                         Integer dataSourceId = itemGroup.getDataSourceId();
-                        List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroupId);
+                        List<Item> itemList = itemGroupDao.getBasicItemList(itemGroupId, ConstantStr.BASIC_ATTRIBUTES);
                         Long dataIndex = itemGroupDao.getMaxIndex(itemGroupId, dataSourceId);
                         if (Blank.isNotEmpty(dataIndex)) {
                             opcAsyncTask.packageEventTable(itemList, dataSourceId, dataIndex);
@@ -68,7 +68,7 @@ public class InitRunner {
                         List<String> belongTimeList = rawDataDao.getRawDataBelongTime(itemGroupId);
                         if (Blank.isNotEmpty(belongTimeList)) {
                             for (int i = 0; i < belongTimeList.size(); i++) {
-                                List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroupId);
+                                List<Item> itemList = itemGroupDao.getBasicItemList(itemGroupId, ConstantStr.BASIC_ATTRIBUTES);
                                 Integer dataSourceId = itemGroup.getDataSourceId();
                                 opcAsyncTask.packageRawDataList1(itemList, dataSourceId, belongTimeList.get(i));
                             }

+ 135 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/ChartController.java

@@ -0,0 +1,135 @@
+package com.example.opc_da.controller;
+
+import com.example.opc_common.entity.Chart;
+import com.example.opc_common.enums.ModelEnum;
+import com.example.opc_common.enums.OperationEnum;
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.enums.ServerEnum;
+import com.example.opc_common.util.Blank;
+import com.example.opc_common.util.Result;
+import com.example.opc_da.annotation.WebLog;
+import com.example.opc_da.service.ChartService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("chart")
+@Slf4j
+public class ChartController {
+
+    @Autowired
+    private ChartService chartService;
+
+    /**
+     * 新增首页统计图
+     *
+     * @param chart
+     * @return
+     */
+    @PostMapping("/addChart")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.ADD)
+    public Result addChart(@RequestBody Chart chart) {
+        if (Blank.isEmpty(chart, chart.getChartType(), chart.getValueType(), chart.getChartName(),
+                chart.getValueTakingMode(), chart.getBucketType(), chart.getBucketValue(), chart.getChartItemList())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "统计图类型、取值类型、名称、取值模式、时段类型、时段值、数据项都不能为空");
+        }
+        return chartService.addChart(chart);
+    }
+
+    /**
+     * 修改首页统计图
+     *
+     * @param chart
+     * @return
+     */
+    @PostMapping("/updateChart")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.ADD)
+    public Result updateChart(@RequestBody Chart chart) {
+        if (Blank.isEmpty(chart, chart.getId(), chart.getChartType(), chart.getValueType(), chart.getChartName(),
+                chart.getValueTakingMode(), chart.getBucketType(), chart.getBucketValue(), chart.getChartItemList())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "统计图id、类型、取值类型、名称、取值模式、时段类型、时段值、数据项都不能为空");
+        }
+        return chartService.updateChart(chart);
+    }
+
+    /**
+     * 获取当前登录人创建的所有首页统计图
+     *
+     * @param page
+     * @param limit
+     * @return
+     */
+    @GetMapping("/getAllChart")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.SELECT)
+    public Result getAllChart(Integer page, Integer limit) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "page,limit不能为空,且必须大于0");
+        }
+        return chartService.getAllChart(page, limit);
+    }
+
+    /**
+     * 通过id获取首页统计图
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/getChartById")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.SELECT)
+    public Result getChartById(@PathVariable Integer id) {
+        if (Blank.isEmpty(id)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "统计图id不能为空");
+        }
+        return chartService.getChartById(id);
+    }
+
+    /**
+     * 通过id删除统计图
+     *
+     * @param id
+     * @return
+     */
+    @PostMapping("/delChartById")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.DELETE)
+    public Result delChartById(@PathVariable Integer id) {
+        if (Blank.isEmpty(id)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "统计图id不能为空");
+        }
+        return chartService.delChartById(id);
+    }
+
+    /**
+     * 给首页统计图分配用户组
+     *
+     * @param chart
+     * @return
+     */
+    @PostMapping("/chartAssignUserGroup")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.ASSIGN)
+    public Result chartAssignUserGroup(@RequestBody Chart chart) {
+        if (Blank.isEmpty(chart, chart.getId())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "统计图id不能为空");
+        }
+        return chartService.chartAssignUserGroup(chart);
+    }
+
+    /**
+     * 获取用户可以查看的所有统计图
+     *
+     * @param page
+     * @param limit
+     * @param chartType
+     * @param chartName
+     * @return
+     */
+    @GetMapping("/getAllOkChart")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MAINCHART, OperationEnum = OperationEnum.SELECT)
+    public Result getAllOkChart(Integer page, Integer limit, String chartType, String chartName) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "page,limit不能为空,且必须大于0");
+        }
+        return chartService.getAllOkChart(page, limit, chartType, chartName);
+    }
+
+}

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

@@ -154,7 +154,7 @@ public class ReportTableController {
     @PostMapping("/addReportTable")
     @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.REPORTTABLE, OperationEnum = OperationEnum.ADD)
     public Result addReportTable(@RequestBody ReportTable reportTable) {
-        if (Blank.isEmpty(reportTable, reportTable.getReportTableType(), reportTable.getTableTemplateId(),
+        if (Blank.isEmpty(reportTable, reportTable.getReportTableType(), reportTable.getValueType(), reportTable.getTableTemplateId(),
                 reportTable.getReportTableName(), reportTable.getReportTableData())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表类型、取值类型、模板、名称、内容不能为空");
         }

+ 39 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/ChartDao.java

@@ -0,0 +1,39 @@
+package com.example.opc_da.dao;
+
+import com.example.opc_common.entity.Chart;
+import com.example.opc_common.entity.ChartItem;
+import com.example.opc_common.entity.UserGroup;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ChartDao {
+    Integer addChart(Chart chart);
+
+    Integer updateChart(Chart chart);
+
+    Integer addChartItem(Integer chartId, List<ChartItem> chartItemList);
+
+    Long getChartCount(String userId);
+
+    List<Chart> getAllChart(String userId, Long startNum, Long limitNum);
+
+    Chart getChartById(Integer id);
+
+    List<ChartItem> getChartItemList(Integer chartId);
+
+    Integer delChartUserGroup(Integer chartId);
+
+    Integer addChartUserGroup(Integer chartId, List<UserGroup> userGroupList);
+
+    List<Chart> getChartByUserGroupId(Integer userGroupId);
+
+    Long getAllOkChartCount(String userId, String chartType, String chartName);
+
+    List<Chart> getAllOkChart(Long startNum, Long limitNum, String userId, String chartType, String chartName);
+
+    Integer delChartById(Integer id);
+
+    Integer delChartItem(Integer chartId);
+}

+ 7 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java

@@ -1,5 +1,6 @@
 package com.example.opc_da.dao;
 
+import com.example.opc_common.entity.AttachRawData;
 import com.example.opc_common.entity.CursorRawData;
 import com.example.opc_common.entity.Item;
 import com.example.opc_common.entity.RawData;
@@ -50,4 +51,10 @@ public interface RawDataDao {
     List<CursorRawData> getTableCursorData(Integer itemGroupId, Integer dataSourceId, String itemName, String sqlCurrentYmdh);
 
     List<String> getCursorYmdh(Integer itemGroupId, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
+
+    AttachRawData getAttachRawData(Integer itemGroupId,Integer dataSourceId,String itemName);
+
+    Integer addAttachRawData(AttachRawData attachRawData);
+
+    Integer updateAttachRawData(AttachRawData attachRawData);
 }

+ 21 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/ChartService.java

@@ -0,0 +1,21 @@
+package com.example.opc_da.service;
+
+import com.example.opc_common.entity.Chart;
+import com.example.opc_common.entity.DataModel;
+import com.example.opc_common.util.Result;
+
+public interface ChartService {
+    Result addChart(Chart chart);
+
+    Result updateChart(Chart chart);
+
+    Result getChartById(Integer id);
+
+    Result getAllChart(Integer page, Integer limit);
+
+    Result chartAssignUserGroup(Chart chart);
+
+    Result getAllOkChart(Integer page, Integer limit, String chartType, String chartName);
+
+    Result delChartById(Integer id);
+}

+ 212 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ChartServiceImpl.java

@@ -0,0 +1,212 @@
+package com.example.opc_da.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.entity.*;
+import com.example.opc_common.enums.ResultEnum;
+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.Result;
+import com.example.opc_da.dao.ChartDao;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.RawDataDao;
+import com.example.opc_da.service.ChartService;
+import com.example.opc_da.task.ReportTask;
+import com.example.opc_da.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+@Transactional
+public class ChartServiceImpl implements ChartService {
+
+    @Autowired
+    private ChartDao chartDao;
+
+    @Autowired
+    private UserUtil userUtil;
+
+    @Autowired
+    private ItemGroupDao itemGroupDao;
+
+    @Autowired
+    private RawDataDao rawDataDao;
+
+    @Override
+    public synchronized Result addChart(Chart chart) {
+        String userId = userUtil.getCurrentUserId();
+        chart.setUserId(userId);
+        if (chartDao.addChart(chart) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "添加统计图失败");
+        }
+        chartDao.addChartItem(chart.getId(), chart.getChartItemList());
+        return Result.ok("添加统计图成功");
+    }
+
+    @Override
+    public synchronized Result updateChart(Chart chart) {
+        if (chartDao.updateChart(chart) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改统计图失败");
+        }
+        return Result.ok("修改统计图成功");
+    }
+
+    @Override
+    public Result getChartById(Integer id) {
+        Chart chart = chartDao.getChartById(id);
+        List<ChartItem> chartItemList = chartDao.getChartItemList(id);
+        if (Blank.isNotEmpty(chartItemList)) {
+            Integer valueType = chart.getValueType();
+            Boolean flage = valueType.equals(ConstantStr.CALCULATED_VALUE);
+            Integer valueTakingMode = chart.getValueTakingMode();
+            Integer bucketType = chart.getBucketType();
+            Integer bucketValue = chart.getBucketValue();
+            Date startTime = chart.getStartTime();
+            Date endTime = chart.getEndTime();
+            String pattern = null;
+            if (bucketType.equals(ConstantStr.PERIOD_TIME_DAY)) {
+                pattern = ConstantStr.TIME_DAY_STR;
+            } else if (bucketType.equals(ConstantStr.PERIOD_TIME_HOUR)) {
+                pattern = ConstantStr.TIME_HOUR_STR;
+            } else if (bucketType.equals(ConstantStr.PERIOD_TIME_MINUTE)) {
+                pattern = ConstantStr.TIME_MINUTE_STR;
+            } else if (bucketType.equals(ConstantStr.PERIOD_TIME_SECOND)) {
+                pattern = ConstantStr.TIME_SECOND_STR;
+            }
+            int timeLength = DateUtil.timeDifference(startTime, endTime, pattern, bucketValue);
+            for (int i = 0; i < chartItemList.size(); i++) {
+                ChartItem chartItem = chartItemList.get(i);
+                Integer itemId = chartItem.getItemId();
+                Item item = itemGroupDao.getItemById(itemId);
+                Integer itemGroupId = item.getItemGroupId();
+                Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
+                ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
+                Integer dataSourceId = itemGroup.getDataSourceId();
+                String itemName = item.getItemName();
+                if (Blank.isEmpty(item)) {
+                    continue;
+                }
+                Integer itemType = item.getItemType();
+                long startTimeTime = startTime.getTime();
+                long endTimeTime;
+                if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                    AttachRawData attachRawData = rawDataDao.getAttachRawData(itemGroupId, dataSourceId, itemName);
+                    String dataType = attachRawData.getDataType();
+                    if (!dataType.toLowerCase().equals("boolean")) {
+                        try {
+                            List<BigDecimal> valueList = new ArrayList<>();
+                            List<String> valueTimeList = new ArrayList<>();
+                            List<Long> valueIndexList = new ArrayList<>();
+                            BigDecimal bigDecimal = JSON.parseObject(flage ? attachRawData.getDataValue() : attachRawData.getOrgDataValue(), BigDecimal.class);
+                            for (int j = 0; j < timeLength; j++) {
+                                if (i != timeLength - 1) {
+                                    endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
+                                } else {
+                                    endTimeTime = endTime.getTime();
+                                }
+                                valueList.add(bigDecimal);
+                                valueTimeList.add(DateUtil.dateChangeStrYmdhmss(new Date(startTimeTime)));
+                                valueIndexList.add((long) j);
+                                startTimeTime = endTimeTime;
+                            }
+                            chartItem.setValueList(valueList.toString());
+                            chartItem.setValueTimeList(valueTimeList.toString());
+                            chartItem.setValueIndexList(valueIndexList.toString());
+                        } catch (Exception e) {
+
+                        }
+                    }
+                } else {
+                    String startBelongTime;
+                    String endBelongTime;
+                    List<RawData> rawDataList = new ArrayList<>();
+                    if (bucketType.equals(ConstantStr.PERIOD_TIME_DAY)) {
+                        startBelongTime = DateUtil.dateChangeStrYmdhms(startTime).substring(0, ConstantStr.TIME_DAY_STR.length());
+                        endBelongTime = DateUtil.dateChangeStrYmdhms(endTime).substring(0, ConstantStr.TIME_DAY_STR.length());
+                        rawDataList = rawDataDao.getTableDataByDay(itemGroupId, remainder, dataSourceId, itemName, startBelongTime, endBelongTime);
+                    } else {
+                        startBelongTime = DateUtil.dateChangeStrYmdhms(startTime).substring(0, ConstantStr.TIME_HOUR_STR.length());
+                        endBelongTime = DateUtil.dateChangeStrYmdhms(endTime).substring(0, ConstantStr.TIME_HOUR_STR.length());
+                        rawDataList = rawDataDao.getTableData(itemGroupId, remainder, dataSourceId, itemName, startBelongTime, endBelongTime);
+                    }
+                    List<String> sqlCurrentYmdhList = rawDataDao.getCursorYmdh(itemGroupId, dataSourceId, itemName, startBelongTime, endBelongTime);
+                    if (Blank.isNotEmpty(sqlCurrentYmdhList)) {
+                        for (String sqlCurrentYmdh : sqlCurrentYmdhList) {
+                            List<CursorRawData> cursorRawDataList = rawDataDao.getTableCursorData(itemGroupId, dataSourceId, itemName, sqlCurrentYmdh);
+                            rawDataList = ReportTask.genRawAddCursor(rawDataList, cursorRawDataList, itemGroupId, dataSourceId, sqlCurrentYmdh);
+                        }
+                    }
+                    if (Blank.isNotEmpty(rawDataList)) {
+                        String dataType = rawDataList.get(0).getDataType();
+                        if (dataType.equals("boolean")) {
+//                            map = ReportTask.genBoolean(rawDataList, startTime, endTime, valueTakingMode, bucketType, bucketValue);
+                        } else {
+                            try {
+//                                map = ReportTask.genBigDecimal(rawDataList, startTime, endTime, valueTakingMode, bucketType, bucketValue);
+                            } catch (Exception e) {
+//                                map = ReportTask.genString(rawDataList, startTime, endTime, bucketType, bucketValue);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        chart.setChartItemList(chartItemList);
+        return Result.ok(chart);
+    }
+
+    @Override
+    public Result getAllChart(Integer page, Integer limit) {
+        JSONObject jsonObject = new JSONObject();
+        String userId = userUtil.getCurrentUserId();
+        Long count = chartDao.getChartCount(userId);
+        Long startNum = Long.valueOf((page - 1) * limit);
+        List<Chart> chartList = chartDao.getAllChart(userId, startNum, Long.valueOf(limit));
+        jsonObject.put("count", count);
+        jsonObject.put("chartList", chartList);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public Result chartAssignUserGroup(Chart chart) {
+        Integer id = chart.getId();
+        chartDao.delChartUserGroup(id);
+        if (Blank.isNotEmpty(chart.getUserGroupList())) {
+            if (chartDao.addChartUserGroup(id, chart.getUserGroupList()) <= 0) {
+                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "分配用户组失败");
+            }
+        }
+        return Result.ok("分配用户组成功");
+    }
+
+    @Override
+    public Result getAllOkChart(Integer page, Integer limit, String chartType, String chartName) {
+        String userId = userUtil.getCurrentUserId();
+        Long startNum = Long.valueOf((page - 1) * limit);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("count", chartDao.getAllOkChartCount(userId, chartType, chartName));
+        jsonObject.put("reportTableList", chartDao.getAllOkChart(startNum, Long.valueOf(limit), userId, chartType, chartName));
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public Result delChartById(Integer id) {
+        Chart chart = chartDao.getChartById(id);
+        if (!chart.getUserId().equals(userUtil.getCurrentUserId())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "这是别人分享的统计图,不能删除");
+        }
+        if (chartDao.delChartById(id) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "删除统计图失败");
+        }
+        chartDao.delChartItem(id);
+        chartDao.delChartUserGroup(id);
+        return Result.ok("删除统计图成功");
+    }
+}

+ 16 - 4
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java

@@ -252,7 +252,6 @@ public class ReportTableServiceImpl implements ReportTableService {
     @Override
     public synchronized Result addReportTable(ReportTable reportTable) {
         Integer reportTableType = reportTable.getReportTableType();
-        Integer valueType = reportTable.getValueType();
         Integer tableTemplateId = reportTable.getTableTemplateId();
         TableTemplate tableTemplate = reportTableDao.getTableTemplateById(tableTemplateId);
         List<TableTemplateItem> tableTemplateItemList = reportTableDao.getTtiDataByTemplateId(tableTemplateId);
@@ -278,7 +277,7 @@ public class ReportTableServiceImpl implements ReportTableService {
             if (reportTableDao.addReportTable(reportTable) <= 0) {
                 return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "添加报表失败");
             }
-            reportTableTask.manualReport(reportTable.getId(), valueType.equals(ConstantStr.CALCULATED_VALUE), tableTemplateItemList);
+            reportTableTask.manualReport(reportTable.getId(), tableTemplateItemList);
         } else if (reportTableType.equals(ConstantStr.AUTOMATIC_REPORT)) {
             String cron = reportTable.getCron();
             Date startTime = reportTable.getStartTime();
@@ -476,6 +475,18 @@ public class ReportTableServiceImpl implements ReportTableService {
                         Integer valueTakingMode = t.getValueTakingMode();
                         Integer bucketType = t.getBucketType();
                         Integer bucketValue = t.getBucketValue();
+                        Item item = itemGroupDao.getItemById(itemId);
+                        if (Blank.isEmpty(item)) {
+                            continue;
+                        }
+                        Integer itemType = item.getItemType();
+                        if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                            AttachRawData attachRawData = rawDataDao.getAttachRawData(itemGroupId, dataSourceId, itemName);
+                            reportTableItemList.add(new ReportTableItem(
+                                    id, itemId, xaxis, yaxis, standby, flage ? attachRawData.getDataValue() : attachRawData.getOrgDataValue(), attachRawData.getDataValueTime(), null
+                            ));
+                            continue;
+                        }
                         String valueList = null;
                         String valueTimeList = null;
                         String valueIndexList = null;
@@ -615,9 +626,10 @@ public class ReportTableServiceImpl implements ReportTableService {
 
     @Override
     public Result tableAssignUserById(ReportTable reportTable) {
-        reportTableDao.delTableUserGroup(reportTable.getId());
+        Integer id = reportTable.getId();
+        reportTableDao.delTableUserGroup(id);
         if (Blank.isNotEmpty(reportTable.getUserGroupList())) {
-            if (reportTableDao.addTableUserGroup(reportTable.getId(), reportTable.getUserGroupList()) <= 0) {
+            if (reportTableDao.addTableUserGroup(id, reportTable.getUserGroupList()) <= 0) {
                 return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "分配用户组失败");
             }
         }

+ 11 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/UserGroupServiceImpl.java

@@ -1,6 +1,7 @@
 package com.example.opc_da.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.entity.Chart;
 import com.example.opc_common.entity.Department;
 import com.example.opc_common.entity.ReportTable;
 import com.example.opc_common.entity.UserGroup;
@@ -8,11 +9,13 @@ import com.example.opc_common.enums.ResultEnum;
 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.ChartDao;
 import com.example.opc_da.dao.DepartmentDao;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.dao.UserGroupDao;
 import com.example.opc_da.service.UserGroupService;
 import com.example.opc_da.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -37,6 +40,9 @@ public class UserGroupServiceImpl implements UserGroupService {
     @Resource
     private ReportTableDao reportTableDao;
 
+    @Autowired
+    private ChartDao chartDao;
+
     @Override
     public synchronized Result addUserGroup(UserGroup userGroup) {
         String userId = userUtil.getCurrentUserId();
@@ -83,9 +89,13 @@ public class UserGroupServiceImpl implements UserGroupService {
     @Override
     public synchronized Result delUserGroupById(Integer id) {
         List<ReportTable> reportTableList = reportTableDao.getReportTableByUserGroupId(id);
-        if (Blank.isNotEmpty(reportTableList)){
+        if (Blank.isNotEmpty(reportTableList)) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "此用户组已分配在报表中,不能删除");
         }
+        List<Chart> chartList = chartDao.getChartByUserGroupId(id);
+        if (Blank.isNotEmpty(chartList)) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "此用户组已分配在首页统计图中,不能删除");
+        }
         userGroupDao.delUserGroupUserListById(id);
         if (userGroupDao.delUserGroupById(id) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "删除用户组失败");

+ 96 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcAsyncTask.java

@@ -65,9 +65,14 @@ public class OpcAsyncTask {
         }
     }
 
-    public synchronized void addAttachRawData(AttachRawData attachRawData){
-        if (Blank.isNotEmpty(attachRawData)){
-
+    public synchronized void addAttachRawData(AttachRawData attachRawData) {
+        if (Blank.isNotEmpty(attachRawData)) {
+            AttachRawData attachRawData1 = rawDataDao.getAttachRawData(attachRawData.getItemGroupId(), attachRawData.getDataSourceId(), attachRawData.getItemName());
+            if (Blank.isEmpty(attachRawData1)) {
+                rawDataDao.addAttachRawData(attachRawData);
+            } else {
+                rawDataDao.updateAttachRawData(attachRawData);
+            }
         }
     }
 
@@ -119,6 +124,14 @@ public class OpcAsyncTask {
                                 //根据索引进行排序,将数据丢到相应的位置
                                 for (TableTemplateItem t : tableTemplateItemList) {
                                     Integer itemId = t.getItemId();
+                                    Item item = itemGroupDao.getItemById(itemId);
+                                    if (Blank.isEmpty(item)) {
+                                        continue;
+                                    }
+                                    Integer itemType = item.getItemType();
+                                    if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                        continue;
+                                    }
                                     List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, indexList);
                                     if (Blank.isNotEmpty(cursorRawDataList)) {
                                         Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -157,6 +170,14 @@ public class OpcAsyncTask {
                                         //根据索引进行排序,并添加数据
                                         for (TableTemplateItem t : tableTemplateItemList) {
                                             Integer itemId = t.getItemId();
+                                            Item item = itemGroupDao.getItemById(itemId);
+                                            if (Blank.isEmpty(item)) {
+                                                continue;
+                                            }
+                                            Integer itemType = item.getItemType();
+                                            if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                continue;
+                                            }
                                             List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, dataIndexList);
                                             if (Blank.isNotEmpty(cursorRawDataList)) {
                                                 Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -194,6 +215,14 @@ public class OpcAsyncTask {
                                         //根据索引进行排序,并添加数据
                                         for (TableTemplateItem t : tableTemplateItemList) {
                                             Integer itemId = t.getItemId();
+                                            Item item = itemGroupDao.getItemById(itemId);
+                                            if (Blank.isEmpty(item)) {
+                                                continue;
+                                            }
+                                            Integer itemType = item.getItemType();
+                                            if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                continue;
+                                            }
                                             List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, dataIndexList);
                                             if (Blank.isNotEmpty(cursorRawDataList)) {
                                                 Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -228,6 +257,14 @@ public class OpcAsyncTask {
                                     //根据索引进行排序,将数据丢到相应的位置
                                     for (TableTemplateItem t : tableTemplateItemList) {
                                         Integer itemId = t.getItemId();
+                                        Item item = itemGroupDao.getItemById(itemId);
+                                        if (Blank.isEmpty(item)) {
+                                            continue;
+                                        }
+                                        Integer itemType = item.getItemType();
+                                        if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                            continue;
+                                        }
                                         List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, indexList);
                                         if (Blank.isNotEmpty(cursorRawDataList)) {
                                             Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -263,6 +300,14 @@ public class OpcAsyncTask {
                                             //根据索引进行排序,并添加数据
                                             for (TableTemplateItem t : tableTemplateItemList) {
                                                 Integer itemId = t.getItemId();
+                                                Item item = itemGroupDao.getItemById(itemId);
+                                                if (Blank.isEmpty(item)) {
+                                                    continue;
+                                                }
+                                                Integer itemType = item.getItemType();
+                                                if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                    continue;
+                                                }
                                                 List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, dataIndexList);
                                                 if (Blank.isNotEmpty(cursorRawDataList)) {
                                                     Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -300,6 +345,14 @@ public class OpcAsyncTask {
                                             //根据索引进行排序,并添加数据
                                             for (TableTemplateItem t : tableTemplateItemList) {
                                                 Integer itemId = t.getItemId();
+                                                Item item = itemGroupDao.getItemById(itemId);
+                                                if (Blank.isEmpty(item)) {
+                                                    continue;
+                                                }
+                                                Integer itemType = item.getItemType();
+                                                if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                    continue;
+                                                }
                                                 List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, dataIndexList);
                                                 if (Blank.isNotEmpty(cursorRawDataList)) {
                                                     Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -321,6 +374,14 @@ public class OpcAsyncTask {
                                     }
                                     for (TableTemplateItem t : tableTemplateItemList) {
                                         Integer itemId = t.getItemId();
+                                        Item item = itemGroupDao.getItemById(itemId);
+                                        if (Blank.isEmpty(item)) {
+                                            continue;
+                                        }
+                                        Integer itemType = item.getItemType();
+                                        if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                            continue;
+                                        }
                                         ReportTableItem reportTableItem = reportTableDao.getReportTableItem(chTableId, itemId);
                                         List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, indexList);
                                         if (Blank.isNotEmpty(cursorRawDataList)) {
@@ -347,6 +408,14 @@ public class OpcAsyncTask {
                                     }
                                     for (TableTemplateItem t : tableTemplateItemList) {
                                         Integer itemId = t.getItemId();
+                                        Item item = itemGroupDao.getItemById(itemId);
+                                        if (Blank.isEmpty(item)) {
+                                            continue;
+                                        }
+                                        Integer itemType = item.getItemType();
+                                        if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                            continue;
+                                        }
                                         ReportTableItem reportTableItem = reportTableDao.getReportTableItem(chTableId, itemId);
                                         List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, oldIndexList);
                                         if (Blank.isNotEmpty(cursorRawDataList)) {
@@ -374,6 +443,14 @@ public class OpcAsyncTask {
                                         //根据索引进行排序,将数据丢到相应的位置
                                         for (TableTemplateItem t : tableTemplateItemList) {
                                             Integer itemId = t.getItemId();
+                                            Item item = itemGroupDao.getItemById(itemId);
+                                            if (Blank.isEmpty(item)) {
+                                                continue;
+                                            }
+                                            Integer itemType = item.getItemType();
+                                            if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                continue;
+                                            }
                                             List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, newIndexList);
                                             if (Blank.isNotEmpty(cursorRawDataList)) {
                                                 Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -409,6 +486,14 @@ public class OpcAsyncTask {
                                                 //根据索引进行排序,并添加数据
                                                 for (TableTemplateItem t : tableTemplateItemList) {
                                                     Integer itemId = t.getItemId();
+                                                    Item item = itemGroupDao.getItemById(itemId);
+                                                    if (Blank.isEmpty(item)) {
+                                                        continue;
+                                                    }
+                                                    Integer itemType = item.getItemType();
+                                                    if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                        continue;
+                                                    }
                                                     List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, newIndexList);
                                                     if (Blank.isNotEmpty(cursorRawDataList)) {
                                                         Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);
@@ -446,6 +531,14 @@ public class OpcAsyncTask {
                                                 //根据索引进行排序,并添加数据
                                                 for (TableTemplateItem t : tableTemplateItemList) {
                                                     Integer itemId = t.getItemId();
+                                                    Item item = itemGroupDao.getItemById(itemId);
+                                                    if (Blank.isEmpty(item)) {
+                                                        continue;
+                                                    }
+                                                    Integer itemType = item.getItemType();
+                                                    if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                                                        continue;
+                                                    }
                                                     List<CursorRawData> cursorRawDataList = rawDataDao.getEventDataList(itemGroupId, dataSourceId, itemId, dataIndexList);
                                                     if (Blank.isNotEmpty(cursorRawDataList)) {
                                                         Map<String, String> map = ReportTask.genEventCursor(cursorRawDataList);

+ 14 - 10
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTableTask.java

@@ -52,7 +52,7 @@ public class ReportTableTask {
      * @param id
      * @param tableTemplateItemList
      */
-    public void manualReport(Integer id, Boolean flage, List<TableTemplateItem> tableTemplateItemList) {
+    public void manualReport(Integer id, List<TableTemplateItem> tableTemplateItemList) {
         if (Blank.isNotEmpty(tableTemplateItemList)) {
             List<ReportTableItem> reportTableItemList = new ArrayList<>();
             for (TableTemplateItem t : tableTemplateItemList) {
@@ -64,16 +64,8 @@ public class ReportTableTask {
                 Integer xaxis = t.getXaxis();
                 Integer yaxis = t.getYaxis();
                 String standby = t.getStandby();
-                String valueList = null;
-                String valueTimeList = null;
-                String valueIndexList = null;
-                Map<String, String> map = new HashMap<>();
-
-                valueList = map.get(flage ? "valueList" : "orgValueList");
-                valueTimeList = map.get("valueTimeList");
-                valueIndexList = map.get("valueIndexList");
                 reportTableItemList.add(new ReportTableItem(
-                        id, itemId, xaxis, yaxis, standby, valueList, valueTimeList, valueIndexList
+                        id, itemId, xaxis, yaxis, standby, null, null, null
                 ));
             }
             if (Blank.isNotEmpty(reportTableItemList)) {
@@ -185,6 +177,18 @@ public class ReportTableTask {
                 Integer valueTakingMode = t.getValueTakingMode();
                 Integer bucketType = t.getBucketType();
                 Integer bucketValue = t.getBucketValue();
+                Item item = itemGroupDao.getItemById(itemId);
+                if (Blank.isEmpty(item)) {
+                    continue;
+                }
+                Integer itemType = item.getItemType();
+                if (itemType.equals(ConstantStr.ATTACH_ATTRIBUTES)) {
+                    AttachRawData attachRawData = rawDataDao.getAttachRawData(itemGroupId, dataSourceId, itemName);
+                    reportTableDao.addReportTableItem(new ReportTableItem(
+                            id, itemId, xaxis, yaxis, standby, flage ? attachRawData.getDataValue() : attachRawData.getOrgDataValue(), attachRawData.getDataValueTime(), null
+                    ));
+                    continue;
+                }
                 String valueList = null;
                 String valueTimeList = null;
                 String valueIndexList = null;

+ 0 - 3
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/ReportTask.java

@@ -62,7 +62,6 @@ public class ReportTask {
             List<Boolean> list = new ArrayList<>();
             if (i != timeLength - 1) {
                 endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
-
             } else {
                 endTimeTime = endTime.getTime();
             }
@@ -185,7 +184,6 @@ public class ReportTask {
             List<BigDecimal> list = new ArrayList<>();
             if (i != timeLength - 1) {
                 endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
-
             } else {
                 endTimeTime = endTime.getTime();
             }
@@ -302,7 +300,6 @@ public class ReportTask {
             List<String> list = new ArrayList<>();
             if (i != timeLength - 1) {
                 endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
-
             } else {
                 endTimeTime = endTime.getTime();
             }

+ 218 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/ChartDao.xml

@@ -0,0 +1,218 @@
+<?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_da.dao.ChartDao">
+
+    <sql id="chart">
+        id
+        ,user_id, chart_type, value_type, chart_name, value_taking_mode, bucket_type, bucket_value,
+                             start_time, end_time, standby
+    </sql>
+
+    <sql id="chartItem">
+        id
+        , chart_id, item_id, value_list, value_time_list, value_index_list
+    </sql>
+
+    <insert id="addChart">
+        insert into t_chart (user_id, chart_type, value_type, chart_name, value_taking_mode, bucket_type, bucket_value,
+                             start_time, end_time, standby)
+            VALUE (#{userId}, #{chartType}, #{valueType}, #{chartName}, #{valueTakingMode}, #{bucketType}, #{bucketValue},
+            #{startTime}, #{endTime}, #{standby})
+    </insert>
+
+    <insert id="addChartItem">
+        insert into t_chart_item(chart_id, item_id, value_list, value_time_list, value_index_list)
+        values
+        <foreach collection="chartItemList" item="chartItem" index="index" separator=",">
+            (#{chartId}, #{chartItem.itemId}, #{chartItem.valueList}, #{chartItem.valueTimeList},
+            #{chartItem.valueIndexList})
+        </foreach>
+    </insert>
+
+    <insert id="addChartUserGroup">
+        insert into t_chart_user_group (table_id, user_group_id)
+        values
+        <foreach collection="userGroupList" item="userGroup" index="index" separator=",">
+            (#{chartId}, #{userGroup.id})
+        </foreach>
+    </insert>
+
+    <update id="updateChart">
+        update t_data_model
+        set chart_type=#{chartType},
+            value_type=#{valueType},
+            chart_name=#{chartName},
+            value_taking_mode=#{valueTakingMode},
+            bucket_type=#{bucketType},
+            bucket_value=#{bucketValue},
+            start_time=#{startTime},
+            end_time = #{endTime},
+            standby=#{standby}
+        where id = #{id}
+    </update>
+
+    <delete id="delChartById">
+        delete
+        from t_chart
+        where id = #{id}
+    </delete>
+
+    <delete id="delChartUserGroup">
+        delete
+        from t_chart_user_group
+        where chart_id = #{chartId}
+    </delete>
+
+    <delete id="delChartItem">
+        delete
+        from t_chart_item
+        where chart_id = #{chartId}
+    </delete>
+
+    <select id="getChartCount" resultType="java.lang.Long">
+        select count(*)
+        from t_chart
+        where user_id = #{userId}
+    </select>
+
+    <select id="getAllChart" resultType="com.example.opc_common.entity.Chart">
+        select
+        <include refid="chart"/>
+        from t_chart
+        where user_id = #{userId}
+        limit #{startNum},#{limitNum}
+    </select>
+
+    <select id="getChartById" resultType="com.example.opc_common.entity.Chart">
+        select
+        <include refid="chart"/>
+        from t_chart
+        where id = #{id}
+    </select>
+
+    <select id="getChartItemList" resultType="com.example.opc_common.entity.ChartItem">
+        select
+        <include refid="chartItem"/>
+        from t_chart_item
+        where chart_id = #{chartId}
+    </select>
+
+    <select id="getChartByUserGroupId" resultType="com.example.opc_common.entity.Chart">
+        id
+        ,user_id, chart_type, chart_name, value_taking_mode, bucket_type, bucket_value,
+                             start_time, end_time, standby
+        SELECT tc.id,
+               tc.user_id,
+               tc.chart_type,
+               tc.value_type,
+               tc.chart_name,
+               tc.value_taking_mode,
+               tc.bucket_type,
+               tc.bucket_value,
+               tc.start_time,
+               tc.end_time,
+               tc.standby
+        FROM t_chart tc
+                 INNER JOIN (SELECT chart_id FROM t_chart_user_group WHERE user_group_id = #{userGroupId}) tcug
+                            ON trt.id = tcug.chart_id;
+    </select>
+
+    <select id="getAllOkChartCount" resultType="java.lang.Long">
+        select count(a.id) from ((select
+        <include refid="chart"/>
+        from t_chart where user_id=#{userId}
+        <if test="chartType != null">
+            AND chart_type = #{chartType}
+        </if>
+        <if test="chartName != null">
+            AND chart_name LIKE CONCAT('%', #{chartName}, '%')
+        </if>)
+        UNION
+        (select
+        <include refid="chart"/>
+        from t_chart where 1=1
+        <if test="chartType != null">
+            AND chart_type = #{chartType}
+        </if>
+        <if test="chartName != null">
+            AND chart_name LIKE CONCAT('%', #{chartName}, '%')
+        </if>
+        AND id IN (SELECT DISTINCT
+        ( table_id )
+        FROM
+        t_table_user_group
+        WHERE
+        user_group_id IN
+        (SELECT user_group_id FROM t_user_group_user WHERE
+        user_id = #{userId})
+        ))) a
+    </select>
+
+    <select id="getAllOkChart" resultMap="allChart">
+        select
+        tc.id,
+        tc.user_id,
+        su.user_name,
+        tc.chart_type,
+        tc.value_type,
+        tc.chart_name,
+        tc.value_taking_mode,
+        tc.bucket_type,
+        tc.bucket_value,
+        tc.start_time,
+        tc.end_time,
+        tc.standby
+        from (
+        (select
+        <include refid="chart"/>
+        from t_chart where user_id=#{userId}
+        <if test="chartType != null">
+            AND chart_type = #{chartType}
+        </if>
+        <if test="chartName != null">
+            AND chart_name LIKE CONCAT('%', #{chartName}, '%')
+        </if>)
+        UNION
+        (select
+        <include refid="chart"/>
+        from t_chart where 1=1
+        <if test="chartType != null">
+            AND chart_type = #{chartType}
+        </if>
+        <if test="chartName != null">
+            AND chart_name LIKE CONCAT('%', #{chartName}, '%')
+        </if>
+        AND id IN (SELECT DISTINCT
+        ( table_id )
+        FROM
+        t_table_user_group
+        WHERE
+        user_group_id IN
+        (SELECT user_group_id FROM t_user_group_user WHERE
+        user_id = #{userId})
+        ))) tc LEFT JOIN sys_user su ON tc.user_id = su.user_id
+        order by tc.create_time desc
+        limit #{startNum},#{limitNum}
+    </select>
+
+    <resultMap type="com.example.opc_common.entity.Chart" id="allChart">
+        <id property="id" column="id"/>
+        <result property="userId" column="user_id"/>
+        <result property="userName" column="user_name"/>
+        <result property="chartType" column="chart_type"/>
+        <result property="valueType" column="value_type"/>
+        <result property="chartName" column="chart_name"/>
+        <result property="valueTakingMode" column="value_taking_mode"/>
+        <result property="bucketType" column="bucket_type"/>
+        <result property="bucketValue" column="bucket_value"/>
+        <result property="startTime" column="start_time"/>
+        <result property="endTime" column="end_time"/>
+        <result property="standby" column="standby"/>
+        <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>
+
+</mapper>

+ 44 - 8
chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml

@@ -12,6 +12,11 @@
         , item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, data_index, value_belong_time, is_record, create_time
     </sql>
 
+    <sql id="attachRawData">
+        id
+        , item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, create_time
+    </sql>
+
     <insert id="addRawData">
         insert into t_raw_data${remainder}
         (item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, data_index,
@@ -33,6 +38,26 @@
                 #{dataValueTime}, #{dataIndex}, #{valueBelongTime}, #{isRecord}, #{createTime})
     </insert>
 
+    <insert id="addAttachRawData">
+        insert into t_attach_raw_data
+        (item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time,
+         create_time)
+            VALUE (#{itemGroupId}, #{dataSourceId}, #{itemName}, #{dataType},
+            #{orgDataValue}, #{dataValue},
+            #{dataValueTime}, #{createTime})
+    </insert>
+
+    <update id="updateAttachRawData">
+        update t_attach_raw_data
+        set data_type=#{dataType},
+            org_data_value=#{orgDataValue},
+            data_value=#{dataValue},
+            data_value_time=#{dataValueTime}
+        where item_group_id = #{itemGroupId}
+          and data_source_id = #{dataSourceId}
+          and item_name = #{itemName}
+    </update>
+
     <delete id="delCursorRawDataList">
         delete
         from t_raw_data
@@ -236,16 +261,27 @@
     </select>
 
     <select id="getCursorYmdh" resultType="java.lang.String">
-        select
-        value_belong_time
+        select value_belong_time
         from t_raw_data
         WHERE item_group_id = #{itemGroupId}
-        AND data_source_id = #{dataSourceId}
-        AND item_name = (SELECT item_read_name FROM t_item WHERE item_group_id = #{itemGroupId} AND item_name =
-        #{itemName})
-        AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
-        GROUP BY
-        value_belong_time
+          AND data_source_id = #{dataSourceId}
+          AND item_name = (SELECT item_read_name
+                           FROM t_item
+                           WHERE item_group_id = #{itemGroupId}
+                             AND item_name =
+                                 #{itemName})
+          AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
+        GROUP BY value_belong_time
         ORDER BY value_belong_time
     </select>
+
+    <select id="getAttachRawData" resultType="com.example.opc_common.entity.AttachRawData">
+        select
+        <include refid="attachRawData"/>
+        from t_attach_raw_data
+        where item_group_id=#{itemGroupId}
+        and data_source_id=#{dataSourceId}
+        and item_name= (SELECT item_read_name FROM t_item WHERE item_group_id = #{itemGroupId} AND item_name =
+        #{itemName})
+    </select>
 </mapper>

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

@@ -18,4 +18,6 @@ public interface ItemGroupDao {
     Integer stopItemGroupById(Integer id, Integer runState);
 
     List<ItemGroup> getAllItemGroup(String userId);
+
+    List<Item> getBasicItemList(Integer itemGroupId, Integer itemType);
 }

+ 7 - 0
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.AttachRawData;
 import com.example.opc_common.entity.CursorRawData;
 import com.example.opc_common.entity.Item;
 import com.example.opc_common.entity.RawData;
@@ -31,4 +32,10 @@ public interface RawDataDao {
     List<CursorRawData> getEventDataList(Integer itemGroupId, Integer dataSourceId, Integer itemId, List<Long> indexList);
 
     Integer delEventByIndexList(Integer itemGroupId, Integer dataSourceId, Long dataIndex);
+
+    AttachRawData getAttachRawData(AttachRawData attachRawData);
+
+    Integer addAttachRawData(AttachRawData attachRawData);
+
+    Integer updateAttachRawData(AttachRawData attachRawData);
 }

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

@@ -52,6 +52,17 @@ public class OpcAsyncTask {
         }
     }
 
+    public void addAttachRawData(AttachRawData attachRawData) {
+        if (Blank.isNotEmpty(attachRawData)) {
+            AttachRawData attachRawData1 = rawDataDao.getAttachRawData(attachRawData);
+            if (Blank.isEmpty(attachRawData1)) {
+                rawDataDao.addAttachRawData(attachRawData);
+            } else {
+                rawDataDao.updateAttachRawData(attachRawData);
+            }
+        }
+    }
+
     /**
      * 此接口,只有事件驱动任务才会调用,其他地方不调用
      *

+ 130 - 94
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/task/OpcUaTask.java

@@ -1,11 +1,14 @@
 package com.example.opc_ua.task;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 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.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_ua.dao.DataModelDao;
 import com.example.opc_ua.dao.ItemGroupDao;
 import com.example.opc_ua.dao.MessageNoticeDao;
@@ -14,11 +17,15 @@ import com.example.opc_ua.util.OpcUaUtil;
 import com.example.opc_ua.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
+import org.eclipse.milo.opcua.stack.core.types.builtin.*;
+import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
@@ -62,108 +69,137 @@ public class OpcUaTask {
         Date startDate = DateUtil.strYmdhmsChangeDate(startTime);
         Date endDate = DateUtil.strYmdhmsChangeDate(endTime);
 
-        Boolean flage = false;
         //获取组中所有标签的数据模型,并转换为map<itemName,DataModel>
-        List<Item> allItemList = itemGroupDao.getItemListByGroupId(id);
-        itemGroup.setItemList(allItemList);
-        if (Blank.isNotEmpty(allItemList)) {
-            for (Item item : allItemList) {
-                if (Blank.isNotEmpty(item.getDataModelId())) {
-                    flage = true;
-                    break;
+        List<Item> basicItemList = itemGroupDao.getBasicItemList(id, ConstantStr.BASIC_ATTRIBUTES);
+        List<DataModel> dmBasicItemList = dataModelDao.getDmListByItemList(basicItemList);
+        Map<String, DataModel> basicMap = DataModel.genMap(basicItemList, dmBasicItemList);
+
+        if (Blank.isNotEmpty(basicItemList)) {
+            Timer timer = new Timer();
+            OpcUaClient opcUaClient = null;
+            try {
+                opcUaClient = OpcUaUtil.createClient(dataSource);
+                opcUaClient.connect().get();
+            } catch (Exception e) {
+                messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
+                        itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
+                        OpcUaUtil.genException(e.getMessage()),
+                        ConstantStr.NO_READ));
+
+                itemGroupDao.stopItemGroupById(id, ConstantStr.EXCEPT_STOP_UP);
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
                 }
+                if (Blank.isNotEmpty(timer)) {
+                    timer.cancel();
+                }
+                cronTaskRegister.removeCronTask(cronId);
+            }
+            if (readMode == ConstantStr.ON_FREQUENCY) {
+                timer.schedule(new OpcUaFrequencyTask(
+                                redisUtil,
+                                opcAsyncTask,
+                                cronId,
+                                cronTaskRegister,
+                                itemGroupDao,
+                                messageNoticeDao,
+                                opcUaClient,
+                                basicItemList,
+                                basicMap,
+                                itemGroup,
+                                dataSource,
+                                timer,
+                                timeFormat,
+                                endDate.getTime()),
+                        startDate, (int) (Math.round(itemGroup.getModeValue() * 1000)));
+            } else if (readMode == ConstantStr.ON_CHANGE) {
+                timer.schedule(new OpcUaChangeTask(
+                                redisUtil,
+                                opcAsyncTask,
+                                cronId,
+                                cronTaskRegister,
+                                itemGroupDao,
+                                messageNoticeDao,
+                                opcUaClient,
+                                basicItemList,
+                                basicMap,
+                                itemGroup,
+                                dataSource,
+                                timer,
+                                timeFormat,
+                                endDate.getTime()),
+                        startDate, 500);
+            } else if (readMode == ConstantStr.EXCEED_SET_VALUE) {
+                timer.schedule(new OpcUaExceedTask(redisUtil,
+                                opcAsyncTask,
+                                cronId,
+                                cronTaskRegister,
+                                itemGroupDao,
+                                messageNoticeDao,
+                                opcUaClient,
+                                basicItemList,
+                                basicMap,
+                                itemGroup,
+                                dataSource,
+                                timer,
+                                timeFormat,
+                                endDate.getTime()),
+                        startDate, 500);
+            } else {
+                cronTaskRegister.removeCronTask(cronId);
+                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种采样模式");
             }
         }
-        Map<String, DataModel> map = new HashMap<>();
-        if (flage) {
-            List<DataModel> dmListByItemList = dataModelDao.getDmListByItemList(allItemList);
-            if (Blank.isNotEmpty(dmListByItemList)) {
-                for (int i = 0; i < allItemList.size(); i++) {
-                    for (DataModel dm : dmListByItemList) {
-                        if (dm.getId().equals(allItemList.get(i).getDataModelId())) {
-                            map.put(allItemList.get(i).getItemReadName(), dm);
-                            break;
+        List<Item> attachItemList = itemGroupDao.getBasicItemList(id, ConstantStr.ATTACH_ATTRIBUTES);
+        List<DataModel> dmAttachItemList = dataModelDao.getDmListByItemList(attachItemList);
+        Map<String, DataModel> attachMap = DataModel.genMap(attachItemList, dmAttachItemList);
+        if (Blank.isNotEmpty(attachItemList)) {
+            OpcUaClient opcUaClient = null;
+            try {
+                opcUaClient = OpcUaUtil.createClient(dataSource);
+                opcUaClient.connect().get();
+                for (Item item : attachItemList) {
+                    NodeId n = new NodeId(item.getNodeIndex(), item.getItemReadName());
+                    String itemName = item.getItemReadName();
+                    DataModel dm = attachMap.get(itemName);
+                    JSONObject jsonObject = new JSONObject();
+                    DataValue dataValue = opcUaClient.readValue(0.0, TimestampsToReturn.Both, n).get();
+                    StatusCode statusCode = dataValue.getStatusCode();
+                    jsonObject.put("quality", statusCode.isGood());
+                    Object value = dataValue.getValue().getValue();
+                    Date time = dataValue.getServerTime().getJavaDate();
+                    String javaType = OpcUaUtil.getValType(dataValue);
+                    jsonObject.put("dataType", javaType);
+                    if (javaType.toLowerCase().equals("boolean")) {
+                        AttachRawData attachRawData = new AttachRawData(
+                                id, dataSource.getId(), itemName, javaType, value.toString(), value.toString(), DateUtil.dateChangeStrYmdhmss(time), new Date()
+                        );
+                        opcAsyncTask.addAttachRawData(attachRawData);
+                    } else {
+                        try {
+                            BigDecimal bigDecimal = JSON.parseObject(value.toString(), BigDecimal.class);
+                            AttachRawData attachRawData = new AttachRawData(
+                                    id, dataSource.getId(), itemName, javaType, bigDecimal.toString(),
+                                    (Blank.isNotEmpty(dm) ? MathUtil.quadricOperation(dm.getMathParameter(), dm.getOperationRule(), bigDecimal) : bigDecimal).toString(),
+                                    DateUtil.dateChangeStrYmdhmss(time), new Date()
+                            );
+                            opcAsyncTask.addAttachRawData(attachRawData);
+                        } catch (Exception e) {
+                            AttachRawData attachRawData = new AttachRawData(
+                                    id, dataSource.getId(), itemName, javaType, value.toString(), value.toString(), DateUtil.dateChangeStrYmdhmss(time), new Date()
+                            );
+                            opcAsyncTask.addAttachRawData(attachRawData);
                         }
                     }
                 }
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
+            } finally {
+                if (Blank.isNotEmpty(opcUaClient)) {
+                    opcUaClient.disconnect();
+                }
             }
         }
-
-        List<Item> itemList = itemGroupDao.getItemListByGroupId(id);
-        OpcUaClient opcUaClient = null;
-        Timer timer = new Timer();
-        try {
-            opcUaClient = OpcUaUtil.createClient(dataSource);
-            opcUaClient.connect().get();
-        } catch (Exception e) {
-            messageNoticeDao.addMessageNotice(new MessageNotice(itemGroup.getUserId(),
-                    itemGroup.getGroupName() + DateUtil.dateChangeStrYmdhms(new Date()) + "运行停止",
-                    OpcUaUtil.genException(e.getMessage()),
-                    ConstantStr.NO_READ));
-
-            itemGroupDao.stopItemGroupById(id, ConstantStr.EXCEPT_STOP_UP);
-            if (Blank.isNotEmpty(opcUaClient)) {
-                opcUaClient.disconnect();
-            }
-            if (Blank.isNotEmpty(timer)) {
-                timer.cancel();
-            }
-            cronTaskRegister.removeCronTask(cronId);
-        }
-        if (readMode == ConstantStr.ON_FREQUENCY) {
-            timer.schedule(new OpcUaFrequencyTask(
-                            redisUtil,
-                            opcAsyncTask,
-                            cronId,
-                            cronTaskRegister,
-                            itemGroupDao,
-                            messageNoticeDao,
-                            opcUaClient,
-                            itemList,
-                            map,
-                            itemGroup,
-                            dataSource,
-                            timer,
-                            timeFormat,
-                            endDate.getTime()),
-                    startDate, (int) (Math.round(itemGroup.getModeValue() * 1000)));
-        } else if (readMode == ConstantStr.ON_CHANGE) {
-            timer.schedule(new OpcUaChangeTask(
-                            redisUtil,
-                            opcAsyncTask,
-                            cronId,
-                            cronTaskRegister,
-                            itemGroupDao,
-                            messageNoticeDao,
-                            opcUaClient,
-                            itemList,
-                            map,
-                            itemGroup,
-                            dataSource,
-                            timer,
-                            timeFormat,
-                            endDate.getTime()),
-                    startDate, 500);
-        } else if (readMode == ConstantStr.EXCEED_SET_VALUE) {
-            timer.schedule(new OpcUaExceedTask(redisUtil,
-                            opcAsyncTask,
-                            cronId,
-                            cronTaskRegister,
-                            itemGroupDao,
-                            messageNoticeDao,
-                            opcUaClient,
-                            itemList,
-                            map,
-                            itemGroup,
-                            dataSource,
-                            timer,
-                            timeFormat,
-                            endDate.getTime()),
-                    startDate, 500);
-        } else {
-            cronTaskRegister.removeCronTask(cronId);
-            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种采样模式");
-        }
-
     }
 }

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

@@ -38,6 +38,25 @@
         </if>
     </select>
 
+    <select id="getBasicItemList" resultType="com.example.opc_common.entity.Item">
+        select ti.id,
+               ti.item_group_id,
+               ti.item_name,
+               ti.item_read_name,
+               ti.item_type,
+               ti.node_index,
+               ti.data_type,
+               ti.`describe`,
+               ti.data_model_id,
+               ti.is_driver_item,
+               tdm.operation_rule
+        FROM t_item ti
+                 LEFT JOIN t_data_model tdm ON ti.data_model_id = tdm.id
+        where ti.item_group_id = #{itemGroupId}
+          and ti.item_type = #{itemType}
+        order by is_driver_item DESC, item_name
+    </select>
+
     <update id="runItemGroupById">
         update t_item_group
         set run_state=#{runState},

+ 34 - 0
chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml

@@ -12,6 +12,11 @@
         , item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, data_index, value_belong_time, is_record, create_time
     </sql>
 
+    <sql id="attachRawData">
+        id
+        , item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, create_time
+    </sql>
+
     <insert id="addRawData">
         insert into t_raw_data${remainder}
         (item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time, data_index,
@@ -33,6 +38,26 @@
                 #{dataValueTime}, #{dataIndex}, #{valueBelongTime}, #{isRecord}, #{createTime})
     </insert>
 
+    <insert id="addAttachRawData">
+        insert into t_attach_raw_data
+        (item_group_id, data_source_id, item_name, data_type, org_data_value, data_value, data_value_time,
+         create_time)
+            VALUE (#{itemGroupId}, #{dataSourceId}, #{itemName}, #{dataType},
+            #{orgDataValue}, #{dataValue},
+            #{dataValueTime}, #{createTime})
+    </insert>
+
+    <update id="updateAttachRawData">
+        update t_attach_raw_data
+        set data_type=#{dataType},
+            org_data_value=#{orgDataValue},
+            data_value=#{dataValue},
+            data_value_time=#{dataValueTime}
+        where item_group_id = #{itemGroupId}
+          and data_source_id = #{dataSourceId}
+          and item_name = #{itemName}
+    </update>
+
     <delete id="delEventRawDataList">
         delete
         from t_event_raw_data
@@ -152,4 +177,13 @@
         </if>
     </select>
 
+    <select id="getAttachRawData" resultType="com.example.opc_common.entity.AttachRawData">
+        select
+        <include refid="attachRawData"/>
+        from t_attach_raw_data
+        where item_group_id=#{itemGroupId}
+        and data_source_id=#{dataSourceId}
+        and item_name=#{itemName}
+    </select>
+
 </mapper>