Excel支持dictType读取字符串组内容

pull/172/MERGE
RuoYi 4 years ago
parent 9ad3cc0b9a
commit a3bb603382

@ -281,7 +281,7 @@ public class ExcelUtil<T>
}
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);
}
@ -552,7 +552,7 @@ public class ExcelUtil<T>
}
else if (StringUtils.isNotEmpty(dictType))
{
cell.setCellValue(convertDictByExp(dictType, Convert.toStr(value)));
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
}
else
{
@ -711,31 +711,33 @@ public class ExcelUtil<T>
/**
*
*
* @param dictType
* @param dictValue
* @param dictType
* @param separator
* @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");
String methodName = "getDictLabel";
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictValue));
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictValue, separator));
}
/**
*
*
* @param dictLabel
* @param dictType
* @param dictValue
* @param separator
* @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");
String methodName = "getDictValue";
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictLabel));
Method method = bean.getClass().getDeclaredMethod(methodName, String.class, String.class, String.class);
return Convert.toStr(method.invoke(bean, dictType, dictLabel, separator));
}
/**

@ -15,6 +15,11 @@ import com.ruoyi.system.domain.SysDictData;
@Component
public class DictUtils
{
/**
*
*/
public static final String SEPARATOR = ",";
/**
*
*
@ -52,21 +57,59 @@ 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.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
{
List<SysDictData> datas = getDictCache(dictType);
if (StringUtils.isNotEmpty(datas))
for (SysDictData dict : datas)
{
for (SysDictData dict : datas)
for (String value : dictValue.split(separator))
{
if (dictValue.equals(dict.getDictValue()))
if (value.equals(dict.getDictValue()))
{
return dict.getDictLabel();
propertyString.append(dict.getDictLabel() + separator);
break;
}
}
}
}
return dictValue;
else
{
for (SysDictData dict : datas)
{
if (dictValue.equals(dict.getDictValue()))
{
return dict.getDictLabel();
}
}
}
return StringUtils.stripEnd(propertyString.toString(), separator);
}
/**
@ -74,25 +117,39 @@ public class DictUtils
*
* @param dictType
* @param dictLabel
* @param separator
* @return
*/
public static String getDictValue(String dictType, String dictLabel)
public static String getDictValue(String dictType, String dictLabel, String separator)
{
if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotEmpty(dictLabel))
StringBuilder propertyString = new StringBuilder();
List<SysDictData> datas = getDictCache(dictType);
if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
{
List<SysDictData> datas = getDictCache(dictType);
if (StringUtils.isNotEmpty(datas))
for (SysDictData dict : datas)
{
for (SysDictData dict : datas)
for (String label : dictLabel.split(separator))
{
if (dictLabel.equals(dict.getDictLabel()))
if (label.equals(dict.getDictLabel()))
{
return dict.getDictValue();
propertyString.append(dict.getDictValue() + separator);
break;
}
}
}
}
return dictLabel;
else
{
for (SysDictData dict : datas)
{
if (dictLabel.equals(dict.getDictLabel()))
{
return dict.getDictValue();
}
}
}
return StringUtils.stripEnd(propertyString.toString(), separator);
}
/**

Loading…
Cancel
Save