From 76c0aa74f105d8b1fc5ba11439b10c85f36a039a Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Thu, 28 Aug 2025 01:21:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(property):=20=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E7=94=B5/=E6=B0=B4/=E6=B0=94=E8=B6=8B=E5=8A=BF=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbMeterRecordController.java | 23 ++++++- .../TbMeterRecordMapper.java | 9 +++ .../TbMeterRecordServiceImpl.java | 29 +++++++-- .../ITbMeterRecordService.java | 12 ++++ .../TbMeterReocordMapper.xml | 60 +++++++++++++++++++ 5 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java index d25a2488..998c8208 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterRecordController.java @@ -65,7 +65,7 @@ public class TbMeterRecordController extends BaseController { @SaCheckPermission("property:meterRecord:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable("id") Long id) { + @PathVariable("id") Long id) { return R.ok(tbMeterRecordService.queryById(id)); } @@ -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 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(); + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/smartDevicesMapper/TbMeterRecordMapper.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/smartDevicesMapper/TbMeterRecordMapper.java index e82a4650..73a1068e 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/smartDevicesMapper/TbMeterRecordMapper.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/smartDevicesMapper/TbMeterRecordMapper.java @@ -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 { + List> getHourTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("day") String day); + + List> getDayTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("year") String year, @Param("month") String month); + + List> getMonthTrend(@Param("floorId") Long floorId, @Param("meterId") Long meterId, @Param("meterType") Long meterType, @Param("year") String year); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java index df552533..bcbdb9c2 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterRecordServiceImpl.java @@ -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> 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> 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> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year); + log.info("月数据:{}", monthList); + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java index 4b8b30f9..b084f76a 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterRecordService.java @@ -73,4 +73,16 @@ public interface ITbMeterRecordService { * @param results 推送消息 */ void autoWriteMeterRecord(List 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); } diff --git a/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml b/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml new file mode 100644 index 00000000..e3fca9c9 --- /dev/null +++ b/ruoyi-modules/Property/src/main/resources/mapper/Property/smartDevicesService/TbMeterReocordMapper.xml @@ -0,0 +1,60 @@ + + + + + + + + + + +