diff --git a/mh-admin/src/test/java/com/mh/MHApplicationTest.java b/mh-admin/src/test/java/com/mh/MHApplicationTest.java
index 98231c4..29d889d 100644
--- a/mh-admin/src/test/java/com/mh/MHApplicationTest.java
+++ b/mh-admin/src/test/java/com/mh/MHApplicationTest.java
@@ -7,6 +7,7 @@ import com.mh.common.core.domain.entity.DeviceReport;
import com.mh.common.core.domain.entity.SysParams;
import com.mh.common.core.domain.entity.SysUser;
import com.mh.common.core.domain.entity.WeatherData;
+import com.mh.common.core.domain.vo.EnergyQueryVO;
import com.mh.common.utils.DateUtils;
import com.mh.common.utils.StringUtils;
import com.mh.quartz.task.DealDataTask;
@@ -18,6 +19,7 @@ import com.mh.system.service.ISysUserService;
import com.mh.system.service.device.IDeviceQrManageService;
import com.mh.system.service.operation.IAlarmRecordsService;
import com.mh.system.service.overview.IProOverviewService;
+import com.mh.system.service.report.IComprehensiveReportService;
import com.mh.system.service.report.IMeterReadingsHisService;
import com.mh.system.service.report.IReportHotWaterService;
import jakarta.annotation.Resource;
@@ -61,6 +63,23 @@ public class MHApplicationTest {
@Autowired
private IProOverviewService proOverviewService;
+ @Autowired
+ private IComprehensiveReportService comprehensiveReportService;
+
+ @Test
+ public void comprehensiveReport() {
+ long startTime = System.currentTimeMillis();
+ EnergyQueryVO vo = new EnergyQueryVO();
+ vo.setStartTime("2025-12-24 00:00:00");
+ vo.setEndTime("2025-12-24 23:59:59");
+ vo.setPageNum(1);
+ vo.setPageSize(10);
+ vo.setTimeType("hour");
+ System.out.println("开始查询");
+ List> report = comprehensiveReportService.report(vo);
+ System.out.println("报表耗时:" + (System.currentTimeMillis() - startTime) + "ms");
+ }
+
@Test
public void testHome() throws Exception {
// 开始计时
@@ -76,7 +95,7 @@ public class MHApplicationTest {
@Test
public void testExecProMeterReadingsHis() {
- meterReadingsHisService.execProMeterReadingsHis("2025-10-22");
+ meterReadingsHisService.execProMeterReadingsHis("2025-12-11");
}
@Test
diff --git a/mh-common/src/main/java/com/mh/common/constant/CacheConstants.java b/mh-common/src/main/java/com/mh/common/constant/CacheConstants.java
index 0441c75..130c56a 100644
--- a/mh-common/src/main/java/com/mh/common/constant/CacheConstants.java
+++ b/mh-common/src/main/java/com/mh/common/constant/CacheConstants.java
@@ -41,4 +41,14 @@ public class CacheConstants
* 登录账户密码错误次数 redis key
*/
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
+
+ /**
+ * 获取项目概况
+ */
+ public static final String PRO_PROFILE = "pro_profile";
+
+ /**
+ * 首页各个采集类型月数据
+ */
+ public static final String ENERGY_ANALYSIS = "energy_analysis";
}
diff --git a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java
index ce4dc54..c2187a2 100644
--- a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java
+++ b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java
@@ -280,7 +280,6 @@ public class DataProcessServiceImpl implements DataProcessService {
entity = dataProcessMapper.queryLastValue(deviceNum, lastTable);
} catch (Exception e) {
log.error("没有当前表:{}", lastTable);
- e.printStackTrace();
}
}
return entity;
diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/HomeTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/HomeTask.java
new file mode 100644
index 0000000..8796f83
--- /dev/null
+++ b/mh-quartz/src/main/java/com/mh/quartz/task/HomeTask.java
@@ -0,0 +1,38 @@
+package com.mh.quartz.task;
+
+import com.mh.common.constant.CacheConstants;
+import com.mh.common.core.redis.RedisCache;
+import com.mh.system.service.overview.IProOverviewService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project EEMCS
+ * @description 首页任务
+ * @date 2025-12-24 09:04:57
+ */
+@Slf4j
+@Component("homeTask")
+public class HomeTask {
+
+ @Autowired
+ private IProOverviewService proOverviewService;
+
+ @Autowired
+ private RedisCache redisCache;
+
+ public void updateHomeData() {
+ if (redisCache.hasKey(CacheConstants.PRO_PROFILE)) {
+ redisCache.deleteObject(CacheConstants.PRO_PROFILE);
+ }
+ proOverviewService.getProProfile();
+ if (redisCache.hasKey(CacheConstants.ENERGY_ANALYSIS)) {
+ redisCache.deleteObject(CacheConstants.ENERGY_ANALYSIS);
+ }
+ proOverviewService.energyAnalysis();
+ }
+
+}
diff --git a/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java b/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java
index e0449fa..34cdaad 100644
--- a/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java
+++ b/mh-system/src/main/java/com/mh/system/mapper/report/ComprehensiveReportMapper.java
@@ -36,88 +36,57 @@ public interface ComprehensiveReportMapper {
@Select("")
- List energyAnalysisManyTable(@Param("deviceNums") List deviceNums,
- @Param("lastTableName") String lastTableName,
- @Param("curTableName") String curTableName,
- @Param("startTime") Date startTime,
- @Param("endTime") Date endTime,
- @Param("timeType") String timeType);
+ "WITH combined_data AS ( " +
+ " SELECT " +
+ " CASE " +
+ " WHEN #{timeType} = 'year' THEN to_char(date_trunc('year', cur_time), 'YYYY') " +
+ " WHEN #{timeType} = 'month' THEN to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " WHEN #{timeType} = 'day' THEN to_char(date_trunc('day', cur_time), 'YYYY-MM-DD') " +
+ " WHEN #{timeType} = 'hour' THEN to_char(date_trunc('hour', cur_time), 'YYYY-MM-DD HH24') " +
+ " ELSE to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " END AS period, " +
+ " calc_value " +
+ " FROM ${lastTableName} " +
+ " WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp " +
+ " " +
+ " AND device_num IN " +
+ " " +
+ " #{item.mtNum} " +
+ " " +
+ " " +
+ " UNION ALL " +
+ " SELECT " +
+ " CASE " +
+ " WHEN #{timeType} = 'year' THEN to_char(date_trunc('year', cur_time), 'YYYY') " +
+ " WHEN #{timeType} = 'month' THEN to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " WHEN #{timeType} = 'day' THEN to_char(date_trunc('day', cur_time), 'YYYY-MM-DD') " +
+ " WHEN #{timeType} = 'hour' THEN to_char(date_trunc('hour', cur_time), 'YYYY-MM-DD HH24') " +
+ " ELSE to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " END AS period, " +
+ " calc_value " +
+ " FROM ${curTableName} " +
+ " WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp " +
+ " " +
+ " AND device_num IN " +
+ " " +
+ " #{item.mtNum} " +
+ " " +
+ " " +
+ ") " +
+ "SELECT " +
+ " period AS name, " +
+ " SUM(calc_value) AS value " +
+ "FROM combined_data " +
+ "GROUP BY period " +
+ "ORDER BY period; " +
+ "")
+List energyAnalysisManyTable(@Param("deviceNums") List deviceNums,
+ @Param("lastTableName") String lastTableName,
+ @Param("curTableName") String curTableName,
+ @Param("startTime") Date startTime,
+ @Param("endTime") Date endTime,
+ @Param("timeType") String timeType);
+
@Select("")
- List energyAnalysisOneTable(@Param("deviceNums") List deviceNums,
- @Param("lastTableName") String lastTableName,
- @Param("curTableName") String curTableName,
- @Param("startTime") Date startTime,
- @Param("endTime") Date endTime,
- @Param("timeType") String timeType);
+ "WITH time_bucketed_data AS ( " +
+ " SELECT " +
+ " CASE " +
+ " WHEN #{timeType} = 'year' THEN to_char(date_trunc('year', cur_time), 'YYYY') " +
+ " WHEN #{timeType} = 'month' THEN to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " WHEN #{timeType} = 'day' THEN to_char(date_trunc('day', cur_time), 'YYYY-MM-DD') " +
+ " WHEN #{timeType} = 'hour' THEN to_char(date_trunc('hour', cur_time), 'YYYY-MM-DD HH24') " +
+ " ELSE to_char(date_trunc('month', cur_time), 'YYYY-MM') " +
+ " END AS period, " +
+ " calc_value " +
+ " FROM ${lastTableName} " +
+ " WHERE cur_time >= #{startTime}::timestamp AND cur_time <= #{endTime}::timestamp " +
+ " " +
+ " AND device_num IN " +
+ " " +
+ " #{item.mtNum} " +
+ " " +
+ " " +
+ ") " +
+ "SELECT " +
+ " period AS name, " +
+ " SUM(calc_value) AS value " +
+ "FROM time_bucketed_data " +
+ "GROUP BY period " +
+ "ORDER BY period; " +
+ "")
+List energyAnalysisOneTable(@Param("deviceNums") List deviceNums,
+ @Param("lastTableName") String lastTableName,
+ @Param("curTableName") String curTableName,
+ @Param("startTime") Date startTime,
+ @Param("endTime") Date endTime,
+ @Param("timeType") String timeType);
+
}
diff --git a/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java
index 567fd94..f9bd2b0 100644
--- a/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java
+++ b/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java
@@ -1,14 +1,14 @@
package com.mh.system.service.overview.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mh.common.constant.CacheConstants;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.dto.DeviceMonitorDTO;
import com.mh.common.core.domain.dto.OverviewEnergyDTO;
import com.mh.common.core.domain.dto.ProProfileDTO;
-import com.mh.common.core.domain.entity.ChillersEntity;
import com.mh.common.core.domain.entity.CollectionParamsManage;
-import com.mh.common.core.domain.entity.DataMonth;
import com.mh.common.core.domain.entity.SysDictData;
+import com.mh.common.core.redis.RedisCache;
import com.mh.common.utils.DateUtils;
import com.mh.system.mapper.SysDictDataMapper;
import com.mh.system.mapper.device.CollectionParamsManageMapper;
@@ -35,13 +35,16 @@ import java.util.stream.Stream;
@Service
public class ProOverviewServiceImpl implements IProOverviewService {
+ private final RedisCache redisCache;
+
private final CollectionParamsManageMapper collectionParamsManageMapper;
private final SysDictDataMapper sysDictDataMapper;
private final OverviewMapper overviewMapper;
- public ProOverviewServiceImpl(CollectionParamsManageMapper collectionParamsManageMapper, SysDictDataMapper sysDictDataMapper, OverviewMapper overviewMapper) {
+ public ProOverviewServiceImpl(RedisCache redisCache, CollectionParamsManageMapper collectionParamsManageMapper, SysDictDataMapper sysDictDataMapper, OverviewMapper overviewMapper) {
+ this.redisCache = redisCache;
this.collectionParamsManageMapper = collectionParamsManageMapper;
this.sysDictDataMapper = sysDictDataMapper;
this.overviewMapper = overviewMapper;
@@ -222,6 +225,13 @@ public class ProOverviewServiceImpl implements IProOverviewService {
@Override
public List energyAnalysis() {
+ // 添加缓存处理
+ if (redisCache.hasKey(CacheConstants.ENERGY_ANALYSIS)) {
+ List energyAnalysis = redisCache.getCacheList(CacheConstants.ENERGY_ANALYSIS, OverviewEnergyDTO.class);
+ if (energyAnalysis != null && !energyAnalysis.isEmpty()) {
+ return energyAnalysis;
+ }
+ }
// 查询系统类型数据
List sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type");
// 定义参数类型
@@ -270,6 +280,9 @@ public class ProOverviewServiceImpl implements IProOverviewService {
initialEnergyData(dataList, energyMap.get(paramType), getEnergyLabel(paramType), getEnergyUnit(paramType), result);
}
})).toArray(CompletableFuture[]::new)).join();
+ redisCache.deleteObject(CacheConstants.ENERGY_ANALYSIS);
+ redisCache.setCacheList(CacheConstants.ENERGY_ANALYSIS, result.isEmpty() ? List.of() : result);
+ redisCache.expire(CacheConstants.ENERGY_ANALYSIS, 60 * 60);
return result.isEmpty() ? List.of() : result;
}
@@ -381,6 +394,13 @@ public class ProOverviewServiceImpl implements IProOverviewService {
@Override
public List getProProfile() {
+ // 增加缓存处理
+ if (redisCache.hasKey(CacheConstants.PRO_PROFILE)) {
+ List resultList = redisCache.getCacheList(CacheConstants.PRO_PROFILE, ProProfileDTO.class);
+ if (resultList != null && !resultList.isEmpty()) {
+ return resultList;
+ }
+ }
// 请求各个系统中有没有对应的总表,如果有直接查询总表,没有就是各个分表之和
List sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type");
String[] paramTypes = {"16", "17", "18", "19"};
@@ -482,6 +502,9 @@ public class ProOverviewServiceImpl implements IProOverviewService {
}
ProProfileDTO proProfileDTO = new ProProfileDTO(totalEle, totalCold, totalWater, totalGas, yearEle, yearCold, yearWater, yearGas);
+ redisCache.deleteObject(CacheConstants.PRO_PROFILE);
+ redisCache.setCacheList(CacheConstants.PRO_PROFILE, List.of(proProfileDTO));
+ redisCache.expire(CacheConstants.PRO_PROFILE, 60 * 60);
return List.of(proProfileDTO);
}
diff --git a/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java
index f52bf27..cc21a8c 100644
--- a/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java
+++ b/mh-system/src/main/java/com/mh/system/service/report/impl/ComprehensiveReportServiceImpl.java
@@ -42,77 +42,185 @@ public class ComprehensiveReportServiceImpl implements IComprehensiveReportServi
@Override
public List> report(EnergyQueryVO vo) {
DateUtils.sysEnergyDateChange(vo);
+
// 获取参数
- AtomicReference lastTableName = new AtomicReference<>("data_" + vo.getTimeType());
- AtomicReference curTableName = new AtomicReference<>("data_" + vo.getTimeType());
+ String lastTableName = "data_" + vo.getTimeType();
+ String curTableName = "data_" + vo.getTimeType();
String timeType = vo.getTimeType();
// 判断是否是单表
boolean isSingleTable = "month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType);
if (!isSingleTable) {
- lastTableName.set(lastTableName + vo.getStartTime().substring(0, 4));
- curTableName.set(curTableName + vo.getEndTime().substring(0, 4));
+ lastTableName = lastTableName + vo.getStartTime().substring(0, 4);
+ curTableName = curTableName + vo.getEndTime().substring(0, 4);
}
// 查询系统类型数据
List sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type");
// 定义参数类型
String[] paramTypes = {"16", "17", "18", "19"};
- // 初始化结果列表
+
+ // 批量查询所有采集参数
+ Map> allCollectionParams = batchQueryCollectionParams(paramTypes, sysTypeData);
+
+ // 批量查询能耗数据
+ Map> allEnergyData = batchQueryEnergyData(
+ allCollectionParams, lastTableName, curTableName, vo, timeType, isSingleTable);
+
+ // 构建结果
List result = new ArrayList<>();
- // 使用Map存储不同类型的能源DTO
Map energyMap = new HashMap<>();
energyMap.put("16", new OverviewEnergyDTO());
energyMap.put("17", new OverviewEnergyDTO());
energyMap.put("18", new OverviewEnergyDTO());
energyMap.put("19", new OverviewEnergyDTO());
+ // 组合并处理数据
for (String paramType : paramTypes) {
- List dataList = new ArrayList<>();
+ List combinedData = new ArrayList<>();
for (SysDictData sysDictData : sysTypeData) {
String sysType = sysDictData.getDictValue();
- // 查询采集参数
- List collectionParamsManages = queryCollectionParams(paramType, sysType, 40, null, false);
- // 合并数据
- if (collectionParamsManages != null && !collectionParamsManages.isEmpty()) {
- // 判断两个表是否一样
- boolean isSameTable = lastTableName.get().equals(curTableName.get());
- if (isSameTable) {
- List columnFilters = comprehensiveReportMapper.energyAnalysisOneTable(collectionParamsManages,
- lastTableName.get(),
- curTableName.get(),
- DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()),
- DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()),
- timeType);
- dataList.addAll(columnFilters);
+ String key = paramType + "_" + sysType;
+ List typeData = allEnergyData.get(key);
+ if (typeData != null) {
+ combinedData.addAll(typeData);
+ }
+ }
+ initialEnergyData(combinedData, energyMap.get(paramType),
+ getEnergyLabel(paramType), getEnergyUnit(paramType), result);
+ }
+
+ // 转换为最终结果
+ return convertToCompreReportDTO(result);
+ }
+
+ private Map> batchQueryCollectionParams(
+ String[] paramTypes, List sysTypeData) {
+
+ Map> allCollectionParams = new HashMap<>();
+
+ // 批量查询所有参数
+ List allParams = queryAllCollectionParams(paramTypes, sysTypeData);
+
+ // 按参数类型和系统类型分组
+ Map> groupedParams = allParams.stream()
+ .collect(Collectors.groupingBy(param ->
+ param.getParamType() + "_" + param.getSystemType()));
+
+ // 验证并补充缺失的总表数据
+ for (String paramType : paramTypes) {
+ for (SysDictData sysDictData : sysTypeData) {
+ String sysType = sysDictData.getDictValue();
+ String key = paramType + "_" + sysType;
+
+ List params = groupedParams.get(key);
+ if (params == null || params.isEmpty()) {
+ // 尝试查询总表
+ params = queryCollectionParamsFromSumTable(paramType, sysType, 40);
+ if (params != null && !params.isEmpty()) {
+ allCollectionParams.put(key, params);
+ }
+ } else {
+ allCollectionParams.put(key, params);
+ }
+ }
+ }
+
+ return allCollectionParams;
+ }
+
+ private List queryAllCollectionParams(String[] paramTypes, List sysTypeData) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("grade", 40);
+
+ // 构建所有条件的组合
+ if (paramTypes.length > 0 && sysTypeData.size() > 0) {
+ boolean firstCondition = true;
+ for (String paramType : paramTypes) {
+ for (SysDictData sysDictData : sysTypeData) {
+ if (firstCondition) {
+ queryWrapper.nested(nested -> nested.eq("param_type", paramType)
+ .eq("system_type", sysDictData.getDictValue()));
+ firstCondition = false;
} else {
- // 两个表不一样
- List columnFilters = comprehensiveReportMapper.energyAnalysisManyTable(collectionParamsManages,
- lastTableName.get(),
- curTableName.get(),
- DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()),
- DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()),
- timeType);
- dataList.addAll(columnFilters);
+ queryWrapper.or().nested(nested -> nested.eq("param_type", paramType)
+ .eq("system_type", sysDictData.getDictValue()));
}
}
}
- // 初始化能源数据
- initialEnergyData(dataList, energyMap.get(paramType), getEnergyLabel(paramType), getEnergyUnit(paramType), result);
+ }
+
+ return collectionParamsManageMapper.selectList(queryWrapper);
+ }
+
+
+ private List queryCollectionParamsFromSumTable(String paramType, String sysType, int grade) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("param_type", paramType)
+ .eq("system_type", sysType)
+ .eq("grade", grade)
+ .eq("mt_is_sum", 0); // 查询总表
+ return collectionParamsManageMapper.selectList(queryWrapper);
+ }
+
+
+// private Map> batchQueryCollectionParams(
+// String[] paramTypes, List sysTypeData) {
+//
+// Map> allCollectionParams = new HashMap<>();
+//
+// // 构建所有需要查询的组合
+// for (String paramType : paramTypes) {
+// for (SysDictData sysDictData : sysTypeData) {
+// String sysType = sysDictData.getDictValue();
+// List params = queryCollectionParams(paramType, sysType, 40, null, false);
+// if (params != null && !params.isEmpty()) {
+// String key = paramType + "_" + sysType;
+// allCollectionParams.put(key, params);
+// }
+// }
+// }
+//
+// return allCollectionParams;
+// }
+
+ private Map> batchQueryEnergyData(
+ Map> allCollectionParams,
+ String lastTableName, String curTableName, EnergyQueryVO vo,
+ String timeType, boolean isSingleTable) {
+
+ Map> result = new HashMap<>();
+ Date startTime = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime());
+ Date endTime = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime());
+
+ for (Map.Entry> entry : allCollectionParams.entrySet()) {
+ String key = entry.getKey();
+ List params = entry.getValue();
+
+ List data;
+ if (isSingleTable) {
+ data = comprehensiveReportMapper.energyAnalysisOneTable(
+ params, lastTableName, curTableName, startTime, endTime, timeType);
+ } else {
+ data = comprehensiveReportMapper.energyAnalysisManyTable(
+ params, lastTableName, curTableName, startTime, endTime, timeType);
+ }
+ result.put(key, data);
}
- // 这里再拆分result数据,根据每个对象的时间进行比较赋值,如果都是相等,然后分别赋值给CompreReportDTO,其中
- // name="总用电量"的对应的data赋值给CompreReportDTO的electValue,
- // name="总热水补水量"的对应的data赋值给CompreReportDTO的hotValue,
- // name="总产冷量"的对应的data赋值给CompreReportDTO的coldValue,
- // name="总蒸汽流量"的对应的data赋值给CompreReportDTO的steamValue,
- // timeStr就赋值给CompreReportDTO的time
+
+ return result;
+ }
+
+ private List convertToCompreReportDTO(List result) {
List compreReportDTOS = new ArrayList<>();
if (!result.isEmpty()) {
+ // 将结果按照名称映射
Map energyDataMap = result.stream()
- .collect(Collectors.toMap(OverviewEnergyDTO::getName, dto -> dto));
+ .collect(Collectors.toMap(OverviewEnergyDTO::getName, dto -> dto, (existing, replacement) -> existing));
+ // 获取各种能源类型的数据
OverviewEnergyDTO electDto = energyDataMap.get("总用电量");
OverviewEnergyDTO hotDto = energyDataMap.get("总热水补水量");
OverviewEnergyDTO coldDto = energyDataMap.get("总产冷量");
@@ -138,9 +246,110 @@ public class ComprehensiveReportServiceImpl implements IComprehensiveReportServi
}
return compreReportDTOS.isEmpty() ? List.of() : compreReportDTOS;
-
}
+// @Override
+// public List> report(EnergyQueryVO vo) {
+// DateUtils.sysEnergyDateChange(vo);
+// // 获取参数
+// AtomicReference lastTableName = new AtomicReference<>("data_" + vo.getTimeType());
+// AtomicReference curTableName = new AtomicReference<>("data_" + vo.getTimeType());
+// String timeType = vo.getTimeType();
+//
+// // 判断是否是单表
+// boolean isSingleTable = "month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType);
+// if (!isSingleTable) {
+// lastTableName.set(lastTableName + vo.getStartTime().substring(0, 4));
+// curTableName.set(curTableName + vo.getEndTime().substring(0, 4));
+// }
+//
+// // 查询系统类型数据
+// List sysTypeData = sysDictDataMapper.selectDictDataByType("sys_type");
+// // 定义参数类型
+// String[] paramTypes = {"16", "17", "18", "19"};
+// // 初始化结果列表
+// List result = new ArrayList<>();
+// // 使用Map存储不同类型的能源DTO
+// Map energyMap = new HashMap<>();
+// energyMap.put("16", new OverviewEnergyDTO());
+// energyMap.put("17", new OverviewEnergyDTO());
+// energyMap.put("18", new OverviewEnergyDTO());
+// energyMap.put("19", new OverviewEnergyDTO());
+//
+// for (String paramType : paramTypes) {
+// List dataList = new ArrayList<>();
+// for (SysDictData sysDictData : sysTypeData) {
+// String sysType = sysDictData.getDictValue();
+// // 查询采集参数
+// List collectionParamsManages = queryCollectionParams(paramType, sysType, 40, null, false);
+// // 合并数据
+// if (collectionParamsManages != null && !collectionParamsManages.isEmpty()) {
+// // 判断两个表是否一样
+// boolean isSameTable = lastTableName.get().equals(curTableName.get());
+// if (isSameTable) {
+// List columnFilters = comprehensiveReportMapper.energyAnalysisOneTable(collectionParamsManages,
+// lastTableName.get(),
+// curTableName.get(),
+// DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()),
+// DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()),
+// timeType);
+// dataList.addAll(columnFilters);
+// } else {
+// // 两个表不一样
+// List columnFilters = comprehensiveReportMapper.energyAnalysisManyTable(collectionParamsManages,
+// lastTableName.get(),
+// curTableName.get(),
+// DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getStartTime()),
+// DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", vo.getEndTime()),
+// timeType);
+// dataList.addAll(columnFilters);
+// }
+// }
+// }
+// // 初始化能源数据
+// initialEnergyData(dataList, energyMap.get(paramType), getEnergyLabel(paramType), getEnergyUnit(paramType), result);
+//
+// }
+// // 这里再拆分result数据,根据每个对象的时间进行比较赋值,如果都是相等,然后分别赋值给CompreReportDTO,其中
+// // name="总用电量"的对应的data赋值给CompreReportDTO的electValue,
+// // name="总热水补水量"的对应的data赋值给CompreReportDTO的hotValue,
+// // name="总产冷量"的对应的data赋值给CompreReportDTO的coldValue,
+// // name="总蒸汽流量"的对应的data赋值给CompreReportDTO的steamValue,
+// // timeStr就赋值给CompreReportDTO的time
+// List compreReportDTOS = new ArrayList<>();
+//
+// if (!result.isEmpty()) {
+// Map energyDataMap = result.stream()
+// .collect(Collectors.toMap(OverviewEnergyDTO::getName, dto -> dto));
+//
+// OverviewEnergyDTO electDto = energyDataMap.get("总用电量");
+// OverviewEnergyDTO hotDto = energyDataMap.get("总热水补水量");
+// OverviewEnergyDTO coldDto = energyDataMap.get("总产冷量");
+// OverviewEnergyDTO steamDto = energyDataMap.get("总蒸汽流量");
+//
+// if (electDto != null && electDto.getTimeStr() != null) {
+// String[] times = electDto.getTimeStr();
+// String[] electValues = electDto.getData();
+// String[] hotValues = hotDto != null ? hotDto.getData() : new String[times.length];
+// String[] coldValues = coldDto != null ? coldDto.getData() : new String[times.length];
+// String[] steamValues = steamDto != null ? steamDto.getData() : new String[times.length];
+//
+// for (int i = 0; i < times.length; i++) {
+// CompreReportDTO dto = new CompreReportDTO();
+// dto.setTime(times[i]);
+// dto.setElectValue(i < electValues.length ? electValues[i] : "0.00");
+// dto.setHotValue(i < hotValues.length ? hotValues[i] : "0.00");
+// dto.setColdValue(i < coldValues.length ? coldValues[i] : "0.00");
+// dto.setSteamValue(i < steamValues.length ? steamValues[i] : "0.00");
+// compreReportDTOS.add(dto);
+// }
+// }
+// }
+//
+// return compreReportDTOS.isEmpty() ? List.of() : compreReportDTOS;
+//
+// }
+
private List queryCollectionParams(String paramType, String sysType, int grade, String terminalDeviceType, boolean isNow) {
QueryWrapper queryWrapper = new QueryWrapper<>();
LocalDate today = LocalDate.now();