Commit 6fac8380 authored by 赵啸非's avatar 赵啸非

修改部分生成代码逻辑

parent cde02a3d
...@@ -4,8 +4,10 @@ import com.mortals.framework.model.BaseEntityLong; ...@@ -4,8 +4,10 @@ import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.common.utils.StringUtils; import com.mortals.xhx.common.utils.StringUtils;
import lombok.Data; import lombok.Data;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* Description:Gentable * Description:Gentable
...@@ -23,6 +25,9 @@ public class GentableEntityExt extends BaseEntityLong { ...@@ -23,6 +25,9 @@ public class GentableEntityExt extends BaseEntityLong {
* 子表信息 * 子表信息
*/ */
private GentableEntity subTable; private GentableEntity subTable;
private String requestMapping;
/** /**
* 表列信息 * 表列信息
*/ */
......
...@@ -46,6 +46,8 @@ import java.util.stream.Collectors; ...@@ -46,6 +46,8 @@ import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import static com.mortals.xhx.common.utils.GenUtils.getBusinessNameExt;
/** /**
* <p>Title: 代码生成业务表</p> * <p>Title: 代码生成业务表</p>
* <p>Description: GentableService service接口 </p> * <p>Description: GentableService service接口 </p>
...@@ -166,17 +168,16 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -166,17 +168,16 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
if (temp.equals("enum.java.ftl")) { if (temp.equals("enum.java.ftl")) {
continue; continue;
} }
if (temp.equals("api.md.ftl")) { if (temp.equals("api.md.ftl")) {
continue; continue;
} }
if (temp.equals("api-two.md.ftl")) { // if (temp.equals("api-two.md.ftl")) {
continue; // continue;
} // }
if (temp.equals("apidict.md.ftl")) { // if (temp.equals("apidict.md.ftl")) {
continue; // continue;
} // }
try { try {
//初始化freeMarkers //初始化freeMarkers
FreeMarkerUtils.initFreeMarker(genFreePath(temp)); FreeMarkerUtils.initFreeMarker(genFreePath(temp));
...@@ -206,19 +207,31 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -206,19 +207,31 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
@SneakyThrows @SneakyThrows
@Override @Override
public byte[] downloadCode(Long tableId, String genTypes) { public byte[] downloadCode(Long tableId, String genTypes) {
List<GentableEntity> tableList = new ArrayList<>();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
FreeMarkerUtils.menuSql = new StringBuilder(); // FreeMarkerUtils.menuSql = new StringBuilder();
FreeMarkerUtils.paramsSql = new StringBuilder(); // FreeMarkerUtils.paramsSql = new StringBuilder();
FreeMarkerUtils.dbSql = new StringBuilder(); // FreeMarkerUtils.dbSql = new StringBuilder();
FreeMarkerUtils.apimd = new StringBuilder(); // FreeMarkerUtils.apimd = new StringBuilder();
FreeMarkerUtils.apitwomd = new StringBuilder(); // FreeMarkerUtils.apitwomd = new StringBuilder();
FreeMarkerUtils.apidict = new StringBuilder(); // FreeMarkerUtils.apidict = new StringBuilder();
FreeMarkerUtils.apidict.append("## 字典附录\n"); // FreeMarkerUtils.apidict.append("## 字典附录\n");
FreeMarkerUtils.apimd.append(headStr); // FreeMarkerUtils.apimd.append(headStr);
FreeMarkerUtils.apitwomd.append(headStr); // FreeMarkerUtils.apitwomd.append(headStr);
generatorCode(tableId, genTypes, zip); GentableEntity gentableEntity = generatorCode(tableId, genTypes, zip);
if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) { tableList.add(gentableEntity);
Map data = new HashMap();
data.put("tableList", tableList);
FreeMarkerUtils.initFreeMarker(genFreePath("menu.sql.ftl"));
zipTemplate("menu.sql.ftl","db/menu.sql",data,zip);
zipTemplate("db.sql.ftl","db/db.sql",data,zip);
FreeMarkerUtils.initFreeMarker(genFreePath("api.md.ftl"));
zipTemplate("api.md.ftl","doc/api.md",data,zip);
/*if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) {
zip.putNextEntry(new ZipEntry("db/menu.sql")); zip.putNextEntry(new ZipEntry("db/menu.sql"));
IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8); IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8);
} }
...@@ -236,14 +249,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -236,14 +249,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
} }
if (StringUtils.isNotEmpty(FreeMarkerUtils.apitwomd)) { if (StringUtils.isNotEmpty(FreeMarkerUtils.apitwomd)) {
zip.putNextEntry(new ZipEntry("doc/api-two.md")); // zip.putNextEntry(new ZipEntry("doc/api-two.md"));
zip.putNextEntry(new ZipEntry("doc/api.md"));
IOUtils.write(FreeMarkerUtils.apitwomd.toString(), zip, Constant.UTF8); IOUtils.write(FreeMarkerUtils.apitwomd.toString(), zip, Constant.UTF8);
} }
if (StringUtils.isNotEmpty(FreeMarkerUtils.apidict)) { if (StringUtils.isNotEmpty(FreeMarkerUtils.apidict)) {
zip.putNextEntry(new ZipEntry("doc/dict.md")); zip.putNextEntry(new ZipEntry("doc/dict.md"));
IOUtils.write(FreeMarkerUtils.apidict.toString(), zip, Constant.UTF8); IOUtils.write(FreeMarkerUtils.apidict.toString(), zip, Constant.UTF8);
} }*/
IOUtils.closeQuietly(zip); IOUtils.closeQuietly(zip);
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
...@@ -251,23 +265,78 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -251,23 +265,78 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
@SneakyThrows @SneakyThrows
@Override @Override
public byte[] downloadCode(Long[] tableIds, String genTypes) { public byte[] downloadCode(Long[] tableIds, String genTypes) {
FreeMarkerUtils.menuSql = new StringBuilder(); List<GentableEntity> tableList = new ArrayList<>();
FreeMarkerUtils.dbSql = new StringBuilder(); // FreeMarkerUtils.menuSql = new StringBuilder();
FreeMarkerUtils.paramsSql = new StringBuilder(); // FreeMarkerUtils.dbSql = new StringBuilder();
FreeMarkerUtils.apimd = new StringBuilder(); // FreeMarkerUtils.paramsSql = new StringBuilder();
FreeMarkerUtils.apitwomd = new StringBuilder(); // FreeMarkerUtils.apimd = new StringBuilder();
FreeMarkerUtils.apidict = new StringBuilder(); // FreeMarkerUtils.apitwomd = new StringBuilder();
FreeMarkerUtils.apidict.append("## 字典附录\n"); // FreeMarkerUtils.apidict = new StringBuilder();
FreeMarkerUtils.apimd.append(headStr); // FreeMarkerUtils.apidict.append("## 字典附录\n");
FreeMarkerUtils.apitwomd.append(headStr); // FreeMarkerUtils.apimd.append(headStr);
// FreeMarkerUtils.apitwomd.append(headStr);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream); ZipOutputStream zip = new ZipOutputStream(outputStream);
for (Long tableId : tableIds) { for (Long tableId : tableIds) {
generatorCode(tableId, genTypes, zip); GentableEntity gentableEntity = generatorCode(tableId, genTypes, zip);
tableList.add(gentableEntity);
} }
Map data = new HashMap();
data.put("tableList", tableList);
FreeMarkerUtils.initFreeMarker(genFreePath("menu.sql.ftl"));
zipTemplate("menu.sql.ftl","db/menu.sql",data,zip);
zipTemplate("db.sql.ftl","db/db.sql",data,zip);
FreeMarkerUtils.initFreeMarker(genFreePath("api.md.ftl"));
zipTemplate("api.md.ftl","doc/api.md",data,zip);
/* try {
StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw);
zip.putNextEntry(new ZipEntry("db/menu.sql"));
IOUtils.write(sw.toString(), zip, Constant.UTF8);
if (template.getName().equals("menu.sql.ftl")) {
FreeMarkerUtils.menuSql.append(sw.toString());
} else if (template.getName().equals("db.sql.ftl")) {
FreeMarkerUtils.dbSql.append(sw.toString());
} else if (template.getName().equals("params.sql.ftl")) {
FreeMarkerUtils.paramsSql.append(sw.toString());
} else if (template.getName().equals("api.md.ftl")) {
FreeMarkerUtils.apimd.append(sw.toString());
} else if (template.getName().equals("api-two.md.ftl")) {
FreeMarkerUtils.apitwomd.append(sw.toString());
} else if (template.getName().equals("apidict.md.ftl")) {
FreeMarkerUtils.apidict.append(sw.toString() + "\n");
} else {
zip.putNextEntry(new ZipEntry(FreeMarkerUtils.getFileName(template.getName(), gentableEntity)));
IOUtils.write(sw.toString(), zip, Constant.UTF8);
}
IOUtils.closeQuietly(sw);
zip.flush();
zip.closeEntry();
} catch (Exception e) {
log.error("渲染模板失败,表名:" + gentableEntity.getTableName(), e);
}
zip.putNextEntry(new ZipEntry("db/menu.sql"));
StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw);
if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) { if (StringUtils.isNotEmpty(FreeMarkerUtils.menuSql)) {
zip.putNextEntry(new ZipEntry("db/menu.sql")); zip.putNextEntry(new ZipEntry("db/menu.sql"));
StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw);
IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8); IOUtils.write(FreeMarkerUtils.menuSql.toString(), zip, Constant.UTF8);
} }
if (StringUtils.isNotEmpty(FreeMarkerUtils.dbSql)) { if (StringUtils.isNotEmpty(FreeMarkerUtils.dbSql)) {
...@@ -290,7 +359,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -290,7 +359,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
zip.putNextEntry(new ZipEntry("doc/api-two.md")); zip.putNextEntry(new ZipEntry("doc/api-two.md"));
IOUtils.write(FreeMarkerUtils.apitwomd.toString(), zip, Constant.UTF8); IOUtils.write(FreeMarkerUtils.apitwomd.toString(), zip, Constant.UTF8);
} }*/
// if (StringUtils.isNotEmpty(FreeMarkerUtils.apidict)) { // if (StringUtils.isNotEmpty(FreeMarkerUtils.apidict)) {
...@@ -302,10 +371,21 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -302,10 +371,21 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
private void zipTemplate(String temp, String zipPath, Map data, ZipOutputStream zip) {
try {
StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw);
zip.putNextEntry(new ZipEntry(zipPath));
IOUtils.write(sw.toString(), zip, Constant.UTF8);
} catch (Exception e) {
log.error("异常", e);
}
}
@Override @Override
public void synchDb(Long tableId) { public void synchDb(Long tableId) {
GentableEntity table = this.get(tableId); GentableEntity table = this.get(tableId);
List<GentableColumnEntity> tableColumns = gentableColumnService.find(new GentableColumnQuery().tableId(table.getId())); List<GentableColumnEntity> tableColumns = gentableColumnService.find(new GentableColumnQuery().tableId(table.getId()));
table.setColumns(tableColumns); table.setColumns(tableColumns);
...@@ -371,7 +451,6 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -371,7 +451,6 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
@Override @Override
public void importDoc(MultipartFile file, Long appId, Context context) { public void importDoc(MultipartFile file, Long appId, Context context) {
List<GentableEntity> tableList = ReadDoc.readWord(file); List<GentableEntity> tableList = ReadDoc.readWord(file);
String operName = context.getUser().getLoginName(); String operName = context.getUser().getLoginName();
try { try {
...@@ -433,20 +512,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -433,20 +512,15 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
@Override @Override
public void crateTableBySql(String tableSql, Context context) { public void crateTableBySql(String tableSql, Context context) {
Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*.*?\\*/"); Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*.*?\\*/");
tableSql = p.matcher(tableSql).replaceAll("$1"); tableSql = p.matcher(tableSql).replaceAll("$1");
log.info("去除注释后的sql:" + tableSql); log.info("去除注释后的sql:" + tableSql);
//校验部分命令 禁止使用 比如清库的 //校验部分命令 禁止使用 比如清库的
// if(tableSql.indexOf("")!=-1){ // if(tableSql.indexOf("")!=-1){
// throw new AppException("禁止使用"); // throw new AppException("禁止使用");
// } // }
List<String> list = StrUtil.splitTrim(tableSql, ";".charAt(0), -1); List<String> list = StrUtil.splitTrim(tableSql, ";".charAt(0), -1);
list.stream().filter(f -> !ObjectUtils.isEmpty(f)).peek(item -> { list.stream().filter(f -> !ObjectUtils.isEmpty(f)).peek(item -> {
log.info("sql:" + item); log.info("sql:" + item);
this.getDao().createTable(item); this.getDao().createTable(item);
...@@ -457,7 +531,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -457,7 +531,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
/** /**
* 查询表信息并生成代码 * 查询表信息并生成代码
*/ */
private void generatorCode(Long tableId, String genTypes, ZipOutputStream zip) { private GentableEntity generatorCode(Long tableId, String genTypes, ZipOutputStream zip) {
GentableEntity gentableEntity = this.get(tableId); GentableEntity gentableEntity = this.get(tableId);
Set<String> types = StrUtil.splitTrim(genTypes, ",".charAt(0), -1).stream().collect(Collectors.toSet()); Set<String> types = StrUtil.splitTrim(genTypes, ",".charAt(0), -1).stream().collect(Collectors.toSet());
if (!ObjectUtils.isEmpty(gentableEntity)) { if (!ObjectUtils.isEmpty(gentableEntity)) {
...@@ -470,11 +544,12 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -470,11 +544,12 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
}).collect(Collectors.toList()); }).collect(Collectors.toList());
gentableEntity.setColumns(columnEntities); gentableEntity.setColumns(columnEntities);
// 设置主子表信息 // 设置主子表信息
setSubTable(gentableEntity); setSubTable(gentableEntity);
// 设置主键列信息 // 设置主键列信息
setPkColumn(gentableEntity); setPkColumn(gentableEntity);
String requestMapping = Arrays.stream(getBusinessNameExt(gentableEntity.getTableName()).split("\\.")).collect(Collectors.joining("/"));
gentableEntity.setRequestMapping(requestMapping);
//生成模板基础数据 //生成模板基础数据
Map data = FreeMarkerUtils.prepareSetFreeMarkerData(gentableEntity); Map data = FreeMarkerUtils.prepareSetFreeMarkerData(gentableEntity);
...@@ -488,14 +563,12 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -488,14 +563,12 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
continue; continue;
} }
} }
//通过模板生成不同的业务类 //通过模板生成不同的业务类
if (temp.equals("enum.java.ftl")) { if (temp.equals("enum.java.ftl")) {
//单独生成枚举类 //单独生成枚举类
List<GentableColumnEntity> collect = gentableEntity.getColumns().stream() List<GentableColumnEntity> collect = gentableEntity.getColumns().stream()
.filter(f -> f.getDict() != null) .filter(f -> f.getDict() != null)
.map(item -> { .map(item -> {
Map enumData = FreeMarkerUtils.prepareSetFreeMarkerDataByEnum(item.getDict(), item.getColumnComment(), item.getColumnName(), item.getJavaType()); Map enumData = FreeMarkerUtils.prepareSetFreeMarkerDataByEnum(item.getDict(), item.getColumnComment(), item.getColumnName(), item.getJavaType());
try { try {
FreeMarkerUtils.initFreeMarker(genFreePath(temp)); FreeMarkerUtils.initFreeMarker(genFreePath(temp));
...@@ -521,14 +594,28 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -521,14 +594,28 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
continue; continue;
} }
//restBody模式 不加载web,webForm模式
if (gentableEntity.getIsShowControl() == 2) {
if (temp.contains("web.java.ftl") || temp.contains("webForm.java.ftl")) {
continue;
}
}
if (temp.equals("menu.sql.ftl")) {
continue;
}
if (temp.equals("db.sql.ftl")) {
continue;
}
if (temp.equals("api.md.ftl")) {
continue;
}
try { try {
FreeMarkerUtils.initFreeMarker(genFreePath(temp)); FreeMarkerUtils.initFreeMarker(genFreePath(temp));
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Template template = FreeMarkerUtils.getTemplate(temp); Template template = FreeMarkerUtils.getTemplate(temp);
template.process(data, sw); template.process(data, sw);
// 添加到zip // 添加到zip
if (template.getName().equals("menu.sql.ftl")) { /* if (template.getName().equals("menu.sql.ftl")) {
FreeMarkerUtils.menuSql.append(sw.toString()); FreeMarkerUtils.menuSql.append(sw.toString());
} else if (template.getName().equals("db.sql.ftl")) { } else if (template.getName().equals("db.sql.ftl")) {
FreeMarkerUtils.dbSql.append(sw.toString()); FreeMarkerUtils.dbSql.append(sw.toString());
...@@ -541,9 +628,10 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -541,9 +628,10 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
} else if (template.getName().equals("apidict.md.ftl")) { } else if (template.getName().equals("apidict.md.ftl")) {
FreeMarkerUtils.apidict.append(sw.toString() + "\n"); FreeMarkerUtils.apidict.append(sw.toString() + "\n");
} else { } else {
zip.putNextEntry(new ZipEntry(FreeMarkerUtils.getFileName(template.getName(), gentableEntity)));
IOUtils.write(sw.toString(), zip, Constant.UTF8); }*/
} zip.putNextEntry(new ZipEntry(FreeMarkerUtils.getFileName(template.getName(), gentableEntity)));
IOUtils.write(sw.toString(), zip, Constant.UTF8);
IOUtils.closeQuietly(sw); IOUtils.closeQuietly(sw);
zip.flush(); zip.flush();
...@@ -552,8 +640,8 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -552,8 +640,8 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
log.error("渲染模板失败,表名:" + gentableEntity.getTableName(), e); log.error("渲染模板失败,表名:" + gentableEntity.getTableName(), e);
} }
} }
} }
return gentableEntity;
} }
/** /**
...@@ -585,7 +673,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -585,7 +673,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
ByteArrayOutputStream byteArrayOutputStream = null; ByteArrayOutputStream byteArrayOutputStream = null;
try { try {
ClassPathResource classPathResource = new ClassPathResource("template/doc/base.docx"); ClassPathResource classPathResource = new ClassPathResource("template/doc/base.docx");
template = XWPFTemplate.compile( classPathResource.getInputStream(), config).render(data); template = XWPFTemplate.compile(classPathResource.getInputStream(), config).render(data);
byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream = new ByteArrayOutputStream();
template.write(byteArrayOutputStream); template.write(byteArrayOutputStream);
return byteArrayOutputStream.toByteArray(); return byteArrayOutputStream.toByteArray();
......
...@@ -74,18 +74,15 @@ public class FreeMarkerUtils { ...@@ -74,18 +74,15 @@ public class FreeMarkerUtils {
*/ */
@SneakyThrows @SneakyThrows
public static void initFreeMarkerPath(String templatePath) { public static void initFreeMarkerPath(String templatePath) {
//初始化模板引擎 //初始化模板引擎
cfg = new Configuration(Configuration.VERSION_2_3_29); cfg = new Configuration(Configuration.VERSION_2_3_29);
cfg.setDirectoryForTemplateLoading(new File(templatePath)); cfg.setDirectoryForTemplateLoading(new File(templatePath));
//设置字符编码集 //设置字符编码集
cfg.setDefaultEncoding("UTF-8"); cfg.setDefaultEncoding("UTF-8");
//设置异常的处理方式 //设置异常的处理方式
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
//设置输出时间格式 //设置输出时间格式
cfg.setDateFormat("yyyy-MM-dd HH:mm:ss"); cfg.setDateFormat("yyyy-MM-dd HH:mm:ss");
} }
...@@ -102,16 +99,16 @@ public class FreeMarkerUtils { ...@@ -102,16 +99,16 @@ public class FreeMarkerUtils {
templates.add("entityQuery.java.ftl"); templates.add("entityQuery.java.ftl");
templates.add("dao.java.ftl"); templates.add("dao.java.ftl");
templates.add("daoImpl.java.ftl"); templates.add("daoImpl.java.ftl");
// templates.add("web.java.ftl"); templates.add("web.java.ftl");
templates.add("webBody.java.ftl"); templates.add("webBody.java.ftl");
templates.add("webForm.java.ftl"); templates.add("webForm.java.ftl");
templates.add("sqlMap.xml.ftl"); templates.add("sqlMap.xml.ftl");
templates.add("db.sql.ftl"); templates.add("db.sql.ftl");
templates.add("menu.sql.ftl"); templates.add("menu.sql.ftl");
templates.add("params.sql.ftl"); // templates.add("params.sql.ftl");
templates.add("api.md.ftl"); templates.add("api.md.ftl");
templates.add("api-two.md.ftl"); // templates.add("api-two.md.ftl");
templates.add("apidict.md.ftl"); // templates.add("apidict.md.ftl");
templates.add("httpclient.test.ftl"); templates.add("httpclient.test.ftl");
if (GenConstants.TPL_CRUD.equals(tplCategory)) { if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add("service.java.ftl"); templates.add("service.java.ftl");
...@@ -168,11 +165,9 @@ public class FreeMarkerUtils { ...@@ -168,11 +165,9 @@ public class FreeMarkerUtils {
* @return 模板列表 * @return 模板列表
*/ */
public static Map prepareSetFreeMarkerData(GentableEntity genTable) { public static Map prepareSetFreeMarkerData(GentableEntity genTable) {
Map data = new HashMap(); Map data = new HashMap();
String moduleName = genTable.getModuleName(); String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName().replace("\\.", ""); String businessName = genTable.getBusinessName().replace("\\.", "");
String packageName = genTable.getPackageName() + "." + moduleName + "." + businessName; String packageName = genTable.getPackageName() + "." + moduleName + "." + businessName;
String tplCategory = genTable.getTplCategory(); String tplCategory = genTable.getTplCategory();
String functionName = genTable.getFunctionName(); String functionName = genTable.getFunctionName();
...@@ -435,9 +430,9 @@ public class FreeMarkerUtils { ...@@ -435,9 +430,9 @@ public class FreeMarkerUtils {
} else if (template.contains("serviceImpl-tree.java.ftl")) { } else if (template.contains("serviceImpl-tree.java.ftl")) {
fileName = StringUtils.format("{}/{}/service/impl/{}ServiceImpl.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/service/impl/{}ServiceImpl.java", javaPath, businessName, className);
} }
// else if (template.contains("web.java.ftl")) { else if (template.contains("web.java.ftl")) {
// fileName = StringUtils.format("{}/{}/web/{}Controller.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/web/{}Controller.java", javaPath, businessName, className);
// } }
else if (template.contains("webBody.java.ftl")) { else if (template.contains("webBody.java.ftl")) {
fileName = StringUtils.format("{}/{}/web/{}Controller.java", javaPath, businessName, className); fileName = StringUtils.format("{}/{}/web/{}Controller.java", javaPath, businessName, className);
} }
......
## ${functionName}
### 查询${functionName}列表
**请求URL:** ${RequestMapping}/list
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 查询${functionName}
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:---|:---
page|Integer|否|当前页
size|Integer|否|每页条数,值为-1,查询所有记录
<#list columns as column>
<#if column.isQuery == 1>
<#if column.javaType=="String" >
${column.javaField}|${column.javaType}|${column.columnComment}|否|字段前后添加%%模糊查询
<#else>
${column.javaField}|${column.javaType}|${column.columnComment}|否|-
</#if>
</#if>
</#list>
**请求样例:**
```
{
<#list columns as column>
<#if column.isQuery == 1>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
"page":1,
"size":10
}
```
**响应参数:**
参数名称|参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
&emsp;per_page|Integer|每页条数
&emsp;total|Integer|总条数
&emsp;last_page|Integer|总页数
&emsp;current_page|Integer|当前页
&emsp;data|array|结果集列表|数组
<#list columns as column>
&emsp;&emsp;${column.javaField}|${column.javaType}|${column.columnComment}
</#list>
dict|object|字典对象
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&emsp;${column.javaField}|object|字典属性对象,详见附录
</#if>
</#list>
**响应消息样例:**
```
{
"code":1,
"data":{
}
}
```
### 查看${functionName}
**请求URL:** ${RequestMapping}/info
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 查看${functionName},返回实例详细信息
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
${pkColumn.javaField}|${pkColumn.javaType}|是|ID
**请求样例:**
```
http://localhost/${RequestMapping}/info?id=549
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:-------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
<#list columns as column>
&emsp;${column.javaField}|${column.javaType}|${column.columnComment}
</#list>
dict|object|字典对象
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&emsp;${column.javaField}|object|字典属性对象,详见附录
</#if>
</#list>
**响应消息样例:**
```
{
"code": 1,
"data": {
<#list columns as column>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#list>
}
}
```
### 保存更新${functionName}
**请求URL:** ${RequestMapping}/save
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 保存或更新${functionName}:id为空时为新增保存,否则为更新提交
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:-------
<#list columns as column>
<#if !column.isSuperColumn(column.javaField)>
${column.javaField}|${column.javaType}|是|${column.columnComment}
</#if>
</#list>
**请求样例:**
```
{
<#list columns as column>
<#if !column.isSuperColumn(column.javaField)>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
}
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
&emsp;id|Long|保存后主键id
&emsp;entity|object|保存更新实体
<#list columns as column>
&emsp;&emsp;${column.javaField}|${column.javaType}|${column.columnComment}
</#list>
**响应消息样例:**
```
{
"msg":"新增模块成功",
"code":1,
"data":{}
}
}
```
### 删除${functionName}
**请求URL:** ${RequestMapping}/delete
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除${functionName}
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
${pkColumn.javaField}|String|是|数组
**请求样例:**
```
http://localhost:8080/${RequestMapping}/delete?id=1&id=2'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
<#if table.isGenExport==1 >
### 导入${functionName}模板下载
**请求URL:** ${RequestMapping}/downloadTemplate
**请求方式:** POST
**内容类型:** application/octet-stream;charset=utf-8
**简要描述:** ${functionName}导入模板下载
**请求样例:**
```
http://localhost/${RequestMapping}/downloadTemplate
```
**Response-example:**
```
...
```
### 导入${functionName}
**请求URL:** ${RequestMapping}/importData
**请求方式:** POST
**内容类型:** multipart/form-data
**简要描述:** 导入${functionName}
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
file|file|是|文件流
**请求样例:**
```
http://localhost/${RequestMapping}/importData --data 'updateSupport=true'
```
**Response-example:**
```
...
```
### 导出${functionName}
**请求URL:** ${RequestMapping}/exportExcel
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 导出${functionName}
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
idList|Arrays|否|id数组
<#list columns as column>
<#if column.isQuery == 1>
${column.javaField}|${column.javaType}|${column.columnComment}|否|参数查询条件
</#if>
</#list>
**请求样例:**
```
{
idList:[1,2],
<#list columns as column>
<#if column.isQuery == 1>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
}
```
**Response-example:**
```
...
```
</#if>
# 服务平台
版本 | 创建时间 | 作者 | 备注信息
---|---|---|---
v1.0|2022-01-20|zxfei| 接口文档
## 数据类型
类型名称|类型描述|参考样例
---|---|---
String |字符串|A、a、ab
Integer|数字类型|1、12、-1
Long|长整型数字|1、12、-1
date|时间类型,单位纳秒数字|167988745573
BigDecimal|小数类型|545.256
object|对象类型|{"name":"zhang3"}
arrays|数组类型|[{"name":"zhang3"},{"name":"zhang2"}]
## ${functionName}服务接口 <#list tableList as table>
### 查询${functionName}列表 ## ${table.functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/list
**Type:** POST ### 查询${table.functionName}列表
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **请求URL:** ${table.requestMapping}/list
**Description:** 查询${functionName} **请求方式:** POST
**Query-parameters:** **内容类型:** application/json;charset=utf-8
参数名称|类型|备注|必填|其它 **简要描述:** 查询${table.functionName}
---|---|---|---|---
pageInfo|object|分页对象|否|- **请求参数:**
└─beginIndex|Integer|开始记录序号|否|-
└─prePageResult|Integer|每页条数|否|- 参数名称|类型|必填|描述
└─totalResult|Integer|总条数|否|- :---|:---|:---|:------
└─totalPage|Integer|总页数|否|- page|Integer|否|当前页
└─currPage|Integer|当前页|否|- size|Integer|否|每页条数,值为-1,查询所有记录
└─displayPageSize|Integer|显示页数量|否|- <#list table.columns as column>
└─hasNextPage|Boolean|是否有下一页|否|- <#if column.isQuery == 1>
└─hasPrePage|Boolean|是否有前一页|否|- <#if column.javaType=="String" >
└─lastRecordKey|String|最后一条|否|- ${column.javaField}|${column.javaType}|否|${column.columnComment},字段前后添加%%模糊查询
└─countPage|Boolean|是否计算总页数|否|- <#else>
query|object|查询对象|否|- ${column.javaField}|${column.javaType}|否|${column.columnComment}
<#list columns as column> </#if>
└─${column.javaField}|${column.javaType}|${column.columnComment}|否|- </#if>
</#list>
<#list columns as column>
<#if column.javaType == "Long"||column.javaType == "Integer"||column.javaType == "BigDecimal">
└─${column.javaField}Start|${column.javaType}|大于 > ${column.columnComment}|否|-
└─${column.javaField}End|${column.javaType}|小于 < ${column.columnComment}|否|-
└─${column.javaField}List|array|${column.columnComment}列表|否|-
</#if>
<#if column.javaType == "String">
└─${column.javaField}List|array|${column.columnComment}列表|否|-
</#if>
<#if column.javaType == "Date">
└─${column.javaField}Start|${column.javaType}|大于 > ${column.columnComment}|否|-
└─${column.javaField}End|${column.javaType}|小于 < ${column.columnComment}|否|-
</#if>
</#list> </#list>
**请求样例:** **请求样例:**
``` ```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/list --data 'query.id=1' {
<#list table.columns as column>
<#if column.isQuery == 1>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
"page":1,
"size":10
}
``` ```
**响应参数:** **响应参数:**
参数名称 |参数类型|备注|其它 参数名称|参数类型|描述
---|---|---|--- :---|:---|:------
code|Integer|结果码(0.失败,1.成功)|- code|Integer|结果码(-1.失败,1.成功)
msg|String|消息|- msg|String|消息
data|object|数据对象|- data|object|数据对象
└─result|array|结果集列表|数组 &emsp;per_page|Integer|每页条数
<#list columns as column> &emsp;total|Integer|总条数
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|- &emsp;last_page|Integer|总页数
&emsp;current_page|Integer|当前页
&emsp;data|array|结果集列表|数组
<#list table.columns as column>
&emsp;&emsp;${column.javaField}|${column.javaType}|${column.columnComment}
</#list> </#list>
└─pageInfo|object|分页对象|- dict|object|字典对象
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─beginIndex|Integer|开始记录序号|- <#list table.columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─prePageResult|Integer|每页条数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─totalResult|Integer|总条数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─totalPage|Integer|总页数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─currPage|Integer|当前页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─displayPageSize|Integer|显示页数量|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─hasNextPage|Boolean|是否有下一页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─hasPrePage|Boolean|是否有前一页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─lastRecordKey|String|最后一条|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─countPage|Boolean|是否计算总页数|-
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)> <#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|- &emsp;${column.javaField}|object|字典属性对象,详见附录
</#if> </#if>
</#list> </#list>
└─query|object|查询时候返回的查询列表参数对象|-
**响应消息样例:** **响应消息样例:**
``` ```
{ {
"code":1, "code":1,
"data":{ "data":{
"result":[
{
"appId":6,
"businessName":"device",
}
],
"pageInfo":{
"currPage":1,
"prePageResult":200,
"totalPage":1,
"totalResult":16
},
"dict":{
"dividedTableType":{
"0":"无",
"1":"日"
}
}
},
"query":{
"appId":6
} }
} }
``` ```
### 编辑${functionName} ### 查看${table.functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/edit
**Type:** POST **请求URL:** ${table.requestMapping}/info
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **请求方式:** GET
**Description:** 编辑${functionName},返回实例详细信息 **内容类型:** application/json;charset=utf-8
**Query-parameters:** **简要描述:** 查看${table.functionName},返回实例详细信息
参数名称|类型|备注|必填|其它 **请求参数:**
---|---|---|---|---
${pkColumn.javaField}|array|实例主键ID,数组形式|是|- 参数名称|类型|必填|描述
:---|:---|:---|:------
${table.pkColumn.javaField}|${table.pkColumn.javaType}|是|ID
**请求样例:** **请求样例:**
``` ```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/edit --data 'id=[1]' http://localhost/${table.requestMapping}/info?id=549
``` ```
**响应参数:** **响应参数:**
参数名称 |参数类型|备注|其它 参数名称 |参数类型|描述
---|---|---|--- :---|:---|:-------
code|Integer|结果码(0.失败,1.成功)|- code|Integer|结果码(-1.失败,1.成功)
msg|String|消息|- msg|String|消息
data|object|数据对象|- data|object|数据对象
└─entity|object|对象实体|对象 <#list table.columns as column>
<#list columns as column> &emsp;${column.javaField}|${column.javaType}|${column.columnComment}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list> </#list>
└─dict|object|字典对象|- dict|object|字典对象
<#list columns as column> <#list table.columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)> <#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|- &emsp;${column.javaField}|object|字典属性对象,详见附录
</#if> </#if>
</#list> </#list>
**响应消息样例:** **响应消息样例:**
``` ```
{ {
"code":1, "code": 1,
"data":{ "data": {
"dict":{ <#list table.columns as column>
"interimExcuteStatus":{ <#if column.javaType=="String" ||column.javaType=="Date">
"0":"未启用", <#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
"1":"立即执行并保留" <#else>
} <#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
}, </#if>
"entity":{ "${column.javaField}":${fakeValue}<#sep>,</#sep>
"createTime":1628737643000, </#list>
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
} }
}
} }
``` ```
### 保存更新${functionName} ### 保存更新${table.functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/save
**Type:** POST **请求URL:** ${table.requestMapping}/save
**请求方式:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **内容类型:** application/json;charset=utf-8
**Description:** 保存或更新${functionName}:id为空时为新增保存,否则为更新提交 **简要描述:** 保存或更新${table.functionName}:id为空时为新增保存,否则为更新提交
**Query-parameters:** **请求参数:**
参数名称|类型|备注|必填|其它 参数名称|类型|必填|描述
---|---|---|---|--- :---|:---|:---|:-------
entity|object|实体对象|是|- <#list table.columns as column>
<#list columns as column>
<#if !column.isSuperColumn(column.javaField)> <#if !column.isSuperColumn(column.javaField)>
└─${column.javaField}|${column.javaType}|${column.columnComment}|是|- ${column.javaField}|${column.javaType}|是|${column.columnComment}
</#if> </#if>
</#list> </#list>
**请求样例:** **请求样例:**
``` ```
... {
<#list table.columns as column>
<#if !column.isSuperColumn(column.javaField)>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
}
``` ```
**响应参数:** **响应参数:**
参数名称 |参数类型|备注|其它 参数名称 |参数类型|描述
---|---|---|--- :---|:---|:------
code|Integer|结果码(0.失败,1.成功)|- code|Integer|结果码(-1.失败,1.成功)
msg|String|消息|- msg|String|消息
data|object|数据对象|- data|object|数据对象
└─entity|object|保存实体|对象 &emsp;id|Long|保存后主键id
<#list columns as column> &emsp;entity|object|保存更新实体
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|- <#list table.columns as column>
</#list> &emsp;&emsp;${column.javaField}|${column.javaType}|${column.columnComment}
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象想,详见附录|-
</#if>
</#list> </#list>
**响应消息样例:** **响应消息样例:**
``` ```
{ {
"msg":"新增模块成功",
"code":1, "code":1,
"msg":"成功", "data":{}
"data":{
"dict":{
"interimExcuteStatus":{
"0":"未启用",
"1":"立即执行并保留"
}
},
"entity":{
"createTime":1628737643000,
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
}
} }
} }
``` ```
### 查看${functionName} ### 删除${table.functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/view
**请求URL:** ${table.requestMapping}/delete
**Type:** POST **请求方式:** GET
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **内容类型:** application/json;charset=utf-8
**Description:** 查看${functionName},返回实例详细信息 **简要描述:** 删除${table.functionName}
**Query-parameters:** **请求参数:**
参数名称|类型|备注|必填|其它 参数名称|类型|必填|描述
---|---|---|---|--- :---|:---|:---|:------
${pkColumn.javaField}|array|实例主键ID,数组形式|是|- ${table.pkColumn.javaField}|String|是|数组
**请求样例:** **请求样例:**
``` ```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/view --data 'id=[1]' http://localhost:8080/${table.requestMapping}/delete?id=1&id=2'
``` ```
**响应参数:** **响应参数:**
参数名称 |参数类型|备注|其它 参数名称 |参数类型|备注|其它
---|---|---|--- ---|---|---|---
code|Integer|结果码(0.失败,1.成功)|- code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|- msg|String|消息|-
data|object|数据对象|-
└─entity|object|对象实体|对象
<#list columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list>
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|-
</#if>
</#list>
**响应消息样例:** **响应消息样例:**
``` ```
{ {
"code":1, "code":1,
"data":{ "msg":"成功"
"dict":{
"interimExcuteStatus":{
"0":"未启用",
"1":"立即执行并保留"
}
},
"entity":{
"createTime":1628737643000,
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
}
}
} }
```
### 删除${functionName} ```
**URL:** http://localhost:8080/m/${RequestMapping}/delete <#if table.isGenExport==1 >
**Type:** POST ### 导入${table.functionName}模板下载
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **请求URL:** ${table.requestMapping}/downloadTemplate
**Description:** 删除${functionName} **请求方式:** POST
**Query-parameters:** **内容类型:** application/octet-stream;charset=utf-8
参数名称|类型|备注|必填|其它 **简要描述:** ${table.functionName}导入模板下载
---|---|---|---|---
${pkColumn.javaField}|array|实例主键ID,数组形式|是|-
**请求样例:** **请求样例:**
``` ```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/delete --data 'id=[1]' http://localhost/${table.requestMapping}/downloadTemplate
``` ```
**响应参数:**
参数名称 |参数类型|备注|其它 **Response-example:**
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
``` ```
{ ...
"code":1,
"msg":"成功"
}
``` ```
### ${functionName}导入模板下载 ### 导入${table.functionName}
**URL:** http://localhost:8081/m/${RequestMapping}/downloadTemplate
**请求URL:** ${table.requestMapping}/importData
**Type:** POST **请求方式:** POST
**内容类型:** multipart/form-data
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8 **简要描述:** 导入${table.functionName}
**Description:** ${functionName}导入模板下载 **请求参数:**
**Request-example:** 参数名称|类型|必填|描述
:---|:---|:---|:------
file|file|是|文件流
**请求样例:**
``` ```
curl -X POST -i http://localhost:8081/m/${RequestMapping}/downloadTemplate http://localhost/${table.requestMapping}/importData --data 'updateSupport=true'
``` ```
**Response-example:** **Response-example:**
``` ```
... ...
``` ```
### 导入${functionName} ### 导出${table.functionName}
**URL:** http://localhost:8081/m/${RequestMapping}/importData
**Type:** POST **请求URL:** ${table.requestMapping}/exportExcel
**请求方式:** POST
**Content-Type:** multipart/form-data **内容类型:** application/json;charset=utf-8
**Description:** 导入${functionName} **简要描述:** 导出${table.functionName}
**Query-parameters:** **请求参数:**
参数名称|类型|备注|必填|其它 参数名称|类型|必填|描述
---|---|---|---|--- :---|:---|:---|:------
file|file|文件流|是|- idList|Arrays|否|id数组
updateSupport|boolean|相同数据项是否更新|false|- <#list table.columns as column>
<#if column.isQuery == 1>
${column.javaField}|${column.javaType}|${column.columnComment}|否|参数查询条件
</#if>
</#list>
**Request-example:** **请求样例:**
``` ```
curl -X POST -H 'Content-Type: multipart/form-data' -i http://localhost:8081/m/${RequestMapping}/importData --data 'updateSupport=true' {
idList:[1,2],
<#list table.columns as column>
<#if column.isQuery == 1>
<#if column.javaType=="String" ||column.javaType=="Date">
<#assign fakeValue>"${column.randomStr(column.javaType)}"</#assign>
<#else>
<#assign fakeValue>${column.randomStr(column.javaType)}</#assign>
</#if>
"${column.javaField}":${fakeValue}<#sep>,</#sep>
</#if>
</#list>
}
``` ```
**Response-example:** **Response-example:**
``` ```
... ...
``` ```
</#if>
</#list>
<#list tableList as table>
<#list table.columns as column>
<#if column.dict??>
<#assign comment=column.subComment(column.columnComment) />
### ${column.javaField}
字典参数key|字典参数值|其它
:---|:---|:---
<#list column.dict as dict>
${dict.num}|${dict.value}|-
</#list>
</#if>
</#list>
</#list>
\ No newline at end of file
## ${functionName}服务接口
### 查询${functionName}列表
**URL:** http://localhost:8080/m/${RequestMapping}/list
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** 查询${functionName}
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
pageInfo|object|分页对象|否|-
└─beginIndex|Integer|开始记录序号|否|-
└─prePageResult|Integer|每页条数|否|-
└─totalResult|Integer|总条数|否|-
└─totalPage|Integer|总页数|否|-
└─currPage|Integer|当前页|否|-
└─displayPageSize|Integer|显示页数量|否|-
└─hasNextPage|Boolean|是否有下一页|否|-
└─hasPrePage|Boolean|是否有前一页|否|-
└─lastRecordKey|String|最后一条|否|-
└─countPage|Boolean|是否计算总页数|否|-
query|object|查询对象|否|-
<#list columns as column>
└─${column.javaField}|${column.javaType}|${column.columnComment}|否|-
</#list>
<#list columns as column>
<#if column.javaType == "Long"||column.javaType == "Integer"||column.javaType == "BigDecimal">
└─${column.javaField}Start|${column.javaType}|大于 > ${column.columnComment}|否|-
└─${column.javaField}End|${column.javaType}|小于 < ${column.columnComment}|否|-
└─${column.javaField}List|array|${column.columnComment}列表|否|-
</#if>
<#if column.javaType == "String">
└─${column.javaField}List|array|${column.columnComment}列表|否|-
</#if>
<#if column.javaType == "Date">
└─${column.javaField}Start|${column.javaType}|大于 > ${column.columnComment}|否|-
└─${column.javaField}End|${column.javaType}|小于 < ${column.columnComment}|否|-
</#if>
</#list>
**请求样例:**
```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/list --data 'query.id=1'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
└─result|array|结果集列表|数组
<#list columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list>
└─pageInfo|object|分页对象|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─beginIndex|Integer|开始记录序号|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─prePageResult|Integer|每页条数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─totalResult|Integer|总条数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─totalPage|Integer|总页数|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─currPage|Integer|当前页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─displayPageSize|Integer|显示页数量|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─hasNextPage|Boolean|是否有下一页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─hasPrePage|Boolean|是否有前一页|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─lastRecordKey|String|最后一条|-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─countPage|Boolean|是否计算总页数|-
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|-
</#if>
</#list>
└─query|object|查询时候返回的查询列表参数对象|-
**响应消息样例:**
```
{
"code":1,
"data":{
"result":[
{
"appId":6,
"businessName":"device",
}
],
"pageInfo":{
"currPage":1,
"prePageResult":200,
"totalPage":1,
"totalResult":16
},
"dict":{
"dividedTableType":{
"0":"无",
"1":"日"
}
}
},
"query":{
"appId":6
}
}
```
### 编辑${functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/edit
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** 编辑${functionName},返回实例详细信息
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
${pkColumn.javaField}|array|实例主键ID,数组形式|是|-
**请求样例:**
```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/edit --data 'id=[1]'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
└─entity|object|对象实体|对象
<#list columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list>
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|-
</#if>
</#list>
**响应消息样例:**
```
{
"code":1,
"data":{
"dict":{
"interimExcuteStatus":{
"0":"未启用",
"1":"立即执行并保留"
}
},
"entity":{
"createTime":1628737643000,
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
}
}
}
```
### 保存更新${functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/save
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** 保存或更新${functionName}:id为空时为新增保存,否则为更新提交
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
entity|object|实体对象|是|-
<#list columns as column>
<#if !column.isSuperColumn(column.javaField)>
└─${column.javaField}|${column.javaType}|${column.columnComment}|是|-
</#if>
</#list>
**请求样例:**
```
...
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
└─entity|object|保存实体|对象
<#list columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list>
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象想,详见附录|-
</#if>
</#list>
**响应消息样例:**
```
{
"code":1,
"msg":"成功",
"data":{
"dict":{
"interimExcuteStatus":{
"0":"未启用",
"1":"立即执行并保留"
}
},
"entity":{
"createTime":1628737643000,
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
}
}
}
```
### 查看${functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/view
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** 查看${functionName},返回实例详细信息
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
${pkColumn.javaField}|array|实例主键ID,数组形式|是|-
**请求样例:**
```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/view --data 'id=[1]'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
└─entity|object|对象实体|对象
<#list columns as column>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|${column.javaType}|${column.columnComment}|-
</#list>
└─dict|object|字典对象|-
<#list columns as column>
<#if column.dict??&&(column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5)>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─${column.javaField}|object|字典属性对象,详见附录|-
</#if>
</#list>
**响应消息样例:**
```
{
"code":1,
"data":{
"dict":{
"interimExcuteStatus":{
"0":"未启用",
"1":"立即执行并保留"
}
},
"entity":{
"createTime":1628737643000,
"createUserId":1,
"createUserName":"系统管理员",
"excuteDate":0
}
}
}
```
### 删除${functionName}
**URL:** http://localhost:8080/m/${RequestMapping}/delete
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** 删除${functionName}
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
${pkColumn.javaField}|array|实例主键ID,数组形式|是|-
**请求样例:**
```
curl -X POST -i http://localhost:8080/m/${RequestMapping}/delete --data 'id=[1]'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(0.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
### ${functionName}导入模板下载
**URL:** http://localhost:8081/m/${RequestMapping}/downloadTemplate
**Type:** POST
**Content-Type:** application/x-www-form-urlencoded;charset=utf-8
**Description:** ${functionName}导入模板下载
**Request-example:**
```
curl -X POST -i http://localhost:8081/m/${RequestMapping}/downloadTemplate
```
**Response-example:**
```
...
```
### 导入${functionName}
**URL:** http://localhost:8081/m/${RequestMapping}/importData
**Type:** POST
**Content-Type:** multipart/form-data
**Description:** 导入${functionName}
**Query-parameters:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
file|file|文件流|是|-
updateSupport|boolean|相同数据项是否更新|false|-
**Request-example:**
```
curl -X POST -H 'Content-Type: multipart/form-data' -i http://localhost:8081/m/${RequestMapping}/importData --data 'updateSupport=true'
```
**Response-example:**
```
...
```
<#list tableList as table>
-- ---------------------------- -- ----------------------------
-- ${functionName}表 -- ${table.functionName}表
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `${tableName}`; DROP TABLE IF EXISTS `${table.tableName}`;
CREATE TABLE ${tableName}( CREATE TABLE ${table.tableName}(
<#list columns as column> <#list table.columns as column>
<#if column.isIncrement==1 > <#if column.isIncrement==1 >
<#assign autoInc>AUTO_INCREMENT</#assign> <#assign autoInc>AUTO_INCREMENT</#assign>
<#else> <#else>
...@@ -34,5 +35,7 @@ CREATE TABLE ${tableName}( ...@@ -34,5 +35,7 @@ CREATE TABLE ${tableName}(
</#if> </#if>
`${column.columnName}` ${column.columnType} ${Required} ${autoInc} COMMENT '${column.columnComment}', `${column.columnName}` ${column.columnType} ${Required} ${autoInc} COMMENT '${column.columnComment}',
</#list> </#list>
PRIMARY KEY (`${pkColumn.columnName}`) PRIMARY KEY (`${table.pkColumn.columnName}`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${functionName}'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='${table.functionName}';
</#list>
\ No newline at end of file
<#list tableList as table>
-- ---------------------------- -- ----------------------------
-- ${functionName}菜单 SQL -- ${table.functionName}菜单 SQL
-- ---------------------------- -- ----------------------------
INSERT INTO `mortals_xhx_menu` VALUES (null, '${tableComment}', '/${RequestMapping}/list', 0, 1, 1, 0, 0,'',NULL, NULL, NULL, 0, 0, 1, NULL, NULL, NULL); INSERT INTO `mortals_xhx_menu` VALUES (null, '${table.tableComment}', '/${table.requestMapping}/list', 0, 1, 1, 0, 0,'',NULL, NULL, NULL, 0, 0, 1, NULL, NULL, NULL);
-- ---------------------------- -- ----------------------------
-- ${functionName}资源路径 SQL -- ${table.functionName}资源路径 SQL
-- ---------------------------- -- ----------------------------
INSERT INTO `mortals_xhx_resource` VALUES (null, '${functionName}-菜单管理-查看', '/${RequestMapping}/list,/${RequestMapping}/view,/${RequestMapping}/info,/${RequestMapping}/export,/${RequestMapping}/exportExcel,/${RequestMapping}/downloadTemplate,/${RequestMapping}/download', 3, 0, NULL, NULL, NULL, 0); INSERT INTO `mortals_xhx_resource` VALUES (null, '${table.functionName}-菜单管理-查看', '/${table.requestMapping}/list,/${table.requestMapping}/view,/${table.requestMapping}/info,/${table.requestMapping}/export,/${table.requestMapping}/exportExcel,/${table.requestMapping}/downloadTemplate,/${table.requestMapping}/download', 3, 0, NULL, NULL, NULL, 0);
INSERT INTO `mortals_xhx_resource` VALUES (null, '${functionName}-菜单管理-维护', '/${RequestMapping}/add,/${RequestMapping}/edit,/${RequestMapping}/delete,/${RequestMapping}/logicDelete,/${RequestMapping}/save,/${RequestMapping}/importData', 3, 0, NULL, NULL, NULL, 0); INSERT INTO `mortals_xhx_resource` VALUES (null, '${table.functionName}-菜单管理-维护', '/${table.requestMapping}/add,/${table.requestMapping}/edit,/${table.requestMapping}/delete,/${table.requestMapping}/logicDelete,/${table.requestMapping}/save,/${table.requestMapping}/importData', 3, 0, NULL, NULL, NULL, 0);
-- ----------------------------
-- ${table.functionName}参数 SQL
-- ----------------------------
<#list table.columns as column>
<#if column.dict??>
<#list column.dict as dict>
INSERT INTO `mortals_xhx_param` VALUES (null, '${column.subComment(column.columnComment)}', '${table.className}', '${column.javaField}', '${dict.num}', '${dict.value}', 1, 4, 0, '${column.javaField}', NULL, NULL, NULL);
</#list>
</#if>
</#list>
</#list>
\ No newline at end of file
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