|
|
|
@ -153,12 +153,7 @@ public class ExcelUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// excel 文本框最大长度
|
|
|
|
|
if(String.valueOf(cellValue).length() > 30000){
|
|
|
|
|
hssfRow.createCell(j, CellType.STRING).setCellValue(String.valueOf(cellValue).substring(0, 30000));
|
|
|
|
|
}else{
|
|
|
|
|
hssfRow.createCell(j, CellType.STRING).setCellValue(String.valueOf(cellValue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hssfRow.createCell(j, CellType.STRING).setCellValue(StringTool.valueExcelOf(cellValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -208,6 +203,7 @@ public class ExcelUtil {
|
|
|
|
|
// 校验sheet是否超过最大行数
|
|
|
|
|
Sheet sheet = wb.getSheet(importClass.getSimpleName());
|
|
|
|
|
int maxRow = Integer.parseInt(sysConfigService.getSysConfigByCode(PlatformConstWords.EXCEL_IMPORT_MAX_ROW).getConfigValue());
|
|
|
|
|
System.out.println(maxRow);
|
|
|
|
|
if (sheet != null && sheet.getLastRowNum() > maxRow) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
@ -246,30 +242,33 @@ public class ExcelUtil {
|
|
|
|
|
row = sheet.getRow(i);
|
|
|
|
|
obj = importClass.newInstance();
|
|
|
|
|
for (int j = 0; j < fields.length; j++) {
|
|
|
|
|
// 判断是否存在引用关系
|
|
|
|
|
if (fields[j].isAnnotationPresent(AnnoOutputColumn.class)) {
|
|
|
|
|
inputColumn = fields[j].getAnnotation(AnnoOutputColumn.class);
|
|
|
|
|
row.getCell(j).setCellType(CellType.STRING);
|
|
|
|
|
cellValue = row.getCell(j).getStringCellValue();
|
|
|
|
|
|
|
|
|
|
// 判断是否为枚举字段
|
|
|
|
|
if (inputColumn.refClass().isEnum()) {
|
|
|
|
|
method = inputColumn.refClass().getDeclaredMethod(
|
|
|
|
|
inputColumn.value() + "Of" + StringTool.toUpperCaseFirstOne(inputColumn.refForeignKey()),
|
|
|
|
|
inputColumn.refClass().getDeclaredMethod("get"+
|
|
|
|
|
StringTool.toUpperCaseFirstOne(inputColumn.value())).getReturnType());
|
|
|
|
|
cellValue = method.invoke(null, cellValue);
|
|
|
|
|
}else if(inputColumn.refClass().equals(SysDictionary.class) && cellValue != null){
|
|
|
|
|
cellValue = sysDictionaryService.getSysDictionaryByParentCodeAndName(inputColumn.refForeignKey(), String.valueOf(cellValue)).getName();
|
|
|
|
|
} else if(!inputColumn.refClass().equals(Object.class) && !inputColumn.refClass().equals(SysDictionary.class)){
|
|
|
|
|
cellValue = selectByProperty(inputColumn.refClass(), inputColumn.refForeignKey(), inputColumn.value(), cellValue);
|
|
|
|
|
Field field = fields[j];
|
|
|
|
|
if(field != null){
|
|
|
|
|
// 判断是否存在引用关系
|
|
|
|
|
if (field.isAnnotationPresent(AnnoOutputColumn.class)) {
|
|
|
|
|
inputColumn = fields[j].getAnnotation(AnnoOutputColumn.class);
|
|
|
|
|
row.getCell(j).setCellType(CellType.STRING);
|
|
|
|
|
cellValue = row.getCell(j).getStringCellValue();
|
|
|
|
|
|
|
|
|
|
// 判断是否为枚举字段
|
|
|
|
|
if (inputColumn.refClass().isEnum()) {
|
|
|
|
|
method = inputColumn.refClass().getDeclaredMethod(
|
|
|
|
|
inputColumn.value() + "Of" + StringTool.toUpperCaseFirstOne(inputColumn.refForeignKey()),
|
|
|
|
|
inputColumn.refClass().getDeclaredMethod("get"+
|
|
|
|
|
StringTool.toUpperCaseFirstOne(inputColumn.value())).getReturnType());
|
|
|
|
|
cellValue = method.invoke(null, cellValue);
|
|
|
|
|
}else if(inputColumn.refClass().equals(SysDictionary.class) && cellValue != null){
|
|
|
|
|
cellValue = sysDictionaryService.getSysDictionaryByParentCodeAndName(inputColumn.refForeignKey(), String.valueOf(cellValue)).getName();
|
|
|
|
|
} else if(!inputColumn.refClass().equals(Object.class) && !inputColumn.refClass().equals(SysDictionary.class)){
|
|
|
|
|
cellValue = selectByProperty(inputColumn.refClass(), inputColumn.refForeignKey(), inputColumn.value(), cellValue);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
cellValue = getExcelCell(row.getCell(j), field.getType());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
cellValue = getExcelCell(row.getCell(j), fields[j].getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fields[j].setAccessible(true);
|
|
|
|
|
fields[j].set(obj, cellValue);
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
field.set(obj, cellValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dataList.add(obj);
|
|
|
|
|
}
|
|
|
|
|