Commit 91d7938ddf0891c80cb721bac06029f517bfe087
1 parent
7e6b084f
代码生成器:简化 vo 和 convert 的生成逻辑
Showing
16 changed files
with
159 additions
and
250 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.codegen.inner; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.lang.Filter; | |
| 5 | 4 | import cn.hutool.core.map.MapUtil; |
| 6 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 7 | 6 | import cn.hutool.core.util.StrUtil; |
| ... | ... | @@ -15,6 +14,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 15 | 14 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 16 | 15 | import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
| 17 | 16 | import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; |
| 17 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 18 | 18 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 19 | 19 | import cn.iocoder.yudao.framework.common.util.string.StrUtils; |
| 20 | 20 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| ... | ... | @@ -63,16 +63,11 @@ public class CodegenEngine { |
| 63 | 63 | */ |
| 64 | 64 | private static final Map<String, String> SERVER_TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序 |
| 65 | 65 | // Java module-biz Main |
| 66 | - .put(javaTemplatePath("controller/vo/baseVO"), javaModuleImplVOFilePath("BaseVO")) | |
| 67 | - .put(javaTemplatePath("controller/vo/createReqVO"), javaModuleImplVOFilePath("CreateReqVO")) | |
| 68 | 66 | .put(javaTemplatePath("controller/vo/pageReqVO"), javaModuleImplVOFilePath("PageReqVO")) |
| 69 | - .put(javaTemplatePath("controller/vo/respVO"), javaModuleImplVOFilePath("RespVO")) | |
| 70 | - .put(javaTemplatePath("controller/vo/updateReqVO"), javaModuleImplVOFilePath("UpdateReqVO")) | |
| 71 | 67 | .put(javaTemplatePath("controller/vo/listReqVO"), javaModuleImplVOFilePath("ListReqVO")) |
| 72 | - .put(javaTemplatePath("controller/vo/excelVO"), javaModuleImplVOFilePath("ExcelVO")) | |
| 68 | + .put(javaTemplatePath("controller/vo/respVO"), javaModuleImplVOFilePath("RespVO")) | |
| 69 | + .put(javaTemplatePath("controller/vo/saveReqVO"), javaModuleImplVOFilePath("SaveReqVO")) | |
| 73 | 70 | .put(javaTemplatePath("controller/controller"), javaModuleImplControllerFilePath()) |
| 74 | - .put(javaTemplatePath("convert/convert"), | |
| 75 | - javaModuleImplMainFilePath("convert/${table.businessName}/${table.className}Convert")) | |
| 76 | 71 | .put(javaTemplatePath("dal/do"), |
| 77 | 72 | javaModuleImplMainFilePath("dal/dataobject/${table.businessName}/${table.className}DO")) |
| 78 | 73 | .put(javaTemplatePath("dal/do_sub"), // 特殊:主子表专属逻辑 |
| ... | ... | @@ -192,6 +187,7 @@ public class CodegenEngine { |
| 192 | 187 | globalBindingMap.put("DictConvertClassName", DictConvert.class.getName()); |
| 193 | 188 | globalBindingMap.put("OperateLogClassName", OperateLog.class.getName()); |
| 194 | 189 | globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName()); |
| 190 | + globalBindingMap.put("BeanUtils", BeanUtils.class.getName()); | |
| 195 | 191 | } |
| 196 | 192 | |
| 197 | 193 | /** |
| ... | ... | @@ -218,11 +214,16 @@ public class CodegenEngine { |
| 218 | 214 | generateSubCode(table, subTables, result, vmPath, filePath, bindingMap); |
| 219 | 215 | return; |
| 220 | 216 | // 2.2 特殊:树表专属逻辑 |
| 221 | - } else if (isPageTemplate(vmPath)) { | |
| 217 | + } else if (isPageReqVOTemplate(vmPath)) { | |
| 222 | 218 | // 减少多余的类生成,例如说 PageVO.java 类 |
| 223 | 219 | if (CodegenTemplateTypeEnum.isTree(table.getTemplateType())) { |
| 224 | 220 | return; |
| 225 | 221 | } |
| 222 | + } else if (isListReqVOTemplate(vmPath)) { | |
| 223 | + // 减少多余的类生成,例如说 ListVO.java 类 | |
| 224 | + if (!CodegenTemplateTypeEnum.isTree(table.getTemplateType())) { | |
| 225 | + return; | |
| 226 | + } | |
| 226 | 227 | } |
| 227 | 228 | // 2.3 默认生成 |
| 228 | 229 | generateCode(result, vmPath, filePath, bindingMap); |
| ... | ... | @@ -469,8 +470,12 @@ public class CodegenEngine { |
| 469 | 470 | return path.contains("_sub"); |
| 470 | 471 | } |
| 471 | 472 | |
| 472 | - private static boolean isPageTemplate(String path) { | |
| 473 | - return path.contains("page"); | |
| 473 | + private static boolean isPageReqVOTemplate(String path) { | |
| 474 | + return path.contains("pageReqVO"); | |
| 475 | + } | |
| 476 | + | |
| 477 | + private static boolean isListReqVOTemplate(String path) { | |
| 478 | + return path.contains("listReqVO"); | |
| 474 | 479 | } |
| 475 | 480 | |
| 476 | 481 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm
| ... | ... | @@ -18,6 +18,7 @@ import java.io.IOException; |
| 18 | 18 | import ${PageParamClassName}; |
| 19 | 19 | import ${PageResultClassName}; |
| 20 | 20 | import ${CommonResultClassName}; |
| 21 | +import ${BeanUtils}; | |
| 21 | 22 | import static ${CommonResultClassName}.success; |
| 22 | 23 | |
| 23 | 24 | import ${ExcelUtilsClassName}; |
| ... | ... | @@ -31,7 +32,6 @@ import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.business |
| 31 | 32 | #foreach ($subTable in $subTables) |
| 32 | 33 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; |
| 33 | 34 | #end |
| 34 | -import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; | |
| 35 | 35 | import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service; |
| 36 | 36 | |
| 37 | 37 | @Tag(name = "${sceneEnum.name} - ${table.classComment}") |
| ... | ... | @@ -49,7 +49,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 49 | 49 | #if ($sceneEnum.scene == 1) |
| 50 | 50 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") |
| 51 | 51 | #end |
| 52 | - public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { | |
| 52 | + public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) { | |
| 53 | 53 | return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); |
| 54 | 54 | } |
| 55 | 55 | |
| ... | ... | @@ -58,7 +58,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 58 | 58 | #if ($sceneEnum.scene == 1) |
| 59 | 59 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") |
| 60 | 60 | #end |
| 61 | - public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { | |
| 61 | + public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) { | |
| 62 | 62 | ${classNameVar}Service.update${simpleClassName}(updateReqVO); |
| 63 | 63 | return success(true); |
| 64 | 64 | } |
| ... | ... | @@ -82,7 +82,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 82 | 82 | #end |
| 83 | 83 | public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { |
| 84 | 84 | ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); |
| 85 | - return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); | |
| 85 | + return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | #if ( $table.templateType != 2 ) |
| ... | ... | @@ -93,7 +93,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 93 | 93 | #end |
| 94 | 94 | public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { |
| 95 | 95 | PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO); |
| 96 | - return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); | |
| 96 | + return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | ## 特殊:树表专属逻辑(树不需要分页接口) |
| ... | ... | @@ -105,7 +105,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 105 | 105 | #end |
| 106 | 106 | public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) { |
| 107 | 107 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO); |
| 108 | - return success(${table.className}Convert.INSTANCE.convertList(list)); | |
| 108 | + return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | #end |
| ... | ... | @@ -115,13 +115,25 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { |
| 115 | 115 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')") |
| 116 | 116 | #end |
| 117 | 117 | @OperateLog(type = EXPORT) |
| 118 | +#if ( $table.templateType != 2 ) | |
| 119 | + public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO, | |
| 120 | + HttpServletResponse response) throws IOException { | |
| 121 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 122 | + List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList(); | |
| 123 | + // 导出 Excel | |
| 124 | + ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class, | |
| 125 | + BeanUtils.toBean(list, ${table.className}RespVO.class)); | |
| 126 | + } | |
| 127 | +## 特殊:树表专属逻辑(树不需要分页接口) | |
| 128 | +#else | |
| 118 | 129 | public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO, |
| 119 | 130 | HttpServletResponse response) throws IOException { |
| 120 | 131 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO); |
| 121 | 132 | // 导出 Excel |
| 122 | - List<${sceneEnum.prefixClass}${table.className}ExcelVO> dataList = ${table.className}Convert.INSTANCE.convertList02(list); | |
| 123 | - ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, dataList); | |
| 133 | + ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${table.className}RespVO.class, | |
| 134 | + BeanUtils.toBean(list, ${table.className}RespVO.class)); | |
| 124 | 135 | } |
| 136 | +#end | |
| 125 | 137 | |
| 126 | 138 | ## 特殊:主子表专属逻辑 |
| 127 | 139 | #foreach ($subTable in $subTables) | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm deleted
| 1 | -## 提供给 baseVO、createVO、updateVO 生成字段 | |
| 2 | - @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) | |
| 3 | -#if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解 | |
| 4 | -#if (${column.javaType} == 'String') | |
| 5 | - @NotEmpty(message = "${column.columnComment}不能为空") | |
| 6 | -#else | |
| 7 | - @NotNull(message = "${column.columnComment}不能为空") | |
| 8 | -#end | |
| 9 | -#end | |
| 10 | -#if (${column.javaType} == "LocalDateTime")## 时间类型 | |
| 11 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 12 | -#end | |
| 13 | - private ${column.javaType} ${column.javaField}; |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm deleted
| 1 | -package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; | |
| 2 | - | |
| 3 | -import lombok.*; | |
| 4 | -import java.util.*; | |
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | -import javax.validation.constraints.*; | |
| 7 | -## 处理 Date 字段的引入 | |
| 8 | -#foreach ($column in $columns) | |
| 9 | -#if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}) | |
| 10 | - && ${column.javaType} == "LocalDateTime")## 时间类型 | |
| 11 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 12 | -import java.time.LocalDateTime; | |
| 13 | -import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | -#break | |
| 15 | -#end | |
| 16 | -#end | |
| 17 | - | |
| 18 | -@Schema(description = "${sceneEnum.name} - ${table.classComment}创建 Request VO") | |
| 19 | -@Data | |
| 20 | -@EqualsAndHashCode(callSuper = true) | |
| 21 | -@ToString(callSuper = true) | |
| 22 | -public class ${sceneEnum.prefixClass}${table.className}CreateReqVO extends ${sceneEnum.prefixClass}${table.className}BaseVO { | |
| 23 | - | |
| 24 | -#foreach ($column in $columns) | |
| 25 | -#if (${column.createOperation} && (!${column.updateOperation} || !${column.listOperationResult}))##不是通用字段 | |
| 26 | - #parse("codegen/java/controller/vo/_column.vm") | |
| 27 | - | |
| 28 | -#end | |
| 29 | -#end | |
| 30 | -} | |
| 31 | 0 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm deleted
| 1 | -package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import java.util.*; | |
| 6 | -#foreach ($column in $columns) | |
| 7 | -#if (${column.javaType} == "BigDecimal") | |
| 8 | -import java.math.BigDecimal; | |
| 9 | -#break | |
| 10 | -#end | |
| 11 | -#if (${column.javaType} == "LocalDateTime") | |
| 12 | -import java.time.LocalDateTime; | |
| 13 | -#break | |
| 14 | -#end | |
| 15 | -#end | |
| 16 | - | |
| 17 | -import com.alibaba.excel.annotation.ExcelProperty; | |
| 18 | -#foreach ($column in $columns) | |
| 19 | -#if ("$!column.dictType" != "")## 有设置数据字典 | |
| 20 | -import ${DictFormatClassName}; | |
| 21 | -import ${DictConvertClassName}; | |
| 22 | - | |
| 23 | -#break | |
| 24 | -#end | |
| 25 | -#end | |
| 26 | - | |
| 27 | -/** | |
| 28 | - * ${table.classComment} Excel VO | |
| 29 | - * | |
| 30 | - * @author ${table.author} | |
| 31 | - */ | |
| 32 | -@Data | |
| 33 | -public class ${sceneEnum.prefixClass}${table.className}ExcelVO { | |
| 34 | - | |
| 35 | -#foreach ($column in $columns) | |
| 36 | - #if (${column.listOperationResult})##返回字段 | |
| 37 | - #if ("$!column.dictType" != "")##处理枚举值 | |
| 38 | - @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) | |
| 39 | - @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 40 | - #else | |
| 41 | - @ExcelProperty("${column.columnComment}") | |
| 42 | - #end | |
| 43 | - private ${column.javaType} ${column.javaField}; | |
| 44 | - | |
| 45 | - #end | |
| 46 | -#end | |
| 47 | -} | |
| 48 | 0 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/listReqVO.vm
| ... | ... | @@ -4,9 +4,15 @@ import lombok.*; |
| 4 | 4 | import java.util.*; |
| 5 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 6 | import ${PageParamClassName}; |
| 7 | -## 处理 Date 字段的引入 | |
| 8 | 7 | #foreach ($column in $columns) |
| 9 | -#if (${column.listOperation} && ${column.javaType} == "LocalDateTime")## 时间类型 | |
| 8 | +#if (${column.javaType} == "BigDecimal") | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +#break | |
| 11 | +#end | |
| 12 | +#end | |
| 13 | +## 处理 LocalDateTime 字段的引入 | |
| 14 | +#foreach ($column in $columns) | |
| 15 | +#if (${column.listOperation} && ${column.javaType} == "LocalDateTime") | |
| 10 | 16 | import java.time.LocalDateTime; |
| 11 | 17 | import org.springframework.format.annotation.DateTimeFormat; |
| 12 | 18 | |
| ... | ... | @@ -20,9 +26,9 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 20 | 26 | private ${column.javaType}#if ("$!prefix" != "") ${prefix}${JavaField}#else ${column.javaField}#end; |
| 21 | 27 | #end |
| 22 | 28 | |
| 23 | -@Schema(description = "${sceneEnum.name} - ${table.classComment} Excel 导出 Request VO,参数和 ${table.className}PageReqVO 是一致的") | |
| 29 | +@Schema(description = "${sceneEnum.name} - ${table.classComment}列表 Request VO") | |
| 24 | 30 | @Data |
| 25 | -public class ${sceneEnum.prefixClass}${table.className}ExportReqVO { | |
| 31 | +public class ${sceneEnum.prefixClass}${table.className}ListReqVO { | |
| 26 | 32 | |
| 27 | 33 | #foreach ($column in $columns) |
| 28 | 34 | #if (${column.listOperation})##查询操作 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm
| ... | ... | @@ -4,9 +4,15 @@ import lombok.*; |
| 4 | 4 | import java.util.*; |
| 5 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 6 | import ${PageParamClassName}; |
| 7 | -## 处理 Date 字段的引入 | |
| 8 | 7 | #foreach ($column in $columns) |
| 9 | -#if (${column.listOperation} && ${column.javaType} == "LocalDateTime")## 时间类型 | |
| 8 | +#if (${column.javaType} == "BigDecimal") | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +#break | |
| 11 | +#end | |
| 12 | +#end | |
| 13 | +## 处理 LocalDateTime 字段的引入 | |
| 14 | +#foreach ($column in $columns) | |
| 15 | +#if (${column.listOperationCondition} && ${column.javaType} == "LocalDateTime") | |
| 10 | 16 | import org.springframework.format.annotation.DateTimeFormat; |
| 11 | 17 | import java.time.LocalDateTime; |
| 12 | 18 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm
| ... | ... | @@ -2,22 +2,51 @@ package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePac |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.*; |
| 5 | +import java.util.*; | |
| 6 | +## 处理 BigDecimal 字段的引入 | |
| 7 | +import java.util.*; | |
| 5 | 8 | #foreach ($column in $columns) |
| 6 | -#if (${column.javaType} == "LocalDateTime") | |
| 9 | +#if (${column.javaType} == "BigDecimal") | |
| 10 | +import java.math.BigDecimal; | |
| 11 | +#break | |
| 12 | +#end | |
| 13 | +#end | |
| 14 | +## 处理 LocalDateTime 字段的引入 | |
| 15 | +#foreach ($column in $columns) | |
| 16 | +#if (${table.listOperationResult} && ${column.javaType} == "LocalDateTime") | |
| 17 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 7 | 18 | import java.time.LocalDateTime; |
| 8 | 19 | #break |
| 9 | 20 | #end |
| 10 | 21 | #end |
| 22 | +## 处理 Excel 导出 | |
| 23 | +import com.alibaba.excel.annotation.*; | |
| 24 | +#foreach ($column in $columns) | |
| 25 | +#if ("$!column.dictType" != "")## 有设置数据字典 | |
| 26 | +import ${DictFormatClassName}; | |
| 27 | +import ${DictConvertClassName}; | |
| 28 | +#break | |
| 29 | +#end | |
| 30 | +#end | |
| 11 | 31 | |
| 12 | 32 | @Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO") |
| 13 | 33 | @Data |
| 14 | -@EqualsAndHashCode(callSuper = true) | |
| 15 | -@ToString(callSuper = true) | |
| 16 | -public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnum.prefixClass}${table.className}BaseVO { | |
| 34 | +@ExcelIgnoreUnannotated | |
| 35 | +public class ${sceneEnum.prefixClass}${table.className}RespVO { | |
| 17 | 36 | |
| 37 | +## 逐个处理字段 | |
| 18 | 38 | #foreach ($column in $columns) |
| 19 | -#if (${column.listOperationResult} && (!${column.createOperation} || !${column.updateOperation}))##不是通用字段 | |
| 39 | +#if (${column.listOperationResult}) | |
| 40 | +## 1. 处理 Swagger 注解 | |
| 20 | 41 | @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) |
| 42 | +## 2. 处理 Excel 导出 | |
| 43 | +#if ("$!column.dictType" != "")##处理枚举值 | |
| 44 | + @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) | |
| 45 | + @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 46 | +#else | |
| 47 | + @ExcelProperty("${column.columnComment}") | |
| 48 | +#end | |
| 49 | +## 3. 处理字段定义 | |
| 21 | 50 | private ${column.javaType} ${column.javaField}; |
| 22 | 51 | |
| 23 | 52 | #end | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/baseVO.vm renamed to yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/saveReqVO.vm
| ... | ... | @@ -3,24 +3,20 @@ package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePac |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.*; |
| 5 | 5 | import java.util.*; |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +## 处理 BigDecimal 字段的引入 | |
| 8 | +import java.util.*; | |
| 6 | 9 | #foreach ($column in $columns) |
| 7 | 10 | #if (${column.javaType} == "BigDecimal") |
| 8 | 11 | import java.math.BigDecimal; |
| 9 | 12 | #break |
| 10 | 13 | #end |
| 11 | -#if (${column.javaType} == "LocalDateTime") | |
| 12 | -import java.time.LocalDateTime; | |
| 13 | -#break | |
| 14 | -#end | |
| 15 | 14 | #end |
| 16 | -import javax.validation.constraints.*; | |
| 17 | -## 处理 Date 字段的引入 | |
| 15 | +## 处理 LocalDateTime 字段的引入 | |
| 18 | 16 | #foreach ($column in $columns) |
| 19 | -#if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult} | |
| 20 | - && ${column.javaType} == "LocalDateTime")## 时间类型 | |
| 17 | +#if ((${column.createOperation} || ${column.updateOperation}) && ${column.javaType} == "LocalDateTime") | |
| 21 | 18 | import org.springframework.format.annotation.DateTimeFormat; |
| 22 | - | |
| 23 | -import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 19 | +import java.time.LocalDateTime; | |
| 24 | 20 | #break |
| 25 | 21 | #end |
| 26 | 22 | #end |
| ... | ... | @@ -29,16 +25,25 @@ import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 29 | 25 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; |
| 30 | 26 | #end |
| 31 | 27 | |
| 32 | -/** | |
| 33 | - * ${table.classComment} Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 34 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 35 | - */ | |
| 28 | +@Schema(description = "${sceneEnum.name} - ${table.classComment}新增/修改 Request VO") | |
| 36 | 29 | @Data |
| 37 | -public class ${sceneEnum.prefixClass}${table.className}BaseVO { | |
| 30 | +public class ${sceneEnum.prefixClass}${table.className}SaveReqVO { | |
| 38 | 31 | |
| 32 | +## 逐个处理字段 | |
| 39 | 33 | #foreach ($column in $columns) |
| 40 | -#if (${column.createOperation} && ${column.updateOperation} && ${column.listOperationResult})##通用操作 | |
| 41 | - #parse("codegen/java/controller/vo/_column.vm") | |
| 34 | +#if (${column.createOperation} || ${column.updateOperation}) | |
| 35 | +## 1. 处理 Swagger 注解 | |
| 36 | + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) | |
| 37 | +#if (!${column.nullable}) | |
| 38 | +## 2. 处理 Validator 参数校验 | |
| 39 | +#if (${column.javaType} == 'String') | |
| 40 | + @NotEmpty(message = "${column.columnComment}不能为空") | |
| 41 | +#else | |
| 42 | + @NotNull(message = "${column.columnComment}不能为空") | |
| 43 | +#end | |
| 44 | +#end | |
| 45 | +## 3. 处理字段定义 | |
| 46 | + private ${column.javaType} ${column.javaField}; | |
| 42 | 47 | |
| 43 | 48 | #end |
| 44 | 49 | #end | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm deleted
| 1 | -package ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | -import java.util.*; | |
| 6 | -import javax.validation.constraints.*; | |
| 7 | -## 处理 Date 字段的引入 | |
| 8 | -#foreach ($column in $columns) | |
| 9 | -#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}) | |
| 10 | - && ${column.javaType} == "LocalDateTime")## 时间类型 | |
| 11 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 12 | -import java.time.LocalDateTime; | |
| 13 | -import static ${DateUtilsClassName}.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | -#break | |
| 15 | -#end | |
| 16 | -#end | |
| 17 | - | |
| 18 | -@Schema(description = "${sceneEnum.name} - ${table.classComment}更新 Request VO") | |
| 19 | -@Data | |
| 20 | -@EqualsAndHashCode(callSuper = true) | |
| 21 | -@ToString(callSuper = true) | |
| 22 | -public class ${sceneEnum.prefixClass}${table.className}UpdateReqVO extends ${sceneEnum.prefixClass}${table.className}BaseVO { | |
| 23 | - | |
| 24 | -#foreach ($column in $columns) | |
| 25 | -#if (${column.updateOperation} && (!${column.createOperation} || !${column.listOperationResult}))##不是通用字段 | |
| 26 | - #parse("codegen/java/controller/vo/_column.vm") | |
| 27 | - | |
| 28 | -#end | |
| 29 | -#end | |
| 30 | -} | |
| 31 | 0 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm deleted
| 1 | -package ${basePackage}.module.${table.moduleName}.convert.${table.businessName}; | |
| 2 | - | |
| 3 | -import java.util.*; | |
| 4 | - | |
| 5 | -import ${PageResultClassName}; | |
| 6 | - | |
| 7 | -import org.mapstruct.Mapper; | |
| 8 | -import org.mapstruct.factory.Mappers; | |
| 9 | -import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; | |
| 10 | -import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * ${table.classComment} Convert | |
| 14 | - * | |
| 15 | - * @author ${table.author} | |
| 16 | - */ | |
| 17 | -@Mapper | |
| 18 | -public interface ${table.className}Convert { | |
| 19 | - | |
| 20 | - ${table.className}Convert INSTANCE = Mappers.getMapper(${table.className}Convert.class); | |
| 21 | - | |
| 22 | - ${table.className}DO convert(${sceneEnum.prefixClass}${table.className}CreateReqVO bean); | |
| 23 | - | |
| 24 | - ${table.className}DO convert(${sceneEnum.prefixClass}${table.className}UpdateReqVO bean); | |
| 25 | - | |
| 26 | - ${sceneEnum.prefixClass}${table.className}RespVO convert(${table.className}DO bean); | |
| 27 | - | |
| 28 | - List<${sceneEnum.prefixClass}${table.className}RespVO> convertList(List<${table.className}DO> list); | |
| 29 | -## 特殊:树表专属逻辑(树不需要分页接口) | |
| 30 | -#if ( $table.templateType != 2 ) | |
| 31 | - PageResult<${sceneEnum.prefixClass}${table.className}RespVO> convertPage(PageResult<${table.className}DO> page); | |
| 32 | -#end | |
| 33 | - | |
| 34 | - List<${sceneEnum.prefixClass}${table.className}ExcelVO> convertList02(List<${table.className}DO> list); | |
| 35 | - | |
| 36 | -} | |
| 37 | 0 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm
| ... | ... | @@ -57,14 +57,14 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className} |
| 57 | 57 | .orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序 |
| 58 | 58 | |
| 59 | 59 | } |
| 60 | - | |
| 61 | -#end | |
| 60 | +#else | |
| 62 | 61 | default List<${table.className}DO> selectList(${sceneEnum.prefixClass}${table.className}ListReqVO reqVO) { |
| 63 | 62 | return selectList(new LambdaQueryWrapperX<${table.className}DO>() |
| 64 | 63 | #listCondition() |
| 65 | 64 | .orderByDesc(${table.className}DO::getId));## 大多数情况下,id 倒序 |
| 66 | 65 | |
| 67 | 66 | } |
| 67 | +#end | |
| 68 | 68 | |
| 69 | 69 | ## 特殊:树表专属逻辑 |
| 70 | 70 | #if ( $table.templateType == 2 ) | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm
| ... | ... | @@ -24,14 +24,14 @@ public interface ${table.className}Service { |
| 24 | 24 | * @param createReqVO 创建信息 |
| 25 | 25 | * @return 编号 |
| 26 | 26 | */ |
| 27 | - ${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO); | |
| 27 | + ${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO); | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * 更新${table.classComment} |
| 31 | 31 | * |
| 32 | 32 | * @param updateReqVO 更新信息 |
| 33 | 33 | */ |
| 34 | - void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO); | |
| 34 | + void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * 删除${table.classComment} |
| ... | ... | @@ -57,8 +57,7 @@ public interface ${table.className}Service { |
| 57 | 57 | * @return ${table.classComment}分页 |
| 58 | 58 | */ |
| 59 | 59 | PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO); |
| 60 | - | |
| 61 | -#end | |
| 60 | +#else | |
| 62 | 61 | /** |
| 63 | 62 | * 获得${table.classComment}列表 |
| 64 | 63 | * |
| ... | ... | @@ -66,6 +65,7 @@ public interface ${table.className}Service { |
| 66 | 65 | * @return ${table.classComment}列表 |
| 67 | 66 | */ |
| 68 | 67 | List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO); |
| 68 | +#end | |
| 69 | 69 | |
| 70 | 70 | ## 特殊:主子表专属逻辑 |
| 71 | 71 | #foreach ($subTable in $subTables) | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm
| ... | ... | @@ -14,8 +14,8 @@ import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.bu |
| 14 | 14 | #end |
| 15 | 15 | import ${PageResultClassName}; |
| 16 | 16 | import ${PageParamClassName}; |
| 17 | +import ${BeanUtils}; | |
| 17 | 18 | |
| 18 | -import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; | |
| 19 | 19 | import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper; |
| 20 | 20 | ## 特殊:主子表专属逻辑 |
| 21 | 21 | #foreach ($subTable in $subTables) |
| ... | ... | @@ -49,9 +49,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 49 | 49 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| 50 | 50 | @Transactional(rollbackFor = Exception.class) |
| 51 | 51 | #end |
| 52 | - public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { | |
| 52 | + public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) { | |
| 53 | 53 | // 插入 |
| 54 | - ${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO); | |
| 54 | + ${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class); | |
| 55 | 55 | ${classNameVar}Mapper.insert(${classNameVar}); |
| 56 | 56 | ## 特殊:主子表专属逻辑(非 ERP 模式) |
| 57 | 57 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| ... | ... | @@ -78,11 +78,11 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 78 | 78 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| 79 | 79 | @Transactional(rollbackFor = Exception.class) |
| 80 | 80 | #end |
| 81 | - public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { | |
| 81 | + public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) { | |
| 82 | 82 | // 校验存在 |
| 83 | 83 | validate${simpleClassName}Exists(updateReqVO.getId()); |
| 84 | 84 | // 更新 |
| 85 | - ${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO); | |
| 85 | + ${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class); | |
| 86 | 86 | ${classNameVar}Mapper.updateById(updateObj); |
| 87 | 87 | ## 特殊:主子表专属逻辑(非 ERP 模式) |
| 88 | 88 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11) |
| ... | ... | @@ -151,12 +151,12 @@ public class ${table.className}ServiceImpl implements ${table.className}Service |
| 151 | 151 | public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { |
| 152 | 152 | return ${classNameVar}Mapper.selectPage(pageReqVO); |
| 153 | 153 | } |
| 154 | - | |
| 155 | -#end | |
| 154 | +#else | |
| 156 | 155 | @Override |
| 157 | 156 | public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) { |
| 158 | 157 | return ${classNameVar}Mapper.selectList(listReqVO); |
| 159 | 158 | } |
| 159 | +#end | |
| 160 | 160 | |
| 161 | 161 | ## 特殊:主子表专属逻辑 |
| 162 | 162 | #foreach ($subTable in $subTables) | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm
| ... | ... | @@ -77,15 +77,15 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { |
| 77 | 77 | @Test |
| 78 | 78 | public void testCreate${simpleClassName}_success() { |
| 79 | 79 | // 准备参数 |
| 80 | - ${sceneEnum.prefixClass}${table.className}CreateReqVO reqVO = randomPojo(${sceneEnum.prefixClass}${table.className}CreateReqVO.class); | |
| 80 | + ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class).setId(null); | |
| 81 | 81 | |
| 82 | 82 | // 调用 |
| 83 | - ${primaryColumn.javaType} ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(reqVO); | |
| 83 | + ${primaryColumn.javaType} ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(createReqVO); | |
| 84 | 84 | // 断言 |
| 85 | 85 | assertNotNull(${classNameVar}Id); |
| 86 | 86 | // 校验记录的属性是否正确 |
| 87 | 87 | ${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(${classNameVar}Id); |
| 88 | - assertPojoEquals(reqVO, ${classNameVar}); | |
| 88 | + assertPojoEquals(createReqVO, ${classNameVar}); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | @Test |
| ... | ... | @@ -94,24 +94,24 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { |
| 94 | 94 | ${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class); |
| 95 | 95 | ${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据 |
| 96 | 96 | // 准备参数 |
| 97 | - ${sceneEnum.prefixClass}${table.className}UpdateReqVO reqVO = randomPojo(${sceneEnum.prefixClass}${table.className}UpdateReqVO.class, o -> { | |
| 97 | + ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class, o -> { | |
| 98 | 98 | o.setId(db${simpleClassName}.getId()); // 设置更新的 ID |
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | // 调用 |
| 102 | - ${classNameVar}Service.update${simpleClassName}(reqVO); | |
| 102 | + ${classNameVar}Service.update${simpleClassName}(updateReqVO); | |
| 103 | 103 | // 校验是否更新正确 |
| 104 | - ${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(reqVO.getId()); // 获取最新的 | |
| 105 | - assertPojoEquals(reqVO, ${classNameVar}); | |
| 104 | + ${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 105 | + assertPojoEquals(updateReqVO, ${classNameVar}); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | @Test |
| 109 | 109 | public void testUpdate${simpleClassName}_notExists() { |
| 110 | 110 | // 准备参数 |
| 111 | - ${sceneEnum.prefixClass}${table.className}UpdateReqVO reqVO = randomPojo(${sceneEnum.prefixClass}${table.className}UpdateReqVO.class); | |
| 111 | + ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO = randomPojo(${sceneEnum.prefixClass}${table.className}SaveReqVO.class); | |
| 112 | 112 | |
| 113 | 113 | // 调用, 并断言异常 |
| 114 | - assertServiceException(() -> ${classNameVar}Service.update${simpleClassName}(reqVO), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); | |
| 114 | + assertServiceException(() -> ${classNameVar}Service.update${simpleClassName}(updateReqVO), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | @Test |
| ... | ... | @@ -151,8 +151,7 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { |
| 151 | 151 | assertEquals(1, pageResult.getList().size()); |
| 152 | 152 | assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0)); |
| 153 | 153 | } |
| 154 | - | |
| 155 | -#end | |
| 154 | +#else | |
| 156 | 155 | @Test |
| 157 | 156 | @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 |
| 158 | 157 | public void testGet${simpleClassName}List() { |
| ... | ... | @@ -164,5 +163,6 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { |
| 164 | 163 | assertEquals(1, list.size()); |
| 165 | 164 | assertPojoEquals(db${simpleClassName}, list.get(0)); |
| 166 | 165 | } |
| 166 | +#end | |
| 167 | 167 | |
| 168 | 168 | } |
| 169 | 169 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm
| 1 | 1 | -- 将该建表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/create_tables.sql 文件里 |
| 2 | 2 | CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" ( |
| 3 | 3 | #foreach ($column in $columns) |
| 4 | -#if (${column.javaType} == 'Long') | |
| 5 | - #set ($dataType='bigint') | |
| 6 | -#elseif (${column.javaType} == 'Integer') | |
| 7 | - #set ($dataType='int') | |
| 8 | -#elseif (${column.javaType} == 'Boolean') | |
| 9 | - #set ($dataType='bit') | |
| 10 | -#elseif (${column.javaType} == 'Date') | |
| 11 | - #set ($dataType='datetime') | |
| 12 | -#else | |
| 13 | - #set ($dataType='varchar') | |
| 14 | -#end | |
| 4 | + #if (${column.javaType} == 'Long') | |
| 5 | + #set ($dataType='bigint') | |
| 6 | + #elseif (${column.javaType} == 'Integer') | |
| 7 | + #set ($dataType='int') | |
| 8 | + #elseif (${column.javaType} == 'Boolean') | |
| 9 | + #set ($dataType='bit') | |
| 10 | + #elseif (${column.javaType} == 'Date') | |
| 11 | + #set ($dataType='datetime') | |
| 12 | + #else | |
| 13 | + #set ($dataType='varchar') | |
| 14 | + #end | |
| 15 | 15 | #if (${column.primaryKey})##处理主键 |
| 16 | 16 | "${column.javaField}"#if (${column.javaType} == 'String') ${dataType} NOT NULL#else ${dataType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end, |
| 17 | 17 | #else |
| 18 | - #if (${column.columnName} == 'create_time') | |
| 19 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 20 | - #elseif (${column.columnName} == 'update_time') | |
| 21 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 22 | - #elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater') | |
| 23 | - "${column.columnName}" ${dataType} DEFAULT '', | |
| 24 | - #elseif (${column.columnName} == 'deleted') | |
| 25 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 26 | - #else | |
| 27 | - "${column.columnName.toLowerCase()}" ${dataType}#if (${column.nullable} == false) NOT NULL#end, | |
| 28 | - #end | |
| 18 | + #if (${column.columnName} == 'create_time') | |
| 19 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 20 | + #elseif (${column.columnName} == 'update_time') | |
| 21 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 22 | + #elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater') | |
| 23 | + "${column.columnName}" ${dataType} DEFAULT '', | |
| 24 | + #elseif (${column.columnName} == 'deleted') | |
| 25 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 26 | + #elseif (${column.columnName} == 'tenantId') | |
| 27 | + "tenant_id" bigint NOT NULL DEFAULT 0, | |
| 28 | + #else | |
| 29 | + "${column.columnName.toLowerCase()}" ${dataType}#if (${column.nullable} == false) NOT NULL#end, | |
| 30 | + #end | |
| 29 | 31 | #end |
| 30 | 32 | #end |
| 31 | - PRIMARY KEY ("${primaryColumn.columnName.toLowerCase()}") | |
| 33 | +PRIMARY KEY ("${primaryColumn.columnName.toLowerCase()}") | |
| 32 | 34 | ) COMMENT '${table.tableComment}'; |
| 33 | 35 | |
| 34 | 36 | -- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里 | ... | ... |