fix:修复产品缓存bug

V0.5.x
xiwa 2024-03-09 20:23:08 +08:00
parent 49aec5df04
commit d4d6f6a7c5
4 changed files with 12 additions and 3 deletions

View File

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

View File

@ -29,13 +29,13 @@ public class ProductDataCache implements IProductData {
} }
@Override @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) { public Product findByProductKey(String productKey) {
return productData.findByProductKey(productKey); return productData.findByProductKey(productKey);
} }
@Override @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) { public void delByProductKey(String productKey) {
} }
@ -72,6 +72,7 @@ public class ProductDataCache implements IProductData {
Product p = productData.save(data); Product p = productData.save(data);
//清除缓存 //清除缓存
productCacheEvict.findById(p.getId()); productCacheEvict.findById(p.getId());
productCacheEvict.findByProductKey(p.getProductKey());
return p; return p;
} }

View File

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

View File

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