|
@@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
@@ -309,6 +310,8 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
@Override
|
|
|
public JSONObject totalElectricityConsumptionReport() {
|
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
JSONObject result = new JSONObject();
|
|
|
Query query = new Query();
|
|
|
query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
@@ -327,18 +330,26 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
|
|
|
List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
|
|
|
-//
|
|
|
-// Map<String, String> deviceInfoMap = deviceInformationList.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// DeviceInformation::getId, // Key: Device ID
|
|
|
-// DeviceInformation::getDeviceTitle // Value: Device Title
|
|
|
-// ));
|
|
|
|
|
|
-// // 遍历 fpgStatiscsModelDataList,匹配 deviceTitle
|
|
|
-// fpgStatiscsModelDataList.forEach(data -> {
|
|
|
-// String deviceTitle = deviceInfoMap.get(data.getDeviceInformationId());
|
|
|
-// data.setDeviceTitle(deviceTitle); // 赋值 deviceTitle
|
|
|
-// });
|
|
|
+ List<String> regionIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceRegionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceRegion> regionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ regionLambdaQueryWrapper.in(DeviceRegion::getId, regionIds);
|
|
|
+ List<DeviceRegion> deviceRegionList = deviceRegionMapper.selectList(regionLambdaQueryWrapper);
|
|
|
+
|
|
|
+ Map<String, String> regionMap = deviceRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ DeviceRegion::getId, // Key: Device ID
|
|
|
+ DeviceRegion::getRegionTitle // Value: Device Title
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 遍历 fpgStatiscsModelDataList,匹配 deviceTitle
|
|
|
+ fpgStatiscsModelDataList.forEach(data -> {
|
|
|
+ String regionTitle = regionMap.get(data.getDeviceRegionId());
|
|
|
+ data.setRegionTitle(regionTitle); // 赋值 regionTitle
|
|
|
+ });
|
|
|
|
|
|
|
|
|
// 将listA转换为以(设备Id, 区域Id)为键的Map
|
|
@@ -357,14 +368,14 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
|
|
|
b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
|
|
|
b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
|
|
|
- b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString, null, null);
|
|
|
+ b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString, b.getRegionTitle(), mapDeviceType(a.getDeviceType()));
|
|
|
}
|
|
|
return null;
|
|
|
}).filter(x -> x != null).collect(Collectors.toList());
|
|
|
JSONArray jsonResult = new JSONArray();
|
|
|
|
|
|
// 龙钢变各工序报表
|
|
|
- List<ModelDataResult> modelDataResults = new ArrayList<>();
|
|
|
+ List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
for (ModelReportFormResult modelReportFormResult : combinedList) {
|
|
|
|
|
|
BigDecimal sum = modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower());
|
|
@@ -374,8 +385,10 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String deviceRegionId = modelReportFormResult.getDeviceRegionId();
|
|
|
String deviceInformationId = modelReportFormResult.getDeviceInformationId();
|
|
|
String createTime = modelReportFormResult.getDates();
|
|
|
+ String regionTitle = modelReportFormResult.getRegionName();
|
|
|
+ String deviceTypeName = modelReportFormResult.getDeviceTypeName();
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
- ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
|
|
|
if (i == 0) {
|
|
|
modelDataResult.setKey("反有总");
|
|
@@ -403,10 +416,20 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
modelDataResult.setValue(modelReportFormResult.getValleysPower());
|
|
|
}
|
|
|
|
|
|
+ // 解析日期字符串为 LocalDate 对象
|
|
|
+ LocalDate date = LocalDate.parse(createTime, formatter);
|
|
|
+
|
|
|
+ // 获取年份和月份并拼接成 "yyyy年MM月" 格式
|
|
|
+ String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
+
|
|
|
modelDataResult.setDeviceTitle(deviceTitle);
|
|
|
modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
modelDataResult.setCreateTime(createTime);
|
|
|
+ modelDataResult.setRegionTitle(regionTitle);
|
|
|
+ modelDataResult.setDeviceTypeName(deviceTypeName);
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+ modelDataResult.setMonth(formattedDate);
|
|
|
modelDataResults.add(modelDataResult);
|
|
|
}
|
|
|
}
|
|
@@ -421,6 +444,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
@Override
|
|
|
public JSONObject electricityControl() {
|
|
|
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
JSONObject result = new JSONObject();
|
|
|
Query query = new Query();
|
|
|
query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
@@ -486,6 +512,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 龙钢变各工序报表
|
|
|
List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
+ List<ElectricityControlReport> finalResult = new ArrayList<>();
|
|
|
for (ModelReportFormResult modelReportFormResult : combinedList) {
|
|
|
|
|
|
BigDecimal sum = modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower());
|
|
@@ -497,106 +524,393 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String createTime = modelReportFormResult.getDates();
|
|
|
String regionTitle = modelReportFormResult.getRegionName();
|
|
|
String deviceTypeName = modelReportFormResult.getDeviceTypeName();
|
|
|
- for (int i = 0; i < 9; i++) {
|
|
|
-
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
+
|
|
|
+// if (i == 0) {
|
|
|
+// modelDataResult.setKey("总");
|
|
|
+// modelDataResult.setKey1("总");
|
|
|
+// modelDataResult.setValue(modelReportFormResult.getTopsPower()
|
|
|
+// .add(modelReportFormResult.getPeaksPower())
|
|
|
+// .add(modelReportFormResult.getFlatPower())
|
|
|
+// .add(modelReportFormResult.getValleysPower()));
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
if (i == 0) {
|
|
|
- modelDataResult.setKey("总");
|
|
|
- modelDataResult.setKey1("总");
|
|
|
- modelDataResult.setValue(modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower()));
|
|
|
- }
|
|
|
- if (i == 1) {
|
|
|
modelDataResult.setKey("尖");
|
|
|
modelDataResult.setKey1("尖");
|
|
|
modelDataResult.setValue(modelReportFormResult.getTopsPower());
|
|
|
- }
|
|
|
- if (i == 2) {
|
|
|
- modelDataResult.setKey("尖");
|
|
|
- modelDataResult.setKey1("尖(%)");
|
|
|
|
|
|
- // 检查 sum 是否为零,避免除以零
|
|
|
- if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
- modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- // sum 不为零时,正常进行除法
|
|
|
- modelDataResult.setValue(
|
|
|
- modelReportFormResult.getTopsPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- }
|
|
|
}
|
|
|
- if (i == 3) {
|
|
|
+
|
|
|
+// if (i == 2) {
|
|
|
+// modelDataResult.setKey("尖");
|
|
|
+// modelDataResult.setKey1("尖(%)");
|
|
|
+//
|
|
|
+// // 检查 sum 是否为零,避免除以零
|
|
|
+// if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+// } else {
|
|
|
+// modelDataResult.setValue(modelReportFormResult.getTopsPower()
|
|
|
+// .divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+// .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ if (i == 1) {
|
|
|
modelDataResult.setKey("峰");
|
|
|
modelDataResult.setKey1("峰");
|
|
|
modelDataResult.setValue(modelReportFormResult.getPeaksPower());
|
|
|
+
|
|
|
}
|
|
|
- if (i == 4) {
|
|
|
- modelDataResult.setKey("峰");
|
|
|
- modelDataResult.setKey1("峰(%)");
|
|
|
- // 检查 sum 是否为零,避免除以零
|
|
|
- if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
- modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- // sum 不为零时,正常进行除法
|
|
|
- modelDataResult.setValue(
|
|
|
- modelReportFormResult.getPeaksPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- if (i == 5) {
|
|
|
+
|
|
|
+// if (i == 4) {
|
|
|
+// modelDataResult.setKey("峰");
|
|
|
+// modelDataResult.setKey1("峰(%)");
|
|
|
+//
|
|
|
+// // 检查 sum 是否为零,避免除以零
|
|
|
+// if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+// } else {
|
|
|
+// modelDataResult.setValue(modelReportFormResult.getPeaksPower()
|
|
|
+// .divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+// .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ if (i == 2) {
|
|
|
modelDataResult.setKey("平");
|
|
|
modelDataResult.setKey1("平");
|
|
|
modelDataResult.setValue(modelReportFormResult.getFlatPower());
|
|
|
+
|
|
|
}
|
|
|
- if (i == 6) {
|
|
|
- modelDataResult.setKey("平");
|
|
|
- modelDataResult.setKey1("平(%)");
|
|
|
- // 检查 sum 是否为零,避免除以零
|
|
|
- if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
- modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- // sum 不为零时,正常进行除法
|
|
|
- modelDataResult.setValue(
|
|
|
- modelReportFormResult.getFlatPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- if (i == 7) {
|
|
|
+
|
|
|
+// if (i == 6) {
|
|
|
+// modelDataResult.setKey("平");
|
|
|
+// modelDataResult.setKey1("平(%)");
|
|
|
+//
|
|
|
+// // 检查 sum 是否为零,避免除以零
|
|
|
+// if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+// } else {
|
|
|
+// modelDataResult.setValue(modelReportFormResult.getFlatPower()
|
|
|
+// .divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+// .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ if (i == 3) {
|
|
|
modelDataResult.setKey("谷");
|
|
|
modelDataResult.setKey1("谷");
|
|
|
modelDataResult.setValue(modelReportFormResult.getValleysPower());
|
|
|
+
|
|
|
}
|
|
|
- if (i == 8) {
|
|
|
- modelDataResult.setKey("谷");
|
|
|
- modelDataResult.setKey1("谷(%)");
|
|
|
- // 检查 sum 是否为零,避免除以零
|
|
|
- if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
- modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- // sum 不为零时,正常进行除法
|
|
|
- modelDataResult.setValue(
|
|
|
- modelReportFormResult.getValleysPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
- .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+// if (i == 8) {
|
|
|
+// modelDataResult.setKey("谷");
|
|
|
+// modelDataResult.setKey1("谷(%)");
|
|
|
+//
|
|
|
+// // 检查 sum 是否为零,避免除以零
|
|
|
+// if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+// } else {
|
|
|
+// modelDataResult.setValue(modelReportFormResult.getValleysPower()
|
|
|
+// .divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+// .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
+ // 解析日期字符串为 LocalDate 对象
|
|
|
+ LocalDate date = LocalDate.parse(createTime, formatter);
|
|
|
+
|
|
|
+ // 获取年份和月份并拼接成 "yyyy年MM月" 格式
|
|
|
+ String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
+
|
|
|
modelDataResult.setDeviceTitle(deviceTitle);
|
|
|
modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
modelDataResult.setCreateTime(createTime);
|
|
|
modelDataResult.setRegionTitle(regionTitle);
|
|
|
modelDataResult.setDeviceTypeName(deviceTypeName);
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+ modelDataResult.setMonth(formattedDate);
|
|
|
+ modelDataResult.setMonthTotal(formattedDate + "总计");
|
|
|
+
|
|
|
modelDataResults.add(modelDataResult);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 使用Collectors.groupingBy按monthTotal进行分组
|
|
|
+ Map<String, List<ElectricityControlReport>> groupedByMonthTotal = modelDataResults.stream()
|
|
|
+ .collect(Collectors.groupingBy(ElectricityControlReport::getMonthTotal));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<ElectricityControlReport>> entry : groupedByMonthTotal.entrySet()) {
|
|
|
+ String monthTotal = entry.getKey();
|
|
|
+ List<ElectricityControlReport> groupedData = entry.getValue();
|
|
|
+
|
|
|
+ // 先将所有的功率数据(尖、峰、平、谷)提取出来
|
|
|
+ BigDecimal topsTotalPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal peaksTotalPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal flatTotalPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal valleysTotalPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalPowerForKey1 = BigDecimal.ZERO; // 用来存储总功率
|
|
|
+
|
|
|
+ // 处理功率数据(尖、峰、平、谷、总)
|
|
|
+ List<ElectricityControlReport> powerReports = new ArrayList<>();
|
|
|
+ for (ElectricityControlReport report : groupedData) {
|
|
|
+ switch (report.getKey1()) {
|
|
|
+ case "尖":
|
|
|
+ topsTotalPower = topsTotalPower.add(report.getValue());
|
|
|
+ powerReports.add(report);
|
|
|
+ break;
|
|
|
+ case "峰":
|
|
|
+ peaksTotalPower = peaksTotalPower.add(report.getValue());
|
|
|
+ powerReports.add(report);
|
|
|
+ break;
|
|
|
+ case "平":
|
|
|
+ flatTotalPower = flatTotalPower.add(report.getValue());
|
|
|
+ powerReports.add(report);
|
|
|
+ break;
|
|
|
+ case "谷":
|
|
|
+ valleysTotalPower = valleysTotalPower.add(report.getValue());
|
|
|
+ powerReports.add(report);
|
|
|
+ break;
|
|
|
+ case "总":
|
|
|
+ totalPowerForKey1 = totalPowerForKey1.add(report.getValue());
|
|
|
+ powerReports.add(report);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果 "总" 没有在数据中,手动计算总功率
|
|
|
+ if (totalPowerForKey1.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ totalPowerForKey1 = topsTotalPower.add(peaksTotalPower).add(flatTotalPower).add(valleysTotalPower);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理功率数据(尖、峰、平、谷、总)
|
|
|
+ for (ElectricityControlReport report : powerReports) {
|
|
|
+ if ("尖".equals(report.getKey1())) {
|
|
|
+ report.setTopsPower(topsTotalPower);
|
|
|
+ report.setMonthTotalValue(topsTotalPower);
|
|
|
+ report.setOrderIndex(2);
|
|
|
+ } else if ("峰".equals(report.getKey1())) {
|
|
|
+ report.setPeaksPower(peaksTotalPower);
|
|
|
+ report.setMonthTotalValue(peaksTotalPower);
|
|
|
+ report.setOrderIndex(3);
|
|
|
+ } else if ("平".equals(report.getKey1())) {
|
|
|
+ report.setFlatPower(flatTotalPower);
|
|
|
+ report.setMonthTotalValue(flatTotalPower);
|
|
|
+ report.setOrderIndex(4);
|
|
|
+ } else if ("谷".equals(report.getKey1())) {
|
|
|
+ report.setValleysPower(valleysTotalPower);
|
|
|
+ report.setMonthTotalValue(valleysTotalPower);
|
|
|
+ report.setOrderIndex(5);
|
|
|
+ } else if ("总".equals(report.getKey1())) {
|
|
|
+ report.setPower(totalPowerForKey1);
|
|
|
+ report.setMonthTotalValue(totalPowerForKey1);
|
|
|
+ report.setOrderIndex(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理占比数据(尖(%)、峰(%)、平(%)、谷(%))
|
|
|
+ List<ElectricityControlReport> percentageReports = new ArrayList<>();
|
|
|
+ for (ElectricityControlReport report : groupedData) {
|
|
|
+ if ("尖(%)".equals(report.getKey1()) || "峰(%)".equals(report.getKey1()) ||
|
|
|
+ "平(%)".equals(report.getKey1()) || "谷(%)".equals(report.getKey1())) {
|
|
|
+ percentageReports.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算占比
|
|
|
+ for (ElectricityControlReport report : percentageReports) {
|
|
|
+ // 判断totalPowerForKey1是否大于零,避免除以零的情况
|
|
|
+ if (totalPowerForKey1.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ // 根据key1的占比设置
|
|
|
+ if ("尖(%)".equals(report.getKey1())) {
|
|
|
+ BigDecimal proportion = topsTotalPower.divide(totalPowerForKey1, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ report.setTopsProportion(proportion);
|
|
|
+ report.setMonthTotalValue(proportion);
|
|
|
+ report.setOrderIndex(6);
|
|
|
+ } else if ("峰(%)".equals(report.getKey1())) {
|
|
|
+ BigDecimal proportion = peaksTotalPower.divide(totalPowerForKey1, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ report.setPeaksProportion(proportion);
|
|
|
+ report.setMonthTotalValue(proportion);
|
|
|
+ report.setOrderIndex(7);
|
|
|
+ } else if ("平(%)".equals(report.getKey1())) {
|
|
|
+ BigDecimal proportion = flatTotalPower.divide(totalPowerForKey1, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ report.setFlatProportion(proportion);
|
|
|
+ report.setMonthTotalValue(proportion);
|
|
|
+ report.setOrderIndex(8);
|
|
|
+ } else if ("谷(%)".equals(report.getKey1())) {
|
|
|
+ BigDecimal proportion = valleysTotalPower.divide(totalPowerForKey1, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
|
|
+ report.setValleysProportion(proportion);
|
|
|
+ report.setMonthTotalValue(proportion);
|
|
|
+ report.setOrderIndex(9);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将所有处理好的数据添加到finalResult中
|
|
|
+ finalResult.addAll(groupedData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ jsonResult = JSON.parseArray(JSON.toJSONString(finalResult));
|
|
|
+
|
|
|
+ log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
|
+ result.put("data", jsonResult);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject electricityControlMonth() {
|
|
|
+
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Query query = new Query();
|
|
|
+ query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
+ List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_day_powerproportioncurrent");
|
|
|
+
|
|
|
+ if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)) {
|
|
|
+ log.info("{}{}", "mongo数据查询为空,峰平谷报表导出失败!", "total_day_powerproportioncurrent");
|
|
|
+ result.put("data", new JSONArray());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> deviceInformationIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceInformationId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
|
|
|
+ List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ List<String> regionIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceRegionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceRegion> regionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ regionLambdaQueryWrapper.in(DeviceRegion::getId, regionIds);
|
|
|
+ List<DeviceRegion> deviceRegionList = deviceRegionMapper.selectList(regionLambdaQueryWrapper);
|
|
|
+
|
|
|
+ Map<String, String> regionMap = deviceRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ DeviceRegion::getId, // Key: Device ID
|
|
|
+ DeviceRegion::getRegionTitle // Value: Device Title
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 遍历 fpgStatiscsModelDataList,匹配 deviceTitle
|
|
|
+ fpgStatiscsModelDataList.forEach(data -> {
|
|
|
+ String regionTitle = regionMap.get(data.getDeviceRegionId());
|
|
|
+ data.setRegionTitle(regionTitle); // 赋值 regionTitle
|
|
|
+ });
|
|
|
+
|
|
|
+ // 将listA转换为以(设备Id, 区域Id)为键的Map
|
|
|
+ Map<String, DeviceInformation> mapA = deviceInformationList.stream()
|
|
|
+ .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
|
|
|
+
|
|
|
+ // 遍历listB,根据相同的(设备Id, 区域Id)与mapA中的对象合并成新的ModelResult并添加到新列表
|
|
|
+ List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(b -> {
|
|
|
+ String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
|
|
|
+ DeviceInformation a = mapA.get(key);
|
|
|
+ if (a != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateString = sdf.format(b.getCreateTime());
|
|
|
+ return new ModelReportFormResult(a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
|
|
|
+ b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
|
|
|
+ b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
|
|
|
+ b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
|
|
|
+ b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString, b.getRegionTitle(), mapDeviceType(a.getDeviceType()));
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).filter(x -> x != null).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 按设备ID和月份进行分组
|
|
|
+ Map<String, List<ModelReportFormResult>> groupedByDeviceAndMonth = combinedList.stream()
|
|
|
+ .collect(Collectors.groupingBy(resultItem -> resultItem.getDeviceInformationId() + "_" + resultItem.getDates().substring(0, 7)));
|
|
|
+
|
|
|
+ List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<ModelReportFormResult>> entry : groupedByDeviceAndMonth.entrySet()) {
|
|
|
+ // 对每个设备和月份的组进行汇总
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<ModelReportFormResult> groupedResults = entry.getValue();
|
|
|
+
|
|
|
+ BigDecimal totalTopsPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalPeaksPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalFlatPower = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalValleysPower = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 汇总功率
|
|
|
+ for (ModelReportFormResult modelReportFormResult : groupedResults) {
|
|
|
+ totalTopsPower = totalTopsPower.add(modelReportFormResult.getTopsPower());
|
|
|
+ totalPeaksPower = totalPeaksPower.add(modelReportFormResult.getPeaksPower());
|
|
|
+ totalFlatPower = totalFlatPower.add(modelReportFormResult.getFlatPower());
|
|
|
+ totalValleysPower = totalValleysPower.add(modelReportFormResult.getValleysPower());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 为每个分组的数据创建报表项
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
+
|
|
|
+ if (i == 0) {
|
|
|
+ modelDataResult.setKey("尖");
|
|
|
+ modelDataResult.setKey1("尖");
|
|
|
+ modelDataResult.setValue(totalTopsPower);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 1) {
|
|
|
+ modelDataResult.setKey("峰");
|
|
|
+ modelDataResult.setKey1("峰");
|
|
|
+ modelDataResult.setValue(totalPeaksPower);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 2) {
|
|
|
+ modelDataResult.setKey("平");
|
|
|
+ modelDataResult.setKey1("平");
|
|
|
+ modelDataResult.setValue(totalFlatPower);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 3) {
|
|
|
+ modelDataResult.setKey("谷");
|
|
|
+ modelDataResult.setKey1("谷");
|
|
|
+ modelDataResult.setValue(totalValleysPower);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置其他属性
|
|
|
+ ModelReportFormResult firstResult = groupedResults.get(0); // 获取分组中的第一个对象
|
|
|
+ LocalDate date = LocalDate.parse(firstResult.getDates(), formatter);
|
|
|
+ String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
|
|
|
+ String yearFormattedDate = date.getYear() + "年";
|
|
|
+
|
|
|
+ modelDataResult.setDeviceTitle(firstResult.getDeviceTitle());
|
|
|
+ modelDataResult.setDeviceRegionId(firstResult.getDeviceRegionId());
|
|
|
+ modelDataResult.setDeviceInformationId(firstResult.getDeviceInformationId());
|
|
|
+ modelDataResult.setCreateTime(firstResult.getDates());
|
|
|
+ modelDataResult.setRegionTitle(firstResult.getRegionName());
|
|
|
+ modelDataResult.setDeviceTypeName(firstResult.getDeviceTypeName());
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+ modelDataResult.setMonth(formattedDate);
|
|
|
+ modelDataResult.setYear(yearFormattedDate);
|
|
|
+
|
|
|
+ modelDataResults.add(modelDataResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray jsonResult = new JSONArray();
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
|
|
|
log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
@@ -604,6 +918,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject operatingStatistic() {
|
|
|
|
|
@@ -980,6 +1297,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
@Override
|
|
|
public JSONObject valleyPeakDifferenceStatistics() {
|
|
|
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
JSONObject result = new JSONObject();
|
|
|
Query query = new Query();
|
|
|
query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
@@ -1008,6 +1328,20 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
Map<String, DeviceInformation> mapA = deviceInformationList.stream()
|
|
|
.collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
|
|
|
|
|
|
+ List<String> regionIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceRegionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceRegion> regionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ regionLambdaQueryWrapper.in(DeviceRegion::getId, regionIds);
|
|
|
+ List<DeviceRegion> deviceRegionList = deviceRegionMapper.selectList(regionLambdaQueryWrapper);
|
|
|
+
|
|
|
+ Map<String, String> regionMap = deviceRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ DeviceRegion::getId, // Key: Device ID
|
|
|
+ DeviceRegion::getRegionTitle // Value: Device Title
|
|
|
+ ));
|
|
|
+
|
|
|
// 生成合并列表
|
|
|
List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
|
|
|
.map(b -> {
|
|
@@ -1038,7 +1372,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
// 结果列表
|
|
|
- List<ModelDataResult> modelDataResults = new ArrayList<>();
|
|
|
+ List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
|
|
|
// 遍历每个设备-区域组合和日期
|
|
|
for (String key : uniqueKeys) {
|
|
@@ -1047,6 +1381,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String deviceRegionId = keyParts[1];
|
|
|
|
|
|
for (String date : allDates) {
|
|
|
+
|
|
|
+ // 解析日期字符串为 LocalDate 对象
|
|
|
+ LocalDate datestr = LocalDate.parse(date, formatter);
|
|
|
+
|
|
|
+ // 获取年份和月份并拼接成 "yyyy年MM月" 格式
|
|
|
+ String formattedDate = datestr.getYear() + "年" + datestr.getMonthValue() + "月";
|
|
|
+
|
|
|
// 查找是否有对应设备和日期的对象
|
|
|
Optional<ModelReportFormResult> match = combinedList.stream()
|
|
|
.filter(model -> model.getDeviceInformationId().equals(deviceInformationId)
|
|
@@ -1054,6 +1395,10 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
&& model.getDates().equals(date))
|
|
|
.findFirst();
|
|
|
|
|
|
+ LambdaQueryWrapper<DeviceInformation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(DeviceInformation::getId, deviceInformationId);
|
|
|
+ DeviceInformation deviceInformation = deviceInformationMapper.selectOne(lambdaQueryWrapper);
|
|
|
+
|
|
|
if (match.isPresent()) {
|
|
|
// 如果有匹配对象,则按原逻辑处理
|
|
|
ModelReportFormResult modelReportFormResult = match.get();
|
|
@@ -1065,17 +1410,21 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
// 计算差值
|
|
|
BigDecimal difference = valleysPower.subtract(peaksPower).subtract(topsPower);
|
|
|
|
|
|
- ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
modelDataResult.setDeviceTitle(modelReportFormResult.getDeviceTitle());
|
|
|
modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
modelDataResult.setCreateTime(date);
|
|
|
modelDataResult.setValue(difference);
|
|
|
+ modelDataResult.setRegionTitle(regionMap.get(modelDataResult.getDeviceRegionId()));
|
|
|
+ modelDataResult.setDeviceTypeName(mapDeviceType(deviceInformation.getDeviceType()));
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+ modelDataResult.setMonth(formattedDate);
|
|
|
|
|
|
modelDataResults.add(modelDataResult);
|
|
|
} else {
|
|
|
// 如果没有匹配对象,则初始化一个新对象,value 设置为 0
|
|
|
- ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
DeviceInformation deviceInfo = mapA.get(deviceInformationId + "_" + deviceRegionId);
|
|
|
|
|
|
modelDataResult.setDeviceTitle(deviceInfo != null ? deviceInfo.getDeviceTitle() : "未知设备");
|
|
@@ -1083,12 +1432,17 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
modelDataResult.setCreateTime(date);
|
|
|
modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ modelDataResult.setRegionTitle(regionMap.get(modelDataResult.getDeviceRegionId()));
|
|
|
+ modelDataResult.setDeviceTypeName(mapDeviceType(deviceInformation.getDeviceType()));
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+ modelDataResult.setMonth(formattedDate);
|
|
|
|
|
|
modelDataResults.add(modelDataResult);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 转换为 JSON 格式
|
|
|
JSONArray jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
|
|
@@ -1097,6 +1451,117 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public JSONObject valleyPeakDifferenceStatisticsMonth() {
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Query query = new Query();
|
|
|
+ query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
+
|
|
|
+ // 查询 MongoDB 中的数据
|
|
|
+ List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList =
|
|
|
+ mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_day_powerproportioncurrent");
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(fpgStatiscsModelDataList)) {
|
|
|
+ log.info("{}{}", "mongo数据查询为空,峰平谷报表导出失败!", "total_day_powerproportioncurrent");
|
|
|
+ result.put("data", new JSONArray());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取设备 ID 列表
|
|
|
+ List<String> deviceInformationIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceInformationId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询设备信息
|
|
|
+ LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
|
|
|
+ List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 将设备信息转换为 Map,键为 (设备Id_区域Id)
|
|
|
+ Map<String, DeviceInformation> mapA = deviceInformationList.stream()
|
|
|
+ .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
|
|
|
+
|
|
|
+ List<String> regionIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceRegionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceRegion> regionLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ regionLambdaQueryWrapper.in(DeviceRegion::getId, regionIds);
|
|
|
+ List<DeviceRegion> deviceRegionList = deviceRegionMapper.selectList(regionLambdaQueryWrapper);
|
|
|
+
|
|
|
+ Map<String, String> regionMap = deviceRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(DeviceRegion::getId, DeviceRegion::getRegionTitle));
|
|
|
+
|
|
|
+ // 转换为合并列表
|
|
|
+ List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(b -> {
|
|
|
+ String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
|
|
|
+ DeviceInformation a = mapA.get(key);
|
|
|
+ if (a != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateString = sdf.format(b.getCreateTime());
|
|
|
+ return new ModelReportFormResult(
|
|
|
+ a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
|
|
|
+ b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
|
|
|
+ b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
|
|
|
+ b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
|
|
|
+ b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(),
|
|
|
+ b.getProportion(), b.getDates(), dateString, null, null);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 按设备和月份进行分组
|
|
|
+ Map<String, List<ModelReportFormResult>> groupedByDeviceAndMonth = combinedList.stream()
|
|
|
+ .collect(Collectors.groupingBy(resultItem -> resultItem.getDeviceInformationId() + "_" + resultItem.getDates().substring(0, 7)));
|
|
|
+
|
|
|
+ List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
+
|
|
|
+ // 遍历分组结果,计算月谷峰差值
|
|
|
+ for (Map.Entry<String, List<ModelReportFormResult>> entry : groupedByDeviceAndMonth.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<ModelReportFormResult> group = entry.getValue();
|
|
|
+
|
|
|
+ // 按设备信息和月份汇总月谷峰差值
|
|
|
+ BigDecimal monthlyDifference = group.stream()
|
|
|
+ .map(model -> model.getValleysPower()
|
|
|
+ .subtract(model.getPeaksPower())
|
|
|
+ .subtract(model.getTopsPower()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ // 获取分组的第一个对象作为模板
|
|
|
+ ModelReportFormResult firstResult = group.get(0);
|
|
|
+
|
|
|
+ // 构建报表对象
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
+ modelDataResult.setDeviceTitle(firstResult.getDeviceTitle());
|
|
|
+ modelDataResult.setDeviceRegionId(firstResult.getDeviceRegionId());
|
|
|
+ modelDataResult.setDeviceInformationId(firstResult.getDeviceInformationId());
|
|
|
+ modelDataResult.setCreateTime(firstResult.getDates().substring(0, 7)); // 取月份
|
|
|
+ modelDataResult.setValue(monthlyDifference); // 设置月谷峰差值
|
|
|
+ modelDataResult.setRegionTitle(regionMap.get(firstResult.getDeviceRegionId()));
|
|
|
+ modelDataResult.setDeviceTypeName(mapDeviceType(mapA.get(firstResult.getDeviceInformationId() + "_" + firstResult.getDeviceRegionId()).getDeviceType()));
|
|
|
+ modelDataResult.setCompanyName("龙钢公司");
|
|
|
+
|
|
|
+ // 解析日期为年份和月份
|
|
|
+ LocalDate date = LocalDate.parse(firstResult.getDates(), formatter);
|
|
|
+ modelDataResult.setMonth(date.getYear() + "年" + date.getMonthValue() + "月");
|
|
|
+ modelDataResult.setYear(date.getYear() + "年");
|
|
|
+
|
|
|
+ modelDataResults.add(modelDataResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为 JSON 格式
|
|
|
+ JSONArray jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
+ log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
|
+ result.put("data", jsonResult);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 基于模型编码、采集点ID、设备ID、区域ID、峰平谷配置时间范围 动态查询mongoDB
|
|
|
*
|