|
@@ -1,7 +1,9 @@
|
|
|
package com.ruoyi.common.utils;
|
|
package com.ruoyi.common.utils;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
@@ -89,37 +91,25 @@ public class DictUtils
|
|
|
*/
|
|
*/
|
|
|
public static String getDictLabel(String dictType, String dictValue, String separator)
|
|
public static String getDictLabel(String dictType, String dictValue, String separator)
|
|
|
{
|
|
{
|
|
|
- StringBuilder propertyString = new StringBuilder();
|
|
|
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
|
- if (StringUtils.isNull(datas))
|
|
|
|
|
|
|
+ if (StringUtils.isNull(datas) || StringUtils.isEmpty(dictValue))
|
|
|
{
|
|
{
|
|
|
return StringUtils.EMPTY;
|
|
return StringUtils.EMPTY;
|
|
|
}
|
|
}
|
|
|
- if (StringUtils.containsAny(separator, dictValue))
|
|
|
|
|
|
|
+ Map<String, String> dictMap = datas.stream().collect(HashMap::new, (map, dict) -> map.put(dict.getDictValue(), dict.getDictLabel()), Map::putAll);
|
|
|
|
|
+ if (!StringUtils.contains(dictValue, separator))
|
|
|
{
|
|
{
|
|
|
- for (SysDictData dict : datas)
|
|
|
|
|
- {
|
|
|
|
|
- for (String value : dictValue.split(separator))
|
|
|
|
|
- {
|
|
|
|
|
- if (value.equals(dict.getDictValue()))
|
|
|
|
|
- {
|
|
|
|
|
- propertyString.append(dict.getDictLabel()).append(separator);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return dictMap.getOrDefault(dictValue, StringUtils.EMPTY);
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+ StringBuilder labelBuilder = new StringBuilder();
|
|
|
|
|
+ for (String seperatedValue : dictValue.split(separator))
|
|
|
{
|
|
{
|
|
|
- for (SysDictData dict : datas)
|
|
|
|
|
|
|
+ if (dictMap.containsKey(seperatedValue))
|
|
|
{
|
|
{
|
|
|
- if (dictValue.equals(dict.getDictValue()))
|
|
|
|
|
- {
|
|
|
|
|
- return dict.getDictLabel();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ labelBuilder.append(dictMap.get(seperatedValue)).append(separator);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
|
|
|
+ return StringUtils.removeEnd(labelBuilder.toString(), separator);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -132,37 +122,25 @@ public class DictUtils
|
|
|
*/
|
|
*/
|
|
|
public static String getDictValue(String dictType, String dictLabel, String separator)
|
|
public static String getDictValue(String dictType, String dictLabel, String separator)
|
|
|
{
|
|
{
|
|
|
- StringBuilder propertyString = new StringBuilder();
|
|
|
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
|
- if (StringUtils.isNull(datas))
|
|
|
|
|
|
|
+ if (StringUtils.isNull(datas) || StringUtils.isEmpty(dictLabel))
|
|
|
{
|
|
{
|
|
|
return StringUtils.EMPTY;
|
|
return StringUtils.EMPTY;
|
|
|
}
|
|
}
|
|
|
- if (StringUtils.containsAny(separator, dictLabel))
|
|
|
|
|
|
|
+ Map<String, String> dictMap = datas.stream().collect(HashMap::new, (map, dict) -> map.put(dict.getDictLabel(), dict.getDictValue()), Map::putAll);
|
|
|
|
|
+ if (!StringUtils.contains(dictLabel, separator))
|
|
|
{
|
|
{
|
|
|
- for (SysDictData dict : datas)
|
|
|
|
|
- {
|
|
|
|
|
- for (String label : dictLabel.split(separator))
|
|
|
|
|
- {
|
|
|
|
|
- if (label.equals(dict.getDictLabel()))
|
|
|
|
|
- {
|
|
|
|
|
- propertyString.append(dict.getDictValue()).append(separator);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return dictMap.getOrDefault(dictLabel, StringUtils.EMPTY);
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+ StringBuilder valueBuilder = new StringBuilder();
|
|
|
|
|
+ for (String seperatedValue : dictLabel.split(separator))
|
|
|
{
|
|
{
|
|
|
- for (SysDictData dict : datas)
|
|
|
|
|
|
|
+ if (dictMap.containsKey(seperatedValue))
|
|
|
{
|
|
{
|
|
|
- if (dictLabel.equals(dict.getDictLabel()))
|
|
|
|
|
- {
|
|
|
|
|
- return dict.getDictValue();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ valueBuilder.append(dictMap.get(seperatedValue)).append(separator);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
|
|
|
+ return StringUtils.removeEnd(valueBuilder.toString(), separator);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|