|
@@ -9,12 +9,14 @@ import api.common.util.ObjectUtil;
|
|
|
import com.css.simulation.resource.feign.RedisService;
|
|
|
import com.css.simulation.resource.system.mapper.DictMapper;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DictService {
|
|
|
|
|
@@ -27,11 +29,11 @@ public class DictService {
|
|
|
public String refreshDicts(DictParam param) throws JsonProcessingException {
|
|
|
String dictTypes = param.getDictTypes();
|
|
|
List<String> dictTypeList = Arrays.asList(dictTypes.split(","));
|
|
|
- if(dictTypeList.size() == 0){//防止参数为","
|
|
|
+ if (dictTypeList.size() == 0) {//防止参数为","
|
|
|
dictTypeList = new ArrayList<String>();
|
|
|
dictTypeList.add("xxx");
|
|
|
}
|
|
|
- if("all".equals(dictTypes)){//关键字all时刷新全部字典
|
|
|
+ if ("all".equals(dictTypes)) {//关键字all时刷新全部字典
|
|
|
dictTypeList = new ArrayList<String>();
|
|
|
}
|
|
|
//数据库取值
|
|
@@ -42,7 +44,7 @@ public class DictService {
|
|
|
List<RedisParameter> dictLists = new ArrayList<>();
|
|
|
List<RedisParameter> dictMaps = new ArrayList<>();
|
|
|
Set<String> keySet = DictVOMap.keySet();
|
|
|
- for (String key: keySet) {
|
|
|
+ for (String key : keySet) {
|
|
|
List<DictVO> dictVOS = DictVOMap.get(key);
|
|
|
//list 字典
|
|
|
String dictList = JsonUtil.listToJson(dictVOS);
|
|
@@ -53,10 +55,10 @@ public class DictService {
|
|
|
dictLists.add(listParameter);
|
|
|
//map 字典
|
|
|
Map<String, String> map = new HashMap();
|
|
|
- for (DictVO dictVO: dictVOS) {
|
|
|
+ for (DictVO dictVO : dictVOS) {
|
|
|
String code = dictVO.getDictCode();
|
|
|
String name = dictVO.getDictName();
|
|
|
- map.put(code,name);
|
|
|
+ map.put(code, name);
|
|
|
}
|
|
|
String dictMap = JsonUtil.beanToJson(map);
|
|
|
//放入列表
|
|
@@ -81,11 +83,11 @@ public class DictService {
|
|
|
Map<String, String> map = responseBodyVO.getInfo();
|
|
|
Map<String, List<DictVO>> dictLists = new HashMap<>();
|
|
|
Set<String> keySet = map.keySet();
|
|
|
- for (String key: keySet) {
|
|
|
+ for (String key : keySet) {
|
|
|
String val = map.get(key);
|
|
|
//json转javaBean
|
|
|
List<DictVO> DictVOS = JsonUtil.jsonToList(val, DictVO.class);
|
|
|
- dictLists.put(key,DictVOS);
|
|
|
+ dictLists.put(key, DictVOS);
|
|
|
}
|
|
|
return dictLists;
|
|
|
}
|
|
@@ -99,46 +101,47 @@ public class DictService {
|
|
|
Map<String, String> map = responseBodyVO.getInfo();
|
|
|
Map<String, List<DictVO>> dictTrees = new HashMap<>();
|
|
|
Set<String> keySet = map.keySet();
|
|
|
- for (String key: keySet) {
|
|
|
+ for (String key : keySet) {
|
|
|
String val = map.get(key);
|
|
|
//json转javaBean
|
|
|
List<DictVO> dictVOS = JsonUtil.jsonToList(val, DictVO.class);
|
|
|
//list转tree
|
|
|
List<DictVO> tree = ObjectUtil.DictListToTree(dictVOS);
|
|
|
- dictTrees.put(key,tree);
|
|
|
+ dictTrees.put(key, tree);
|
|
|
}
|
|
|
return dictTrees;
|
|
|
}
|
|
|
|
|
|
- public Map<String, Map<String,String>> getDictMapsByTypes(DictParam param) {
|
|
|
+ public Map<String, Map<String, String>> getDictMapsByTypes(DictParam param) {
|
|
|
+ log.info("DictService--getDictMapsByTypes 查询字典信息:" + param);
|
|
|
//解析参数进行查询
|
|
|
String dictTypes = param.getDictTypes();
|
|
|
List<String> dictTypeList = Arrays.asList(dictTypes.split(","));
|
|
|
ResponseBodyVO<Map<String, String>> responseBodyVO = redisService.getDictMaps(dictTypeList);
|
|
|
//查询结果转换至map对象
|
|
|
Map<String, String> map = responseBodyVO.getInfo();
|
|
|
- Map<String, Map<String,String>> dictMaps = new HashMap<>();
|
|
|
+ Map<String, Map<String, String>> dictMaps = new HashMap<>();
|
|
|
Set<String> keySet = map.keySet();
|
|
|
- for (String key: keySet) {
|
|
|
+ for (String key : keySet) {
|
|
|
String val = map.get(key);
|
|
|
//json转map
|
|
|
Map hashMap = JsonUtil.jsonToMap(val);
|
|
|
- dictMaps.put(key,hashMap);
|
|
|
+ dictMaps.put(key, hashMap);
|
|
|
}
|
|
|
return dictMaps;
|
|
|
}
|
|
|
|
|
|
- public Map<String, Map<String,String>> getDictMapsByTypes(String param) {
|
|
|
+ public Map<String, Map<String, String>> getDictMapsByTypes(String param) {
|
|
|
DictParam dictParam = new DictParam();
|
|
|
dictParam.setDictTypes(param);
|
|
|
return getDictMapsByTypes(dictParam);
|
|
|
}
|
|
|
|
|
|
- public Map<String, Map<String,String>> getDictMapsByTypes(String param,String ...arg) {
|
|
|
+ public Map<String, Map<String, String>> getDictMapsByTypes(String param, String... arg) {
|
|
|
StringBuffer sb = new StringBuffer(param);
|
|
|
- if(arg != null){
|
|
|
- for (String s: arg) {
|
|
|
- if(s != null && s != ""){
|
|
|
+ if (arg != null) {
|
|
|
+ for (String s : arg) {
|
|
|
+ if (s != null && s != "") {
|
|
|
sb.append(",").append(s);
|
|
|
}
|
|
|
}
|
|
@@ -148,12 +151,12 @@ public class DictService {
|
|
|
return getDictMapsByTypes(dictParam);
|
|
|
}
|
|
|
|
|
|
- public Map<String,String> getDictMapByType(String param) {
|
|
|
+ public Map<String, String> getDictMapByType(String param) {
|
|
|
DictParam dictParam = new DictParam();
|
|
|
dictParam.setDictTypes(param);
|
|
|
Map<String, Map<String, String>> dictMaps = getDictMapsByTypes(dictParam);
|
|
|
Map<String, String> dictMap = dictMaps.get(param);
|
|
|
- if(ObjectUtil.isNull(dictMap)){
|
|
|
+ if (ObjectUtil.isNull(dictMap)) {
|
|
|
new HashMap<>();
|
|
|
}
|
|
|
return dictMap;
|