feat(property): 添加用电/水/气趋势分析功能

This commit is contained in:
2025-08-28 01:21:12 +08:00
parent e61b56b05e
commit 76c0aa74f1
5 changed files with 128 additions and 5 deletions

View File

@@ -103,4 +103,25 @@ public class TbMeterRecordController extends BaseController {
@PathVariable("ids") Long[] ids) {
return toAjax(tbMeterRecordService.deleteWithValidByIds(List.of(ids), true));
}
/**
* 获取用电/水/气趋势分析数据
*
* @param floorId 楼层id
* @param meterId 仪表id
* @param meterType 仪表类型
* @param day 日期
* @param month 月份
* @param year 年份
*/
@GetMapping("/trend")
public R<Void> getEnergyTrend(@RequestParam(required = false) String floorId,
@RequestParam(required = false) String meterId,
@RequestParam Long meterType,
@RequestParam String day,
@RequestParam String month,
@RequestParam String year) {
tbMeterRecordService.getEnergyTrend(floorId, meterId, meterType, day, month, year);
return R.ok();
}
}

View File

@@ -1,10 +1,14 @@
package org.dromara.property.mapper.smartDevicesMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.property.domain.entity.smartDevices.TbMeterRecord;
import org.dromara.property.domain.vo.smartDevicesVo.TbMeterRecordVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import java.util.List;
import java.util.Map;
/**
* 抄记录Mapper接口
*
@@ -14,4 +18,9 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
@Mapper
public interface TbMeterRecordMapper extends BaseMapperPlus<TbMeterRecord, TbMeterRecordVo> {
List<Map<String, Object>> getHourTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("day") String day);
List<Map<String, Object>> getDayTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("year") String year, @Param("month") String month);
List<Map<String, Object>> getMonthTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("year") String year);
}

View File

@@ -3,9 +3,8 @@ package org.dromara.property.service.impl.smartDevicesImpl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.json.JSONObject;
import cn.hutool.core.util.StrUtil;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -13,13 +12,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo;
import org.dromara.property.domain.enums.MeterRecordTypeEnum;
import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo;
import org.dromara.property.rocketmq.domain.MeterResult;
import org.dromara.property.service.smartDevicesService.ITbMeterInfoService;
import org.dromara.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import org.dromara.property.domain.bo.smartDevicesBo.TbMeterRecordBo;
import org.dromara.property.domain.vo.smartDevicesVo.TbMeterRecordVo;
@@ -225,4 +222,28 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
Assert.isTrue(flag, "批量写入抄表记录失败!");
}
}
/**
* 获取用电/水/气趋势分析数据
*
* @param floorId 楼层id
* @param meterId 仪表id
* @param meterType 仪表类型
* @param day 日期
* @param month 月份
* @param year 年份
*/
@Override
public void getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year) {
List<Map<String, Object>> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day);
log.info("小时数据:{}", hourList);
String[] monthArr = month.split("-");
List<Map<String, Object>> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, monthArr[0], monthArr[1]);
log.info("天数据:{}", dayList);
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
log.info("月数据:{}", monthList);
}
}

View File

@@ -73,4 +73,16 @@ public interface ITbMeterRecordService {
* @param results 推送消息
*/
void autoWriteMeterRecord(List<MeterResult> results);
/**
* 获取用电/水/气趋势分析数据
*
* @param floorId 楼层id
* @param meterId 仪表id
* @param meterType 仪表类型
* @param day 日期
* @param month 月份
* @param year 年份
*/
void getEnergyTrend(String floorId, String meterId, Long meterType, String day, String month, String year);
}

View File

@@ -0,0 +1,60 @@
<?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="org.dromara.property.mapper.smartDevicesMapper.TbMeterRecordMapper">
<select id="getHourTrend" resultType="map">
SELECT CONCAT_WS(':', HOUR(reading_time), '00') as hour, SUM(consumption) as total_consumption
FROM tb_meter_record a
LEFT JOIN tb_meter_info b ON a.meter_id = b.id
WHERE DATE(reading_time) = #{day}
AND b.meter_type = #{meterType}
<if test="floorId != '' and floorId != null">
AND b.floor_id = #{floorId}
</if>
<if test="meterId != '' and meterId != null">
AND a.meter_id = #{meterId}
</if>
GROUP BY CONCAT_WS(':', HOUR(reading_time), '00')
ORDER BY hour
</select>
<select id="getDayTrend" resultType="map">
SELECT
DAY(reading_time) AS `day`,
SUM(consumption) AS total_consumption
FROM tb_meter_record a
LEFT JOIN tb_meter_info b ON a.meter_id = b.id
WHERE YEAR(reading_time) = #{year}
AND MONTH(reading_time) = #{month}
AND b.meter_type = #{meterType}
<if test="floorId != '' and floorId != null">
AND b.floor_id = #{floorId}
</if>
<if test="meterId != '' and meterId != null">
AND a.meter_id = #{meterId}
</if>
GROUP BY DAY(reading_time)
ORDER BY `day`;
</select>
<select id="getMonthTrend" resultType="map">
SELECT
MONTH(reading_time) AS `month`,
SUM(consumption) AS total_consumption
FROM tb_meter_record a
LEFT JOIN tb_meter_info b ON a.meter_id = b.id
WHERE YEAR(reading_time) = #{year}
AND b.meter_type = #{meterType}
<if test="floorId != '' and floorId != null">
AND b.floor_id = #{floorId}
</if>
<if test="meterId != '' and meterId != null">
AND a.meter_id = #{meterId}
</if>
GROUP BY MONTH(reading_time)
ORDER BY `month`;
</select>
</mapper>