Commit 7fe4dd2368f8fb45ce3e5b206e1a80e11ff03887
1 parent
f5f8c418
【功能新增】IoT:设备模拟更新状态
Showing
2 changed files
with
18 additions
and
9 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; |
| 12 | -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; | |
| 13 | 12 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 14 | 13 | import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 14 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStateUpdateReqDTO; | |
| 15 | 15 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; |
| 16 | 16 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 17 | 17 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; |
| ... | ... | @@ -263,9 +263,13 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | @Override |
| 266 | - @TenantIgnore | |
| 267 | - @Cacheable(value = RedisKeyConstants.DEVICE, key = "#productKey + '_' + #deviceName", unless = "#result == null") | |
| 268 | 266 | public IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) { |
| 267 | + // 保证在 @CacheEvict 之前,忽略租户 | |
| 268 | + return TenantUtils.executeIgnore(() -> getSelf().getDeviceByProductKeyAndDeviceNameFromCache0(productKey, deviceName)); | |
| 269 | + } | |
| 270 | + | |
| 271 | + @Cacheable(value = RedisKeyConstants.DEVICE, key = "#productKey + '_' + #deviceName", unless = "#result == null") | |
| 272 | + public IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache0(String productKey, String deviceName) { | |
| 269 | 273 | return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName); |
| 270 | 274 | } |
| 271 | 275 | |
| ... | ... | @@ -386,6 +390,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 386 | 390 | return respVO; |
| 387 | 391 | } |
| 388 | 392 | |
| 393 | + // TODO @芋艿:要不改成 simulationUpstream,原因:里面不只有上报,还有更新状态,那么 upstream 更适合 | |
| 389 | 394 | @Override |
| 390 | 395 | @SuppressWarnings("unchecked") |
| 391 | 396 | public void simulationReportDevice(IotDeviceSimulationReportReqVO reportReqVO) { |
| ... | ... | @@ -408,9 +413,10 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 408 | 413 | } |
| 409 | 414 | // 2.3 情况三:状态变更 |
| 410 | 415 | if (Objects.equals(reportReqVO.getType(), IotDeviceMessageTypeEnum.STATE.getType())) { |
| 411 | - // TODO 芋艿:待实现 | |
| 412 | -// updateDeviceState(new IotDeviceStatusUpdateReqVO().setId(device.getId()) | |
| 413 | -// .setStatus((Integer) reportReqVO.getData())); | |
| 416 | + deviceUpstreamService.updateDeviceState(((IotDeviceStateUpdateReqDTO) | |
| 417 | + new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()).setReportTime(LocalDateTime.now()) | |
| 418 | + .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) | |
| 419 | + .setState((Integer) reportReqVO.getData())); | |
| 414 | 420 | return; |
| 415 | 421 | } |
| 416 | 422 | throw new IllegalArgumentException("未知的类型:" + reportReqVO.getType()); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
| ... | ... | @@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil; |
| 6 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; | |
| 10 | 9 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 11 | 10 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; |
| 12 | 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelParam; |
| ... | ... | @@ -136,9 +135,13 @@ public class IotThingModelServiceImpl implements IotThingModelService { |
| 136 | 135 | } |
| 137 | 136 | |
| 138 | 137 | @Override |
| 139 | - @TenantIgnore | |
| 140 | - @Cacheable(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey") | |
| 141 | 138 | public List<IotThingModelDO> getThingModelListByProductKeyFromCache(String productKey) { |
| 139 | + // 保证在 @CacheEvict 之前,忽略租户 | |
| 140 | + return TenantUtils.executeIgnore(() -> getSelf().getThingModelListByProductKeyFromCache0(productKey)); | |
| 141 | + } | |
| 142 | + | |
| 143 | + @Cacheable(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey") | |
| 144 | + public List<IotThingModelDO> getThingModelListByProductKeyFromCache0(String productKey) { | |
| 142 | 145 | return thingModelMapper.selectListByProductKey(productKey); |
| 143 | 146 | } |
| 144 | 147 | ... | ... |