Эх сурвалжийг харах

优化自动报表获取实时数据接口,使用索引的方式。优化自动报表生成时获取数据接口,使用索引的方式。优化手机端统计图和数据项查询接口,使用索引的方式。修改报表中,主报表如果在没启动的情况下,不获取实时数据

zhoupeng 1 жил өмнө
parent
commit
e5dcabcda0

+ 5 - 3
cqcy-ei/cqcy-ei-common/src/main/java/com/example/opc_common/entity/ChartItem.java

@@ -26,20 +26,22 @@ public class ChartItem implements Serializable {
     private Integer itemId;
     //虚拟字段,数据项名称
     private String itemName;
+    //虚拟字段,数据项名称
+    private String itemReadName;
     //虚拟字段数据项描述
     private String describe;
     /**
      * 结果集
      */
-    List<BigDecimal> valueList=new ArrayList<>();
+    List<BigDecimal> valueList = new ArrayList<>();
     /**
      * 结果集对应的时间
      */
-    List<String> valueTimeList=new ArrayList<>();
+    List<String> valueTimeList = new ArrayList<>();
     /**
      * 结果集对应的索引
      */
-    List<Long> valueIndexList=new ArrayList<>();
+    List<Long> valueIndexList = new ArrayList<>();
 
 
 }

+ 10 - 1
cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/dao/RawDataDao.java

@@ -47,6 +47,8 @@ public interface RawDataDao {
 
     List<CursorRawData> getTableCursorData(Integer itemGroupId, Integer dataSourceId, String itemName, String sqlCurrentYmdh);
 
+    List<CursorRawData> getTableCursorData1(Integer itemGroupId, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
+
     List<String> getCursorYmdh(Integer itemGroupId, Integer dataSourceId, String itemName, String startBelongTime, String endBelongTime);
 
     AttachRawData getAttachRawData(Integer itemGroupId, Integer dataSourceId, String itemName);
@@ -67,16 +69,23 @@ public interface RawDataDao {
 
     List<RawData> getTableChartDataGroupByDay(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<TableTemplateChartItem> tableTemplateChartItemList, String startBelongTime, String endBelongTime);
 
+    List<RawData> getTableChartDataByDay(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<ChartItem> chartItemList, String startBelongTime, String endBelongTime);
+
     List<CursorRawData> getTableCursorDataGroupByDay(Integer itemGroupId, Integer dataSourceId, List<TableTemplateTableItem> tableTemplateItemList, String startBelongTime, String endBelongTime);
 
     List<CursorRawData> getTableChartCursorDataGroupByDay(Integer itemGroupId, Integer dataSourceId, List<TableTemplateChartItem> tableTemplateChartItemList, String startBelongTime, String endBelongTime);
 
+    List<CursorRawData> getTableChartCursorDataByDay(Integer itemGroupId, Integer dataSourceId, List<ChartItem> chartItemList, String startBelongTime, String endBelongTime);
+
     List<RawData> getTableDataGroup(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<TableTemplateTableItem> tableTemplateItemList, String startBelongTime, String endBelongTime);
 
     List<RawData> getTableChartDataGroup(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<TableTemplateChartItem> tableTemplateChartItemList, String startBelongTime, String endBelongTime);
 
+    List<RawData> getTableChartData(Integer itemGroupId, Integer remainder, Integer dataSourceId, List<ChartItem> chartItemList, String startBelongTime, String endBelongTime);
+
     List<CursorRawData> getTableCursorDataGroup(Integer itemGroupId, Integer dataSourceId, List<TableTemplateTableItem> tableTemplateItemList, String startBelongTime, String endBelongTime);
 
     List<CursorRawData> getTableChartCursorDataGroup(Integer itemGroupId, Integer dataSourceId, List<TableTemplateChartItem> tableTemplateChartItemList, String startBelongTime, String endBelongTime);
 
-    }
+    List<CursorRawData> getTableChartCursorData(Integer itemGroupId, Integer dataSourceId, List<ChartItem> chartItemList, String startBelongTime, String endBelongTime);
+}

+ 73 - 63
cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/service/impl/ChartServiceImpl.java

@@ -19,10 +19,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Service
 @Transactional
@@ -115,82 +112,95 @@ public class ChartServiceImpl implements ChartService {
                 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;
-                }
-                long startTimeTime = startTime.getTime();
-                long endTimeTime;
-                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);
+            ChartItem chartItem0 = chartItemList.get(0);
+            Integer itemId = chartItem0.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 startBelongTime;
+            String endBelongTime;
+            List<RawData> rawDataList = new ArrayList<>();
+            List<CursorRawData> cursorRawDataList = 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.getTableChartDataByDay(itemGroupId, remainder, dataSourceId, chartItemList, startBelongTime, endBelongTime);
+                cursorRawDataList = rawDataDao.getTableChartCursorDataByDay(itemGroupId, dataSourceId, chartItemList, 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.getTableChartData(itemGroupId, remainder, dataSourceId, chartItemList, startBelongTime, endBelongTime);
+                cursorRawDataList = rawDataDao.getTableChartCursorData(itemGroupId, dataSourceId, chartItemList, startBelongTime, endBelongTime);
+            }
+            for (ChartItem chartItem : chartItemList) {
+                Integer itemGroupId1 = chartItem.getItemGroupId();
+                String itemReadName = chartItem.getItemReadName();
+                List<RawData> currentRawDataList = new ArrayList<>();
+                List<CursorRawData> currentCursorRawDataList = new ArrayList<>();
+                for (int i = 0; i < rawDataList.size(); i++) {
+                    RawData rawData = rawDataList.get(i);
+                    if (rawData.getItemGroupId().equals(itemGroupId1)
+                            && rawData.getItemName().equals(itemReadName)) {
+                        currentRawDataList.add(rawData);
+                        rawDataList.remove(i);
+                        i--;
+                    }
                 }
-                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);
+                for (int i = 0; i < cursorRawDataList.size(); i++) {
+                    CursorRawData cursorRawData = cursorRawDataList.get(i);
+                    //生成临时数据
+                    if (cursorRawData.getItemGroupId().equals(itemGroupId1)
+                            && cursorRawData.getItemName().equals(itemReadName)) {
+                        currentCursorRawDataList.add(cursorRawData);
+                        cursorRawDataList.remove(i);
+                        i--;
                     }
                 }
+                //将所有数据组合成一个List<CursorRawData>
+                currentCursorRawDataList.addAll(ReportTask.genRawChangeCursor(currentRawDataList));
+                //对currentCursorRawDataList进行排序,使用dataValueTime排序
+                Collections.sort(currentCursorRawDataList, new Comparator<CursorRawData>() {
+                    @Override
+                    public int compare(CursorRawData o1, CursorRawData o2) {
+                        return o1.getDataValueTime().compareTo(o2.getDataValueTime());
+                    }
+                });
+                long startTimeTime = startTime.getTime();
+                long endTimeTime;
                 //如果查询出来有数据
-                if (Blank.isNotEmpty(rawDataList)) {
-                    String dataType = rawDataList.get(0).getDataType();
+                if (Blank.isNotEmpty(currentCursorRawDataList)) {
+                    String dataType = currentCursorRawDataList.get(0).getDataType();
                     if (!dataType.toLowerCase().equals("boolean")) {
                         try {
-                            List<BigDecimal> orgRawList = new ArrayList<>();
-                            List<BigDecimal> rawList = new ArrayList<>();
-                            List<String> rawTimeList = new ArrayList<>();
-                            for (int j = 0; j < rawDataList.size(); j++) {
-                                RawData rawData = rawDataList.get(j);
-                                orgRawList.addAll(new ArrayList<>(Arrays.asList(JSON.parseObject(rawData.getOrgDataValue(), BigDecimal[].class))));
-                                rawList.addAll(new ArrayList<>(Arrays.asList(JSON.parseObject(rawData.getDataValue(), BigDecimal[].class))));
-                                rawTimeList.addAll(new ArrayList<>(Arrays.asList(JSON.parseObject(rawData.getDataValueTime(), String[].class))));
-                            }
                             List<BigDecimal> orgValueList = new ArrayList<>();
                             List<BigDecimal> valueList = new ArrayList<>();
                             List<String> valueTimeList = new ArrayList<>();
                             List<Long> valueIndexList = new ArrayList<>();
-                            for (int j = 0; j < timeLength; j++) {
+                            for (int i = 0; i < timeLength; i++) {
                                 List<BigDecimal> orgList = new ArrayList<>();
                                 List<BigDecimal> list = new ArrayList<>();
-                                if (j != timeLength - 1) {
+                                if (i != timeLength - 1) {
                                     endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
                                 } else {
                                     endTimeTime = endTime.getTime();
                                 }
-                                for (int k = 0; k < rawTimeList.size(); k++) {
-                                    long time = DateUtil.strYmdhmssChangeDate(rawTimeList.get(k)).getTime();
+                                for (int j = 0; j < currentCursorRawDataList.size(); j++) {
+                                    CursorRawData cursorRawData = currentCursorRawDataList.get(j);
+                                    long time = DateUtil.strYmdhmssChangeDate(cursorRawData.getDataValueTime()).getTime();
                                     if (startTimeTime > time) {
-                                        rawTimeList.remove(k);
-                                        orgRawList.remove(k);
-                                        rawList.remove(k);
-                                        k--;
+
                                         continue;
                                     }
                                     if (startTimeTime <= time && time < endTimeTime) {
-                                        orgList.add(orgRawList.get(k));
-                                        list.add(rawList.get(k));
-                                        rawTimeList.remove(k);
-                                        orgRawList.remove(k);
-                                        rawList.remove(k);
-                                        k--;
+                                        orgList.add(JSON.parseObject(cursorRawData.getOrgDataValue(), BigDecimal.class));
+                                        list.add(JSON.parseObject(cursorRawData.getDataValue(), BigDecimal.class));
                                     }
+                                    currentCursorRawDataList.remove(j);
+                                    j--;
                                     if (time >= endTimeTime) {
                                         break;
                                     }
@@ -198,7 +208,7 @@ public class ChartServiceImpl implements ChartService {
                                 orgValueList.add(ReportTask.genBigDecimalValue(orgList, valueTakingMode));
                                 valueList.add(ReportTask.genBigDecimalValue(list, valueTakingMode));
                                 valueTimeList.add(DateUtil.dateChangeStrYmdhmss(new Date(startTimeTime)));
-                                valueIndexList.add(((long) j));
+                                valueIndexList.add(((long) i));
                                 startTimeTime = endTimeTime;
                                 orgList = new ArrayList<>();
                                 list = new ArrayList<>();
@@ -216,10 +226,10 @@ public class ChartServiceImpl implements ChartService {
                     List<BigDecimal> valueList = new ArrayList<>();
                     List<String> valueTimeList = new ArrayList<>();
                     List<Long> valueIndexList = new ArrayList<>();
-                    for (int j = 0; j < timeLength; j++) {
+                    for (int i = 0; i < timeLength; i++) {
                         List<BigDecimal> orgList = new ArrayList<>();
                         List<BigDecimal> list = new ArrayList<>();
-                        if (j != timeLength - 1) {
+                        if (i != timeLength - 1) {
                             endTimeTime = DateUtil.addTimeStamp(startTimeTime, pattern, bucketValue);
                         } else {
                             endTimeTime = endTime.getTime();
@@ -227,7 +237,7 @@ public class ChartServiceImpl implements ChartService {
                         orgValueList.add(ReportTask.genBigDecimalValue(orgList, valueTakingMode));
                         valueList.add(ReportTask.genBigDecimalValue(list, valueTakingMode));
                         valueTimeList.add(DateUtil.dateChangeStrYmdhmss(new Date(startTimeTime)));
-                        valueIndexList.add(((long) j));
+                        valueIndexList.add(((long) i));
                         startTimeTime = endTimeTime;
                         orgList = new ArrayList<>();
                         list = new ArrayList<>();

+ 25 - 27
cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -25,10 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 @Service
 @Transactional
@@ -515,16 +512,22 @@ public class ItemGroupServiceImpl implements ItemGroupService {
         if (itemType.equals(ConstantStr.BASIC_ATTRIBUTES)) {
             String startBelongTime = startTime.substring(0, ConstantStr.TIME_HOUR_STR.length());
             String endBelongTime = endTime.substring(0, ConstantStr.TIME_HOUR_STR.length());
+            //得到历史表中打得数据
             List<RawData> 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);
+            //得到临时表中的数据
+            List<CursorRawData> cursorRawDataList = rawDataDao.getTableCursorData1(itemGroupId, dataSourceId, itemName, startBelongTime, endBelongTime);
+            //将所有数据组合成一个List<CursorRawData>
+            cursorRawDataList.addAll(ReportTask.genRawChangeCursor(rawDataList));
+            //对cursorRawDataList进行排序,使用dataValueTime排序
+            Collections.sort(cursorRawDataList, new Comparator<CursorRawData>() {
+                @Override
+                public int compare(CursorRawData o1, CursorRawData o2) {
+                    return o1.getDataValueTime().compareTo(o2.getDataValueTime());
                 }
-            }
-            if (Blank.isNotEmpty(rawDataList)) {
-                String dataType = rawDataList.get(0).getDataType();
+            });
+
+            if (Blank.isNotEmpty(cursorRawDataList)) {
+                String dataType = cursorRawDataList.get(0).getDataType();
                 if (dataType.toLowerCase().equals("boolean")) {
                     Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据项数据类型为boolean类型,不支持,请重新选择数据项");
                 } else {
@@ -534,21 +537,16 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                         List<String> rawTimeList = new ArrayList<>();
                         long startTimeTime = DateUtil.strYmdhmsChangeDate(startTime).getTime();
                         long endTimeTime = DateUtil.strYmdhmsChangeDate(endTime).getTime();
-                        for (int i = 0; i < rawDataList.size(); i++) {
-                            RawData rawData = rawDataList.get(i);
-                            BigDecimal[] orgDataValue = JSON.parseObject(rawData.getOrgDataValue(), BigDecimal[].class);
-                            BigDecimal[] dataValue = JSON.parseObject(rawData.getDataValue(), BigDecimal[].class);
-                            String[] dataValueTime = JSON.parseObject(rawData.getDataValueTime(), String[].class);
-                            for (int j = 0; j < dataValueTime.length; j++) {
-                                long time = DateUtil.strYmdhmssChangeDate(dataValueTime[j]).getTime();
-                                if (endTimeTime < time) {
-                                    break;
-                                }
-                                if (startTimeTime <= time) {
-                                    orgRawList.add(orgDataValue[j]);
-                                    rawList.add(dataValue[j]);
-                                    rawTimeList.add(dataValueTime[j]);
-                                }
+                        for (int i = 0; i < cursorRawDataList.size(); i++) {
+                            CursorRawData cursorRawData = cursorRawDataList.get(i);
+                            long time = DateUtil.strYmdhmssChangeDate(cursorRawData.getDataValueTime()).getTime();
+                            if (startTimeTime <= time && time < endTimeTime) {
+                                orgRawList.add(JSON.parseObject(cursorRawData.getOrgDataValue(), BigDecimal.class));
+                                rawList.add(JSON.parseObject(cursorRawData.getDataValue(), BigDecimal.class));
+                                rawTimeList.add(cursorRawData.getDataValueTime());
+                            }
+                            if (time >= endTimeTime) {
+                                break;
                             }
                         }
                         JSONObject jsonObject = new JSONObject();

+ 18 - 0
cqcy-ei/cqcy-ei-da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java

@@ -293,6 +293,12 @@ public class ReportTableServiceImpl implements ReportTableService {
         return Result.ok(jsonObject);
     }
 
+    /**
+     * 主报表如果没有启动,则没有数据
+     *
+     * @param id
+     * @return
+     */
     @Override
     public Result getReportTableById(String id) {
         //如果是子表,则reportTableData使用主表的,生成子表时不生成reportTableData
@@ -309,6 +315,10 @@ public class ReportTableServiceImpl implements ReportTableService {
             return Result.ok(reportTableTask.getManualReport(reportTable));
             //如果是自动报表主表
         } else if (reportTableType.equals(ConstantStr.AUTOMATIC_REPORT)) {
+            Integer runState = reportTable.getRunState();
+            if (!runState.equals(ConstantStr.START_UP)) {
+                return Result.ok(reportTable);
+            }
             return Result.ok(reportTableTask.getAutoReport(reportTable));
             //如果是自动报表子表
         } else if (reportTableType.equals(ConstantStr.AUTOMATIC_GENERATE_REPORT)) {
@@ -329,6 +339,10 @@ public class ReportTableServiceImpl implements ReportTableService {
             return Result.ok(reportTable);
             //如果是事件驱动报表主表
         } else if (reportTableType.equals(ConstantStr.EVENT_DRIVEN_REPORT)) {
+            Integer runState = reportTable.getRunState();
+            if (!runState.equals(ConstantStr.START_UP)) {
+                return Result.ok(reportTable);
+            }
             Integer tableTemplateId = reportTable.getTableTemplateId();
             List<TableTemplateTableItem> tttItemList = reportTableDao.getTttiByTemplateId(tableTemplateId);
             List<ReportTableItem> reportTableItemList = new ArrayList<>();
@@ -360,6 +374,10 @@ public class ReportTableServiceImpl implements ReportTableService {
             return Result.ok(reportTable);
             //如果是设备报表主表
         } else if (reportTableType.equals(ConstantStr.DEVICE_REPORT)) {
+            Integer runState = reportTable.getRunState();
+            if (!runState.equals(ConstantStr.START_UP)) {
+                return Result.ok(reportTable);
+            }
             Integer tableTemplateId = reportTable.getTableTemplateId();
             Object o = redisUtil.get(ConstantStr.TABLE_ID + tableTemplateId);
             if (Blank.isNotEmpty(o)) {

+ 1 - 0
cqcy-ei/cqcy-ei-da/src/main/resources/mapper/ChartDao.xml

@@ -96,6 +96,7 @@
              , tci.item_id
              , ti.item_group_id
              , ti.item_name
+             , ti.item_read_name
              , ti.describe
         from t_chart_item tci
                  left join t_item ti on tci.item_id = ti.id

+ 101 - 41
cqcy-ei/cqcy-ei-da/src/main/resources/mapper/RawDataDao.xml

@@ -227,28 +227,41 @@
     </select>
 
     <select id="getTableDataGroup" resultType="com.example.opc_common.entity.RawData">
+        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator=" UNION ALL ">
+            select
+            <include refid="rawData"/>
+            from t_raw_data${remainder}
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name =#{tableTemplateItem.itemReadName}
+        </foreach>
+        AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
+        ORDER BY value_belong_time
+    </select>
+
+    <select id="getTableChartDataGroup" resultType="com.example.opc_common.entity.RawData">
         select
         <include refid="rawData"/>
         from t_raw_data${remainder}
         WHERE item_group_id = #{itemGroupId}
         AND data_source_id = #{dataSourceId}
         AND item_name IN
-        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator="," open="(" close=")">
-            #{tableTemplateItem.itemReadName}
+        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator="," open="(" close=")">
+            #{tableTemplateChartItem.itemReadName}
         </foreach>
         AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY value_belong_time
     </select>
 
-    <select id="getTableChartDataGroup" resultType="com.example.opc_common.entity.RawData">
+    <select id="getTableChartData" resultType="com.example.opc_common.entity.RawData">
         select
         <include refid="rawData"/>
         from t_raw_data${remainder}
         WHERE item_group_id = #{itemGroupId}
         AND data_source_id = #{dataSourceId}
         AND item_name IN
-        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator="," open="(" close=")">
-            #{tableTemplateChartItem.itemReadName}
+        <foreach collection="chartItemList" item="chartItem" separator="," open="(" close=")">
+            #{chartItem.itemReadName}
         </foreach>
         AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY value_belong_time
@@ -267,56 +280,78 @@
     </select>
 
     <select id="getTableDataGroupByDay" resultType="com.example.opc_common.entity.RawData">
-        select
-        <include refid="rawData"/>
-        from t_raw_data${remainder}
-        WHERE item_group_id = #{itemGroupId}
-        AND data_source_id = #{dataSourceId}
-        AND item_name IN
-        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator="," open="(" close=")">
-            #{tableTemplateItem.itemReadName}
+        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator=" UNION ALL ">
+            select
+            <include refid="rawData"/>
+            from t_raw_data${remainder}
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name =#{tableTemplateItem.itemReadName}
         </foreach>
         AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY value_belong_time
     </select>
 
     <select id="getTableChartDataGroupByDay" resultType="com.example.opc_common.entity.RawData">
-        select
-        <include refid="rawData"/>
-        from t_raw_data${remainder}
-        WHERE item_group_id = #{itemGroupId}
-        AND data_source_id = #{dataSourceId}
-        AND item_name IN
-        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator="," open="(" close=")">
-            #{tableTemplateChartItem.itemReadName}
+        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator=" UNION ALL ">
+            select
+            <include refid="rawData"/>
+            from t_raw_data${remainder}
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name = #{tableTemplateChartItem.itemReadName}
+        </foreach>
+        AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
+        ORDER BY value_belong_time
+    </select>
+
+    <select id="getTableChartDataByDay" resultType="com.example.opc_common.entity.RawData">
+        <foreach collection="chartItemList" item="chartItem" separator=" UNION ALL ">
+            select
+            <include refid="rawData"/>
+            from t_raw_data${remainder}
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name = #{chartItem.itemReadName}
         </foreach>
         AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY value_belong_time
     </select>
 
     <select id="getTableCursorDataGroupByDay" resultType="com.example.opc_common.entity.CursorRawData">
-        select
-        <include refid="cursorRawData"/>
-        from t_raw_data
-        WHERE item_group_id = #{itemGroupId}
-        AND data_source_id = #{dataSourceId}
-        AND item_name IN
-        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator="," open="(" close=")">
-            #{tableTemplateItem.itemReadName}
+        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator=" UNION ALL ">
+            select
+            <include refid="cursorRawData"/>
+            from t_raw_data
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name = #{tableTemplateItem.itemReadName}
         </foreach>
         AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY data_index
     </select>
 
     <select id="getTableChartCursorDataGroupByDay" resultType="com.example.opc_common.entity.CursorRawData">
-        select
-        <include refid="cursorRawData"/>
-        from t_raw_data
-        WHERE item_group_id = #{itemGroupId}
-        AND data_source_id = #{dataSourceId}
-        AND item_name IN
-        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator="," open="(" close=")">
-            #{tableTemplateChartItem.itemReadName}
+        <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator=" UNION ALL ">
+            select
+            <include refid="cursorRawData"/>
+            from t_raw_data
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name = #{tableTemplateChartItem.itemReadName}
+        </foreach>
+        AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
+        ORDER BY data_index
+    </select>
+
+    <select id="getTableChartCursorDataByDay" resultType="com.example.opc_common.entity.CursorRawData">
+        <foreach collection="chartItemList" item="chartItem" separator=" UNION ALL ">
+            select
+            <include refid="cursorRawData"/>
+            from t_raw_data
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name = #{chartItem.itemReadName}
         </foreach>
         AND DATE_FORMAT(value_belong_time,'%Y-%m-%d') BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY data_index
@@ -350,15 +385,26 @@
         ORDER BY data_index
     </select>
 
-    <select id="getTableCursorDataGroup" resultType="com.example.opc_common.entity.CursorRawData">
+    <select id="getTableCursorData1" resultType="com.example.opc_common.entity.CursorRawData">
         select
         <include refid="cursorRawData"/>
         from t_raw_data
         WHERE item_group_id = #{itemGroupId}
         AND data_source_id = #{dataSourceId}
-        AND item_name IN
-        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator="," open="(" close=")">
-            #{tableTemplateItem.itemReadName}
+        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}
+        ORDER BY value_belong_time
+    </select>
+
+    <select id="getTableCursorDataGroup" resultType="com.example.opc_common.entity.CursorRawData">
+        <foreach collection="tableTemplateItemList" item="tableTemplateItem" separator=" UNION ALL ">
+            select
+            <include refid="cursorRawData"/>
+            from t_raw_data
+            WHERE item_group_id = #{itemGroupId}
+            AND data_source_id = #{dataSourceId}
+            AND item_name=#{tableTemplateItem.itemReadName}
         </foreach>
         AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
         ORDER BY data_index
@@ -378,6 +424,20 @@
         ORDER BY data_index
     </select>
 
+    <select id="getTableChartCursorData" resultType="com.example.opc_common.entity.CursorRawData">
+        select
+        <include refid="cursorRawData"/>
+        from t_raw_data
+        WHERE item_group_id = #{itemGroupId}
+        AND data_source_id = #{dataSourceId}
+        AND item_name IN
+        <foreach collection="chartItemList" item="chartItem" separator="," open="(" close=")">
+            #{chartItem.itemReadName}
+        </foreach>
+        AND value_belong_time BETWEEN #{startBelongTime} AND #{endBelongTime}
+        ORDER BY data_index
+    </select>
+
     <select id="getCursorYmdh" resultType="java.lang.String">
         select value_belong_time
         from t_raw_data