节能减排
This commit is contained in:
parent
320263d480
commit
590682dd08
|
|
@ -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",
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 格式,包含 startDate、endDate(格式:yyyy-MM-dd)
|
||||
* 返回结果:AjaxResult.success(data)
|
||||
*/
|
||||
@PostMapping("selectEnergyStatsByDateRange")
|
||||
public AjaxResult selectEnergyStatsByDateRange(@RequestBody DeviceEnergyAnalysis entity) {
|
||||
return service.selectEnergyStatsByDateRange(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询时间段内每台设备的总能耗(按设备汇总)
|
||||
* <p>
|
||||
* 接口路径:POST /largeScreen/deviceEnergyAnalysis/selectDeviceEnergyByDateRange
|
||||
* 请求参数:JSON 格式,包含 startDate、endDate(格式: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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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: 包括 totalConsumptionKwh、totalRenewableUsedKwh 等聚合值
|
||||
* <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);
|
||||
}
|
||||
|
|
@ -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 查询参数封装类(需包含 startDate、endDate,可选 proId 等)
|
||||
* @return AjaxResult 封装的查询结果:
|
||||
* 成功:AjaxResult.success(List<Map<String, Object>>),
|
||||
* 每条记录包含 statDate、totalConsumptionKwh、totalRenewableUsedKwh 等字段
|
||||
*/
|
||||
AjaxResult selectEnergyStatsByDateRange(DeviceEnergyAnalysis entity);
|
||||
|
||||
/**
|
||||
* 查询指定时间段内每台设备的总能耗(按设备聚合)
|
||||
*
|
||||
* @param entity 查询参数封装类(需包含 startDate、endDate,可选 proId 等)
|
||||
* @return AjaxResult 封装的查询结果:
|
||||
* 成功:AjaxResult.success(List<Map<String, Object>>),
|
||||
* 每条记录包含 deviceName、totalConsumptionKwh 等字段
|
||||
*/
|
||||
AjaxResult selectDeviceEnergyByDateRange(DeviceEnergyAnalysis entity);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询能耗异常信息
|
||||
* <p>
|
||||
* 该方法用于从 device_energy_analysis 表中查询在指定时间范围内存在能耗异常的数据记录。
|
||||
* 查询条件包括:
|
||||
* - 统计日期在指定的开始时间和结束时间之间(包含边界)
|
||||
* - 异常标志 anomaly_flag 为 true(即值为 1)
|
||||
* <p>
|
||||
* 可用于页面或报表展示一段时间内设备的异常能耗情况,支持工程维度、单位维度筛选。
|
||||
*
|
||||
* @return AjaxResult 封装的查询结果:
|
||||
*/
|
||||
AjaxResult selectAnomalyByDateRange(DeviceEnergyAnalysis entity);
|
||||
}
|
||||
|
|
@ -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("查询能耗异常分析失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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>
|
||||
Loading…
Reference in New Issue