Commit 9705ae061c9b817473015cb8c0a6377cd8499603
1 parent
0af205ed
codegen:1)增加 vue3 + crud 模式下的单测;2)增加主子表的 db 字段
Showing
51 changed files
with
1643 additions
and
24 deletions
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; |
| 4 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.column.CodegenColumnBaseVO; |
| 5 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO; |
| 6 | 6 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; |
| 7 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; | |
| 7 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 8 | 9 | import lombok.Data; |
| 9 | 10 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -43,6 +44,12 @@ public class CodegenUpdateReqVO { |
| 43 | 44 | || getParentMenuId() != null; |
| 44 | 45 | } |
| 45 | 46 | |
| 47 | + @AssertTrue(message = "关联的子表与字段不能为空") | |
| 48 | + public boolean isSubValid() { | |
| 49 | + return ObjectUtil.notEqual(getTemplateType(), CodegenTemplateTypeEnum.MASTER_SUB) | |
| 50 | + || (getSubTableId() != null && getSubColumnId() != null); | |
| 51 | + } | |
| 52 | + | |
| 46 | 53 | } |
| 47 | 54 | |
| 48 | 55 | @Schema(description = "更新表定义") | ... | ... |
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 { |
| 58 | 58 | @Schema(description = "父菜单编号", example = "1024") |
| 59 | 59 | private Long parentMenuId; |
| 60 | 60 | |
| 61 | + @Schema(description = "子表的表编号", example = "2048") | |
| 62 | + private Long subTableId; | |
| 63 | + @Schema(description = "子表的关联字段编号", example = "4096") | |
| 64 | + private Long subColumnId; | |
| 65 | + | |
| 61 | 66 | } | ... | ... |
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 { |
| 116 | 116 | */ |
| 117 | 117 | private Long parentMenuId; |
| 118 | 118 | |
| 119 | + // ========== 主子表相关字段 ========== | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * 子表的表编号 | |
| 123 | + * | |
| 124 | + * 关联 {@link CodegenTableDO#getId()} | |
| 125 | + */ | |
| 126 | + private Long subTableId; | |
| 127 | + /** | |
| 128 | + * 子表的关联字段编号 | |
| 129 | + * | |
| 130 | + * 关联 {@link CodegenColumnDO#getId()} | |
| 131 | + */ | |
| 132 | + private Long subColumnId; | |
| 133 | + | |
| 119 | 134 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java
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 { |
| 235 | 235 | throw exception(CODEGEN_COLUMN_NOT_EXISTS); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | + // 校验子表是否已经存在 | |
| 239 | + CodegenTableDO subTable = null; | |
| 240 | + List<CodegenColumnDO> subColumns = null; | |
| 241 | + if (table.getSubTableId() != null) { | |
| 242 | + subTable = codegenTableMapper.selectById(table.getSubTableId()); | |
| 243 | + subColumns = codegenColumnMapper.selectListByTableId(table.getSubTableId()); | |
| 244 | + } | |
| 245 | + | |
| 238 | 246 | // 执行生成 |
| 239 | - return codegenEngine.execute(table, columns); | |
| 247 | + return codegenEngine.execute(table, columns, subTable, subColumns); | |
| 240 | 248 | } |
| 241 | 249 | |
| 242 | 250 | @Override | ... | ... |
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; |
| 26 | 26 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; |
| 27 | 27 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; |
| 28 | 28 | import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; |
| 29 | +import com.google.common.annotations.VisibleForTesting; | |
| 29 | 30 | import com.google.common.collect.ImmutableTable; |
| 30 | 31 | import com.google.common.collect.Maps; |
| 31 | 32 | import com.google.common.collect.Table; |
| ... | ... | @@ -37,6 +38,7 @@ import java.util.HashMap; |
| 37 | 38 | import java.util.LinkedHashMap; |
| 38 | 39 | import java.util.List; |
| 39 | 40 | import java.util.Map; |
| 41 | +import java.util.function.Predicate; | |
| 40 | 42 | |
| 41 | 43 | import static cn.hutool.core.map.MapUtil.getStr; |
| 42 | 44 | import static cn.hutool.core.text.CharSequenceUtil.*; |
| ... | ... | @@ -149,7 +151,8 @@ public class CodegenEngine { |
| 149 | 151 | } |
| 150 | 152 | |
| 151 | 153 | @PostConstruct |
| 152 | - private void initGlobalBindingMap() { | |
| 154 | + @VisibleForTesting | |
| 155 | + void initGlobalBindingMap() { | |
| 153 | 156 | // 全局配置 |
| 154 | 157 | globalBindingMap.put("basePackage", codegenProperties.getBasePackage()); |
| 155 | 158 | globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage() |
| ... | ... | @@ -176,13 +179,28 @@ public class CodegenEngine { |
| 176 | 179 | globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName()); |
| 177 | 180 | } |
| 178 | 181 | |
| 179 | - public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns) { | |
| 182 | + /** | |
| 183 | + * 生成代码 | |
| 184 | + * | |
| 185 | + * @param table 表定义 | |
| 186 | + * @param columns table 的字段定义数组 | |
| 187 | + * @param subTable 子表定义,当且仅当主子表时使用 | |
| 188 | + * @param subColumns subTable 的字段定义数组 | |
| 189 | + * @return 生成的代码,key 是路径,value 是对应代码 | |
| 190 | + */ | |
| 191 | + public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns, | |
| 192 | + CodegenTableDO subTable, List<CodegenColumnDO> subColumns) { | |
| 180 | 193 | // 创建 bindingMap |
| 181 | 194 | Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); |
| 182 | 195 | bindingMap.put("table", table); |
| 183 | 196 | bindingMap.put("columns", columns); |
| 184 | 197 | bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段 |
| 185 | 198 | bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene())); |
| 199 | + if (subTable != null) { | |
| 200 | + bindingMap.put("subTable", subTable); | |
| 201 | + bindingMap.put("subColumns", subColumns); | |
| 202 | + bindingMap.put("subColumn", CollectionUtils.findFirst(subColumns, column -> column.getId().equals(table.getSubColumnId()))); | |
| 203 | + } | |
| 186 | 204 | |
| 187 | 205 | // className 相关 |
| 188 | 206 | // 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀 | ... | ... |
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 { |
| 108 | 108 | ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | -} |
| 112 | +} | |
| 112 | 113 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/_column.vm
| 1 | 1 | ## 提供给 baseVO、createVO、updateVO 生成字段 |
| 2 | 2 | @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end) |
| 3 | 3 | #if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解 |
| 4 | -#if (${field.fieldType} == 'String') | |
| 4 | +#if (${column.javaType} == 'String') | |
| 5 | 5 | @NotEmpty(message = "${column.columnComment}不能为空") |
| 6 | 6 | #else |
| 7 | 7 | @NotNull(message = "${column.columnComment}不能为空") | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/createReqVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/excelVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/exportReqVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/pageReqVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/respVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/vo/updateReqVO.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/convert/convert.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/do.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper.xml.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm
| 1 | 1 | // TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! |
| 2 | 2 | // ========== ${table.classComment} TODO 补充编号 ========== |
| 3 | 3 | -ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在"); |
| 4 | +ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在"); | |
| 4 | 5 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/test/serviceTest.vm
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()}" ( |
| 32 | 32 | ) COMMENT '${table.tableComment}'; |
| 33 | 33 | |
| 34 | 34 | -- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里 |
| 35 | 35 | -DELETE FROM "${table.tableName}"; |
| 36 | +DELETE FROM "${table.tableName}"; | |
| 36 | 37 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/sql.vm
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) => { |
| 43 | 43 | // 导出${table.classComment} Excel |
| 44 | 44 | export const export${simpleClassName} = async (params) => { |
| 45 | 45 | return await request.download({ url: `${baseURL}/export-excel`, params }) |
| 46 | 46 | -} |
| 47 | +} | |
| 47 | 48 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.codegen.inner; | |
| 2 | + | |
| 3 | +import cn.hutool.core.io.FileUtil; | |
| 4 | +import cn.hutool.core.io.IoUtil; | |
| 5 | +import cn.hutool.core.io.resource.ResourceUtil; | |
| 6 | +import cn.hutool.core.util.ClassUtil; | |
| 7 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; | |
| 10 | +import cn.iocoder.yudao.module.infra.enums.codegen.*; | |
| 11 | +import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; | |
| 12 | +import org.apache.ibatis.type.JdbcType; | |
| 13 | +import org.junit.jupiter.api.BeforeEach; | |
| 14 | +import org.junit.jupiter.api.Test; | |
| 15 | +import org.mockito.InjectMocks; | |
| 16 | +import org.mockito.Mock; | |
| 17 | +import org.mockito.Spy; | |
| 18 | + | |
| 19 | +import java.util.Arrays; | |
| 20 | +import java.util.List; | |
| 21 | +import java.util.Map; | |
| 22 | +import java.util.function.BiConsumer; | |
| 23 | + | |
| 24 | +import static org.junit.jupiter.api.Assertions.assertEquals; | |
| 25 | +import static org.junit.jupiter.api.Assertions.assertTrue; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * {@link CodegenEngine} 的单元测试 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | +public class CodegenEngineTest extends BaseMockitoUnitTest { | |
| 33 | + | |
| 34 | + @InjectMocks | |
| 35 | + private CodegenEngine codegenEngine; | |
| 36 | + | |
| 37 | + @Spy | |
| 38 | + private CodegenProperties codegenProperties = new CodegenProperties() | |
| 39 | + .setBasePackage("cn.iocoder.yudao.module"); | |
| 40 | + | |
| 41 | + @BeforeEach | |
| 42 | + public void setUp() { | |
| 43 | + codegenEngine.initGlobalBindingMap(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Test | |
| 47 | + public void testExecute_vue3_crud() { | |
| 48 | + // 准备请求参数 | |
| 49 | + CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene()) | |
| 50 | + .setTableName("system_user").setTableComment("用户表") | |
| 51 | + .setModuleName("system").setBusinessName("user").setClassName("SystemUser") | |
| 52 | + .setClassComment("用户").setAuthor("芋道源码") | |
| 53 | + .setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()) | |
| 54 | + .setFrontType(CodegenFrontTypeEnum.VUE3.getType()) | |
| 55 | + .setParentMenuId(10L); | |
| 56 | + CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name()) | |
| 57 | + .setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true) | |
| 58 | + .setOrdinalPosition(1).setJavaType("Long").setJavaField("id").setExample("1024") | |
| 59 | + .setCreateOperation(false).setUpdateOperation(true).setListOperation(false) | |
| 60 | + .setListOperationResult(true); | |
| 61 | + CodegenColumnDO nameColumn = new CodegenColumnDO().setColumnName("name").setDataType(JdbcType.VARCHAR.name()) | |
| 62 | + .setColumnComment("名字").setNullable(false).setPrimaryKey(false) | |
| 63 | + .setOrdinalPosition(2).setJavaType("String").setJavaField("name").setExample("芋头") | |
| 64 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 65 | + .setListOperationCondition(CodegenColumnListConditionEnum.LIKE.getCondition()).setListOperationResult(true) | |
| 66 | + .setHtmlType(CodegenColumnHtmlTypeEnum.INPUT.getType()); | |
| 67 | + CodegenColumnDO avatarColumn = new CodegenColumnDO().setColumnName("avatar").setDataType(JdbcType.VARCHAR.name()) | |
| 68 | + .setColumnComment("头像").setNullable(true).setPrimaryKey(false) | |
| 69 | + .setOrdinalPosition(3).setJavaType("String").setJavaField("avatar").setExample("https://www.iocoder.cn/1.png") | |
| 70 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) | |
| 71 | + .setListOperationResult(true) | |
| 72 | + .setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE.getType()); | |
| 73 | + CodegenColumnDO videoColumn = new CodegenColumnDO().setColumnName("video").setDataType(JdbcType.VARCHAR.name()) | |
| 74 | + .setColumnComment("视频").setNullable(true).setPrimaryKey(false) | |
| 75 | + .setOrdinalPosition(4).setJavaType("String").setJavaField("video").setExample("https://www.iocoder.cn/1.mp4") | |
| 76 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) | |
| 77 | + .setListOperationResult(true) | |
| 78 | + .setHtmlType(CodegenColumnHtmlTypeEnum.UPLOAD_FILE.getType()); | |
| 79 | + CodegenColumnDO descriptionColumn = new CodegenColumnDO().setColumnName("description").setDataType(JdbcType.VARCHAR.name()) | |
| 80 | + .setColumnComment("个人简介").setNullable(true).setPrimaryKey(false) | |
| 81 | + .setOrdinalPosition(5).setJavaType("String").setJavaField("description").setExample("我是介绍") | |
| 82 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) | |
| 83 | + .setListOperationResult(true) | |
| 84 | + .setHtmlType(CodegenColumnHtmlTypeEnum.EDITOR.getType()); | |
| 85 | + CodegenColumnDO sex1Column = new CodegenColumnDO().setColumnName("sex1").setDataType(JdbcType.VARCHAR.name()) | |
| 86 | + .setColumnComment("性别 1").setNullable(true).setPrimaryKey(false) | |
| 87 | + .setOrdinalPosition(6).setJavaType("String").setJavaField("sex1").setExample("男") | |
| 88 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 89 | + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) | |
| 90 | + .setHtmlType(CodegenColumnHtmlTypeEnum.SELECT.getType()).setDictType("system_sex1"); | |
| 91 | + CodegenColumnDO sex2Column = new CodegenColumnDO().setColumnName("sex2").setDataType(JdbcType.INTEGER.name()) | |
| 92 | + .setColumnComment("性别 2").setNullable(true).setPrimaryKey(false) | |
| 93 | + .setOrdinalPosition(7).setJavaType("Integer").setJavaField("sex2").setExample("1") | |
| 94 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 95 | + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) | |
| 96 | + .setHtmlType(CodegenColumnHtmlTypeEnum.CHECKBOX.getType()).setDictType("system_sex2"); | |
| 97 | + CodegenColumnDO sex3Column = new CodegenColumnDO().setColumnName("sex3").setDataType(JdbcType.BOOLEAN.name()) | |
| 98 | + .setColumnComment("性别 3").setNullable(true).setPrimaryKey(false) | |
| 99 | + .setOrdinalPosition(8).setJavaType("Boolean").setJavaField("sex3").setExample("true") | |
| 100 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 101 | + .setListOperationResult(true) | |
| 102 | + .setHtmlType(CodegenColumnHtmlTypeEnum.RADIO.getType()).setDictType("system_sex3"); | |
| 103 | + CodegenColumnDO birthdayColumn = new CodegenColumnDO().setColumnName("birthday").setDataType(JdbcType.DATE.name()) | |
| 104 | + .setColumnComment("出生日期").setNullable(true).setPrimaryKey(false) | |
| 105 | + .setOrdinalPosition(9).setJavaType("LocalDateTime").setJavaField("birthday") | |
| 106 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 107 | + .setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition()).setListOperationResult(true) | |
| 108 | + .setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType()); | |
| 109 | + CodegenColumnDO memoColumn = new CodegenColumnDO().setColumnName("memo").setDataType(JdbcType.VARCHAR.name()) | |
| 110 | + .setColumnComment("备注").setNullable(true).setPrimaryKey(false) | |
| 111 | + .setOrdinalPosition(10).setJavaType("String").setJavaField("memo").setExample("我是备注") | |
| 112 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(false) | |
| 113 | + .setListOperationResult(true) | |
| 114 | + .setHtmlType(CodegenColumnHtmlTypeEnum.TEXTAREA.getType()); | |
| 115 | + CodegenColumnDO createTimeColumn = new CodegenColumnDO().setColumnName("create_time").setDataType(JdbcType.DATE.name()) | |
| 116 | + .setColumnComment("创建时间").setNullable(true).setPrimaryKey(false) | |
| 117 | + .setOrdinalPosition(11).setJavaType("LocalDateTime").setJavaField("createTime") | |
| 118 | + .setCreateOperation(true).setUpdateOperation(true).setListOperation(true) | |
| 119 | + .setListOperationCondition(CodegenColumnListConditionEnum.BETWEEN.getCondition()).setListOperationResult(true) | |
| 120 | + .setHtmlType(CodegenColumnHtmlTypeEnum.DATETIME.getType()); | |
| 121 | + List<CodegenColumnDO> columns = Arrays.asList(idColumn, nameColumn, avatarColumn, descriptionColumn, | |
| 122 | + sex1Column, sex2Column, sex3Column, birthdayColumn, memoColumn, createTimeColumn); | |
| 123 | + | |
| 124 | + // 调用 | |
| 125 | + Map<String, String> result = codegenEngine.execute(table, columns, null, null); | |
| 126 | + | |
| 127 | + // 断言 | |
| 128 | + assertEquals(21, result.size()); | |
| 129 | + // 断言 vo 类 | |
| 130 | + for (String vo : new String[]{"SystemUserBaseVO", "SystemUserCreateReqVO", "SystemUserUpdateReqVO", "SystemUserRespVO", | |
| 131 | + "SystemUserPageReqVO", "SystemUserExportReqVO", "SystemUserExcelVO"}) { | |
| 132 | + assertPathContentEquals("vue3_crud/java/" + vo, | |
| 133 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/controller/admin/user/vo/" + vo + ".java"); | |
| 134 | + } | |
| 135 | + // 断言 controller 类 | |
| 136 | + assertPathContentEquals("vue3_crud/java/SystemUserController", | |
| 137 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/controller/admin/user/SystemUserController.java"); | |
| 138 | + // 断言 service 类 | |
| 139 | + assertPathContentEquals("vue3_crud/java/SystemUserService", | |
| 140 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserService.java"); | |
| 141 | + assertPathContentEquals("vue3_crud/java/SystemUserServiceImpl", | |
| 142 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserServiceImpl.java"); | |
| 143 | + // 断言 convert 类 | |
| 144 | + assertPathContentEquals("vue3_crud/java/SystemUserConvert", | |
| 145 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/convert/user/SystemUserConvert.java"); | |
| 146 | + // 断言 enums 类 | |
| 147 | + assertPathContentEquals("vue3_crud/java/ErrorCodeConstants", | |
| 148 | + result, "yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/module/system/enums/ErrorCodeConstants_手动操作.java"); | |
| 149 | + // 断言 dal 类 | |
| 150 | + assertPathContentEquals("vue3_crud/java/SystemUserDO", | |
| 151 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/dal/dataobject/user/SystemUserDO.java"); | |
| 152 | + assertPathContentEquals("vue3_crud/java/SystemUserMapper", | |
| 153 | + result, "yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/module/system/dal/mysql/user/SystemUserMapper.java"); | |
| 154 | + assertPathContentEquals("vue3_crud/java/SystemUserMapper_xml", | |
| 155 | + result, "yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/user/SystemUserMapper.xml"); | |
| 156 | + // 断言 test 类 | |
| 157 | + assertPathContentEquals("vue3_crud/java/SystemUserServiceImplTest", | |
| 158 | + result, "yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/module/system/service/user/SystemUserServiceImplTest.java"); | |
| 159 | + // 断言 sql 语句 | |
| 160 | + assertPathContentEquals("vue3_crud/sql/h2", | |
| 161 | + result, "sql/h2.sql"); | |
| 162 | + assertPathContentEquals("vue3_crud/sql/sql", | |
| 163 | + result, "sql/sql.sql"); | |
| 164 | + // 断言 vue 语句 | |
| 165 | + assertPathContentEquals("vue3_crud/vue/index", | |
| 166 | + result, "yudao-ui-admin-vue3/src/views/system/user/index.vue"); | |
| 167 | + assertPathContentEquals("vue3_crud/vue/form", | |
| 168 | + result, "yudao-ui-admin-vue3/src/views/system/user/UserForm.vue"); | |
| 169 | + assertPathContentEquals("vue3_crud/vue/api", | |
| 170 | + result, "yudao-ui-admin-vue3/src/api/system/user/index.ts"); | |
| 171 | +// result.forEach(new BiConsumer<String, String>() { | |
| 172 | +// @Override | |
| 173 | +// public void accept(String s, String s2) { | |
| 174 | +// System.out.println(s); | |
| 175 | +// System.out.println(s2); | |
| 176 | +// System.out.println("================="); | |
| 177 | +// } | |
| 178 | +// }); | |
| 179 | + } | |
| 180 | + | |
| 181 | + private void assertPathContentEquals(String path, Map<String, String> result, String key) { | |
| 182 | + String pathContent = ResourceUtil.readUtf8Str("codegen/" + path); | |
| 183 | + String valueContent = result.get(key); | |
| 184 | + assertEquals(pathContent, valueContent); | |
| 185 | + } | |
| 186 | + | |
| 187 | +} | |
| 0 | 188 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/package-info.java
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/ErrorCodeConstants
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserBaseVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | +import javax.validation.constraints.*; | |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 10 | + | |
| 11 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 用户 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 15 | + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +public class SystemUserBaseVO { | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "头像", example = "https://www.iocoder.cn/1.png") | |
| 25 | + private String avatar; | |
| 26 | + | |
| 27 | + @Schema(description = "个人简介", example = "我是介绍") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "性别 1", example = "男") | |
| 31 | + private String sex1; | |
| 32 | + | |
| 33 | + @Schema(description = "性别 2", example = "1") | |
| 34 | + private Integer sex2; | |
| 35 | + | |
| 36 | + @Schema(description = "性别 3", example = "true") | |
| 37 | + private Boolean sex3; | |
| 38 | + | |
| 39 | + @Schema(description = "出生日期") | |
| 40 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + | |
| 43 | + @Schema(description = "备注", example = "我是备注") | |
| 44 | + private String memo; | |
| 45 | + | |
| 46 | + @Schema(description = "创建时间") | |
| 47 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 48 | + private LocalDateTime createTime; | |
| 49 | + | |
| 50 | +} | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 20 | + | |
| 21 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 24 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 25 | + | |
| 26 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 27 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 28 | +import cn.iocoder.yudao.module.module.system.convert.user.SystemUserConvert; | |
| 29 | +import cn.iocoder.yudao.module.module.system.service.user.SystemUserService; | |
| 30 | + | |
| 31 | +@Tag(name = "管理后台 - 用户") | |
| 32 | +@RestController | |
| 33 | +@RequestMapping("/system/user") | |
| 34 | +@Validated | |
| 35 | +public class SystemUserController { | |
| 36 | + | |
| 37 | + @Resource | |
| 38 | + private SystemUserService userService; | |
| 39 | + | |
| 40 | + @PostMapping("/create") | |
| 41 | + @Operation(summary = "创建用户") | |
| 42 | + @PreAuthorize("@ss.hasPermission('system:user:create')") | |
| 43 | + public CommonResult<Long> createUser(@Valid @RequestBody SystemUserCreateReqVO createReqVO) { | |
| 44 | + return success(userService.createUser(createReqVO)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @PutMapping("/update") | |
| 48 | + @Operation(summary = "更新用户") | |
| 49 | + @PreAuthorize("@ss.hasPermission('system:user:update')") | |
| 50 | + public CommonResult<Boolean> updateUser(@Valid @RequestBody SystemUserUpdateReqVO updateReqVO) { | |
| 51 | + userService.updateUser(updateReqVO); | |
| 52 | + return success(true); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @DeleteMapping("/delete") | |
| 56 | + @Operation(summary = "删除用户") | |
| 57 | + @Parameter(name = "id", description = "编号", required = true) | |
| 58 | + @PreAuthorize("@ss.hasPermission('system:user:delete')") | |
| 59 | + public CommonResult<Boolean> deleteUser(@RequestParam("id") Long id) { | |
| 60 | + userService.deleteUser(id); | |
| 61 | + return success(true); | |
| 62 | + } | |
| 63 | + | |
| 64 | + @GetMapping("/get") | |
| 65 | + @Operation(summary = "获得用户") | |
| 66 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 67 | + @PreAuthorize("@ss.hasPermission('system:user:query')") | |
| 68 | + public CommonResult<SystemUserRespVO> getUser(@RequestParam("id") Long id) { | |
| 69 | + SystemUserDO user = userService.getUser(id); | |
| 70 | + return success(SystemUserConvert.INSTANCE.convert(user)); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @GetMapping("/list") | |
| 74 | + @Operation(summary = "获得用户列表") | |
| 75 | + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | |
| 76 | + @PreAuthorize("@ss.hasPermission('system:user:query')") | |
| 77 | + public CommonResult<List<SystemUserRespVO>> getUserList(@RequestParam("ids") Collection<Long> ids) { | |
| 78 | + List<SystemUserDO> list = userService.getUserList(ids); | |
| 79 | + return success(SystemUserConvert.INSTANCE.convertList(list)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/page") | |
| 83 | + @Operation(summary = "获得用户分页") | |
| 84 | + @PreAuthorize("@ss.hasPermission('system:user:query')") | |
| 85 | + public CommonResult<PageResult<SystemUserRespVO>> getUserPage(@Valid SystemUserPageReqVO pageVO) { | |
| 86 | + PageResult<SystemUserDO> pageResult = userService.getUserPage(pageVO); | |
| 87 | + return success(SystemUserConvert.INSTANCE.convertPage(pageResult)); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @GetMapping("/export-excel") | |
| 91 | + @Operation(summary = "导出用户 Excel") | |
| 92 | + @PreAuthorize("@ss.hasPermission('system:user:export')") | |
| 93 | + @OperateLog(type = EXPORT) | |
| 94 | + public void exportUserExcel(@Valid SystemUserExportReqVO exportReqVO, | |
| 95 | + HttpServletResponse response) throws IOException { | |
| 96 | + List<SystemUserDO> list = userService.getUserList(exportReqVO); | |
| 97 | + // 导出 Excel | |
| 98 | + List<SystemUserExcelVO> datas = SystemUserConvert.INSTANCE.convertList02(list); | |
| 99 | + ExcelUtils.write(response, "用户.xls", "数据", SystemUserExcelVO.class, datas); | |
| 100 | + } | |
| 101 | + | |
| 102 | +} | |
| 0 | 103 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserConvert
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.convert.user; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | + | |
| 7 | +import org.mapstruct.Mapper; | |
| 8 | +import org.mapstruct.factory.Mappers; | |
| 9 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 用户 Convert | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface SystemUserConvert { | |
| 19 | + | |
| 20 | + SystemUserConvert INSTANCE = Mappers.getMapper(SystemUserConvert.class); | |
| 21 | + | |
| 22 | + SystemUserDO convert(SystemUserCreateReqVO bean); | |
| 23 | + | |
| 24 | + SystemUserDO convert(SystemUserUpdateReqVO bean); | |
| 25 | + | |
| 26 | + SystemUserRespVO convert(SystemUserDO bean); | |
| 27 | + | |
| 28 | + List<SystemUserRespVO> convertList(List<SystemUserDO> list); | |
| 29 | + | |
| 30 | + PageResult<SystemUserRespVO> convertPage(PageResult<SystemUserDO> page); | |
| 31 | + | |
| 32 | + List<SystemUserExcelVO> convertList02(List<SystemUserDO> list); | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserCreateReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 用户创建 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class SystemUserCreateReqVO extends SystemUserBaseVO { | |
| 13 | + | |
| 14 | +} | |
| 0 | 15 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.dal.dataobject.user; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 用户 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("system_user") | |
| 16 | +@KeySequence("system_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class SystemUserDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 头像 | |
| 36 | + */ | |
| 37 | + private String avatar; | |
| 38 | + /** | |
| 39 | + * 个人简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 性别 1 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_sex1 对应的类} | |
| 46 | + */ | |
| 47 | + private String sex1; | |
| 48 | + /** | |
| 49 | + * 性别 2 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO system_sex2 对应的类} | |
| 52 | + */ | |
| 53 | + private Integer sex2; | |
| 54 | + /** | |
| 55 | + * 性别 3 | |
| 56 | + * | |
| 57 | + * 枚举 {@link TODO system_sex3 对应的类} | |
| 58 | + */ | |
| 59 | + private Boolean sex3; | |
| 60 | + /** | |
| 61 | + * 出生日期 | |
| 62 | + */ | |
| 63 | + private LocalDateTime birthday; | |
| 64 | + /** | |
| 65 | + * 备注 | |
| 66 | + */ | |
| 67 | + private String memo; | |
| 68 | + | |
| 69 | +} | |
| 0 | 70 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExcelVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 用户 Excel VO | |
| 16 | + * | |
| 17 | + * @author 芋道源码 | |
| 18 | + */ | |
| 19 | +@Data | |
| 20 | +public class SystemUserExcelVO { | |
| 21 | + | |
| 22 | + @ExcelProperty("编号") | |
| 23 | + private Long id; | |
| 24 | + | |
| 25 | + @ExcelProperty("名字") | |
| 26 | + private String name; | |
| 27 | + | |
| 28 | + @ExcelProperty("头像") | |
| 29 | + private String avatar; | |
| 30 | + | |
| 31 | + @ExcelProperty("个人简介") | |
| 32 | + private String description; | |
| 33 | + | |
| 34 | + @ExcelProperty(value = "性别 1", converter = DictConvert.class) | |
| 35 | + @DictFormat("system_sex1") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 36 | + private String sex1; | |
| 37 | + | |
| 38 | + @ExcelProperty(value = "性别 2", converter = DictConvert.class) | |
| 39 | + @DictFormat("system_sex2") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 40 | + private Integer sex2; | |
| 41 | + | |
| 42 | + @ExcelProperty(value = "性别 3", converter = DictConvert.class) | |
| 43 | + @DictFormat("system_sex3") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 44 | + private Boolean sex3; | |
| 45 | + | |
| 46 | + @ExcelProperty("出生日期") | |
| 47 | + private LocalDateTime birthday; | |
| 48 | + | |
| 49 | + @ExcelProperty("备注") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | + @ExcelProperty("创建时间") | |
| 53 | + private LocalDateTime createTime; | |
| 54 | + | |
| 55 | +} | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserExportReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 用户 Excel 导出 Request VO,参数和 SystemUserPageReqVO 是一致的") | |
| 13 | +@Data | |
| 14 | +public class SystemUserExportReqVO { | |
| 15 | + | |
| 16 | + @Schema(description = "名字", example = "芋头") | |
| 17 | + private String name; | |
| 18 | + | |
| 19 | + @Schema(description = "性别 1", example = "男") | |
| 20 | + private String sex1; | |
| 21 | + | |
| 22 | + @Schema(description = "性别 2", example = "1") | |
| 23 | + private Integer sex2; | |
| 24 | + | |
| 25 | + @Schema(description = "性别 3", example = "true") | |
| 26 | + private Boolean sex3; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期") | |
| 29 | + private LocalDateTime birthday; | |
| 30 | + | |
| 31 | + @Schema(description = "创建时间") | |
| 32 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 33 | + private LocalDateTime[] createTime; | |
| 34 | + | |
| 35 | +} | |
| 0 | 36 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.dal.mysql.user; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 用户 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface SystemUserMapper extends BaseMapperX<SystemUserDO> { | |
| 19 | + | |
| 20 | + default PageResult<SystemUserDO> selectPage(SystemUserPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<SystemUserDO>() | |
| 22 | + .likeIfPresent(SystemUserDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(SystemUserDO::getSex1, reqVO.getSex1()) | |
| 24 | + .eqIfPresent(SystemUserDO::getSex2, reqVO.getSex2()) | |
| 25 | + .eqIfPresent(SystemUserDO::getBirthday, reqVO.getBirthday()) | |
| 26 | + .betweenIfPresent(SystemUserDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(SystemUserDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | + default List<SystemUserDO> selectList(SystemUserExportReqVO reqVO) { | |
| 31 | + return selectList(new LambdaQueryWrapperX<SystemUserDO>() | |
| 32 | + .likeIfPresent(SystemUserDO::getName, reqVO.getName()) | |
| 33 | + .eqIfPresent(SystemUserDO::getSex1, reqVO.getSex1()) | |
| 34 | + .eqIfPresent(SystemUserDO::getSex2, reqVO.getSex2()) | |
| 35 | + .eqIfPresent(SystemUserDO::getBirthday, reqVO.getBirthday()) | |
| 36 | + .betweenIfPresent(SystemUserDO::getCreateTime, reqVO.getCreateTime()) | |
| 37 | + .orderByDesc(SystemUserDO::getId)); | |
| 38 | + } | |
| 39 | + | |
| 40 | +} | |
| 0 | 41 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserMapper_xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.module.system.dal.mysql.user.SystemUserMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 用户分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class SystemUserPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "性别 1", example = "男") | |
| 22 | + private String sex1; | |
| 23 | + | |
| 24 | + @Schema(description = "性别 2", example = "1") | |
| 25 | + private Integer sex2; | |
| 26 | + | |
| 27 | + @Schema(description = "性别 3", example = "true") | |
| 28 | + private Boolean sex3; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期") | |
| 31 | + private LocalDateTime birthday; | |
| 32 | + | |
| 33 | + @Schema(description = "创建时间") | |
| 34 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 35 | + private LocalDateTime[] createTime; | |
| 36 | + | |
| 37 | +} | |
| 0 | 38 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | + | |
| 7 | +@Schema(description = "管理后台 - 用户 Response VO") | |
| 8 | +@Data | |
| 9 | +@EqualsAndHashCode(callSuper = true) | |
| 10 | +@ToString(callSuper = true) | |
| 11 | +public class SystemUserRespVO extends SystemUserBaseVO { | |
| 12 | + | |
| 13 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | +} | |
| 0 | 17 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.service.user; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 用户 Service 接口 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +public interface SystemUserService { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 创建用户 | |
| 18 | + * | |
| 19 | + * @param createReqVO 创建信息 | |
| 20 | + * @return 编号 | |
| 21 | + */ | |
| 22 | + Long createUser(@Valid SystemUserCreateReqVO createReqVO); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 更新用户 | |
| 26 | + * | |
| 27 | + * @param updateReqVO 更新信息 | |
| 28 | + */ | |
| 29 | + void updateUser(@Valid SystemUserUpdateReqVO updateReqVO); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 删除用户 | |
| 33 | + * | |
| 34 | + * @param id 编号 | |
| 35 | + */ | |
| 36 | + void deleteUser(Long id); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 获得用户 | |
| 40 | + * | |
| 41 | + * @param id 编号 | |
| 42 | + * @return 用户 | |
| 43 | + */ | |
| 44 | + SystemUserDO getUser(Long id); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 获得用户列表 | |
| 48 | + * | |
| 49 | + * @param ids 编号 | |
| 50 | + * @return 用户列表 | |
| 51 | + */ | |
| 52 | + List<SystemUserDO> getUserList(Collection<Long> ids); | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 获得用户分页 | |
| 56 | + * | |
| 57 | + * @param pageReqVO 分页查询 | |
| 58 | + * @return 用户分页 | |
| 59 | + */ | |
| 60 | + PageResult<SystemUserDO> getUserPage(SystemUserPageReqVO pageReqVO); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * 获得用户列表, 用于 Excel 导出 | |
| 64 | + * | |
| 65 | + * @param exportReqVO 查询条件 | |
| 66 | + * @return 用户列表 | |
| 67 | + */ | |
| 68 | + List<SystemUserDO> getUserList(SystemUserExportReqVO exportReqVO); | |
| 69 | + | |
| 70 | +} | |
| 0 | 71 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.service.user; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | + | |
| 7 | +import java.util.*; | |
| 8 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 9 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 11 | + | |
| 12 | +import cn.iocoder.yudao.module.module.system.convert.user.SystemUserConvert; | |
| 13 | +import cn.iocoder.yudao.module.module.system.dal.mysql.user.SystemUserMapper; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 16 | +import static cn.iocoder.yudao.module.module.system.enums.ErrorCodeConstants.*; | |
| 17 | + | |
| 18 | +import cn.hutool.core.collection.CollUtil; | |
| 19 | +import cn.hutool.core.collection.ListUtil; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * 用户 Service 实现类 | |
| 23 | + * | |
| 24 | + * @author 芋道源码 | |
| 25 | + */ | |
| 26 | +@Service | |
| 27 | +@Validated | |
| 28 | +public class SystemUserServiceImpl implements SystemUserService { | |
| 29 | + | |
| 30 | + @Resource | |
| 31 | + private SystemUserMapper userMapper; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public Long createUser(SystemUserCreateReqVO createReqVO) { | |
| 35 | + // 插入 | |
| 36 | + SystemUserDO user = SystemUserConvert.INSTANCE.convert(createReqVO); | |
| 37 | + userMapper.insert(user); | |
| 38 | + // 返回 | |
| 39 | + return user.getId(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public void updateUser(SystemUserUpdateReqVO updateReqVO) { | |
| 44 | + // 校验存在 | |
| 45 | + validateUserExists(updateReqVO.getId()); | |
| 46 | + // 更新 | |
| 47 | + SystemUserDO updateObj = SystemUserConvert.INSTANCE.convert(updateReqVO); | |
| 48 | + userMapper.updateById(updateObj); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public void deleteUser(Long id) { | |
| 53 | + // 校验存在 | |
| 54 | + validateUserExists(id); | |
| 55 | + // 删除 | |
| 56 | + userMapper.deleteById(id); | |
| 57 | + } | |
| 58 | + | |
| 59 | + private void validateUserExists(Long id) { | |
| 60 | + if (userMapper.selectById(id) == null) { | |
| 61 | + throw exception(USER_NOT_EXISTS); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public SystemUserDO getUser(Long id) { | |
| 67 | + return userMapper.selectById(id); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public List<SystemUserDO> getUserList(Collection<Long> ids) { | |
| 72 | + if (CollUtil.isEmpty(ids)) { | |
| 73 | + return ListUtil.empty(); | |
| 74 | + } | |
| 75 | + return userMapper.selectBatchIds(ids); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + public PageResult<SystemUserDO> getUserPage(SystemUserPageReqVO pageReqVO) { | |
| 80 | + return userMapper.selectPage(pageReqVO); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Override | |
| 84 | + public List<SystemUserDO> getUserList(SystemUserExportReqVO exportReqVO) { | |
| 85 | + return userMapper.selectList(exportReqVO); | |
| 86 | + } | |
| 87 | + | |
| 88 | +} | |
| 0 | 89 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.service.user; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.module.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.module.system.controller.admin.user.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.module.system.dal.dataobject.user.SystemUserDO; | |
| 13 | +import cn.iocoder.yudao.module.module.system.dal.mysql.user.SystemUserMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.module.system.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.module.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.module.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link SystemUserServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(SystemUserServiceImpl.class) | |
| 37 | +public class SystemUserServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private SystemUserServiceImpl userService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private SystemUserMapper userMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateUser_success() { | |
| 47 | + // 准备参数 | |
| 48 | + SystemUserCreateReqVO reqVO = randomPojo(SystemUserCreateReqVO.class); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long userId = userService.createUser(reqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(userId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + SystemUserDO user = userMapper.selectById(userId); | |
| 56 | + assertPojoEquals(reqVO, user); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateUser_success() { | |
| 61 | + // mock 数据 | |
| 62 | + SystemUserDO dbUser = randomPojo(SystemUserDO.class); | |
| 63 | + userMapper.insert(dbUser);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + SystemUserUpdateReqVO reqVO = randomPojo(SystemUserUpdateReqVO.class, o -> { | |
| 66 | + o.setId(dbUser.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + userService.updateUser(reqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + SystemUserDO user = userMapper.selectById(reqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(reqVO, user); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateUser_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + SystemUserUpdateReqVO reqVO = randomPojo(SystemUserUpdateReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> userService.updateUser(reqVO), USER_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteUser_success() { | |
| 87 | + // mock 数据 | |
| 88 | + SystemUserDO dbUser = randomPojo(SystemUserDO.class); | |
| 89 | + userMapper.insert(dbUser);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbUser.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + userService.deleteUser(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(userMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteUser_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> userService.deleteUser(id), USER_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetUserPage() { | |
| 111 | + // mock 数据 | |
| 112 | + SystemUserDO dbUser = randomPojo(SystemUserDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setSex1(null); | |
| 115 | + o.setSex2(null); | |
| 116 | + o.setSex3(null); | |
| 117 | + o.setBirthday(null); | |
| 118 | + o.setCreateTime(null); | |
| 119 | + }); | |
| 120 | + userMapper.insert(dbUser); | |
| 121 | + // 测试 name 不匹配 | |
| 122 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setName(null))); | |
| 123 | + // 测试 sex1 不匹配 | |
| 124 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex1(null))); | |
| 125 | + // 测试 sex2 不匹配 | |
| 126 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex2(null))); | |
| 127 | + // 测试 sex3 不匹配 | |
| 128 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex3(null))); | |
| 129 | + // 测试 birthday 不匹配 | |
| 130 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setBirthday(null))); | |
| 131 | + // 测试 createTime 不匹配 | |
| 132 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setCreateTime(null))); | |
| 133 | + // 准备参数 | |
| 134 | + SystemUserPageReqVO reqVO = new SystemUserPageReqVO(); | |
| 135 | + reqVO.setName(null); | |
| 136 | + reqVO.setSex1(null); | |
| 137 | + reqVO.setSex2(null); | |
| 138 | + reqVO.setSex3(null); | |
| 139 | + reqVO.setBirthday(null); | |
| 140 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 141 | + | |
| 142 | + // 调用 | |
| 143 | + PageResult<SystemUserDO> pageResult = userService.getUserPage(reqVO); | |
| 144 | + // 断言 | |
| 145 | + assertEquals(1, pageResult.getTotal()); | |
| 146 | + assertEquals(1, pageResult.getList().size()); | |
| 147 | + assertPojoEquals(dbUser, pageResult.getList().get(0)); | |
| 148 | + } | |
| 149 | + | |
| 150 | + @Test | |
| 151 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 152 | + public void testGetUserList() { | |
| 153 | + // mock 数据 | |
| 154 | + SystemUserDO dbUser = randomPojo(SystemUserDO.class, o -> { // 等会查询到 | |
| 155 | + o.setName(null); | |
| 156 | + o.setSex1(null); | |
| 157 | + o.setSex2(null); | |
| 158 | + o.setSex3(null); | |
| 159 | + o.setBirthday(null); | |
| 160 | + o.setCreateTime(null); | |
| 161 | + }); | |
| 162 | + userMapper.insert(dbUser); | |
| 163 | + // 测试 name 不匹配 | |
| 164 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setName(null))); | |
| 165 | + // 测试 sex1 不匹配 | |
| 166 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex1(null))); | |
| 167 | + // 测试 sex2 不匹配 | |
| 168 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex2(null))); | |
| 169 | + // 测试 sex3 不匹配 | |
| 170 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setSex3(null))); | |
| 171 | + // 测试 birthday 不匹配 | |
| 172 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setBirthday(null))); | |
| 173 | + // 测试 createTime 不匹配 | |
| 174 | + userMapper.insert(cloneIgnoreId(dbUser, o -> o.setCreateTime(null))); | |
| 175 | + // 准备参数 | |
| 176 | + SystemUserExportReqVO reqVO = new SystemUserExportReqVO(); | |
| 177 | + reqVO.setName(null); | |
| 178 | + reqVO.setSex1(null); | |
| 179 | + reqVO.setSex2(null); | |
| 180 | + reqVO.setSex3(null); | |
| 181 | + reqVO.setBirthday(null); | |
| 182 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 183 | + | |
| 184 | + // 调用 | |
| 185 | + List<SystemUserDO> list = userService.getUserList(reqVO); | |
| 186 | + // 断言 | |
| 187 | + assertEquals(1, list.size()); | |
| 188 | + assertPojoEquals(dbUser, list.get(0)); | |
| 189 | + } | |
| 190 | + | |
| 191 | +} | |
| 0 | 192 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/java/SystemUserUpdateReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.module.system.controller.admin.user.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 用户更新 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class SystemUserUpdateReqVO extends SystemUserBaseVO { | |
| 13 | + | |
| 14 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | + @NotNull(message = "编号不能为空") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | +} | |
| 0 | 19 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-system-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "system_user" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "avatar" varchar, | |
| 6 | + "description" varchar, | |
| 7 | + "sex1" varchar, | |
| 8 | + "sex2" int, | |
| 9 | + "sex3" bit, | |
| 10 | + "birthday" varchar, | |
| 11 | + "memo" varchar, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '用户表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-system-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "system_user"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '用户管理', '', 2, 0, 10, | |
| 8 | + 'user', '', 'system/user/index', 0, 'SystemUser' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '用户查询', 'system:user:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '用户创建', 'system:user:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '用户更新', 'system:user:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '用户删除', 'system:user:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '用户导出', 'system:user:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/api
0 → 100644
| 1 | +import request from '@/config/axios' | |
| 2 | + | |
| 3 | +export interface UserVO { | |
| 4 | + id: number | |
| 5 | + name: string | |
| 6 | + avatar: string | |
| 7 | + description: string | |
| 8 | + sex1: string | |
| 9 | + sex2: number | |
| 10 | + sex3: boolean | |
| 11 | + birthday: Date | |
| 12 | + memo: string | |
| 13 | + createTime: Date | |
| 14 | +} | |
| 15 | + | |
| 16 | +// 查询用户列表 | |
| 17 | +export const getUserPage = async (params) => { | |
| 18 | + return await request.get({ url: `/system/user/page`, params }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 查询用户详情 | |
| 22 | +export const getUser = async (id: number) => { | |
| 23 | + return await request.get({ url: `/system/user/get?id=` + id }) | |
| 24 | +} | |
| 25 | + | |
| 26 | +// 新增用户 | |
| 27 | +export const createUser = async (data: UserVO) => { | |
| 28 | + return await request.post({ url: `/system/user/create`, data }) | |
| 29 | +} | |
| 30 | + | |
| 31 | +// 修改用户 | |
| 32 | +export const updateUser = async (data: UserVO) => { | |
| 33 | + return await request.put({ url: `/system/user/update`, data }) | |
| 34 | +} | |
| 35 | + | |
| 36 | +// 删除用户 | |
| 37 | +export const deleteUser = async (id: number) => { | |
| 38 | + return await request.delete({ url: `/system/user/delete?id=` + id }) | |
| 39 | +} | |
| 40 | + | |
| 41 | +// 导出用户 Excel | |
| 42 | +export const exportUser = async (params) => { | |
| 43 | + return await request.download({ url: `/system/user/export-excel`, params }) | |
| 44 | +} | |
| 0 | 45 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/form
0 → 100644
| 1 | +<template> | |
| 2 | + <Dialog :title="dialogTitle" v-model="dialogVisible"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-width="100px" | |
| 8 | + v-loading="formLoading" | |
| 9 | + > | |
| 10 | + <el-form-item label="名字" prop="name"> | |
| 11 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 12 | + </el-form-item> | |
| 13 | + <el-form-item label="个人简介"> | |
| 14 | + <Editor v-model="formData.description" height="150px" /> | |
| 15 | + </el-form-item> | |
| 16 | + <el-form-item label="性别 1" prop="sex1"> | |
| 17 | + <el-select v-model="formData.sex1" placeholder="请选择性别 1"> | |
| 18 | + <el-option | |
| 19 | + v-for="dict in getStrDictOptions(DICT_TYPE.SYSTEM_SEX1)" | |
| 20 | + :key="dict.value" | |
| 21 | + :label="dict.label" | |
| 22 | + :value="dict.value" | |
| 23 | + /> | |
| 24 | + </el-select> | |
| 25 | + </el-form-item> | |
| 26 | + <el-form-item label="性别 2" prop="sex2"> | |
| 27 | + <el-checkbox-group v-model="formData.sex2"> | |
| 28 | + <el-checkbox | |
| 29 | + v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_SEX2)" | |
| 30 | + :key="dict.value" | |
| 31 | + :label="dict.value" | |
| 32 | + > | |
| 33 | + {{ dict.label }} | |
| 34 | + </el-checkbox> | |
| 35 | + </el-checkbox-group> | |
| 36 | + </el-form-item> | |
| 37 | + <el-form-item label="性别 3" prop="sex3"> | |
| 38 | + <el-radio-group v-model="formData.sex3"> | |
| 39 | + <el-radio | |
| 40 | + v-for="dict in getBoolDictOptions(DICT_TYPE.SYSTEM_SEX3)" | |
| 41 | + :key="dict.value" | |
| 42 | + :label="dict.value" | |
| 43 | + > | |
| 44 | + {{ dict.label }} | |
| 45 | + </el-radio> | |
| 46 | + </el-radio-group> | |
| 47 | + </el-form-item> | |
| 48 | + <el-form-item label="出生日期" prop="birthday"> | |
| 49 | + <el-date-picker | |
| 50 | + v-model="formData.birthday" | |
| 51 | + type="date" | |
| 52 | + value-format="x" | |
| 53 | + placeholder="选择出生日期" | |
| 54 | + /> | |
| 55 | + </el-form-item> | |
| 56 | + <el-form-item label="备注" prop="memo"> | |
| 57 | + <el-input v-model="formData.memo" type="textarea" placeholder="请输入备注" /> | |
| 58 | + </el-form-item> | |
| 59 | + <el-form-item label="创建时间" prop="createTime"> | |
| 60 | + <el-date-picker | |
| 61 | + v-model="formData.createTime" | |
| 62 | + type="date" | |
| 63 | + value-format="x" | |
| 64 | + placeholder="选择创建时间" | |
| 65 | + /> | |
| 66 | + </el-form-item> | |
| 67 | + </el-form> | |
| 68 | + <template #footer> | |
| 69 | + <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button> | |
| 70 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 71 | + </template> | |
| 72 | + </Dialog> | |
| 73 | +</template> | |
| 74 | +<script setup lang="ts"> | |
| 75 | +import { DICT_TYPE, getStrDictOptions, getIntDictOptions, getBoolDictOptions } from '@/utils/dict' | |
| 76 | +import * as UserApi from '@/api/system/user' | |
| 77 | + | |
| 78 | +const { t } = useI18n() // 国际化 | |
| 79 | +const message = useMessage() // 消息弹窗 | |
| 80 | + | |
| 81 | +const dialogVisible = ref(false) // 弹窗的是否展示 | |
| 82 | +const dialogTitle = ref('') // 弹窗的标题 | |
| 83 | +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 84 | +const formType = ref('') // 表单的类型:create - 新增;update - 修改 | |
| 85 | +const formData = ref({ | |
| 86 | + id: undefined, | |
| 87 | + name: undefined, | |
| 88 | + avatar: undefined, | |
| 89 | + description: undefined, | |
| 90 | + sex1: undefined, | |
| 91 | + sex2: [], | |
| 92 | + sex3: undefined, | |
| 93 | + birthday: undefined, | |
| 94 | + memo: undefined, | |
| 95 | + createTime: undefined | |
| 96 | +}) | |
| 97 | +const formRules = reactive({ | |
| 98 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }] | |
| 99 | +}) | |
| 100 | +const formRef = ref() // 表单 Ref | |
| 101 | + | |
| 102 | +/** 打开弹窗 */ | |
| 103 | +const open = async (type: string, id?: number) => { | |
| 104 | + dialogVisible.value = true | |
| 105 | + dialogTitle.value = t('action.' + type) | |
| 106 | + formType.value = type | |
| 107 | + resetForm() | |
| 108 | + // 修改时,设置数据 | |
| 109 | + if (id) { | |
| 110 | + formLoading.value = true | |
| 111 | + try { | |
| 112 | + formData.value = await UserApi.getUser(id) | |
| 113 | + } finally { | |
| 114 | + formLoading.value = false | |
| 115 | + } | |
| 116 | + } | |
| 117 | +} | |
| 118 | +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 | |
| 119 | + | |
| 120 | +/** 提交表单 */ | |
| 121 | +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 | |
| 122 | +const submitForm = async () => { | |
| 123 | + // 校验表单 | |
| 124 | + if (!formRef) return | |
| 125 | + const valid = await formRef.value.validate() | |
| 126 | + if (!valid) return | |
| 127 | + // 提交请求 | |
| 128 | + formLoading.value = true | |
| 129 | + try { | |
| 130 | + const data = formData.value as unknown as UserApi.UserVO | |
| 131 | + if (formType.value === 'create') { | |
| 132 | + await UserApi.createUser(data) | |
| 133 | + message.success(t('common.createSuccess')) | |
| 134 | + } else { | |
| 135 | + await UserApi.updateUser(data) | |
| 136 | + message.success(t('common.updateSuccess')) | |
| 137 | + } | |
| 138 | + dialogVisible.value = false | |
| 139 | + // 发送操作成功的事件 | |
| 140 | + emit('success') | |
| 141 | + } finally { | |
| 142 | + formLoading.value = false | |
| 143 | + } | |
| 144 | +} | |
| 145 | + | |
| 146 | +/** 重置表单 */ | |
| 147 | +const resetForm = () => { | |
| 148 | + formData.value = { | |
| 149 | + id: undefined, | |
| 150 | + name: undefined, | |
| 151 | + avatar: undefined, | |
| 152 | + description: undefined, | |
| 153 | + sex1: undefined, | |
| 154 | + sex2: [], | |
| 155 | + sex3: undefined, | |
| 156 | + birthday: undefined, | |
| 157 | + memo: undefined, | |
| 158 | + createTime: undefined | |
| 159 | + } | |
| 160 | + formRef.value?.resetFields() | |
| 161 | +} | |
| 162 | +</script> | |
| 0 | 163 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_crud/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <ContentWrap> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <el-form | |
| 5 | + class="-mb-15px" | |
| 6 | + :model="queryParams" | |
| 7 | + ref="queryFormRef" | |
| 8 | + :inline="true" | |
| 9 | + label-width="68px" | |
| 10 | + > | |
| 11 | + <el-form-item label="名字" prop="name"> | |
| 12 | + <el-input | |
| 13 | + v-model="queryParams.name" | |
| 14 | + placeholder="请输入名字" | |
| 15 | + clearable | |
| 16 | + @keyup.enter="handleQuery" | |
| 17 | + class="!w-240px" | |
| 18 | + /> | |
| 19 | + </el-form-item> | |
| 20 | + <el-form-item label="性别 1" prop="sex1"> | |
| 21 | + <el-select v-model="queryParams.sex1" placeholder="请选择性别 1" clearable class="!w-240px"> | |
| 22 | + <el-option | |
| 23 | + v-for="dict in getStrDictOptions(DICT_TYPE.SYSTEM_SEX1)" | |
| 24 | + :key="dict.value" | |
| 25 | + :label="dict.label" | |
| 26 | + :value="dict.value" | |
| 27 | + /> | |
| 28 | + </el-select> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="性别 3" prop="sex3"> | |
| 31 | + <el-select v-model="queryParams.sex3" placeholder="请选择性别 3" clearable class="!w-240px"> | |
| 32 | + <el-option | |
| 33 | + v-for="dict in getBoolDictOptions(DICT_TYPE.SYSTEM_SEX3)" | |
| 34 | + :key="dict.value" | |
| 35 | + :label="dict.label" | |
| 36 | + :value="dict.value" | |
| 37 | + /> | |
| 38 | + </el-select> | |
| 39 | + </el-form-item> | |
| 40 | + <el-form-item label="出生日期" prop="birthday"> | |
| 41 | + <el-date-picker | |
| 42 | + v-model="queryParams.birthday" | |
| 43 | + value-format="YYYY-MM-DD" | |
| 44 | + type="date" | |
| 45 | + placeholder="选择出生日期" | |
| 46 | + clearable | |
| 47 | + class="!w-240px" | |
| 48 | + /> | |
| 49 | + </el-form-item> | |
| 50 | + <el-form-item label="创建时间" prop="createTime"> | |
| 51 | + <el-date-picker | |
| 52 | + v-model="queryParams.createTime" | |
| 53 | + value-format="YYYY-MM-DD HH:mm:ss" | |
| 54 | + type="daterange" | |
| 55 | + start-placeholder="开始日期" | |
| 56 | + end-placeholder="结束日期" | |
| 57 | + :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" | |
| 58 | + class="!w-240px" | |
| 59 | + /> | |
| 60 | + </el-form-item> | |
| 61 | + <el-form-item> | |
| 62 | + <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> | |
| 63 | + <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> | |
| 64 | + <el-button type="primary" @click="openForm('create')" v-hasPermi="['system:user:create']"> | |
| 65 | + <Icon icon="ep:plus" class="mr-5px" /> 新增 | |
| 66 | + </el-button> | |
| 67 | + <el-button | |
| 68 | + type="success" | |
| 69 | + plain | |
| 70 | + @click="handleExport" | |
| 71 | + :loading="exportLoading" | |
| 72 | + v-hasPermi="['system:user:export']" | |
| 73 | + > | |
| 74 | + <Icon icon="ep:download" class="mr-5px" /> 导出 | |
| 75 | + </el-button> | |
| 76 | + </el-form-item> | |
| 77 | + </el-form> | |
| 78 | + </ContentWrap> | |
| 79 | + | |
| 80 | + <!-- 列表 --> | |
| 81 | + <ContentWrap> | |
| 82 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 83 | + <el-table-column label="编号" align="center" prop="id"> | |
| 84 | + <template #default="scope"> | |
| 85 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 86 | + </template> | |
| 87 | + </el-table-column> | |
| 88 | + <el-table-column label="名字" align="center" prop="name"> | |
| 89 | + <template #default="scope"> | |
| 90 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 91 | + </template> | |
| 92 | + </el-table-column> | |
| 93 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 94 | + <template #default="scope"> | |
| 95 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 96 | + </template> | |
| 97 | + </el-table-column> | |
| 98 | + <el-table-column label="个人简介" align="center" prop="description"> | |
| 99 | + <template #default="scope"> | |
| 100 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 101 | + </template> | |
| 102 | + </el-table-column> | |
| 103 | + <el-table-column label="性别 1" align="center" prop="sex1"> | |
| 104 | + <template #default="scope"> | |
| 105 | + <dict-tag :type="DICT_TYPE.SYSTEM_SEX1" :value="scope.row.sex1" /> | |
| 106 | + </template> | |
| 107 | + </el-table-column> | |
| 108 | + <el-table-column label="性别 2" align="center" prop="sex2"> | |
| 109 | + <template #default="scope"> | |
| 110 | + <dict-tag :type="DICT_TYPE.SYSTEM_SEX2" :value="scope.row.sex2" /> | |
| 111 | + </template> | |
| 112 | + </el-table-column> | |
| 113 | + <el-table-column label="性别 3" align="center" prop="sex3"> | |
| 114 | + <template #default="scope"> | |
| 115 | + <dict-tag :type="DICT_TYPE.SYSTEM_SEX3" :value="scope.row.sex3" /> | |
| 116 | + </template> | |
| 117 | + </el-table-column> | |
| 118 | + <el-table-column | |
| 119 | + label="出生日期" | |
| 120 | + align="center" | |
| 121 | + prop="birthday" | |
| 122 | + :formatter="dateFormatter" | |
| 123 | + width="180px" | |
| 124 | + /> | |
| 125 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 126 | + <template #default="scope"> | |
| 127 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 128 | + </template> | |
| 129 | + </el-table-column> | |
| 130 | + <el-table-column | |
| 131 | + label="创建时间" | |
| 132 | + align="center" | |
| 133 | + prop="createTime" | |
| 134 | + :formatter="dateFormatter" | |
| 135 | + width="180px" | |
| 136 | + /> | |
| 137 | + <el-table-column label="操作" align="center"> | |
| 138 | + <template #default="scope"> | |
| 139 | + <el-button | |
| 140 | + link | |
| 141 | + type="primary" | |
| 142 | + @click="openForm('update', scope.row.id)" | |
| 143 | + v-hasPermi="['system:user:update']" | |
| 144 | + > | |
| 145 | + 编辑 | |
| 146 | + </el-button> | |
| 147 | + <el-button | |
| 148 | + link | |
| 149 | + type="danger" | |
| 150 | + @click="handleDelete(scope.row.id)" | |
| 151 | + v-hasPermi="['system:user:delete']" | |
| 152 | + > | |
| 153 | + 删除 | |
| 154 | + </el-button> | |
| 155 | + </template> | |
| 156 | + </el-table-column> | |
| 157 | + </el-table> | |
| 158 | + <!-- 分页 --> | |
| 159 | + <Pagination | |
| 160 | + :total="total" | |
| 161 | + v-model:page="queryParams.pageNo" | |
| 162 | + v-model:limit="queryParams.pageSize" | |
| 163 | + @pagination="getList" | |
| 164 | + /> | |
| 165 | + </ContentWrap> | |
| 166 | + | |
| 167 | + <!-- 表单弹窗:添加/修改 --> | |
| 168 | + <UserForm ref="formRef" @success="getList" /> | |
| 169 | +</template> | |
| 170 | + | |
| 171 | +<script setup lang="ts"> | |
| 172 | +import { DICT_TYPE, getStrDictOptions, getBoolDictOptions } from '@/utils/dict' | |
| 173 | +import { dateFormatter } from '@/utils/formatTime' | |
| 174 | +import download from '@/utils/download' | |
| 175 | +import * as UserApi from '@/api/system/user' | |
| 176 | +import UserForm from './UserForm.vue' | |
| 177 | + | |
| 178 | +defineOptions({ name: 'SystemUser' }) | |
| 179 | + | |
| 180 | +const message = useMessage() // 消息弹窗 | |
| 181 | +const { t } = useI18n() // 国际化 | |
| 182 | + | |
| 183 | +const loading = ref(true) // 列表的加载中 | |
| 184 | +const total = ref(0) // 列表的总页数 | |
| 185 | +const list = ref([]) // 列表的数据 | |
| 186 | +const queryParams = reactive({ | |
| 187 | + pageNo: 1, | |
| 188 | + pageSize: 10, | |
| 189 | + name: null, | |
| 190 | + sex1: null, | |
| 191 | + sex2: null, | |
| 192 | + sex3: null, | |
| 193 | + birthday: null, | |
| 194 | + birthday: [], | |
| 195 | + createTime: [] | |
| 196 | +}) | |
| 197 | +const queryFormRef = ref() // 搜索的表单 | |
| 198 | +const exportLoading = ref(false) // 导出的加载中 | |
| 199 | + | |
| 200 | +/** 查询列表 */ | |
| 201 | +const getList = async () => { | |
| 202 | + loading.value = true | |
| 203 | + try { | |
| 204 | + const data = await UserApi.getUserPage(queryParams) | |
| 205 | + list.value = data.list | |
| 206 | + total.value = data.total | |
| 207 | + } finally { | |
| 208 | + loading.value = false | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 212 | +/** 搜索按钮操作 */ | |
| 213 | +const handleQuery = () => { | |
| 214 | + queryParams.pageNo = 1 | |
| 215 | + getList() | |
| 216 | +} | |
| 217 | + | |
| 218 | +/** 重置按钮操作 */ | |
| 219 | +const resetQuery = () => { | |
| 220 | + queryFormRef.value.resetFields() | |
| 221 | + handleQuery() | |
| 222 | +} | |
| 223 | + | |
| 224 | +/** 添加/修改操作 */ | |
| 225 | +const formRef = ref() | |
| 226 | +const openForm = (type: string, id?: number) => { | |
| 227 | + formRef.value.open(type, id) | |
| 228 | +} | |
| 229 | + | |
| 230 | +/** 删除按钮操作 */ | |
| 231 | +const handleDelete = async (id: number) => { | |
| 232 | + try { | |
| 233 | + // 删除的二次确认 | |
| 234 | + await message.delConfirm() | |
| 235 | + // 发起删除 | |
| 236 | + await UserApi.deleteUser(id) | |
| 237 | + message.success(t('common.delSuccess')) | |
| 238 | + // 刷新列表 | |
| 239 | + await getList() | |
| 240 | + } catch {} | |
| 241 | +} | |
| 242 | + | |
| 243 | +/** 导出按钮操作 */ | |
| 244 | +const handleExport = async () => { | |
| 245 | + try { | |
| 246 | + // 导出的二次确认 | |
| 247 | + await message.exportConfirm() | |
| 248 | + // 发起导出 | |
| 249 | + exportLoading.value = true | |
| 250 | + const data = await UserApi.exportUser(queryParams) | |
| 251 | + download.excel(data, '用户.xls') | |
| 252 | + } catch { | |
| 253 | + } finally { | |
| 254 | + exportLoading.value = false | |
| 255 | + } | |
| 256 | +} | |
| 257 | + | |
| 258 | +/** 初始化 **/ | |
| 259 | +onMounted(() => { | |
| 260 | + getList() | |
| 261 | +}) | |
| 262 | +</script> | |
| 0 | 263 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue3_master_sub/1
0 → 100644