|
|
|
@ -15,6 +15,11 @@ import com.ruoyi.system.domain.SysDictData;
|
|
|
|
|
@Component
|
|
|
|
|
public class DictUtils
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 分隔符
|
|
|
|
|
*/
|
|
|
|
|
public static final String SEPARATOR = ",";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置字典缓存
|
|
|
|
|
*
|
|
|
|
@ -52,10 +57,49 @@ public class DictUtils
|
|
|
|
|
*/
|
|
|
|
|
public static String getDictLabel(String dictType, String dictValue)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictValue))
|
|
|
|
|
return getDictLabel(dictType, dictValue, SEPARATOR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据字典类型和字典标签获取字典值
|
|
|
|
|
*
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
* @param dictLabel 字典标签
|
|
|
|
|
* @return 字典值
|
|
|
|
|
*/
|
|
|
|
|
public static String getDictValue(String dictType, String dictLabel)
|
|
|
|
|
{
|
|
|
|
|
return getDictValue(dictType, dictLabel, SEPARATOR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据字典类型和字典值获取字典标签
|
|
|
|
|
*
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
* @param dictValue 字典值
|
|
|
|
|
* @param separator 分隔符
|
|
|
|
|
* @return 字典标签
|
|
|
|
|
*/
|
|
|
|
|
public static String getDictLabel(String dictType, String dictValue, String separator)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder propertyString = new StringBuilder();
|
|
|
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
|
|
|
if (StringUtils.isNotEmpty(datas))
|
|
|
|
|
|
|
|
|
|
if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
|
|
|
|
|
{
|
|
|
|
|
for (SysDictData dict : datas)
|
|
|
|
|
{
|
|
|
|
|
for (String value : dictValue.split(separator))
|
|
|
|
|
{
|
|
|
|
|
if (value.equals(dict.getDictValue()))
|
|
|
|
|
{
|
|
|
|
|
propertyString.append(dict.getDictLabel() + separator);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (SysDictData dict : datas)
|
|
|
|
|
{
|
|
|
|
@ -65,8 +109,7 @@ public class DictUtils
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dictValue;
|
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -74,14 +117,29 @@ public class DictUtils
|
|
|
|
|
*
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
* @param dictLabel 字典标签
|
|
|
|
|
* @param separator 分隔符
|
|
|
|
|
* @return 字典值
|
|
|
|
|
*/
|
|
|
|
|
public static String getDictValue(String dictType, String dictLabel)
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictLabel))
|
|
|
|
|
public static String getDictValue(String dictType, String dictLabel, String separator)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder propertyString = new StringBuilder();
|
|
|
|
|
List<SysDictData> datas = getDictCache(dictType);
|
|
|
|
|
if (StringUtils.isNotEmpty(datas))
|
|
|
|
|
|
|
|
|
|
if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
|
|
|
|
|
{
|
|
|
|
|
for (SysDictData dict : datas)
|
|
|
|
|
{
|
|
|
|
|
for (String label : dictLabel.split(separator))
|
|
|
|
|
{
|
|
|
|
|
if (label.equals(dict.getDictLabel()))
|
|
|
|
|
{
|
|
|
|
|
propertyString.append(dict.getDictValue() + separator);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (SysDictData dict : datas)
|
|
|
|
|
{
|
|
|
|
@ -91,8 +149,7 @@ public class DictUtils
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return dictLabel;
|
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|