master
wangbing 5 years ago
parent 989ce9462d
commit e0f06eb14f

@ -643,6 +643,7 @@ public class SpringBootCallable implements Callable {
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ResponseUtil.java"), option + "/java/frame/utils/ResponseUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/frame/utils/RSAUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/frame/utils/RSAUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "StringUtil.java"), option + "/java/frame/utils/StringUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "StringUtil.java"), option + "/java/frame/utils/StringUtil.java", ctx);
freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ValidationUtil.java"), option + "/java/frame/utils/ValidationUtil.java", ctx); freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ValidationUtil.java"), option + "/java/frame/utils/ValidationUtil.java", ctx);

@ -2,10 +2,21 @@ package ${basePackage}.action.ajax.${module};
import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.module.${module}.mgr.${table.getCName()}Manager; import ${basePackage}.module.${module}.mgr.${table.getCName()}Manager;
import ${basePackage}.module.${module}.ent.${table.getCName()};
import ${basePackage}.module.${module}.req.*; import ${basePackage}.module.${module}.req.*;
import ${basePackage}.module.${module}.rsp.*; import ${basePackage}.module.${module}.rsp.*;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WSheet;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public class ${table.getCName()}Ajax{ public class ${table.getCName()}Ajax{
@ -13,84 +24,75 @@ public class ${table.getCName()}Ajax{
private ${table.getCName()}Manager ${table.getFName()}Manager; private ${table.getCName()}Manager ${table.getFName()}Manager;
<#if table.getCreate()> <#if table.getCreate()>
public ${table.getCName()}CreateResponse create(String jsonParam) { public ${table.getCName()}CreateResponse create(TreeNode jsonParam) {
${table.getCName()}CreateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}CreateRequest.class); ${table.getCName()}CreateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}CreateRequest.class);
return ${table.getFName()}Manager.create(request, LocalData.getToken()); return ${table.getFName()}Manager.create(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getDelete()> <#if table.getDelete()>
public ${table.getCName()}DeleteResponse delete(String jsonParam) { public ${table.getCName()}DeleteResponse delete(TreeNode jsonParam) {
${table.getCName()}DeleteRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}DeleteRequest.class); ${table.getCName()}DeleteRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}DeleteRequest.class);
return ${table.getFName()}Manager.delete(request, LocalData.getToken()); return ${table.getFName()}Manager.delete(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getUpdate()> <#if table.getUpdate()>
public ${table.getCName()}UpdateResponse update(String jsonParam) { public ${table.getCName()}UpdateResponse update(TreeNode jsonParam) {
${table.getCName()}UpdateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}UpdateRequest.class); ${table.getCName()}UpdateRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}UpdateRequest.class);
return ${table.getFName()}Manager.update(request, LocalData.getToken()); return ${table.getFName()}Manager.update(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getFind()> <#if table.getFind()>
public ${table.getCName()}FindResponse find(String jsonParam) { public ${table.getCName()}FindResponse find(TreeNode jsonParam) {
${table.getCName()}FindRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}FindRequest.class); ${table.getCName()}FindRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}FindRequest.class);
return ${table.getFName()}Manager.find(request, LocalData.getToken()); return ${table.getFName()}Manager.find(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getGet()> <#if table.getGet()>
public ${table.getCName()}GetResponse get(String jsonParam) { public ${table.getCName()}GetResponse get(TreeNode jsonParam) {
${table.getCName()}GetRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetRequest.class); ${table.getCName()}GetRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetRequest.class);
return ${table.getFName()}Manager.get(request, LocalData.getToken()); return ${table.getFName()}Manager.get(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getSearch()> <#if table.getSearch()>
public ${table.getCName()}SearchResponse search(String jsonParam) { public ${table.getCName()}SearchResponse search(TreeNode jsonParam) {
${table.getCName()}SearchRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}SearchRequest.class); ${table.getCName()}SearchRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}SearchRequest.class);
return ${table.getFName()}Manager.search(request, LocalData.getToken()); return ${table.getFName()}Manager.search(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getGetAll()> <#if table.getGetAll()>
public ${table.getCName()}GetAllResponse getAll(String jsonParam) { public ${table.getCName()}GetAllResponse getAll(TreeNode jsonParam) {
${table.getCName()}GetAllRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetAllRequest.class); ${table.getCName()}GetAllRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}GetAllRequest.class);
return ${table.getFName()}Manager.getAll(request, LocalData.getToken()); return ${table.getFName()}Manager.getAll(request, LocalData.getToken());
} }
</#if> </#if>
<#if table.getHtml()> <#if table.getHtml()>
public Object template(){ public Object template(){
try { return ResponseUtil.apply(new WSheet<>(${table.getCName()}.class));
WSheet<DictItemCreateRequest> sheet = new WSheet<>(DictItemCreateRequest.class);
byte[] bytes = sheet.getBytes();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + ".xlsx","utf-8"));
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
} catch (IOException e) {
BaseResponse baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "");
return baseResponse;
} }
public Object exports(TreeNode jsonParam) {
${table.getCName()}FindRequest request = MapperUtil.toJava(jsonParam, ${table.getCName()}FindRequest.class);
${table.getCName()}FindResponse response = ${table.getFName()}Manager.find(request, LocalData.getToken());
if (response.hasError()) {
return response;
}
return ResponseUtil.apply(new WSheet<>(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
byte[] bytes = file.getBytes(); WSheet<${table.getCName()}> sheet = new WSheet<>(file.getBytes(), ${table.getCName()}.class);
WSheet<DictCreateRequest> sheet = new WSheet<>(bytes, DictCreateRequest.class);
if (sheet.hasError()) { if (sheet.hasError()) {
byte[] sheetBytes = sheet.getBytes(true); return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-err.xlsx");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + "-err.xlsx","utf-8"));
return new ResponseEntity<>(sheetBytes, headers, HttpStatus.OK);
} else { } else {
return baseResponse; return baseResponse;
} }
@ -99,7 +101,6 @@ public class ${table.getCName()}Ajax{
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException | ReadErrorException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;
} }
</#if> </#if>

@ -1,25 +1,22 @@
package ${basePackage}.action.ajax.system; package ${basePackage}.action.ajax.system;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import ${basePackage}.frame.auth.LocalData; import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WSheet; import ${basePackage}.frame.excel.WSheet;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.module.system.ent.Dict;
import ${basePackage}.module.system.mgr.DictManager; import ${basePackage}.module.system.mgr.DictManager;
import ${basePackage}.module.system.req.*; import ${basePackage}.module.system.req.*;
import ${basePackage}.module.system.rsp.*; import ${basePackage}.module.system.rsp.*;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
public class DictAjax { public class DictAjax {
@ -57,33 +54,25 @@ public class DictAjax {
} }
public Object template(){ public Object template(){
try { return ResponseUtil.apply(new WSheet<>(Dict.class));
WSheet<DictCreateRequest> sheet = new WSheet<>(DictCreateRequest.class);
byte[] bytes = sheet.getBytes();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + ".xlsx","utf-8"));
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
} catch (IOException e) {
BaseResponse baseResponse = new BaseResponse();
baseResponse.addError(ErrorType.BUSINESS_ERROR, "");
return baseResponse;
} }
public Object exports(TreeNode jsonParam) {
DictFindRequest request = MapperUtil.toJava(jsonParam, DictFindRequest.class);
DictFindResponse response = dictManager.find(request, LocalData.getToken());
if (response.hasError()) {
return response;
}
return ResponseUtil.apply(new WSheet<>(response.getResult()));
} }
public Object imports(MultipartFile file) { public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse(); BaseResponse baseResponse = new BaseResponse();
try { try {
byte[] bytes = file.getBytes(); WSheet<Dict> sheet = new WSheet<>(file.getBytes(), Dict.class);
WSheet<DictCreateRequest> sheet = new WSheet<>(bytes, DictCreateRequest.class);
if (sheet.hasError()) { if (sheet.hasError()) {
byte[] sheetBytes = sheet.getBytes(true); return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-err.xlsx");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(sheet.getName() + "-err.xlsx","utf-8"));
return new ResponseEntity<>(sheetBytes, headers, HttpStatus.OK);
} else { } else {
return baseResponse; return baseResponse;
} }
@ -92,7 +81,6 @@ public class DictAjax {
} catch (TemplateNotMatchException | ReadErrorException e) { } catch (TemplateNotMatchException | ReadErrorException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage()); baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
} }
return baseResponse; return baseResponse;
} }
} }

@ -43,7 +43,6 @@ public class WColumn implements Serializable {
public WColumn() { public WColumn() {
this.name = ""; this.name = "";
this.cellWidth = 1; this.cellWidth = 1;
this.isHidden = false;
this.isRequired = false; this.isRequired = false;
this.description = ""; this.description = "";
} }
@ -51,7 +50,6 @@ public class WColumn implements Serializable {
public WColumn(String name) { public WColumn(String name) {
this.name = name; this.name = name;
this.cellWidth = 1; this.cellWidth = 1;
this.isHidden = false;
this.isRequired = false; this.isRequired = false;
this.description = ""; this.description = "";
} }
@ -83,14 +81,6 @@ public class WColumn implements Serializable {
this.cellWidth = cellWidth; this.cellWidth = cellWidth;
} }
public boolean isHidden() {
return isHidden;
}
public void setHidden(boolean isHidden) {
this.isHidden = isHidden;
}
public boolean isRequired() { public boolean isRequired() {
return isRequired; return isRequired;
} }

@ -5,6 +5,7 @@ import ${basePackage}.frame.excel.style.ErrorCellStyle;
import ${basePackage}.frame.excel.style.HeadCellStyle; import ${basePackage}.frame.excel.style.HeadCellStyle;
import ${basePackage}.frame.excel.style.RedFont; import ${basePackage}.frame.excel.style.RedFont;
import ${basePackage}.frame.utils.ClassUtil; import ${basePackage}.frame.utils.ClassUtil;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.StringUtil; import ${basePackage}.frame.utils.StringUtil;
import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.annotation.*; import ${basePackage}.frame.excel.annotation.*;
@ -79,12 +80,13 @@ public class WSheet<T> implements Serializable, Cloneable {
boolean parentFirst = clazz.isAnnotationPresent(ParentFirst.class) && clazz.getAnnotation(ParentFirst.class).value(); boolean parentFirst = clazz.isAnnotationPresent(ParentFirst.class) && clazz.getAnnotation(ParentFirst.class).value();
Field[] fields = ClassUtil.getFields(clazz, parentFirst); Field[] fields = ClassUtil.getFields(clazz, parentFirst);
for (Field field : fields) { for (Field field : fields) {
WColumn WColumn = new WColumn();
WColumn.setField(field);
if (field.isAnnotationPresent(Ignore.class) && field.getAnnotation(Ignore.class).value()) { if (field.isAnnotationPresent(Ignore.class) && field.getAnnotation(Ignore.class).value()) {
WColumn.setHidden(true); continue;
} }
WColumn WColumn = new WColumn();
WColumn.setField(field);
//获取列名称 //获取列名称
if (!field.isAnnotationPresent(ColumnName.class)) { if (!field.isAnnotationPresent(ColumnName.class)) {
WColumn.setName(field.getName()); WColumn.setName(field.getName());
@ -164,7 +166,7 @@ public class WSheet<T> implements Serializable, Cloneable {
* @throws InvocationTargetException * @throws InvocationTargetException
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public WSheet(List<T> list) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { public WSheet(List<T> list) {
if (list == null || list.size() == 0) { if (list == null || list.size() == 0) {
throw new RuntimeException("不允许传入空的列表"); throw new RuntimeException("不允许传入空的列表");
} }
@ -185,8 +187,13 @@ public class WSheet<T> implements Serializable, Cloneable {
method = t.getClass().getMethod("get" + att); method = t.getClass().getMethod("get" + att);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
// 尝试获取is方法工具生成布尔值可能是is而不是get // 尝试获取is方法工具生成布尔值可能是is而不是get
try {
method = t.getClass().getMethod("is" + att); method = t.getClass().getMethod("is" + att);
} catch (NoSuchMethodException e1) {
LogUtil.w(field.getName()+"can not find get method");
} }
}
try {
Object value = method.invoke(t); Object value = method.invoke(t);
if (null == value) { if (null == value) {
row.put(column.getName(), new WCell()); row.put(column.getName(), new WCell());
@ -194,6 +201,11 @@ public class WSheet<T> implements Serializable, Cloneable {
String string = column.getConverter().string(value); String string = column.getConverter().string(value);
row.put(column.getName(), new WCell(string)); row.put(column.getName(), new WCell(string));
} }
} catch (IllegalAccessException e) {
LogUtil.w( "can not invoke get method!");
} catch (InvocationTargetException e) {
LogUtil.w(method.getName() + " unexpected exception!");
}
} }
this.rowList.add(row); this.rowList.add(row);
} }
@ -210,6 +222,10 @@ public class WSheet<T> implements Serializable, Cloneable {
* 2:<br/> * 2:<br/>
*/ */
public WSheet(byte[] bytes, Class<T> clazz) throws TemplateNotMatchException, ReadErrorException { public WSheet(byte[] bytes, Class<T> clazz) throws TemplateNotMatchException, ReadErrorException {
this(bytes, clazz, null);
}
public WSheet(byte[] bytes, Class<T> clazz, Validator validator) throws TemplateNotMatchException, ReadErrorException {
Workbook workbook = null; Workbook workbook = null;
InputStream is = null; InputStream is = null;
boolean flag; boolean flag;
@ -301,6 +317,7 @@ public class WSheet<T> implements Serializable, Cloneable {
try { try {
T t = transferOneObject(clazz, i); T t = transferOneObject(clazz, i);
List<String> validate = ValidationUtil.validate(t); List<String> validate = ValidationUtil.validate(t);
validate.addAll(validator != null ? validator.validate(t) : null);
if (validate.size() > 0) { if (validate.size() > 0) {
for (String s : validate) { for (String s : validate) {
row.addError(s); row.addError(s);
@ -335,11 +352,6 @@ public class WSheet<T> implements Serializable, Cloneable {
} }
for (int j = 0; j < this.columnList.size(); j++) { for (int j = 0; j < this.columnList.size(); j++) {
WColumn wColumn = this.columnList.get(0);
if (wColumn.isHidden()) {
continue;
}
String key = this.columnList.get(j).getName(); String key = this.columnList.get(j).getName();
for (WColumn column : columnList) { for (WColumn column : columnList) {
@ -458,21 +470,19 @@ public class WSheet<T> implements Serializable, Cloneable {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public byte[] getBytes() throws IOException { public byte[] getBytes() {
XSSFWorkbook workbook = getExcel(false); return getBytes(false);
if (workbook != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workbook.write(outputStream);
return outputStream.toByteArray();
}
return null;
} }
public byte[] getBytes(boolean checkResult) throws IOException { public byte[] getBytes(boolean checkResult) {
XSSFWorkbook workbook = getExcel(checkResult); XSSFWorkbook workbook = getExcel(checkResult);
if (workbook != null) { if (workbook != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
workbook.write(outputStream); workbook.write(outputStream);
} catch (IOException e) {
return null;
}
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
return null; return null;
@ -601,4 +611,8 @@ public class WSheet<T> implements Serializable, Cloneable {
return cell.getStringCellValue(); return cell.getStringCellValue();
} }
} }
public interface Validator<T> {
List<String> validate(T t);
}
} }

@ -5,10 +5,11 @@ import java.lang.reflect.Method;
import java.util.*; import java.util.*;
/** /**
* Created on 2015/5/28. * ClassUtil
* *
* @author * @author wangbing
* @version 2.1.0 * @version 0.0.1
* @since 2017-01-01
*/ */
public class ClassUtil { public class ClassUtil {
@ -20,31 +21,13 @@ public class ClassUtil {
* @return * @return
*/ */
public static Field[] getFields(Class clazz, boolean parentFirst) { public static Field[] getFields(Class clazz, boolean parentFirst) {
List<Field> returnList = new ArrayList<>();
Set<String> nameSet = new HashSet<>();
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
returnList.add(field);
nameSet.add(field.getName());
}
List<Field> parentList = getParentFields(clazz.getSuperclass(), nameSet, parentFirst);
if (parentFirst) { if (parentFirst) {
parentList.addAll(returnList); Field[] parentFields = getParentFields(clazz.getSuperclass());
returnList = parentList; return concat(fields, parentFields);
} else {
returnList.addAll(parentList);
}
fields = new Field[returnList.size()];
int index = 0;
for (Field field : returnList) {
fields[index++] = field;
} }
return fields; return fields;
} }
/** /**
@ -115,12 +98,6 @@ public class ClassUtil {
return pojoClass.getMethod(getMethodName.toString(), type); return pojoClass.getMethod(getMethodName.toString(), type);
} }
/**
* java
*
* @param field
* @return
*/
public static boolean isJavaClass(Field field) { public static boolean isJavaClass(Field field) {
Class<?> fieldType = field.getType(); Class<?> fieldType = field.getType();
boolean isBaseClass = false; boolean isBaseClass = false;
@ -136,37 +113,23 @@ public class ClassUtil {
return isBaseClass; return isBaseClass;
} }
/**
*
*
* @param clazz
* @return
*/
public static Field[] getFields(Class clazz) { public static Field[] getFields(Class clazz) {
return getFields(clazz, false); return getFields(clazz, false);
} }
private static List<Field> getParentFields(Class parentClazz, Set<String> nameSet, boolean parentFirst) { private static Field[] getParentFields(Class parentClazz) {
List<Field> fieldList = new ArrayList<>();
if (parentClazz != null) { if (parentClazz != null) {
Field[] parentList = parentClazz.getDeclaredFields(); Field[] fields = parentClazz.getDeclaredFields();
int index = 0; Field[] parentFields = getParentFields(parentClazz.getSuperclass());
for (Field field : parentList) { return concat(fields, parentFields);
int beginSize = nameSet.size();
nameSet.add(field.getName());
int endSize = nameSet.size();
if (endSize > beginSize) {
if (parentFirst) {
fieldList.add(index++, field);
} else {
fieldList.add(field);
}
}
} }
fieldList.addAll(getParentFields(parentClazz.getSuperclass(), nameSet, parentFirst)); return new Field[0];
} }
return fieldList;
private static Field[] concat(Field[] f1, Field[] f2) {
Field[] fields = new Field[f1.length + f2.length];
System.arraycopy(f1, 0, fields, 0, f1.length);
System.arraycopy(f2, 0, fields, f1.length, f2.length);
return fields;
} }
} }

@ -1,6 +1,5 @@
package ${basePackage}.frame.utils; package ${basePackage}.frame.utils;
/** /**
* Message - * Message -
* *

@ -0,0 +1,42 @@
package ${basePackage}.frame.utils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import ${basePackage}.frame.excel.WSheet;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Base64Util
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class ResponseUtil {
/**
* ResponseEntity
*
* @param bytes
* @param fileName
* @return
*/
public static ResponseEntity<byte[]> apply(byte[] bytes, String fileName) {
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", URLEncoder.encode(fileName, "utf-8"));
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
} catch (UnsupportedEncodingException e) {
return null;
}
}
public static ResponseEntity<byte[]> apply(WSheet sheet) {
return apply(sheet.getBytes(), sheet.getName() + ".xlsx");
}
}

@ -404,21 +404,18 @@
onSelectionChange: function (select) { onSelectionChange: function (select) {
this.select = select; this.select = select;
}, },
excelTemplate: function () { selectExcel: function () {
this.$ajax.template(this.module, this.target, {});
},
excelSelect: function () {
this.$refs['excel'].dispatchEvent(new MouseEvent('click')) this.$refs['excel'].dispatchEvent(new MouseEvent('click'))
}, },
excelImport: function (item) { onTemplate: function () {
this.$ajax.template(this.module, this.target, {});
},
onImport: function (item) {
const file = item.target.files[0]; const file = item.target.files[0];
this.$ajax.imports(this.module, this.target, file).then(function (response) { this.$ajax.imports(this.module, this.target, file);
if (response.errors.length > 0) { },
this.e(response.errors[0].message); onExport: function () {
} else { this.$ajax.exports(this.module, this.target, this.vm);
this.i("文件上传成功!");
}
}.bind(this))
}, },
onSave: function () { onSave: function () {
this.$refs['form'].validate(function (valid) { this.$refs['form'].validate(function (valid) {

@ -18,9 +18,9 @@
<el-card class="box-card"> <el-card class="box-card">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增 <el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增</el-button>
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button> <el-button type="warning" size="small" icon="el-icon-download" @click="onExport">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog"> <el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px"> <el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
@ -42,13 +42,13 @@
<el-col :span="12"> <el-col :span="12">
<el-button-group style="float: right;"> <el-button-group style="float: right;">
<el-tooltip effect="dark" content="Excel模板下载" placement="bottom"> <el-tooltip effect="dark" content="Excel模板下载" placement="bottom">
<el-button size="small" icon="el-icon-date" @click="excelTemplate"></el-button> <el-button size="small" icon="el-icon-date" @click="onTemplate"></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip effect="dark" content="Excel导入" placement="bottom"> <el-tooltip effect="dark" content="Excel导入" placement="bottom">
<el-button size="small" @click="excelSelect"> <el-button size="small" @click="selectExcel">
<i class="el-icon-upload2"> <i class="el-icon-upload2">
<input type="file" style="display: none" @change="excelImport($event)" ref="excel"> <input type="file" style="display: none" @change="onImport($event)" ref="excel">
</i> </i>
</el-button> </el-button>
</el-tooltip> </el-tooltip>

@ -24,10 +24,9 @@
<el-card class="box-card"> <el-card class="box-card">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增 <el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增</el-button>
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button> <el-button type="warning" size="small" icon="el-icon-download" @click="onExport">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog"> <el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px"> <el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
@ -60,13 +59,13 @@
<el-col :span="12"> <el-col :span="12">
<el-button-group style="float: right;"> <el-button-group style="float: right;">
<el-tooltip effect="dark" content="Excel模板下载" placement="bottom"> <el-tooltip effect="dark" content="Excel模板下载" placement="bottom">
<el-button size="small" icon="el-icon-date" @click="excelTemplate"></el-button> <el-button size="small" icon="el-icon-date" @click="onTemplate"></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip effect="dark" content="Excel导入" placement="bottom"> <el-tooltip effect="dark" content="Excel导入" placement="bottom">
<el-button size="small" @click="excelSelect"> <el-button size="small" @click="selectExcel">
<i class="el-icon-upload2"> <i class="el-icon-upload2">
<input type="file" style="display: none" @change="excelImport($event)" ref="excel"> <input type="file" style="display: none" @change="onImport($event)" ref="excel">
</i> </i>
</el-button> </el-button>
</el-tooltip> </el-tooltip>

@ -27,10 +27,9 @@
<el-card class="box-card"> <el-card class="box-card">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-button type="success" size="small" icon="el-icon-plus" @click="onCreate(['create',''])">新增 <el-button type="success" size="small" icon="el-icon-plus" @click="onCreate">新增</el-button>
</el-button>
<el-button type="warning" size="small" icon="el-icon-download">导出</el-button> <el-button type="warning" size="small" icon="el-icon-download" @click="onExport">导出</el-button>
<el-dialog class="form" :title="form.title" :visible.sync="form.dialog"> <el-dialog class="form" :title="form.title" :visible.sync="form.dialog">
<el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px"> <el-form :model="form" :inline="true" :rules="formRules" ref="form" label-width="90px">
@ -58,13 +57,13 @@
<el-col :span="12"> <el-col :span="12">
<el-button-group style="float: right;"> <el-button-group style="float: right;">
<el-tooltip effect="dark" content="Excel模板下载" placement="bottom"> <el-tooltip effect="dark" content="Excel模板下载" placement="bottom">
<el-button size="small" icon="el-icon-date" @click="excelTemplate"></el-button> <el-button size="small" icon="el-icon-date" @click="onTemplate"></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip effect="dark" content="Excel导入" placement="bottom"> <el-tooltip effect="dark" content="Excel导入" placement="bottom">
<el-button size="small" @click="excelSelect"> <el-button size="small" @click="selectExcel">
<i class="el-icon-upload2"> <i class="el-icon-upload2">
<input type="file" style="display: none" @change="excelImport($event)" ref="excel"> <input type="file" style="display: none" @change="onImport($event)" ref="excel">
</i> </i>
</el-button> </el-button>
</el-tooltip> </el-tooltip>

Loading…
Cancel
Save

Powered by TurnKey Linux.