com.ape9527.core.service.DictService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ape-core Show documentation
Show all versions of ape-core Show documentation
Ape low code platform core module
The newest version!
package com.ape9527.core.service;
import com.ape9527.core.constant.Const;
import com.ape9527.core.service.BaseDataService;
import com.ape9527.utils.string.StringUtil;
import com.ape9527.core.entity.SysDictDetail;
import com.ape9527.core.model.base.BaseQueryVo;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
/**
* @author YuanShuai[[email protected]]
*/
@Service
public class DictService {
private final BaseDataService baseDataService;
private final RedisTemplate redisTemplate;
public DictService(BaseDataService baseDataService, RedisTemplate redisTemplate) {
this.baseDataService = baseDataService;
this.redisTemplate = redisTemplate;
}
/**
* 获取字典键值
* @param dictCode 字典编码
* @param dictLabel 字典标签
* @return
*/
public String queryValue(String dictCode, String dictLabel) {
String redisKey = Const.DICT_PREFIX + dictCode;
String value = (String) redisTemplate.opsForHash().get(redisKey, dictLabel);
if(StringUtil.isEmpty(value)){
BaseQueryVo queryVo = new BaseQueryVo("sys_dict_detail");
queryVo.eq("dict_name", dictCode);
queryVo.eq("dict_label", dictLabel);
SysDictDetail sysDictDetail = baseDataService.queryOne(queryVo, SysDictDetail.class);
value = sysDictDetail.getDictValue();
addCache(dictCode, dictLabel, value);
}
return value;
}
@Async
public void addCache(String dictCode, String dictLabel, String dictValue){
String redisKey = Const.DICT_PREFIX + dictCode;
redisTemplate.opsForHash().put(redisKey, dictLabel, dictValue);
}
}