系统配置-增加判断configStatus
This commit is contained in:
@@ -2,18 +2,12 @@ package com.accompany.core.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.BlankUtil;
|
||||
import com.accompany.core.config.SysConfNacosConfig;
|
||||
import com.accompany.core.dto.SysConfDto;
|
||||
import com.accompany.core.model.SysConf;
|
||||
import com.accompany.core.service.base.BaseService;
|
||||
import com.accompany.core.vo.SplashVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -24,26 +18,10 @@ import java.util.Optional;
|
||||
* Created by liuguofu on 2017/7/12.
|
||||
*/
|
||||
@Service
|
||||
public class SysConfService extends BaseService implements InitializingBean {
|
||||
public class SysConfService extends BaseService {
|
||||
@Autowired
|
||||
private SysConfNacosConfig sysConfNacosConfig;
|
||||
|
||||
/**
|
||||
* 获取闪屏的配置信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SplashVo getSplashConf() {
|
||||
SplashVo splashVo = new SplashVo();
|
||||
splashVo.setPict(getSysConfValueById(Constant.SysConfId.splash_pict));
|
||||
splashVo.setLink(getSysConfValueById(Constant.SysConfId.splash_link));
|
||||
String splashType = getSysConfValueById(Constant.SysConfId.splash_type);
|
||||
if (!BlankUtil.isBlank(splashType)) {
|
||||
splashVo.setType(Integer.valueOf(splashType));
|
||||
}
|
||||
return splashVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取sys_conf对象
|
||||
*
|
||||
@@ -51,7 +29,8 @@ public class SysConfService extends BaseService implements InitializingBean {
|
||||
* @return
|
||||
*/
|
||||
public SysConf getSysConfById(String configId) {
|
||||
Optional<SysConf> foundConfOptional = sysConfNacosConfig.getData().stream().filter(conf -> conf.getConfigId().equals(configId)).findFirst();
|
||||
Optional<SysConf> foundConfOptional = sysConfNacosConfig.getData().stream()
|
||||
.filter(conf -> conf.getConfigId().equals(configId) && !Constant.status.delete.equals(conf.getConfigStatus())).findFirst();
|
||||
return foundConfOptional.orElse(null);
|
||||
}
|
||||
|
||||
@@ -63,7 +42,7 @@ public class SysConfService extends BaseService implements InitializingBean {
|
||||
*/
|
||||
public String getSysConfValueById(String configId) {
|
||||
SysConf sysConf = getSysConfById(configId);
|
||||
return sysConf == null ? "" : sysConf.getConfigValue();
|
||||
return sysConf == null? "" : sysConf.getConfigValue();
|
||||
}
|
||||
|
||||
public int getIntValueById(String configId) {
|
||||
@@ -113,26 +92,6 @@ public class SysConfService extends BaseService implements InitializingBean {
|
||||
return sysConfNacosConfig.getData();
|
||||
}
|
||||
|
||||
|
||||
public boolean getConfigValueCacheBoolean(String key) {
|
||||
return getConfigValueOptional(key)
|
||||
.map(cv -> Boolean.parseBoolean(cv.trim()))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private Optional<String> getConfigValueOptional(String key) {
|
||||
String sysConfStr = getSysConfCache(key);
|
||||
return Optional.ofNullable(sysConfStr)
|
||||
.filter(s -> !s.trim().isEmpty())
|
||||
.map(s -> new Gson().fromJson(s, SysConfDto.class))
|
||||
.filter(sc -> Constant.status.valid.equals(sc.getConfigStatus()))
|
||||
.map(SysConfDto::getConfigValue);
|
||||
}
|
||||
|
||||
private String getSysConfCache(String key) {
|
||||
return jedisService.hget(RedisKey.sys_conf.getKey(), key);
|
||||
}
|
||||
|
||||
public <T> T getJsonValueById(String configId, Class<T> clazz) {
|
||||
SysConf sysConf = getSysConfById(configId);
|
||||
if (sysConf == null || StringUtils.isBlank(sysConf.getConfigValue())) {
|
||||
@@ -163,9 +122,4 @@ public class SysConfService extends BaseService implements InitializingBean {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
org.springframework.util.Assert.notEmpty(getRealTimeSysConfs(), "sys_conf is required");
|
||||
}
|
||||
}
|
||||
|
@@ -613,9 +613,6 @@ public class Constant {
|
||||
public static class SysConfId {
|
||||
public static final String auditing_version = "auditing_version";
|
||||
public static final String face_version = "face_version";
|
||||
public static final String splash_pict = "splash_pict"; // 闪屏图片
|
||||
public static final String splash_link = "splash_link"; // 闪屏链接
|
||||
public static final String splash_type = "splash_type"; // 跳转类型
|
||||
public static final String newest_version = "newest_version"; //当前最新版本
|
||||
public static final String dynamic_publish_switch = "dynamic_publish_switch"; // 动态发布开关
|
||||
public static final String comment_publish_switch = "comment_publish_switch"; // 动态评论发布开关
|
||||
|
@@ -37,7 +37,7 @@ public enum RedisKey {
|
||||
gift, // 礼物
|
||||
gift_magic_list, // 魔法礼物
|
||||
gift_magic_item, // 魔法礼物
|
||||
sys_conf,
|
||||
|
||||
banner,
|
||||
panel,
|
||||
audit_panel,
|
||||
|
Reference in New Issue
Block a user