refactor(iot,ops): 重构客流计数器重置为按区域删除阈值 key
- ResetTrafficCounterReqDTO: 废弃 newBaseValue 字段 - IotDeviceControlApiImpl: 重置逻辑改为通过区域关联查询后删除阈值 key - CleanOrderEventListener: 简化异步重置调用,移除 triggerData 依赖 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,8 @@ import com.viewsh.module.iot.core.enums.IotDeviceMessageMethodEnum;
|
||||
import com.viewsh.module.iot.core.enums.IotDeviceStateEnum;
|
||||
import com.viewsh.module.iot.core.mq.message.IotDeviceMessage;
|
||||
import com.viewsh.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
import com.viewsh.module.iot.dal.redis.clean.TrafficCounterBaseRedisDAO;
|
||||
import com.viewsh.module.iot.dal.redis.clean.TrafficCounterRedisDAO;
|
||||
import com.viewsh.module.iot.service.integration.clean.CleanOrderIntegrationConfigService;
|
||||
import com.viewsh.module.iot.service.device.IotDeviceService;
|
||||
import com.viewsh.module.iot.service.device.message.IotDeviceMessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -48,7 +49,10 @@ public class IotDeviceControlApiImpl implements IotDeviceControlApi {
|
||||
private IotDeviceMessageService deviceMessageService;
|
||||
|
||||
@Resource
|
||||
private TrafficCounterBaseRedisDAO trafficCounterBaseRedisDAO;
|
||||
private TrafficCounterRedisDAO trafficCounterRedisDAO;
|
||||
|
||||
@Resource
|
||||
private CleanOrderIntegrationConfigService configService;
|
||||
|
||||
@Override
|
||||
@PostMapping(PREFIX + "/invoke-service")
|
||||
@@ -130,29 +134,36 @@ public class IotDeviceControlApiImpl implements IotDeviceControlApi {
|
||||
public CommonResult<Boolean> resetTrafficCounter(@RequestBody ResetTrafficCounterReqDTO reqDTO) {
|
||||
try {
|
||||
Long deviceId = reqDTO.getDeviceId();
|
||||
Long newBaseValue = reqDTO.getNewBaseValue();
|
||||
|
||||
log.info("[resetTrafficCounter] 重置客流计数器: deviceId={}, newBaseValue={}, orderId={}, remark={}",
|
||||
deviceId, newBaseValue, reqDTO.getOrderId(), reqDTO.getRemark());
|
||||
log.info("[resetTrafficCounter] 重置客流计数器:deviceId={}, orderId={}, remark={}",
|
||||
deviceId, reqDTO.getOrderId(), reqDTO.getRemark());
|
||||
|
||||
// 1. 验证设备存在
|
||||
IotDeviceDO device = deviceService.getDeviceFromCache(deviceId);
|
||||
if (device == null) {
|
||||
log.warn("[resetTrafficCounter] 设备不存在: deviceId={}", deviceId);
|
||||
log.warn("[resetTrafficCounter] 设备不存在:deviceId={}", deviceId);
|
||||
return success(false);
|
||||
}
|
||||
|
||||
// 2. 重置基准值
|
||||
trafficCounterBaseRedisDAO.setBaseValue(deviceId, newBaseValue);
|
||||
// 2. 获取区域ID
|
||||
CleanOrderIntegrationConfigService.AreaDeviceConfigWrapper wrapper =
|
||||
configService.getConfigWrapperByDeviceId(deviceId);
|
||||
if (wrapper == null) {
|
||||
log.warn("[resetTrafficCounter] 设备无区域关联:deviceId={}", deviceId);
|
||||
return success(false);
|
||||
}
|
||||
|
||||
log.info("[resetTrafficCounter] 客流计数器重置成功: deviceId={}, newBaseValue={}",
|
||||
deviceId, newBaseValue);
|
||||
// 3. 重置阈值计数器(删除 key)
|
||||
trafficCounterRedisDAO.resetThreshold(deviceId, wrapper.getAreaId());
|
||||
|
||||
log.info("[resetTrafficCounter] 客流计数器重置成功:deviceId={}, areaId={}",
|
||||
deviceId, wrapper.getAreaId());
|
||||
|
||||
return success(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("[resetTrafficCounter] 重置客流计数器失败: deviceId={}, newBaseValue={}",
|
||||
reqDTO.getDeviceId(), reqDTO.getNewBaseValue(), e);
|
||||
log.error("[resetTrafficCounter] 重置客流计数器失败:deviceId={}",
|
||||
reqDTO.getDeviceId(), e);
|
||||
return success(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user