Merge pull request '- 新增 EnergyConsumptionController,提供能耗数据接口' (#7) from master into prod
All checks were successful
Build and Push to Target Registry / 构建并推送镜像到目标仓库 (push) Successful in 12m53s
All checks were successful
Build and Push to Target Registry / 构建并推送镜像到目标仓库 (push) Successful in 12m53s
Reviewed-on: #7
This commit is contained in:
@@ -1,8 +1,16 @@
|
|||||||
package org.dromara.property.controller.cockpit;
|
package org.dromara.property.controller.cockpit;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.property.service.smartDevicesService.ITbMeterRecordService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 大屏能耗接口
|
* 大屏能耗接口
|
||||||
*/
|
*/
|
||||||
@@ -10,6 +18,25 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping("/cockpit")
|
@RequestMapping("/cockpit")
|
||||||
public class EnergyConsumptionController {
|
public class EnergyConsumptionController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ITbMeterRecordService tbMeterRecordService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取近一个月水、电能耗
|
||||||
|
*
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
@GetMapping("/energy/consumption")
|
||||||
|
public R<?> getEnergyConsumption() {
|
||||||
|
Date now = new Date();
|
||||||
|
String year = DateUtil.format(now, "yyyy");
|
||||||
|
String month = DateUtil.format(now, "yyyy-MM");
|
||||||
|
String day = DateUtil.format(now, "yyyy-MM-dd");
|
||||||
|
|
||||||
|
Map<String, Object> power = tbMeterRecordService.getEnergyTrend(null, null, 1L, day, month, year);
|
||||||
|
Map<String, Object> water = tbMeterRecordService.getEnergyTrend(null, null, 2L, day, month, year);
|
||||||
|
|
||||||
|
return R.ok(Map.of("power", power, "water", water));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
package org.dromara.property.controller.cockpit;
|
package org.dromara.property.controller.cockpit;
|
||||||
|
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
|
import org.dromara.property.rocketmq.RocketMqConstants;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -9,4 +13,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/cockpit")
|
@RequestMapping("/cockpit")
|
||||||
public class FlowController {
|
public class FlowController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当天24小时人行流量
|
||||||
|
*
|
||||||
|
* @return list
|
||||||
|
*/
|
||||||
|
@GetMapping("/personFlow/today")
|
||||||
|
public R<?> getPersonFlowToday() {
|
||||||
|
if (RedisUtils.isExistsObject(RocketMqConstants.PASS_RECORD)) {
|
||||||
|
return R.ok(RedisUtils.getCacheObject(RocketMqConstants.PASS_RECORD));
|
||||||
|
} else {
|
||||||
|
return R.fail("数据不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,15 @@ public interface RocketMqConstants {
|
|||||||
// 授权记录消费组
|
// 授权记录消费组
|
||||||
String AUTH_GROUP = "AUTH_GROUP";
|
String AUTH_GROUP = "AUTH_GROUP";
|
||||||
|
|
||||||
|
// 通行记录消费组
|
||||||
|
String PASS_GROUP = "PASS_GROUP";
|
||||||
|
|
||||||
/*-----------------------------------消息tag------------------------------------*/
|
/*-----------------------------------消息tag------------------------------------*/
|
||||||
// 仪表记录
|
// 仪表记录
|
||||||
String METER_RECORD = "METER_RECORD_TAG";
|
String METER_RECORD = "METER_RECORD_TAG";
|
||||||
// 授权记录
|
// 授权记录
|
||||||
String AUTH_RECORD = "AUTH_MESSAGE_REPORT";
|
String AUTH_RECORD = "AUTH_MESSAGE_REPORT";
|
||||||
|
// 通行记录
|
||||||
|
String PASS_RECORD = "PASS_RECORD_REPORT";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
package org.dromara.property.rocketmq.consumer;
|
||||||
|
|
||||||
|
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.common.redis.utils.RedisUtils;
|
||||||
|
import org.dromara.property.rocketmq.RocketMqConstants;
|
||||||
|
import org.dromara.property.rocketmq.domain.MeterResult;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lsm
|
||||||
|
* @apiNote PassRecordConsumer
|
||||||
|
* @since 2025/9/12
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RocketMQMessageListener(
|
||||||
|
topic = RocketMqConstants.TOPIC,
|
||||||
|
consumerGroup = RocketMqConstants.PASS_GROUP,
|
||||||
|
selectorExpression = RocketMqConstants.PASS_RECORD
|
||||||
|
)
|
||||||
|
public class PassRecordConsumer implements RocketMQListener<MessageExt> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(MessageExt ext) {
|
||||||
|
log.info("消费通行记录上报数据,数据长度={}", ext.getBody().length);
|
||||||
|
try {
|
||||||
|
List<Object[]> result = JSONUtil.toList(new String(ext.getBody()), Object[].class);
|
||||||
|
RedisUtils.setCacheObject(RocketMqConstants.PASS_RECORD, result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("消费仪表上报数据处理失败,", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -209,19 +209,20 @@ public class TbMeterRecordServiceImpl implements ITbMeterRecordService {
|
|||||||
record.setCurrentReading(BigDecimal.ZERO);
|
record.setCurrentReading(BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置上次读数
|
/// 设置上次读数
|
||||||
|
BigDecimal previousReading;
|
||||||
if (hasOldRecords) {
|
if (hasOldRecords) {
|
||||||
TbMeterRecord oldRecord = oldRecordMap.get(info.getId());
|
TbMeterRecord oldRecord = oldRecordMap.get(info.getId());
|
||||||
// 如果没有找到对应的旧记录,使用默认值
|
previousReading = (oldRecord != null) ? oldRecord.getCurrentReading() : record.getCurrentReading();
|
||||||
record.setPreviousReading(Objects.requireNonNullElse(oldRecord, record).getCurrentReading());
|
|
||||||
} else {
|
} else {
|
||||||
record.setPreviousReading(record.getCurrentReading());
|
previousReading = record.getCurrentReading();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果上次抄表记录为0,则设置为当前读数
|
// 如果上次读数为0,则使用当前读数(避免因采集器离线导致的异常)
|
||||||
if (record.getPreviousReading().compareTo(BigDecimal.ZERO) == 0) {
|
if (previousReading.compareTo(BigDecimal.ZERO) == 0) {
|
||||||
record.setPreviousReading(record.getCurrentReading());
|
previousReading = record.getCurrentReading();
|
||||||
}
|
}
|
||||||
|
record.setPreviousReading(previousReading);
|
||||||
|
|
||||||
// 通信状态改为离线
|
// 通信状态改为离线
|
||||||
TbMeterInfoBo bo = new TbMeterInfoBo();
|
TbMeterInfoBo bo = new TbMeterInfoBo();
|
||||||
|
Reference in New Issue
Block a user