通话逻辑
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 主要用于动态配置管理
|
||||
* <p>created on 2022/8/18 17:21</p>
|
||||
* @author ZL
|
||||
*/
|
||||
@Service
|
||||
public class SystemConfigManager {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 获取配置信息返回boolean
|
||||
* @param systemConfig
|
||||
* @return
|
||||
*/
|
||||
public boolean getSystemConfigOfBool(SystemConfigEnum systemConfig){
|
||||
String value = getSystemConfig(systemConfig);
|
||||
return "1".equals(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息返回Integer
|
||||
* @param systemConfig
|
||||
* @return
|
||||
*/
|
||||
public Integer getSystemConfigOfInt(SystemConfigEnum systemConfig){
|
||||
String value = getSystemConfig(systemConfig);
|
||||
return Integer.valueOf(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取配置信息返回Integer
|
||||
* @param systemConfig
|
||||
* @return
|
||||
*/
|
||||
public Long getSystemConfigOfLong(SystemConfigEnum systemConfig){
|
||||
String value = getSystemConfig(systemConfig);
|
||||
return Long.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
* @param systemConfig
|
||||
* @return
|
||||
*/
|
||||
public String getSystemConfig(SystemConfigEnum systemConfig){
|
||||
String value = (String) redisTemplate.opsForHash().get(RedisConstant.SYSTEM_CONFIG, systemConfig.name());
|
||||
if(StringUtils.isBlank(value)){
|
||||
return systemConfig.getDefaultValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getSystemConfigOfList(SystemConfigEnum systemConfig){
|
||||
String value = getSystemConfig(systemConfig);
|
||||
if(StringUtils.isBlank(value)){
|
||||
value = systemConfig.getDefaultValue();
|
||||
}
|
||||
return Stream.of(value.split(",")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有配置
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> getAllSystemConfig(){
|
||||
HashOperations<String, String, String> stringObjectObjectHashOperations = redisTemplate.opsForHash();
|
||||
return stringObjectObjectHashOperations.entries(RedisConstant.SYSTEM_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
public void setSystemConfig(SystemConfigEnum systemConfig,String value){
|
||||
redisTemplate.opsForHash().put(RedisConstant.SYSTEM_CONFIG, systemConfig.name(),value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user