修改代码生成模板.

This commit is contained in:
lijiahang
2023-09-27 18:34:01 +08:00
parent aa9a77d73b
commit 778efa1a86
22 changed files with 45 additions and 27 deletions

View File

@@ -317,7 +317,7 @@ public class CodeGenerator {
// convert 文件
new String[]{"/templates/orion-server-module-convert.java.vm", "${type}Convert.java", "convert"},
// cache dto 文件
new String[]{"/templates/orion-server-module-cache-dto.java.vm", "${type}CacheDTO.java", "entity.dto.${bizPackage}"},
new String[]{"/templates/orion-server-module-cache-dto.java.vm", "${type}CacheDTO.java", "entity.dto"},
// cache key define 文件
new String[]{"/templates/orion-server-module-cache-key-define.java.vm", "${type}CacheKeyDefine.java", "define"},
// -------------------- 后端 - provider --------------------
@@ -401,7 +401,6 @@ public class CodeGenerator {
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- vue 代码需要注意同一模块的 router 需要自行合并\n")
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- vue 枚举需要自行更改数据类型\n")
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 菜单 sql 执行完成后 需要在菜单页面刷新缓存\n")
.append(AnsiForeground.BRIGHT_RED.and(AnsiFont.BOLD), "- 数据库实体字段长度限制为最大 65535\n")
.toString();
System.out.print(line);
}

View File

@@ -87,26 +87,9 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
p.setProperty("file.resource.loader.unicode", StringPool.TRUE);
this.velocityEngine = new VelocityEngine(p);
}
// 处理表结构
this.getConfigBuilder().getTableInfoList().forEach(this::processTasble);
return this;
}
/**
* 处理表结构
*
* @param tableInfo tableInfo
*/
private void processTasble(TableInfo tableInfo) {
for (TableField field : tableInfo.getFields()) {
TableField.MetaInfo metaInfo = field.getMetaInfo();
// 限制字段长度最大为 65535
if (metaInfo.getLength() > 65535) {
Fields.setFieldValue(metaInfo, "length", 65535);
}
}
}
@Override
public void writer(@NotNull Map<String, Object> objectMap, @NotNull String templatePath, @NotNull File outputFile) throws Exception {
Template template = velocityEngine.getTemplate(templatePath, ConstVal.UTF8);

View File

@@ -32,7 +32,9 @@ public class ${type}CreateRequest implements Serializable {
#if("$!field.propertyName" != "id")
#if("$field.propertyType" == "String")
@NotBlank
#if("$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#else
@NotNull
#end

View File

@@ -25,7 +25,7 @@ import java.math.*;
public class ${type}QueryRequest extends PageRequest {
#foreach($field in ${table.fields})
#if("$field.propertyType" == "String")
#if("$field.propertyType" == "String" && "$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#if("$!field.comment" != "")

View File

@@ -31,7 +31,9 @@ public class ${type}UpdateRequest implements Serializable {
#if("$field.propertyType" == "String")
@NotBlank
#if("$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#else
@NotNull
#end

View File

@@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
/**
* $!{table.comment} 服务实现类

View File

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* $!{table.comment} 对外服务实现类

View File

@@ -31,7 +31,9 @@ public class ${type}CreateDTO implements Serializable {
#if("$!field.propertyName" != "id")
#if("$field.propertyType" == "String")
@NotBlank
#if("$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#else
@NotNull
#end

View File

@@ -26,7 +26,7 @@ import java.math.*;
public class ${type}QueryDTO implements Serializable {
#foreach($field in ${table.fields})
#if("$field.propertyType" == "String")
#if("$field.propertyType" == "String" && "$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#if("$!field.comment" != "")

View File

@@ -30,7 +30,9 @@ public class ${type}UpdateDTO implements Serializable {
#if("$field.propertyType" == "String")
@NotBlank
#if("$field.metaInfo.jdbcType" != "LONGVARCHAR")
@Size(max = $field.metaInfo.length)
#end
#else
@NotNull
#end

View File

@@ -5,9 +5,13 @@ CREATE TABLE `${table.name}`
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id',
#foreach($field in ${table.fields})
#if("$!field.propertyName" != "id")
#if("$field.metaInfo.jdbcType" == "TINYINT" || "$field.metaInfo.jdbcType" == "SMALLINT" || "$field.metaInfo.jdbcType" == "INTEGER" || "$field.metaInfo.jdbcType" == "BIGINT" || "$field.metaInfo.jdbcType" == "FLOAT" || "$field.metaInfo.jdbcType" == "DOUBLE" || "$field.metaInfo.jdbcType" == "NUMERIC" || "$field.metaInfo.jdbcType" == "LONGVARCHAR" || "$field.metaInfo.jdbcType" == "DATE" || "$field.metaInfo.jdbcType" == "TIME" || "$field.metaInfo.jdbcType" == "TIMESTAMP")
`${field.columnName}` ${field.metaInfo.jdbcType}#if(!$field.metaInfo.nullable) NOT NULL#end#if($null.isNull($field.metaInfo.defaultValue) || "$!{field.metaInfo.defaultValue}" == "") DEFAULT NULL#else DEFAULT#if(${field.propertyType} == 'String') '${field.metaInfo.defaultValue}'#else ${field.metaInfo.defaultValue}#end#end COMMENT '$!{field.metaInfo.remarks}',
#else
`${field.columnName}` ${field.metaInfo.jdbcType}(${field.metaInfo.length})#if(!$field.metaInfo.nullable) NOT NULL#end#if($null.isNull($field.metaInfo.defaultValue) || "$!{field.metaInfo.defaultValue}" == "") DEFAULT NULL#else DEFAULT#if(${field.propertyType} == 'String') '${field.metaInfo.defaultValue}'#else ${field.metaInfo.defaultValue}#end#end COMMENT '$!{field.metaInfo.remarks}',
#end
#end
#end
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`creator` VARCHAR(64) DEFAULT NULL COMMENT '创建人',

View File

@@ -1,7 +1,7 @@
import { FieldRule } from '@arco-design/web-vue';
#foreach($field in ${table.fields})
#if("$!field.propertyName" != "id")
#if(${field.propertyType} == 'String')
#if(${field.propertyType} == 'String' && "$field.metaInfo.jdbcType" != "LONGVARCHAR")
export const ${field.propertyName} = [{
required: true,
message: '请输入${field.comment}'