diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java index 2531fd768..58c4177f9 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.column.CodegenColumnBaseVO; import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -43,6 +44,12 @@ public class CodegenUpdateReqVO { || getParentMenuId() != null; } + @AssertTrue(message = "关联的子表与字段不能为空") + public boolean isSubValid() { + return ObjectUtil.notEqual(getTemplateType(), CodegenTemplateTypeEnum.MASTER_SUB) + || (getSubTableId() != null && getSubColumnId() != null); + } + } @Schema(description = "更新表定义") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java index ede10fccd..42ac5d0d1 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/table/CodegenTableBaseVO.java @@ -58,4 +58,9 @@ public class CodegenTableBaseVO { @Schema(description = "父菜单编号", example = "1024") private Long parentMenuId; + @Schema(description = "子表的表编号", example = "2048") + private Long subTableId; + @Schema(description = "子表的关联字段编号", example = "4096") + private Long subColumnId; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java index 02cd782e1..78f3fcd8a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenTableDO.java @@ -116,4 +116,19 @@ public class CodegenTableDO extends BaseDO { */ private Long parentMenuId; + // ========== 主子表相关字段 ========== + + /** + * 子表的表编号 + * + * 关联 {@link CodegenTableDO#getId()} + */ + private Long subTableId; + /** + * 子表的关联字段编号 + * + * 关联 {@link CodegenColumnDO#getId()} + */ + private Long subColumnId; + } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java index ce2799e34..18259df3e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java @@ -14,6 +14,7 @@ public enum CodegenTemplateTypeEnum { CRUD(1), // 单表(增删改查) TREE(2), // 树表(增删改查) + MASTER_SUB(3), // 主子表 ; /** diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index 26d07d326..f5c3821b1 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -235,8 +235,16 @@ public class CodegenServiceImpl implements CodegenService { throw exception(CODEGEN_COLUMN_NOT_EXISTS); } + // 校验子表是否已经存在 + CodegenTableDO subTable = null; + List subColumns = null; + if (table.getSubTableId() != null) { + subTable = codegenTableMapper.selectById(table.getSubTableId()); + subColumns = codegenColumnMapper.selectListByTableId(table.getSubTableId()); + } + // 执行生成 - return codegenEngine.execute(table, columns); + return codegenEngine.execute(table, columns, subTable, subColumns); } @Override diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index 40c7a41c7..5e5e2603c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -26,6 +26,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Maps; import com.google.common.collect.Table; @@ -37,6 +38,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import static cn.hutool.core.map.MapUtil.getStr; import static cn.hutool.core.text.CharSequenceUtil.*; @@ -149,7 +151,8 @@ public class CodegenEngine { } @PostConstruct - private void initGlobalBindingMap() { + @VisibleForTesting + void initGlobalBindingMap() { // 全局配置 globalBindingMap.put("basePackage", codegenProperties.getBasePackage()); globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage() @@ -176,13 +179,28 @@ public class CodegenEngine { globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName()); } - public Map execute(CodegenTableDO table, List columns) { + /** + * 生成代码 + * + * @param table 表定义 + * @param columns table 的字段定义数组 + * @param subTable 子表定义,当且仅当主子表时使用 + * @param subColumns subTable 的字段定义数组 + * @return 生成的代码,key 是路径,value 是对应代码 + */ + public Map execute(CodegenTableDO table, List columns, + CodegenTableDO subTable, List subColumns) { // 创建 bindingMap Map bindingMap = new HashMap<>(globalBindingMap); bindingMap.put("table", table); bindingMap.put("columns", columns); bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段 bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene())); + if (subTable != null) { + bindingMap.put("subTable", subTable); + bindingMap.put("subColumns", subColumns); + bindingMap.put("subColumn", CollectionUtils.findFirst(subColumns, column -> column.getId().equals(table.getSubColumnId()))); + } // className 相关 // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm index a8c1f62c5..6396657e5 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm @@ -108,4 +108,4 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm index 98b09f272..57a6ef123 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm @@ -1,7 +1,7 @@ ## 提供给 baseVO、createVO、updateVO 生成字段 @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) #if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解 -#if (${field.fieldType} == 'String') +#if (${column.javaType} == 'String') @NotEmpty(message = "${column.columnComment}不能为空") #else @NotNull(message = "${column.columnComment}不能为空") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm index d4f6f8ea9..eb58b981e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm @@ -27,4 +27,4 @@ public class ${sceneEnum.prefixClass}${table.className}CreateReqVO extends ${sce #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm index 15c6660c8..de797e38b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm @@ -42,4 +42,4 @@ public class ${sceneEnum.prefixClass}${table.className}ExcelVO { #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm index d3ef4aacd..6eb53baca 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm @@ -36,4 +36,4 @@ public class ${sceneEnum.prefixClass}${table.className}ExportReqVO { #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm index 6f9868da3..3d65213ac 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm @@ -38,4 +38,4 @@ public class ${sceneEnum.prefixClass}${table.className}PageReqVO extends PagePar #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm index 517d8bcd5..cdc18461c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm @@ -22,4 +22,4 @@ public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnu #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm index 48d74321d..c7cf76898 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm @@ -27,4 +27,4 @@ public class ${sceneEnum.prefixClass}${table.className}UpdateReqVO extends ${sce #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm index 6176e0f54..413a4a502 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm @@ -31,4 +31,4 @@ public interface ${table.className}Convert { List<${sceneEnum.prefixClass}${table.className}ExcelVO> convertList02(List<${table.className}DO> list); -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/do.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/do.vm index d551d4b30..1ddee7293 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/do.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/do.vm @@ -44,4 +44,4 @@ public class ${table.className}DO extends BaseDO { #end #end -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm index 615ae337b..2c7088d13 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm @@ -63,4 +63,4 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className} } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.xml.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.xml.vm index d930db916..290378d36 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.xml.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.xml.vm @@ -9,4 +9,4 @@ 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ --> - + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm index a9a6daf25..669a8c67c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm @@ -1,3 +1,3 @@ // TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! // ========== ${table.classComment} TODO 补充编号 ========== -ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在"); +ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在"); \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm index b8c637698..8aae73e4b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm @@ -67,4 +67,4 @@ public interface ${table.className}Service { */ List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO); -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm index 9cb6e8b27..cbd2173a8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm @@ -85,4 +85,4 @@ public class ${table.className}ServiceImpl implements ${table.className}Service return ${classNameVar}Mapper.selectList(exportReqVO); } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm index ec1b45a96..45332ce8f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm @@ -162,4 +162,4 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { assertPojoEquals(db${simpleClassName}, list.get(0)); } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm index 20c33ad59..f8f0e69fa 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm @@ -32,4 +32,4 @@ CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" ( ) COMMENT '${table.tableComment}'; -- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里 -DELETE FROM "${table.tableName}"; +DELETE FROM "${table.tableName}"; \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm index 902ca7414..2e78ceee8 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm @@ -25,4 +25,4 @@ VALUES ( '${table.classComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, @parentId, '', '', '', 0 ); -#end +#end \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm index 401796db8..5476bcbae 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm @@ -43,4 +43,4 @@ export const delete${simpleClassName} = async (id: number) => { // 导出${table.classComment} Excel export const export${simpleClassName} = async (params) => { return await request.download({ url: `${baseURL}/export-excel`, params }) -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm index 4e23f2f08..6fab81d5a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm @@ -231,4 +231,4 @@ const resetForm = () => { } formRef.value?.resetFields() } - + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm index 477654a37..92ddcc426 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm @@ -286,4 +286,4 @@ const handleExport = async () => { onMounted(() => { getList() }) - + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java new file mode 100644 index 000000000..3ff973aa9 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java @@ -0,0 +1,187 @@ +package cn.iocoder.yudao.module.infra.service.codegen.inner; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.resource.ResourceUtil; +import cn.hutool.core.util.ClassUtil; +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; +import cn.iocoder.yudao.module.infra.enums.codegen.*; +import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; +import org.apache.ibatis.type.JdbcType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link CodegenEngine} 的单元测试 + * + * @author 芋道源码 + */ +public class CodegenEngineTest extends BaseMockitoUnitTest { + + @InjectMocks + private CodegenEngine codegenEngine; + + @Spy + private CodegenProperties codegenProperties = new CodegenProperties() + .setBasePackage("cn.iocoder.yudao.module"); + + @BeforeEach + public void setUp() { + codegenEngine.initGlobalBindingMap(); + } + + @Test + public void testExecute_vue3_crud() { + // 准备请求参数 + CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene()) + .setTableName("system_user").setTableComment("用户表") + .setModuleName("system").setBusinessName("user").setClassName("SystemUser") + .setClassComment("用户").setAuthor("芋道源码") + .setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()) + .setFrontType(CodegenFrontTypeEnum.VUE3.getType()) + .setParentMenuId(10L); + CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name()) + .setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true) + .setOrdinalPosition(1).setJavaType("Long").setJavaField("id").setExample("1024") + .setCreateOperation(false).setUpdateOperation(true).setListOperation(false) + .setListOperationResult(true); + CodegenColumnDO nameColumn = new CodegenColumnDO().setColumnName("name").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("名字").setNullable(false).setPrimaryKey(false) + .setOrdinalPosition(2).setJavaType("String").setJavaField("name").setExample("芋头") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationCondition(CodegenColumnListConditionEnum.LIKE.getCondition()).setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.INPUT.getType()); + CodegenColumnDO avatarColumn = new CodegenColumnDO().setColumnName("avatar").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("头像").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(3).setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) + .setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE.getType()); + CodegenColumnDO videoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("视频").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(4).setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) + .setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_FILE.getType()); + CodegenColumnDO descriptionColumn = new CodegenColumnDO().setColumnName("description").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("个人简介").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(5).setJavaType("String").setJavaField("description").setExample("我是介绍") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) + .setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.EDITOR.getType()); + CodegenColumnDO sex1Column = new CodegenColumnDO().setColumnName("sex1").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("性别 1").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(6).setJavaType("String").setJavaField("sex1").setExample("男") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.SELECT.getType()).setDictType("system_sex1"); + CodegenColumnDO sex2Column = new CodegenColumnDO().setColumnName("sex2").setDataType(JdbcType.INTEGER.name()) + .setColumnComment("性别 2").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(7).setJavaType("Integer").setJavaField("sex2").setExample("1") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.CHECKBOX.getType()).setDictType("system_sex2"); + CodegenColumnDO sex3Column = new CodegenColumnDO().setColumnName("sex3").setDataType(JdbcType.BOOLEAN.name()) + .setColumnComment("性别 3").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(8).setJavaType("Boolean").setJavaField("sex3").setExample("true") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.RADIO.getType()).setDictType("system_sex3"); + CodegenColumnDO birthdayColumn = new CodegenColumnDO().setColumnName("birthday").setDataType(JdbcType.DATE.name()) + .setColumnComment("出生日期").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(9).setJavaType("LocalDateTime").setJavaField("birthday") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType()); + CodegenColumnDO memoColumn = new CodegenColumnDO().setColumnName("memo").setDataType(JdbcType.VARCHAR.name()) + .setColumnComment("备注").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(10).setJavaType("String").setJavaField("memo").setExample("我是备注") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) + .setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.TEXTAREA.getType()); + CodegenColumnDO createTimeColumn = new CodegenColumnDO().setColumnName("create_time").setDataType(JdbcType.DATE.name()) + .setColumnComment("创建时间").setNullable(true).setPrimaryKey(false) + .setOrdinalPosition(11).setJavaType("LocalDateTime").setJavaField("createTime") + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) + .setListOperationCondition(CodegenColumnListConditionEnum.BETWEEN.getCondition()).setListOperationResult(true) + .setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType()); + List columns = Arrays.asList(idColumn, nameColumn, avatarColumn, descriptionColumn, + sex1Column, sex2Column, sex3Column, birthdayColumn, memoColumn, createTimeColumn); + + // 调用 + Map result = codegenEngine.execute(table, columns, null, null); + + // 断言 + assertEquals(21, result.size()); + // 断言 vo 类 + for (String vo : new String[]{"SystemUserBaseVO", "SystemUserCreateReqVO", "SystemUserUpdateReqVO", "SystemUserRespVO", + "SystemUserPageReqVO", "SystemUserExportReqVO", "SystemUserExcelVO"}) { + assertPathContentEquals("vue3_crud/java/" + vo, + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/controller/admin/user/vo/" + vo + ".java"); + } + // 断言 controller 类 + assertPathContentEquals("vue3_crud/java/SystemUserController", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/controller/admin/user/SystemUserController.java"); + // 断言 service 类 + assertPathContentEquals("vue3_crud/java/SystemUserService", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserService.java"); + assertPathContentEquals("vue3_crud/java/SystemUserServiceImpl", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserServiceImpl.java"); + // 断言 convert 类 + assertPathContentEquals("vue3_crud/java/SystemUserConvert", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/convert/user/SystemUserConvert.java"); + // 断言 enums 类 + assertPathContentEquals("vue3_crud/java/ErrorCodeConstants", + result, "yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/module/system/enums/ErrorCodeConstants_手动操作.java"); + // 断言 dal 类 + assertPathContentEquals("vue3_crud/java/SystemUserDO", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/dal/dataobject/user/SystemUserDO.java"); + assertPathContentEquals("vue3_crud/java/SystemUserMapper", + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/dal/mysql/user/SystemUserMapper.java"); + assertPathContentEquals("vue3_crud/java/SystemUserMapper_xml", + result, "yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/user/SystemUserMapper.xml"); + // 断言 test 类 + assertPathContentEquals("vue3_crud/java/SystemUserServiceImplTest", + result, "yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserServiceImplTest.java"); + // 断言 sql 语句 + assertPathContentEquals("vue3_crud/sql/h2", + result, "sql/h2.sql"); + assertPathContentEquals("vue3_crud/sql/sql", + result, "sql/sql.sql"); + // 断言 vue 语句 + assertPathContentEquals("vue3_crud/vue/index", + result, "yudao-ui-admin-vue3/src/views/system/user/index.vue"); + assertPathContentEquals("vue3_crud/vue/form", + result, "yudao-ui-admin-vue3/src/views/system/user/UserForm.vue"); + assertPathContentEquals("vue3_crud/vue/api", + result, "yudao-ui-admin-vue3/src/api/system/user/index.ts"); +// result.forEach(new BiConsumer() { +// @Override +// public void accept(String s, String s2) { +// System.out.println(s); +// System.out.println(s2); +// System.out.println("================="); +// } +// }); + } + + private void assertPathContentEquals(String path, Map result, String key) { + String pathContent = ResourceUtil.readUtf8Str("codegen/" + path); + String valueContent = result.get(key); + assertEquals(pathContent, valueContent); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/package-info.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/package-info.java new file mode 100644 index 000000000..68d9854ff --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位,无其它作用 + */ +package cn.iocoder.yudao.module.infra.service.codegen; \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/ErrorCodeConstants b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/ErrorCodeConstants new file mode 100644 index 000000000..261f51cfa --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/ErrorCodeConstants @@ -0,0 +1,3 @@ +// TODO 待办:请将下面的错误码复制到 yudao-module-system-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! +// ========== 用户 TODO 补充编号 ========== +ErrorCode USER_NOT_EXISTS = new ErrorCode(TODO 补充编号, "用户不存在"); \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserBaseVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserBaseVO new file mode 100644 index 000000000..59b649ef9 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserBaseVO @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 用户 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class SystemUserBaseVO { + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") + @NotEmpty(message = "名字不能为空") + private String name; + + @Schema(description = "头像", example = "https://www.iocoder.cn/1.png") + private String avatar; + + @Schema(description = "个人简介", example = "我是介绍") + private String description; + + @Schema(description = "性别 1", example = "男") + private String sex1; + + @Schema(description = "性别 2", example = "1") + private Integer sex2; + + @Schema(description = "性别 3", example = "true") + private Boolean sex3; + + @Schema(description = "出生日期") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime birthday; + + @Schema(description = "备注", example = "我是备注") + private String memo; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime createTime; + +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserController b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserController new file mode 100644 index 000000000..a8a2d437b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserController @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; +import cn.iocoder.yudao.module.module.system.convert.user.SystemUserConvert; +import cn.iocoder.yudao.module.module.system.service.user.SystemUserService; + +@Tag(name = "管理后台 - 用户") +@RestController +@RequestMapping("/system/user") +@Validated +public class SystemUserController { + + @Resource + private SystemUserService userService; + + @PostMapping("/create") + @Operation(summary = "创建用户") + @PreAuthorize("@ss.hasPermission('system:user:create')") + public CommonResult createUser(@Valid @RequestBody SystemUserCreateReqVO createReqVO) { + return success(userService.createUser(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户") + @PreAuthorize("@ss.hasPermission('system:user:update')") + public CommonResult updateUser(@Valid @RequestBody SystemUserUpdateReqVO updateReqVO) { + userService.updateUser(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除用户") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('system:user:delete')") + public CommonResult deleteUser(@RequestParam("id") Long id) { + userService.deleteUser(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得用户") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('system:user:query')") + public CommonResult getUser(@RequestParam("id") Long id) { + SystemUserDO user = userService.getUser(id); + return success(SystemUserConvert.INSTANCE.convert(user)); + } + + @GetMapping("/list") + @Operation(summary = "获得用户列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('system:user:query')") + public CommonResult> getUserList(@RequestParam("ids") Collection ids) { + List list = userService.getUserList(ids); + return success(SystemUserConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得用户分页") + @PreAuthorize("@ss.hasPermission('system:user:query')") + public CommonResult> getUserPage(@Valid SystemUserPageReqVO pageVO) { + PageResult pageResult = userService.getUserPage(pageVO); + return success(SystemUserConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出用户 Excel") + @PreAuthorize("@ss.hasPermission('system:user:export')") + @OperateLog(type = EXPORT) + public void exportUserExcel(@Valid SystemUserExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = userService.getUserList(exportReqVO); + // 导出 Excel + List datas = SystemUserConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "用户.xls", "数据", SystemUserExcelVO.class, datas); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserConvert b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserConvert new file mode 100644 index 000000000..27b7c500d --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserConvert @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.module.system.convert.user; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; + +/** + * 用户 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface SystemUserConvert { + + SystemUserConvert INSTANCE = Mappers.getMapper(SystemUserConvert.class); + + SystemUserDO convert(SystemUserCreateReqVO bean); + + SystemUserDO convert(SystemUserUpdateReqVO bean); + + SystemUserRespVO convert(SystemUserDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserCreateReqVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserCreateReqVO new file mode 100644 index 000000000..61a5dab84 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserCreateReqVO @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SystemUserCreateReqVO extends SystemUserBaseVO { + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserDO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserDO new file mode 100644 index 000000000..90c675fff --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserDO @@ -0,0 +1,69 @@ +package cn.iocoder.yudao.module.module.system.dal.dataobject.user; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 用户 DO + * + * @author 芋道源码 + */ +@TableName("system_user") +@KeySequence("system_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SystemUserDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 名字 + */ + private String name; + /** + * 头像 + */ + private String avatar; + /** + * 个人简介 + */ + private String description; + /** + * 性别 1 + * + * 枚举 {@link TODO system_sex1 对应的类} + */ + private String sex1; + /** + * 性别 2 + * + * 枚举 {@link TODO system_sex2 对应的类} + */ + private Integer sex2; + /** + * 性别 3 + * + * 枚举 {@link TODO system_sex3 对应的类} + */ + private Boolean sex3; + /** + * 出生日期 + */ + private LocalDateTime birthday; + /** + * 备注 + */ + private String memo; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExcelVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExcelVO new file mode 100644 index 000000000..33d4bf2cd --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExcelVO @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + + +/** + * 用户 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SystemUserExcelVO { + + @ExcelProperty("编号") + private Long id; + + @ExcelProperty("名字") + private String name; + + @ExcelProperty("头像") + private String avatar; + + @ExcelProperty("个人简介") + private String description; + + @ExcelProperty(value = "性别 1", converter = DictConvert.class) + @DictFormat("system_sex1") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String sex1; + + @ExcelProperty(value = "性别 2", converter = DictConvert.class) + @DictFormat("system_sex2") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Integer sex2; + + @ExcelProperty(value = "性别 3", converter = DictConvert.class) + @DictFormat("system_sex3") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Boolean sex3; + + @ExcelProperty("出生日期") + private LocalDateTime birthday; + + @ExcelProperty("备注") + private String memo; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExportReqVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExportReqVO new file mode 100644 index 000000000..b0d2cf51c --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExportReqVO @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.time.LocalDateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户 Excel 导出 Request VO,参数和 SystemUserPageReqVO 是一致的") +@Data +public class SystemUserExportReqVO { + + @Schema(description = "名字", example = "芋头") + private String name; + + @Schema(description = "性别 1", example = "男") + private String sex1; + + @Schema(description = "性别 2", example = "1") + private Integer sex2; + + @Schema(description = "性别 3", example = "true") + private Boolean sex3; + + @Schema(description = "出生日期") + private LocalDateTime birthday; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper new file mode 100644 index 000000000..306ce187c --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.module.system.dal.mysql.user; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; + +/** + * 用户 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface SystemUserMapper extends BaseMapperX { + + default PageResult selectPage(SystemUserPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(SystemUserDO::getName, reqVO.getName()) + .eqIfPresent(SystemUserDO::getSex1, reqVO.getSex1()) + .eqIfPresent(SystemUserDO::getSex2, reqVO.getSex2()) + .eqIfPresent(SystemUserDO::getBirthday, reqVO.getBirthday()) + .betweenIfPresent(SystemUserDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SystemUserDO::getId)); + } + + default List selectList(SystemUserExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(SystemUserDO::getName, reqVO.getName()) + .eqIfPresent(SystemUserDO::getSex1, reqVO.getSex1()) + .eqIfPresent(SystemUserDO::getSex2, reqVO.getSex2()) + .eqIfPresent(SystemUserDO::getBirthday, reqVO.getBirthday()) + .betweenIfPresent(SystemUserDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SystemUserDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper_xml b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper_xml new file mode 100644 index 000000000..6bdd3c5e5 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper_xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserPageReqVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserPageReqVO new file mode 100644 index 000000000..46ff17449 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserPageReqVO @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SystemUserPageReqVO extends PageParam { + + @Schema(description = "名字", example = "芋头") + private String name; + + @Schema(description = "性别 1", example = "男") + private String sex1; + + @Schema(description = "性别 2", example = "1") + private Integer sex2; + + @Schema(description = "性别 3", example = "true") + private Boolean sex3; + + @Schema(description = "出生日期") + private LocalDateTime birthday; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserRespVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserRespVO new file mode 100644 index 000000000..49b96857f --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserRespVO @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 用户 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SystemUserRespVO extends SystemUserBaseVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserService b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserService new file mode 100644 index 000000000..1876b0656 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserService @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.module.system.service.user; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 用户 Service 接口 + * + * @author 芋道源码 + */ +public interface SystemUserService { + + /** + * 创建用户 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createUser(@Valid SystemUserCreateReqVO createReqVO); + + /** + * 更新用户 + * + * @param updateReqVO 更新信息 + */ + void updateUser(@Valid SystemUserUpdateReqVO updateReqVO); + + /** + * 删除用户 + * + * @param id 编号 + */ + void deleteUser(Long id); + + /** + * 获得用户 + * + * @param id 编号 + * @return 用户 + */ + SystemUserDO getUser(Long id); + + /** + * 获得用户列表 + * + * @param ids 编号 + * @return 用户列表 + */ + List getUserList(Collection ids); + + /** + * 获得用户分页 + * + * @param pageReqVO 分页查询 + * @return 用户分页 + */ + PageResult getUserPage(SystemUserPageReqVO pageReqVO); + + /** + * 获得用户列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 用户列表 + */ + List getUserList(SystemUserExportReqVO exportReqVO); + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImpl b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImpl new file mode 100644 index 000000000..e8d686afb --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImpl @@ -0,0 +1,88 @@ +package cn.iocoder.yudao.module.module.system.service.user; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.module.system.convert.user.SystemUserConvert; +import cn.iocoder.yudao.module.module.system.dal.mysql.user.SystemUserMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.module.system.enums.ErrorCodeConstants.*; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; + +/** + * 用户 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SystemUserServiceImpl implements SystemUserService { + + @Resource + private SystemUserMapper userMapper; + + @Override + public Long createUser(SystemUserCreateReqVO createReqVO) { + // 插入 + SystemUserDO user = SystemUserConvert.INSTANCE.convert(createReqVO); + userMapper.insert(user); + // 返回 + return user.getId(); + } + + @Override + public void updateUser(SystemUserUpdateReqVO updateReqVO) { + // 校验存在 + validateUserExists(updateReqVO.getId()); + // 更新 + SystemUserDO updateObj = SystemUserConvert.INSTANCE.convert(updateReqVO); + userMapper.updateById(updateObj); + } + + @Override + public void deleteUser(Long id) { + // 校验存在 + validateUserExists(id); + // 删除 + userMapper.deleteById(id); + } + + private void validateUserExists(Long id) { + if (userMapper.selectById(id) == null) { + throw exception(USER_NOT_EXISTS); + } + } + + @Override + public SystemUserDO getUser(Long id) { + return userMapper.selectById(id); + } + + @Override + public List getUserList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return ListUtil.empty(); + } + return userMapper.selectBatchIds(ids); + } + + @Override + public PageResult getUserPage(SystemUserPageReqVO pageReqVO) { + return userMapper.selectPage(pageReqVO); + } + + @Override + public List getUserList(SystemUserExportReqVO exportReqVO) { + return userMapper.selectList(exportReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImplTest b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImplTest new file mode 100644 index 000000000..e9aa3ab6b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImplTest @@ -0,0 +1,191 @@ +package cn.iocoder.yudao.module.module.system.service.user; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.module.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; +import cn.iocoder.yudao.module.module.system.dal.mysql.user.SystemUserMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.module.system.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.module.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * {@link SystemUserServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ +@Import(SystemUserServiceImpl.class) +public class SystemUserServiceImplTest extends BaseDbUnitTest { + + @Resource + private SystemUserServiceImpl userService; + + @Resource + private SystemUserMapper userMapper; + + @Test + public void testCreateUser_success() { + // 准备参数 + SystemUserCreateReqVO reqVO = randomPojo(SystemUserCreateReqVO.class); + + // 调用 + Long userId = userService.createUser(reqVO); + // 断言 + assertNotNull(userId); + // 校验记录的属性是否正确 + SystemUserDO user = userMapper.selectById(userId); + assertPojoEquals(reqVO, user); + } + + @Test + public void testUpdateUser_success() { + // mock 数据 + SystemUserDO dbUser = randomPojo(SystemUserDO.class); + userMapper.insert(dbUser);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SystemUserUpdateReqVO reqVO = randomPojo(SystemUserUpdateReqVO.class, o -> { + o.setId(dbUser.getId()); // 设置更新的 ID + }); + + // 调用 + userService.updateUser(reqVO); + // 校验是否更新正确 + SystemUserDO user = userMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, user); + } + + @Test + public void testUpdateUser_notExists() { + // 准备参数 + SystemUserUpdateReqVO reqVO = randomPojo(SystemUserUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> userService.updateUser(reqVO), USER_NOT_EXISTS); + } + + @Test + public void testDeleteUser_success() { + // mock 数据 + SystemUserDO dbUser = randomPojo(SystemUserDO.class); + userMapper.insert(dbUser);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbUser.getId(); + + // 调用 + userService.deleteUser(id); + // 校验数据不存在了 + assertNull(userMapper.selectById(id)); + } + + @Test + public void testDeleteUser_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> userService.deleteUser(id), USER_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetUserPage() { + // mock 数据 + SystemUserDO dbUser = randomPojo(SystemUserDO.class, o -> { // 等会查询到 + o.setName(null); + o.setSex1(null); + o.setSex2(null); + o.setSex3(null); + o.setBirthday(null); + o.setCreateTime(null); + }); + userMapper.insert(dbUser); + // 测试 name 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setName(null))); + // 测试 sex1 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex1(null))); + // 测试 sex2 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex2(null))); + // 测试 sex3 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex3(null))); + // 测试 birthday 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setBirthday(null))); + // 测试 createTime 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setCreateTime(null))); + // 准备参数 + SystemUserPageReqVO reqVO = new SystemUserPageReqVO(); + reqVO.setName(null); + reqVO.setSex1(null); + reqVO.setSex2(null); + reqVO.setSex3(null); + reqVO.setBirthday(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = userService.getUserPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbUser, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetUserList() { + // mock 数据 + SystemUserDO dbUser = randomPojo(SystemUserDO.class, o -> { // 等会查询到 + o.setName(null); + o.setSex1(null); + o.setSex2(null); + o.setSex3(null); + o.setBirthday(null); + o.setCreateTime(null); + }); + userMapper.insert(dbUser); + // 测试 name 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setName(null))); + // 测试 sex1 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex1(null))); + // 测试 sex2 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex2(null))); + // 测试 sex3 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex3(null))); + // 测试 birthday 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setBirthday(null))); + // 测试 createTime 不匹配 + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setCreateTime(null))); + // 准备参数 + SystemUserExportReqVO reqVO = new SystemUserExportReqVO(); + reqVO.setName(null); + reqVO.setSex1(null); + reqVO.setSex2(null); + reqVO.setSex3(null); + reqVO.setBirthday(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + List list = userService.getUserList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbUser, list.get(0)); + } + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserUpdateReqVO b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserUpdateReqVO new file mode 100644 index 000000000..16d656201 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserUpdateReqVO @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SystemUserUpdateReqVO extends SystemUserBaseVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/h2 b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/h2 new file mode 100644 index 000000000..fdbb25be1 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/h2 @@ -0,0 +1,17 @@ +-- 将该建表 SQL 语句,添加到 yudao-module-system-biz 模块的 test/resources/sql/create_tables.sql 文件里 +CREATE TABLE IF NOT EXISTS "system_user" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar NOT NULL, + "avatar" varchar, + "description" varchar, + "sex1" varchar, + "sex2" int, + "sex3" bit, + "birthday" varchar, + "memo" varchar, + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY ("id") +) COMMENT '用户表'; + +-- 将该删表 SQL 语句,添加到 yudao-module-system-biz 模块的 test/resources/sql/clean.sql 文件里 +DELETE FROM "system_user"; \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/sql b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/sql new file mode 100644 index 000000000..315c1de88 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/sql @@ -0,0 +1,55 @@ +-- 菜单 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status, component_name +) +VALUES ( + '用户管理', '', 2, 0, 10, + 'user', '', 'system/user/index', 0, 'SystemUser' +); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户查询', 'system:user:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户创建', 'system:user:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户更新', 'system:user:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户删除', 'system:user:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户导出', 'system:user:export', 3, 5, @parentId, + '', '', '', 0 +); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/api b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/api new file mode 100644 index 000000000..b363a363f --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/api @@ -0,0 +1,44 @@ +import request from '@/config/axios' + +export interface UserVO { + id: number + name: string + avatar: string + description: string + sex1: string + sex2: number + sex3: boolean + birthday: Date + memo: string + createTime: Date +} + +// 查询用户列表 +export const getUserPage = async (params) => { + return await request.get({ url: `/system/user/page`, params }) +} + +// 查询用户详情 +export const getUser = async (id: number) => { + return await request.get({ url: `/system/user/get?id=` + id }) +} + +// 新增用户 +export const createUser = async (data: UserVO) => { + return await request.post({ url: `/system/user/create`, data }) +} + +// 修改用户 +export const updateUser = async (data: UserVO) => { + return await request.put({ url: `/system/user/update`, data }) +} + +// 删除用户 +export const deleteUser = async (id: number) => { + return await request.delete({ url: `/system/user/delete?id=` + id }) +} + +// 导出用户 Excel +export const exportUser = async (params) => { + return await request.download({ url: `/system/user/export-excel`, params }) +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/form b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/form new file mode 100644 index 000000000..1bf86847f --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/form @@ -0,0 +1,162 @@ + + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/index b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/index new file mode 100644 index 000000000..d69502a66 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/index @@ -0,0 +1,262 @@ + + + \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_master_sub/1 b/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_master_sub/1 new file mode 100644 index 000000000..e69de29bb