Procházet zdrojové kódy

修改周期报表启动和不启动查看数据情况

zhoupeng před 1 rokem
rodič
revize
37a350df04

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

@@ -270,7 +270,6 @@ public class ReportTableServiceImpl implements ReportTableService {
      */
     @Override
     public Result getReportTableById(String id) {
-        //如果是子表,则reportTableData使用主表的,生成子表时不生成reportTableData
         ReportTable reportTable = reportTableDao.getReportTableById(id);
         if (Blank.isEmpty(reportTable)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "报表不存在,请刷新再试");

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

@@ -1,5 +1,7 @@
 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;
@@ -14,6 +16,7 @@ import com.example.opc_da.timer.PeriodTimerFactory;
 import com.example.opc_da.timer.QuartzTimerFactory;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -25,7 +28,43 @@ public class AutomaticMaReportTableValidate extends AutomaticReportTableValidate
 
     @Override
     public ReportTable getData(ReportTable reportTable) {
-        return reportTable.setReportTableData(resolveAutoTableData(reportTable.getReportTableData(), LocalDateTime.now()));
+        Integer runState = reportTable.getRunState();
+        if (ConstantStr.START_UP.equals(runState)) {
+            return reportTable.setReportTableData(resolveAutoTableData(reportTable.getReportTableData(), LocalDateTime.now()));
+        }
+        //解析自动报表结构
+        JSONObject reportTableData = JSONObject.parseObject(reportTable.getReportTableData());
+        //得到sheet数据
+        JSONObject sheet = reportTableData.getJSONObject("sheet");
+        JSONArray sheetData = sheet.getJSONArray("data");
+        echoSheet(sheetData, new HashMap<>());
+        sheet.put("data", sheetData);
+        reportTableData.put("sheet", sheet);
+
+        //得到chart数据
+        JSONObject chart = reportTableData.getJSONObject("chart");
+        for (Map.Entry<String, Object> entry : chart.entrySet()) {
+            String entryKey = entry.getKey();
+            //获取统计图的配置信息
+            JSONObject chartJson = chart.getJSONObject(entryKey);
+            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)) {
+                for (int i = 0; i < series.size(); i++) {
+                    JSONObject serieJsonObject = series.getJSONObject(i);
+                    serieJsonObject.put("data", new ArrayList<>());
+                }
+                JSONObject xAxis = chartData.getJSONArray("xAxis").getJSONObject(0);
+                xAxis.put("data", new ArrayList<>());
+            } else if (chartType.equals(ConstantStr.PIE_CHART)) {
+                series.getJSONObject(0).put("data", new ArrayList<>());
+            }
+            chart.put(entryKey, chartJson);
+        }
+        reportTableData.put("chart", chart);
+        return reportTable.setReportTableData(reportTableData.toJSONString());
     }
 
     @Override

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

@@ -87,7 +87,7 @@ public abstract class AutomaticReportTableValidate implements ReportTableValidat
      * @param sheetData
      * @param sheetTableDataMap
      */
-    private void echoSheet(JSONArray sheetData, Map<String, Map<String, List<Item>>> sheetTableDataMap) {
+    protected 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++) {
@@ -102,40 +102,46 @@ public abstract class AutomaticReportTableValidate implements ReportTableValidat
                         if (type.equals("data")) {
                             JSONObject rowColData = rowColJson.getJSONObject("data");
                             String uid = rowColData.getString("uid");
-                            if (Blank.isNotEmpty(uid)) {
-                                List<Item> itemList = sheetTableDataMap.get(tableId) != null ? sheetTableDataMap.get(tableId).get(uid) : null;
-                                if (itemList != null && !itemList.isEmpty()) {
-                                    String value = itemList.get(0).getValue();
-                                    rowCol.put("v", value);
-                                    rowCol.put("m", value);
-                                    itemList.remove(0);
-                                }
+                            if (Blank.isEmpty(uid) || sheetTableDataMap.get(tableId) == null || sheetTableDataMap.get(tableId).get(uid) == null
+                                    || sheetTableDataMap.get(tableId).get(uid).isEmpty()) {
+                                rowCol.put("v", null);
+                                rowCol.put("m", null);
+                            } else {
+                                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")) {
-                            sheetTableDataMap.get(tableId).entrySet().stream().findFirst().ifPresent(entry -> {
-                                List<Item> itemList = entry.getValue();
+                            if (Blank.isEmpty(sheetTableDataMap.get(tableId))
+                                    || sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>()).isEmpty()) {
+                                rowCol.put("v", null);
+                                rowCol.put("m", null);
+                            } else {
+                                List<Item> itemList = sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>());
                                 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) {
                         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", null);
-                                rowCol.put("m", null);
-                            }
+                        if (v.matches(regex) && Arrays.stream(ReportTableBasicItemEnum.values())
+                                .filter(b -> b.name().equals(v.substring(2, v.length() - 1))).findFirst().orElse(null) != null) {
+                            String value = Objects.requireNonNull(Arrays.stream(ReportTableBasicItemEnum.values())
+                                    .filter(b -> b.name().equals(v.substring(2, v.length() - 1))).findFirst().orElse(null)).getValue();
+                            rowCol.put("v", value);
+                            rowCol.put("m", value);
+                        } else {
+                            rowCol.put("v", null);
+                            rowCol.put("m", null);
                         }
                     }
                 }
@@ -408,19 +414,19 @@ public abstract class AutomaticReportTableValidate implements ReportTableValidat
         //如果为柱状图或折线图
         if (chartType.equals(ConstantStr.LINE_CHART) || chartType.equals(ConstantStr.BAR_CHART)) {
             //所有时间数据,组成x轴
-            List<String> allXaiosList = new ArrayList<>();
+            List<String> allAxiosList = 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()));
+                allAxiosList.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());
+            List<String> xAxisList = allAxiosList.stream().distinct().sorted().collect(Collectors.toList());
 
             for (int i = 0; i < series.size(); i++) {
                 JSONObject serieJsonObject = series.getJSONObject(i);