|
|
@ -128,7 +128,15 @@ public class ${table.getCName()}Ajax{
|
|
|
|
public Object imports(MultipartFile file) {
|
|
|
|
public Object imports(MultipartFile file) {
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
WExcel sheet = new WExcel<>(${table.getCName()}.class).read(file.getBytes(), new WExcel.Processor<${table.getCName()}>() {
|
|
|
|
// 检查文件格式
|
|
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
|
|
|
|
|
|
|
if (!originalFilename.matches("\\.xlsx?")) {
|
|
|
|
|
|
|
|
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件格式错误!");
|
|
|
|
|
|
|
|
return baseResponse;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 兼容2003以前老版本.xls
|
|
|
|
|
|
|
|
ExcelTypeEnum excelTypeEnum = file.getOriginalFilename().endsWith(".xlsx") ? ExcelTypeEnum.XLSX : ExcelTypeEnum.XLS;
|
|
|
|
|
|
|
|
WExcel sheet = new WExcel<>(${table.getCName()}.class).read(file.getBytes(), excelTypeEnum, new WExcel.Processor<${table.getCName()}>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<String> exec(${table.getCName()} o, int index) {
|
|
|
|
public List<String> exec(${table.getCName()} o, int index) {
|
|
|
|
${table.getCName()}CreateRequest request = MapperUtil.map(o, ${table.getCName()}CreateRequest.class);
|
|
|
|
${table.getCName()}CreateRequest request = MapperUtil.map(o, ${table.getCName()}CreateRequest.class);
|
|
|
@ -144,7 +152,7 @@ public class ${table.getCName()}Ajax{
|
|
|
|
return validate;
|
|
|
|
return validate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 当导入出现错误时可以将存在标注错误的Excel返回给用户改正
|
|
|
|
if (sheet.hasError()) {
|
|
|
|
if (sheet.hasError()) {
|
|
|
|
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
|
|
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|