EasyExcel 优化

Former-commit-id: 21f61e084fa2d170eb0ba70d04415a1d98c1b574
master
wangbing 5 years ago
parent b5b8df9b8d
commit ad71a7e8c5

@ -10,7 +10,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil; import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.${moduleName}.ent.${table.getCName()}; import ${basePackage}.module.${moduleName}.ent.${table.getCName()};
import ${basePackage}.module.${moduleName}.mgr.${table.getCName()}Manager; import ${basePackage}.module.${moduleName}.mgr.${table.getCName()}Manager;
@ -102,15 +101,15 @@ public class ${table.getCName()}Ajax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(${table.getCName()}.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(${table.getCName()}.class).addDatas(response.getResult()));
} }
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).loadData(file.getBytes(), new WExcel.Processor<${table.getCName()}>() { WExcel sheet = new WExcel<>(${table.getCName()}.class).read(file.getBytes(), new WExcel.Processor<${table.getCName()}>() {
@Override @Override
public List<String> exec(${table.getCName()} o) { 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);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -125,7 +124,7 @@ public class ${table.getCName()}Ajax{
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class DeptAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Dept.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Dept.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Dept.class).loadData(file.getBytes(), new WExcel.Processor<Dept>() { WExcel sheet = new WExcel<>(Dept.class).read(file.getBytes(), new WExcel.Processor<Dept>() {
@Override @Override
public List<String> exec(Dept o) { public List<String> exec(Dept o, int index) {
DeptCreateRequest request = MapperUtil.map(o, DeptCreateRequest.class); DeptCreateRequest request = MapperUtil.map(o, DeptCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -88,7 +87,7 @@ public class DeptAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class DictAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Dict.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Dict.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Dict.class).loadData(file.getBytes(), new WExcel.Processor<Dict>() { WExcel sheet = new WExcel<>(Dict.class).read(file.getBytes(), new WExcel.Processor<Dict>() {
@Override @Override
public List<String> exec(Dict o) { public List<String> exec(Dict o, int index) {
DictCreateRequest request = MapperUtil.map(o, DictCreateRequest.class); DictCreateRequest request = MapperUtil.map(o, DictCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -88,7 +87,7 @@ public class DictAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class DictItemAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<DictItem>(DictItem.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<DictItem>(DictItem.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(DictItem.class).loadData(file.getBytes(), new WExcel.Processor<DictItem>() { WExcel sheet = new WExcel<>(DictItem.class).read(file.getBytes(), new WExcel.Processor<DictItem>() {
@Override @Override
public List<String> exec(DictItem o) { public List<String> exec(DictItem o, int index) {
DictItemCreateRequest request = MapperUtil.map(o, DictItemCreateRequest.class); DictItemCreateRequest request = MapperUtil.map(o, DictItemCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class DictItemAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -10,7 +10,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class FileAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(File.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(File.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(File.class).loadData(file.getBytes(), new WExcel.Processor<File>() { WExcel sheet = new WExcel<>(File.class).read(file.getBytes(), new WExcel.Processor<File>() {
@Override @Override
public List<String> exec(File o) { public List<String> exec(File o, int index) {
FileCreateRequest request = MapperUtil.map(o, FileCreateRequest.class); FileCreateRequest request = MapperUtil.map(o, FileCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class FileAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class LogErrAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(LogErr.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(LogErr.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(LogErr.class).loadData(file.getBytes(), new WExcel.Processor<LogErr>() { WExcel sheet = new WExcel<>(LogErr.class).read(file.getBytes(), new WExcel.Processor<LogErr>() {
@Override @Override
public List<String> exec(LogErr o) { public List<String> exec(LogErr o, int index) {
LogErrCreateRequest request = MapperUtil.map(o, LogErrCreateRequest.class); LogErrCreateRequest request = MapperUtil.map(o, LogErrCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class LogErrAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -10,7 +10,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil; import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.system.ent.Profiles; import ${basePackage}.module.system.ent.Profiles;
import ${basePackage}.module.system.mgr.ProfilesManager; import ${basePackage}.module.system.mgr.ProfilesManager;
@ -59,15 +58,15 @@ public class ProfilesAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Profiles.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Profiles.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Profiles.class).loadData(file.getBytes(), new WExcel.Processor<Profiles>() { WExcel sheet = new WExcel<>(Profiles.class).read(file.getBytes(), new WExcel.Processor<Profiles>() {
@Override @Override
public List<String> exec(Profiles o) { public List<String> exec(Profiles o, int index) {
ProfilesCreateRequest request = MapperUtil.map(o, ProfilesCreateRequest.class); ProfilesCreateRequest request = MapperUtil.map(o, ProfilesCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class ProfilesAjax{
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class ResAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Res.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Res.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Res.class).loadData(file.getBytes(), new WExcel.Processor<Res>() { WExcel sheet = new WExcel<>(Res.class).read(file.getBytes(), new WExcel.Processor<Res>() {
@Override @Override
public List<String> exec(Res o) { public List<String> exec(Res o, int index) {
ResCreateRequest request = MapperUtil.map(o, ResCreateRequest.class); ResCreateRequest request = MapperUtil.map(o, ResCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -88,7 +87,7 @@ public class ResAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class RoleAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Role.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Role.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Role.class).loadData(file.getBytes(), new WExcel.Processor<Role>() { WExcel sheet = new WExcel<>(Role.class).read(file.getBytes(), new WExcel.Processor<Role>() {
@Override @Override
public List<String> exec(Role o) { public List<String> exec(Role o, int index) {
RoleCreateRequest request = MapperUtil.map(o, RoleCreateRequest.class); RoleCreateRequest request = MapperUtil.map(o, RoleCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class RoleAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -11,7 +11,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil; import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.system.ent.TaskSql; import ${basePackage}.module.system.ent.TaskSql;
import ${basePackage}.module.system.mgr.TaskSqlManager; import ${basePackage}.module.system.mgr.TaskSqlManager;
@ -60,15 +59,15 @@ public class TaskSqlAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(TaskSql.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(TaskSql.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(TaskSql.class).loadData(file.getBytes(), new WExcel.Processor<TaskSql>() { WExcel sheet = new WExcel<>(TaskSql.class).read(file.getBytes(), new WExcel.Processor<TaskSql>() {
@Override @Override
public List<String> exec(TaskSql o) { public List<String> exec(TaskSql o, int index) {
TaskSqlCreateRequest request = MapperUtil.map(o, TaskSqlCreateRequest.class); TaskSqlCreateRequest request = MapperUtil.map(o, TaskSqlCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -83,7 +82,7 @@ public class TaskSqlAjax{
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class TokensAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Tokens.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Tokens.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Tokens.class).loadData(file.getBytes(), new WExcel.Processor<Tokens>() { WExcel sheet = new WExcel<>(Tokens.class).read(file.getBytes(), new WExcel.Processor<Tokens>() {
@Override @Override
public List<String> exec(Tokens o) { public List<String> exec(Tokens o, int index) {
TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class); TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -88,7 +87,7 @@ public class TokensAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -8,7 +8,6 @@ import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.CookieUtil; import ${basePackage}.frame.utils.CookieUtil;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
@ -211,15 +210,15 @@ public class UserAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(User.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(User.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(User.class).loadData(file.getBytes(), new WExcel.Processor<User>() { WExcel sheet = new WExcel<>(User.class).read(file.getBytes(), new WExcel.Processor<User>() {
@Override @Override
public List<String> exec(User o) { public List<String> exec(User o, int index) {
UserCreateRequest request = MapperUtil.map(o, UserCreateRequest.class); UserCreateRequest request = MapperUtil.map(o, UserCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -234,7 +233,7 @@ public class UserAjax {
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse; import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType; import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil; import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class VisitorAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空"); response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response; return response;
} }
return ResponseUtil.apply(new WExcel<>(Visitor.class).loadData(response.getResult())); return ResponseUtil.apply(new WExcel<>(Visitor.class).addDatas(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
WExcel sheet = new WExcel<>(Visitor.class).loadData(file.getBytes(), new WExcel.Processor<Visitor>() { WExcel sheet = new WExcel<>(Visitor.class).read(file.getBytes(), new WExcel.Processor<Visitor>() {
@Override @Override
public List<String> exec(Visitor o) { public List<String> exec(Visitor o, int index) {
VisitorCreateRequest request = MapperUtil.map(o, VisitorCreateRequest.class); VisitorCreateRequest request = MapperUtil.map(o, VisitorCreateRequest.class);
return ValidationUtil.validate(request); return ValidationUtil.validate(request);
} }
@ -82,7 +81,7 @@ public class VisitorAjax{
e.printStackTrace(); e.printStackTrace();
LogUtil.dumpException(e); LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错"); baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;

@ -2,6 +2,7 @@ package ${basePackage}.frame.excel;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat; import com.alibaba.excel.annotation.format.NumberFormat;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ExcelNote; import ${basePackage}.frame.excel.annotation.ExcelNote;
@ -19,35 +20,45 @@ public class DemoData extends BaseEntity {
@ExcelProperty({"字符列", "可选字符列"}) @ExcelProperty({"字符列", "可选字符列"})
@ExcelSelect({"选项一", "选项二"}) @ExcelSelect({"选项一", "选项二"})
@ExcelNote("可选字符列(选项一,选项二)")
private String str2; private String str2;
@ExcelNote("无ExcelProperty默认为字段名称")
private String str3;//无ExcelProperty默认为字段名称 private String str3;//无ExcelProperty默认为字段名称
@ExcelIgnore @ExcelIgnore
private String str4;//忽略的字段 private String str4;//忽略的字段
@ExcelProperty("短整数列") @ExcelProperty("短整数列")
@ExcelNote("短整数列")
private short sint; private short sint;
@ExcelProperty("整数列") @ExcelProperty("整数列")
@ExcelNote("整数列")
private int mint; private int mint;
@ExcelProperty("长整数列") @ExcelProperty("长整数列")
@ExcelNote("长整数列")
private long lint; private long lint;
@ExcelProperty("双精度列") @ExcelProperty("双精度列")
@NumberFormat("#.##") @NumberFormat("#.##")
@ExcelNote("双精度列,格式化#.##")
private double dbn; private double dbn;
@ExcelProperty("单精度列") @ExcelProperty("单精度列")
@NumberFormat("#.##") @NumberFormat("#.##")
@ExcelNote("单精度列,格式化#.##")
private float fln; private float fln;
@ExcelProperty("时间列") @ExcelProperty("时间列")
@DateTimeFormat("yyyy年MM月dd日 HH时mm分ss秒")
@ExcelNote("时间列格式化yyyy年MM月dd日 HH时mm分ss秒")
private Date date; private Date date;
@ExcelProperty("是否有效") @ExcelProperty("是否有效")
@ExcelSelect({"是", "否"}) @ExcelSelect({"是", "否"})
@ExcelNote("布尔值(是, 否)")
private boolean valid; private boolean valid;
public String getStr1() { public String getStr1() {

@ -1,6 +1,8 @@
package ${basePackage}.frame.excel; package ${basePackage}.frame.excel;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
@ -14,7 +16,7 @@ import ${basePackage}.frame.excel.handler.HeadWriteHandler;
import ${basePackage}.frame.excel.handler.WCellWriteHandler; import ${basePackage}.frame.excel.handler.WCellWriteHandler;
import ${basePackage}.frame.excel.handler.WRowWriteHandler; import ${basePackage}.frame.excel.handler.WRowWriteHandler;
import ${basePackage}.frame.excel.handler.WSheetWriteHandler; import ${basePackage}.frame.excel.handler.WSheetWriteHandler;
import ${basePackage}.frame.excel.listener.CheckHeadReadListener; import ${basePackage}.frame.excel.listener.WReadListener;
import ${basePackage}.frame.utils.ClassUtil; import ${basePackage}.frame.utils.ClassUtil;
import ${basePackage}.frame.utils.FileUtil; import ${basePackage}.frame.utils.FileUtil;
import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.utils.ValidationUtil;
@ -60,7 +62,7 @@ public class WExcel<T> {
/** /**
* Map key:,String: * Map key:,String:
*/ */
private Map<Integer, String> errMap; private Map<Integer, List<String>> errMap;
/** /**
* ,{@link WSheetWriteHandler#beforeSheetCreate}. * ,{@link WSheetWriteHandler#beforeSheetCreate}.
@ -103,8 +105,6 @@ public class WExcel<T> {
.registerWriteHandler(new HeadWriteHandler() { .registerWriteHandler(new HeadWriteHandler() {
@Override @Override
protected void handlerHead(Head head) { protected void handlerHead(Head head) {
WHead wHead = new WHead(head); WHead wHead = new WHead(head);
Field field = fieldMap.get(wHead.getHead().getFieldName()); Field field = fieldMap.get(wHead.getHead().getFieldName());
@ -126,6 +126,16 @@ public class WExcel<T> {
wHeads.addAll(wHeadMap.values()); wHeads.addAll(wHeadMap.values());
} }
/**
*
*
* @param os
* @return WExcel
*/
public WExcel addDatas(List<T> os) {
return addDatas(os, null);
}
/** /**
* *
* *
@ -143,7 +153,17 @@ public class WExcel<T> {
/** /**
* *
* *
* @param o * @param o
* @return WExcel
*/
public WExcel addData(T o) {
return addData(o, null);
}
/**
*
*
* @param o
* @param processor * @param processor
* @return WExcel * @return WExcel
*/ */
@ -154,7 +174,9 @@ public class WExcel<T> {
if ((validate == null || validate.isEmpty()) && processor != null) { if ((validate == null || validate.isEmpty()) && processor != null) {
List<String> exec = processor.exec(o, this.data.size()); List<String> exec = processor.exec(o, this.data.size());
if (exec != null && exec.size() > 0) { if (exec != null && exec.size() > 0) {
errMap.put(data.size() - 1, String.join("\r\n", exec)); errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
List<String> errs = errMap.get(data.size());
errs.addAll(exec);
} }
} }
this.data.add(o); this.data.add(o);
@ -171,7 +193,7 @@ public class WExcel<T> {
/** /**
* @return Excel * @return Excel
*/ */
public byte[] getByte() { public byte[] getBytes() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcel.write(outputStream) EasyExcel.write(outputStream)
.head(this.clazz) .head(this.clazz)
@ -179,8 +201,8 @@ public class WExcel<T> {
.registerConverter(new BooleanConverter()) .registerConverter(new BooleanConverter())
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.registerWriteHandler(new WSheetWriteHandler(wHeads, styles)) .registerWriteHandler(new WSheetWriteHandler(wHeads, styles))
.registerWriteHandler(new WRowWriteHandler(wHeads.size(), errMap)) .registerWriteHandler(new WRowWriteHandler(wHeads, errMap))
.registerWriteHandler(new WCellWriteHandler(styles, errMap)) .registerWriteHandler(new WCellWriteHandler(wHeads, styles, errMap))
.sheet(this.name).doWrite(data); .sheet(this.name).doWrite(data);
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
@ -191,7 +213,7 @@ public class WExcel<T> {
* @param file * @param file
*/ */
public void toFile(File file) { public void toFile(File file) {
byte[] aByte = getByte(); byte[] aByte = getBytes();
FileUtil.writeBytesToFile(aByte, file); FileUtil.writeBytesToFile(aByte, file);
} }
@ -217,6 +239,28 @@ public class WExcel<T> {
/** /**
* @param bytes * @param bytes
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(byte[] bytes) throws TemplateNotMatchException, IOException {
return read(bytes, ExcelTypeEnum.XLSX, null);
}
/**
* @param bytes
* @param processor
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(byte[] bytes, Processor<T> processor) throws TemplateNotMatchException, IOException {
return read(bytes, ExcelTypeEnum.XLSX, processor);
}
/**
* @param bytes
* @param et Excel
* @param processor * @param processor
* @return WExcel * @return WExcel
* @throws TemplateNotMatchException * @throws TemplateNotMatchException
@ -227,9 +271,31 @@ public class WExcel<T> {
return read(stream, et, processor); return read(stream, et, processor);
} }
/**
* @param in
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(InputStream in) throws TemplateNotMatchException {
return read(in, ExcelTypeEnum.XLSX, null);
}
/**
* @param in
* @param processor
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(InputStream in, Processor<T> processor) throws TemplateNotMatchException {
return read(in, ExcelTypeEnum.XLSX, processor);
}
/** /**
* @param in * @param in
* @param processor * @param processor
* @param et Excel
* @return WExcel * @return WExcel
* @throws TemplateNotMatchException * @throws TemplateNotMatchException
* @throws IOException * @throws IOException
@ -241,35 +307,32 @@ public class WExcel<T> {
.excelType(et) .excelType(et)
.head(this.clazz) .head(this.clazz)
.registerConverter(new BooleanConverter()) .registerConverter(new BooleanConverter())
.registerReadListener(new CheckHeadReadListener(wHeads, e)) .registerReadListener(new WReadListener<T>(wHeads, e) {
// .registerReadListener(new AnalysisEventListener<T>() { @Override
// public void onException(Exception exception, AnalysisContext context) throws Exception {
// @Override if (exception instanceof ExcelDataConvertException) {
// public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { ExcelDataConvertException convertException = (ExcelDataConvertException) exception;
// errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
// } List<String> errs = errMap.get(data.size());
// errs.add(convertException.getCause().getMessage());
// @Override }else {
// public void invoke(T o, AnalysisContext analysisContext) { super.onException(exception, context);
// if (processor != null) { }
// List<String> exec = processor.exec(o, data.size()); }
// if (exec != null && exec.size() > 0) {
// errMap.put(data.size(), String.join(",", exec)); @Override
// } public void invoke(T o) {
// } if (processor != null) {
// data.add(o); List<String> exec = processor.exec(o, data.size());
// } if (exec != null && exec.size() > 0) {
// errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
// @Override List<String> errs = errMap.get(data.size());
// public void doAfterAllAnalysed(AnalysisContext analysisContext) { errs.addAll(exec);
// }
// } }
// data.add(o);
// @Override }
// public boolean hasNext(AnalysisContext context) { })
// return super.hasNext(context);
// }
// })
.sheet().doRead(); .sheet().doRead();
if (e[0] != null) { if (e[0] != null) {
throw e[0]; throw e[0];
@ -281,48 +344,17 @@ public class WExcel<T> {
List<String> exec(T t, int index); List<String> exec(T t, int index);
} }
public static void main(String[] args) throws TemplateNotMatchException, IOException { /**
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); * @return
System.out.println("数据创建开始:" + dateFormat.format(new Date())); */
// 写 public boolean hasError() {
List<DemoData> visitors = new ArrayList<>(); return !errMap.isEmpty();
for (int i = 0; i < 100; i++) { }
DemoData demoData = new DemoData();
demoData.setStr1("我是标题Str1" + i); /**
demoData.setStr2("我是标题Str2" + i); * @return
demoData.setStr3("我是标题Str3" + i); */
demoData.setStr4("我是标题Str4" + i); public String getName() {
demoData.setSint((short) 1); return name;
demoData.setMint(1);
demoData.setLint(1L);
demoData.setDbn(0.01);
demoData.setFln(0.01f);
demoData.setDate(new Date());
visitors.add(demoData);
}
System.out.println("数据创建完成:" + dateFormat.format(new Date()));
// new WExcel<>(DemoData.class).addDatas(visitors, null).toFile(new File("D:\\xx.xlsx"));
System.out.println("数据导出完成:" + dateFormat.format(new Date()));
System.out.println();
// 读
System.out.println("数据导入开始:" + dateFormat.format(new Date()));
WExcel<DemoData> wExcel = new WExcel<>(DemoData.class).read(new File("D:\\xx.xlsx"), new Processor<DemoData>() {
@Override
public List<String> exec(DemoData demoData, int index) {
if (index % 50 == 0) {
// System.out.println(MapperUtil.toJson(demoData));
return Arrays.asList("测试,第" + index + "条有错误");
}
return null;
}
});
System.out.println("数据导入完成:" + dateFormat.format(new Date()));
System.out.println();
System.out.println("错误导出开始:" + dateFormat.format(new Date()));
wExcel.toFile(new File("D:\\xx-err.xlsx"));
System.out.println("错误导出结束:" + dateFormat.format(new Date()));
System.out.println();
} }
} }

@ -16,7 +16,7 @@ public class BooleanConverter implements Converter<Boolean> {
return CellDataTypeEnum.STRING; return CellDataTypeEnum.STRING;
} }
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ValueConverterException { public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
String lowerCase = cellData.getStringValue().toLowerCase(); String lowerCase = cellData.getStringValue().toLowerCase();
if (lowerCase.matches("y|n")) { if (lowerCase.matches("y|n")) {
return "y".equals(lowerCase); return "y".equals(lowerCase);
@ -31,7 +31,7 @@ public class BooleanConverter implements Converter<Boolean> {
} else if (lowerCase.matches("是|不是")) { } else if (lowerCase.matches("是|不是")) {
return "是".equals(lowerCase); return "是".equals(lowerCase);
} else { } else {
throw new ValueConverterException("[" + cellData.getStringValue() + "] can not convert to Boolean"); throw new RuntimeException("[" + cellData.getStringValue() + "] 值有错误!");
} }
} }

@ -7,8 +7,8 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import ${basePackage}.frame.excel.WHead;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -16,9 +16,9 @@ import java.util.Map;
public class WCellWriteHandler implements CellWriteHandler { public class WCellWriteHandler implements CellWriteHandler {
private CellStyle[] styles; private CellStyle[] styles;
private Map<Integer, String> errMap; private Map<Integer, List<String>> errMap;
public WCellWriteHandler(CellStyle[] styles, Map<Integer, String> errMap) { public WCellWriteHandler(List<WHead> wHeads, CellStyle[] styles, Map<Integer, List<String>> errMap) {
this.styles = styles; this.styles = styles;
this.errMap = errMap; this.errMap = errMap;
} }
@ -42,23 +42,8 @@ public class WCellWriteHandler implements CellWriteHandler {
@Override @Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer rowIndex, Boolean isHead) { public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer rowIndex, Boolean isHead) {
if (isHead) { if (isHead) {
// 创建批注
Drawing<?> drawingPatriarch = writeSheetHolder.getSheet().createDrawingPatriarch();
// for (int i = 0; i < wHeads.size(); i++) {
// WHead wHead = wHeads.get(i);
// if (wHead.getNote() != null && !"".equals(wHead.getNote())) {
// // 创建一个批注
// Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) i, 0, (short) i + 1, 2));
// // 输入批注信息
// comment.setString(new XSSFRichTextString(wHead.getNote()));
// // 将批注添加到标题对象中
// writeSheetHolder.getSheet().getRow(0).getCell(i).setCellComment(comment);
// }
// }
cell.setCellStyle(styles[0]); cell.setCellStyle(styles[0]);
} else if (!"".equals(errMap.getOrDefault(rowIndex, ""))) { } else if (errMap.get(rowIndex) != null) {
// cell.getCellStyle().setFillForegroundColor(IndexedColors.RED.getIndex());
// cell.getCellStyle().setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(styles[1]); cell.setCellStyle(styles[1]);
} }
} }

@ -1,20 +1,27 @@
package ${basePackage}.frame.excel.handler; package ${basePackage}.frame.excel.handler;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.RowWriteHandler; import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import ${basePackage}.frame.excel.WHead;
import ${basePackage}.frame.utils.StringUtil;
import java.util.List;
import java.util.Map; import java.util.Map;
public class WRowWriteHandler implements RowWriteHandler { public class WRowWriteHandler implements RowWriteHandler {
private int errColIndex; private List<WHead> wHeads;
private Map<Integer, String> errMap; private Map<Integer, List<String>> errMap;
public WRowWriteHandler(int errColIndex, Map<Integer, String> errMap) { public WRowWriteHandler(List<WHead> wHeads, Map<Integer, List<String>> errMap) {
this.errColIndex = errColIndex; this.wHeads = wHeads;
this.errMap = errMap; this.errMap = errMap;
} }
@ -30,10 +37,51 @@ public class WRowWriteHandler implements RowWriteHandler {
@Override @Override
public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Boolean isHead) { public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Boolean isHead) {
if (!isHead && !"".equals(errMap.getOrDefault(rowIndex, ""))) { if (isHead && getHeadMaxRow() == rowIndex) {
Cell cell = row.createCell(errColIndex); for (int i = 0; i < wHeads.size(); i++) {
WHead wHead = wHeads.get(i);
if (StringUtil.isNotEmpty(wHead.getNote())) {
Drawing<?> drawingPatriarch = writeSheetHolder.getSheet().createDrawingPatriarch();
// 创建一个批注
int headRow = getHeadRow(wHead.getHead());
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) i, headRow, (short) i + 1, headRow + 3));
// 输入批注信息
comment.setString(new XSSFRichTextString(wHead.getNote()));
// 将批注添加到标题对象中
writeSheetHolder.getSheet().getRow(headRow).getCell(i).setCellComment(comment);
}
}
}
if (!isHead && errMap.get(rowIndex) != null) {
Cell cell = row.createCell(wHeads.size());
cell.getCellStyle().setWrapText(true); cell.getCellStyle().setWrapText(true);
cell.setCellValue(errMap.get(rowIndex)); List<String> errs = errMap.get(rowIndex);
cell.setCellValue(String.join("\r\n", errs));
}
}
public int getHeadMaxRow() {
int r = 0;
for (WHead wHead : wHeads) {
if (wHead.getHead().getHeadNameList().size() - 1 > r) r = wHead.getHead().getHeadNameList().size() - 1;
}
return r;
}
public int getHeadRow(Head head) {
List<String> nameList = head.getHeadNameList();
if (nameList.size() == 1) {
return 0;
}
int r = nameList.size() - 1;
String last = nameList.get(r);
for (int i = nameList.size() - 2; i >= 0; i--) {
String s = nameList.get(i);
if (s.equals(last)) {
r--;
}
} }
return r;
} }
} }

@ -1,23 +0,0 @@
package ${basePackage}.frame.excel.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
public class HeadReadListener extends AnalysisEventListener {
@Override
public void invoke(Object o, AnalysisContext analysisContext) {
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
@Override
public boolean hasNext(AnalysisContext context) {
return false;
}
}

@ -9,13 +9,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class CheckHeadReadListener extends AnalysisEventListener { public abstract class WReadListener<T> extends AnalysisEventListener<T> {
private List<WHead> wHeads; private List<WHead> wHeads;
private TemplateNotMatchException[] es; private TemplateNotMatchException[] es;
private boolean isHead;
public CheckHeadReadListener(List<WHead> wHeads, TemplateNotMatchException[] es) { public WReadListener(List<WHead> wHeads, TemplateNotMatchException[] es) {
this.wHeads = wHeads; this.wHeads = wHeads;
this.es = es; this.es = es;
this.isHead = true;
} }
@Override @Override
@ -36,10 +38,13 @@ public class CheckHeadReadListener extends AnalysisEventListener {
} }
@Override @Override
public void invoke(Object o, AnalysisContext analysisContext) { public void invoke(T o, AnalysisContext analysisContext) {
isHead = false;
invoke(o);
} }
public abstract void invoke(T o);
@Override @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) { public void doAfterAllAnalysed(AnalysisContext analysisContext) {
@ -47,6 +52,13 @@ public class CheckHeadReadListener extends AnalysisEventListener {
@Override @Override
public boolean hasNext(AnalysisContext context) { public boolean hasNext(AnalysisContext context) {
return es[0] != null; // 请求head
if (isHead) {//多级表头,头部未结束
return true;
}
if (!isHead && es[0] == null) {
return true;
}
return false;
} }
} }

@ -4,10 +4,10 @@ package ${basePackage}.module.${moduleName}.ent;
import java.util.Date; import java.util.Date;
</#if> </#if>
<#if table.getHtml()> <#if table.getHtml()>
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
</#if> </#if>
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
@ -19,7 +19,7 @@ import ${basePackage}.frame.base.BaseEntity;
* @since ${.now?string["yyyy-MM-dd"]} * @since ${.now?string["yyyy-MM-dd"]}
*/ */
<#if table.getHtml()> <#if table.getHtml()>
@SheetName("${table.tableComment?default("")}") @ExcelSheet("${table.tableComment?default("")}")
</#if> </#if>
public class ${table.getCName()} extends BaseEntity { public class ${table.getCName()} extends BaseEntity {
@ -29,10 +29,10 @@ public class ${table.getCName()} extends BaseEntity {
* ${field.fieldName} - ${field.fieldComment?default("")} * ${field.fieldName} - ${field.fieldComment?default("")}
*/ */
<#if table.getHtml()> <#if table.getHtml()>
@ColumnName("${field.fieldComment?default("")}") @ExcelProperty("${field.fieldComment?default("")}")
@ColumnDescription("") @ExcelNote("")
<#if field.fieldType.javaType()=="Boolean"> <#if field.fieldType.javaType()=="Boolean">
@ColumnList({"是","否"}) @ExcelSelect({"是","否"})
</#if> </#if>
</#if> </#if>
private ${field.fieldType.javaType()} ${field.getFName()}; private ${field.fieldType.javaType()} ${field.getFName()};

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -13,45 +13,45 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("部门") @ExcelSheet("部门")
public class Dept extends BaseEntity { public class Dept extends BaseEntity {
/** /**
* DEPT_CODE - * DEPT_CODE -
*/ */
@ColumnName("部门代码") @ExcelProperty("部门代码")
@ColumnDescription("") @ExcelNote("")
private String deptCode; private String deptCode;
/** /**
* DEPT_NAME - * DEPT_NAME -
*/ */
@ColumnName("部门名称") @ExcelProperty("部门名称")
@ColumnDescription("") @ExcelNote("")
private String deptName; private String deptName;
/** /**
* DEPT_ALIAS - * DEPT_ALIAS -
*/ */
@ColumnName("部门别名") @ExcelProperty("部门别名")
@ColumnDescription("") @ExcelNote("")
private String deptAlias; private String deptAlias;
/** /**
* SUP_CODE - * SUP_CODE -
*/ */
@ColumnName("上级代码") @ExcelProperty("上级代码")
@ColumnDescription("") @ExcelNote("")
private String supCode; private String supCode;
/** /**
* SUP_NAME - * SUP_NAME -
*/ */
@ColumnName("上级名称") @ExcelProperty("上级名称")
@ColumnDescription("") @ExcelNote("")
private String supName; private String supName;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("") @ExcelNote("")
@ColumnList({"是", "否"}) @ExcelSelect({"是", "否"})
private Boolean valid; private Boolean valid;
public String getDeptCode() { public String getDeptCode() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
/** /**
* DICT - * DICT -
@ -12,32 +12,32 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("字典") @ExcelSheet("字典")
public class Dict extends BaseEntity { public class Dict extends BaseEntity {
/** /**
* DICT_NAME - * DICT_NAME -
*/ */
@ColumnName("字典名称") @ExcelProperty("字典名称")
@ColumnDescription("1-50长度的字典名称") @ExcelNote("1-50长度的字典名称")
private String dictName; private String dictName;
/** /**
* DICT_COMMENT - * DICT_COMMENT -
*/ */
@ColumnName("字典描述") @ExcelProperty("字典描述")
@ColumnDescription("1-50长度的字典描述") @ExcelNote("1-50长度的字典描述")
private String dictComment; private String dictComment;
/** /**
* VERSION - * VERSION -
*/ */
@ColumnName("字典版本") @ExcelProperty("字典版本")
@ColumnDescription("字典版本.例如:yyyy-MM-dd HH:mm:ss") @ExcelNote("字典版本.例如:yyyy-MM-dd HH:mm:ss")
private String version; private String version;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("Y/N,是/否") @ExcelNote("Y/N,是/否")
private Boolean valid; private Boolean valid;
public String getDictName() { public String getDictName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
/** /**
* DICT_ITEM - * DICT_ITEM -
@ -12,38 +12,38 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("字典项") @ExcelSheet("字典项")
public class DictItem extends BaseEntity { public class DictItem extends BaseEntity {
/** /**
* DICT_NAME - * DICT_NAME -
*/ */
@ColumnName("字典名称") @ExcelProperty("字典名称")
@ColumnDescription("字典名称,可为中文或英文,且不能出现重复") @ExcelNote("字典名称,可为中文或英文,且不能出现重复")
private String dictName; private String dictName;
/** /**
* KEY - * KEY -
*/ */
@ColumnName("字典键") @ExcelProperty("字典键")
@ColumnDescription("字典键一般使用数字或字母 01,02... A,B...") @ExcelNote("字典键一般使用数字或字母 01,02... A,B...")
private String key; private String key;
/** /**
* VALUE - * VALUE -
*/ */
@ColumnName("字典值") @ExcelProperty("字典值")
@ColumnDescription("字典值一般是实际意思字符或文字\n 长度在(1-100)之间") @ExcelNote("字典值一般是实际意思字符或文字\n 长度在(1-100)之间")
private String value; private String value;
/** /**
* SORT - * SORT -
*/ */
@ColumnName("字典排序值") @ExcelProperty("字典排序值")
@ColumnDescription("用于标识字典值排列顺序、必须为数字") @ExcelNote("用于标识字典值排列顺序、必须为数字")
private Integer sort; private Integer sort;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("用于标识该字典值是否有效") @ExcelNote("用于标识该字典值是否有效")
private Boolean valid; private Boolean valid;
public String getDictName() { public String getDictName() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -12,50 +12,50 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("文件") @ExcelSheet("文件")
public class File extends BaseEntity { public class File extends BaseEntity {
/** /**
* NAME - * NAME -
*/ */
@ColumnName("文件名称") @ExcelProperty("文件名称")
@ColumnDescription("文件名称") @ExcelNote("文件名称")
private String name; private String name;
/** /**
* FILE_TYPE - * FILE_TYPE -
*/ */
@ColumnName("文件类型") @ExcelProperty("文件类型")
@ColumnDescription("文件类型") @ExcelNote("文件类型")
private String fileType; private String fileType;
/** /**
* ATTRIBUTE1 - 1 * ATTRIBUTE1 - 1
*/ */
@ColumnName("扩展属性1") @ExcelProperty("扩展属性1")
@ColumnDescription("扩展属性1") @ExcelNote("扩展属性1")
private String attribute1; private String attribute1;
/** /**
* ATTRIBUTE2 - 2 * ATTRIBUTE2 - 2
*/ */
@ColumnName("扩展属性2") @ExcelProperty("扩展属性2")
@ColumnDescription("扩展属性2") @ExcelNote("扩展属性2")
private String attribute2; private String attribute2;
/** /**
* LOCATION - * LOCATION -
*/ */
@ColumnName("存放地址") @ExcelProperty("存放地址")
@ColumnDescription("存放地址") @ExcelNote("存放地址")
private String location; private String location;
/** /**
* URL - 访 * URL - 访
*/ */
@ColumnName("访问地址") @ExcelProperty("访问地址")
@ColumnDescription("访问地址") @ExcelNote("访问地址")
private String url; private String url;
/** /**
* URL_DOWNLOAD - * URL_DOWNLOAD -
*/ */
@ColumnName("下载地址") @ExcelProperty("下载地址")
@ColumnDescription("下载地址") @ExcelNote("下载地址")
private String urlDownload; private String urlDownload;
public String getName() { public String getName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -13,50 +13,50 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2020-06-07 * @since 2020-06-07
*/ */
@SheetName("错误日志") @ExcelSheet("错误日志")
public class LogErr extends BaseEntity { public class LogErr extends BaseEntity {
/** /**
* LOG_ERR_TYPE - * LOG_ERR_TYPE -
*/ */
@ColumnName("错误类型") @ExcelProperty("错误类型")
@ColumnDescription("") @ExcelNote("")
private String logErrType; private String logErrType;
/** /**
* LOG_TITLE - * LOG_TITLE -
*/ */
@ColumnName("日志标题") @ExcelProperty("日志标题")
@ColumnDescription("") @ExcelNote("")
private String logTitle; private String logTitle;
/** /**
* LOG_NOTE - * LOG_NOTE -
*/ */
@ColumnName("日志内容") @ExcelProperty("日志内容")
@ColumnDescription("") @ExcelNote("")
private String logNote; private String logNote;
/** /**
* LOG_ERR_RESULT - * LOG_ERR_RESULT -
*/ */
@ColumnName("处理结果") @ExcelProperty("处理结果")
@ColumnDescription("") @ExcelNote("")
private String logErrResult; private String logErrResult;
/** /**
* LOG_ATTR1 - 1 * LOG_ATTR1 - 1
*/ */
@ColumnName("属性1") @ExcelProperty("属性1")
@ColumnDescription("") @ExcelNote("")
private String logAttr1; private String logAttr1;
/** /**
* LOG_ATTR2 - 2 * LOG_ATTR2 - 2
*/ */
@ColumnName("属性2") @ExcelProperty("属性2")
@ColumnDescription("") @ExcelNote("")
private String logAttr2; private String logAttr2;
/** /**
* LOG_ATTR3 - 3 * LOG_ATTR3 - 3
*/ */
@ColumnName("属性3") @ExcelProperty("属性3")
@ColumnDescription("") @ExcelNote("")
private String logAttr3; private String logAttr3;
public String getLogErrType() { public String getLogErrType() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
/** /**
* PROFILES - * PROFILES -
@ -12,26 +12,26 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1 * @version 0.0.1
* @since 2020-05-24 * @since 2020-05-24
*/ */
@SheetName("系统配置") @ExcelSheet("系统配置")
public class Profiles extends BaseEntity { public class Profiles extends BaseEntity {
/** /**
* ACTIVE - * ACTIVE -
*/ */
@ColumnName("环境") @ExcelProperty("环境")
@ColumnDescription("") @ExcelNote("")
private String active; private String active;
/** /**
* KEY - * KEY -
*/ */
@ColumnName("键") @ExcelProperty("键")
@ColumnDescription("") @ExcelNote("")
private String key; private String key;
/** /**
* VALUE - * VALUE -
*/ */
@ColumnName("值") @ExcelProperty("值")
@ColumnDescription("") @ExcelNote("")
private String value; private String value;
public String getActive() { public String getActive() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -13,58 +13,58 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("资源") @ExcelSheet("资源")
public class Res extends BaseEntity { public class Res extends BaseEntity {
/** /**
* RES_CODE - * RES_CODE -
*/ */
@ColumnName("资源代码") @ExcelProperty("资源代码")
@ColumnDescription("") @ExcelNote("")
private String resCode; private String resCode;
/** /**
* RES_NAME - * RES_NAME -
*/ */
@ColumnName("资源名称") @ExcelProperty("资源名称")
@ColumnDescription("") @ExcelNote("")
private String resName; private String resName;
/** /**
* RES_TYPE - * RES_TYPE -
*/ */
@ColumnName("资源类型") @ExcelProperty("资源类型")
@ColumnDescription("") @ExcelNote("")
private String resType; private String resType;
/** /**
* RES_VALUE - * RES_VALUE -
*/ */
@ColumnName("资源内容") @ExcelProperty("资源内容")
@ColumnDescription("") @ExcelNote("")
private String resValue; private String resValue;
/** /**
* SUP_CODE - * SUP_CODE -
*/ */
@ColumnName("上级代码") @ExcelProperty("上级代码")
@ColumnDescription("") @ExcelNote("")
private String supCode; private String supCode;
/** /**
* SUP_NAME - * SUP_NAME -
*/ */
@ColumnName("上级名称") @ExcelProperty("上级名称")
@ColumnDescription("") @ExcelNote("")
private String supName; private String supName;
/** /**
* FREE - * FREE -
*/ */
@ColumnName("是否免费") @ExcelProperty("是否免费")
@ColumnDescription("") @ExcelNote("")
@ColumnList({"是","否"}) @ExcelSelect({"是","否"})
private Boolean free; private Boolean free;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("") @ExcelNote("")
@ColumnList({"是","否"}) @ExcelSelect({"是","否"})
private Boolean valid; private Boolean valid;
public String getResCode() { public String getResCode() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -12,26 +12,26 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("角色") @ExcelSheet("角色")
public class Role extends BaseEntity { public class Role extends BaseEntity {
/** /**
* CODE - * CODE -
*/ */
@ColumnName("角色代码") @ExcelProperty("角色代码")
@ColumnDescription("") @ExcelNote("")
private String code; private String code;
/** /**
* NAME - * NAME -
*/ */
@ColumnName("角色名称") @ExcelProperty("角色名称")
@ColumnDescription("") @ExcelNote("")
private String name; private String name;
/** /**
* COMMENT - * COMMENT -
*/ */
@ColumnName("角色描述") @ExcelProperty("角色描述")
@ColumnDescription("") @ExcelNote("")
private String comment; private String comment;
public String getCode() { public String getCode() {

@ -1,10 +1,10 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
/** /**
* TASK_SQL - SQL * TASK_SQL - SQL
@ -13,45 +13,45 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1 * @version 0.0.1
* @since 2020-05-24 * @since 2020-05-24
*/ */
@SheetName("SQL任务") @ExcelSheet("SQL任务")
public class TaskSql extends BaseEntity { public class TaskSql extends BaseEntity {
/** /**
* TASK_NAME - * TASK_NAME -
*/ */
@ColumnName("任务名称") @ExcelProperty("任务名称")
@ColumnDescription("") @ExcelNote("")
private String taskName; private String taskName;
/** /**
* TASK_NOTE - * TASK_NOTE -
*/ */
@ColumnName("详细注释") @ExcelProperty("详细注释")
@ColumnDescription("") @ExcelNote("")
private String taskNote; private String taskNote;
/** /**
* TASK_TYPE - * TASK_TYPE -
*/ */
@ColumnName("任务类型") @ExcelProperty("任务类型")
@ColumnDescription("") @ExcelNote("")
private String taskType; private String taskType;
/** /**
* TYPE_VALUE - * TYPE_VALUE -
*/ */
@ColumnName("任务类型值") @ExcelProperty("任务类型值")
@ColumnDescription("") @ExcelNote("")
private String typeValue; private String typeValue;
/** /**
* TASK_SQL - SQL * TASK_SQL - SQL
*/ */
@ColumnName("任务SQL") @ExcelProperty("任务SQL")
@ColumnDescription("") @ExcelNote("")
private String taskSql; private String taskSql;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("") @ExcelNote("")
@ColumnList({"是","否"}) @ExcelSelect({"是","否"})
private Boolean valid; private Boolean valid;
public String getTaskName() { public String getTaskName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import java.util.Date; import java.util.Date;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -13,80 +13,80 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("通行证") @ExcelSheet("通行证")
public class Tokens extends BaseEntity { public class Tokens extends BaseEntity {
/** /**
* TOKEN - * TOKEN -
*/ */
@ColumnName("登录令牌") @ExcelProperty("登录令牌")
@ColumnDescription("") @ExcelNote("")
private String token; private String token;
/** /**
* USER_ID - * USER_ID -
*/ */
@ColumnName("用户主键") @ExcelProperty("用户主键")
@ColumnDescription("") @ExcelNote("")
private Long userId; private Long userId;
/** /**
* USER_NAME - * USER_NAME -
*/ */
@ColumnName("用户名称") @ExcelProperty("用户名称")
@ColumnDescription("") @ExcelNote("")
private String userName; private String userName;
/** /**
* LOGIN_TIME - * LOGIN_TIME -
*/ */
@ColumnName("登录时间") @ExcelProperty("登录时间")
@ColumnDescription("") @ExcelNote("")
private Date loginTime; private Date loginTime;
/** /**
* VALID_TIME - * VALID_TIME -
*/ */
@ColumnName("有效时间") @ExcelProperty("有效时间")
@ColumnDescription("") @ExcelNote("")
private Date validTime; private Date validTime;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("") @ExcelNote("")
private Boolean valid; private Boolean valid;
/** /**
* DEPT_ID - * DEPT_ID -
*/ */
@ColumnName("部门主键") @ExcelProperty("部门主键")
@ColumnDescription("") @ExcelNote("")
private Long deptId; private Long deptId;
/** /**
* DEPT_CODE - * DEPT_CODE -
*/ */
@ColumnName("部门代码") @ExcelProperty("部门代码")
@ColumnDescription("") @ExcelNote("")
private String deptCode; private String deptCode;
/** /**
* DEPT_NAME - * DEPT_NAME -
*/ */
@ColumnName("部门名称") @ExcelProperty("部门名称")
@ColumnDescription("") @ExcelNote("")
private String deptName; private String deptName;
/** /**
* TERMINAL_TYPE - * TERMINAL_TYPE -
*/ */
@ColumnName("终端类型") @ExcelProperty("终端类型")
@ColumnDescription("") @ExcelNote("")
private String terminalType; private String terminalType;
/** /**
* TERMINAL_IP - * TERMINAL_IP -
*/ */
@ColumnName("终端地址") @ExcelProperty("终端地址")
@ColumnDescription("") @ExcelNote("")
private String terminalIp; private String terminalIp;
/** /**
* TERMINAL_INFO - * TERMINAL_INFO -
*/ */
@ColumnName("终端信息") @ExcelProperty("终端信息")
@ColumnDescription("") @ExcelNote("")
private String terminalInfo; private String terminalInfo;
public String getToken() { public String getToken() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
/** /**
@ -12,56 +12,56 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1 * @version 0.0.1
* @since 2017-01-01 * @since 2017-01-01
*/ */
@SheetName("用户") @ExcelSheet("用户")
public class User extends BaseEntity { public class User extends BaseEntity {
/** /**
* USER_NAME - * USER_NAME -
*/ */
@ColumnName("用户账户") @ExcelProperty("用户账户")
@ColumnDescription("") @ExcelNote("")
private String userName; private String userName;
/** /**
* USER_CODE - * USER_CODE -
*/ */
@ColumnName("用户代码") @ExcelProperty("用户代码")
@ColumnDescription("") @ExcelNote("")
private String userCode; private String userCode;
/** /**
* USER_ALIAS - * USER_ALIAS -
*/ */
@ColumnName("用户别名") @ExcelProperty("用户别名")
@ColumnDescription("") @ExcelNote("")
private String userAlias; private String userAlias;
/** /**
* USER_PWD - * USER_PWD -
*/ */
@ColumnName("用户密码") @ExcelProperty("用户密码")
@ColumnDescription("") @ExcelNote("")
private String userPwd; private String userPwd;
/** /**
* USER_STATUS - * USER_STATUS -
*/ */
@ColumnName("用户状态") @ExcelProperty("用户状态")
@ColumnDescription("") @ExcelNote("")
private String userStatus; private String userStatus;
/** /**
* DEPT_ID - * DEPT_ID -
*/ */
@ColumnName("部门主键") @ExcelProperty("部门主键")
@ColumnDescription("") @ExcelNote("")
private Long deptId; private Long deptId;
/** /**
* DEPT_CODE - * DEPT_CODE -
*/ */
@ColumnName("部门代码") @ExcelProperty("部门代码")
@ColumnDescription("") @ExcelNote("")
private String deptCode; private String deptCode;
/** /**
* DEPT_NAME - * DEPT_NAME -
*/ */
@ColumnName("部门名称") @ExcelProperty("部门名称")
@ColumnDescription("") @ExcelNote("")
private String deptName; private String deptName;
private String roleNames; private String roleNames;

@ -1,10 +1,10 @@
package ${basePackage}.module.system.ent; package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity; import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription; import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ColumnList; import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ColumnName; import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.SheetName; import ${basePackage}.frame.excel.annotation.ExcelSheet;
/** /**
* VISITOR - * VISITOR -
@ -13,39 +13,39 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1 * @version 0.0.1
* @since 2020-06-25 * @since 2020-06-25
*/ */
@SheetName("应用接入") @ExcelSheet("应用接入")
public class Visitor extends BaseEntity { public class Visitor extends BaseEntity {
/** /**
* APP_NAME - * APP_NAME -
*/ */
@ColumnName("应用名称") @ExcelProperty("应用名称")
@ColumnDescription("") @ExcelNote("")
private String appName; private String appName;
/** /**
* APP_NOTE - * APP_NOTE -
*/ */
@ColumnName("应用简介") @ExcelProperty("应用简介")
@ColumnDescription("") @ExcelNote("")
private String appNote; private String appNote;
/** /**
* APP_KEY - * APP_KEY -
*/ */
@ColumnName("应用码") @ExcelProperty("应用码")
@ColumnDescription("") @ExcelNote("")
private String appKey; private String appKey;
/** /**
* APP_SECRET - * APP_SECRET -
*/ */
@ColumnName("安全码") @ExcelProperty("安全码")
@ColumnDescription("") @ExcelNote("")
private String appSecret; private String appSecret;
/** /**
* VALID - * VALID -
*/ */
@ColumnName("是否有效") @ExcelProperty("是否有效")
@ColumnDescription("") @ExcelNote("")
@ColumnList({"是","否"}) @ExcelSelect({"是","否"})
private Boolean valid; private Boolean valid;
public String getAppName() { public String getAppName() {

@ -1,28 +1,27 @@
package ${basePackage}; package ${basePackage};
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ${basePackage}.frame.excel.DemoData;
import ${basePackage}.frame.excel.WExcel; import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException; import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.AESUtil; import ${basePackage}.frame.utils.AESUtil;
import ${basePackage}.frame.utils.Base64Util; import ${basePackage}.frame.utils.Base64Util;
import ${basePackage}.frame.utils.IDgenerator; import ${basePackage}.frame.utils.IDgenerator;
import ${basePackage}.frame.utils.MD5Util; import ${basePackage}.frame.utils.MD5Util;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.ProcessUtil; import ${basePackage}.frame.utils.ProcessUtil;
import ${basePackage}.frame.utils.RSAUtil; import ${basePackage}.frame.utils.RSAUtil;
import ${basePackage}.frame.utils.ZipUtil; import ${basePackage}.frame.utils.ZipUtil;
import ${basePackage}.module.system.ent.Dept;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -119,47 +118,45 @@ public class UtilTest {
} }
@Test @Test
public void testExcel() { public void testExcel() throws IOException, TemplateNotMatchException {
// 准备导出数据 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Dept dept = new Dept(); System.out.println("数据创建开始:" + dateFormat.format(new Date()));
dept.setDeptCode("A000101"); // 写
dept.setDeptName("人事部"); List<DemoData> visitors = new ArrayList<>();
dept.setDeptAlias("人事部"); for (int i = 0; i < 100; i++) {
dept.setSupCode("A0001"); DemoData demoData = new DemoData();
dept.setSupName("董事会"); demoData.setStr1("我是标题Str1" + i);
dept.setValid(true); demoData.setStr2("我是标题Str2" + i);
ArrayList<Dept> depts = new ArrayList<Dept>(); demoData.setStr3("我是标题Str3" + i);
depts.add(dept); demoData.setStr4("我是标题Str4" + i);
demoData.setSint((short) 1);
// 设置文件地址及导出 demoData.setMint(1);
try { demoData.setLint(1L);
File file = new File("E:\\E.xlsx"); demoData.setDbn(0.01);
new WExcel<Dept>(Dept.class).loadData(depts).toFile(file); demoData.setFln(0.01f);
} catch (IOException e) { demoData.setDate(new Date());
e.printStackTrace(); demoData.setValid(i % 5 == 0);
visitors.add(demoData);
} }
System.out.println("数据创建完成:" + dateFormat.format(new Date()));
new WExcel<>(DemoData.class).addDatas(visitors, null).toFile(new File("D:\\xx.xlsx"));
System.out.println("数据导出完成:" + dateFormat.format(new Date()));
// 导入数据 System.out.println();
try {
File file = new File("E:\\E.xlsx"); // 读
WExcel.Processor<Dept> processor = new WExcel.Processor<Dept>() { System.out.println("数据导入开始:" + dateFormat.format(new Date()));
@Override WExcel<DemoData> wExcel = new WExcel<>(DemoData.class).read(new File("D:\\xx.xlsx"), (demoData, index) -> {
public List<String> exec(Dept o) { if (index % 50 == 0) {
System.out.println("从Excel中读取对象:" + MapperUtil.toJson(o)); return Arrays.asList("测试,第" + index + "条有错误");
return Arrays.asList("模拟处理对象业务时出现的错误信息1","模拟处理对象业务时出现的错误信息2");
}
};
WExcel check = new WExcel<Dept>(Dept.class).loadData(file, processor);
if (check.hasError()) {
System.out.println("导入或处理有错误.");
check.toFile(new File("E:\\E_err.xlsx"));
} }
} catch (TemplateNotMatchException e) { return null;
Assert.assertTrue("导入文件与模板不匹配,请重新下载模板!", false); });
} catch (ReadErrorException e) { System.out.println("数据导入完成:" + dateFormat.format(new Date()));
Assert.assertTrue("导入文件错误,请检查格式或文件是否被破坏!", false); System.out.println();
} catch (IOException e) { System.out.println("错误导出开始:" + dateFormat.format(new Date()));
Assert.assertTrue("读取错误!", false); wExcel.toFile(new File("D:\\xx-err.xlsx"));
} System.out.println("错误导出结束:" + dateFormat.format(new Date()));
System.out.println();
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.