mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
系统配置增加缓存
This commit is contained in:
@@ -22,6 +22,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -65,6 +68,11 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
CacheManager cacheManager;
|
||||
@Autowired ApplicationContext applicationContext;
|
||||
|
||||
@Cacheable(cacheNames = Constants.CACHE_SYSCONFIG, key = "#configKey")
|
||||
public String getConfigVal(String configKey) {
|
||||
|
||||
SysConfigEntity config = this.repository.findByCode(configKey);
|
||||
@@ -72,8 +80,12 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
|
||||
return config.getConfigVal();
|
||||
}
|
||||
|
||||
public void clearCache(){
|
||||
cacheManager.getCache(Constants.CACHE_SYSCONFIG).clear();
|
||||
}
|
||||
|
||||
public boolean isEnable(String configKey) {
|
||||
return StringUtils.equalsIgnoreCase(getConfigVal(configKey), "1");
|
||||
return StringUtils.equalsIgnoreCase(applicationContext.getBean(this.getClass()).getConfigVal(configKey), "1");
|
||||
}
|
||||
|
||||
public void saveAllConfig(SaveAllConfigDto dto) {
|
||||
@@ -98,6 +110,8 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
|
||||
});
|
||||
|
||||
this.repository.saveAll(joins.stream().map(x -> x._1).collect(Collectors.toList()));
|
||||
|
||||
this.clearCache();
|
||||
}
|
||||
|
||||
public SysConfigDto create(CreateSysConfigDto request) {
|
||||
@@ -105,6 +119,7 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
|
||||
SysConfigEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
this.clearCache();
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@@ -114,6 +129,8 @@ public class SysConfigService extends BaseService<SysConfigEntity, SysConfigRepo
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
this.clearCache();
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user