|
@@ -1,6 +1,8 @@
|
|
|
package com.example.opc_da.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.example.opc_common.entity.Dict;
|
|
|
import com.example.opc_common.entity.ReportTable;
|
|
@@ -21,19 +23,19 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
+@Slf4j
|
|
|
public class ReportTableServiceImpl implements ReportTableService {
|
|
|
|
|
|
@Resource
|
|
@@ -110,6 +112,12 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
if (reportTableDao.addHaveKeyReport(reportTable) <= 0) {
|
|
|
throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "生成数据报表失败");
|
|
|
}
|
|
|
+
|
|
|
+ // 从报表中分析报表、策略、点位关系
|
|
|
+ List<Map<String, Object>> resultList = getReportTableIdAndPolicyIdAndItemIdToMapList(reportTable);
|
|
|
+ // 添加报表、策略、点位关系
|
|
|
+ reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
|
|
|
+
|
|
|
return Result.ok("添加报表模板成功");
|
|
|
}
|
|
|
|
|
@@ -160,6 +168,13 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
if (reportTableDao.updateReportTable(reportTable) <= 0) {
|
|
|
throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "修改数据报表失败");
|
|
|
}
|
|
|
+
|
|
|
+ // 从报表中分析报表、策略、点位关系
|
|
|
+ List<Map<String, Object>> resultList = getReportTableIdAndPolicyIdAndItemIdToMapList(reportTable);
|
|
|
+ // 删除报表、策略、点位关系
|
|
|
+ reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
|
|
|
+ // 添加报表、策略、点位关系
|
|
|
+ reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
|
|
|
return Result.ok("修改报表模板成功");
|
|
|
}
|
|
|
|
|
@@ -224,9 +239,17 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
String reportTableId = reportTable.getId();
|
|
|
reportTableDao.delReportTableById(reportTableId);
|
|
|
reportTableDao.delTableUserGroup(reportTableId);
|
|
|
+
|
|
|
+ // 删除报表、策略、点位关系
|
|
|
+ reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
|
|
|
} else {
|
|
|
//将相应的报表变为逻辑删除
|
|
|
reportTableDao.logicDeleteReportTable(id, templateType, ConstantStr.PUBLIC_IS_DELETE);
|
|
|
+
|
|
|
+ ReportTable reportTable = reportTableDao.getReportTableByTemplate(tableTemplate);
|
|
|
+ String reportTableId = reportTable.getId();
|
|
|
+ // 删除报表、策略、点位关系
|
|
|
+ reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
|
|
|
}
|
|
|
return Result.ok("删除报表成功");
|
|
|
} else {
|
|
@@ -245,6 +268,10 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
reportTableDao.delTableTemplateLogByTtId(id);
|
|
|
//将相应的报表变为逻辑删除
|
|
|
reportTableDao.logicDeleteReportTable(id, templateType, ConstantStr.PUBLIC_IS_DELETE);
|
|
|
+
|
|
|
+ String reportTableId = reportTable.getId();
|
|
|
+ // 删除报表、策略、点位关系
|
|
|
+ reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
|
|
|
return Result.ok("删除报表模板成功");
|
|
|
}
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
@@ -369,6 +396,7 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
reportTableDao.delAutoChLogList(idList);
|
|
|
//删除相应子报表的用户组信息
|
|
|
reportTableDao.delTableUserGroupList(idList);
|
|
|
+
|
|
|
return Result.ok("删除子报表成功");
|
|
|
}
|
|
|
|
|
@@ -472,4 +500,119 @@ public class ReportTableServiceImpl implements ReportTableService {
|
|
|
}
|
|
|
return dictIdList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从报表中分析报表、策略、点位关系
|
|
|
+ * @param reportTable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String, Object>> getReportTableIdAndPolicyIdAndItemIdToMapList(ReportTable reportTable){
|
|
|
+ String reportTableId = reportTable.getId();
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ //解析自动报表结构
|
|
|
+ String reportTableDataStr = reportTable.getReportTableData();
|
|
|
+ JSONObject reportTableData = JSONObject.parseObject(reportTableDataStr);
|
|
|
+
|
|
|
+ //得到sheet数据
|
|
|
+ JSONObject sheet = reportTableData.getJSONObject("sheet");
|
|
|
+ reportTableIdAndPolicyIdAndItemIdToMapListBySheetData(resultList, reportTableId, sheet);
|
|
|
+
|
|
|
+ //得到chart数据
|
|
|
+ JSONObject chart = reportTableData.getJSONObject("chart");
|
|
|
+ reportTableIdAndPolicyIdAndItemIdToMapListByChartData(resultList, reportTableId, chart);
|
|
|
+
|
|
|
+ // 去重排序
|
|
|
+ resultList = resultList.stream().map((map) ->
|
|
|
+ map.getOrDefault("reportTableId","")
|
|
|
+ + "-" + map.getOrDefault("policyId","")
|
|
|
+ + "-" + map.getOrDefault("itemId","")
|
|
|
+ ).distinct().sorted().map((str)->{
|
|
|
+ String[] split = str.split("-");
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("reportTableId", split[0]);
|
|
|
+ map.put("policyId", split[1]);
|
|
|
+ map.put("itemId", split[2]);
|
|
|
+ return map;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //log.info("-------------------resultList");
|
|
|
+ //log.info(JSONUtil.toJsonStr(resultList));
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 遍历sheet所有单元格,获取报表ID,策略ID,点位ID关联关系的list<Map<String, Object>>
|
|
|
+ *
|
|
|
+ * @param resultList
|
|
|
+ * @param reportTableId
|
|
|
+ * @param sheet
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void reportTableIdAndPolicyIdAndItemIdToMapListBySheetData(
|
|
|
+ List<Map<String, Object>> resultList, String reportTableId, JSONObject sheet) {
|
|
|
+ Map<String, Object> resultMap = null;
|
|
|
+ try {
|
|
|
+ JSONArray sheetData = sheet.getJSONArray("data");
|
|
|
+ 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)) {
|
|
|
+ String v = rowCol.getString("v");
|
|
|
+ if(JSONUtil.isJsonObj(v)){
|
|
|
+ JSONObject rowColJson = JSONObject.parseObject(v);
|
|
|
+ //String tableId = rowColJson.getString("tableId");
|
|
|
+ String type = rowColJson.getString("type");
|
|
|
+ if (type.equals("data")) {
|
|
|
+ JSONObject rowColData = rowColJson.getJSONObject("data");
|
|
|
+ resultMap = new HashMap<>();
|
|
|
+ resultMap.put("reportTableId", reportTableId);
|
|
|
+ resultMap.put("policyId", rowColData.getString("policyId"));
|
|
|
+ resultMap.put("itemId", rowColData.getString("itemId"));
|
|
|
+ resultList.add(resultMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取报表ID,策略ID,点位ID关联关系错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 遍历统计图配置信息,获取报表ID,策略ID,点位ID关联关系的list<Map<String, Object>>
|
|
|
+ *
|
|
|
+ * @param resultList
|
|
|
+ * @param reportTableId
|
|
|
+ * @param chart
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void reportTableIdAndPolicyIdAndItemIdToMapListByChartData(
|
|
|
+ List<Map<String, Object>> resultList, String reportTableId, JSONObject chart) {
|
|
|
+ try {
|
|
|
+ for (String key : chart.keySet()) {
|
|
|
+ JSONObject chartData = chart.getJSONObject(key);
|
|
|
+ JSONObject dataForm = chartData.getJSONObject("dataForm");
|
|
|
+ JSONArray items = chartData.getJSONArray("items");
|
|
|
+ String policyId = dataForm.getString("chart-item-group");
|
|
|
+ //获取统计图配置的所有点位
|
|
|
+ List<Map<String, Object>> chartDataList = items.stream().map(v -> {
|
|
|
+ String itemId = ((JSONObject) v).getString("value");
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("reportTableId", reportTableId);
|
|
|
+ resultMap.put("policyId", policyId);
|
|
|
+ resultMap.put("itemId", itemId);
|
|
|
+ return resultMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+// log.info("-------------------chartDataList");
|
|
|
+// log.info(JSONUtil.toJsonStr(chartDataList));
|
|
|
+ resultList.addAll(chartDataList);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取报表ID,策略ID,点位ID关联关系错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|