Commit ef029db4 authored by yanzg's avatar yanzg

接口文档的支持

parent edc89a28
......@@ -55,6 +55,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
* @param downFileName 下载文件名
*/
public ExcelHttp down(HttpServletResponse response, String downFileName) throws IOException {
if (StringHelper.isEmpty(downFileName)) {
downFileName = this.getConfig().getDownFileName();
}
if (StringHelper.isEmpty(downFileName)) {
downFileName = this.getConfig().getFileName();
}
......@@ -70,12 +73,24 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
* @param excelDao dao层实现接口
*/
public static <T extends Object, M extends Object> void export(ExportBase<T> req, HttpServletResponse response, ExcelDao<T, M> excelDao) {
ExcelHttp<M> excel = new ExcelHttp<>(req.getConfig());
ExportData config = req.getConfig();
if (config == null) {
throw new CodeException("导出时请传入配置信息");
}
if (StringHelper.isEmpty(config.getServerPath())) {
config.setServerPath("/home/cache/");
}
if (StringHelper.isEmpty(config.getFileName())) {
config.setFileName(String.format("%s.xlsx", StringHelper.getNewID()));
}
if (StringHelper.isEmpty(config.getDownFileName())) {
config.setDownFileName(String.format("%s-%s.xlsx", config.getTitle(), config.getSubTitle()));
}
ExcelHttp<M> excel = new ExcelHttp<>(config);
try {
excel.open();
excelDao.export(excel, req.getCond());
excel.save();
excel.down(response);
} catch (IOException e) {
e.printStackTrace();
......
package com.yanzuoguang.excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 导出数据
*
* @param <T>
* @author 颜佐光
*/
@ApiModel(description = "订单导出基本请求信息")
public class ExportBase<T extends Object> {
/**
* 导出格式
*/
@ApiModelProperty(notes = "导出格式配置信息", required = true)
private ExportData config;
/**
* 查询条件
*/
@ApiModelProperty(notes = "查询条件", required = true)
private T cond;
public ExportData getConfig() {
......
package com.yanzuoguang.excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
......@@ -8,58 +11,85 @@ import java.util.List;
*
* @author 颜佐光
*/
@ApiModel(description = "订单导出数据配置信息")
public class ExportData {
@ApiModelProperty(notes = "行默认高度")
public static final short ROW_HEIGHT_UNIT = 10;
@ApiModelProperty(notes = "标题默认高度")
public static final short TITLE_HEIGHT = 80;
@ApiModelProperty(notes = "子标题默认高度")
public static final short SUB_TITLE_HEIGHT = 40;
@ApiModelProperty(notes = "头默认高度")
public static final short HEAD_HEIGHT = 20;
@ApiModelProperty(notes = "行默认高度")
public static final short ROW_HEIGHT = 20;
@ApiModelProperty(notes = "列默认宽度")
public static final short COLUMN_WIDTH = 120;
/**
* 服务器保存路径
*/
@ApiModelProperty(notes = "服务器保存路径")
private String serverPath;
/**
* 文件名
*/
@ApiModelProperty(notes = "文件名")
private String fileName;
/**
* 下载文件名
*/
@ApiModelProperty(notes = "下载文件名")
private String downFileName;
/**
* 标题
*/
@ApiModelProperty(notes = "标题")
private String title;
/**
* 标题高度
*/
@ApiModelProperty(notes = "标题高度")
private short titleHeight;
/**
* 子标题
*/
@ApiModelProperty(notes = "子标题")
private String subTitle;
/**
* 子标题高度
*/
@ApiModelProperty(notes = "子标题高度")
private short subTitleHeight;
/**
* 列标题高度
*/
@ApiModelProperty(notes = "列标题高度")
private short headHeight;
/**
* 行高度
*/
@ApiModelProperty(notes = "行高度")
private short rowHeight;
/**
* 包含列
*/
@ApiModelProperty(notes = "包含列")
private List<ExportColumn> columns = new ArrayList<>();
public String getServerPath() {
......@@ -78,6 +108,14 @@ public class ExportData {
this.fileName = fileName;
}
public String getDownFileName() {
return downFileName;
}
public void setDownFileName(String downFileName) {
this.downFileName = downFileName;
}
public String getTitle() {
return title;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment