com.zznote.basecommon.service.impl.TConfigServiceImpl Maven / Gradle / Ivy
The newest version!
package com.zznote.basecommon.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zznote.basecommon.common.constant.Constants;
import com.zznote.basecommon.common.util.cache.RedisUtils;
import com.zznote.basecommon.dao.TConfigDao;
import com.zznote.basecommon.entity.system.TConfig;
import com.zznote.basecommon.service.TConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
/**
* @Author: zhangzhen
* @Date: create in 2022/4/19 2:43 下午
*/
@Service("tConfigService")
public class TConfigServiceImpl extends ServiceImpl implements TConfigService {
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数key
* @return 参数键值
*/
@Override
public String selectConfigByKey(String configKey) {
String configValue = Convert.toStr(RedisUtils.getCacheObject(getCacheKey(configKey)));
if (StringUtils.isNotEmpty(configValue)) {
return configValue;
}
TConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper()
.eq(TConfig::getConfigKey, configKey));
if (ObjectUtil.isNotNull(retConfig)) {
RedisUtils.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
private String getCacheKey(String configKey) {
return Constants.SYS_CONFIG_KEY + configKey;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy