Excel支持dictType读取字符串组内容
parent
9ad3cc0b9a
commit
a3bb603382
|
@ -281,7 +281,7 @@ public class ExcelUtil<T>
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(attr.dictType()))
|
else if (StringUtils.isNotEmpty(attr.dictType()))
|
||||||
{
|
{
|
||||||
val = reverseDictByExp(attr.dictType(), Convert.toStr(val));
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
||||||
}
|
}
|
||||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||||
}
|
}
|
||||||
|
@ -552,7 +552,7 @@ public class ExcelUtil<T>
|
||||||
}
|
}
|
||||||
else if (StringUtils.isNotEmpty(dictType))
|
else if (StringUtils.isNotEmpty(dictType))
|
||||||
{
|
{
|
||||||
cell.setCellValue(convertDictByExp(dictType, Convert.toStr(value)));
|
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -711,31 +711,33 @@ public class ExcelUtil<T>
|
||||||
/**
|
/**
|
||||||
* 解析字典值
|
* 解析字典值
|
||||||
*
|
*
|
||||||
* @param dictType 字典类型
|
|
||||||
* @param dictValue 字典值
|
* @param dictValue 字典值
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param separator 分隔符
|
||||||
* @return 字典标签
|
* @return 字典标签
|
||||||
*/
|
*/
|
||||||
public static String convertDictByExp(String dictType, String dictValue) throws Exception
|
public static String convertDictByExp(String dictValue, String dictType, String separator) throws Exception
|
||||||
{
|
{
|
||||||
Object bean = SpringUtils.getBean("dictUtils");
|
Object bean = SpringUtils.getBean("dictUtils");
|
||||||
String methodName = "getDictLabel";
|
String methodName = "getDictLabel";
|
||||||
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
|
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
|
||||||
return Convert.toStr(method.invoke(bean, dictType, dictValue));
|
return Convert.toStr(method.invoke(bean, dictType, dictValue, separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 反向解析值字典值
|
* 反向解析值字典值
|
||||||
*
|
*
|
||||||
|
* @param dictLabel 字典标签
|
||||||
* @param dictType 字典类型
|
* @param dictType 字典类型
|
||||||
* @param dictValue 字典标签
|
* @param separator 分隔符
|
||||||
* @return 字典值
|
* @return 字典值
|
||||||
*/
|
*/
|
||||||
public static String reverseDictByExp(String dictType, String dictLabel) throws Exception
|
public static String reverseDictByExp(String dictLabel, String dictType, String separator) throws Exception
|
||||||
{
|
{
|
||||||
Object bean = SpringUtils.getBean("dictUtils");
|
Object bean = SpringUtils.getBean("dictUtils");
|
||||||
String methodName = "getDictValue";
|
String methodName = "getDictValue";
|
||||||
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
|
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
|
||||||
return Convert.toStr(method.invoke(bean, dictType, dictLabel));
|
return Convert.toStr(method.invoke(bean, dictType, dictLabel, separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,11 @@ import com.ruoyi.system.domain.SysDictData;
|
||||||
@Component
|
@Component
|
||||||
public class DictUtils
|
public class DictUtils
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 分隔符
|
||||||
|
*/
|
||||||
|
public static final String SEPARATOR = ",";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置字典缓存
|
* 设置字典缓存
|
||||||
*
|
*
|
||||||
|
@ -52,21 +57,7 @@ public class DictUtils
|
||||||
*/
|
*/
|
||||||
public static String getDictLabel(String dictType, String dictValue)
|
public static String getDictLabel(String dictType, String dictValue)
|
||||||
{
|
{
|
||||||
if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictValue))
|
return getDictLabel(dictType, dictValue, SEPARATOR);
|
||||||
{
|
|
||||||
List<SysDictData> datas = getDictCache(dictType);
|
|
||||||
if (StringUtils.isNotEmpty(datas))
|
|
||||||
{
|
|
||||||
for (SysDictData dict : datas)
|
|
||||||
{
|
|
||||||
if (dictValue.equals(dict.getDictValue()))
|
|
||||||
{
|
|
||||||
return dict.getDictLabel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dictValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,10 +69,77 @@ public class DictUtils
|
||||||
*/
|
*/
|
||||||
public static String getDictValue(String dictType, String dictLabel)
|
public static String getDictValue(String dictType, String dictLabel)
|
||||||
{
|
{
|
||||||
if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(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);
|
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)
|
||||||
|
{
|
||||||
|
if (dictValue.equals(dict.getDictValue()))
|
||||||
|
{
|
||||||
|
return dict.getDictLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型和字典标签获取字典值
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param dictLabel 字典标签
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 字典值
|
||||||
|
*/
|
||||||
|
public static String getDictValue(String dictType, String dictLabel, String separator)
|
||||||
|
{
|
||||||
|
StringBuilder propertyString = new StringBuilder();
|
||||||
|
List<SysDictData> datas = getDictCache(dictType);
|
||||||
|
|
||||||
|
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)
|
for (SysDictData dict : datas)
|
||||||
{
|
{
|
||||||
|
@ -91,8 +149,7 @@ public class DictUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||||
return dictLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue