From 816b90e9e145f176e53ded5f0b9e7362a6dde029 Mon Sep 17 00:00:00 2001 From: yuyongle <1150359267@qq.com> Date: Wed, 27 Aug 2025 18:07:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=B0=B4?= =?UTF-8?q?=E7=94=B5=E6=8A=84=E8=A1=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sis/controller/SisVisitorController.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java index 607120f0..c0ce0a21 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/controller/SisVisitorController.java @@ -42,44 +42,44 @@ public class SisVisitorController { @GetMapping("/list") public TableDataInfo list(QueryDto dto) { -// TableDataInfo tableDataInfo = new TableDataInfo(); -// List accessRecordFindResList = new ArrayList<>(); -// AccessRecordFindRes accessRecordFindRes = new AccessRecordFindRes(); -// accessRecordFindRes.setDeviceName("4#岗亭09"); -// accessRecordFindRes.setDoorName("4#岗亭09"); -// accessRecordFindRes.setDeviceType(1102); -// accessRecordFindRes.setReaderName(""); -// accessRecordFindRes.setGatewayType(1); -// accessRecordFindRes.setCustomerName("德隆吴鹏"); -// accessRecordFindRes.setOrganFullPath("主楼11楼"); -// accessRecordFindRes.setPictureUrl("https://bpic.588ku.com/back_list_pic/23/04/21/ef5e2a3dd5cfc336fdcf2fd000474f0f.jpg"); -// accessRecordFindRes.setCardType(34); -// accessRecordFindRes.setRecordType(2); -// accessRecordFindRes.setActionTime(new Date()); -// accessRecordFindResList.add(accessRecordFindRes); -// tableDataInfo.setRows(accessRecordFindResList); -// tableDataInfo.setTotal(1); -// tableDataInfo.setCode(200); -// return tableDataInfo; - - dto.setPageIndex(1); - dto.setMaxResultCount(20); - - // 10秒内 - String starTime = DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, -10), "yyyy-MM-dd HH:mm:ss"); - String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); - - AccessRecordFindReq lift = new AccessRecordFindReq(); - lift.setStartTime(starTime); - lift.setEndTime(endTime); - lift.setRecordType(2); - // 9号电梯 - lift.setDeviceId(550757939925061L); - dto.setQueryDto(lift); -// TableDataInfo nineLiftList = e8PlatformApi.getPageAccessRecordList(dto); - TableDataInfo pageAccessRecordList = new TableDataInfo(); - - return e8PlatformApi.getPageAccessRecordList(dto); + TableDataInfo tableDataInfo = new TableDataInfo(); + List accessRecordFindResList = new ArrayList<>(); + AccessRecordFindRes accessRecordFindRes = new AccessRecordFindRes(); + accessRecordFindRes.setDeviceName("4#岗亭09"); + accessRecordFindRes.setDoorName("4#岗亭09"); + accessRecordFindRes.setDeviceType(1102); + accessRecordFindRes.setReaderName(""); + accessRecordFindRes.setGatewayType(1); + accessRecordFindRes.setCustomerName("德隆吴鹏"); + accessRecordFindRes.setOrganFullPath("主楼11楼"); + accessRecordFindRes.setPictureUrl("https://bpic.588ku.com/back_list_pic/23/04/21/ef5e2a3dd5cfc336fdcf2fd000474f0f.jpg"); + accessRecordFindRes.setCardType(34); + accessRecordFindRes.setRecordType(2); + accessRecordFindRes.setActionTime(new Date()); + accessRecordFindResList.add(accessRecordFindRes); + tableDataInfo.setRows(accessRecordFindResList); + tableDataInfo.setTotal(1); + tableDataInfo.setCode(200); + return tableDataInfo; +// +// dto.setPageIndex(1); +// dto.setMaxResultCount(20); +// +// // 10秒内 +// String starTime = DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, -10), "yyyy-MM-dd HH:mm:ss"); +// String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); +// +// AccessRecordFindReq lift = new AccessRecordFindReq(); +// lift.setStartTime(starTime); +// lift.setEndTime(endTime); +// lift.setRecordType(2); +// // 9号电梯 +// lift.setDeviceId(550757939925061L); +// dto.setQueryDto(lift); +//// TableDataInfo nineLiftList = e8PlatformApi.getPageAccessRecordList(dto); +// TableDataInfo pageAccessRecordList = new TableDataInfo(); +// +// return e8PlatformApi.getPageAccessRecordList(dto); //如果pageAccessRecordList报错就捕获并封装 } } From 368eea91e89ef68b98861bd2c1a3677abb5df264 Mon Sep 17 00:00:00 2001 From: yuyongle <1150359267@qq.com> Date: Wed, 27 Aug 2025 18:14:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=B0=B4?= =?UTF-8?q?=E7=94=B5=E6=8A=84=E8=A1=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumer/MeterRecordConsumer.java | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java index 8360613a..3a0a80d0 100644 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java +++ b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java @@ -1,44 +1,44 @@ -package org.dromara.sis.rocketmq.consumer; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; -import org.apache.rocketmq.spring.core.RocketMQListener; -import org.dromara.sis.rocketmq.RocketMqConstants; -import org.dromara.sis.rocketmq.producer.ProducerService; -import org.springframework.stereotype.Component; - -/** - * @author lsm - * @apiNote MeterRecordConsumer - * @since 2025/8/25 - */ -@Slf4j -@Component -@RequiredArgsConstructor -@RocketMQMessageListener( - topic = RocketMqConstants.TOPIC, - consumerGroup = RocketMqConstants.METER_GROUP, - selectorExpression = RocketMqConstants.METER_RECORD, - nameServer = "${rocketmq.cluster1.name-server}" -) -public class MeterRecordConsumer implements RocketMQListener { - - private final ProducerService producerService; - - @Override - public void onMessage(MessageExt ext) { - try { - if (ext.getBody() == null) { - log.info("仪表上报消息数据,不转发!"); - } else { - producerService.defaultSend(RocketMqConstants.TOPIC, RocketMqConstants.METER_RECORD, new String(ext.getBody())); - log.info("转发仪表上报数据处理成功"); - } - } catch (Exception e) { - log.error("转发仪表上报数据处理失败,", e); - } - - } -} +//package org.dromara.sis.rocketmq.consumer; +// +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.rocketmq.common.message.MessageExt; +//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +//import org.apache.rocketmq.spring.core.RocketMQListener; +//import org.dromara.sis.rocketmq.RocketMqConstants; +//import org.dromara.sis.rocketmq.producer.ProducerService; +//import org.springframework.stereotype.Component; +// +///** +// * @author lsm +// * @apiNote MeterRecordConsumer +// * @since 2025/8/25 +// */ +//@Slf4j +//@Component +//@RequiredArgsConstructor +//@RocketMQMessageListener( +// topic = RocketMqConstants.TOPIC, +// consumerGroup = RocketMqConstants.METER_GROUP, +// selectorExpression = RocketMqConstants.METER_RECORD, +// nameServer = "${rocketmq.cluster1.name-server}" +//) +//public class MeterRecordConsumer implements RocketMQListener { +// +// private final ProducerService producerService; +// +// @Override +// public void onMessage(MessageExt ext) { +// try { +// if (ext.getBody() == null) { +// log.info("仪表上报消息数据,不转发!"); +// } else { +// producerService.defaultSend(RocketMqConstants.TOPIC, RocketMqConstants.METER_RECORD, new String(ext.getBody())); +// log.info("转发仪表上报数据处理成功"); +// } +// } catch (Exception e) { +// log.error("转发仪表上报数据处理失败,", e); +// } +// +// } +//} From 4d76a4df451db7772e08c2bc7a4b6783100912b3 Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Wed, 27 Aug 2025 19:27:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat(property):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8A=84=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbMeterInfoController.java | 14 +++ .../bo/smartDevicesBo/TbMeterRecordBo.java | 4 +- .../entity/smartDevices/TbMeterRecord.java | 2 +- .../domain/enums/MeterRecordTypeEnum.java | 33 ++++++ .../vo/smartDevicesVo/TbMeterRecordVo.java | 2 +- .../consumer/MeterRecordConsumer.java | 15 ++- .../property/rocketmq/domain/MeterResult.java | 20 ++++ .../TbMeterInfoServiceImpl.java | 79 +++++++++++++ .../TbMeterRecordServiceImpl.java | 105 ++++++++++++++++-- .../ITbMeterInfoService.java | 10 ++ .../ITbMeterRecordService.java | 8 ++ .../sis/config/RocketMQClusterConfig.java | 75 ------------- .../consumer/MeterRecordConsumer.java | 44 -------- .../rocketmq/producer/ProducerService.java | 65 ----------- 14 files changed, 275 insertions(+), 201 deletions(-) create mode 100644 ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterRecordTypeEnum.java create mode 100644 ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/domain/MeterResult.java delete mode 100644 ruoyi-modules/Sis/src/main/java/org/dromara/sis/config/RocketMQClusterConfig.java delete mode 100644 ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java delete mode 100644 ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/producer/ProducerService.java diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterInfoController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterInfoController.java index 5a38934f..df9b6d17 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterInfoController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/smartDevicesController/TbMeterInfoController.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; +import org.dromara.common.core.domain.TreeNode; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import org.dromara.common.idempotent.annotation.RepeatSubmit; @@ -103,4 +104,17 @@ public class TbMeterInfoController extends BaseController { @PathVariable("ids") Long[] ids) { return toAjax(tbMeterInfoService.deleteWithValidByIds(List.of(ids), true)); } + + /** + * 生成 社区/建组/单元/楼栋/(水电气表)树结构 + * + * @param meterType 水电气类型 + * + * @return (水电气表)树结构 + */ + @GetMapping("/tree/{meterType}") + public R>> queryMeterInfoTree(@PathVariable("meterType") Long meterType) { + return R.ok(tbMeterInfoService.queryMeterInfoTree(meterType)); + } + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterRecordBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterRecordBo.java index abd989aa..c056e4cb 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterRecordBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/smartDevicesBo/TbMeterRecordBo.java @@ -32,8 +32,8 @@ public class TbMeterRecordBo extends BaseEntity { /** * 仪表编号 */ - @NotBlank(message = "仪表编号不能为空", groups = { AddGroup.class, EditGroup.class }) - private String meterId; + @NotNull(message = "仪表编号不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long meterId; /** * 设备类型(1-电表,2-水表,3-气表) diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterRecord.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterRecord.java index 4c3d6296..c7dd3b04 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterRecord.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/entity/smartDevices/TbMeterRecord.java @@ -33,7 +33,7 @@ public class TbMeterRecord extends TenantEntity { /** * 仪表编号 */ - private String meterId; + private Long meterId; /** * 设备类型(1-电表,2-水表,3-气表) diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterRecordTypeEnum.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterRecordTypeEnum.java new file mode 100644 index 00000000..40f0ca78 --- /dev/null +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/enums/MeterRecordTypeEnum.java @@ -0,0 +1,33 @@ +package org.dromara.property.domain.enums; + +import lombok.Getter; + +/** + * @author lsm + * @apiNote MeterRecordTypeEnum + * @since 2025/8/27 + */ +@Getter +public enum MeterRecordTypeEnum { + + /** + * 手动上报 + */ + MANUAL_RECORD(1L), + + /** + * 自动上报 + */ + AUTO_RECORD(2L), + + /** + * 用户上报 + */ + USER_RECORD(3L); + + private final Long code; + + MeterRecordTypeEnum(Long code) { + this.code = code; + } +} diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterRecordVo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterRecordVo.java index 8fbec766..ae03eb08 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterRecordVo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/smartDevicesVo/TbMeterRecordVo.java @@ -37,7 +37,7 @@ public class TbMeterRecordVo implements Serializable { * 仪表编号 */ @ExcelProperty(value = "仪表编号") - private String meterId; + private Long meterId; /** * 设备类型(1-电表,2-水表,3-气表) diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/consumer/MeterRecordConsumer.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/consumer/MeterRecordConsumer.java index 75aa5189..8abf3c37 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/consumer/MeterRecordConsumer.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/consumer/MeterRecordConsumer.java @@ -1,15 +1,18 @@ package org.dromara.property.rocketmq.consumer; -import com.alibaba.fastjson.JSONObject; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; import org.apache.rocketmq.spring.core.RocketMQListener; import org.dromara.property.rocketmq.RocketMqConstants; +import org.dromara.property.rocketmq.domain.MeterResult; +import org.dromara.property.service.smartDevicesService.ITbMeterRecordService; import org.springframework.stereotype.Component; -import java.util.Arrays; +import java.util.List; /** * @author lsm @@ -21,17 +24,19 @@ import java.util.Arrays; @RequiredArgsConstructor @RocketMQMessageListener( topic = RocketMqConstants.TOPIC, - consumerGroup = RocketMqConstants.GROUP, + consumerGroup = RocketMqConstants.METER_GROUP, selectorExpression = RocketMqConstants.METER_RECORD ) public class MeterRecordConsumer implements RocketMQListener { + private final ITbMeterRecordService meterRecordService; + @Override public void onMessage(MessageExt ext) { log.info("消费仪表上报数据,数据长度={}", ext.getBody().length); try { - String message = new String(ext.getBody()); - log.info("物业仪表上报数据,数据={}", message); + List meterResults = JSONUtil.toList(new String(ext.getBody()), MeterResult.class); + meterRecordService.autoWriteMeterRecord(meterResults); } catch (Exception e) { log.error("消费仪表上报数据处理失败,", e); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/domain/MeterResult.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/domain/MeterResult.java new file mode 100644 index 00000000..be468078 --- /dev/null +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/rocketmq/domain/MeterResult.java @@ -0,0 +1,20 @@ +package org.dromara.property.rocketmq.domain; + +import lombok.Data; + +import java.util.List; + +/** + * @author lsm + * @apiNote MeterResult + * @since 2025/8/27 + */ +@Data +public class MeterResult { + + private String ip; + + private String recordTime; + + private List collectionValue; +} diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterInfoServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterInfoServiceImpl.java index 35ebee2e..a5a71bec 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterInfoServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/smartDevicesImpl/TbMeterInfoServiceImpl.java @@ -1,8 +1,10 @@ package org.dromara.property.service.impl.smartDevicesImpl; import cn.hutool.core.lang.Assert; +import org.dromara.common.core.domain.TreeNode; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.core.utils.TreeUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.PageQuery; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -10,9 +12,15 @@ 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.TbFloorBo; +import org.dromara.property.domain.vo.TbBuildingVo; +import org.dromara.property.domain.vo.TbCommunityVo; import org.dromara.property.domain.vo.TbFloorVo; +import org.dromara.property.service.ITbBuildingService; +import org.dromara.property.service.ITbCommunityService; import org.dromara.property.service.ITbFloorService; +import org.dromara.system.api.model.LoginUser; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo; import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo; @@ -21,6 +29,7 @@ import org.dromara.property.mapper.smartDevicesMapper.TbMeterInfoMapper; import org.dromara.property.service.smartDevicesService.ITbMeterInfoService; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Collection; @@ -39,6 +48,8 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { private final TbMeterInfoMapper baseMapper; private final ITbFloorService floorService; + private final ITbBuildingService buildingService; + private final ITbCommunityService communityService; /** * 查询水电气 @@ -94,6 +105,7 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.orderByAsc(TbMeterInfo::getId); + lqw.like(StringUtils.isNotBlank(bo.getHostIp()), TbMeterInfo::getHostIp, bo.getHostIp()); lqw.like(StringUtils.isNotBlank(bo.getMeterName()), TbMeterInfo::getMeterName, bo.getMeterName()); lqw.eq(StringUtils.isNotBlank(bo.getMeterCode()), TbMeterInfo::getMeterCode, bo.getMeterCode()); lqw.eq(StringUtils.isNotBlank(bo.getFactoryNo()), TbMeterInfo::getFactoryNo, bo.getFactoryNo()); @@ -160,4 +172,71 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { } return baseMapper.deleteByIds(ids) > 0; } + + /** + * 查询水电气树结构 + * + * @param meterType 水电气类型 + * @return 水电气树结构 + */ + @Override + public List> queryMeterInfoTree(Long meterType) { + // 默认加载社区树 + List> treeList = new ArrayList<>(); + List tbCommunityVos = communityService.queryAll(); + if (tbCommunityVos == null || tbCommunityVos.isEmpty()) { + return treeList; + } + List> l1 = tbCommunityVos.stream().map(item -> { + TreeNode node = new TreeNode<>(); + node.setLevel(1); + node.setCode(item.getId()); + node.setParentCode(0L); + node.setLabel(item.getCommunityName()); + return node; + }).toList(); + treeList.addAll(l1); + List tbBuildingVos = buildingService.queryAll(); + if (tbBuildingVos == null || tbBuildingVos.isEmpty()) { + return treeList; + } + List> l2 = tbBuildingVos.stream().map(item -> { + TreeNode node = new TreeNode<>(); + node.setLevel(2); + node.setCode(item.getId()); + node.setParentCode(item.getCommunityId()); + node.setLabel(item.getBuildingName()); + return node; + }).toList(); + treeList.addAll(l2); + List tbFloorVos = floorService.queryAll(); + if (tbFloorVos == null || tbFloorVos.isEmpty()) { + return treeList; + } + List> l3 = tbFloorVos.stream().map(item -> { + TreeNode node = new TreeNode<>(); + node.setLevel(3); + node.setCode(item.getId()); + node.setParentCode(item.getBuildingId()); + node.setLabel(item.getFloorName()); + return node; + }).toList(); + treeList.addAll(l3); + + TbMeterInfoBo bo = new TbMeterInfoBo(); + bo.setMeterType(meterType); + List meterInfoVos = this.queryList(bo); + if (meterInfoVos != null && !meterInfoVos.isEmpty()) { + List> l4 = meterInfoVos.stream().map(item -> { + TreeNode node = new TreeNode<>(); + node.setLevel(4); + node.setCode(item.getId()); + node.setParentCode(item.getFloorId()); + node.setLabel(item.getMeterName()); + return node; + }).toList(); + treeList.addAll(l4); + } + return TreeUtils.build(treeList, 0L); + } } 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 cd225632..df552533 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 @@ -1,5 +1,9 @@ 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 org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -9,22 +13,31 @@ 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; import org.dromara.property.domain.entity.smartDevices.TbMeterRecord; import org.dromara.property.mapper.smartDevicesMapper.TbMeterRecordMapper; import org.dromara.property.service.smartDevicesService.ITbMeterRecordService; +import org.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Map; -import java.util.Collection; +import java.math.BigDecimal; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 抄记录Service业务层处理 * * @author lsm - * @date 2025-07-19 + * @since 2025-07-19 */ @Slf4j @RequiredArgsConstructor @@ -32,6 +45,7 @@ import java.util.Collection; public class TbMeterRecordServiceImpl implements ITbMeterRecordService { private final TbMeterRecordMapper baseMapper; + private final ITbMeterInfoService tbMeterInfoService; /** * 查询抄记录 @@ -40,7 +54,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { * @return 抄记录 */ @Override - public TbMeterRecordVo queryById(Long id){ + public TbMeterRecordVo queryById(Long id) { return baseMapper.selectVoById(id); } @@ -74,7 +88,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.orderByAsc(TbMeterRecord::getId); - lqw.eq(StringUtils.isNotBlank(bo.getMeterId()), TbMeterRecord::getMeterId, bo.getMeterId()); + lqw.eq(bo.getMeterId() != null, TbMeterRecord::getMeterId, bo.getMeterId()); lqw.eq(bo.getMeterType() != null, TbMeterRecord::getMeterType, bo.getMeterType()); lqw.eq(bo.getReaderId() != null, TbMeterRecord::getReaderId, bo.getReaderId()); lqw.eq(bo.getReadingTime() != null, TbMeterRecord::getReadingTime, bo.getReadingTime()); @@ -118,7 +132,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(TbMeterRecord entity){ + private void validEntityBeforeSave(TbMeterRecord entity) { //TODO 做一些数据校验,如唯一约束 } @@ -131,9 +145,84 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService { */ @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ + if (isValid) { //TODO 做一些业务上的校验,判断是否需要校验 } return baseMapper.deleteByIds(ids) > 0; } + + /** + * 自动写入抄表记录 + * + * @param results 推送消息 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void autoWriteMeterRecord(List results) { + log.info("自动写入抄表记录, msg:{}", results); + + for (MeterResult result : results) { + // 取出同一个采集器ip下,所有设备 + TbMeterInfoBo infoBo = new TbMeterInfoBo(); + infoBo.setHostIp(result.getIp()); + List infoList = tbMeterInfoService.queryList(infoBo); + + if (CollUtil.isEmpty(infoList)) { + log.info("当前采集器ip下无设备, ip:{}", result.getIp()); + continue; + } + + // 获取设备id + Collection meterIds = infoList.stream().map(TbMeterInfoVo::getId).toList(); + + // 取出上次抄表记录 + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.in(TbMeterRecord::getMeterId, meterIds) + .orderByDesc(TbMeterRecord::getReadingTime) + .last("limit " + meterIds.size()); + List recordOld = baseMapper.selectList(lqw); + + List recordNew = new ArrayList<>(infoList.size()); + boolean hasOldRecords = CollUtil.isNotEmpty(recordOld); + + log.info("当前采集器ip下{}抄表记录, ip:{}", hasOldRecords ? "有" : "无", result.getIp()); + // 创建meterId到旧记录的映射,提高查找效率 + Map oldRecordMap = hasOldRecords ? + recordOld.stream().collect(Collectors.toMap(TbMeterRecord::getMeterId, Function.identity())) : + Collections.emptyMap(); + + for (TbMeterInfoVo info : infoList) { + TbMeterRecord record = new TbMeterRecord(); + record.setMeterId(info.getId()); + record.setMeterType(info.getMeterType()); + record.setReaderId(1L); + record.setReadingTime(DateUtil.parse(result.getRecordTime(), "yyyy-MM-dd HH:mm:ss")); + + // 获取当前读数 + BigDecimal currentReading = BigDecimal.valueOf( + result.getCollectionValue().get(Integer.parseInt(info.getMeterCode())) + ); + record.setCurrentReading(currentReading); + + // 设置上次读数 + if (hasOldRecords) { + TbMeterRecord oldRecord = oldRecordMap.get(info.getId()); + if (oldRecord != null) { + record.setPreviousReading(oldRecord.getCurrentReading()); + } else { + // 如果没有找到对应的旧记录,使用默认值 + record.setPreviousReading(BigDecimal.ZERO); + } + } else { + record.setPreviousReading(BigDecimal.ZERO); + } + + record.setReadingMethod(MeterRecordTypeEnum.AUTO_RECORD.getCode()); + recordNew.add(record); + } + + boolean flag = baseMapper.insertBatch(recordNew); + Assert.isTrue(flag, "批量写入抄表记录失败!"); + } + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterInfoService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterInfoService.java index fbcc807e..7695b8f2 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterInfoService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/smartDevicesService/ITbMeterInfoService.java @@ -1,5 +1,6 @@ package org.dromara.property.service.smartDevicesService; +import org.dromara.common.core.domain.TreeNode; import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo; import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -65,4 +66,13 @@ public interface ITbMeterInfoService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + /** + * 查询水电气树结构 + * + * @param meterType 水电气类型 + * + * @return 水电气树结构 + */ + List> queryMeterInfoTree(Long meterType); } 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 475e0e18..4b8b30f9 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 @@ -4,6 +4,7 @@ import org.dromara.property.domain.vo.smartDevicesVo.TbMeterRecordVo; import org.dromara.property.domain.bo.smartDevicesBo.TbMeterRecordBo; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.property.rocketmq.domain.MeterResult; import java.util.Collection; import java.util.List; @@ -65,4 +66,11 @@ public interface ITbMeterRecordService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + /** + * 自动写入抄表记录 + * + * @param results 推送消息 + */ + void autoWriteMeterRecord(List results); } diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/config/RocketMQClusterConfig.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/config/RocketMQClusterConfig.java deleted file mode 100644 index 8096dfc1..00000000 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/config/RocketMQClusterConfig.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.dromara.sis.config; - -import org.apache.rocketmq.client.producer.DefaultMQProducer; -import org.apache.rocketmq.spring.core.RocketMQTemplate; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author lsm - * @apiNote RocketMQClusterConfig - * @since 2025/8/26 - */ -@Configuration -public class RocketMQClusterConfig { - - // 从配置文件中读取 cluster 的配置 - @Value("${rocketmq.cluster1.name-server}") - private String nameServer1; - - @Value("${rocketmq.cluster1.producer.group}") - private String producerGroup1; - - // 为第一个集群创建生产者实例 - @Bean({"clusterProducerOne"}) - public DefaultMQProducer clusterProducerOne() throws Exception { - DefaultMQProducer producer = new DefaultMQProducer(producerGroup1); - producer.setNamesrvAddr(nameServer1); - // 设置发送超时时间 - producer.setSendMsgTimeout(5000); - // 设置重试次数 - producer.setRetryTimesWhenSendFailed(2); - producer.setRetryTimesWhenSendAsyncFailed(2); - return producer; - } - - // 使用上面的生产者实例创建 RocketMQTemplate - @Bean("rocketMQTemplateClusterOne") - public RocketMQTemplate rocketMQTemplateClusterOne(@Qualifier("clusterProducerOne") DefaultMQProducer producer) { - RocketMQTemplate template = new RocketMQTemplate(); - template.setProducer(producer); - return template; - } - - - // 从配置文件中读取 cluster 的配置 -// @Value("${rocketmq.cluster2.name-server}") -// private String nameServer2; -// -// @Value("${rocketmq.cluster2.producer.group}") -// private String producerGroup2; -// -// // 为第二个集群创建生产者实例 -// @Bean({"clusterProducerTwo"}) -// public DefaultMQProducer clusterProducerTwo() throws Exception { -// DefaultMQProducer producer = new DefaultMQProducer(producerGroup2); -// producer.setNamesrvAddr(nameServer2); -// // 设置发送超时时间 -// producer.setSendMsgTimeout(5000); -// // 设置重试次数 -// producer.setRetryTimesWhenSendFailed(2); -// producer.setRetryTimesWhenSendAsyncFailed(2); -// return producer; -// } -// -// // 使用上面的生产者实例创建 RocketMQTemplate -// @Bean("rocketMQTemplateClusterTwo") -// public RocketMQTemplate rocketMQTemplateClusterTwo(@Qualifier("clusterProducerTwo") DefaultMQProducer producer) { -// RocketMQTemplate template = new RocketMQTemplate(); -// template.setProducer(producer); -// return template; -// } - -} diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java deleted file mode 100644 index 8360613a..00000000 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.dromara.sis.rocketmq.consumer; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; -import org.apache.rocketmq.spring.core.RocketMQListener; -import org.dromara.sis.rocketmq.RocketMqConstants; -import org.dromara.sis.rocketmq.producer.ProducerService; -import org.springframework.stereotype.Component; - -/** - * @author lsm - * @apiNote MeterRecordConsumer - * @since 2025/8/25 - */ -@Slf4j -@Component -@RequiredArgsConstructor -@RocketMQMessageListener( - topic = RocketMqConstants.TOPIC, - consumerGroup = RocketMqConstants.METER_GROUP, - selectorExpression = RocketMqConstants.METER_RECORD, - nameServer = "${rocketmq.cluster1.name-server}" -) -public class MeterRecordConsumer implements RocketMQListener { - - private final ProducerService producerService; - - @Override - public void onMessage(MessageExt ext) { - try { - if (ext.getBody() == null) { - log.info("仪表上报消息数据,不转发!"); - } else { - producerService.defaultSend(RocketMqConstants.TOPIC, RocketMqConstants.METER_RECORD, new String(ext.getBody())); - log.info("转发仪表上报数据处理成功"); - } - } catch (Exception e) { - log.error("转发仪表上报数据处理失败,", e); - } - - } -} diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/producer/ProducerService.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/producer/ProducerService.java deleted file mode 100644 index 7c40a8de..00000000 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/producer/ProducerService.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.dromara.sis.rocketmq.producer; - -import lombok.extern.slf4j.Slf4j; -import org.apache.rocketmq.common.message.Message; -import org.apache.rocketmq.spring.core.RocketMQTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -/** - * @author lsm - * @apiNote ProducerService - * @since 2025/8/26 - */ -@Slf4j -@Component -public class ProducerService { - - @Autowired - @Qualifier("rocketMQTemplateClusterOne") - private RocketMQTemplate rocketMQTemplateClusterOne; - -// @Autowired -// @Qualifier("rocketMQTemplateClusterTwo") -// private RocketMQTemplate rocketMQTemplateClusterTwo; - - /** - * 向mq写入消息 - * - * @param topic 消息topic - * @param tag 消息tag - * @param msg 消息 - */ - public void defaultSend(String topic, String tag, String msg) { - try { - String destination = topic + ":" + tag; - // 使用 RocketMQTemplate 的同步发送方法 - rocketMQTemplateClusterOne.syncSend(destination, msg); - - log.info("发送RocketMQOne消息成功, nameServer:{}", rocketMQTemplateClusterOne.getProducer().getNamesrvAddr()); - } catch (Exception e) { - log.error("发送RocketMQOne消息失败", e); - } - } - - - /** - * 向mq写入消息 - * - * @param topic 消息topic - * @param tag 消息tag - * @param msg 消息 - */ -// public void clusterSend(String topic, String tag, String msg) { -// try { -// String destination = topic + ":" + tag; -// // 使用 RocketMQTemplate 的同步发送方法 -// rocketMQTemplateClusterTwo.syncSend(destination, msg); -// -// log.info("发送RocketMQTwo消息成功, nameServer:{}", rocketMQTemplateClusterTwo.getProducer().getNamesrvAddr()); -// } catch (Exception e) { -// log.error("发送RocketMQTwo消息失败", e); -// } -// } -} From e61b56b05ee155466edfb6e58654d2c7a399d2b2 Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Wed, 27 Aug 2025 19:28:24 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(property):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8A=84=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumer/MeterRecordConsumer.java | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java diff --git a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java b/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java deleted file mode 100644 index 591fb908..00000000 --- a/ruoyi-modules/Sis/src/main/java/org/dromara/sis/rocketmq/consumer/MeterRecordConsumer.java +++ /dev/null @@ -1,45 +0,0 @@ - -//package org.dromara.sis.rocketmq.consumer; -// -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.apache.rocketmq.common.message.MessageExt; -//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; -//import org.apache.rocketmq.spring.core.RocketMQListener; -//import org.dromara.sis.rocketmq.RocketMqConstants; -//import org.dromara.sis.rocketmq.producer.ProducerService; -//import org.springframework.stereotype.Component; -// -///** -// * @author lsm -// * @apiNote MeterRecordConsumer -// * @since 2025/8/25 -// */ -//@Slf4j -//@Component -//@RequiredArgsConstructor -//@RocketMQMessageListener( -// topic = RocketMqConstants.TOPIC, -// consumerGroup = RocketMqConstants.METER_GROUP, -// selectorExpression = RocketMqConstants.METER_RECORD, -// nameServer = "${rocketmq.cluster1.name-server}" -//) -//public class MeterRecordConsumer implements RocketMQListener { -// -// private final ProducerService producerService; -// -// @Override -// public void onMessage(MessageExt ext) { -// try { -// if (ext.getBody() == null) { -// log.info("仪表上报消息数据,不转发!"); -// } else { -// producerService.defaultSend(RocketMqConstants.TOPIC, RocketMqConstants.METER_RECORD, new String(ext.getBody())); -// log.info("转发仪表上报数据处理成功"); -// } -// } catch (Exception e) { -// log.error("转发仪表上报数据处理失败,", e); -// } -// -// } -//} From 76c0aa74f105d8b1fc5ba11439b10c85f36a039a Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Thu, 28 Aug 2025 01:21:12 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat(property):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E7=94=B5/=E6=B0=B4/=E6=B0=94=E8=B6=8B=E5=8A=BF?= =?UTF-8?q?=E5=88=86=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 @@ + + + + + + + + + + +