|
|
@ -1,10 +1,21 @@
|
|
|
|
package com.ruoyi.common.dict.service.impl;
|
|
|
|
package com.ruoyi.common.dict.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.context.SaHolder;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollStreamUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.constant.CacheConstants;
|
|
|
|
import com.ruoyi.common.core.service.DictService;
|
|
|
|
import com.ruoyi.common.core.service.DictService;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
|
import com.ruoyi.system.api.RemoteDictService;
|
|
|
|
import com.ruoyi.system.api.RemoteDictService;
|
|
|
|
|
|
|
|
import com.ruoyi.system.api.domain.SysDictData;
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 字典服务服务
|
|
|
|
* 字典服务服务
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -24,9 +35,24 @@ public class DictServiceImpl implements DictService {
|
|
|
|
* @param separator 分隔符
|
|
|
|
* @param separator 分隔符
|
|
|
|
* @return 字典标签
|
|
|
|
* @return 字典标签
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked cast")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getDictLabel(String dictType, String dictValue, String separator) {
|
|
|
|
public String getDictLabel(String dictType, String dictValue, String separator) {
|
|
|
|
return remoteDictService.getDictLabel(dictType, dictValue, separator);
|
|
|
|
// 优先从本地缓存获取
|
|
|
|
|
|
|
|
List<SysDictData> datas = (List<SysDictData>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType);
|
|
|
|
|
|
|
|
if (ObjectUtil.isNull(datas)) {
|
|
|
|
|
|
|
|
datas = remoteDictService.selectDictDataByType(dictType);
|
|
|
|
|
|
|
|
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = CollStreamUtil.toMap(datas, SysDictData::getDictValue, SysDictData::getDictLabel);
|
|
|
|
|
|
|
|
if (StringUtils.containsAny(dictValue, separator)) {
|
|
|
|
|
|
|
|
return Arrays.stream(dictValue.split(separator))
|
|
|
|
|
|
|
|
.map(v -> map.getOrDefault(v, StringUtils.EMPTY))
|
|
|
|
|
|
|
|
.collect(Collectors.joining(separator));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return map.getOrDefault(dictValue, StringUtils.EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -37,9 +63,24 @@ public class DictServiceImpl implements DictService {
|
|
|
|
* @param separator 分隔符
|
|
|
|
* @param separator 分隔符
|
|
|
|
* @return 字典值
|
|
|
|
* @return 字典值
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked cast")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getDictValue(String dictType, String dictLabel, String separator) {
|
|
|
|
public String getDictValue(String dictType, String dictLabel, String separator) {
|
|
|
|
return remoteDictService.getDictValue(dictType, dictLabel, separator);
|
|
|
|
// 优先从本地缓存获取
|
|
|
|
|
|
|
|
List<SysDictData> datas = (List<SysDictData>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType);
|
|
|
|
|
|
|
|
if (ObjectUtil.isNull(datas)) {
|
|
|
|
|
|
|
|
datas = remoteDictService.selectDictDataByType(dictType);
|
|
|
|
|
|
|
|
SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> map = CollStreamUtil.toMap(datas, SysDictData::getDictLabel, SysDictData::getDictValue);
|
|
|
|
|
|
|
|
if (StringUtils.containsAny(dictLabel, separator)) {
|
|
|
|
|
|
|
|
return Arrays.stream(dictLabel.split(separator))
|
|
|
|
|
|
|
|
.map(l -> map.getOrDefault(l, StringUtils.EMPTY))
|
|
|
|
|
|
|
|
.collect(Collectors.joining(separator));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return map.getOrDefault(dictLabel, StringUtils.EMPTY);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|