Эх сурвалжийг харах

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

YunaiV 6 сар өмнө
parent
commit
7fe4dd2368

+ 12 - 6
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;
 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());

+ 6 - 3
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;
 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);
     }