节能减排

This commit is contained in:
jiang 2025-07-24 00:04:54 +08:00
parent 320263d480
commit 590682dd08
7 changed files with 408 additions and 1 deletions

View File

@ -72,7 +72,10 @@ public class ParamSecureHandler implements AsyncHandlerInterceptor {
"/largeScreen/engineeringSafetyAnalysis/list",
"/largeScreen/engineeringSafetyAnalysis/environmental",
"/largeScreen/engineeringSafetyAnalysis/hazards",
"/Dashapi/pages/dashInfo"
"/Dashapi/pages/dashInfo",
"/largeScreen/deviceEnergyAnalysis/selectEnergyStatsByDateRange",
"/largeScreen/deviceEnergyAnalysis/selectDeviceEnergyByDateRange",
"/largeScreen/deviceEnergyAnalysis/selectAnomalyByDateRange",
};
/**

View File

@ -0,0 +1,66 @@
package com.securitycontrol.screen.controller;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.screen.domain.DeviceEnergyAnalysis;
import com.securitycontrol.screen.service.DeviceEnergyAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 设备能耗分析控制器
* 提供大屏端接口查询能耗统计数据
*/
@RestController
@RequestMapping("/largeScreen/deviceEnergyAnalysis/")
@Slf4j
public class DeviceEnergyAnalysisController {
@Resource
private DeviceEnergyAnalysisService service;
/**
* 查询时间段内的每日能耗与可再生能源使用量按日期汇总
* <p>
* 接口路径POST /largeScreen/deviceEnergyAnalysis/selectEnergyStatsByDateRange
* 请求参数JSON 格式包含 startDateendDate格式yyyy-MM-dd
* 返回结果AjaxResult.success(data)
*/
@PostMapping("selectEnergyStatsByDateRange")
public AjaxResult selectEnergyStatsByDateRange(@RequestBody DeviceEnergyAnalysis entity) {
return service.selectEnergyStatsByDateRange(entity);
}
/**
* 查询时间段内每台设备的总能耗按设备汇总
* <p>
* 接口路径POST /largeScreen/deviceEnergyAnalysis/selectDeviceEnergyByDateRange
* 请求参数JSON 格式包含 startDateendDate格式yyyy-MM-dd
* 返回结果AjaxResult.success(data)
*/
@PostMapping("selectDeviceEnergyByDateRange")
public AjaxResult selectDeviceEnergyByDateRange(@RequestBody DeviceEnergyAnalysis entity) {
return service.selectDeviceEnergyByDateRange(entity);
}
/**
* 根据时间范围查询能耗异常信息
* <p>
* 该方法用于从 device_energy_analysis 表中查询在指定时间范围内存在能耗异常的数据记录
* 查询条件包括
* - 统计日期在指定的开始时间和结束时间之间包含边界
* - 异常标志 anomaly_flag true即值为 1
* <p>
* 可用于页面或报表展示一段时间内设备的异常能耗情况支持工程维度单位维度筛选
*
* @param entity
* @return AjaxResult 封装的查询结果
*/
@PostMapping("selectAnomalyByDateRange")
public AjaxResult selectAnomalyByDateRange(@RequestBody DeviceEnergyAnalysis entity) {
return service.selectAnomalyByDateRange(entity);
}
}

View File

@ -0,0 +1,81 @@
package com.securitycontrol.screen.domain;
import lombok.Data;
import java.util.Date;
/**
* 设备能耗分析实体类对应表 device_energy_analysis
* 用于记录设备每日能耗数据可再生能源使用情况异常情况等
*/
@Data
public class DeviceEnergyAnalysis {
/**
* 主键自增ID
*/
private Long id;
/**
* 设备名称
* 示例塔吊电焊机照明系统等
*/
private String deviceName;
/**
* 统计日期
* 表示这条数据对应的日期yyyy-MM-dd
*/
private String statDate;
/**
* 设备当日能耗单位为千瓦时kWh
*/
private Double consumptionKwh;
/**
* 使用的可再生能源量单位为千瓦时kWh
*/
private Double renewableUsedKwh;
/**
* 是否存在能耗异常
* true 表示存在异常false 表示正常
*/
private Boolean anomalyFlag;
/**
* 异常等级
* 示例info信息warning警告danger严重
*/
private String anomalyLevel;
/**
* 能耗异常描述
* 说明异常情况的具体信息可为空
*/
private String anomalyDesc;
/**
* 数据创建时间记录插入时间
*/
private Date createdAt;
/**
* 查询条件开始时间非数据库字段
* 用于按时间段筛选数据
*/
private String startDate;
/**
* 查询条件结束时间非数据库字段
* 用于按时间段筛选数据
*/
private String endDate;
/**
* 工程ID项目标识
* 用于区分所属工程可作为查询过滤条件
*/
private String proId;
}

View File

@ -0,0 +1,77 @@
package com.securitycontrol.screen.mapper;
import com.securitycontrol.screen.domain.DeviceEnergyAnalysis;
import org.apache.ibatis.annotations.MapKey;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Mapper接口设备能耗分析相关查询
* 对应表device_energy_analysis
*/
@Repository(value = "DeviceEnergyAnalysisMapper")
public interface DeviceEnergyAnalysisMapper {
/**
* 查询指定时间段内的每日总能耗和可再生能源使用量按日期维度聚合
*
* @param entity 传入查询参数封装对象主要使用 startDate endDate 字段
* @return 返回一个 List列表中的每个 Map 对应某一天的数据
* - key: statDate日期
* - value: 包括 totalConsumptionKwhtotalRenewableUsedKwh 等聚合值
* <p>
* 示例返回格式
* [
* {
* statDate: "2025-07-01",
* totalConsumptionKwh: 123.45,
* totalRenewableUsedKwh: 45.67
* },
* ...
* ]
*/
@MapKey("statDate")
List<Map<String, Objects>> selectEnergyStatsByDateRange(DeviceEnergyAnalysis entity);
/**
* 查询指定时间段内每台设备的总能耗按设备维度聚合
*
* @param entity 传入查询参数封装对象主要使用 startDate endDate 字段
* @return 返回一个 List列表中的每个 Map 对应某个设备的数据
* - key: deviceName设备名称
* - value: 包括 totalConsumptionKwh 等聚合值
* <p>
* 示例返回格式
* [
* {
* deviceName: "塔吊",
* totalConsumptionKwh: 300.5
* },
* ...
* ]
*/
@MapKey("deviceName")
List<Map<String, Objects>> selectDeviceEnergyByDateRange(DeviceEnergyAnalysis entity);
/**
* 根据时间范围查询能耗异常信息
* <p>
* 该方法用于从 device_energy_analysis 表中查询在指定时间范围内存在能耗异常的数据记录
* 查询条件包括
* - 统计日期在指定的开始时间和结束时间之间包含边界
* - 异常标志 anomaly_flag true即值为 1
* <p>
* 可用于页面或报表展示一段时间内设备的异常能耗情况支持工程维度单位维度筛选
*
* @param entity DeviceEnergyAnalysis 实体类用于传递以下查询参数
* - statDate (作为查询开始时间)
* - endDate (自定义字段需添加到实体类中用作查询结束时间)
* - proId (可选工程ID用于筛选特定工程)
* - unitId (可选单位ID用于筛选特定单位)
* @return List<DeviceEnergyAnalysis> 查询到的异常能耗记录列表
*/
List<DeviceEnergyAnalysis> selectAnomalyByDateRange(DeviceEnergyAnalysis entity);
}

View File

@ -0,0 +1,47 @@
package com.securitycontrol.screen.service;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.screen.domain.DeviceEnergyAnalysis;
import java.util.List;
/**
* 设备能耗分析服务接口
* 提供按时间段统计设备能耗数据的服务能力
*/
public interface DeviceEnergyAnalysisService {
/**
* 查询指定时间段内每日总能耗和可再生能源使用量按日期聚合
*
* @param entity 查询参数封装类需包含 startDateendDate可选 proId
* @return AjaxResult 封装的查询结果
* 成功AjaxResult.success(List<Map<String, Object>>)
* 每条记录包含 statDatetotalConsumptionKwhtotalRenewableUsedKwh 等字段
*/
AjaxResult selectEnergyStatsByDateRange(DeviceEnergyAnalysis entity);
/**
* 查询指定时间段内每台设备的总能耗按设备聚合
*
* @param entity 查询参数封装类需包含 startDateendDate可选 proId
* @return AjaxResult 封装的查询结果
* 成功AjaxResult.success(List<Map<String, Object>>)
* 每条记录包含 deviceNametotalConsumptionKwh 等字段
*/
AjaxResult selectDeviceEnergyByDateRange(DeviceEnergyAnalysis entity);
/**
* 根据时间范围查询能耗异常信息
* <p>
* 该方法用于从 device_energy_analysis 表中查询在指定时间范围内存在能耗异常的数据记录
* 查询条件包括
* - 统计日期在指定的开始时间和结束时间之间包含边界
* - 异常标志 anomaly_flag true即值为 1
* <p>
* 可用于页面或报表展示一段时间内设备的异常能耗情况支持工程维度单位维度筛选
*
* @return AjaxResult 封装的查询结果
*/
AjaxResult selectAnomalyByDateRange(DeviceEnergyAnalysis entity);
}

View File

@ -0,0 +1,83 @@
package com.securitycontrol.screen.service.impl;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.screen.domain.DeviceEnergyAnalysis;
import com.securitycontrol.screen.mapper.DeviceEnergyAnalysisMapper;
import com.securitycontrol.screen.service.DeviceEnergyAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 设备能耗分析服务实现类
* 实现对设备能耗数据的查询包括按日期聚合和按设备聚合
*/
@Slf4j
@Service(value = "DeviceEnergyAnalysisService")
public class DeviceEnergyAnalysisServiceImpl implements DeviceEnergyAnalysisService {
@Resource
private DeviceEnergyAnalysisMapper mapper;
/**
* 查询指定时间段内每日的总能耗与可再生能源使用量按日期汇总
*
* @param entity 包含 startDate endDate 的查询实体
* @return AjaxResult.success(data) AjaxResult.error()
*/
@Override
public AjaxResult selectEnergyStatsByDateRange(DeviceEnergyAnalysis entity) {
try {
List<Map<String, Objects>> maps = mapper.selectEnergyStatsByDateRange(entity);
return AjaxResult.success(maps);
} catch (Exception e) {
log.error("查询每日能耗失败: {}", e.getMessage(), e);
return AjaxResult.error("查询每日能耗失败");
}
}
/**
* 查询指定时间段内每台设备的总能耗按设备汇总
*
* @param entity 包含 startDate endDate 的查询实体
* @return AjaxResult.success(data) AjaxResult.error()
*/
@Override
public AjaxResult selectDeviceEnergyByDateRange(DeviceEnergyAnalysis entity) {
try {
List<Map<String, Objects>> maps = mapper.selectDeviceEnergyByDateRange(entity);
return AjaxResult.success(maps);
} catch (Exception e) {
log.error("查询设备能耗失败: {}", e.getMessage(), e);
return AjaxResult.error("查询设备能耗失败");
}
}
/**
* 根据时间范围查询能耗异常信息
* <p>
* 该方法用于从 device_energy_analysis 表中查询在指定时间范围内存在能耗异常的数据记录
* 查询条件包括
* - 统计日期在指定的开始时间和结束时间之间包含边界
* - 异常标志 anomaly_flag true即值为 1
* <p>
* 可用于页面或报表展示一段时间内设备的异常能耗情况支持工程维度单位维度筛选
*
* @param entity
* @return AjaxResult 封装的查询结果
*/
@Override
public AjaxResult selectAnomalyByDateRange(DeviceEnergyAnalysis entity) {
try {
List<DeviceEnergyAnalysis> maps = mapper.selectAnomalyByDateRange(entity);
return AjaxResult.success(maps);
} catch (Exception e) {
log.error("查询能耗异常分析失败: {}", e.getMessage(), e);
return AjaxResult.error("查询能耗异常分析失败");
}
}
}

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.securitycontrol.screen.mapper.DeviceEnergyAnalysisMapper">
<select id="selectEnergyStatsByDateRange" resultType="com.securitycontrol.screen.domain.DeviceEnergyAnalysis">
SELECT stat_date AS statDate,
SUM(consumption_kwh) AS consumptionKwh,
SUM(renewable_used_kwh) AS renewableUsedKwh
FROM device_energy_analysis
WHERE stat_date BETWEEN #{startDate} AND #{endDate}
and pro_id =#{proId}
GROUP BY stat_date
ORDER BY stat_date ASC
</select>
<select id="selectDeviceEnergyByDateRange" resultType="com.securitycontrol.screen.domain.DeviceEnergyAnalysis">
SELECT device_name AS deviceName,
SUM(consumption_kwh) AS consumptionKwh
FROM device_energy_analysis
WHERE stat_date BETWEEN #{startDate} AND #{endDate}
and pro_id = #{proId}
GROUP BY device_name
ORDER BY consumptionKwh ASC
LIMIT 10
</select>
<select id="selectAnomalyByDateRange" resultType="com.securitycontrol.screen.domain.DeviceEnergyAnalysis">
SELECT id AS id,
device_name AS deviceName,
stat_date AS statDate,
consumption_kwh AS consumptionKwh,
renewable_used_kwh AS renewableUsedKwh,
anomaly_level AS anomalyLevel,
anomaly_desc AS anomalyDesc
FROM device_energy_analysis
WHERE anomaly_flag = 1
AND stat_date BETWEEN #{startDate} AND #{endDate}
and pro_id = #{proId}
ORDER BY
FIELD(anomaly_level, 'danger', 'warning', 'info') ASC,
stat_date ASC;
</select>
</mapper>