瀏覽代碼

Merge branch 'master' of http://116.63.33.55/git/industry-data-platform

lry 1 年之前
父節點
當前提交
b080f94bb5
共有 29 個文件被更改,包括 1011 次插入191 次删除
  1. 9 0
      industry-system/industry-da/src/main/java/com/example/opc_da/config/SpringContextUtils.java
  2. 1 1
      industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportDataPolicyTask.java
  3. 2 96
      industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportTableTask.java
  4. 5 84
      industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java
  5. 2 2
      industry-system/industry-da/src/main/java/com/example/opc_da/task/AsyncTask.java
  6. 26 0
      industry-system/industry-da/src/main/java/com/example/opc_da/task/ReportTableBasicItemEnum.java
  7. 17 5
      industry-system/industry-da/src/main/java/com/example/opc_da/task/ReportTableTask.java
  8. 14 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticChReportTableValidate.java
  9. 13 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticMaReportTableValidate.java
  10. 649 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticReportTableValidate.java
  11. 13 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceChReportTableValidate.java
  12. 13 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceMaReportTableValidate.java
  13. 7 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceReportTableValidate.java
  14. 64 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventChReportTableValidate.java
  15. 37 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventMaReportTableValidate.java
  16. 72 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventReportTableValidate.java
  17. 13 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ManualReportTableValidate.java
  18. 18 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ReportTableValidate.java
  19. 33 0
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ReportTableValidateFactory.java
  20. 1 1
      industry-system/industry-da/src/main/resources/static/page/index.html
  21. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/app.30c89522.js
  22. 1 1
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d0bd283.72cc391d.js
  23. 1 1
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d213e6a.6727e252.js
  24. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2ff9c2aa.4a8669e4.js
  25. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-3c7280bc.326bb34f.js
  26. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-49846205.dcbc3206.js
  27. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-7cd04953.f26dc502.js
  28. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-844beabe.3c156594.js
  29. 0 0
      industry-system/industry-da/src/main/resources/static/page/static/js/chunk-c6993184.d61da4a7.js

+ 9 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/config/SpringContextUtils.java

@@ -58,4 +58,13 @@ public class SpringContextUtils implements ApplicationContextAware {
     public static <T> T getBean(String name, Class<T> clazz) {
         return getApplicationContext().getBean(name, clazz);
     }
+
+    /**
+     * 获取yml文件中配置的值
+     * @param key
+     * @return
+     */
+    public static String getYamlProperty(String key) {
+        return applicationContext.getEnvironment().getProperty(key);
+    }
 }

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportDataPolicyTask.java

@@ -153,7 +153,7 @@ public class EventReportDataPolicyTask extends ReportDataPolicyTask {
             asyncTask.addData(getReportDataPolicy().getId(), policyItemList);
             //异步生成事件驱动报表
             for (Map.Entry<String, EventReportTableTask> entry : this.EventReportTableTaskMap.entrySet()) {
-                String key = entry.getKey();
+//                String key = entry.getKey();
                 EventReportTableTask eventReportTableTask = entry.getValue();
 //                log.info("向报表【{}】填充数据", key + ":" + eventReportTableTask.getReportTable().getReportTableName());
                 eventReportTableTask.add(policyItemList);

+ 2 - 96
industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportTableTask.java

@@ -12,6 +12,7 @@ import com.example.opc_common.util.ConstantStr;
 import com.example.opc_da.config.SpringContextUtils;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.task.AsyncTask;
+import com.example.opc_da.validate.reportTable.EventReportTableValidate;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
@@ -168,7 +169,7 @@ public class EventReportTableTask implements DisposableBean {
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
         JSONArray sheetData = sheet.getJSONArray("data");
-        echoSheetAll(sheetData, this.itemDataMap);
+        EventReportTableValidate.echoSheetAll(sheetData, this.itemDataMap);
         sheet.put("data", sheetData);
         return reportTableData.toJSONString();
     }
@@ -271,99 +272,4 @@ public class EventReportTableTask implements DisposableBean {
         return sheetTableMap;
     }
 
-    /**
-     * 回填表格数据
-     *
-     * @param sheetData
-     * @param itemDataMap
-     */
-    public static void echoSheet(JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
-        for (int i = 0; i < sheetData.size(); i++) {
-            JSONArray row = sheetData.getJSONArray(i);
-            for (int j = 0; j < row.size(); j++) {
-                JSONObject rowCol = row.getJSONObject(j);
-                if (Blank.isNotEmpty(rowCol)) {
-                    //能解析的数据才赋值
-                    try {
-                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
-                        String type = rowColJson.getString("type");
-                        //如果类型为数据,则存入数据
-                        if (type.equals("data")) {
-                            JSONObject rowColData = rowColJson.getJSONObject("data");
-                            String itemId = rowColData.getString("itemId");
-                            if (Blank.isNotEmpty(itemId)) {
-                                List<Item> itemList = itemDataMap.get(itemId);
-                                String value = itemList.get(0).getValue();
-                                rowCol.put("v", value);
-                                rowCol.put("m", value);
-                                itemList.remove(0);
-                            }
-                            //如果类型为时间,则存入时间
-                        } else if (type.equals("datatime")) {
-                            List<Item> itemList = itemDataMap.entrySet().stream().findFirst().get().getValue();
-                            String time = itemList.get(0).getTime();
-                            rowCol.put("v", time);
-                            rowCol.put("m", time);
-                        }
-                    } catch (Exception e) {
-
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 回填表格数据,如果没得数据回填,则全部为空
-     *
-     * @param sheetData
-     * @param itemDataMap
-     */
-    public static void echoSheetAll(JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
-        for (int i = 0; i < sheetData.size(); i++) {
-            JSONArray row = sheetData.getJSONArray(i);
-            for (int j = 0; j < row.size(); j++) {
-                JSONObject rowCol = row.getJSONObject(j);
-                if (Blank.isNotEmpty(rowCol)) {
-                    //能解析的数据才赋值
-                    try {
-                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
-                        String type = rowColJson.getString("type");
-                        //如果类型为数据,则存入数据
-                        if (type.equals("data")) {
-                            JSONObject rowColData = rowColJson.getJSONObject("data");
-                            String itemId = rowColData.getString("itemId");
-                            if (Blank.isNotEmpty(itemId)) {
-                                List<Item> itemList = itemDataMap.get(itemId);
-                                if (CollUtil.isNotEmpty(itemList)) {
-                                    String value = itemList.get(0).getValue();
-                                    rowCol.put("v", value);
-                                    rowCol.put("m", value);
-                                    itemList.remove(0);
-                                } else {
-                                    rowCol.put("v", null);
-                                    rowCol.put("m", null);
-                                }
-                            }
-                            //如果类型为时间,则存入时间
-                        } else if (type.equals("datatime")) {
-                            List<Item> itemList = itemDataMap.entrySet().stream().findFirst().get().getValue();
-                            if (CollUtil.isNotEmpty(itemList)) {
-                                String time = itemList.get(0).getTime();
-                                rowCol.put("v", time);
-                                rowCol.put("m", time);
-                            } else {
-                                rowCol.put("v", null);
-                                rowCol.put("m", null);
-                            }
-                        }
-                    } catch (Exception e) {
-
-                    }
-                }
-            }
-        }
-    }
-
-
 }

+ 5 - 84
industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java

@@ -25,6 +25,8 @@ import com.example.opc_da.timer.PeriodTimerFactory;
 import com.example.opc_da.timer.QuartzTimerFactory;
 import com.example.opc_da.util.RedisUtil;
 import com.example.opc_da.util.UserUtil;
+import com.example.opc_da.validate.reportTable.ReportTableValidate;
+import com.example.opc_da.validate.reportTable.ReportTableValidateFactory;
 import org.quartz.CronExpression;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -281,91 +283,10 @@ public class ReportTableServiceImpl implements ReportTableService {
         if (Blank.isEmpty(reportTable)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表不存在,请刷新再试");
         }
-
         Integer reportTableType = reportTable.getReportTableType();
-        if (Blank.isEmpty(reportTableType)) {
-            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表类型不存在");
-        }
-        if (reportTableType.equals(ConstantStr.AUTOMATIC_REPORT)) {
-            reportTable.setReportTableData(reportTableTask.resolveAutoTableData(reportTable.getReportTableData(), null));
-        } else if (reportTableType.equals(ConstantStr.EVENT_DRIVEN_REPORT)) {
-            reportTable.setReportTableData(
-                    eventReportDataPolicyTaskRegister.getReportTableData(reportTable)
-            );
-        } else if (reportTableType.equals(ConstantStr.EVENT_GENERATE_REPORT)) {
-
-        }
-        //如果是手动报表
-//        if (reportTableType.equals(ConstantStr.MANUAL_REPORT)) {
-//            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)) {
-//            //获取到主报表的数据
-//            ReportTable mainReportTable = reportTableDao.getMainTableBychTableId(id);
-//            //如果版本和主报表版本一致,则直接获取主报表的reportTableData
-//            //如果不一致,则获取版本号一样的子报表最早的一条数据
-//            if (reportTable.getVersion() == mainReportTable.getVersion()) {
-//                reportTable.setReportTableData(mainReportTable.getReportTableData());
-//            } else {
-//                String chOrgTableId = reportTableDao.getChTableIdByVersion(mainReportTable.getId(), reportTable.getVersion());
-//                ReportTable chOrgReportTable = reportTableDao.getReportTableById(chOrgTableId);
-//                reportTable.setReportTableData(chOrgReportTable.getReportTableData());
-//            }
-//            reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));
-//            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);
-//            }
-//            //如果是事件驱动报表子表
-//        } else if (reportTableType.equals(ConstantStr.EVENT_GENERATE_REPORT)) {
-//            //获取到主报表的数据
-//            ReportTable mainReportTable = reportTableDao.getMainTableBychTableId(id);
-//            //如果版本和主报表版本一致,则直接获取主报表的reportTableData
-//            //如果不一致,则获取版本号一样的子报表最早的一条数据
-//            if (reportTable.getVersion() == mainReportTable.getVersion()) {
-//                reportTable.setReportTableData(mainReportTable.getReportTableData());
-//            } else {
-//                String chOrgTableId = reportTableDao.getChTableIdByVersion(mainReportTable.getId(), reportTable.getVersion());
-//                ReportTable chOrgReportTable = reportTableDao.getReportTableById(chOrgTableId);
-//                reportTable.setReportTableData(chOrgReportTable.getReportTableData());
-//            }
-//            reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));
-//            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);
-//            reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));
-//            ///如果是设备报表子表
-//        } else if (reportTableType.equals(ConstantStr.DEVICE_GENERATE_REPORT)) {
-//            ///获取到主报表的数据
-//            ReportTable mainReportTable = reportTableDao.getMainTableBychTableId(id);
-//            //如果版本和主报表版本一致,则直接获取主报表的reportTableData
-//            //如果不一致,则获取版本号一样的子报表最早的一条数据
-//            if (reportTable.getVersion() == mainReportTable.getVersion()) {
-//                reportTable.setReportTableData(mainReportTable.getReportTableData());
-//            } else {
-//                String chOrgTableId = reportTableDao.getChTableIdByVersion(mainReportTable.getId(), reportTable.getVersion());
-//                ReportTable chOrgReportTable = reportTableDao.getReportTableById(chOrgTableId);
-//                reportTable.setReportTableData(chOrgReportTable.getReportTableData());
-//            }
-//            reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));
-//            return Result.ok(reportTable);
-//        }
+        ReportTableValidate reportTableValidate = ReportTableValidateFactory.getReportTableValidate(reportTableType);
+        reportTableValidate.getData(reportTable);
+
         reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));
         return Result.ok(reportTable);
     }

+ 2 - 2
industry-system/industry-da/src/main/java/com/example/opc_da/task/AsyncTask.java

@@ -13,8 +13,8 @@ import com.example.opc_common.util.DateUtil;
 import com.example.opc_da.dao.AlarmConfigDao;
 import com.example.opc_da.dao.PrintDao;
 import com.example.opc_da.dao.ReportTableDao;
-import com.example.opc_da.policy.EventReportTableTask;
 import com.example.opc_da.util.RedisUtil;
+import com.example.opc_da.validate.reportTable.EventChReportTableValidate;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -119,7 +119,7 @@ public class AsyncTask {
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
         JSONArray sheetData = sheet.getJSONArray("data");
-        EventReportTableTask.echoSheet(sheetData, itemDataMap);
+        EventChReportTableValidate.echoSheet(sheetData, itemDataMap);
         sheet.put("data", sheetData);
         reportTableDao.updateReportTableDataById(reportTableId, reportTableData.toJSONString());
 

+ 26 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/task/ReportTableBasicItemEnum.java

@@ -0,0 +1,26 @@
+package com.example.opc_da.task;
+
+import com.example.opc_da.config.SpringContextUtils;
+import com.example.opc_da.util.UserUtil;
+import lombok.Getter;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+@Getter
+public enum ReportTableBasicItemEnum {
+    currDate("currDate", LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))),
+    currDateTime("currDateTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
+    userName("userName", SpringContextUtils.getBean(UserUtil.class).getCurrentUser().getUserName()),
+    winUserName("winUserName", System.getProperty("user.name"));
+
+    private String name;
+    private String value;
+
+    private ReportTableBasicItemEnum(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+}

+ 17 - 5
industry-system/industry-da/src/main/java/com/example/opc_da/task/ReportTableTask.java

@@ -25,10 +25,7 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -155,7 +152,22 @@ public class ReportTableTask {
                             rowCol.put("m", time);
                         }
                     } catch (Exception e) {
-
+                        String v = rowCol.getString("v");
+                        String regex = "^\\$\\{.*\\}$";
+                        //赋值基础数据项
+                        if (v.matches(regex)) {
+                            String basicItem = v.substring(2, v.length() - 1);
+                            ReportTableBasicItemEnum reportTableBasicItemEnum = Arrays.stream(ReportTableBasicItemEnum.values())
+                                    .filter(b -> b.name().equals(basicItem)).findFirst().get();
+                            if (Blank.isNotEmpty(reportTableBasicItemEnum)) {
+                                String value = reportTableBasicItemEnum.getValue();
+                                rowCol.put("v", value);
+                                rowCol.put("m", value);
+                            } else {
+                                rowCol.put("v", "");
+                                rowCol.put("m", "");
+                            }
+                        }
                     }
                 }
             }

+ 14 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticChReportTableValidate.java

@@ -0,0 +1,14 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 自动子报表验证具体类
+ */
+public class AutomaticChReportTableValidate extends AutomaticReportTableValidate{
+
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable;
+    }
+}

+ 13 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticMaReportTableValidate.java

@@ -0,0 +1,13 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 自动主报表验证具体类
+ */
+public class AutomaticMaReportTableValidate extends AutomaticReportTableValidate{
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable.setReportTableData(resolveAutoTableData(reportTable.getReportTableData(), null));
+    }
+}

+ 649 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticReportTableValidate.java

@@ -0,0 +1,649 @@
+package com.example.opc_da.validate.reportTable;
+
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cqcy.ei.influxdb.entity.Item;
+import com.cqcy.ei.influxdb.service.InFluxDBService;
+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_da.config.SpringContextUtils;
+import com.example.opc_da.task.ReportTableBasicItemEnum;
+import org.jetbrains.annotations.NotNull;
+
+import javax.validation.constraints.NotBlank;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * 自动报表验证抽象类
+ */
+public abstract class AutomaticReportTableValidate implements ReportTableValidate {
+
+    private static final String timePattern = "yyyy-MM-dd HH:mm:ss.SSS";
+
+    InFluxDBService inFluxDBService = SpringContextUtils.getBean(InFluxDBService.class);
+    String bucket = SpringContextUtils.getYamlProperty("influxdb.bucket");
+
+    /**
+     * 将自动报表的reportTableData解析出来,并赋值相应的数据
+     *
+     * @param reportTableDataStr 报表字符串
+     * @param referTime          参考时间
+     * @return
+     */
+    protected String resolveAutoTableData(@NotBlank String reportTableDataStr, LocalDateTime referTime) {
+        //解析自动报表结构
+        JSONObject reportTableData = JSONObject.parseObject(reportTableDataStr);
+        //得到sheet数据
+        JSONObject sheet = reportTableData.getJSONObject("sheet");
+        reportTableData.put("sheet", resolveAutoTableSheetData(sheet, referTime));
+
+        //得到chart数据
+        JSONObject chart = reportTableData.getJSONObject("chart");
+        reportTableData.put("chart", resolveAutoTableChartData(chart, referTime));
+
+        //将生成的数据重新转换为json
+        return reportTableData.toJSONString();
+    }
+
+    /**
+     * 解析周期报表sheet数据
+     *
+     * @param sheet
+     * @param referTime 参考时间
+     * @return
+     */
+    private JSONObject resolveAutoTableSheetData(JSONObject sheet, LocalDateTime referTime) {
+        JSONArray sheetData = sheet.getJSONArray("data");
+        //遍历sheet所有单元格,并存为Map<tableId,Map<uid,JSONObject>>格式
+        Map<String, Map<String, JSONObject>> sheetTableMap = getAutoStringMapMap(sheetData);
+
+        //遍历生成的sheetTableMap,根据配置获取数据,并存为Map<tableId, Map<uid,List<Item>>>格式
+        Map<String, Map<String, List<Item>>> sheetTableDataMap = new HashMap<>();
+        for (Map.Entry<String, Map<String, JSONObject>> sheetTable : sheetTableMap.entrySet()) {
+            sheetTableDataMap.put(sheetTable.getKey(),
+                    generateSheetTableDataMap(sheetTable.getValue(), referTime));
+        }
+
+        //sheet数据最后往Json中存为data[0].data,回填数据
+        echoSheet(sheetData, sheetTableDataMap);
+        sheet.put("data", sheetData);
+        return sheet;
+    }
+
+    /**
+     * 回填表格数据
+     *
+     * @param sheetData
+     * @param sheetTableDataMap
+     */
+    private static void echoSheet(JSONArray sheetData, Map<String, Map<String, List<Item>>> sheetTableDataMap) {
+        for (int i = 0; i < sheetData.size(); i++) {
+            JSONArray row = sheetData.getJSONArray(i);
+            for (int j = 0; j < row.size(); j++) {
+                JSONObject rowCol = row.getJSONObject(j);
+                if (Blank.isNotEmpty(rowCol)) {
+                    //能解析的数据才赋值
+                    try {
+                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
+                        String type = rowColJson.getString("type");
+                        String tableId = rowColJson.getString("tableId");
+                        //如果类型为数据,则存入数据
+                        if (type.equals("data")) {
+                            JSONObject rowColData = rowColJson.getJSONObject("data");
+                            String uid = rowColData.getString("uid");
+                            if (Blank.isNotEmpty(uid)) {
+                                List<Item> itemList = sheetTableDataMap.get(tableId).get(uid);
+                                String value = itemList.get(0).getValue();
+                                rowCol.put("v", value);
+                                rowCol.put("m", value);
+                                itemList.remove(0);
+                            }
+                            //如果类型为时间,则存入时间
+                        } else if (type.equals("datatime")) {
+                            List<Item> itemList = sheetTableDataMap.get(tableId).entrySet().stream().findFirst().get().getValue();
+                            String time = itemList.get(0).getTime();
+                            rowCol.put("v", time);
+                            rowCol.put("m", time);
+                        }
+                    } catch (Exception e) {
+                        String v = rowCol.getString("v");
+                        String regex = "^\\$\\{.*\\}$";
+                        //赋值基础数据项
+                        if (v.matches(regex)) {
+                            String basicItem = v.substring(2, v.length() - 1);
+                            ReportTableBasicItemEnum reportTableBasicItemEnum = Arrays.stream(ReportTableBasicItemEnum.values())
+                                    .filter(b -> b.name().equals(basicItem)).findFirst().get();
+                            if (Blank.isNotEmpty(reportTableBasicItemEnum)) {
+                                String value = reportTableBasicItemEnum.getValue();
+                                rowCol.put("v", value);
+                                rowCol.put("m", value);
+                            } else {
+                                rowCol.put("v", "");
+                                rowCol.put("m", "");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 遍历sheet所有单元格,并存为Map<tableId,Map<uid,JSONObject>>格式
+     *
+     * @param sheetData
+     * @return
+     */
+    @NotNull
+    private static Map<String, Map<String, JSONObject>> getAutoStringMapMap(JSONArray sheetData) {
+        Map<String, Map<String, JSONObject>> sheetTableMap = new HashMap<>();
+        for (int i = 0; i < sheetData.size(); i++) {
+            JSONArray row = sheetData.getJSONArray(i);
+            for (int j = 0; j < row.size(); j++) {
+                JSONObject rowCol = row.getJSONObject(j);
+                if (Blank.isNotEmpty(rowCol)) {
+                    try {
+                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
+                        String tableId = rowColJson.getString("tableId");
+                        String type = rowColJson.getString("type");
+                        if (type.equals("data")) {
+                            JSONObject rowColData = rowColJson.getJSONObject("data");
+                            String uid = rowColData.getString("uid");
+                            Map<String, JSONObject> sheetUidMap = sheetTableMap.get(tableId);
+                            if (Blank.isEmpty(sheetUidMap)) sheetUidMap = new HashMap<>();
+                            //得到所有sheet数据生成条件
+                            if (Blank.isEmpty(sheetUidMap.get(uid)) && Blank.isNotEmpty(uid)) {
+                                sheetUidMap.put(uid, rowColJson);
+                                sheetTableMap.put(tableId, sheetUidMap);
+                            }
+                        }
+                    } catch (Exception e) {
+
+                    }
+                }
+            }
+        }
+        return sheetTableMap;
+    }
+
+    /**
+     * @param sheetUidMap
+     * @param referTime
+     * @return
+     */
+    public Map<String, List<Item>> generateSheetTableDataMap(
+            Map<String, JSONObject> sheetUidMap, LocalDateTime referTime) {
+        //得到单个区域所有的数据项配置信息
+        List<JSONObject> tableJsonObjectList = sheetUidMap.values().stream().collect(Collectors.toList());
+        //对数据项配置信息,通过报表数据策略id,数据切换类型,开始时间,结束时间,取值类型进行分组
+        //Map<分组条件Json,分组后集合List<JSONObject>>
+        Map<JSONObject, List<JSONObject>> jsonMap = tableJsonObjectList.stream()
+                .collect(Collectors.groupingBy(getSheetJSONObjectFunction()));
+
+        //将单个区域数据项配置信息,转换为Map<uid,上面的jsonMap键>格式
+        Map<String, JSONObject> uidMap = tableJsonObjectList.stream()
+                .collect(Collectors.toMap(j -> j.getJSONObject("data").getString("uid"),
+                        getSheetJSONObjectFunction()));
+
+        //通过分组的信息,查询数据,并再分组,Map<JSONObject,Map<uid,List<Item>>
+        //遍历分组之后的jsonMap,
+        Map<JSONObject, Map<String, List<Item>>> sheetItemMap = new HashMap<>();
+        for (Map.Entry<JSONObject, List<JSONObject>> json : jsonMap.entrySet()) {
+            //查询单个分组集合的数据,并转换为Map<policyItemId,List<Item>>,然后回填到sheetItemMap中
+            JSONObject jsonObject = json.getKey();
+            List<JSONObject> jsonObjectList = json.getValue();
+
+            //查询单个分组集合的数据
+            List<Item> itemList = getItems(referTime, jsonObjectList, jsonObject);
+            //转换为Map<policyItemId,List<Item>>,然后回填到sheetItemMap中
+            sheetItemMap.put(jsonObject, itemList.stream().collect(Collectors.groupingBy(i -> i.getName())));
+        }
+        //将单个区域的数据项,生成Map<uid,List<Item>>结构数据
+        Map<String, List<Item>> sheetUidDataMap = new HashMap<>();
+        for (Map.Entry<String, JSONObject> sheetUid : sheetUidMap.entrySet()) {
+            JSONObject jsonObject = sheetUid.getValue();
+            String uid = sheetUid.getKey();
+            String itemId = jsonObject.getJSONObject("data").getString("itemId");
+            Map<String, List<Item>> stringListMap = sheetItemMap.get(uidMap.get(uid));
+            List<Item> itemList = stringListMap.get(itemId);
+            //通过计算得到新的集合
+            sheetUidDataMap.put(uid, countUidData(jsonObject, itemList, referTime));
+        }
+        return sheetUidDataMap;
+    }
+
+    /**
+     * 计算单个uid,分割之后的数据
+     *
+     * @param jsonObject
+     * @param itemList
+     * @param referTime
+     * @return
+     */
+    private List<Item> countUidData(JSONObject jsonObject, List<Item> itemList, LocalDateTime referTime) {
+        JSONObject setting = jsonObject.getJSONObject("setting");
+        String bucketType = setting.getString("bucketType");
+
+        //根据上面时间类型,生成sTime,eTime
+        LocalDateTime sTime = getSheetStartTime(setting, referTime);
+        LocalDateTime eTime = getSheetEndTime(setting, referTime);
+        //0数据集,1单值
+        String dataValueType = setting.getString("dataValueType");
+        //取值模式0平均值,1最大值,2最小值,3瞬时值
+        String valueTakingMode = setting.getString("valueTakingMode");
+        //时段值
+        Integer bucketValue = setting.getInteger("bucketValue");
+        return splitData(dataValueType, itemList, sTime, eTime,
+                valueTakingMode, bucketType, bucketValue);
+    }
+
+    /**
+     * 查询单个分组的所有数据
+     *
+     * @param referTime      参考时间
+     * @param jsonObjectList
+     * @param jsonObject
+     * @return
+     */
+    private List<Item> getItems(LocalDateTime referTime, List<JSONObject> jsonObjectList, JSONObject jsonObject) {
+        //得到单个分组的所有数据项id
+        List<String> policyItemIdList = jsonObjectList.stream()
+                .map(j -> j.getJSONObject("data").getString("itemId"))
+                .collect(Collectors.toList());
+
+        //得到单个分组的配置信息
+        JSONObject data = jsonObject.getJSONObject("data");
+        String policyId = data.getString("policyId");
+
+        JSONObject setting = jsonObject.getJSONObject("setting");
+        String valueType = setting.getString("valueType");
+
+        //根据上面时间类型,生成sTime,eTime
+        LocalDateTime sTime = getSheetStartTime(setting, referTime);
+        LocalDateTime eTime = getSheetEndTime(setting, referTime);
+        //根据配置信息查询过滤数据库的所有数据
+        return inFluxDBService.queryHistory(bucket, policyId, sTime, eTime, policyItemIdList, valueType);
+    }
+
+    @NotNull
+    private static Function<JSONObject, JSONObject> getSheetJSONObjectFunction() {
+        return j -> {
+            JSONObject data = j.getJSONObject("data");
+            JSONObject jsonObject = new JSONObject();
+            JSONObject dataJsonObject = new JSONObject();
+            dataJsonObject.put("policyId", data.get("policyId"));
+
+            JSONObject setting = j.getJSONObject("setting");
+            JSONObject setJsonObject = new JSONObject();
+            setJsonObject.put("valueType", setting.getString("valueType"));
+
+            setJsonObject.put("bucketType", setting.getString("bucketType"));
+
+            setJsonObject.put("timeType1", setting.getString("timeType1"));
+            setJsonObject.put("timeValue1", setting.getString("timeValue1"));
+            setJsonObject.put("dateTimeType1", setting.getString("dateTimeType1"));
+            setJsonObject.put("startTime", setting.getString("startTime"));
+
+            setJsonObject.put("timeType2", setting.getString("timeType2"));
+            setJsonObject.put("timeValue2", setting.getString("timeValue2"));
+            setJsonObject.put("dateTimeType2", setting.getString("dateTimeType2"));
+            setJsonObject.put("endTime", setting.getString("endTime"));
+
+            jsonObject.put("data", dataJsonObject);
+            jsonObject.put("setting", setJsonObject);
+            return jsonObject;
+        };
+    }
+
+    /**
+     * 获取sheet单个区域的开始时间
+     *
+     * @param setting   sheet单个区域的配置
+     * @param referTime 参考时间
+     * @return
+     */
+    private LocalDateTime getSheetStartTime(JSONObject setting, LocalDateTime referTime) {
+        String bucketType = setting.getString("bucketType");
+        String timeType1 = setting.getString("timeType1");
+        Integer timeValue1 = setting.getInteger("timeValue1");
+        String dateTimeType1 = setting.getString("dateTimeType1");
+        String startTime = setting.getString("startTime");
+        return generateCycleTime(referTime, bucketType, timeType1, timeValue1, dateTimeType1, startTime);
+    }
+
+    /**
+     * 获取sheet单个区域的结束时间
+     *
+     * @param setting   sheet单个区域的配置
+     * @param referTime 参考时间
+     * @return
+     */
+    private LocalDateTime getSheetEndTime(JSONObject setting, LocalDateTime referTime) {
+        String bucketType = setting.getString("bucketType");
+
+        String timeType2 = setting.getString("timeType2");
+        Integer timeValue2 = setting.getInteger("timeValue2");
+        String dateTimeType2 = setting.getString("dateTimeType2");
+        String endTime = setting.getString("endTime");
+        LocalDateTime localDateTime = generateCycleTime(referTime, bucketType, timeType2, timeValue2, dateTimeType2, endTime);
+        return localDateTime.isBefore(LocalDateTime.now()) ? localDateTime : LocalDateTime.now();
+    }
+
+    /**
+     * 解析周期报表chart数据
+     *
+     * @param chart
+     * @param referTime 参考时间
+     * @return
+     */
+    private JSONObject resolveAutoTableChartData(JSONObject chart, LocalDateTime referTime) {
+        for (Map.Entry<String, Object> entry : chart.entrySet()) {
+            String entryKey = entry.getKey();
+            //获取统计图的配置信息
+            chart.put(entryKey, generateChartJson(chart.getJSONObject(entryKey), referTime));
+        }
+        return chart;
+    }
+
+    /**
+     * 根据统计图配置信息,生成数据,并覆盖原来的模拟值,返回json'
+     *
+     * @param chartJson
+     * @param referTime
+     * @return
+     */
+    private JSONObject generateChartJson(JSONObject chartJson, LocalDateTime referTime) {
+        JSONObject dataForm = chartJson.getJSONObject("dataForm");
+        JSONArray items = chartJson.getJSONArray("items");
+//            String policyId = dataForm.getString("policyId");
+        String policyId = dataForm.getString("chart-item-group");
+
+        String valueType = dataForm.getString("valueType");
+        String bucketType = dataForm.getString("bucketType");
+
+        //根据配置信息,生成统计图的开始和结束时间
+        LocalDateTime sTime = getChartStartTime(dataForm, referTime);
+        LocalDateTime eTime = getChartEndTime(dataForm, referTime);
+        //获取统计图配置的所有数据项
+        List<String> policyItemIdList = items.stream().map(v -> ((JSONObject) v).getString("value")).collect(Collectors.toList());
+        //根据开始、结束时间、数据项等相关信息,查询过滤数据库中的数据
+        List<Item> itemList = inFluxDBService.queryHistory(bucket, policyId, sTime, eTime, policyItemIdList, valueType);
+        //将得到的数据转换为Map<ItemId,List<Item>> 格式
+        Map<String, List<Item>> itemDataMap = itemList.stream().collect(Collectors.groupingBy(i -> i.getName()));
+        String valueTakingMode = dataForm.getString("valueTakingMode");
+        Integer bucketValue = dataForm.getInteger("bucketValue");
+        //得到series的数据
+        //将生成的数据回传到chart中去
+        JSONObject chartData = chartJson.getJSONObject("chartData");
+        JSONArray series = chartData.getJSONArray("series");
+        String chartType = series.getJSONObject(0).getString("type");
+        //如果为柱状图或折线图
+        if (chartType.equals(ConstantStr.LINE_CHART) || chartType.equals(ConstantStr.BAR_CHART)) {
+            //所有时间数据,组成x轴
+            List<String> allXaiosList = new ArrayList<>();
+            List<List<List<String>>> serieDataList = new ArrayList<>();
+            //遍历数据项
+            for (String policyItemId : policyItemIdList) {
+                List<Item> validDataList = splitData(null, itemDataMap.get(policyItemId), sTime, eTime, valueTakingMode, bucketType, bucketValue);
+                allXaiosList.addAll(validDataList.stream().map(Item::getTime).collect(Collectors.toList()));
+                //生成series的数据
+                serieDataList.add(validDataList.stream().map(i ->
+                        Stream.of(i.getTime(), i.getValue()).collect(Collectors.toList())
+                ).collect(Collectors.toList()));
+            }
+            //得到x轴时间去重数据
+            List<String> xAxisList = allXaiosList.stream().distinct().sorted().collect(Collectors.toList());
+
+            for (int i = 0; i < series.size(); i++) {
+                JSONObject serieJsonObject = series.getJSONObject(i);
+                serieJsonObject.put("data", serieDataList.get(i));
+            }
+            JSONObject xAxis = chartData.getJSONArray("xAxis").getJSONObject(0);
+            xAxis.put("data", xAxisList);
+            //如果为饼图
+        } else if (chartType.equals(ConstantStr.PIE_CHART)) {
+            //因为饼图只有一个数据项
+            List<Item> validDataList = itemDataMap.get(policyItemIdList.get(0));
+            //生成series的数据
+            List<JSONObject> serieDataList = validDataList.stream().map(v -> {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("value", v.getValue());
+                jsonObject.put("name", v.getTime());
+                return jsonObject;
+            }).collect(Collectors.toList());
+            series.getJSONObject(0).put("data", serieDataList);
+        }
+        return chartJson;
+    }
+
+    /**
+     * 获取chart单个统计图的开始时间
+     *
+     * @param dataForm  chart单个统计图的配置
+     * @param referTime 参考时间
+     * @return
+     */
+    private LocalDateTime getChartStartTime(JSONObject dataForm, LocalDateTime referTime) {
+        String bucketType = dataForm.getString("bucketType");
+
+        String chartTimeType1 = dataForm.getString("chartTimeType1");
+        Integer chartTimeValue1 = dataForm.getInteger("chartTimeValue1");
+        String chartDateTimeType1 = dataForm.getString("chartDateTimeType1");
+        String chartSettingData1 = dataForm.getString("chartSettingData1");
+        return generateCycleTime(referTime, bucketType, chartTimeType1,
+                chartTimeValue1, chartDateTimeType1, chartSettingData1);
+
+    }
+
+    /**
+     * 获取chart单个统计图的结束时间
+     *
+     * @param dataForm  chart单个统计图的配置
+     * @param referTime 参考时间
+     * @return
+     */
+    private LocalDateTime getChartEndTime(JSONObject dataForm, LocalDateTime referTime) {
+        String bucketType = dataForm.getString("bucketType");
+
+        String chartTimeType2 = dataForm.getString("chartTimeType2");
+        Integer chartTimeValue2 = dataForm.getInteger("chartTimeValue2");
+        String chartDateTimeType2 = dataForm.getString("chartDateTimeType2");
+        String chartSettingData2 = dataForm.getString("chartSettingData2");
+        LocalDateTime localDateTime = generateCycleTime(referTime, bucketType, chartTimeType2,
+                chartTimeValue2, chartDateTimeType2, chartSettingData2);
+        return localDateTime.isBefore(LocalDateTime.now()) ? localDateTime : LocalDateTime.now();
+    }
+
+    /**
+     * 生成周期报表时间方法
+     *
+     * @param referTime     参考时间,如果时间为空,则是查实时数据,不为空,则查历史数据
+     * @param bucketType    时段类型:0月,1天,2时,3粉,4秒
+     * @param timeType      0当,1次
+     * @param timeValue     值
+     * @param dateTimeType
+     * @param dateTimeValue
+     * @return
+     */
+    private LocalDateTime generateCycleTime(LocalDateTime referTime, String bucketType, String timeType, Integer timeValue,
+                                            String dateTimeType, String dateTimeValue) {
+        if (Blank.isNotEmpty(referTime)) {
+            if (bucketType.equals(ConstantStr.PERIOD_TIME_MONTH)) {
+                //如果时段类型选择为月
+                if (timeType.equals(ConstantStr.TYPE_LAST)) {
+                    //参考时间的上一年 指定月 第一天
+                    return referTime.minusYears(1).withMonth(timeValue).with(TemporalAdjusters.firstDayOfMonth());
+                } else if (timeType.equals(ConstantStr.TYPE_CURRENT)) {
+                    //参考时间的本年 指定月 第一天
+                    return referTime.withMonth(timeValue).with(TemporalAdjusters.firstDayOfMonth());
+                }
+            } else if (bucketType.equals(ConstantStr.PERIOD_TIME_DAY)) {
+                //如果时段类型选择为日
+                if (timeType.equals(ConstantStr.TYPE_LAST)) {
+                    //参考时间的本年 上一月 指定天
+                    return referTime.minusMonths(1).withDayOfMonth(timeValue);
+                } else if (timeType.equals(ConstantStr.TYPE_CURRENT)) {
+                    //参考时间的本年 本月 指定天
+                    return referTime.withDayOfMonth(timeValue);
+                }
+            } else if (bucketType.equals(ConstantStr.PERIOD_TIME_HOUR) ||
+                    bucketType.equals(ConstantStr.PERIOD_TIME_MINUTE) ||
+                    bucketType.equals(ConstantStr.PERIOD_TIME_SECOND)) {
+                //如果时段类型选择为时,分,秒
+                if (dateTimeType.equals(ConstantStr.TYPE_LAST)) {
+                    //参考时间的本年 本月 下一天 指定时分秒
+                    return referTime.minusDays(1).with(LocalTime.parse(dateTimeValue, DateTimeFormatter.ofPattern("HH:mm:ss")));
+                } else if (dateTimeType.equals(ConstantStr.TYPE_CURRENT)) {
+                    //参考时间的本年 本月 本天 指定时分秒
+                    return referTime.with(LocalTime.parse(dateTimeValue, DateTimeFormatter.ofPattern("HH:mm:ss")));
+                }
+            }
+        }
+        referTime = LocalDateTime.now();
+        if (bucketType.equals(ConstantStr.PERIOD_TIME_MONTH)) {
+            //如果时段类型选择为月
+            if (timeType.equals(ConstantStr.TYPE_LAST)) {
+                //参考时间的本年 指定月 第一天
+                return referTime.withMonth(timeValue).with(TemporalAdjusters.firstDayOfMonth());
+            } else if (timeType.equals(ConstantStr.TYPE_CURRENT)) {
+                //参考时间的下一年 指定月 第一天
+                return referTime.plusYears(1).withMonth(timeValue).with(TemporalAdjusters.firstDayOfMonth());
+            }
+        } else if (bucketType.equals(ConstantStr.PERIOD_TIME_DAY)) {
+            //如果时段类型选择为日
+            if (timeType.equals(ConstantStr.TYPE_LAST)) {
+                //参考时间的本年 本月 指定天
+                return referTime.withDayOfMonth(timeValue);
+            } else if (timeType.equals(ConstantStr.TYPE_CURRENT)) {
+                //参考时间的本年 下一月 指定天
+                return referTime.plusMonths(1).withDayOfMonth(timeValue);
+            }
+        } else if (bucketType.equals(ConstantStr.PERIOD_TIME_HOUR) ||
+                bucketType.equals(ConstantStr.PERIOD_TIME_MINUTE) ||
+                bucketType.equals(ConstantStr.PERIOD_TIME_SECOND)) {
+            //如果时段类型选择为时,分,秒
+            if (dateTimeType.equals(ConstantStr.TYPE_LAST)) {
+                //参考时间的本年 本月 本天 指定时分秒
+                return referTime.with(LocalTime.parse(dateTimeValue, DateTimeFormatter.ofPattern("HH:mm:ss")));
+            } else if (dateTimeType.equals(ConstantStr.TYPE_CURRENT)) {
+                //参考时间的本年 本月 下一天 指定时分秒
+                return referTime.plusDays(1).with(LocalTime.parse(dateTimeValue, DateTimeFormatter.ofPattern("HH:mm:ss")));
+            }
+        }
+        return LocalDateTime.now();
+    }
+
+    /**
+     * 通过开始时间和结束时间分割数据,并计算
+     *
+     * @param dataValueType   0数据集,1单值,空也为数据集
+     * @param itemList        全部数据项集合
+     * @param startDateTime   开始时间
+     * @param endDateTime     结束时间
+     * @param valueTakingMode 取值模式:0平均值,1最大值,2最小值,3瞬时值,4求和,5计数
+     * @param bucketType      时段类型:0天,1时,2分,3秒
+     * @param bucketValue     时段值
+     * @return
+     */
+    private List<Item> splitData(String dataValueType, List<Item> itemList, LocalDateTime startDateTime, LocalDateTime endDateTime,
+                                 String valueTakingMode, String bucketType, Integer bucketValue) {
+        List<Item> newItemList = new ArrayList<>();
+        //获取数据集
+        if (Blank.isEmpty(dataValueType) || dataValueType.equals(ConstantStr.DATA_SET)) {
+            LocalDateTime sDateTime = startDateTime;
+            LocalDateTime eDateTime;
+            //如果sDateTime小于endDateTime
+            while (sDateTime.isBefore(endDateTime)) {
+                if (bucketType.equals(ConstantStr.PERIOD_TIME_MONTH)) {
+                    eDateTime = sDateTime.plusMonths(bucketValue);
+                } else if (bucketType.equals(ConstantStr.PERIOD_TIME_DAY)) {
+                    eDateTime = sDateTime.plusDays(bucketValue);
+                } else if (bucketType.equals(ConstantStr.PERIOD_TIME_HOUR)) {
+                    eDateTime = sDateTime.plusHours(bucketValue);
+                } else if (bucketType.equals(ConstantStr.PERIOD_TIME_MINUTE)) {
+                    eDateTime = sDateTime.plusMinutes(bucketValue);
+                } else if (bucketType.equals(ConstantStr.PERIOD_TIME_SECOND)) {
+                    eDateTime = sDateTime.plusSeconds(bucketValue);
+                } else {
+                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "时段类型错误");
+                }
+                List<String> valueList = new ArrayList<>();
+                if (CollUtil.isNotEmpty(itemList)) {
+                    for (int i = 0; i < itemList.size(); i++) {
+                        Item item = itemList.get(i);
+                        LocalDateTime itemDateTime = LocalDateTime.parse(item.getTime(), DateTimeFormatter.ofPattern(timePattern));
+                        if (sDateTime.isAfter(itemDateTime)) {
+                            itemList.remove(i);
+                            i--;
+                            continue;
+                        }
+                        if (itemDateTime.isBefore(eDateTime)) {
+                            valueList.add(item.getValue());
+                            itemList.remove(i);
+                            i--;
+                        } else {
+                            break;
+                        }
+                    }
+                }
+                //求出每段应该返回的值
+                newItemList.add(new Item()
+                        .value(countData(valueList, valueTakingMode))
+                        .time(sDateTime.format(DateTimeFormatter.ofPattern(timePattern))));
+                sDateTime = eDateTime;
+            }
+            return newItemList;
+        } else if (dataValueType.equals(ConstantStr.SINGLE_VALUE)) {
+            newItemList.add(new Item()
+                    .value(countData(itemList.stream().map(i ->
+                            i.getValue()).collect(Collectors.toList()), valueTakingMode))
+                    .time(startDateTime.format(DateTimeFormatter.ofPattern(timePattern))));
+        }
+        return newItemList;
+    }
+
+    /**
+     * 将传入的集合数据组,通过不同的取值模式,算出来
+     *
+     * @param valueList       数据集合
+     * @param valueTakingMode 取值模式:0平均值,1最大值,2最小值,3瞬时值,4求和,5计数
+     * @return
+     */
+    public static String countData(List<String> valueList, String valueTakingMode) {
+        if (CollUtil.isNotEmpty(valueList)) {
+            try {
+                if (valueTakingMode.equals(ConstantStr.AVERAGE_VALUE)) {
+                    return valueList.stream().mapToDouble(Double::valueOf).average().getAsDouble() + "";
+                }
+                if (valueTakingMode.equals(ConstantStr.MAX_VALUE)) {
+                    return valueList.stream().mapToDouble(Double::valueOf).max().getAsDouble() + "";
+                }
+                if (valueTakingMode.equals(ConstantStr.MIN_VALUE)) {
+                    return valueList.stream().mapToDouble(Double::valueOf).min().getAsDouble() + "";
+                }
+                if (valueTakingMode.equals(ConstantStr.INSTANTANEOUS_VALUE)) {
+                    return valueList.get(0);
+                }
+                if (valueTakingMode.equals(ConstantStr.SUM_VALUE)) {
+                    return valueList.stream().mapToDouble(Double::valueOf).sum() + "";
+                }
+                if (valueTakingMode.equals(ConstantStr.COUNT_VALUE)) {
+                    return valueList.stream().count() + "";
+                }
+            } catch (Exception e) {
+
+            }
+        }
+        return null;
+    }
+}

+ 13 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceChReportTableValidate.java

@@ -0,0 +1,13 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 设备子报表验证具体类
+ */
+public class DeviceChReportTableValidate extends DeviceReportTableValidate {
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable;
+    }
+}

+ 13 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceMaReportTableValidate.java

@@ -0,0 +1,13 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 设备主报表验证具体类
+ */
+public class DeviceMaReportTableValidate extends DeviceReportTableValidate{
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable;
+    }
+}

+ 7 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceReportTableValidate.java

@@ -0,0 +1,7 @@
+package com.example.opc_da.validate.reportTable;
+
+/**
+ * 设备报表验证抽象类
+ */
+public abstract class DeviceReportTableValidate implements ReportTableValidate {
+}

+ 64 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventChReportTableValidate.java

@@ -0,0 +1,64 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cqcy.ei.influxdb.entity.Item;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.util.Blank;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 事件子报表验证具体类
+ */
+public class EventChReportTableValidate extends EventReportTableValidate {
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable.setReportTableData(
+                eventReportDataPolicyTaskRegister.getReportTableData(reportTable)
+        );
+    }
+
+    /**
+     * 回填表格数据
+     *
+     * @param sheetData
+     * @param itemDataMap
+     */
+    public static void echoSheet(JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
+        for (int i = 0; i < sheetData.size(); i++) {
+            JSONArray row = sheetData.getJSONArray(i);
+            for (int j = 0; j < row.size(); j++) {
+                JSONObject rowCol = row.getJSONObject(j);
+                if (Blank.isNotEmpty(rowCol)) {
+                    //能解析的数据才赋值
+                    try {
+                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
+                        String type = rowColJson.getString("type");
+                        //如果类型为数据,则存入数据
+                        if (type.equals("data")) {
+                            JSONObject rowColData = rowColJson.getJSONObject("data");
+                            String itemId = rowColData.getString("itemId");
+                            if (Blank.isNotEmpty(itemId)) {
+                                List<Item> itemList = itemDataMap.get(itemId);
+                                String value = itemList.get(0).getValue();
+                                rowCol.put("v", value);
+                                rowCol.put("m", value);
+                                itemList.remove(0);
+                            }
+                            //如果类型为时间,则存入时间
+                        } else if (type.equals("datatime")) {
+                            List<Item> itemList = itemDataMap.entrySet().stream().findFirst().get().getValue();
+                            String time = itemList.get(0).getTime();
+                            rowCol.put("v", time);
+                            rowCol.put("m", time);
+                        }
+                    } catch (Exception e) {
+
+                    }
+                }
+            }
+        }
+    }
+}

+ 37 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventMaReportTableValidate.java

@@ -0,0 +1,37 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.exception.CustomException;
+import com.example.opc_common.util.ConstantStr;
+
+/**
+ * 事件主报表验证具体类
+ */
+public class EventMaReportTableValidate extends EventReportTableValidate {
+
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        Integer runState = reportTable.getRunState();
+        //如果处于运行状态,则获取最新一条运行中的子报表数据
+        if (runState.equals(ConstantStr.START_UP)) {
+            return reportTable.setReportTableData(
+                    eventReportDataPolicyTaskRegister.getReportTableData(reportTable)
+            );
+            //如果主报表处于停止状态,则获取到的数据全为空
+        } else if (runState.equals(ConstantStr.STOP_IT)) {
+            //解析事件驱动报表结构
+            JSONObject reportTableDataJson = JSONObject.parseObject(reportTable.getReportTableData());
+            //得到sheet数据
+            JSONObject sheet = reportTableDataJson.getJSONObject("sheet");
+            JSONArray sheetData = sheet.getJSONArray("data");
+            echoSheetAll(sheetData, null);
+            sheet.put("data", sheetData);
+            return reportTable.setReportTableData(reportTableDataJson.toJSONString());
+        } else {
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "运行状态异常");
+        }
+    }
+}

+ 72 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventReportTableValidate.java

@@ -0,0 +1,72 @@
+package com.example.opc_da.validate.reportTable;
+
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cqcy.ei.influxdb.entity.Item;
+import com.example.opc_common.util.Blank;
+import com.example.opc_da.config.SpringContextUtils;
+import com.example.opc_da.policy.EventReportDataPolicyTaskRegister;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 事件报表验证抽象类
+ */
+public abstract class EventReportTableValidate implements ReportTableValidate {
+
+    EventReportDataPolicyTaskRegister eventReportDataPolicyTaskRegister = SpringContextUtils.getBean(EventReportDataPolicyTaskRegister.class);
+
+    /**
+     * 回填表格数据,如果没得数据回填,则全部为空
+     *
+     * @param sheetData
+     * @param itemDataMap
+     */
+    public static void echoSheetAll(JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
+        for (int i = 0; i < sheetData.size(); i++) {
+            JSONArray row = sheetData.getJSONArray(i);
+            for (int j = 0; j < row.size(); j++) {
+                JSONObject rowCol = row.getJSONObject(j);
+                if (Blank.isNotEmpty(rowCol)) {
+                    //能解析的数据才赋值
+                    try {
+                        JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("v"));
+                        String type = rowColJson.getString("type");
+                        //如果类型为数据,则存入数据
+                        if (type.equals("data")) {
+                            JSONObject rowColData = rowColJson.getJSONObject("data");
+                            String itemId = rowColData.getString("itemId");
+                            if (Blank.isNotEmpty(itemId)) {
+                                List<Item> itemList = itemDataMap.get(itemId);
+                                if (CollUtil.isNotEmpty(itemList)) {
+                                    String value = itemList.get(0).getValue();
+                                    rowCol.put("v", value);
+                                    rowCol.put("m", value);
+                                    itemList.remove(0);
+                                } else {
+                                    rowCol.put("v", null);
+                                    rowCol.put("m", null);
+                                }
+                            }
+                            //如果类型为时间,则存入时间
+                        } else if (type.equals("datatime")) {
+                            List<Item> itemList = itemDataMap.entrySet().stream().findFirst().get().getValue();
+                            if (CollUtil.isNotEmpty(itemList)) {
+                                String time = itemList.get(0).getTime();
+                                rowCol.put("v", time);
+                                rowCol.put("m", time);
+                            } else {
+                                rowCol.put("v", null);
+                                rowCol.put("m", null);
+                            }
+                        }
+                    } catch (Exception e) {
+
+                    }
+                }
+            }
+        }
+    }
+}

+ 13 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ManualReportTableValidate.java

@@ -0,0 +1,13 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 手动报表验证具体类
+ */
+public class ManualReportTableValidate implements ReportTableValidate{
+    @Override
+    public ReportTable getData(ReportTable reportTable) {
+        return reportTable;
+    }
+}

+ 18 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ReportTableValidate.java

@@ -0,0 +1,18 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.entity.ReportTable;
+
+/**
+ * 报表验证抽象接口
+ */
+public interface ReportTableValidate {
+
+    /**
+     * 通过数据库存的报表数据,返回展示需要展示的报表数据
+     *
+     * @param reportTable
+     * @return
+     */
+    ReportTable getData(ReportTable reportTable);
+
+}

+ 33 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ReportTableValidateFactory.java

@@ -0,0 +1,33 @@
+package com.example.opc_da.validate.reportTable;
+
+import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.exception.CustomException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 报表验证工厂类
+ */
+public class ReportTableValidateFactory {
+
+    private static final Map<Integer, ReportTableValidate> reportTableValidateMap = new HashMap<>();
+
+    static {
+        reportTableValidateMap.put(0, new ManualReportTableValidate());
+        reportTableValidateMap.put(1, new AutomaticMaReportTableValidate());
+        reportTableValidateMap.put(2, new EventMaReportTableValidate());
+        reportTableValidateMap.put(3, new AutomaticChReportTableValidate());
+        reportTableValidateMap.put(4, new EventChReportTableValidate());
+        reportTableValidateMap.put(5, new DeviceMaReportTableValidate());
+        reportTableValidateMap.put(6, new DeviceChReportTableValidate());
+    }
+
+    public static ReportTableValidate getReportTableValidate(Integer type) {
+        ReportTableValidate reportTableValidate = reportTableValidateMap.get(type);
+        if (reportTableValidate == null) {
+            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前没有此种类型的报表");
+        }
+        return reportTableValidate;
+    }
+}

文件差異過大導致無法顯示
+ 1 - 1
industry-system/industry-da/src/main/resources/static/page/index.html


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/app.30c89522.js


+ 1 - 1
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d0bd283.4869d429.js → industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d0bd283.72cc391d.js

@@ -1 +1 @@
-(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0bd283"],{"2b96":function(e,t,r){"use strict";r.r(t);var o=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("iframe",{style:{height:"90vh",width:"100%",border:"none",display:"block"},attrs:{id:"myIframe",src:e.iframeSrc},on:{load:e.load}})},n=[],s=r("5f87"),i={watch:{"$route.query.t":{handler:function(e,t){this.sendMsg({cmd:"show",data:{reportId:this.$route.query.id}})}}},data:function(){return{reportId:this.$route.query.id,type:this.$route.query.type,files:this.$route.query.files,iframeSrc:"/reportSheet/index.html"}},methods:{load:function(){var e=this,t=localStorage.getItem("IMPORT_FILES_JSON");e.sendMsg({cmd:"init",data:{token:Object(s["c"])(),url:"",reportId:this.reportId,type:this.type,files:t}}),localStorage.setItem("IMPORT_FILES_JSON",""),window.addEventListener("message",(function(t){var r=t.data;"close"===r.cmd&&e.$router.go(-1)}))},sendMsg:function(e){document.getElementById("myIframe").contentWindow.postMessage(e,"*")}},destroyed:function(){window.removeEventListener("message",(function(e){console.log(e)}))}},d=i,a=r("2877"),c=Object(a["a"])(d,o,n,!1,null,null,null);t["default"]=c.exports}}]);
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0bd283"],{"2b96":function(e,t,r){"use strict";r.r(t);var o=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("iframe",{style:{height:"90vh",width:"100%",border:"none",display:"block"},attrs:{id:"myIframe",src:e.iframeSrc},on:{load:e.load}})},n=[],s=r("5f87"),i={watch:{"$route.query.t":{handler:function(e,t){this.sendMsg({cmd:"show",data:{reportId:this.$route.query.id}})}}},data:function(){return{reportId:this.$route.query.id,type:this.$route.query.type,files:this.$route.query.files,iframeSrc:"/reportSheet/index.html"}},methods:{load:function(){var e=this,t=localStorage.getItem("IMPORT_FILES_JSON");e.sendMsg({cmd:"init",data:{token:Object(s["c"])(),url:"",reportId:this.reportId,type:this.type,files:t}}),localStorage.setItem("IMPORT_FILES_JSON",""),window.addEventListener("message",(function(t){var r=t.data;"close"===r.cmd&&e.$router.go(-1)}))},sendMsg:function(e){document.getElementById("myIframe").contentWindow.postMessage(e,"*")}},destroyed:function(){window.removeEventListener("message",(function(e){console.log(e)}))}},d=i,a=r("2877"),c=Object(a["a"])(d,o,n,!1,null,null,null);t["default"]=c.exports}}]);

+ 1 - 1
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d213e6a.47e896e4.js → industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2d213e6a.6727e252.js

@@ -1 +1 @@
-(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d213e6a"],{af3b:function(e,t,n){"use strict";n.r(t);var r=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",[n("iframe",{style:{height:"90vh",width:"100%",border:"none",display:"block"},attrs:{id:"myIframe",src:e.iframeSrc},on:{load:e.sendToken}})])},o=[],s=n("5f87"),d={watch:{"$route.query.t":{handler:function(e,t){this.sendMsg({cmd:"show",data:{reportId:this.$route.query.id}})}}},data:function(){return{reportId:this.$route.query.id,iframeSrc:"/reportSheet/report-history.html"}},methods:{sendToken:function(){var e=this;e.sendMsg({cmd:"init",data:{token:Object(s["c"])(),url:"",reportId:this.reportId}}),window.addEventListener("message",(function(t){var n=t.data;"close"===n.cmd&&e.$router.go(-1)}))},sendMsg:function(e){document.getElementById("myIframe").contentWindow.postMessage(e,"*")}},destroyed:function(){window.removeEventListener("message",(function(e){console.log(e)}))}},i=d,a=n("2877"),c=Object(a["a"])(i,r,o,!1,null,null,null);t["default"]=c.exports}}]);
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d213e6a"],{af3b:function(e,t,n){"use strict";n.r(t);var r=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",[n("iframe",{style:{height:"90vh",width:"100%",border:"none",display:"block"},attrs:{id:"myIframe",src:e.iframeSrc},on:{load:e.sendToken}})])},o=[],s=n("5f87"),d={watch:{"$route.query.t":{handler:function(e,t){this.sendMsg({cmd:"show",data:{reportId:this.$route.query.id}})}}},data:function(){return{reportId:this.$route.query.id,iframeSrc:"/reportSheet/report-history.html"}},methods:{sendToken:function(){var e=this;e.sendMsg({cmd:"init",data:{token:Object(s["c"])(),url:"",reportId:this.reportId}}),window.addEventListener("message",(function(t){var n=t.data;"close"===n.cmd&&e.$router.go(-1)}))},sendMsg:function(e){document.getElementById("myIframe").contentWindow.postMessage(e,"*")}},destroyed:function(){window.removeEventListener("message",(function(e){console.log(e)}))}},i=d,a=n("2877"),c=Object(a["a"])(i,r,o,!1,null,null,null);t["default"]=c.exports}}]);

文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-2ff9c2aa.4a8669e4.js


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-3c7280bc.326bb34f.js


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-49846205.dcbc3206.js


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-7cd04953.f26dc502.js


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-844beabe.3c156594.js


文件差異過大導致無法顯示
+ 0 - 0
industry-system/industry-da/src/main/resources/static/page/static/js/chunk-c6993184.d61da4a7.js


部分文件因文件數量過多而無法顯示