【功能新增】IoT:设备模拟更新状态

This commit is contained in:
YunaiV 2025-01-29 15:13:41 +08:00
parent f5f8c418dc
commit 7fe4dd2368
2 changed files with 18 additions and 9 deletions

View File

@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStateUpdateReqDTO;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO;
@ -263,9 +263,13 @@ public class IotDeviceServiceImpl implements IotDeviceService {
}
@Override
@TenantIgnore
@Cacheable(value = RedisKeyConstants.DEVICE, key = "#productKey + '_' + #deviceName", unless = "#result == null")
public IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) {
// 保证在 @CacheEvict 之前忽略租户
return TenantUtils.executeIgnore(() -> getSelf().getDeviceByProductKeyAndDeviceNameFromCache0(productKey, deviceName));
}
@Cacheable(value = RedisKeyConstants.DEVICE, key = "#productKey + '_' + #deviceName", unless = "#result == null")
public IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache0(String productKey, String deviceName) {
return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName);
}
@ -386,6 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
return respVO;
}
// TODO @芋艿要不改成 simulationUpstream原因里面不只有上报还有更新状态那么 upstream 更适合
@Override
@SuppressWarnings("unchecked")
public void simulationReportDevice(IotDeviceSimulationReportReqVO reportReqVO) {
@ -408,9 +413,10 @@ public class IotDeviceServiceImpl implements IotDeviceService {
}
// 2.3 情况三状态变更
if (Objects.equals(reportReqVO.getType(), IotDeviceMessageTypeEnum.STATE.getType())) {
// TODO 芋艿待实现
// updateDeviceState(new IotDeviceStatusUpdateReqVO().setId(device.getId())
// .setStatus((Integer) reportReqVO.getData()));
deviceUpstreamService.updateDeviceState(((IotDeviceStateUpdateReqDTO)
new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()).setReportTime(LocalDateTime.now())
.setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName()))
.setState((Integer) reportReqVO.getData()));
return;
}
throw new IllegalArgumentException("未知的类型:" + reportReqVO.getType());

View File

@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent;
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelParam;
@ -136,9 +135,13 @@ public class IotThingModelServiceImpl implements IotThingModelService {
}
@Override
@TenantIgnore
@Cacheable(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey")
public List<IotThingModelDO> getThingModelListByProductKeyFromCache(String productKey) {
// 保证在 @CacheEvict 之前忽略租户
return TenantUtils.executeIgnore(() -> getSelf().getThingModelListByProductKeyFromCache0(productKey));
}
@Cacheable(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey")
public List<IotThingModelDO> getThingModelListByProductKeyFromCache0(String productKey) {
return thingModelMapper.selectListByProductKey(productKey);
}