Commit d012835a by 钟明宏

重构代码,保存一下代码

parent 29ccd0cf
/**
*
*/
package cn.yunmaozj.tools.excel.core.utils;
package cn.yunmaozj.tools.excel.core;
import java.io.OutputStream;
import java.util.Collection;
/**
* excel 导出工具
* excel 导出接口
*
* @author Administrator
*/
......
package cn.yunmaozj.tools.excel.core;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 21:26
*/
public interface ReadRowHandler<T> {
/**
* 将一行数据转换成实体类
*
* @param row
* @param rowData
* @return
*/
T convertEntity(int row, List<String> rowData);
}
package cn.yunmaozj.tools.excel.core.readers;
import cn.yunmaozj.tools.excel.core.ExcelReader;
import org.apache.poi.ss.usermodel.Workbook;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 21:35
*/
public abstract class AbstractExcelReader implements ExcelReader {
private Workbook workbook;
public AbstractExcelReader(Workbook workbook) {
this.workbook = workbook;
}
}
package cn.yunmaozj.tools.excel.core.readers;
import cn.yunmaozj.tools.excel.core.ExcelReader;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* 一个默认的excel导入工具
*
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 21:33
*/
public class DefaultExcelReader extends AbstractExcelReader {
public DefaultExcelReader(InputStream is) throws IOException {
super(new XSSFWorkbook(is));
}
/**
* 读取指定工作薄的内容
*
* @param sheetIndex
* @param clazz
* @return
*/
@Override
public <T> List<T> read(int sheetIndex, Class<T> clazz) {
return null;
}
}
package cn.yunmaozj.tools.excel.core.readers;
import cn.yunmaozj.tools.excel.core.ReadRowHandler;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
/**
* 默认的行处理器
*
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 21:38
*/
public class DefaultRowHandler<T> implements ReadRowHandler<T> {
/**
* 将一行数据转换成实体类
*
* @param row
* @param rowData
* @return
*/
@Override
public T convertEntity(int row, List<String> rowData) {
return null;
}
}
......@@ -3,25 +3,14 @@
*/
package cn.yunmaozj.tools.excel.core.utils.abs;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import cn.yunmaozj.tools.excel.core.utils.ExcelWriter;
import cn.yunmaozj.tools.excel.core.utils.ValueSelector;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import cn.yunmaozj.tools.excel.core.ExcelWriter;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* @author Administrator 导出可以 使用json数据 对于类也要转换成这样的List<List<Object>>
......
package cn.yunmaozj.tools.excel.database;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 20:55
*/
public interface DDL {
/**
* 生成创建的ddl文本
*
* @param dataBaseTableModel
* @return
*/
String generateDDLText(DataBaseTableModel dataBaseTableModel);
/**
* 将数据库字段生成模型对象
*
* @return
*/
DataBaseTableModel generateDataBaseTableModel(String table);
}
package cn.yunmaozj.tools.excel.database;
import cn.yunmaozj.tools.excel.core.Excel;
import cn.yunmaozj.tools.excel.core.annotation.ExcelTitleRow;
import java.util.List;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 16:36
*/
public class DataBaseTableModel {
/**
* 表名
*/
private String tableName;
/**
* 备注
*/
private String comment;
/**
* 存储引擎
*/
private String engine;
/**
* 表字符集
*/
private String charset;
/**
* 表的字段集
*/
private List<Column> columns;
public DataBaseTableModel(String tableName, String comment, String engine, String charset, List<Column> columns) {
this.tableName = tableName;
this.comment = comment;
this.engine = engine;
this.charset = charset;
this.columns = columns;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getEngine() {
return engine;
}
public void setEngine(String engine) {
this.engine = engine;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public List<Column> getColumns() {
return columns;
}
public void setColumns(List<Column> columns) {
this.columns = columns;
}
/**
* 表字段
*/
public static class Column {
@ExcelTitleRow("字段名")
private String name;
@ExcelTitleRow("数据类型")
private String type;
@ExcelTitleRow("备注")
private String comment;
@ExcelTitleRow("字符集")
private String charset;
@ExcelTitleRow("是否可以为空")
private boolean isNull;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public boolean isNull() {
return isNull;
}
public void setNull(boolean aNull) {
isNull = aNull;
}
}
}
......@@ -14,6 +14,18 @@ import java.io.OutputStream;
*/
public class ExcelToMysqlDDL implements ExcelToDDL {
private String url;
private String driver;
private String username;
private String password;
public ExcelToMysqlDDL(String url, String driver, String username, String password) {
this.url = url;
this.driver = driver;
this.username = username;
this.password = password;
}
/**
* @param in excel 输入流
* @param out ddl 输出流
......
package cn.yunmaozj.tools.excel.database.mysql;
import cn.yunmaozj.tools.excel.database.DDL;
import cn.yunmaozj.tools.excel.database.DataBaseTableModel;
import static cn.yunmaozj.tools.excel.database.DataBaseTableModel.*;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 20:58
*/
public class MysqlDDL implements DDL {
/**
* 生成创建的ddl文本
*
* @param dataBaseTableModel
* @return
*/
@Override
public String generateDDLText(DataBaseTableModel dataBaseTableModel) {
StringBuilder content = new StringBuilder();
content.append("DROP TABLE IF EXISTS ").append("'")
.append(dataBaseTableModel.getTableName()).append("'").append("\n");
content.append("CREATE TABLE ").append("'")
.append(dataBaseTableModel.getTableName()).append("'").append(" (\n");
for (Column column : dataBaseTableModel.getColumns()) {
content.append("'").append(column.getName()).append("'").append(" ")
.append(column.getType()).append(" CHARACTER SET ").append(column.getCharset())
.append(" COMMENT ").append("'").append(column.getComment()).append("'").append(",\n");
}
content.append(")\n");
return content.toString();
}
/**
* 将数据库字段生成模型对象
*
* @param table
* @return
*/
@Override
public DataBaseTableModel generateDataBaseTableModel(String table) {
return null;
}
}
package cn.yunmaozj.tools.excel.database.mysql;
import cn.yunmaozj.tools.excel.AbstractExcelToolsTest;
import org.junit.Before;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 20:51
*/
public class ExcelToMysqlDDLTest extends AbstractExcelToolsTest {
/**
* 先创建一个 excel
*/
@Before
public void setUp() {
}
}
package cn.yunmaozj.tools.excel.database.mysql;
import cn.yunmaozj.tools.excel.AbstractExcelToolsTest;
import org.junit.Test;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-15 21:08
*/
public class MysqlDDLTest extends AbstractExcelToolsTest {
@Test
public void generatorDDLText(){
}
}
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 sign in to comment