Bladeren bron

1、手动报表、事件驱动报表添加公式处理功能。
2、我的报表、运行配置模块取消分享报表的运行记录的删除功能。
3、系统启动时同时启动设备报表。
4、解决事件驱动报表未替换数据和数据条数错误的问题。
5、事件驱动报表添加值替换和计算功能。

lhy 10 maanden geleden
bovenliggende
commit
0475c624ad

+ 1 - 0
industry-admin/src/views/report/reportTable/index.vue

@@ -199,6 +199,7 @@ export default {
         /** 运行记录 */
         runRecordEvent(row) {
             this.$refs.runRecord.params.autoTableId = row.id
+            this.$refs.runRecord.params.byShare = row.byShare
             this.$refs.runRecord.visible = true
         },
         /** 授权详情 */

+ 4 - 0
industry-admin/src/views/report/reportTable/runRecord.vue

@@ -86,6 +86,9 @@ export default {
                     style: 'color: red;',
                     icon: 'el-icon-delete',
                     methodName: "delReportTableEvent",
+                  hidden: row => {
+                    return  !this.params.byShare
+                  }
                 }
             ],
             tableTotal: 0,
@@ -93,6 +96,7 @@ export default {
                 page: 1,
                 limit: 10,
                 autoTableId: null,
+                byShare: null,
                 reportTableName: null,
                 startTime: null,
                 endTime: null

+ 1 - 0
industry-admin/src/views/report/runConfig/runRecord.vue

@@ -111,6 +111,7 @@ export default {
         },
         /** 弹出层打开事件 */
         handleOpen() {
+            this.isShowCheckbox = this.params.byShare ? false : true
             this.getChReportTable()
         },
         /** 弹出层关闭事件 */

+ 1 - 1
industry-admin/src/views/source/dataQuery/index.vue

@@ -65,7 +65,7 @@
                         </el-col>
                         <el-col :xl="4">
                             <el-form-item label="小数位" prop="decimalPlaces">
-                              <el-select v-model="chartForm.decimalPlaces" filterable clearable placeholder="请选择小数位数">
+                              <el-select v-model="chartForm.decimalPlaces" filterable clearable placeholder="请选择小数位数" style="width: 70px;">
                                 <el-option v-for="(d,index) in decimalPlacesList" :key="index" :label="d.label"
                                            :value="d.value">
                                 </el-option>

+ 2 - 1
industry-system/cqcy-ei-influxdb/src/main/java/com/cqcy/ei/influxdb/entity/Item.java

@@ -3,11 +3,12 @@ package com.cqcy.ei.influxdb.entity;
 import com.cqcy.ei.influxdb.util.InfluxDBUtil;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.time.Instant;
 import java.util.Date;
 
 @Data
-public class Item {
+public class Item implements Serializable {
 
     // 点位名称
     private String name;

+ 19 - 4
industry-system/industry-da/src/main/java/com/example/opc_da/config/MyApplicationRunner.java

@@ -19,10 +19,7 @@ import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.policy.ChangeReportDataPolicyTaskRegister;
 import com.example.opc_da.policy.EventReportDataPolicyTaskRegister;
 import com.example.opc_da.policy.FreReportDataPolicyTaskRegister;
-import com.example.opc_da.task.AutoTableQuartzTask;
-import com.example.opc_da.task.AutoTableTimerTask;
-import com.example.opc_da.task.MonitorTemperatureTimerTask;
-import com.example.opc_da.task.ReportDataPolicyQuartzJob;
+import com.example.opc_da.task.*;
 import com.example.opc_da.timer.PeriodTimerFactory;
 import com.example.opc_da.timer.QuartzTimerFactory;
 import lombok.AllArgsConstructor;
@@ -121,6 +118,24 @@ public class MyApplicationRunner implements ApplicationRunner {
                     }
                 });
             }
+            //将系统原本的设备报表启动
+            reportTableList = reportTableDao.getAllAutoReportTable(ConstantStr.DEVICE_REPORT, ConstantStr.START_UP);
+            if (Blank.isNotEmpty(reportTableList)) {
+                reportTableList.forEach(reportTable -> {
+                    Integer type = reportTable.getType();
+                    String cronId = Blank.isEmpty(reportTable.getCronId()) ?
+                            UUID.randomUUID().toString().replace("-", "") :
+                            reportTable.getCronId();
+                    String cron = reportTable.getCron();
+                    Map<String, Object> tableParamsMap = new HashMap<>();
+                    tableParamsMap.put("reportTable", reportTable);
+                    if (type.equals(0)) {
+                        PeriodTimerFactory.creteTimer().addTask(cronId, DeviceTableTimerTask.class, cron, tableParamsMap);
+                    } else if (type.equals(1)) {
+                        QuartzTimerFactory.creteTimer().addTask(cronId, DeviceTableQuartzTask.class, cron, tableParamsMap);
+                    }
+                });
+            }
 
             // 温度监控
             MonitorTemperatureConectSetting conectSetting = monitorDao.queryMonitorTemperatureConectSettingDtail(null);

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/controller/CollectorController.java

@@ -111,7 +111,7 @@ public class CollectorController {
      * @return
      */
     @GetMapping("client/status")
-    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.COLLECTOR, OperationEnum = OperationEnum.SELECT)
+    //@WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.COLLECTOR, OperationEnum = OperationEnum.SELECT)
     public Result getClientApi(String ip) {
         if (Blank.isEmpty(ip)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS);

+ 27 - 9
industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportTableTask.java

@@ -15,6 +15,7 @@ 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.apache.commons.lang3.SerializationUtils;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.DisposableBean;
 
@@ -96,7 +97,7 @@ public class EventReportTableTask implements DisposableBean {
                 if (optionalPolicyItem.isPresent()) {
                     ReportDataPolicyItem reportDataPolicyItem = optionalPolicyItem.get();
                     value.add(new Item()
-                            .value(reportDataPolicyItem.getDataValue())
+                            .value(reportDataPolicyItem.getCountDataValue())
                             .time(reportDataPolicyItem.getDataTime()));
                 }
             }
@@ -122,8 +123,8 @@ public class EventReportTableTask implements DisposableBean {
                 for (Map.Entry<String, List<Item>> entry : this.itemDataMap.entrySet()) {
                     this.itemDataMap.put(entry.getKey(), new ArrayList<>());
                 }
-            }catch (Exception e){
-                log.error("生成事件驱动报表失败",e);
+            } catch (Exception e) {
+                log.error("生成事件驱动报表失败", e);
             }
         }
     }
@@ -133,8 +134,9 @@ public class EventReportTableTask implements DisposableBean {
      */
     public void generateReportTable() {
         //将解析完的子报表,存入到数据库中
-        asyncTask.updateReportTableDataById(this.reportTable.getId(),this.currentReportTableId
-                , this.currentReportTableData, new HashMap<>(this.itemDataMap));
+        // copyItemDataMap 深度拷贝,this.itemDataMap这个对象一直在变动
+        asyncTask.updateReportTableDataById(this.reportTable.getId(), this.currentReportTableId
+                , this.currentReportTableData, copyItemDataMap(this.itemDataMap));
     }
 
     @Override
@@ -186,10 +188,11 @@ public class EventReportTableTask implements DisposableBean {
         JSONObject reportTableData = JSONObject.parseObject(this.currentReportTableData);
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
-        JSONArray sheetData = sheet.getJSONArray("data");
-        System.err.println("EventReportTableTask.getReportTableDataStr.echoSheetAll");
-        EventReportTableValidate.echoSheetAll(this.reportTable.getId(), sheetData, this.itemDataMap);
-        sheet.put("data", sheetData);
+        //JSONArray sheetData = sheet.getJSONArray("data");
+
+        // copyItemDataMap 深度拷贝,this.itemDataMap这个对象一直在变动
+        EventReportTableValidate.echoSheetAll(this.reportTable.getId(), sheet, copyItemDataMap(this.itemDataMap));
+        //sheet.put("data", sheetData);
         return reportTableData.toJSONString();
     }
 
@@ -291,4 +294,19 @@ public class EventReportTableTask implements DisposableBean {
         return sheetTableMap;
     }
 
+    private Map<String, List<Item>> copyItemDataMap(Map<String, List<Item>> itemDataMap) {
+        Map<String, List<Item>> itemDataMapAll = new HashMap<>();
+        if (CollUtil.isNotEmpty(itemDataMap)) {
+            Set<Map.Entry<String, List<Item>>> entries = itemDataMap.entrySet();
+            for (Map.Entry<String, List<Item>> entry : entries) {
+                List<Item> valueList = entry.getValue();
+                List<Item> copyValueList = new ArrayList<>();
+                for (Item item : valueList) {
+                    copyValueList.add(SerializationUtils.clone(item));
+                }
+                itemDataMapAll.put(entry.getKey(), copyValueList);
+            }
+        }
+        return itemDataMapAll;
+    }
 }

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

@@ -2,7 +2,6 @@ package com.example.opc_da.task;
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cqcy.ei.influxdb.entity.Item;
 import com.cqcy.ei.influxdb.service.InFluxDBService;
@@ -133,10 +132,9 @@ public class AsyncTask {
         JSONObject reportTableData = JSONObject.parseObject(reportTableDataStr);
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
-        JSONArray sheetData = sheet.getJSONArray("data");
-        System.err.println("AsyncTask.updateReportTableDataById.echoSheetAll");
-        EventReportTableValidate.echoSheetAll(mainReportTableId, sheetData, itemDataMap);
-        sheet.put("data", sheetData);
+        //JSONArray sheetData = sheet.getJSONArray("data");
+        EventReportTableValidate.echoSheetAll(mainReportTableId, sheet, itemDataMap);
+        //sheet.put("data", sheetData);
         reportTableDao.updateReportTableDataById(reportTableId, reportTableData.toJSONString());
 
     }

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

@@ -2,7 +2,6 @@ package com.example.opc_da.validate.reportTable;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.LocalDateTimeUtil;
-import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cqcy.ei.influxdb.entity.Item;
@@ -134,11 +133,11 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                             continue;
                         }
                         JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("celldata"));
-                        if(Blank.isEmpty(rowColJson)){
+                        if (Blank.isEmpty(rowColJson)) {
                             continue;
                         }
                         String type = rowColJson.getString("type");
-                        if(Blank.isEmpty(type)){
+                        if (Blank.isEmpty(type)) {
                             continue;
                         }
                         String tableId = rowColJson.getString("tableId");
@@ -182,7 +181,7 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                             rowCol.put("m", item.get("countTime"));
                         }
                     } catch (Exception e) {
-                        log.error("设备报表解析数据出错",e);
+                        log.error("设备报表解析数据出错", e);
                     }
                 }
             }
@@ -220,14 +219,14 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                                 }
                             } else if ("index".equals(type)) {
                                 // ws新增设备逻辑
-                              if (Blank.isEmpty(sheetTableMap.get(tableId + "_deviceIndex"))) {
-
-                                  sheetTableMap.put(tableId + "_deviceIndex", new HashMap<String, JSONObject>() {
-                                          {
-                                              put("data", rowColJson);
-                                          }
-                                  });
-                              }
+                                if (Blank.isEmpty(sheetTableMap.get(tableId + "_deviceIndex"))) {
+
+                                    sheetTableMap.put(tableId + "_deviceIndex", new HashMap<String, JSONObject>() {
+                                        {
+                                            put("data", rowColJson);
+                                        }
+                                    });
+                                }
                             }
                         }
                         String calcCell = rowCol.getString("f");
@@ -268,7 +267,6 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
         List<JSONObject> tableJsonObjectList = new ArrayList<>(sheetUidMap.values());
 
 
-
         //因为单个区域内的配置一样,且归属于同一个报表采集策略,所以直接查询
         //得到此配置信息中,所有的数据
         List<Item> allitemList = getItems(referTime, tableJsonObjectList, tableJsonObjectList.get(0), settingMap);
@@ -277,11 +275,9 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
     }
 
 
-
     /**
      * 计算单个uid,分割之后的数据
      *
-     * @param jsonObject
      * @param itemList
      * @param referTime
      * @return
@@ -422,9 +418,6 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
     }
 
 
-
-
-
     /**
      * 通过开始时间和结束时间分割数据,并计算
      *
@@ -438,7 +431,7 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
      * @return
      */
     private List<Map<String, String>> splitData(String dataValueType, List<Item> itemList, LocalDateTime startDateTime, LocalDateTime endDateTime,
-                                 Integer valueTakingMode, Integer bucketType, Integer bucketValue, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale, JSONObject settingMap) {
+                                                Integer valueTakingMode, Integer bucketType, Integer bucketValue, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale, JSONObject settingMap) {
         List<Map<String, String>> newItemList = new ArrayList<>();
         JSONObject setting = settingMap.getJSONObject("setting");
         String var1 = setting.getString("var1");
@@ -509,7 +502,7 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
     }
 
     private Map<String, String> handleItemList(LocalDateTime time1, LocalDateTime time2, Integer isGenCountTime, String var1, String var2,
-                                List<Item> itemList, Integer valueTakingMode, boolean status, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale) {
+                                               List<Item> itemList, Integer valueTakingMode, boolean status, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale) {
         Map<String, List<Item>> map = itemList.stream().filter(item -> {
             LocalDateTime time = LocalDateTime.parse(item.getTime(), DateTimeFormatter.ofPattern(timePattern));
             return !item.getName().equals(var1) && !item.getName().equals(var2) && (time.isAfter(time1) || time.isEqual(time1))
@@ -525,11 +518,11 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                     if (first.isPresent()) {
                         scale = first.get().getScale();
                     }
-            String val = CalculateDataFactory.getCalculateData(valueTakingMode).calculateData(
-                    entry.getValue().stream().filter(distinctByKey1(Item::getTime))
-                            .sorted(Comparator.comparing(item -> LocalDateTime.parse(item.getTime(), DateTimeFormatter.ofPattern(timePattern))))
-                            .map(Item::getValue).collect(Collectors.toList()), scale, defaultScale);
-                  return Convert.toStr(val, "");
+                    String val = CalculateDataFactory.getCalculateData(valueTakingMode).calculateData(
+                            entry.getValue().stream().filter(distinctByKey1(Item::getTime))
+                                    .sorted(Comparator.comparing(item -> LocalDateTime.parse(item.getTime(), DateTimeFormatter.ofPattern(timePattern))))
+                                    .map(Item::getValue).collect(Collectors.toList()), scale, defaultScale);
+                    return Convert.toStr(val, "");
                 }
         ));
         data.put("startTime", LocalDateTimeUtil.format(time1, timePattern));

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

@@ -1,7 +1,6 @@
 package com.example.opc_da.validate.reportTable;
 
 import cn.hutool.extra.servlet.ServletUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.ReportTable;
 import com.example.opc_common.enums.ResultEnum;
@@ -35,10 +34,10 @@ public class EventMaReportTableValidate extends EventReportTableValidate {
             JSONObject reportTableDataJson = JSONObject.parseObject(reportTable.getReportTableData());
             //得到sheet数据
             JSONObject sheet = reportTableDataJson.getJSONObject("sheet");
-            JSONArray sheetData = sheet.getJSONArray("data");
-            echoSheetAll(reportTable.getId(), sheetData, null);
-            sheet.put("data", sheetData);
-            reportTableDataJson.put("sheet", sheet);
+            //JSONArray sheetData = sheet.getJSONArray("data");
+            echoSheetAll(reportTable.getId(), sheet, null);
+            //sheet.put("data", sheetData);
+            //reportTableDataJson.put("sheet", sheet);
             return reportTable.setReportTableData(reportTableDataJson.toJSONString());
         } else {
             throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "运行状态异常");

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

@@ -2,7 +2,6 @@ package com.example.opc_da.validate.reportTable;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.convert.Convert;
-import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cqcy.ei.influxdb.entity.Item;
@@ -35,31 +34,28 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
 
 
     /**
-     *
-     * @param value 原值
-     * @param policyItemId 策略点位ID
+     * @param value         原值
+     * @param policyItemId  策略点位ID
      * @param itemScaleList 点位小数位数集合
-     * @param defaultScale 默认小数位数
+     * @param defaultScale  默认小数位数
      * @return
      */
-    private static String replaceValueByScale(String value,String policyItemId,List<ReportDataPolicyItem> itemScaleList, Integer defaultScale){
-        if(Blank.isEmpty(value)){
+    private static String replaceValueByScale(String value, String policyItemId, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale) {
+        if (Blank.isEmpty(value)) {
             return value;
         }
-        //log.info("事件驱动报表:EventReportTableValidate.itemScaleList=" + itemScaleList.toString() + ",policyItemId=" + policyItemId);
         Optional<ReportDataPolicyItem> first = itemScaleList.stream()
                 .filter((item) -> policyItemId.equals(item.getId().toString()))
                 .findFirst();
         Integer scale = null;
         if (first.isPresent()) {
             scale = first.get().getScale();
-            //log.info("事件驱动报表:EventReportTableValidate.scale=" + scale);
         }
-        if(Blank.isEmpty(scale)){
+        if (Blank.isEmpty(scale)) {
             scale = defaultScale;
         }
-        if(!(scale == null || scale == -1)){
-            BigDecimal original  = new BigDecimal(value);
+        if (!(scale == null || scale == -1)) {
+            BigDecimal original = new BigDecimal(value);
             BigDecimal rounded = original.setScale(scale, RoundingMode.HALF_UP);
             value = String.valueOf(rounded);
         }
@@ -69,21 +65,24 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
     /**
      * 回填表格数据,如果没得数据回填,则全部为空
      *
-     * @param sheetData
+     * @param sheet
      * @param itemDataMap
      */
-    public static void echoSheetAll(String reportTableId, JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
+    public static void echoSheetAll(String reportTableId, JSONObject sheet, Map<String, List<Item>> itemDataMap) {
+
+        JSONArray sheetData = sheet.getJSONArray("data");
+        String index = sheet.getString("index");
         log.info("事件驱动报表:EventReportTableValidate.reportTableId=" + reportTableId);
         Integer defaultScale = null;
         List<ReportDataPolicyItem> itemScaleList = null;
-        if(CollUtil.isNotEmpty(itemDataMap)){
+        if (CollUtil.isNotEmpty(itemDataMap)) {
             // 数据组未配置点位数据的小数位数,从字典中获取默认小数位数
             DictType dictType = dictDao.queryDictTypeByKeyType("item_scale", null);
             defaultScale = Convert.toInt(dictType.getDictKeyValue());
             itemScaleList = reportTableDao.getItemScaleByReportTableIdOrPolicyIdOrItemId(reportTableId, null, null);
         }
         String eventPolicyItemId = null;
-        if(CollUtil.isNotEmpty(itemDataMap)) {
+        if (CollUtil.isNotEmpty(itemDataMap)) {
             String eventItemId = itemDataMap.entrySet()
                     .stream()
                     .findFirst()
@@ -92,6 +91,7 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
             eventPolicyItemId = reportDataPolicyDao.getEventPolicyItemIdByEventItemId(eventItemId);
         }
 
+        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++) {
@@ -118,11 +118,11 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                             continue;
                         }
                         JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("celldata"));
-                        if(Blank.isEmpty(rowColJson)){
+                        if (Blank.isEmpty(rowColJson)) {
                             continue;
                         }
                         String type = rowColJson.getString("type");
-                        if(Blank.isEmpty(type)){
+                        if (Blank.isEmpty(type)) {
                             continue;
                         }
                         //如果类型为数据,则存入数据
@@ -132,11 +132,12 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                             if (Blank.isEmpty(itemId)) {
                                 continue;
                             }
-                            if(CollUtil.isEmpty(itemDataMap)){
+                            if (CollUtil.isEmpty(itemDataMap)) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
                                 continue;
-                            };
+                            }
+                            ;
                             List<Item> itemList = itemDataMap.get(itemId);
                             if (CollUtil.isEmpty(itemList)) {
                                 rowCol.put("v", null);
@@ -152,11 +153,12 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                         }
                         //如果类型为时间,则存入时间
                         if (type.equals("datatime")) {
-                            if(CollUtil.isEmpty(itemDataMap)){
+                            if (CollUtil.isEmpty(itemDataMap)) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
                                 continue;
-                            };
+                            }
+                            ;
                             String finalEventPolicyItemId = eventPolicyItemId;
                             List<Item> itemList = itemDataMap.entrySet()
                                     .stream()
@@ -174,11 +176,33 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                             rowCol.put("v", time);
                             rowCol.put("m", time);
                         }
+                        String calcCell = rowCol.getString("f");
+                        if (Blank.isNotEmpty(calcCell)) {
+                            JSONObject calcChain = new JSONObject();
+                            calcChain.put("r", i);
+                            calcChain.put("c", j);
+                            calcChain.put("index", index);
+
+                            Map<String, JSONObject> sheetCalcMap = sheetTableMap.get("calcChain");
+                            if (Blank.isEmpty(sheetCalcMap)) sheetCalcMap = new HashMap<>();
+                            String cell = String.format("%d_%d", i, j);
+                            if (Blank.isEmpty(sheetCalcMap.get(cell)) && Blank.isNotEmpty(cell)) {
+                                sheetCalcMap.put(cell, calcChain);
+                                sheetTableMap.put("calcChain", sheetCalcMap);
+                            }
+
+                        }
                     } catch (Exception e) {
-                        log.error("事件驱动报表解析数据出错",e);
+                        log.error("事件驱动报表解析数据出错", e);
                     }
                 }
             }
         }
+        if (Blank.isNotEmpty(sheetTableMap.get("calcChain"))) {
+            //处理公式
+            sheet.put("calcChain", sheetTableMap.get("calcChain").values().toArray());
+            //清除公式
+            sheetTableMap.remove("calcChain");
+        }
     }
 }

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

@@ -102,8 +102,16 @@ public class ManualReportTableValidate implements ReportTableValidate {
      */
     private JSONObject resolveAutoTableSheetData(JSONObject sheet, LocalDateTime referTime, List<ReportDataPolicyItem> itemScaleList, Integer defaultScale) {
         JSONArray sheetData = sheet.getJSONArray("data");
+        String sheetIndex = sheet.getString("index");
         //遍历sheet所有单元格,并存为Map<tableId,Map<uid,JSONObject>>格式
-        Map<String, Map<String, JSONObject>> sheetTableMap = getAutoStringMapMap(sheetData);
+        Map<String, Map<String, JSONObject>> sheetTableMap = getAutoStringMapMap(sheetData, sheetIndex);
+        //
+        if (Blank.isNotEmpty(sheetTableMap.get("calcChain"))) {
+            //处理公式
+            sheet.put("calcChain", sheetTableMap.get("calcChain").values().toArray());
+            //清除公式
+            sheetTableMap.remove("calcChain");
+        }
 
         //遍历生成的sheetTableMap,根据配置获取数据,并存为Map<tableId, Map<uid,List<Item>>>格式
         Map<String, Map<String, List<Item>>> sheetTableDataMap = new HashMap<>();
@@ -141,7 +149,7 @@ public class ManualReportTableValidate implements ReportTableValidate {
      * @return
      */
     @NotNull
-    private static Map<String, Map<String, JSONObject>> getAutoStringMapMap(JSONArray sheetData) {
+    private static Map<String, Map<String, JSONObject>> getAutoStringMapMap(JSONArray sheetData, String index) {
         Map<String, Map<String, JSONObject>> sheetTableMap = new HashMap<>();
         for (int i = 0; i < sheetData.size(); i++) {
             JSONArray row = sheetData.getJSONArray(i);
@@ -166,6 +174,22 @@ public class ManualReportTableValidate implements ReportTableValidate {
                                 }
                             }
                         }
+                        String calcCell = rowCol.getString("f");
+                        if (Blank.isNotEmpty(calcCell)) {
+                            JSONObject calcChain = new JSONObject();
+                            calcChain.put("r", i);
+                            calcChain.put("c", j);
+                            calcChain.put("index", index);
+
+                            Map<String, JSONObject> sheetCalcMap = sheetTableMap.get("calcChain");
+                            if (Blank.isEmpty(sheetCalcMap)) sheetCalcMap = new HashMap<>();
+                            String cell = String.format("%d_%d", i, j);
+                            if (Blank.isEmpty(sheetCalcMap.get(cell)) && Blank.isNotEmpty(cell)) {
+                                sheetCalcMap.put(cell, calcChain);
+                                sheetTableMap.put("calcChain", sheetCalcMap);
+                            }
+
+                        }
                     } catch (Exception e) {
                         log.error("遍历sheet所有单元格失败", e);
                     }
@@ -575,11 +599,11 @@ public class ManualReportTableValidate implements ReportTableValidate {
                             continue;
                         }
                         JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("celldata"));
-                        if(Blank.isEmpty(rowColJson)){
+                        if (Blank.isEmpty(rowColJson)) {
                             continue;
                         }
                         String type = rowColJson.getString("type");
-                        if(Blank.isEmpty(type)){
+                        if (Blank.isEmpty(type)) {
                             continue;
                         }
                         String tableId = rowColJson.getString("tableId");
@@ -620,7 +644,7 @@ public class ManualReportTableValidate implements ReportTableValidate {
                             rowCol.put("m", time);
                         }
                     } catch (Exception e) {
-                        log.error("手动报表解析数据出错",e);
+                        log.error("手动报表解析数据出错", e);
                     }
                 }
             }