feat(Property): 添加水/电/气表当前读数和状态获取功能
This commit is contained in:
@@ -117,4 +117,12 @@ public class TbMeterInfoController extends BaseController {
|
|||||||
return R.ok(tbMeterInfoService.queryMeterInfoTree(meterType));
|
return R.ok(tbMeterInfoService.queryMeterInfoTree(meterType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取水/电/气表当前读数
|
||||||
|
*/
|
||||||
|
@GetMapping("/currentReading/{floorId}")
|
||||||
|
public R<Void> currentReading(@PathVariable("floorId") Long floorId) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -12,15 +12,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
|
||||||
import org.dromara.property.domain.bo.TbFloorBo;
|
import org.dromara.property.domain.bo.TbFloorBo;
|
||||||
import org.dromara.property.domain.vo.TbBuildingVo;
|
import org.dromara.property.domain.vo.TbBuildingVo;
|
||||||
import org.dromara.property.domain.vo.TbCommunityVo;
|
import org.dromara.property.domain.vo.TbCommunityVo;
|
||||||
import org.dromara.property.domain.vo.TbFloorVo;
|
import org.dromara.property.domain.vo.TbFloorVo;
|
||||||
|
import org.dromara.property.rocketmq.domain.MeterResult;
|
||||||
import org.dromara.property.service.ITbBuildingService;
|
import org.dromara.property.service.ITbBuildingService;
|
||||||
import org.dromara.property.service.ITbCommunityService;
|
import org.dromara.property.service.ITbCommunityService;
|
||||||
import org.dromara.property.service.ITbFloorService;
|
import org.dromara.property.service.ITbFloorService;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.property.utils.MeterRecordUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo;
|
import org.dromara.property.domain.bo.smartDevicesBo.TbMeterInfoBo;
|
||||||
import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo;
|
import org.dromara.property.domain.vo.smartDevicesVo.TbMeterInfoVo;
|
||||||
@@ -29,6 +29,7 @@ import org.dromara.property.mapper.smartDevicesMapper.TbMeterInfoMapper;
|
|||||||
import org.dromara.property.service.smartDevicesService.ITbMeterInfoService;
|
import org.dromara.property.service.smartDevicesService.ITbMeterInfoService;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -51,6 +52,8 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
|
|||||||
private final ITbBuildingService buildingService;
|
private final ITbBuildingService buildingService;
|
||||||
private final ITbCommunityService communityService;
|
private final ITbCommunityService communityService;
|
||||||
|
|
||||||
|
private final MeterRecordUtil meterRecordUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询水电气
|
* 查询水电气
|
||||||
*
|
*
|
||||||
@@ -239,4 +242,34 @@ public class TbMeterInfoServiceImpl implements ITbMeterInfoService {
|
|||||||
}
|
}
|
||||||
return TreeUtils.build(treeList, 0L);
|
return TreeUtils.build(treeList, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取水/电/气表当前读数/状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TbMeterInfoVo> getMeterStatus(Long floorId) {
|
||||||
|
TbMeterInfoBo meterInfoBo = new TbMeterInfoBo();
|
||||||
|
meterInfoBo.setFloorId(floorId);
|
||||||
|
List<TbMeterInfoVo> meterInfoVoList = this.queryList(meterInfoBo);
|
||||||
|
if (meterInfoVoList.isEmpty()) return null;
|
||||||
|
|
||||||
|
String[] hostIpArr = meterInfoVoList.stream().map(TbMeterInfoVo::getHostIp).toArray(String[]::new);
|
||||||
|
Map<String, Long> ipCountMap = meterInfoVoList.stream().collect(Collectors.groupingBy(TbMeterInfoVo::getHostIp, Collectors.counting()));
|
||||||
|
List<MeterResult> meterResults = meterRecordUtil.getMeterStatus(ipCountMap, hostIpArr);
|
||||||
|
|
||||||
|
List<TbMeterInfoVo> resultList = new ArrayList<>();
|
||||||
|
for (MeterResult item : meterResults){
|
||||||
|
TbMeterInfoVo meterInfoVo = meterInfoVoList.stream().filter(o -> o.getHostIp().equals(item.getIp())).findFirst().orElse(null);
|
||||||
|
if (meterInfoVo == null) continue;
|
||||||
|
|
||||||
|
BigDecimal initReading = BigDecimal.valueOf(item.getCollectionValue().get(Integer.parseInt(meterInfoVo.getMeterCode())));
|
||||||
|
if (initReading.equals(BigDecimal.ZERO)){
|
||||||
|
meterInfoVo.setCommunicationState(0L);
|
||||||
|
}
|
||||||
|
meterInfoVo.setInitReading(initReading);
|
||||||
|
resultList.add(meterInfoVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -280,9 +280,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
|||||||
Map<String, Object> hourMap = new HashMap<>();
|
Map<String, Object> hourMap = new HashMap<>();
|
||||||
List<Map<String, Object>> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day);
|
List<Map<String, Object>> hourList = baseMapper.getHourTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, day);
|
||||||
List<String[]> hourData = new ArrayList<>();
|
List<String[]> hourData = new ArrayList<>();
|
||||||
hourList.forEach(item -> {
|
hourList.forEach(item -> hourData.add(new String[]{item.get("hour").toString(), item.get("total_consumption").toString()}));
|
||||||
hourData.add(new String[]{item.get("hour").toString(), item.get("total_consumption").toString()});
|
|
||||||
});
|
|
||||||
Float total = hourList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
Float total = hourList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||||
hourMap.put("total", total);
|
hourMap.put("total", total);
|
||||||
hourMap.put("data", hourData);
|
hourMap.put("data", hourData);
|
||||||
@@ -293,9 +291,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
|||||||
Map<String, Object> dayMap = new HashMap<>();
|
Map<String, Object> dayMap = new HashMap<>();
|
||||||
List<Map<String, Object>> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year, month);
|
List<Map<String, Object>> dayList = baseMapper.getDayTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year, month);
|
||||||
List<String[]> dayData = new ArrayList<>();
|
List<String[]> dayData = new ArrayList<>();
|
||||||
dayList.forEach(item -> {
|
dayList.forEach(item -> dayData.add(new String[]{item.get("day").toString(), item.get("total_consumption").toString()}));
|
||||||
dayData.add(new String[]{item.get("day").toString(), item.get("total_consumption").toString()});
|
|
||||||
});
|
|
||||||
Float total = dayList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
Float total = dayList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||||
dayMap.put("total", total);
|
dayMap.put("total", total);
|
||||||
dayMap.put("data", dayData);
|
dayMap.put("data", dayData);
|
||||||
@@ -306,9 +302,7 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
|||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
|
List<Map<String, Object>> monthList = baseMapper.getMonthTrend(StrUtil.isBlank(floorId) ? null : Long.parseLong(floorId), StrUtil.isBlank(meterId) ? null : Long.parseLong(meterId), meterType, year);
|
||||||
List<String[]> monthData = new ArrayList<>();
|
List<String[]> monthData = new ArrayList<>();
|
||||||
monthList.forEach(item -> {
|
monthList.forEach(item -> monthData.add(new String[]{item.get("month").toString(), item.get("total_consumption").toString()}));
|
||||||
monthData.add(new String[]{item.get("month").toString(), item.get("total_consumption").toString()});
|
|
||||||
});
|
|
||||||
Float total = monthList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
Float total = monthList.stream().map(map -> new BigDecimal(map.get("total_consumption").toString())).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).floatValue();
|
||||||
resultMap.put("total", total);
|
resultMap.put("total", total);
|
||||||
resultMap.put("data", monthData);
|
resultMap.put("data", monthData);
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
* 水电气Service接口
|
* 水电气Service接口
|
||||||
*
|
*
|
||||||
* @author lsm
|
* @author lsm
|
||||||
* @date 2025-07-19
|
* @since 2025-07-19
|
||||||
*/
|
*/
|
||||||
public interface ITbMeterInfoService {
|
public interface ITbMeterInfoService {
|
||||||
|
|
||||||
@@ -75,4 +75,9 @@ public interface ITbMeterInfoService {
|
|||||||
* @return 水电气树结构
|
* @return 水电气树结构
|
||||||
*/
|
*/
|
||||||
List<TreeNode<Long>> queryMeterInfoTree(Long meterType);
|
List<TreeNode<Long>> queryMeterInfoTree(Long meterType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取水/电/气表当前读数/状态
|
||||||
|
*/
|
||||||
|
List<TbMeterInfoVo> getMeterStatus(Long floorId);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,86 @@
|
|||||||
|
package org.dromara.property.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.property.rocketmq.domain.MeterResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote MeterRecordUtil
|
||||||
|
* @since 2025/8/30
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class MeterRecordUtil {
|
||||||
|
|
||||||
|
@Value("${eqp.config.meter.host}")
|
||||||
|
private String meterRecordUrl;
|
||||||
|
|
||||||
|
private static final String READING_URL = "reading";
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Result<T> {
|
||||||
|
private Integer code;
|
||||||
|
private T data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起请求并解析响应结果
|
||||||
|
*
|
||||||
|
* @param uri 请求路径
|
||||||
|
* @param params 请求参数
|
||||||
|
* @param <T> 泛型类型
|
||||||
|
* @return 解析后的数据对象
|
||||||
|
*/
|
||||||
|
public <T> T request(String uri, String params) {
|
||||||
|
// 参数校验
|
||||||
|
if (uri == null || uri.isEmpty()) {
|
||||||
|
log.warn("请求URI不能为空");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = meterRecordUrl + uri;
|
||||||
|
log.info("发起请求 - URL: {}, 参数: {}", url, params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 发起POST请求
|
||||||
|
String post = HttpUtil.post(url, params);
|
||||||
|
log.debug("接收到响应: {}", post);
|
||||||
|
|
||||||
|
// 解析JSON响应
|
||||||
|
Result<T> result = JSONUtil.toBean(post, new TypeReference<>() {
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// 判断响应是否成功
|
||||||
|
if (result != null && result.getCode() == 200) {
|
||||||
|
return result.getData();
|
||||||
|
} else {
|
||||||
|
log.warn("请求失败,状态码: {}", result != null ? result.getCode() : "未知");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("请求处理异常 - URL: {}, 参数: {}", url, params, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取水/电/气表当前读数
|
||||||
|
*/
|
||||||
|
public List<MeterResult> getMeterStatus(Map<String, Long> ipMap, String[] ipArr) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.putOnce("ipMap", ipMap);
|
||||||
|
jsonObject.putOnce("ipArr", ipArr);
|
||||||
|
return request(READING_URL, jsonObject.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user