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..697bc188 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); @@ -266,7 +281,7 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService { BigDecimal initReading = BigDecimal.valueOf(meterResult.getCollectionValue().get(Integer.parseInt(item.getMeterCode()))) .setScale(2, RoundingMode.HALF_UP); - if (initReading.equals(BigDecimal.ZERO)) { + if (initReading.compareTo(BigDecimal.ZERO) == 0) { item.setCommunicationState(0L); } else { item.setCommunicationState(1L); 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(); }