Ver código fonte

fix:修复产品缓存bug

xiwa 1 ano atrás
pai
commit
d4d6f6a7c5

+ 4 - 0
iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java

@@ -11,4 +11,8 @@ public class ProductCacheEvict {
     public void findById(Long id) {
     }
 
+    @CacheEvict(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey")
+    public void findByProductKey(String productKey) {
+    }
+
 }

+ 3 - 2
iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java

@@ -29,13 +29,13 @@ public class ProductDataCache implements IProductData {
     }
 
     @Override
-    @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.targetClass+#productKey", unless = "#result == null")
+    @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey", unless = "#result == null")
     public Product findByProductKey(String productKey) {
         return productData.findByProductKey(productKey);
     }
 
     @Override
-    @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.targetClass+#productKey", unless = "#result == null")
+    @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey", unless = "#result == null")
     public void delByProductKey(String productKey) {
 
     }
@@ -72,6 +72,7 @@ public class ProductDataCache implements IProductData {
         Product p = productData.save(data);
         //清除缓存
         productCacheEvict.findById(p.getId());
+        productCacheEvict.findByProductKey(p.getProductKey());
         return p;
     }
 

+ 2 - 1
iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/UserIDAuditorConfig.java

@@ -14,6 +14,7 @@ import java.util.Optional;
 public class UserIDAuditorConfig implements AuditorAware<Long> {
     @Override
     public Optional<Long> getCurrentAuditor() {
-        return Optional.of(LoginHelper.getUserId()==null?1l:LoginHelper.getUserId());
+        Long userId = LoginHelper.getUserId();
+        return Optional.of(userId == null ? 1 : userId);
     }
 }

+ 3 - 0
iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginMainImpl.java

@@ -89,6 +89,9 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
         if (product.isTransparent()) {
             //如果是透传设备,取父级设备进行链路查找
             DeviceInfo parent = deviceInfoData.findByDeviceId(deviceInfo.getParentId());
+            if(parent==null){
+                throw new BizException(ErrCode.DEVICE_NOT_FOUND,"未找到父级设备");
+            }
             linkPk = parent.getProductKey();
             linkDn = parent.getDeviceName();
         }