|
|
@ -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,39 +682,62 @@ 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(",");
|
|
|
|
|
|
|
|
for (String item : convertSource)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String[] convertSource = converterExp.split(",");
|
|
|
|
String[] itemArray = item.split("=");
|
|
|
|
for (String item : convertSource)
|
|
|
|
if (StringUtils.containsAny(separator, propertyValue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String[] itemArray = item.split("=");
|
|
|
|
for (String value : propertyValue.split(separator))
|
|
|
|
if (StringUtils.containsAny(separator, propertyValue))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (String value : propertyValue.split(separator))
|
|
|
|
if (itemArray[1].equals(value))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (itemArray[1].equals(value))
|
|
|
|
propertyString.append(itemArray[0] + separator);
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
propertyString.append(itemArray[0] + separator);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (itemArray[1].equals(propertyValue))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (itemArray[1].equals(propertyValue))
|
|
|
|
return itemArray[0];
|
|
|
|
{
|
|
|
|
|
|
|
|
return itemArray[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
return StringUtils.stripEnd(propertyString.toString(), separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 解析字典值
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param dictType 字典类型
|
|
|
|
|
|
|
|
* @param dictValue 字典值
|
|
|
|
|
|
|
|
* @return 字典标签
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String convertDictByExp(String dictType, String dictValue) 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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 反向解析值字典值
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 编码文件名
|
|
|
|
* 编码文件名
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|