Browse Source

新增尖峰时段违规启动设备统计、峰平谷用电控制月报跟谷峰差月报统计接口

lingpeng.li 7 months ago
parent
commit
c36eec4d02

+ 21 - 1
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/controller/FpgLeanModelController.java

@@ -274,6 +274,16 @@ public class FpgLeanModelController extends JeecgController<FpgLeanModel, IFpgLe
 	}
 	}
 
 
 
 
+	@ApiOperation(value="峰平谷用电控制月报", notes="峰平谷用电控制月报")
+	@GetMapping(value = "/electricityControlMonth")
+	public JSONObject electricityControlMonth() {
+
+		JSONObject result = fpgLeanModelService.electricityControlMonth();
+
+		return result;
+	}
+
+
 	@ApiOperation(value="峰平谷运行统计表", notes="峰平谷运行统计表")
 	@ApiOperation(value="峰平谷运行统计表", notes="峰平谷运行统计表")
 	@GetMapping(value = "/operatingStatistic")
 	@GetMapping(value = "/operatingStatistic")
 	public JSONObject operatingStatistic() {
 	public JSONObject operatingStatistic() {
@@ -284,7 +294,7 @@ public class FpgLeanModelController extends JeecgController<FpgLeanModel, IFpgLe
 	}
 	}
 
 
 
 
-	@ApiOperation(value="峰平谷运行统计表", notes="峰平谷运行统计表")
+	@ApiOperation(value="谷峰差统计", notes="谷峰差统计")
 	@GetMapping(value = "/valleyPeakDifferenceStatistics")
 	@GetMapping(value = "/valleyPeakDifferenceStatistics")
 	public JSONObject valleyPeakDifferenceStatistics() {
 	public JSONObject valleyPeakDifferenceStatistics() {
 
 
@@ -292,4 +302,14 @@ public class FpgLeanModelController extends JeecgController<FpgLeanModel, IFpgLe
 
 
 		return result;
 		return result;
 	}
 	}
+
+
+	@ApiOperation(value="谷峰差统计", notes="谷峰差统计")
+	@GetMapping(value = "/valleyPeakDifferenceStatisticsMonth")
+	public JSONObject valleyPeakDifferenceStatisticsMonth() {
+
+		JSONObject result = fpgLeanModelService.valleyPeakDifferenceStatisticsMonth();
+
+		return result;
+	}
 }
 }

+ 15 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/entity/ElectricityControlReport.java

@@ -11,6 +11,9 @@ public class ElectricityControlReport {
     @ApiModelProperty(value = "峰平谷名称")
     @ApiModelProperty(value = "峰平谷名称")
     private String key;
     private String key;
 
 
+    @ApiModelProperty(value = "公司名称")
+    private String companyName;
+
     @ApiModelProperty(value = "设备名称")
     @ApiModelProperty(value = "设备名称")
     private String deviceTitle;
     private String deviceTitle;
     @ApiModelProperty(value = "区域名称")
     @ApiModelProperty(value = "区域名称")
@@ -80,8 +83,20 @@ public class ElectricityControlReport {
     @ApiModelProperty(value = "谷占比%")
     @ApiModelProperty(value = "谷占比%")
     private BigDecimal valleysProportion;
     private BigDecimal valleysProportion;
 
 
+    @ApiModelProperty(value = "总计")
     private BigDecimal total;
     private BigDecimal total;
 
 
+    @ApiModelProperty(value = "月份")
+    private String month;
+
+    @ApiModelProperty(value = "年份")
+    private String year;
+
+    @ApiModelProperty(value = "当月总计")
+    private String monthTotal;
+
+    private BigDecimal monthTotalValue;
+
     private Integer orderIndex;
     private Integer orderIndex;
 
 
 
 

+ 4 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/service/IFpgLeanModelService.java

@@ -30,9 +30,13 @@ public interface IFpgLeanModelService extends IService<FpgLeanModel> {
 
 
     JSONObject electricityControl();
     JSONObject electricityControl();
 
 
+    JSONObject electricityControlMonth();
+
     JSONObject operatingStatistic();
     JSONObject operatingStatistic();
 
 
     JSONObject valleyPeakDifferenceStatistics();
     JSONObject valleyPeakDifferenceStatistics();
 
 
+    JSONObject valleyPeakDifferenceStatisticsMonth();
+
 
 
 }
 }

+ 552 - 87
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/fpgLeanModel/service/impl/FpgLeanModelServiceImpl.java

@@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.time.format.DateTimeParseException;
@@ -309,6 +310,8 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
     @Override
     @Override
     public JSONObject totalElectricityConsumptionReport() {
     public JSONObject totalElectricityConsumptionReport() {
 
 
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
         JSONObject result = new JSONObject();
         JSONObject result = new JSONObject();
         Query query = new Query();
         Query query = new Query();
         query.with(Sort.by(Sort.Direction.ASC, "createTime"));
         query.with(Sort.by(Sort.Direction.ASC, "createTime"));
@@ -327,18 +330,26 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
         queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
         List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
         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
         // 将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.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
                                 b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
                                 b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
                                 b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
                                 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;
                     return null;
                 }).filter(x -> x != null).collect(Collectors.toList());
                 }).filter(x -> x != null).collect(Collectors.toList());
         JSONArray jsonResult = new JSONArray();
         JSONArray jsonResult = new JSONArray();
 
 
         // 龙钢变各工序报表
         // 龙钢变各工序报表
-        List<ModelDataResult> modelDataResults = new ArrayList<>();
+        List<ElectricityControlReport> modelDataResults = new ArrayList<>();
         for (ModelReportFormResult modelReportFormResult : combinedList) {
         for (ModelReportFormResult modelReportFormResult : combinedList) {
 
 
             BigDecimal sum = modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower());
             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 deviceRegionId = modelReportFormResult.getDeviceRegionId();
             String deviceInformationId = modelReportFormResult.getDeviceInformationId();
             String deviceInformationId = modelReportFormResult.getDeviceInformationId();
             String createTime = modelReportFormResult.getDates();
             String createTime = modelReportFormResult.getDates();
+            String regionTitle = modelReportFormResult.getRegionName();
+            String deviceTypeName = modelReportFormResult.getDeviceTypeName();
             for (int i = 0; i < 5; i++) {
             for (int i = 0; i < 5; i++) {
-                ModelDataResult modelDataResult = new ModelDataResult();
+                ElectricityControlReport modelDataResult = new ElectricityControlReport();
 
 
                 if (i == 0) {
                 if (i == 0) {
                     modelDataResult.setKey("反有总");
                     modelDataResult.setKey("反有总");
@@ -403,10 +416,20 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
                     modelDataResult.setValue(modelReportFormResult.getValleysPower());
                     modelDataResult.setValue(modelReportFormResult.getValleysPower());
                 }
                 }
 
 
+                // 解析日期字符串为 LocalDate 对象
+                LocalDate date = LocalDate.parse(createTime, formatter);
+
+                // 获取年份和月份并拼接成 "yyyy年MM月" 格式
+                String formattedDate = date.getYear() + "年" + date.getMonthValue() + "月";
+
                 modelDataResult.setDeviceTitle(deviceTitle);
                 modelDataResult.setDeviceTitle(deviceTitle);
                 modelDataResult.setDeviceRegionId(deviceRegionId);
                 modelDataResult.setDeviceRegionId(deviceRegionId);
                 modelDataResult.setDeviceInformationId(deviceInformationId);
                 modelDataResult.setDeviceInformationId(deviceInformationId);
                 modelDataResult.setCreateTime(createTime);
                 modelDataResult.setCreateTime(createTime);
+                modelDataResult.setRegionTitle(regionTitle);
+                modelDataResult.setDeviceTypeName(deviceTypeName);
+                modelDataResult.setCompanyName("龙钢公司");
+                modelDataResult.setMonth(formattedDate);
                 modelDataResults.add(modelDataResult);
                 modelDataResults.add(modelDataResult);
             }
             }
         }
         }
@@ -421,6 +444,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
     @Override
     @Override
     public JSONObject electricityControl() {
     public JSONObject electricityControl() {
 
 
+        // 定义日期格式
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
         JSONObject result = new JSONObject();
         JSONObject result = new JSONObject();
         Query query = new Query();
         Query query = new Query();
         query.with(Sort.by(Sort.Direction.ASC, "createTime"));
         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> modelDataResults = new ArrayList<>();
+        List<ElectricityControlReport> finalResult = new ArrayList<>();
         for (ModelReportFormResult modelReportFormResult : combinedList) {
         for (ModelReportFormResult modelReportFormResult : combinedList) {
 
 
             BigDecimal sum = modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower());
             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 createTime = modelReportFormResult.getDates();
             String regionTitle = modelReportFormResult.getRegionName();
             String regionTitle = modelReportFormResult.getRegionName();
             String deviceTypeName = modelReportFormResult.getDeviceTypeName();
             String deviceTypeName = modelReportFormResult.getDeviceTypeName();
-            for (int i = 0; i < 9; i++) {
-
+            for (int i = 0; i < 4; i++) {
                 ElectricityControlReport modelDataResult = new ElectricityControlReport();
                 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) {
                 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.setKey("尖");
                     modelDataResult.setKey1("尖");
                     modelDataResult.setKey1("尖");
                     modelDataResult.setValue(modelReportFormResult.getTopsPower());
                     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.setKey("峰");
                     modelDataResult.setKey1("峰");
                     modelDataResult.setKey1("峰");
                     modelDataResult.setValue(modelReportFormResult.getPeaksPower());
                     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.setKey("平");
                     modelDataResult.setKey1("平");
                     modelDataResult.setKey1("平");
                     modelDataResult.setValue(modelReportFormResult.getFlatPower());
                     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.setKey("谷");
                     modelDataResult.setKey1("谷");
                     modelDataResult.setKey1("谷");
                     modelDataResult.setValue(modelReportFormResult.getValleysPower());
                     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.setDeviceTitle(deviceTitle);
                 modelDataResult.setDeviceRegionId(deviceRegionId);
                 modelDataResult.setDeviceRegionId(deviceRegionId);
                 modelDataResult.setDeviceInformationId(deviceInformationId);
                 modelDataResult.setDeviceInformationId(deviceInformationId);
                 modelDataResult.setCreateTime(createTime);
                 modelDataResult.setCreateTime(createTime);
                 modelDataResult.setRegionTitle(regionTitle);
                 modelDataResult.setRegionTitle(regionTitle);
                 modelDataResult.setDeviceTypeName(deviceTypeName);
                 modelDataResult.setDeviceTypeName(deviceTypeName);
+                modelDataResult.setCompanyName("龙钢公司");
+                modelDataResult.setMonth(formattedDate);
+                modelDataResult.setMonthTotal(formattedDate + "总计");
+
                 modelDataResults.add(modelDataResult);
                 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));
         jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
 
 
         log.info("{}{}", "积木报表导出总数:", jsonResult.size());
         log.info("{}{}", "积木报表导出总数:", jsonResult.size());
@@ -604,6 +918,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         return result;
         return result;
     }
     }
 
 
+
+
+
     @Override
     @Override
     public JSONObject operatingStatistic() {
     public JSONObject operatingStatistic() {
 
 
@@ -980,6 +1297,9 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
     @Override
     @Override
     public JSONObject valleyPeakDifferenceStatistics() {
     public JSONObject valleyPeakDifferenceStatistics() {
 
 
+        // 定义日期格式
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
         JSONObject result = new JSONObject();
         JSONObject result = new JSONObject();
         Query query = new Query();
         Query query = new Query();
         query.with(Sort.by(Sort.Direction.ASC, "createTime"));
         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()
         Map<String, DeviceInformation> mapA = deviceInformationList.stream()
                 .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
                 .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()
         List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
                 .map(b -> {
                 .map(b -> {
@@ -1038,7 +1372,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
                 .collect(Collectors.toSet());
                 .collect(Collectors.toSet());
 
 
         // 结果列表
         // 结果列表
-        List<ModelDataResult> modelDataResults = new ArrayList<>();
+        List<ElectricityControlReport> modelDataResults = new ArrayList<>();
 
 
         // 遍历每个设备-区域组合和日期
         // 遍历每个设备-区域组合和日期
         for (String key : uniqueKeys) {
         for (String key : uniqueKeys) {
@@ -1047,6 +1381,13 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
             String deviceRegionId = keyParts[1];
             String deviceRegionId = keyParts[1];
 
 
             for (String date : allDates) {
             for (String date : allDates) {
+
+                // 解析日期字符串为 LocalDate 对象
+                LocalDate datestr = LocalDate.parse(date, formatter);
+
+                // 获取年份和月份并拼接成 "yyyy年MM月" 格式
+                String formattedDate = datestr.getYear() + "年" + datestr.getMonthValue() + "月";
+
                 // 查找是否有对应设备和日期的对象
                 // 查找是否有对应设备和日期的对象
                 Optional<ModelReportFormResult> match = combinedList.stream()
                 Optional<ModelReportFormResult> match = combinedList.stream()
                         .filter(model -> model.getDeviceInformationId().equals(deviceInformationId)
                         .filter(model -> model.getDeviceInformationId().equals(deviceInformationId)
@@ -1054,6 +1395,10 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
                                 && model.getDates().equals(date))
                                 && model.getDates().equals(date))
                         .findFirst();
                         .findFirst();
 
 
+                LambdaQueryWrapper<DeviceInformation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+                lambdaQueryWrapper.eq(DeviceInformation::getId, deviceInformationId);
+                DeviceInformation deviceInformation = deviceInformationMapper.selectOne(lambdaQueryWrapper);
+
                 if (match.isPresent()) {
                 if (match.isPresent()) {
                     // 如果有匹配对象,则按原逻辑处理
                     // 如果有匹配对象,则按原逻辑处理
                     ModelReportFormResult modelReportFormResult = match.get();
                     ModelReportFormResult modelReportFormResult = match.get();
@@ -1065,17 +1410,21 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
                     // 计算差值
                     // 计算差值
                     BigDecimal difference = valleysPower.subtract(peaksPower).subtract(topsPower);
                     BigDecimal difference = valleysPower.subtract(peaksPower).subtract(topsPower);
 
 
-                    ModelDataResult modelDataResult = new ModelDataResult();
+                    ElectricityControlReport modelDataResult = new ElectricityControlReport();
                     modelDataResult.setDeviceTitle(modelReportFormResult.getDeviceTitle());
                     modelDataResult.setDeviceTitle(modelReportFormResult.getDeviceTitle());
                     modelDataResult.setDeviceRegionId(deviceRegionId);
                     modelDataResult.setDeviceRegionId(deviceRegionId);
                     modelDataResult.setDeviceInformationId(deviceInformationId);
                     modelDataResult.setDeviceInformationId(deviceInformationId);
                     modelDataResult.setCreateTime(date);
                     modelDataResult.setCreateTime(date);
                     modelDataResult.setValue(difference);
                     modelDataResult.setValue(difference);
+                    modelDataResult.setRegionTitle(regionMap.get(modelDataResult.getDeviceRegionId()));
+                    modelDataResult.setDeviceTypeName(mapDeviceType(deviceInformation.getDeviceType()));
+                    modelDataResult.setCompanyName("龙钢公司");
+                    modelDataResult.setMonth(formattedDate);
 
 
                     modelDataResults.add(modelDataResult);
                     modelDataResults.add(modelDataResult);
                 } else {
                 } else {
                     // 如果没有匹配对象,则初始化一个新对象,value 设置为 0
                     // 如果没有匹配对象,则初始化一个新对象,value 设置为 0
-                    ModelDataResult modelDataResult = new ModelDataResult();
+                    ElectricityControlReport modelDataResult = new ElectricityControlReport();
                     DeviceInformation deviceInfo = mapA.get(deviceInformationId + "_" + deviceRegionId);
                     DeviceInformation deviceInfo = mapA.get(deviceInformationId + "_" + deviceRegionId);
 
 
                     modelDataResult.setDeviceTitle(deviceInfo != null ? deviceInfo.getDeviceTitle() : "未知设备");
                     modelDataResult.setDeviceTitle(deviceInfo != null ? deviceInfo.getDeviceTitle() : "未知设备");
@@ -1083,12 +1432,17 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
                     modelDataResult.setDeviceInformationId(deviceInformationId);
                     modelDataResult.setDeviceInformationId(deviceInformationId);
                     modelDataResult.setCreateTime(date);
                     modelDataResult.setCreateTime(date);
                     modelDataResult.setValue(BigDecimal.ZERO);
                     modelDataResult.setValue(BigDecimal.ZERO);
+                    modelDataResult.setRegionTitle(regionMap.get(modelDataResult.getDeviceRegionId()));
+                    modelDataResult.setDeviceTypeName(mapDeviceType(deviceInformation.getDeviceType()));
+                    modelDataResult.setCompanyName("龙钢公司");
+                    modelDataResult.setMonth(formattedDate);
 
 
                     modelDataResults.add(modelDataResult);
                     modelDataResults.add(modelDataResult);
                 }
                 }
             }
             }
         }
         }
 
 
+
         // 转换为 JSON 格式
         // 转换为 JSON 格式
         JSONArray jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
         JSONArray jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
 
 
@@ -1097,6 +1451,117 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
         return result;
         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
      * 基于模型编码、采集点ID、设备ID、区域ID、峰平谷配置时间范围 动态查询mongoDB
      *
      *

+ 33 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/homePageData/controller/HomePageDataController.java

@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.homePageData.entity.IllegalResult;
 import org.jeecg.modules.homePageData.service.IHomePageDataService;
 import org.jeecg.modules.homePageData.service.IHomePageDataService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -167,6 +169,37 @@ public class HomePageDataController {
     }
     }
 
 
 
 
+    /**
+     *  尖峰时段违规启动设备统计
+     *
+     * @return
+     */
+    @AutoLog(value = "尖峰时段违规启动设备统计")
+    @ApiOperation(value="尖峰时段违规启动设备统计", notes="尖峰时段违规启动设备统计")
+    @GetMapping(value = "/illegalActivation")
+    public Result<Map<String, Integer>> illegalActivation() {
+        Map<String, Integer> res = homePageDataService.illegalActivation();
+        return Result.OK(res);
+    }
+
+
+    @AutoLog(value = "尖时段违规启动设备详情")
+    @ApiOperation(value="尖时段违规启动设备详情", notes="尖时段违规启动设备详情")
+    @GetMapping(value = "/topsIllegalActivation")
+    public Result<List<IllegalResult>> topsIllegalActivation() {
+        List<IllegalResult> illegalResultList = homePageDataService.topsIllegalActivation();
+        return Result.OK(illegalResultList);
+    }
+
+    @AutoLog(value = "峰时段违规启动设备详情")
+    @ApiOperation(value="峰时段违规启动设备详情", notes="峰时段违规启动设备详情")
+    @GetMapping(value = "/peaksIllegalActivation")
+    public Result<List<IllegalResult>> peaksIllegalActivation() {
+        List<IllegalResult> illegalResultList = homePageDataService.peaksIllegalActivation();
+        return Result.OK(illegalResultList);
+    }
+
+
     /**
     /**
      * 最新消息
      * 最新消息
      *
      *

+ 20 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/homePageData/entity/IllegalResult.java

@@ -0,0 +1,20 @@
+package org.jeecg.modules.homePageData.entity;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class IllegalResult {
+
+    private String deviceTitle;
+
+    private Date CreateTime;
+
+    private BigDecimal ingTime;
+
+    private BigDecimal power;
+
+
+}

+ 15 - 0
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/homePageData/service/IHomePageDataService.java

@@ -1,5 +1,7 @@
 package org.jeecg.modules.homePageData.service;
 package org.jeecg.modules.homePageData.service;
 
 
+import org.jeecg.modules.homePageData.entity.IllegalResult;
+
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -68,6 +70,19 @@ public interface IHomePageDataService {
      */
      */
     Map<String, Integer> deviceThresholdStats();
     Map<String, Integer> deviceThresholdStats();
 
 
+
+    /**
+     * 尖峰时段违规启动设备统计
+     *
+     * @return
+     */
+    Map<String, Integer> illegalActivation();
+
+
+    List<IllegalResult> topsIllegalActivation();
+
+    List<IllegalResult> peaksIllegalActivation();
+
     /**
     /**
      * 最新消息
      * 最新消息
      *
      *

+ 572 - 54
zgztBus/jeecg-module-lesm/src/main/java/org/jeecg/modules/homePageData/service/impl/HomePageDataServiceImpl.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.homePageData.service.impl;
 package org.jeecg.modules.homePageData.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.common.ModelCodeContant;
 import org.jeecg.modules.common.ModelCodeContant;
 import org.jeecg.modules.deviceLesm.entity.DeviceInformation;
 import org.jeecg.modules.deviceLesm.entity.DeviceInformation;
@@ -10,10 +11,15 @@ import org.jeecg.modules.deviceLesm.mapper.DevicePointMapper;
 import org.jeecg.modules.deviceLesm.service.IDeviceInformationService;
 import org.jeecg.modules.deviceLesm.service.IDeviceInformationService;
 import org.jeecg.modules.deviceLesm.service.IDeviceRegionService;
 import org.jeecg.modules.deviceLesm.service.IDeviceRegionService;
 import org.jeecg.modules.deviceLesm.service.impl.IDeviceOperationLogServiceImpl;
 import org.jeecg.modules.deviceLesm.service.impl.IDeviceOperationLogServiceImpl;
+import org.jeecg.modules.events.entity.LeanEventsHost;
+import org.jeecg.modules.events.service.impl.LeanEventsHostServiceImpl;
 import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
 import org.jeecg.modules.fpgLeanModel.entity.DeviceStatiscsModelMongodb;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModel;
 import org.jeecg.modules.fpgLeanModel.entity.FpgLeanModel;
+import org.jeecg.modules.fpgLeanModel.entity.LeanModelDeviceHistoryInfo;
 import org.jeecg.modules.fpgLeanModel.service.IFpgLeanModelService;
 import org.jeecg.modules.fpgLeanModel.service.IFpgLeanModelService;
 import org.jeecg.modules.gatherData.mapper.FpgGatherDataMapper;
 import org.jeecg.modules.gatherData.mapper.FpgGatherDataMapper;
+import org.jeecg.modules.homePageData.entity.IllegalResult;
+import org.jeecg.modules.homePageData.entity.LeanEventWarnInfo;
 import org.jeecg.modules.homePageData.entity.LeanEventWarnInfoResult;
 import org.jeecg.modules.homePageData.entity.LeanEventWarnInfoResult;
 import org.jeecg.modules.homePageData.entity.ViolationStatisticsResult;
 import org.jeecg.modules.homePageData.entity.ViolationStatisticsResult;
 import org.jeecg.modules.homePageData.mapper.LeanEventWarnInfoMapper;
 import org.jeecg.modules.homePageData.mapper.LeanEventWarnInfoMapper;
@@ -28,12 +34,17 @@ import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 
 
 
 @Service
 @Service
@@ -66,15 +77,22 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
     @Autowired
     @Autowired
     private IDeviceOperationLogServiceImpl deviceOperationLogService;
     private IDeviceOperationLogServiceImpl deviceOperationLogService;
 
 
+    @Autowired
+    private LeanEventsHostServiceImpl leanEventsHostService;
+
+    @Autowired
+    private LeanEventWarnInfoServiceImpl leanEventWarnInfoService;
+
+
     @Override
     @Override
     public List<Map<String, String>> regionPfvElectricity(String modelId) {
     public List<Map<String, String>> regionPfvElectricity(String modelId) {
         String leanModelCode = queryLeanModelCodeById(modelId);
         String leanModelCode = queryLeanModelCodeById(modelId);
         Date today = new Date();
         Date today = new Date();
         String dayDate = new SimpleDateFormat("yyyy-MM-dd").format(today);
         String dayDate = new SimpleDateFormat("yyyy-MM-dd").format(today);
         List<DeviceRegion> list = deviceRegionService.list();
         List<DeviceRegion> list = deviceRegionService.list();
-        List<PeaksAndValleysTimeConfig>  peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
+        List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
         List<Map<String, String>> res = new ArrayList<>();
         List<Map<String, String>> res = new ArrayList<>();
-        if(oConvertUtils.listIsNotEmpty(list)){
+        if (oConvertUtils.listIsNotEmpty(list)) {
             list.forEach(deviceRegion -> {
             list.forEach(deviceRegion -> {
                 Map<String, String> map = new HashMap<>();
                 Map<String, String> map = new HashMap<>();
                 Map<String, Object> mapSum = new HashMap<>();
                 Map<String, Object> mapSum = new HashMap<>();
@@ -86,28 +104,28 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
                 peaksAndValleysTimeConfiglist.forEach(peaksAndValleysTime -> {
                 peaksAndValleysTimeConfiglist.forEach(peaksAndValleysTime -> {
                     String startDate = dayDate + " " + peaksAndValleysTime.getStartTime();
                     String startDate = dayDate + " " + peaksAndValleysTime.getStartTime();
                     String endDate = dayDate + " " + peaksAndValleysTime.getEndTime();
                     String endDate = dayDate + " " + peaksAndValleysTime.getEndTime();
-                    Map peaksAndValleysTimeMap= fpgGatherDataMapper.getFpgTheLeftSideOneData(deviceRegion.getId(), startDate, endDate);
-                    if(peaksAndValleysTimeMap != null){
-                        if("tops".equals(peaksAndValleysTime.getType())){ // 尖值处理
+                    Map peaksAndValleysTimeMap = fpgGatherDataMapper.getFpgTheLeftSideOneData(deviceRegion.getId(), startDate, endDate);
+                    if (peaksAndValleysTimeMap != null) {
+                        if ("tops".equals(peaksAndValleysTime.getType())) { // 尖值处理
                             BigDecimal topsAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal topsAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal topsSum = new BigDecimal(String.valueOf(mapSum.get("topsSum")));
                             BigDecimal topsSum = new BigDecimal(String.valueOf(mapSum.get("topsSum")));
                             mapSum.put("topsSum", topsSum.add(topsAmount));
                             mapSum.put("topsSum", topsSum.add(topsAmount));
-                        }else if("peaks".equals(peaksAndValleysTime.getType())){ // 峰值处理
+                        } else if ("peaks".equals(peaksAndValleysTime.getType())) { // 峰值处理
                             BigDecimal peaksAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal peaksAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal peaksSum = new BigDecimal(String.valueOf(mapSum.get("peaksSum")));
                             BigDecimal peaksSum = new BigDecimal(String.valueOf(mapSum.get("peaksSum")));
                             mapSum.put("peaksSum", peaksSum.add(peaksAmount));
                             mapSum.put("peaksSum", peaksSum.add(peaksAmount));
-                        }else if("flat".equals(peaksAndValleysTime.getType())){ // 平值处理
+                        } else if ("flat".equals(peaksAndValleysTime.getType())) { // 平值处理
                             BigDecimal flatAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal flatAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal flatSum = new BigDecimal(String.valueOf(mapSum.get("flatSum")));
                             BigDecimal flatSum = new BigDecimal(String.valueOf(mapSum.get("flatSum")));
                             mapSum.put("flatSum", flatSum.add(flatAmount));
                             mapSum.put("flatSum", flatSum.add(flatAmount));
-                        }else if("valleys".equals(peaksAndValleysTime.getType())){ // 谷值处理
+                        } else if ("valleys".equals(peaksAndValleysTime.getType())) { // 谷值处理
                             BigDecimal valleysAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal valleysAmount = new BigDecimal(String.valueOf(peaksAndValleysTimeMap.get("active_power")));
                             BigDecimal valleysSum = new BigDecimal(String.valueOf(mapSum.get("valleysSum")));
                             BigDecimal valleysSum = new BigDecimal(String.valueOf(mapSum.get("valleysSum")));
                             mapSum.put("valleysSum", valleysSum.add(valleysAmount));
                             mapSum.put("valleysSum", valleysSum.add(valleysAmount));
                         }
                         }
                     }
                     }
                 });
                 });
-                map.put("name",deviceRegion.getRegionTitle());
+                map.put("name", deviceRegion.getRegionTitle());
                 map.put("tops", String.format("%.2f", mapSum.get("topsSum")));
                 map.put("tops", String.format("%.2f", mapSum.get("topsSum")));
                 map.put("peaks", String.format("%.2f", mapSum.get("peaksSum")));
                 map.put("peaks", String.format("%.2f", mapSum.get("peaksSum")));
                 map.put("flat", String.format("%.2f", mapSum.get("flatSum")));
                 map.put("flat", String.format("%.2f", mapSum.get("flatSum")));
@@ -125,22 +143,22 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
         List<Map<String, Object>> devices = new ArrayList<>();
         List<Map<String, Object>> devices = new ArrayList<>();
         AtomicReference<Integer> online = new AtomicReference<>(0);
         AtomicReference<Integer> online = new AtomicReference<>(0);
         AtomicReference<Integer> offline = new AtomicReference<>(0);
         AtomicReference<Integer> offline = new AtomicReference<>(0);
-        if(oConvertUtils.listIsNotEmpty(list)){
+        if (oConvertUtils.listIsNotEmpty(list)) {
             list.forEach(deviceRegion -> {
             list.forEach(deviceRegion -> {
                 List<DeviceInformation> deviceInformationList = deviceInformationService.list(new LambdaQueryWrapper<DeviceInformation>().eq(DeviceInformation::getDeviceRegionId, deviceRegion.getId()));
                 List<DeviceInformation> deviceInformationList = deviceInformationService.list(new LambdaQueryWrapper<DeviceInformation>().eq(DeviceInformation::getDeviceRegionId, deviceRegion.getId()));
                 Map<String, Object> map = new HashMap<>();
                 Map<String, Object> map = new HashMap<>();
-                map.put("online",  0);
-                map.put("offline",  0);
+                map.put("online", 0);
+                map.put("offline", 0);
                 deviceInformationList.forEach(x -> {
                 deviceInformationList.forEach(x -> {
-                    if("0".equals(x.getStatus())){ // 在线
+                    if ("0".equals(x.getStatus())) { // 在线
                         map.put("online", (int) map.get("online") + 1);
                         map.put("online", (int) map.get("online") + 1);
-                    }else{ // 离线
+                    } else { // 离线
                         map.put("offline", (int) map.get("offline") + 1);
                         map.put("offline", (int) map.get("offline") + 1);
                     }
                     }
                 });
                 });
                 map.put("name", deviceRegion.getRegionTitle());
                 map.put("name", deviceRegion.getRegionTitle());
-                online.updateAndGet(v -> v + (int)map.get("online"));
-                offline.updateAndGet(v -> v + (int)map.get("offline"));
+                online.updateAndGet(v -> v + (int) map.get("online"));
+                offline.updateAndGet(v -> v + (int) map.get("offline"));
                 devices.add(map);
                 devices.add(map);
             });
             });
         }
         }
@@ -168,7 +186,7 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
         List<Map<String, String>> res = new ArrayList<>();
         List<Map<String, String>> res = new ArrayList<>();
         List<DeviceRegion> list = deviceRegionService.list();
         List<DeviceRegion> list = deviceRegionService.list();
         list.forEach(deviceRegion -> {
         list.forEach(deviceRegion -> {
-            Map<String,String> map = new HashMap<>();
+            Map<String, String> map = new HashMap<>();
             ViolationStatisticsResult dayViolationStatisticsResult = leanEventWarnInfoMapper.queryViolationDayStatistics(deviceRegion.getId());
             ViolationStatisticsResult dayViolationStatisticsResult = leanEventWarnInfoMapper.queryViolationDayStatistics(deviceRegion.getId());
             ViolationStatisticsResult monthViolationStatisticsResult = leanEventWarnInfoMapper.queryViolationMonthStatistics(deviceRegion.getId(), new Date());
             ViolationStatisticsResult monthViolationStatisticsResult = leanEventWarnInfoMapper.queryViolationMonthStatistics(deviceRegion.getId(), new Date());
             map.put("name", deviceRegion.getRegionTitle());
             map.put("name", deviceRegion.getRegionTitle());
@@ -184,18 +202,79 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
         List<Map<String, String>> res = new ArrayList<>();
         List<Map<String, String>> res = new ArrayList<>();
         String leanModelCode = queryLeanModelCodeById(modelId);
         String leanModelCode = queryLeanModelCodeById(modelId);
 
 
-        String[] names = {"棒一","棒二","棒三","高线","板带"};
-        Arrays.asList(names).forEach(name -> {
-            Map<String, String> map = new HashMap<>();
-            Double electricity = Math.random()*100+200;
-            map.put("name",name);
-            map.put("tops", String.format("%.2f",electricity*(Math.random()*0.2+1)));
-            map.put("peaks", String.format("%.2f",electricity));
-            map.put("flat", String.format("%.2f",electricity*(Math.random()*0.2+0.7)));
-            map.put("valleys", String.format("%.2f",electricity*(Math.random()*0.2+0.5)));
-            res.add(map);
+        String[] names = {"棒一", "棒二", "棒三", "高线", "板带"};
+
+        LambdaQueryWrapper<DeviceRegion> regionWrapper = new LambdaQueryWrapper<>();
+        regionWrapper.eq(DeviceRegion::getRegionTitle, "轧钢厂");
+        DeviceRegion deviceRegion = deviceRegionService.getOne(regionWrapper);
+
+        LambdaQueryWrapper<DeviceInformation> informationWrapper = new LambdaQueryWrapper<>();
+        informationWrapper.eq(DeviceInformation::getDeviceRegionId, deviceRegion.getId());
+        List<DeviceInformation> deviceInformations = deviceInformationService.list(informationWrapper);
+
+        // 按 DeviceInformation::getDeviceType 分组
+        Map<String, List<DeviceInformation>> groupedByDeviceType = deviceInformations.stream()
+                .collect(Collectors.groupingBy(DeviceInformation::getDeviceType));
+
+        // 创建一个 Map 用于存储每个 deviceType 的 power 累积
+        Map<String, BigDecimal> powerAccumulation = new HashMap<>();
+
+        groupedByDeviceType.forEach((deviceType, devices) -> {
+            devices.forEach(device -> {
+                Query querylr = new Query();
+                querylr.addCriteria(Criteria.where("deviceInformationId").in(device.getId()));
+
+                // 执行查询
+                List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(querylr, DeviceStatiscsModelMongodb.class, "leanmodel_run_realtime");
+
+                // 根据 datestr 降序排列,并取最新一条
+                if (deviceStatiscsModelMongodbList != null && !deviceStatiscsModelMongodbList.isEmpty()) {
+                    DeviceStatiscsModelMongodb latestRecord = deviceStatiscsModelMongodbList.stream()
+                            .sorted((d1, d2) -> d2.getDatestr().compareTo(d1.getDatestr()))  // 降序排序
+                            .findFirst()  // 获取第一条数据(即最新的数据)
+                            .orElse(null);  // 如果没有数据,返回 null
+
+                    // 如果找到最新记录,累加 power
+                    if (latestRecord != null) {
+                        BigDecimal power = latestRecord.getPower();  // 假设 power 字段是 BigDecimal 类型
+                        if (power != null) {
+                            // 累加到对应的 deviceType 中
+                            powerAccumulation.merge(deviceType, power, BigDecimal::add);
+                        }
+                    }
+                }
+            });
         });
         });
 
 
+        // 计算实时总电压占比
+        BigDecimal totalPower = powerAccumulation.values().stream()
+                .reduce(BigDecimal.ZERO, BigDecimal::add); // 计算所有设备的实时总电压
+
+        for (int i = 0; i < names.length; i++) {
+            String deviceTypeKey = String.valueOf(i + 1); // deviceType 从 1 开始
+            BigDecimal currentPower = powerAccumulation.getOrDefault(deviceTypeKey, BigDecimal.ZERO);
+
+            BigDecimal proportion = totalPower.compareTo(BigDecimal.ZERO) > 0
+                    ? currentPower.divide(totalPower, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros() // 转为百分比并保留 4 位小数
+                    : BigDecimal.ZERO;
+
+            // 统计 status 为 0 的设备数量
+            long statusZeroCount = groupedByDeviceType
+                    .getOrDefault(deviceTypeKey, Collections.emptyList())
+                    .stream()
+                    .filter(device -> device != null && "0".equals(device.getStatus())) // 双重防护
+                    .count();
+
+
+            // 构造返回数据
+            Map<String, String> data = new HashMap<>();
+            data.put("name", names[i]);
+            data.put("proportion", proportion.toString());
+            data.put("statusZeroCount", String.valueOf(statusZeroCount));
+
+            res.add(data);
+        }
+
         return res;
         return res;
     }
     }
 
 
@@ -204,7 +283,7 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
         Map<String, List> res = new HashMap<>();
         Map<String, List> res = new HashMap<>();
         // 根据模型ID查询模型编码
         // 根据模型ID查询模型编码
         String leanModelCode = queryLeanModelCodeById(modelId);
         String leanModelCode = queryLeanModelCodeById(modelId);
-        if (leanModelCode.equals(ModelCodeContant.LARGE_SCREEN_RUN_REALTIME)){
+        if (leanModelCode.equals(ModelCodeContant.LARGE_SCREEN_RUN_REALTIME)) {
             Query query = new Query();
             Query query = new Query();
             query.with(Sort.by(Sort.Direction.ASC, "createTime"));
             query.with(Sort.by(Sort.Direction.ASC, "createTime"));
             // 获取当前日期
             // 获取当前日期
@@ -213,12 +292,12 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             // 将当前日期格式化为字符串
             // 将当前日期格式化为字符串
             String formattedDate = currentDate.format(formatter);
             String formattedDate = currentDate.format(formatter);
-            String  queryDateParam = "";
+            String queryDateParam = "";
             queryDateParam = formattedDate;
             queryDateParam = formattedDate;
             query.addCriteria(Criteria.where("dates").is(queryDateParam));
             query.addCriteria(Criteria.where("dates").is(queryDateParam));
             // 执行查询
             // 执行查询
             List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "leanmodel_large_screen_run_realtime");
             List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "leanmodel_large_screen_run_realtime");
-            if (oConvertUtils.listIsEmpty(deviceStatiscsModelMongodbList)){
+            if (oConvertUtils.listIsEmpty(deviceStatiscsModelMongodbList)) {
                 return res;
                 return res;
             }
             }
             deviceStatiscsModelMongodbList.forEach(x -> {
             deviceStatiscsModelMongodbList.forEach(x -> {
@@ -236,14 +315,14 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
     public List<Map<String, String>> realAlarm() {
     public List<Map<String, String>> realAlarm() {
         List<Map<String, String>> res = new ArrayList<>();
         List<Map<String, String>> res = new ArrayList<>();
         List<LeanEventWarnInfoResult> leanEventWarnInfoResult = leanEventWarnInfoMapper.queryLeanEventWarnInfo();
         List<LeanEventWarnInfoResult> leanEventWarnInfoResult = leanEventWarnInfoMapper.queryLeanEventWarnInfo();
-        if(oConvertUtils.listIsNotEmpty(leanEventWarnInfoResult)){
-            leanEventWarnInfoResult.forEach(x ->{
+        if (oConvertUtils.listIsNotEmpty(leanEventWarnInfoResult)) {
+            leanEventWarnInfoResult.forEach(x -> {
                 Map<String, String> map = new HashMap<>();
                 Map<String, String> map = new HashMap<>();
                 SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                 SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                 map.put("time", format.format(x.getCreateTime()));
                 map.put("time", format.format(x.getCreateTime()));
                 map.put("name", x.getDeviceTitle());
                 map.put("name", x.getDeviceTitle());
                 map.put("alarmInfo", x.getDeviceWarnInfo());
                 map.put("alarmInfo", x.getDeviceWarnInfo());
-                map.put("level",x.getDeviceWarnLevel());
+                map.put("level", x.getDeviceWarnLevel());
                 res.add(map);
                 res.add(map);
             });
             });
         }
         }
@@ -252,28 +331,85 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
 
 
     @Override
     @Override
     public List<Map<String, String>> realDeviceRun() {
     public List<Map<String, String>> realDeviceRun() {
-        List<DeviceRegion> list = deviceRegionService.list();
-        List<Map<String, String>> res = new ArrayList<>();
-        if(oConvertUtils.listIsNotEmpty(list)){
-            list.forEach(deviceRegion -> {
-                Map<String,String> map = new HashMap<>();
-                map.put("name",deviceRegion.getRegionTitle());
-                map.put("value",(int)(Math.random()*25+25)+"");
-                res.add(map);
-            });
+        List<DeviceRegion> list = deviceRegionService.list(); // 获取所有设备区域
+        List<Map<String, String>> res = new ArrayList<>(); // 存储结果
+
+        // 获取当前日期并计算当月的起始日期和结束日期
+        LocalDate now = LocalDate.now();
+        LocalDate startOfMonth = now.withDayOfMonth(1); // 当前月的第一天
+        LocalDate endOfMonth = now.withDayOfMonth(now.lengthOfMonth()); // 当前月的最后一天
+
+        // 使用 DateTimeFormatter 将 LocalDate 格式化为字符串(假设格式为 yyyy-MM-dd)
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        String startDateString = startOfMonth.format(formatter);
+        String endDateString = endOfMonth.format(formatter);
+
+        // 遍历所有设备区域
+        for (DeviceRegion deviceRegion : list) {
+            Query querylr = new Query();
+
+            // 添加筛选条件:deviceRegionId 和 当月日期范围
+            querylr.addCriteria(Criteria.where("deviceRegionId").in(deviceRegion.getId())
+                    .and("dates").gte(startDateString).lte(endDateString));
+
+            // 执行查询,获取该区域的设备统计数据
+            List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(
+                    querylr, DeviceStatiscsModelMongodb.class, "total_day_powerproportioncurrent");
+
+            // 初始化总功率以及各时段功率的累加值
+            BigDecimal totalPower = BigDecimal.ZERO;
+            BigDecimal topsPower = BigDecimal.ZERO;
+            BigDecimal peaksPower = BigDecimal.ZERO;
+            BigDecimal flatPower = BigDecimal.ZERO;
+            BigDecimal valleysPower = BigDecimal.ZERO;
+
+            // 遍历当前区域的所有设备统计数据,进行功率累加
+            for (DeviceStatiscsModelMongodb deviceStats : deviceStatiscsModelMongodbList) {
+                topsPower = topsPower.add(deviceStats.getTopsPower() != null ? deviceStats.getTopsPower() : BigDecimal.ZERO);
+                peaksPower = peaksPower.add(deviceStats.getPeaksPower() != null ? deviceStats.getPeaksPower() : BigDecimal.ZERO);
+                flatPower = flatPower.add(deviceStats.getFlatPower() != null ? deviceStats.getFlatPower() : BigDecimal.ZERO);
+                valleysPower = valleysPower.add(deviceStats.getValleysPower() != null ? deviceStats.getValleysPower() : BigDecimal.ZERO);
+            }
+
+            // 计算当月总功率
+            totalPower = topsPower.add(peaksPower).add(flatPower).add(valleysPower);
+
+            // 创建一个Map,保存该区域的统计信息
+            Map<String, String> regionStats = new HashMap<>();
+            regionStats.put("deviceRegionId", deviceRegion.getId().toString());
+            regionStats.put("deviceTitle", deviceRegion.getRegionTitle().toString());
+            regionStats.put("totalPower", totalPower.toString()); // 总功率
+
+            // 计算并保存各时段的占比
+            if (totalPower.compareTo(BigDecimal.ZERO) > 0) {
+                regionStats.put("topsPowerProportion", topsPower.divide(totalPower, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toString());
+                regionStats.put("peaksPowerProportion", peaksPower.divide(totalPower, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toString());
+                regionStats.put("flatPowerProportion", flatPower.divide(totalPower, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toString());
+                regionStats.put("valleysPowerProportion", valleysPower.divide(totalPower, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toString());
+            } else {
+                // 如果总功率为0,则占比设为0
+                regionStats.put("topsPowerProportion", "0.00");
+                regionStats.put("peaksPowerProportion", "0.00");
+                regionStats.put("flatPowerProportion", "0.00");
+                regionStats.put("valleysPowerProportion", "0.00");
+            }
+
+            // 将每个设备区域的统计信息添加到结果列表中
+            res.add(regionStats);
         }
         }
+
         return res;
         return res;
     }
     }
 
 
     @Override
     @Override
     public List<Map<String, String>> electricityManage() {
     public List<Map<String, String>> electricityManage() {
         List<Map<String, String>> res = new ArrayList<>();
         List<Map<String, String>> res = new ArrayList<>();
-        String[] names = {"尖","峰","平","谷"};
-        Arrays.asList(names).forEach(name ->{
-            Map<String,String> map = new HashMap<>();
-            map.put("name",name);
-            map.put("yesterday",String.format("%.2f",Math.random()*35+15));
-            map.put("today",String.format("%.2f",Math.random()*35+15));
+        String[] names = {"尖", "峰", "平", "谷"};
+        Arrays.asList(names).forEach(name -> {
+            Map<String, String> map = new HashMap<>();
+            map.put("name", name);
+            map.put("yesterday", String.format("%.2f", Math.random() * 35 + 15));
+            map.put("today", String.format("%.2f", Math.random() * 35 + 15));
             res.add(map);
             res.add(map);
         });
         });
         return res;
         return res;
@@ -281,13 +417,331 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
 
 
     @Override
     @Override
     public Map<String, Integer> deviceThresholdStats() {
     public Map<String, Integer> deviceThresholdStats() {
-        int count = (int)deviceRegionService.count();
-        Map<String,Integer> res = new HashMap<>();
-        res.put("exceed",(int)(Math.random()*count));
-        res.put("noexceed",count-res.get("exceed"));
+        int count = (int) deviceRegionService.count();
+        Map<String, Integer> res = new HashMap<>();
+        res.put("exceed", (int) (Math.random() * count));
+        res.put("noexceed", count - res.get("exceed"));
         return res;
         return res;
     }
     }
 
 
+    @Override
+    public Map<String, Integer> illegalActivation() {
+
+        Map<String, Integer> res = new HashMap<>();
+        LambdaQueryWrapper<LeanEventsHost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationId, "tops");
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationType, "fpg_close");
+        LeanEventsHost one = leanEventsHostService.getOne(lambdaQueryWrapper);
+        if (null != one) {
+
+            if (oConvertUtils.isNotEmpty(one.getDeviceInformationList())) {
+
+                // 使用 String.split() 按逗号分割字符串
+                String[] array = one.getDeviceInformationList().split(",");
+
+                // 将数组转换为 List
+                List<String> list = Arrays.asList(array);
+
+                // 获取当天的日期和时间
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                String todayDateTime = LocalDateTime.now().format(formatter); // 获取当前的日期时间
+                String todayDate = todayDateTime.split(" ")[0]; // 获取当前日期部分(yyyy-MM-dd)
+
+
+                // 使用 deviceInformationId (s) 和 today's date 来构造 warnInfoLambdaQueryWrapper
+
+                LambdaQueryWrapper<LeanEventWarnInfo> warnInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                warnInfoLambdaQueryWrapper.in(LeanEventWarnInfo::getDeviceInformationId, list);
+                warnInfoLambdaQueryWrapper.likeRight(LeanEventWarnInfo::getCreateTime, todayDate);
+
+                // 查询结果
+                List<LeanEventWarnInfo> warnInfoList = leanEventWarnInfoService.list(warnInfoLambdaQueryWrapper);
+
+                // 使用 Map 去重,基于 deviceInformationId
+                Map<String, LeanEventWarnInfo> uniqueWarnInfoMap = warnInfoList.stream()
+                        .collect(Collectors.toMap(
+                                LeanEventWarnInfo::getDeviceInformationId,  // 用 deviceInformationId 作为 key
+                                warnInfo -> warnInfo,  // value 为 warnInfo 对象
+                                (existing, replacement) -> existing)); // 如果有重复的 key,保留第一个
+
+                // 获取去重后的结果列表
+                List<LeanEventWarnInfo> distinctWarnInfoList = uniqueWarnInfoMap.values().stream().collect(Collectors.toList());
+
+                res.put("tops", distinctWarnInfoList.size());
+            }
+
+            LambdaQueryWrapper<LeanEventsHost> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
+            lambdaQueryWrapper1.eq(LeanEventsHost::getDeviceInformationId, "peaks");
+            lambdaQueryWrapper1.eq(LeanEventsHost::getDeviceInformationType, "fpg_close");
+            LeanEventsHost one1 = leanEventsHostService.getOne(lambdaQueryWrapper);
+            if (null != one1) {
+
+                if (oConvertUtils.isNotEmpty(one1.getDeviceInformationList())) {
+
+                    // 使用 String.split() 按逗号分割字符串
+                    String[] array = one1.getDeviceInformationList().split(",");
+
+                    // 将数组转换为 List
+                    List<String> list = Arrays.asList(array);
+
+                    // 获取当天的日期和时间
+                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                    String todayDateTime = LocalDateTime.now().format(formatter); // 获取当前的日期时间
+                    String todayDate = todayDateTime.split(" ")[0]; // 获取当前日期部分(yyyy-MM-dd)
+
+
+                    // 使用 deviceInformationId (s) 和 today's date 来构造 warnInfoLambdaQueryWrapper
+
+                    LambdaQueryWrapper<LeanEventWarnInfo> warnInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    warnInfoLambdaQueryWrapper.in(LeanEventWarnInfo::getDeviceInformationId, list);
+                    warnInfoLambdaQueryWrapper.likeRight(LeanEventWarnInfo::getCreateTime, todayDate);
+
+                    // 查询结果
+                    List<LeanEventWarnInfo> warnInfoList = leanEventWarnInfoService.list(warnInfoLambdaQueryWrapper);
+
+                    // 使用 Map 去重,基于 deviceInformationId
+                    Map<String, LeanEventWarnInfo> uniqueWarnInfoMap = warnInfoList.stream()
+                            .collect(Collectors.toMap(
+                                    LeanEventWarnInfo::getDeviceInformationId,  // 用 deviceInformationId 作为 key
+                                    warnInfo -> warnInfo,  // value 为 warnInfo 对象
+                                    (existing, replacement) -> existing)); // 如果有重复的 key,保留第一个
+
+                    // 获取去重后的结果列表
+                    List<LeanEventWarnInfo> distinctWarnInfoList = uniqueWarnInfoMap.values().stream().collect(Collectors.toList());
+
+                    res.put("peaks", distinctWarnInfoList.size());
+                }
+
+            }
+
+
+        }
+        return res;
+    }
+
+    @Override
+    public List<IllegalResult> topsIllegalActivation() {
+
+        List<IllegalResult> illegalResultList = new ArrayList<>();
+        LambdaQueryWrapper<LeanEventsHost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationId, "tops");
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationType, "fpg_close");
+        LeanEventsHost one = leanEventsHostService.getOne(lambdaQueryWrapper);
+        if (null != one) {
+
+            if (oConvertUtils.isNotEmpty(one.getDeviceInformationList())) {
+
+                // 使用 String.split() 按逗号分割字符串
+                String[] array = one.getDeviceInformationList().split(",");
+
+                // 将数组转换为 List
+                List<String> list = Arrays.asList(array);
+
+                // 获取当天的日期和时间
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                String todayDateTime = LocalDateTime.now().format(formatter); // 获取当前的日期时间
+                String todayDate = todayDateTime.split(" ")[0]; // 获取当前日期部分(yyyy-MM-dd)
+
+
+                // 使用 deviceInformationId (s) 和 today's date 来构造 warnInfoLambdaQueryWrapper
+
+                LambdaQueryWrapper<LeanEventWarnInfo> warnInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                warnInfoLambdaQueryWrapper.in(LeanEventWarnInfo::getDeviceInformationId, list);
+                warnInfoLambdaQueryWrapper.likeRight(LeanEventWarnInfo::getCreateTime, todayDate);
+
+                // 查询结果
+                List<LeanEventWarnInfo> warnInfoList = leanEventWarnInfoService.list(warnInfoLambdaQueryWrapper);
+
+                // 使用 Map 去重,基于 deviceInformationId
+                Map<String, LeanEventWarnInfo> uniqueWarnInfoMap = warnInfoList.stream()
+                        .collect(Collectors.toMap(
+                                LeanEventWarnInfo::getDeviceInformationId,  // 用 deviceInformationId 作为 key
+                                warnInfo -> warnInfo,  // value 为 warnInfo 对象
+                                (existing, replacement) -> existing)); // 如果有重复的 key,保留第一个
+
+                // 获取去重后的结果列表
+                List<LeanEventWarnInfo> distinctWarnInfoList = uniqueWarnInfoMap.values().stream().collect(Collectors.toList());
+
+                LambdaQueryWrapper<PeaksAndValleysTimeConfig> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(PeaksAndValleysTimeConfig::getType, "tops");
+                List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfigs = peaksAndValleysTimeConfigService.list(wrapper);
+
+                for (PeaksAndValleysTimeConfig peaksAndValleysTimeConfig : peaksAndValleysTimeConfigs) {
+
+                    for (LeanEventWarnInfo leanEventWarnInfo : distinctWarnInfoList) {
+
+
+                        Query querylr = new Query();
+
+                        // 添加筛选条件:deviceRegionId 和 当月日期范围
+                        querylr.addCriteria(Criteria.where("deviceInformationId").in(leanEventWarnInfo.getDeviceInformationId()));
+
+                        // 执行查询,获取该区域的设备统计数据
+                        List<LeanModelDeviceHistoryInfo> deviceStatiscsModelMongodbList = mongoTemplate.find(
+                                querylr, LeanModelDeviceHistoryInfo.class, "leanmodel_run_realtime");
+
+                        List<LeanModelDeviceHistoryInfo> arrayList = new ArrayList<>();
+                        // 采集时间
+                        for (LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo : deviceStatiscsModelMongodbList) {
+
+                            Instant instant = DateUtils.str2Date(leanModelDeviceHistoryInfo.getDatestr(), DateUtils.datetimeFormat.get()).toInstant();
+                            LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+
+                            // 获取今天的日期
+                            LocalDate today = LocalDate.now();
+
+                            // 格式化为 yyyy-MM-dd 格式的字符串
+                            DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                            String dayDate = today.format(formatter1);
+
+                            if (containsCreateTime(localDateTime, dayDate + " " + peaksAndValleysTimeConfig.getStartTime(), dayDate + " " + peaksAndValleysTimeConfig.getEndTime())) {
+
+                                arrayList.add(leanModelDeviceHistoryInfo);
+
+                            }
+
+                        }
+
+                        List<LeanModelDeviceHistoryInfo> leanModelDeviceHistoryInfos = filterLatestData(arrayList);
+
+
+                        for (LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo : leanModelDeviceHistoryInfos) {
+                            IllegalResult illegalResult = new IllegalResult();
+
+                            LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
+                            queryWrapper.eq(DeviceInformation::getId,leanModelDeviceHistoryInfo.getDeviceInformationId());
+                            DeviceInformation deviceInformation = deviceInformationService.getOne(queryWrapper);
+                            if(null != deviceInformation) {
+                                illegalResult.setDeviceTitle(deviceInformation.getDeviceTitle());
+                            }
+                            illegalResult.setIngTime(leanModelDeviceHistoryInfo.getIngTime());
+                            illegalResult.setPower(leanModelDeviceHistoryInfo.getPower());
+                            illegalResult.setCreateTime(DateUtils.str2Date(leanModelDeviceHistoryInfo.getDatestr(), DateUtils.datetimeFormat.get()));
+
+
+                            illegalResultList.add(illegalResult);
+                        }
+
+                    }
+                }
+            }
+
+        }
+
+        return illegalResultList;
+    }
+
+    @Override
+    public List<IllegalResult> peaksIllegalActivation() {
+        List<IllegalResult> illegalResultList = new ArrayList<>();
+        LambdaQueryWrapper<LeanEventsHost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationId, "peaks");
+        lambdaQueryWrapper.eq(LeanEventsHost::getDeviceInformationType, "fpg_close");
+        LeanEventsHost one = leanEventsHostService.getOne(lambdaQueryWrapper);
+        if (null != one) {
+
+            if (oConvertUtils.isNotEmpty(one.getDeviceInformationList())) {
+
+                // 使用 String.split() 按逗号分割字符串
+                String[] array = one.getDeviceInformationList().split(",");
+
+                // 将数组转换为 List
+                List<String> list = Arrays.asList(array);
+
+                // 获取当天的日期和时间
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                String todayDateTime = LocalDateTime.now().format(formatter); // 获取当前的日期时间
+                String todayDate = todayDateTime.split(" ")[0]; // 获取当前日期部分(yyyy-MM-dd)
+
+
+                // 使用 deviceInformationId (s) 和 today's date 来构造 warnInfoLambdaQueryWrapper
+
+                LambdaQueryWrapper<LeanEventWarnInfo> warnInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                warnInfoLambdaQueryWrapper.in(LeanEventWarnInfo::getDeviceInformationId, list);
+                warnInfoLambdaQueryWrapper.likeRight(LeanEventWarnInfo::getCreateTime, todayDate);
+
+                // 查询结果
+                List<LeanEventWarnInfo> warnInfoList = leanEventWarnInfoService.list(warnInfoLambdaQueryWrapper);
+
+                // 使用 Map 去重,基于 deviceInformationId
+                Map<String, LeanEventWarnInfo> uniqueWarnInfoMap = warnInfoList.stream()
+                        .collect(Collectors.toMap(
+                                LeanEventWarnInfo::getDeviceInformationId,  // 用 deviceInformationId 作为 key
+                                warnInfo -> warnInfo,  // value 为 warnInfo 对象
+                                (existing, replacement) -> existing)); // 如果有重复的 key,保留第一个
+
+                // 获取去重后的结果列表
+                List<LeanEventWarnInfo> distinctWarnInfoList = uniqueWarnInfoMap.values().stream().collect(Collectors.toList());
+
+                LambdaQueryWrapper<PeaksAndValleysTimeConfig> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(PeaksAndValleysTimeConfig::getType, "peaks");
+                List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfigs = peaksAndValleysTimeConfigService.list(wrapper);
+
+                for (PeaksAndValleysTimeConfig peaksAndValleysTimeConfig : peaksAndValleysTimeConfigs) {
+
+                    for (LeanEventWarnInfo leanEventWarnInfo : distinctWarnInfoList) {
+
+
+                        Query querylr = new Query();
+
+                        // 添加筛选条件:deviceRegionId 和 当月日期范围
+                        querylr.addCriteria(Criteria.where("deviceInformationId").in(leanEventWarnInfo.getDeviceInformationId()));
+
+                        // 执行查询,获取该区域的设备统计数据
+                        List<LeanModelDeviceHistoryInfo> deviceStatiscsModelMongodbList = mongoTemplate.find(
+                                querylr, LeanModelDeviceHistoryInfo.class, "leanmodel_run_realtime");
+
+                        List<LeanModelDeviceHistoryInfo> arrayList = new ArrayList<>();
+                        // 采集时间
+                        for (LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo : deviceStatiscsModelMongodbList) {
+
+                            Instant instant = DateUtils.str2Date(leanModelDeviceHistoryInfo.getDatestr(), DateUtils.datetimeFormat.get()).toInstant();
+                            LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
+
+                            // 获取今天的日期
+                            LocalDate today = LocalDate.now();
+
+                            // 格式化为 yyyy-MM-dd 格式的字符串
+                            DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                            String dayDate = today.format(formatter1);
+
+                            if (containsCreateTime(localDateTime, dayDate + " " + peaksAndValleysTimeConfig.getStartTime(), dayDate + " " + peaksAndValleysTimeConfig.getEndTime())) {
+
+                                arrayList.add(leanModelDeviceHistoryInfo);
+
+                            }
+
+                        }
+
+                        List<LeanModelDeviceHistoryInfo> leanModelDeviceHistoryInfos = filterLatestData(arrayList);
+
+
+                        for (LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo : leanModelDeviceHistoryInfos) {
+                            IllegalResult illegalResult = new IllegalResult();
+
+                            LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
+                            queryWrapper.eq(DeviceInformation::getId,leanModelDeviceHistoryInfo.getDeviceInformationId());
+                            DeviceInformation deviceInformation = deviceInformationService.getOne(queryWrapper);
+                            if(null != deviceInformation) {
+                                illegalResult.setDeviceTitle(deviceInformation.getDeviceTitle());
+                            }
+                            illegalResult.setIngTime(leanModelDeviceHistoryInfo.getIngTime());
+                            illegalResult.setPower(leanModelDeviceHistoryInfo.getPower());
+                            illegalResult.setCreateTime(DateUtils.str2Date(leanModelDeviceHistoryInfo.getDatestr(), DateUtils.datetimeFormat.get()));
+
+
+                            illegalResultList.add(illegalResult);
+                        }
+
+                    }
+                }
+            }
+
+        }
+
+        return illegalResultList;
+    }
+
     @Override
     @Override
     public List<String> latestMsg() {
     public List<String> latestMsg() {
 
 
@@ -367,7 +821,6 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
     }
     }
 
 
 
 
-
     private Map<String, String> getMap(Date date, String value, String regionId) {
     private Map<String, String> getMap(Date date, String value, String regionId) {
         Map<String, String> res = new HashMap<>();
         Map<String, String> res = new HashMap<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
@@ -384,14 +837,79 @@ public class HomePageDataServiceImpl implements IHomePageDataService {
 
 
     /**
     /**
      * 根据模型ID查询模型编码
      * 根据模型ID查询模型编码
+     *
      * @param modelId
      * @param modelId
      * @return
      * @return
      */
      */
     private String queryLeanModelCodeById(String modelId) {
     private String queryLeanModelCodeById(String modelId) {
         FpgLeanModel fpgLeanModel = fpgLeanModelService.getById(modelId);
         FpgLeanModel fpgLeanModel = fpgLeanModelService.getById(modelId);
-        if (oConvertUtils.isEmpty(fpgLeanModel)){
+        if (oConvertUtils.isEmpty(fpgLeanModel)) {
             return null;
             return null;
         }
         }
         return fpgLeanModel.getLeanModelCode();
         return fpgLeanModel.getLeanModelCode();
     }
     }
+
+
+    /**
+     * 判断创建时间是否在开始时间和结束时间范围内
+     *
+     * @param createTime
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    public static boolean containsCreateTime(LocalDateTime createTime, String startTime, String endTime) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        // 将字符串转换为 LocalDateTime
+        LocalDateTime start_time = LocalDateTime.parse(startTime, formatter);
+        LocalDateTime end_time = LocalDateTime.parse(endTime, formatter);
+
+        // 判断是否跨天
+        boolean isCrossDay = end_time.isBefore(start_time);
+
+        // 根据 createTime 调整 start_time 和 end_time
+        if (isCrossDay) {
+            // 如果 createTime 在 startTime 后且在 endTime 前,且跨天,endTime 应该加一天
+            if (createTime.isAfter(start_time) && createTime.isAfter(end_time)) {
+                end_time = end_time.plusDays(1); // 加一天到第二天
+            }
+            // 如果 createTime 在 startTime 之前且在 endTime 后,startTime 应该减去一天
+            if (createTime.isBefore(start_time) && createTime.isBefore(end_time)) {
+                start_time = start_time.minusDays(1); // 减一天
+            }
+        }
+
+        // 检查 createTime 是否在调整后的区间内
+        return createTime != null && (createTime.isAfter(start_time) || createTime.equals(start_time)) &&
+                (createTime.isBefore(end_time) || createTime.equals(end_time));
+    }
+
+
+    public List<LeanModelDeviceHistoryInfo> filterLatestData(List<LeanModelDeviceHistoryInfo> deviceStatiscsModelMongodbList) {
+        // 按照 deviceInformationId 分组,并找到每组中 datestr 最新的一条数据
+        Map<String, LeanModelDeviceHistoryInfo> latestDataMap = deviceStatiscsModelMongodbList.stream()
+                .collect(Collectors.toMap(
+                        LeanModelDeviceHistoryInfo::getDeviceInformationId,  // 根据 deviceInformationId 进行分组
+                        data -> data,  // 数据本身
+                        (existing, replacement) -> {
+                            // 按照 datestr(时间)比较取最新的
+                            String existingDateStr = existing.getDatestr();
+                            String replacementDateStr = replacement.getDatestr();
+                            try {
+                                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                Date existingDate = formatter.parse(existingDateStr);
+                                Date replacementDate = formatter.parse(replacementDateStr);
+                                return existingDate.after(replacementDate) ? existing : replacement;
+                            } catch (Exception e) {
+                                return existing;  // 如果日期解析失败,默认返回现有的
+                            }
+                        }
+                ));
+
+        // 获取去重后的列表(即每个 deviceInformationId 对应最新的一条数据)
+        return new ArrayList<>(latestDataMap.values());
+    }
+
+
 }
 }