通话逻辑

This commit is contained in:
张良(004796)
2023-12-28 11:42:27 +08:00
parent c5e55374c9
commit f337f57df5
22 changed files with 643 additions and 9 deletions

View File

@@ -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);
}
}