|
@@ -1,23 +1,66 @@
|
|
|
package com.example.opc_da.validate.reportTable;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.cqcy.ei.influxdb.entity.Item;
|
|
|
+import com.example.opc_common.entity.DictType;
|
|
|
+import com.example.opc_common.entity.ReportDataPolicyItem;
|
|
|
import com.example.opc_common.util.Blank;
|
|
|
import com.example.opc_da.config.SpringContextUtils;
|
|
|
+import com.example.opc_da.dao.DictDao;
|
|
|
+import com.example.opc_da.dao.ReportTableDao;
|
|
|
import com.example.opc_da.policy.EventReportDataPolicyTaskRegister;
|
|
|
+import com.example.opc_da.task.ReportTableBasicItemEnum;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 事件报表验证抽象类
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
public abstract class EventReportTableValidate implements ReportTableValidate {
|
|
|
|
|
|
- EventReportDataPolicyTaskRegister eventReportDataPolicyTaskRegister = SpringContextUtils.getBean(EventReportDataPolicyTaskRegister.class);
|
|
|
+ public EventReportDataPolicyTaskRegister eventReportDataPolicyTaskRegister = SpringContextUtils.getBean(EventReportDataPolicyTaskRegister.class);
|
|
|
+ private static ReportTableDao reportTableDao = SpringContextUtils.getBean(ReportTableDao.class);
|
|
|
+ private static DictDao dictDao = SpringContextUtils.getBean(DictDao.class);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param value 原值
|
|
|
+ * @param policyItemId 策略点位ID
|
|
|
+ * @param itemScaleList 点位小数位数集合
|
|
|
+ * @param defaultScale 默认小数位数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String replaceValueByScale(String value,String policyItemId,List<ReportDataPolicyItem> itemScaleList, Integer defaultScale){
|
|
|
+ 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)){
|
|
|
+ scale = defaultScale;
|
|
|
+ }
|
|
|
+ if(!(scale == null || scale == -1)){
|
|
|
+ BigDecimal original = new BigDecimal(value);
|
|
|
+ BigDecimal rounded = original.setScale(scale, RoundingMode.HALF_UP);
|
|
|
+ value = String.valueOf(rounded);
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 回填表格数据,如果没得数据回填,则全部为空
|
|
@@ -25,7 +68,16 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
|
|
|
* @param sheetData
|
|
|
* @param itemDataMap
|
|
|
*/
|
|
|
- public static void echoSheetAll(JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
|
|
|
+ public static void echoSheetAll(String reportTableId, JSONArray sheetData, Map<String, List<Item>> itemDataMap) {
|
|
|
+ log.info("事件驱动报表:EventReportTableValidate.reportTableId=" + reportTableId);
|
|
|
+ Integer defaultScale = null;
|
|
|
+ List<ReportDataPolicyItem> itemScaleList = null;
|
|
|
+ if(CollUtil.isNotEmpty(itemDataMap)){
|
|
|
+ // 数据组未配置点位数据的小数位数,从字典中获取默认小数位数
|
|
|
+ DictType dictType = dictDao.queryDictTypeByKeyType("item_scale", null);
|
|
|
+ defaultScale = Convert.toInt(dictType.getDictKeyValue());
|
|
|
+ itemScaleList = reportTableDao.getItemScaleByReportTableIdOrPolicyIdOrItemId(reportTableId, null, null);
|
|
|
+ }
|
|
|
for (int i = 0; i < sheetData.size(); i++) {
|
|
|
JSONArray row = sheetData.getJSONArray(i);
|
|
|
for (int j = 0; j < row.size(); j++) {
|
|
@@ -47,6 +99,7 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
|
|
|
List<Item> itemList = itemDataMap.get(itemId);
|
|
|
if (CollUtil.isNotEmpty(itemList)) {
|
|
|
String value = itemList.get(0).getValue();
|
|
|
+ value = replaceValueByScale(value, itemId, itemScaleList, defaultScale);
|
|
|
rowCol.put("v", value);
|
|
|
rowCol.put("m", value);
|
|
|
itemList.remove(0);
|
|
@@ -77,7 +130,21 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
+ String v = rowCol.getString("v");
|
|
|
+ String regex = "^\\$\\{.*\\}$";
|
|
|
+ //赋值基础数据项
|
|
|
+ if (v != null && v.matches(regex)) {
|
|
|
+ if (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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|