From f9544ad4e1b157adf0939b4a89cc1c842b3517a8 Mon Sep 17 00:00:00 2001 From: zcxlsm Date: Sun, 31 Aug 2025 12:44:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(property):=20=E4=BC=98=E5=8C=96=E6=B0=B4?= =?UTF-8?q?=E7=94=B5=E6=B0=94=E8=A1=A8=E6=A0=91=E7=BB=93=E6=9E=84=E5=92=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=8E=B7=E5=8F=96=E5=8A=9F=E8=83=BD=20-=20?= =?UTF-8?q?=E5=9C=A8=20queryMeterInfoTree=20=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20isMeter=20=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=BB=AA=E8=A1=A8=E4=BF=A1=E6=81=AF=20-=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20getMeterStatus=20=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20meterType=20=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9A=E6=B0=B4=E7=94=B5=E6=B0=94?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20-=20=E4=BC=98=E5=8C=96=20TbMeterInfoContro?= =?UTF-8?q?ller=20=E4=B8=AD=E7=9A=84=E8=B7=AF=E7=94=B1=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=20query=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=E8=B7=AF=E5=BE=84=E5=8F=82=E6=95=B0-=20?= =?UTF-8?q?=E5=9C=A8=E8=8E=B7=E5=8F=96=E4=BB=AA=E8=A1=A8=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=83=BD=E5=A4=9F=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=89=80=E6=9C=89=E6=95=B0=E6=8D=AE=E5=B9=B6=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=8A=B6=E6=80=81=E4=B8=BA=200=20-=20?= =?UTF-8?q?=E5=9C=A8=20HttpUtil.post=20=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=85=E6=97=B6=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E8=AF=B7=E6=B1=82=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TbMeterInfoController.java | 23 +++++---- .../TbMeterInfoServiceImpl.java | 49 ++++++++++++------- .../ITbMeterInfoService.java | 9 ++-- .../property/utils/MeterRecordUtil.java | 2 +- 4 files changed, 52 insertions(+), 31 deletions(-) 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 3a3874b4..203a4850 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 @@ -28,7 +28,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo; * 前端访问路由地址为:/property/meterInfo * * @author lsm - * @date 2025-07-19 + * @since 2025-07-19 */ @Validated @RequiredArgsConstructor @@ -66,7 +66,7 @@ public class TbMeterInfoController extends BaseController { @SaCheckPermission("property:meterInfo:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable("id") Long id) { + @PathVariable("id") Long id) { return R.ok(tbMeterInfoService.queryById(id)); } @@ -109,20 +109,23 @@ public class TbMeterInfoController extends BaseController { * 生成 社区/建组/单元/楼栋/(水电气表)树结构 * * @param meterType 水电气类型 - * + * @param isMeter 是否返回仪表 * @return (水电气表)树结构 */ - @GetMapping("/tree/{meterType}") - public R>> queryMeterInfoTree(@PathVariable("meterType") Long meterType) { - return R.ok(tbMeterInfoService.queryMeterInfoTree(meterType)); + @GetMapping("/tree") + public R>> queryMeterInfoTree(@RequestParam Long meterType, @RequestParam Boolean isMeter) { + return R.ok(tbMeterInfoService.queryMeterInfoTree(meterType, isMeter)); } /** - * 获取水/电/气表当前读数 + * 获取水/电/气表当前读数/状态 + * + * @param meterType 水电气类型 + * @param floorId 楼栋id */ - @GetMapping("/currentReading/{floorId}") - public R> currentReading(@PathVariable("floorId") Long floorId) { - return R.ok(tbMeterInfoService.getMeterStatus(floorId)); + @GetMapping("/currentReading") + public R> currentReading(@RequestParam Long meterType, @RequestParam Long floorId) { + return R.ok(tbMeterInfoService.getMeterStatus(meterType, floorId)); } } 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 0ec6ff16..a5651461 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 @@ -179,10 +179,11 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { * 查询水电气树结构 * * @param meterType 水电气类型 + * @param isMeter 是否返回仪表 * @return 水电气树结构 */ @Override - public List> queryMeterInfoTree(Long meterType) { + public List> queryMeterInfoTree(Long meterType, Boolean isMeter) { // 默认加载社区树 List> treeList = new ArrayList<>(); List tbCommunityVos = communityService.queryAll(); @@ -225,30 +226,36 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { }).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); + if (isMeter){ + 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); } /** * 获取水/电/气表当前读数/状态 + * + * @param meterType 水电气类型 + * @param floorId 楼栋id */ @Override - public List getMeterStatus(Long floorId) { + public List getMeterStatus(Long meterType, Long floorId) { TbMeterInfoBo meterInfoBo = new TbMeterInfoBo(); meterInfoBo.setFloorId(floorId); + meterInfoBo.setMeterType(meterType); List meterInfoVoList = this.queryList(meterInfoBo); if (meterInfoVoList.isEmpty()) return null; @@ -257,8 +264,16 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { for (String ip : hostIpArr) { ipCountMap.put(ip, baseMapper.selectCount(new LambdaQueryWrapper().eq(TbMeterInfo::getHostIp, ip))); } - List meterResults = meterRecordUtil.getMeterStatus(ipCountMap, hostIpArr); - log.info("获取仪表状态结果={}", meterResults); + List meterResults; + try{ + meterResults = meterRecordUtil.getMeterStatus(ipCountMap, hostIpArr); + } catch (Exception e) { + // 获取数据失败,返回所有数据,设置通信状态为0 + for (TbMeterInfoVo item : meterInfoVoList) { + item.setCommunicationState(0L); + } + return meterInfoVoList; + } for (TbMeterInfoVo item : meterInfoVoList) { MeterResult meterResult = meterResults.stream().filter(o -> o.getIp().equals(item.getHostIp())).findFirst().orElse(null); 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 f3ca6e17..d71fb417 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 @@ -71,13 +71,16 @@ public interface ITbMeterInfoService { * 查询水电气树结构 * * @param meterType 水电气类型 - * + * @param isMeter 是否返回仪表 * @return 水电气树结构 */ - List> queryMeterInfoTree(Long meterType); + List> queryMeterInfoTree(Long meterType, Boolean isMeter); /** * 获取水/电/气表当前读数/状态 + * + * @param meterType 水电气类型 + * @param floorId 楼栋id */ - List getMeterStatus(Long floorId); + List getMeterStatus(Long meterType, Long floorId); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/MeterRecordUtil.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/MeterRecordUtil.java index bfec4d8e..aec441d0 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/MeterRecordUtil.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/utils/MeterRecordUtil.java @@ -40,7 +40,7 @@ public class MeterRecordUtil { JSONObject jsonObject = new JSONObject(); jsonObject.putOnce("ipMap", ipMap); jsonObject.putOnce("ipArr", ipArr); - String post = HttpUtil.post(meterRecordUrl + READING_URL, jsonObject.toString()); + String post = HttpUtil.post(meterRecordUrl + READING_URL, jsonObject.toString(), 3000); Result> result = JSONUtil.toBean(post, new TypeReference>>() {}, true); return result.getData(); }