Skip to content

Commit

Permalink
Merge pull request pingfangushi#52 from lvchaogit/master
Browse files Browse the repository at this point in the history
扩展Execute类,用户可自定义查询器,生成文档
  • Loading branch information
leshalv committed Nov 30, 2021
2 parents 70bc83a + 29004d1 commit 39b939b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import cn.smallbun.screw.core.exception.BuilderException;
import cn.smallbun.screw.core.metadata.model.DataModel;
import cn.smallbun.screw.core.process.DataModelProcess;
import cn.smallbun.screw.core.query.DatabaseQuery;
import cn.smallbun.screw.core.util.ExceptionUtils;

/**
* 文档生成
*
* @author SanLi
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:51
* @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:51
*/
public class DocumentationExecute extends AbstractExecute {

Expand All @@ -42,6 +42,22 @@ public DocumentationExecute(Configuration config) {
*
* @throws BuilderException BuilderException
*/
@Override
public void execute(DatabaseQuery query) throws BuilderException {
try {
long start = System.currentTimeMillis();
//处理数据
DataModel dataModel = new DataModelProcess(config).process(query);
//产生文档
TemplateEngine produce = new EngineFactory(config.getEngineConfig()).newInstance();
produce.produce(dataModel, getDocName(dataModel.getDatabase()));
logger.debug("database document generation complete time consuming:{}ms",
System.currentTimeMillis() - start);
} catch (Exception e) {
throw ExceptionUtils.mpe(e);
}
}

@Override
public void execute() throws BuilderException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@
*/
package cn.smallbun.screw.core.execute;

import cn.smallbun.screw.core.query.DatabaseQuery;

/**
* 执行文档生成
*
* @author SanLi
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:38
* @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1 22:38
*/
public interface Execute {
/**
* 执行生成
*/
void execute();

/**
* 执行生成
* @param query 自定义查询器
*/
void execute(DatabaseQuery query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package cn.smallbun.screw.core.process;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.metadata.Column;
import cn.smallbun.screw.core.metadata.Database;
Expand All @@ -29,11 +33,10 @@
import cn.smallbun.screw.core.query.DatabaseQueryFactory;
import cn.smallbun.screw.core.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static cn.smallbun.screw.core.constant.DefaultConstants.*;
import static cn.smallbun.screw.core.constant.DefaultConstants.N;
import static cn.smallbun.screw.core.constant.DefaultConstants.Y;
import static cn.smallbun.screw.core.constant.DefaultConstants.ZERO;
import static cn.smallbun.screw.core.constant.DefaultConstants.ZERO_DECIMAL_DIGITS;

/**
* 数据模型处理
Expand Down Expand Up @@ -61,6 +64,18 @@ public DataModelProcess(Configuration configuration) {
public DataModel process() {
//获取query对象
DatabaseQuery query = new DatabaseQueryFactory(config.getDataSource()).newInstance();

return this.process(query);
}

/**
* 处理
*
* @return {@link DataModel}
*/
@Override
public DataModel process(DatabaseQuery query) {
//获取query对象
DataModel model = new DataModel();
//Title
model.setTitle(config.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
package cn.smallbun.screw.core.process;

import cn.smallbun.screw.core.metadata.model.DataModel;

import java.io.Serializable;

import cn.smallbun.screw.core.metadata.model.DataModel;
import cn.smallbun.screw.core.query.DatabaseQuery;

/**
* 构建
*
* @author SanLi
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/3/22 21:08
* @author SanLi Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/3/22 21:08
*/
public interface Process extends Serializable {
/**
Expand All @@ -35,4 +35,12 @@ public interface Process extends Serializable {
* @throws Exception Exception
*/
DataModel process() throws Exception;

/**
* 自定义处理
* @param query 自定义查询器
* @return {@link DataModel}
* @throws Exception Exception
*/
DataModel process(DatabaseQuery query) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import cn.smallbun.screw.core.exception.ScrewException;
import cn.smallbun.screw.core.execute.Execute;
import cn.smallbun.screw.core.query.DatabaseQuery;
import cn.smallbun.screw.core.util.ExceptionUtils;
import cn.smallbun.screw.core.util.StringUtils;
import cn.smallbun.screw.extension.pojo.PojoConfiguration;
Expand Down Expand Up @@ -89,6 +90,11 @@ public void execute() {
}
}

@Override
public void execute(DatabaseQuery query) {

}

private String validate(PojoConfiguration config) {
StringBuilder error = new StringBuilder();
String separator = System.lineSeparator();
Expand Down

0 comments on commit 39b939b

Please sign in to comment.