Commit 3e3dbce047e645a43fc8bebeddee9b715d4239dc
Merge remote-tracking branch 'yudao/master-jdk17' into vben5-antd-schema
Showing
10 changed files
with
164 additions
and
32 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenVOTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.enums.codegen; | ||
| 2 | + | ||
| 3 | +import lombok.AllArgsConstructor; | ||
| 4 | +import lombok.Getter; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 代码生成的 VO 类型枚举 | ||
| 8 | + * | ||
| 9 | + * 目前的作用:Controller 新增、修改、响应时,使用 VO 还是 DO | ||
| 10 | + * 注意:不包括 Controller 的分页参数! | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@AllArgsConstructor | ||
| 15 | +@Getter | ||
| 16 | +public enum CodegenVOTypeEnum { | ||
| 17 | + | ||
| 18 | + VO(10, "VO"), | ||
| 19 | + DO(20, "DO"); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 场景 | ||
| 23 | + */ | ||
| 24 | + private final Integer type; | ||
| 25 | + /** | ||
| 26 | + * 场景名 | ||
| 27 | + */ | ||
| 28 | + private final String name; | ||
| 29 | + | ||
| 30 | +} |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/codegen/config/CodegenProperties.java
| 1 | package cn.iocoder.yudao.module.infra.framework.codegen.config; | 1 | package cn.iocoder.yudao.module.infra.framework.codegen.config; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; | 3 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; |
| 4 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum; | ||
| 4 | import lombok.Data; | 5 | import lombok.Data; |
| 5 | import org.springframework.boot.context.properties.ConfigurationProperties; | 6 | import org.springframework.boot.context.properties.ConfigurationProperties; |
| 6 | import org.springframework.validation.annotation.Validated; | 7 | import org.springframework.validation.annotation.Validated; |
| @@ -35,6 +36,14 @@ public class CodegenProperties { | @@ -35,6 +36,14 @@ public class CodegenProperties { | ||
| 35 | private Integer frontType; | 36 | private Integer frontType; |
| 36 | 37 | ||
| 37 | /** | 38 | /** |
| 39 | + * 代码生成的 VO 类型 | ||
| 40 | + * | ||
| 41 | + * 枚举 {@link CodegenVOTypeEnum#getType()} | ||
| 42 | + */ | ||
| 43 | + @NotNull(message = "代码生成的 VO 类型不能为空") | ||
| 44 | + private Integer voType; | ||
| 45 | + | ||
| 46 | + /** | ||
| 38 | * 是否生成单元测试 | 47 | * 是否生成单元测试 |
| 39 | */ | 48 | */ |
| 40 | @NotNull(message = "是否生成单元测试不能为空") | 49 | @NotNull(message = "是否生成单元测试不能为空") |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtils.java
| @@ -21,7 +21,7 @@ import java.io.IOException; | @@ -21,7 +21,7 @@ import java.io.IOException; | ||
| 21 | @Slf4j | 21 | @Slf4j |
| 22 | public class FileTypeUtils { | 22 | public class FileTypeUtils { |
| 23 | 23 | ||
| 24 | - private static final ThreadLocal<Tika> TIKA = TransmittableThreadLocal.withInitial(Tika::new); | 24 | + private static final Tika TIKA = new Tika(); |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * 获得文件的 mineType,对于 doc,jar 等文件会有误差 | 27 | * 获得文件的 mineType,对于 doc,jar 等文件会有误差 |
| @@ -31,7 +31,7 @@ public class FileTypeUtils { | @@ -31,7 +31,7 @@ public class FileTypeUtils { | ||
| 31 | */ | 31 | */ |
| 32 | @SneakyThrows | 32 | @SneakyThrows |
| 33 | public static String getMineType(byte[] data) { | 33 | public static String getMineType(byte[] data) { |
| 34 | - return TIKA.get().detect(data); | 34 | + return TIKA.detect(data); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| @@ -41,7 +41,7 @@ public class FileTypeUtils { | @@ -41,7 +41,7 @@ public class FileTypeUtils { | ||
| 41 | * @return mineType 无法识别时会返回“application/octet-stream” | 41 | * @return mineType 无法识别时会返回“application/octet-stream” |
| 42 | */ | 42 | */ |
| 43 | public static String getMineType(String name) { | 43 | public static String getMineType(String name) { |
| 44 | - return TIKA.get().detect(name); | 44 | + return TIKA.detect(name); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| @@ -52,7 +52,7 @@ public class FileTypeUtils { | @@ -52,7 +52,7 @@ public class FileTypeUtils { | ||
| 52 | * @return mineType 无法识别时会返回“application/octet-stream” | 52 | * @return mineType 无法识别时会返回“application/octet-stream” |
| 53 | */ | 53 | */ |
| 54 | public static String getMineType(byte[] data, String name) { | 54 | public static String getMineType(byte[] data, String name) { |
| 55 | - return TIKA.get().detect(data, name); | 55 | + return TIKA.detect(data, name); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| @@ -31,6 +31,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; | @@ -31,6 +31,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; | ||
| 31 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; | 31 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; |
| 32 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; | 32 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; |
| 33 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; | 33 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; |
| 34 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum; | ||
| 34 | import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; | 35 | import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; |
| 35 | import com.google.common.annotations.VisibleForTesting; | 36 | import com.google.common.annotations.VisibleForTesting; |
| 36 | import com.google.common.collect.ImmutableTable; | 37 | import com.google.common.collect.ImmutableTable; |
| @@ -234,6 +235,7 @@ public class CodegenEngine { | @@ -234,6 +235,7 @@ public class CodegenEngine { | ||
| 234 | globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage() | 235 | globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage() |
| 235 | + '.' + "framework"); // 用于后续获取测试类的 package 地址 | 236 | + '.' + "framework"); // 用于后续获取测试类的 package 地址 |
| 236 | globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax"); | 237 | globalBindingMap.put("jakartaPackage", jakartaEnable ? "jakarta" : "javax"); |
| 238 | + globalBindingMap.put("voType", codegenProperties.getVoType()); | ||
| 237 | // 全局 Java Bean | 239 | // 全局 Java Bean |
| 238 | globalBindingMap.put("CommonResultClassName", CommonResult.class.getName()); | 240 | globalBindingMap.put("CommonResultClassName", CommonResult.class.getName()); |
| 239 | globalBindingMap.put("PageResultClassName", PageResult.class.getName()); | 241 | globalBindingMap.put("PageResultClassName", PageResult.class.getName()); |
| @@ -383,11 +385,13 @@ public class CodegenEngine { | @@ -383,11 +385,13 @@ public class CodegenEngine { | ||
| 383 | 385 | ||
| 384 | // className 相关 | 386 | // className 相关 |
| 385 | // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 | 387 | // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 |
| 388 | + String className = table.getClassName(); | ||
| 386 | String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName() | 389 | String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName() |
| 387 | : removePrefix(table.getClassName(), upperFirst(table.getModuleName())); | 390 | : removePrefix(table.getClassName(), upperFirst(table.getModuleName())); |
| 391 | + String classNameVar = lowerFirst(simpleClassName); | ||
| 388 | bindingMap.put("simpleClassName", simpleClassName); | 392 | bindingMap.put("simpleClassName", simpleClassName); |
| 389 | bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type | 393 | bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type |
| 390 | - bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量 | 394 | + bindingMap.put("classNameVar", classNameVar); // 将 DictType 转换成 dictType,用于变量 |
| 391 | // 将 DictType 转换成 dict-type | 395 | // 将 DictType 转换成 dict-type |
| 392 | String simpleClassNameStrikeCase = toSymbolCase(simpleClassName, '-'); | 396 | String simpleClassNameStrikeCase = toSymbolCase(simpleClassName, '-'); |
| 393 | bindingMap.put("simpleClassName_strikeCase", simpleClassNameStrikeCase); | 397 | bindingMap.put("simpleClassName_strikeCase", simpleClassNameStrikeCase); |
| @@ -441,6 +445,22 @@ public class CodegenEngine { | @@ -441,6 +445,22 @@ public class CodegenEngine { | ||
| 441 | bindingMap.put("subClassNameVars", subClassNameVars); | 445 | bindingMap.put("subClassNameVars", subClassNameVars); |
| 442 | bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases); | 446 | bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases); |
| 443 | } | 447 | } |
| 448 | + | ||
| 449 | + // 多个 vm 公用的 VO 变量 | ||
| 450 | + if (ObjectUtil.equal(codegenProperties.getVoType(), CodegenVOTypeEnum.VO.getType())) { | ||
| 451 | + String prefixClass = CodegenSceneEnum.valueOf(table.getScene()).getPrefixClass(); | ||
| 452 | + bindingMap.put("saveReqVOClass", prefixClass + className + "SaveReqVO"); | ||
| 453 | + bindingMap.put("updateReqVOClass", prefixClass + className + "SaveReqVO"); | ||
| 454 | + bindingMap.put("respVOClass", prefixClass + className + "RespVO"); | ||
| 455 | + bindingMap.put("saveReqVOVar", "createReqVO"); | ||
| 456 | + bindingMap.put("updateReqVOVar", "updateReqVO"); | ||
| 457 | + } else if (ObjectUtil.equal(codegenProperties.getVoType(), CodegenVOTypeEnum.DO.getType())) { | ||
| 458 | + bindingMap.put("saveReqVOClass", className + "DO"); | ||
| 459 | + bindingMap.put("updateReqVOClass", className + "DO"); | ||
| 460 | + bindingMap.put("respVOClass", className + "DO"); | ||
| 461 | + bindingMap.put("saveReqVOVar", classNameVar); | ||
| 462 | + bindingMap.put("updateReqVOVar", classNameVar); | ||
| 463 | + } | ||
| 444 | return bindingMap; | 464 | return bindingMap; |
| 445 | } | 465 | } |
| 446 | 466 | ||
| @@ -461,6 +481,11 @@ public class CodegenEngine { | @@ -461,6 +481,11 @@ public class CodegenEngine { | ||
| 461 | templates.remove(javaTemplatePath("test/serviceTest")); | 481 | templates.remove(javaTemplatePath("test/serviceTest")); |
| 462 | templates.remove("codegen/sql/h2.vm"); | 482 | templates.remove("codegen/sql/h2.vm"); |
| 463 | } | 483 | } |
| 484 | + // 如果禁用 VO 类型,则移除对应的模版 | ||
| 485 | + if (ObjectUtil.notEqual(codegenProperties.getVoType(), CodegenVOTypeEnum.VO.getType())) { | ||
| 486 | + templates.remove(javaTemplatePath("controller/vo/respVO")); | ||
| 487 | + templates.remove(javaTemplatePath("controller/vo/saveReqVO")); | ||
| 488 | + } | ||
| 464 | return templates; | 489 | return templates; |
| 465 | } | 490 | } |
| 466 | 491 |
yudao-module-infra/src/main/resources/codegen/java/controller/controller.vm
| @@ -49,8 +49,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -49,8 +49,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 49 | #if ($sceneEnum.scene == 1) | 49 | #if ($sceneEnum.scene == 1) |
| 50 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") | 50 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") |
| 51 | #end | 51 | #end |
| 52 | - public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) { | ||
| 53 | - return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); | 52 | + public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${saveReqVOClass} ${saveReqVOVar}) { |
| 53 | + return success(${classNameVar}Service.create${simpleClassName}(${saveReqVOVar})); | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | @PutMapping("/update") | 56 | @PutMapping("/update") |
| @@ -58,8 +58,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -58,8 +58,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 58 | #if ($sceneEnum.scene == 1) | 58 | #if ($sceneEnum.scene == 1) |
| 59 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") | 59 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") |
| 60 | #end | 60 | #end |
| 61 | - public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) { | ||
| 62 | - ${classNameVar}Service.update${simpleClassName}(updateReqVO); | 61 | + public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${updateReqVOClass} ${updateReqVOVar}) { |
| 62 | + ${classNameVar}Service.update${simpleClassName}(${updateReqVOVar}); | ||
| 63 | return success(true); | 63 | return success(true); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| @@ -93,9 +93,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -93,9 +93,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 93 | #if ($sceneEnum.scene == 1) | 93 | #if ($sceneEnum.scene == 1) |
| 94 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | 94 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") |
| 95 | #end | 95 | #end |
| 96 | - public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { | 96 | + public CommonResult<${respVOClass}> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { |
| 97 | ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); | 97 | ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); |
| 98 | - return success(BeanUtils.toBean(${classNameVar}, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | 98 | +#if ($voType == 10) |
| 99 | + return success(BeanUtils.toBean(${classNameVar}, ${respVOClass}.class)); | ||
| 100 | +#else | ||
| 101 | + return success(${classNameVar}); | ||
| 102 | +#end | ||
| 99 | } | 103 | } |
| 100 | 104 | ||
| 101 | #if ( $table.templateType != 2 ) | 105 | #if ( $table.templateType != 2 ) |
| @@ -104,9 +108,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -104,9 +108,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 104 | #if ($sceneEnum.scene == 1) | 108 | #if ($sceneEnum.scene == 1) |
| 105 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | 109 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") |
| 106 | #end | 110 | #end |
| 107 | - public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { | 111 | + public CommonResult<PageResult<${respVOClass}>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { |
| 108 | PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO); | 112 | PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO); |
| 109 | - return success(BeanUtils.toBean(pageResult, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | 113 | +#if ($voType == 10) |
| 114 | + return success(BeanUtils.toBean(pageResult, ${respVOClass}.class)); | ||
| 115 | +#else | ||
| 116 | + return success(pageResult); | ||
| 117 | +#end | ||
| 110 | } | 118 | } |
| 111 | 119 | ||
| 112 | ## 特殊:树表专属逻辑(树不需要分页接口) | 120 | ## 特殊:树表专属逻辑(树不需要分页接口) |
| @@ -116,9 +124,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -116,9 +124,13 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 116 | #if ($sceneEnum.scene == 1) | 124 | #if ($sceneEnum.scene == 1) |
| 117 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | 125 | @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") |
| 118 | #end | 126 | #end |
| 119 | - public CommonResult<List<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) { | 127 | + public CommonResult<List<${respVOClass}>> get${simpleClassName}List(@Valid ${sceneEnum.prefixClass}${table.className}ListReqVO listReqVO) { |
| 120 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO); | 128 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(listReqVO); |
| 121 | - return success(BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | 129 | +#if ($voType == 10) |
| 130 | + return success(BeanUtils.toBean(list, ${respVOClass}.class)); | ||
| 131 | +#else | ||
| 132 | + return success(list); | ||
| 133 | +#end | ||
| 122 | } | 134 | } |
| 123 | 135 | ||
| 124 | #end | 136 | #end |
| @@ -134,8 +146,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -134,8 +146,8 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 134 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 146 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 135 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList(); | 147 | List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}Page(pageReqVO).getList(); |
| 136 | // 导出 Excel | 148 | // 导出 Excel |
| 137 | - ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}RespVO.class, | ||
| 138 | - BeanUtils.toBean(list, ${sceneEnum.prefixClass}${table.className}RespVO.class)); | 149 | + ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${respVOClass}.class, |
| 150 | + BeanUtils.toBean(list, ${respVOClass}.class)); | ||
| 139 | } | 151 | } |
| 140 | ## 特殊:树表专属逻辑(树不需要分页接口) | 152 | ## 特殊:树表专属逻辑(树不需要分页接口) |
| 141 | #else | 153 | #else |
yudao-module-infra/src/main/resources/codegen/java/dal/do.vm
| @@ -12,6 +12,18 @@ import java.time.LocalDateTime; | @@ -12,6 +12,18 @@ import java.time.LocalDateTime; | ||
| 12 | #end | 12 | #end |
| 13 | import com.baomidou.mybatisplus.annotation.*; | 13 | import com.baomidou.mybatisplus.annotation.*; |
| 14 | import ${BaseDOClassName}; | 14 | import ${BaseDOClassName}; |
| 15 | +## 处理 Excel 导出 + Schema 注解(仅 DO 模式) | ||
| 16 | +#if ($voType == 20) | ||
| 17 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 18 | +import com.alibaba.excel.annotation.*; | ||
| 19 | +#foreach ($column in $columns) | ||
| 20 | + #if ("$!column.dictType" != "")## 有设置数据字典 | ||
| 21 | + import ${DictFormatClassName}; | ||
| 22 | + import ${DictConvertClassName}; | ||
| 23 | + #break | ||
| 24 | + #end | ||
| 25 | +#end | ||
| 26 | +#end | ||
| 15 | 27 | ||
| 16 | /** | 28 | /** |
| 17 | * ${table.classComment} DO | 29 | * ${table.classComment} DO |
| @@ -26,6 +38,11 @@ import ${BaseDOClassName}; | @@ -26,6 +38,11 @@ import ${BaseDOClassName}; | ||
| 26 | @Builder | 38 | @Builder |
| 27 | @NoArgsConstructor | 39 | @NoArgsConstructor |
| 28 | @AllArgsConstructor | 40 | @AllArgsConstructor |
| 41 | +## 处理 Excel 导出 + Schema 注解(仅 DO 模式) | ||
| 42 | +#if ($voType == 20) | ||
| 43 | +@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO") | ||
| 44 | +@ExcelIgnoreUnannotated | ||
| 45 | +#end | ||
| 29 | public class ${table.className}DO extends BaseDO { | 46 | public class ${table.className}DO extends BaseDO { |
| 30 | 47 | ||
| 31 | ## 特殊:树表专属逻辑 | 48 | ## 特殊:树表专属逻辑 |
| @@ -45,6 +62,18 @@ public class ${table.className}DO extends BaseDO { | @@ -45,6 +62,18 @@ public class ${table.className}DO extends BaseDO { | ||
| 45 | #if (${column.primaryKey})##处理主键 | 62 | #if (${column.primaryKey})##处理主键 |
| 46 | @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end | 63 | @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end |
| 47 | #end | 64 | #end |
| 65 | +#if ($voType == 20) | ||
| 66 | +## 1. 处理 Swagger 注解 | ||
| 67 | + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) | ||
| 68 | +## 2. 处理 Excel 导出 | ||
| 69 | +#if ("$!column.dictType" != "")##处理枚举值 | ||
| 70 | + @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) | ||
| 71 | + @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | ||
| 72 | +#else | ||
| 73 | + @ExcelProperty("${column.columnComment}") | ||
| 74 | +#end | ||
| 75 | +#end | ||
| 76 | +## 3. 处理字段定义 | ||
| 48 | private ${column.javaType} ${column.javaField}; | 77 | private ${column.javaType} ${column.javaField}; |
| 49 | #end | 78 | #end |
| 50 | #end | 79 | #end |
yudao-module-infra/src/main/resources/codegen/java/dal/do_sub.vm
| @@ -14,6 +14,17 @@ import java.time.LocalDateTime; | @@ -14,6 +14,17 @@ import java.time.LocalDateTime; | ||
| 14 | #end | 14 | #end |
| 15 | import com.baomidou.mybatisplus.annotation.*; | 15 | import com.baomidou.mybatisplus.annotation.*; |
| 16 | import ${BaseDOClassName}; | 16 | import ${BaseDOClassName}; |
| 17 | +## 处理 Schema 注解(仅 DO 模式) | ||
| 18 | +#if ($voType == 20) | ||
| 19 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 20 | +#foreach ($column in $columns) | ||
| 21 | + #if ("$!column.dictType" != "")## 有设置数据字典 | ||
| 22 | + import ${DictFormatClassName}; | ||
| 23 | + import ${DictConvertClassName}; | ||
| 24 | + #break | ||
| 25 | + #end | ||
| 26 | +#end | ||
| 27 | +#end | ||
| 17 | 28 | ||
| 18 | /** | 29 | /** |
| 19 | * ${subTable.classComment} DO | 30 | * ${subTable.classComment} DO |
| @@ -28,6 +39,10 @@ import ${BaseDOClassName}; | @@ -28,6 +39,10 @@ import ${BaseDOClassName}; | ||
| 28 | @Builder | 39 | @Builder |
| 29 | @NoArgsConstructor | 40 | @NoArgsConstructor |
| 30 | @AllArgsConstructor | 41 | @AllArgsConstructor |
| 42 | +## 处理 Schema 注解(仅 DO 模式) | ||
| 43 | +#if ($voType == 20) | ||
| 44 | +@Schema(description = "${sceneEnum.name} - ${table.classComment} Response VO") | ||
| 45 | +#end | ||
| 31 | public class ${subTable.className}DO extends BaseDO { | 46 | public class ${subTable.className}DO extends BaseDO { |
| 32 | 47 | ||
| 33 | #foreach ($column in $subColumns) | 48 | #foreach ($column in $subColumns) |
| @@ -42,6 +57,11 @@ public class ${subTable.className}DO extends BaseDO { | @@ -42,6 +57,11 @@ public class ${subTable.className}DO extends BaseDO { | ||
| 42 | #if (${column.primaryKey})##处理主键 | 57 | #if (${column.primaryKey})##处理主键 |
| 43 | @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end | 58 | @TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end |
| 44 | #end | 59 | #end |
| 60 | +#if ($voType == 20) | ||
| 61 | +## 1. 处理 Swagger 注解 | ||
| 62 | + @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) | ||
| 63 | +#end | ||
| 64 | +## 2. 处理字段定义 | ||
| 45 | private ${column.javaType} ${column.javaField}; | 65 | private ${column.javaType} ${column.javaField}; |
| 46 | #end | 66 | #end |
| 47 | #end | 67 | #end |
yudao-module-infra/src/main/resources/codegen/java/service/service.vm
| @@ -21,17 +21,17 @@ public interface ${table.className}Service { | @@ -21,17 +21,17 @@ public interface ${table.className}Service { | ||
| 21 | /** | 21 | /** |
| 22 | * 创建${table.classComment} | 22 | * 创建${table.classComment} |
| 23 | * | 23 | * |
| 24 | - * @param createReqVO 创建信息 | 24 | + * @param ${saveReqVOVar} 创建信息 |
| 25 | * @return 编号 | 25 | * @return 编号 |
| 26 | */ | 26 | */ |
| 27 | - ${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO); | 27 | + ${primaryColumn.javaType} create${simpleClassName}(@Valid ${saveReqVOClass} ${saveReqVOVar}); |
| 28 | 28 | ||
| 29 | /** | 29 | /** |
| 30 | * 更新${table.classComment} | 30 | * 更新${table.classComment} |
| 31 | * | 31 | * |
| 32 | - * @param updateReqVO 更新信息 | 32 | + * @param ${updateReqVOVar} 更新信息 |
| 33 | */ | 33 | */ |
| 34 | - void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO); | 34 | + void update${simpleClassName}(@Valid ${updateReqVOClass} ${updateReqVOVar}); |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * 删除${table.classComment} | 37 | * 删除${table.classComment} |
yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm
| @@ -50,19 +50,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -50,19 +50,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 50 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) | 50 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| 51 | @Transactional(rollbackFor = Exception.class) | 51 | @Transactional(rollbackFor = Exception.class) |
| 52 | #end | 52 | #end |
| 53 | - public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO createReqVO) { | 53 | + public ${primaryColumn.javaType} create${simpleClassName}(${saveReqVOClass} ${saveReqVOVar}) { |
| 54 | ## 特殊:树表专属逻辑 | 54 | ## 特殊:树表专属逻辑 |
| 55 | #if ( $table.templateType == 2 ) | 55 | #if ( $table.templateType == 2 ) |
| 56 | #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 | 56 | #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 |
| 57 | #set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写 | 57 | #set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写 |
| 58 | // 校验${treeParentColumn.columnComment}的有效性 | 58 | // 校验${treeParentColumn.columnComment}的有效性 |
| 59 | - validateParent${simpleClassName}(null, createReqVO.get${TreeParentJavaField}()); | 59 | + validateParent${simpleClassName}(null, ${createReqVOVar}.get${TreeParentJavaField}()); |
| 60 | // 校验${treeNameColumn.columnComment}的唯一性 | 60 | // 校验${treeNameColumn.columnComment}的唯一性 |
| 61 | - validate${simpleClassName}${TreeNameJavaField}Unique(null, createReqVO.get${TreeParentJavaField}(), createReqVO.get${TreeNameJavaField}()); | 61 | + validate${simpleClassName}${TreeNameJavaField}Unique(null, ${createReqVOVar}.get${TreeParentJavaField}(), ${createReqVOVar}.get${TreeNameJavaField}()); |
| 62 | 62 | ||
| 63 | #end | 63 | #end |
| 64 | // 插入 | 64 | // 插入 |
| 65 | +#if ($voType == 10) | ||
| 65 | ${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class); | 66 | ${table.className}DO ${classNameVar} = BeanUtils.toBean(createReqVO, ${table.className}DO.class); |
| 67 | +#end | ||
| 66 | ${classNameVar}Mapper.insert(${classNameVar}); | 68 | ${classNameVar}Mapper.insert(${classNameVar}); |
| 67 | ## 特殊:主子表专属逻辑(非 ERP 模式) | 69 | ## 特殊:主子表专属逻辑(非 ERP 模式) |
| 68 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) | 70 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| @@ -74,9 +76,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -74,9 +76,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 74 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 76 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 75 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 77 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 76 | #if ( $subTable.subJoinMany) | 78 | #if ( $subTable.subJoinMany) |
| 77 | - create${subSimpleClassName}List(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}s()); | 79 | + create${subSimpleClassName}List(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}s()); |
| 78 | #else | 80 | #else |
| 79 | - create${subSimpleClassName}(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}()); | 81 | + create${subSimpleClassName}(${classNameVar}.getId(), ${createReqVOVar}.get${subSimpleClassNames.get($index)}()); |
| 80 | #end | 82 | #end |
| 81 | #end | 83 | #end |
| 82 | #end | 84 | #end |
| @@ -89,22 +91,26 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -89,22 +91,26 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 89 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) | 91 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11 ) |
| 90 | @Transactional(rollbackFor = Exception.class) | 92 | @Transactional(rollbackFor = Exception.class) |
| 91 | #end | 93 | #end |
| 92 | - public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}SaveReqVO updateReqVO) { | 94 | + public void update${simpleClassName}(${updateReqVOClass} ${updateReqVOVar}) { |
| 93 | // 校验存在 | 95 | // 校验存在 |
| 94 | - validate${simpleClassName}Exists(updateReqVO.getId()); | 96 | + validate${simpleClassName}Exists(${updateReqVOVar}.getId()); |
| 95 | ## 特殊:树表专属逻辑 | 97 | ## 特殊:树表专属逻辑 |
| 96 | #if ( $table.templateType == 2 ) | 98 | #if ( $table.templateType == 2 ) |
| 97 | #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 | 99 | #set ($TreeParentJavaField = $treeParentColumn.javaField.substring(0,1).toUpperCase() + ${treeParentColumn.javaField.substring(1)})##首字母大写 |
| 98 | #set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写 | 100 | #set ($TreeNameJavaField = $treeNameColumn.javaField.substring(0,1).toUpperCase() + ${treeNameColumn.javaField.substring(1)})##首字母大写 |
| 99 | // 校验${treeParentColumn.columnComment}的有效性 | 101 | // 校验${treeParentColumn.columnComment}的有效性 |
| 100 | - validateParent${simpleClassName}(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}()); | 102 | + validateParent${simpleClassName}(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${TreeParentJavaField}()); |
| 101 | // 校验${treeNameColumn.columnComment}的唯一性 | 103 | // 校验${treeNameColumn.columnComment}的唯一性 |
| 102 | - validate${simpleClassName}${TreeNameJavaField}Unique(updateReqVO.getId(), updateReqVO.get${TreeParentJavaField}(), updateReqVO.get${TreeNameJavaField}()); | 104 | + validate${simpleClassName}${TreeNameJavaField}Unique(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${TreeParentJavaField}(), ${updateReqVOVar}.get${TreeNameJavaField}()); |
| 103 | 105 | ||
| 104 | #end | 106 | #end |
| 105 | // 更新 | 107 | // 更新 |
| 108 | +#if ($voType == 10) | ||
| 106 | ${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class); | 109 | ${table.className}DO updateObj = BeanUtils.toBean(updateReqVO, ${table.className}DO.class); |
| 107 | ${classNameVar}Mapper.updateById(updateObj); | 110 | ${classNameVar}Mapper.updateById(updateObj); |
| 111 | +#else | ||
| 112 | + ${classNameVar}Mapper.updateById(${updateReqVOVar}); | ||
| 113 | +#end | ||
| 108 | ## 特殊:主子表专属逻辑(非 ERP 模式) | 114 | ## 特殊:主子表专属逻辑(非 ERP 模式) |
| 109 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11) | 115 | #if ( $subTables && $subTables.size() > 0 && $table.templateType != 11) |
| 110 | 116 | ||
| @@ -115,9 +121,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -115,9 +121,9 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 115 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 121 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 116 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 122 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 117 | #if ( $subTable.subJoinMany) | 123 | #if ( $subTable.subJoinMany) |
| 118 | - update${subSimpleClassName}List(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}s()); | 124 | + update${subSimpleClassName}List(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${subSimpleClassNames.get($index)}s()); |
| 119 | #else | 125 | #else |
| 120 | - update${subSimpleClassName}(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}()); | 126 | + update${subSimpleClassName}(${updateReqVOVar}.getId(), ${updateReqVOVar}.get${subSimpleClassNames.get($index)}()); |
| 121 | #end | 127 | #end |
| 122 | #end | 128 | #end |
| 123 | #end | 129 | #end |
yudao-server/src/main/resources/application.yaml
| @@ -269,6 +269,7 @@ yudao: | @@ -269,6 +269,7 @@ yudao: | ||
| 269 | base-package: ${yudao.info.base-package} | 269 | base-package: ${yudao.info.base-package} |
| 270 | db-schemas: ${spring.datasource.dynamic.datasource.master.name} | 270 | db-schemas: ${spring.datasource.dynamic.datasource.master.name} |
| 271 | front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 | 271 | front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 |
| 272 | + vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类 | ||
| 272 | unit-test-enable: false # 是否生成单元测试 | 273 | unit-test-enable: false # 是否生成单元测试 |
| 273 | tenant: # 多租户相关配置项 | 274 | tenant: # 多租户相关配置项 |
| 274 | enable: true | 275 | enable: true |