|
@@ -1022,15 +1022,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 根据createTime分组,计算每组内的value总和
|
|
|
Map<String, BigDecimal> groupedTotalValues = finalResult.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ElectricityControlReport::getCreateTime, // 按createTime分组
|
|
|
- Collectors.mapping(ElectricityControlReport::getValue, // 提取value字段
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)) // 累加value
|
|
|
- ));
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getCreateTime() + "_" + report.getDeviceTitle(),
|
|
|
+ Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
|
|
|
// 根据分组结果,将totalNum字段设置为对应的分组总和
|
|
|
modelDataResults.forEach(report -> {
|
|
|
- BigDecimal totalValueForGroup = groupedTotalValues.get(report.getCreateTime());
|
|
|
+ BigDecimal totalValueForGroup = groupedTotalValues.get(report.getCreateTime() + "_" + report.getDeviceTitle());
|
|
|
report.setTotalNum(totalValueForGroup); // 将分组总和赋值给totalNum// 计算占比(value / totalValueForGroup)
|
|
|
if (totalValueForGroup.compareTo(BigDecimal.ZERO) > 0) { // 避免除以0的情况
|
|
|
BigDecimal proportion = report.getValue()
|
|
@@ -1123,13 +1121,16 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 按 createTime 计算 dailyTotal
|
|
|
+ // 按 createTime、RegionTitle 和 DeviceTypeName(DeviceTypeName 为空或 null 时只按 CreateTime 和 RegionTitle)分组计算 dailyTotal
|
|
|
Map<String, BigDecimal> dailyTotals = finalResult.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ElectricityControlReport::getCreateTime,
|
|
|
- Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
- ));
|
|
|
+ .collect(Collectors.groupingBy(report -> {
|
|
|
+ String key = report.getCreateTime() + "_" + report.getRegionTitle();
|
|
|
+ if (report.getDeviceTypeName()!= null &&!report.getDeviceTypeName().isEmpty()) {
|
|
|
+ key += "_" + report.getDeviceTypeName();
|
|
|
+ }
|
|
|
+ return key;
|
|
|
+ }, Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
|
|
|
// 按 createTime -> regionTitle -> deviceTypeName 分组
|
|
|
Map<String, Map<String, Map<String, List<ElectricityControlReport>>>> groupedData = finalResult.stream()
|
|
@@ -1148,7 +1149,11 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
String yearFormattedDate = date.getYear() + "年";
|
|
|
|
|
|
- BigDecimal dailyTotal = dailyTotals.get(createTime); // 获取当天总值
|
|
|
+ String totalKey = createTime + "_" + regionTitle;
|
|
|
+ if (deviceTypeName!= null &&!deviceTypeName.isEmpty()) {
|
|
|
+ totalKey += "_" + deviceTypeName;
|
|
|
+ }
|
|
|
+ BigDecimal dailyTotal = dailyTotals.get(totalKey); // 获取当天总值
|
|
|
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1274,13 +1279,11 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 按 createTime 计算 dailyTotal
|
|
|
+ // 按 createTime 和 RegionTitle 同时分组计算 dailyTotal
|
|
|
Map<String, BigDecimal> dailyTotals = finalResult.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ElectricityControlReport::getCreateTime,
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getCreateTime() + "_" + report.getRegionTitle(),
|
|
|
Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
- ));
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
|
|
|
// 按 createTime 和 regionTitle 分组,去掉 deviceTypeName
|
|
|
Map<String, Map<String, List<ElectricityControlReport>>> groupedData = finalResult.stream()
|
|
@@ -1296,7 +1299,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
String yearFormattedDate = date.getYear() + "年";
|
|
|
|
|
|
- BigDecimal dailyTotal = dailyTotals.get(createTime); // 获取当天总值
|
|
|
+ BigDecimal dailyTotal = dailyTotals.get(createTime + "_" + regionTitle); // 获取当天总值
|
|
|
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1347,6 +1350,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject electricityControlGsDay() {
|
|
|
|
|
@@ -1422,13 +1426,10 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 按 createTime 计算 dailyTotal
|
|
|
Map<String, BigDecimal> dailyTotals = finalResult.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ElectricityControlReport::getCreateTime,
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getCreateTime() + "_" + report.getCompanyName(),
|
|
|
Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
- ));
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
|
|
|
// 按 createTime 和 CompanyName 分组,去掉 regionTitle
|
|
|
Map<String, Map<String, List<ElectricityControlReport>>> groupedData = finalResult.stream()
|
|
@@ -1444,7 +1445,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
String yearFormattedDate = date.getYear() + "年";
|
|
|
|
|
|
- BigDecimal dailyTotal = dailyTotals.get(createTime); // 获取当天总值
|
|
|
+ BigDecimal dailyTotal = dailyTotals.get(createTime + "_" + companyName); // 获取当天总值
|
|
|
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1634,15 +1635,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 根据month分组,计算每组内的value总和
|
|
|
Map<String, BigDecimal> groupedTotalValues = modelDataResults.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ElectricityControlReport::getMonth, // 按month分组
|
|
|
- Collectors.mapping(ElectricityControlReport::getValue, // 提取value字段
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)) // 累加value
|
|
|
- ));
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getMonth() + "_" + report.getDeviceTitle(),
|
|
|
+ Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
|
|
|
// 根据分组结果,将totalNum字段设置为对应的分组总和
|
|
|
modelDataResults.forEach(report -> {
|
|
|
- BigDecimal totalValueForGroup = groupedTotalValues.get(report.getMonth());
|
|
|
+ BigDecimal totalValueForGroup = groupedTotalValues.get(report.getMonth() + "_" + report.getDeviceTitle());
|
|
|
report.setTotalNum(totalValueForGroup); // 将分组总和赋值给totalNum
|
|
|
if (totalValueForGroup.compareTo(BigDecimal.ZERO) > 0) { // 避免除以0的情况
|
|
|
BigDecimal proportion = report.getValue()
|
|
@@ -1738,6 +1737,17 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+
|
|
|
+ Map<String, BigDecimal> monthTotals = finalResult.stream()
|
|
|
+ .collect(Collectors.groupingBy(report -> {
|
|
|
+ String key = report.getMonth() + "_" + report.getRegionTitle();
|
|
|
+ if (report.getDeviceTypeName()!= null &&!report.getDeviceTypeName().isEmpty()) {
|
|
|
+ key += "_" + report.getDeviceTypeName();
|
|
|
+ }
|
|
|
+ return key;
|
|
|
+ }, Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+
|
|
|
// 按月、区域、设备类型分组
|
|
|
Map<String, Map<String, Map<String, List<ElectricityControlReport>>>> groupedData = finalResult.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1752,15 +1762,15 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 按月和区域计算每月的合计
|
|
|
groupedData.forEach((month, regionGroup) -> {
|
|
|
- // 先计算该月下所有数据的总和(不分regionTitle或deviceTypeName)
|
|
|
- BigDecimal monthlyTotal = regionGroup.values().stream()
|
|
|
- .flatMap(typeGroup -> typeGroup.values().stream())
|
|
|
- .flatMap(List::stream)
|
|
|
- .map(ElectricityControlReport::getValue)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
// 然后按regionTitle、deviceTypeName和key1分组,计算每个key(尖、峰、平、谷)的合计
|
|
|
regionGroup.forEach((regionTitle, typeGroup) -> typeGroup.forEach((deviceTypeName, reports) -> {
|
|
|
+
|
|
|
+
|
|
|
+ String totalKey = month + "_" + regionTitle;
|
|
|
+ if (deviceTypeName!= null &&!deviceTypeName.isEmpty()) {
|
|
|
+ totalKey += "_" + deviceTypeName;
|
|
|
+ }
|
|
|
+ BigDecimal monthlyTotal = monthTotals.get(totalKey); // 获取当天总值
|
|
|
// 按key1计算该区域该设备类型的尖、峰、平、谷合计
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1893,6 +1903,12 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+
|
|
|
+ Map<String, BigDecimal> monthTotals = finalResult.stream()
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getMonth() + "_" + report.getRegionTitle(),
|
|
|
+ Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+
|
|
|
// 按月、区域、设备类型分组
|
|
|
Map<String, Map<String, List<ElectricityControlReport>>> groupedData = finalResult.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -1906,14 +1922,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 按月和区域计算每月的合计
|
|
|
groupedData.forEach((month, regionGroup) -> {
|
|
|
- // 先计算该月下所有数据的总和(不分regionTitle或deviceTypeName)
|
|
|
- BigDecimal monthlyTotal = regionGroup.values().stream()
|
|
|
- .flatMap(List::stream) // 取消设备类型分组,直接处理所有数据
|
|
|
- .map(ElectricityControlReport::getValue)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
// 只按regionTitle和key1分组,取消设备类型分组
|
|
|
regionGroup.forEach((regionTitle, reports) -> {
|
|
|
+
|
|
|
+ BigDecimal monthlyTotal = monthTotals.get(month + "_" + regionTitle); // 获取当天总值
|
|
|
+
|
|
|
+
|
|
|
// 按key1(尖、峰、平、谷)分组并计算每个key的总合
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -2028,6 +2043,11 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+ Map<String, BigDecimal> monthTotals = finalResult.stream()
|
|
|
+ .collect(Collectors.groupingBy(report -> report.getMonth() + "_" + report.getCompanyName(),
|
|
|
+ Collectors.mapping(ElectricityControlReport::getValue,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+
|
|
|
// 按月、公司名称分组
|
|
|
Map<String, Map<String, List<ElectricityControlReport>>> groupedData = finalResult.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
@@ -2041,14 +2061,12 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 按月和公司名称计算每月的合计
|
|
|
groupedData.forEach((month, companyGroup) -> {
|
|
|
- // 先计算该月下所有数据的总和(不分公司名称)
|
|
|
- BigDecimal monthlyTotal = companyGroup.values().stream()
|
|
|
- .flatMap(List::stream)
|
|
|
- .map(ElectricityControlReport::getValue)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
// 只按公司名称和key1(尖、峰、平、谷)分组
|
|
|
companyGroup.forEach((companyName, reports) -> {
|
|
|
+
|
|
|
+ BigDecimal monthlyTotal = monthTotals.get(month + "_" + companyName);
|
|
|
+
|
|
|
// 按key1(尖、峰、平、谷)分组并计算每个key的总合
|
|
|
Map<String, BigDecimal> keyTotals = reports.stream()
|
|
|
.collect(Collectors.groupingBy(
|