|
@@ -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");
|
|
|
+ }
|
|
|
}
|
|
|
}
|