|
|
@ -50,6 +50,7 @@ import com.ruoyi.common.exception.BusinessException;
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Excel相关处理
|
|
|
|
* Excel相关处理
|
|
|
@ -276,7 +277,11 @@ public class ExcelUtil<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
|
|
|
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
val = reverseByExp(String.valueOf(val), attr.readConverterExp(), attr.separator());
|
|
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (StringUtils.isNotEmpty(attr.dictType()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
val = reverseDictByExp(attr.dictType(), Convert.toStr(val));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -536,13 +541,18 @@ public class ExcelUtil<T>
|
|
|
|
String dateFormat = attr.dateFormat();
|
|
|
|
String dateFormat = attr.dateFormat();
|
|
|
|
String readConverterExp = attr.readConverterExp();
|
|
|
|
String readConverterExp = attr.readConverterExp();
|
|
|
|
String separator = attr.separator();
|
|
|
|
String separator = attr.separator();
|
|
|
|
|
|
|
|
String dictType = attr.dictType();
|
|
|
|
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
|
|
|
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
|
|
|
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
|
|
|
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp, separator));
|
|
|
|
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (StringUtils.isNotEmpty(dictType))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cell.setCellValue(convertDictByExp(dictType, Convert.toStr(value)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -672,8 +682,6 @@ public class ExcelUtil<T>
|
|
|
|
public static String reverseByExp(String propertyValue, String converterExp, String separator) throws Exception
|
|
|
|
public static String reverseByExp(String propertyValue, String converterExp, String separator) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder propertyString = new StringBuilder();
|
|
|
|
StringBuilder propertyString = new StringBuilder();
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String[] convertSource = converterExp.split(",");
|
|
|
|
String[] convertSource = converterExp.split(",");
|
|
|
|
for (String item : convertSource)
|
|
|
|
for (String item : convertSource)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -697,12 +705,37 @@ public class ExcelUtil<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 解析字典值
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
|
|
|
* @param dictValue 字典值
|
|
|
|
|
|
|
|
* @return 字典标签
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String convertDictByExp(String dictType, String dictValue) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw e;
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 反向解析值字典值
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
|
|
|
* @param dictValue 字典标签
|
|
|
|
|
|
|
|
* @return 字典值
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String reverseDictByExp(String dictType, String dictLabel) 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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|