1、优化非标准表结构设计

master
王兵 6 years ago
parent 00617c7a8c
commit 19a39169c7

@ -38,7 +38,7 @@ public class SpringBootCallable implements Callable {
dBmapper = ProjectManager.dBmapper;
// 创建项目文件夹
File projectDir = new File(root , project.getProjectName());
File projectDir = new File(root, project.getProjectName());
if (!projectDir.exists()) {
projectDir.mkdir();
} else {
@ -298,10 +298,10 @@ public class SpringBootCallable implements Callable {
// }
for (Table table : md.getTables()) {
for (Field field : table.getFields()) {
if ("Enum".equals(field.getFieldType().javaType())){
ctx.put("Type",field.getCName());
if ("Enum".equals(field.getFieldType().javaType())) {
ctx.put("Type", field.getCName());
ctx.put("FieldComment", field.getFieldComment());
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), field.getCName()+".java"), option + "/java/enums/Type.ftl", ctx);
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), field.getCName() + ".java"), option + "/java/enums/Type.ftl", ctx);
}
}
}
@ -332,7 +332,12 @@ public class SpringBootCallable implements Callable {
for (Table table : md.getTables()) {
ctx.put("table", table);
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/mpr/mapperJava.ftl", ctx);
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx);
if (md.isHasSysFields()) {
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper.ftl", ctx);
} else {
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/mpr/mapper_nosys.ftl", ctx);
}
}
}
@ -345,6 +350,7 @@ public class SpringBootCallable implements Callable {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("tool", Tool.class);
ctx.put("module", md);
ctx.put("basePackage", md.getProjectBasePackage());
ctx.put("moduleName", md.getModuleName());
ctx.put("author", md.getProjectAuthor());
@ -360,7 +366,6 @@ public class SpringBootCallable implements Callable {
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/mgr/manager.ftl", ctx);
freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/mgr/managerImpl.ftl", ctx);
}
}
/**
@ -378,6 +383,7 @@ public class SpringBootCallable implements Callable {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("tool", Tool.class);
ctx.put("module", md);
ctx.put("basePackage", md.getProjectBasePackage());
ctx.put("moduleName", md.getModuleName());
ctx.put("author", md.getProjectAuthor());
@ -434,6 +440,7 @@ public class SpringBootCallable implements Callable {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("tool", Tool.class);
ctx.put("module", md);
ctx.put("basePackage", md.getProjectBasePackage());
ctx.put("moduleName", md.getModuleName());
ctx.put("author", md.getProjectAuthor());
@ -745,6 +752,7 @@ public class SpringBootCallable implements Callable {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("tool", Tool.class);
ctx.put("module", md);
ctx.put("basePackage", md.getProjectBasePackage());
ctx.put("moduleName", md.getModuleName());
ctx.put("table", table);

@ -131,7 +131,7 @@ public class Table extends TreeItem {
}
public Boolean getCreate() {
return create;
return create || !dBhandle.isHasSysFields();
}
public void setCreate(Boolean create) {
@ -139,7 +139,7 @@ public class Table extends TreeItem {
}
public Boolean getDelete() {
return delete;
return delete || !dBhandle.isHasSysFields();
}
public void setDelete(Boolean delete) {
@ -147,7 +147,7 @@ public class Table extends TreeItem {
}
public Boolean getUpdate() {
return update;
return update || !dBhandle.isHasSysFields();
}
public void setUpdate(Boolean update) {
@ -155,7 +155,7 @@ public class Table extends TreeItem {
}
public Boolean getFind() {
return find;
return find || !dBhandle.isHasSysFields();
}
public void setFind(Boolean find) {
@ -163,7 +163,7 @@ public class Table extends TreeItem {
}
public Boolean getGet() {
return get;
return get && dBhandle.isHasSysFields();
}
public void setGet(Boolean get) {
@ -171,7 +171,7 @@ public class Table extends TreeItem {
}
public Boolean getSearch() {
return search;
return search && dBhandle.isHasSysFields();
}
public void setSearch(Boolean search) {
@ -179,7 +179,7 @@ public class Table extends TreeItem {
}
public Boolean getGetAll() {
return getAll;
return getAll && dBhandle.isHasSysFields();
}
public void setGetAll(Boolean getAll) {

@ -47,17 +47,22 @@ public class ${table.getCName()}ManagerImpl implements ${table.getCName()}Manage
return response;
}
<#if module.isHasSysFields()>
long id = IDgenerator.nextId();
${table.getCName()} entity = MapperUtil.map(request, ${table.getCName()}.class);
entity.setId(id);
<#else>
${table.getCName()} entity = MapperUtil.map(request, ${table.getCName()}.class);
</#if>
long result = ${table.getFName()}Mapper.insert(entity, token);
if (1L != result) {
response.addError(ErrorType.BUSINESS_ERROR, Message.CREATE_FAILURE);
return response;
}
<#if module.isHasSysFields()>
response.setId(id);
</#if>
return response;
}

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${basePackage}.${moduleName}.mpr.${table.getCName()}Mapper">
<#if dataBase == 'ORACLE'>
<sql id="table">"${module.modulePrefix?default("")}${table.tableName}"</sql>
<#elseif dataBase='MYSQL'>
<sql id="table">`${module.modulePrefix?default("")}${table.tableName}`</sql>
</#if>
<sql id="entityColumnList">
<#if dataBase == 'ORACLE'>
<#list table.fields as f>"${f.fieldName}"<#if f_has_next>,</#if></#list>
<#elseif dataBase='MYSQL'>
<#list table.fields as f>`${f.fieldName}`<#if f_has_next>,</#if></#list>
</#if>
</sql>
<resultMap id="${table.getFName()}" type="${basePackage}.${moduleName}.ent.${table.getCName()}">
<#list table.fields as f>
<result column="${f.fieldName}" jdbcType="${f.fieldType.jdbcType()}" property="${f.getFName()}"/>
</#list>
</resultMap>
<select id="find" resultMap="${table.getFName()}">
SELECT
<include refid="entityColumnList"/>
FROM
<include refid="table"/>
WHERE
<#list table.fields as f>
<#if f.isQuery>
<#if dataBase == 'ORACLE'>
<#if f.fieldType.javaType() == "String">
<if test="request.${f.getFName()} != null and request.${f.getFName()} != ''">
AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}}
</if>
</#if>
<#if f.fieldType.javaType() == "Boolean">
<if test="request.${f.getFName()} != null">
AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}}
</if>
</#if>
<#elseif dataBase='MYSQL'>
<#if f.fieldType.javaType() == "String">
<if test="request.${f.getFName()} != null and request.${f.getFName()} != ''">
AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}}
</if>
</#if>
<#if f.fieldType.javaType() == "Boolean">
<if test="request.${f.getFName()} != null">
AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}}
</if>
</#if>
</#if>
</#if>
</#list>
</select>
<insert id="insert">
INSERT INTO
<include refid="table"/>
(
<include refid="entityColumnList"/>
)
VALUES
(
<#list table.fields as f>
${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
</#list>
)
</insert>
<delete id="delete">
DELETE FROM
<include refid="table"/>
WHERE
1 = 2
</delete>
<update id="update">
UPDATE
<include refid="table"/>
SET
<#if dataBase == 'ORACLE'>
<#list table.fields as f>
"${f.fieldName}" = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
</#list>
<#elseif dataBase='MYSQL'>
<#list table.fields as f>
`${f.fieldName}` = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
</#list>
</#if>
WHERE
1 = 2
</update>
</mapper>

@ -11,6 +11,7 @@ import ${basePackage}.frame.base.BaseResponse;
*/
public class ${table.getCName()}CreateResponse extends BaseResponse {
<#if module.isHasSysFields()>
/**
* ID
*/
@ -23,4 +24,5 @@ public class ${table.getCName()}CreateResponse extends BaseResponse {
public void setId(Long id) {
this.id = id;
}
</#if>
}

@ -4,7 +4,7 @@ server.servlet.context-path=/
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:static/
spring.application.name=${projectName}
spring.main.banner-mode=on
spring.main.banner-mode=CONSOLE
spring.devtools.restart.enabled=true
<#if cloud>
eureka.client.serviceUrl.defaultZone=http://localhost:18080/eureka/

@ -61,11 +61,17 @@ public class ${table.getCName()}Test {
${table.getCName()}CreateResponse createResponse = ${table.getFName()}Manager.create(createRequest,token);
<#if module.isHasSysFields()>
assertTrue(!createResponse.hasError() && createResponse.getId() > 0);
<#else>
assertTrue(!createResponse.hasError());
</#if>
//删除数据
${table.getCName()}DeleteRequest request = new ${table.getCName()}DeleteRequest();
<#if module.isHasSysFields()>
request.setId(createResponse.getId());
<#else>
</#if>
${table.getCName()}DeleteResponse response = ${table.getFName()}Manager.delete(request,token);
@ -88,7 +94,10 @@ public class ${table.getCName()}Test {
//更新数据
${table.getCName()}UpdateRequest request = new ${table.getCName()}UpdateRequest();
<#if module.isHasSysFields()>
request.setId(createResponse.getId());
<#else>
</#if>
<#list table.fields as field>
<#if !field.isSystem>
request.${field.setterName()}(${field.getTestValue()});

Loading…
Cancel
Save

Powered by TurnKey Linux.