From 6f8baa3110608891e429e1898b44c753a87de234 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Mar 2022 01:29:50 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=98=AF=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8C=E5=BF=85=E9=A1=BB=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/codegen/vo/CodegenUpdateReqVO.java | 11 +++++++ .../service/codegen/CodegenServiceImpl.java | 29 +++---------------- .../service/codegen/inner/CodegenBuilder.java | 9 +++--- .../src/views/infra/codegen/basicInfoForm.vue | 8 ++++- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java index 617182e53..eebbbe4c5 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo; +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 io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -9,6 +11,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import javax.validation.Valid; +import javax.validation.constraints.AssertTrue; import javax.validation.constraints.NotNull; import java.util.List; @@ -28,11 +31,19 @@ public class CodegenUpdateReqVO { @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) + @Valid public static class Table extends CodegenTableBaseVO { @ApiModelProperty(value = "编号", required = true, example = "1") private Long id; + @AssertTrue(message = "生成失败,必须设置上级菜单") + public boolean isParentMenuIdValid() { + // 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的 + return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene()) + || getParentMenuId() != null; + } + } @ApiModel("更新表定义") diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index ec7388b8b..1c2b59ba8 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.service.codegen; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.CodegenUpdateReqVO; import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO; import cn.iocoder.yudao.module.infra.convert.codegen.CodegenConvert; @@ -14,21 +15,18 @@ import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaColumnMapper; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaTableMapper; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenImportTypeEnum; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import org.apache.commons.collections4.KeyValue; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -266,27 +264,8 @@ public class CodegenServiceImpl implements CodegenService { // TODO 强制移除 Quartz 的表,未来做成可配置 tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); tables.removeIf(table -> table.getTableName().startsWith("ACT_")); + tables.removeIf(table -> table.getTableName().startsWith("FLW_")); return tables; } -// /** -// * 修改保存参数校验 -// * -// * @param genTable 业务信息 -// */ -// @Override -// public void validateEdit(GenTable genTable) { -// if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { -// String options = JSON.toJSONString(genTable.getParams()); -// JSONObject paramsObj = JSONObject.parseObject(options); -// if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { -// throw new CustomException("树编码字段不能为空"); -// } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { -// throw new CustomException("树父编码字段不能为空"); -// } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { -// throw new CustomException("树名称字段不能为空"); -// } -// } -// } - } diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java index f3dfbcd2e..afa7c0686 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java @@ -121,14 +121,13 @@ public class CodegenBuilder { private void initTableDefault(CodegenTableDO table) { // 以 system_dept 举例子。moduleName 为 system、businessName 为 dept、className 为 SystemDept // 如果不希望 System 前缀,则可以手动在【代码生成 - 修改生成配置 - 基本信息】,将实体类名称改为 Dept 即可 - table.setModuleName(StrUtil.subBefore(table.getTableName(), - '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 + table.setModuleName(subBefore(table.getTableName(), '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 table.setBusinessName(toCamelCase(subAfter(table.getTableName(), '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰 - table.setClassName(upperFirst(toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写 + table.setClassName(upperFirst(toCamelCase( // 驼峰 + 首字母大写 + subAfter(table.getTableName(), '_', false)))); // 第一个 _ 前缀的前面,作为 class 名字 table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 '表', true)); - table.setAuthor("芋艿"); // TODO 稍后改成创建人 table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); } @@ -157,7 +156,7 @@ public class CodegenBuilder { column.setJavaField(toCamelCase(column.getColumnName())); // 处理 dictType 字段,暂无 // 处理 javaType 字段 - String dbType = StrUtil.subBefore(column.getColumnType(), '(', false); + String dbType = subBefore(column.getColumnType(), '(', false); javaTypeMappings.entrySet().stream() .filter(entry -> entry.getValue().contains(dbType)) .findFirst().ifPresent(entry -> column.setJavaType(entry.getKey())); diff --git a/yudao-ui-admin/src/views/infra/codegen/basicInfoForm.vue b/yudao-ui-admin/src/views/infra/codegen/basicInfoForm.vue index 184141b28..d2b374444 100644 --- a/yudao-ui-admin/src/views/infra/codegen/basicInfoForm.vue +++ b/yudao-ui-admin/src/views/infra/codegen/basicInfoForm.vue @@ -13,7 +13,13 @@ - + + + 实体类名称 + + + + From c11a14b9dab8779c811524129ce3bd0ab24c6abf Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Mar 2022 01:31:26 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=98=AF=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8C=E5=BF=85=E9=A1=BB=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java index eebbbe4c5..2423da077 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java @@ -37,7 +37,7 @@ public class CodegenUpdateReqVO { @ApiModelProperty(value = "编号", required = true, example = "1") private Long id; - @AssertTrue(message = "生成失败,必须设置上级菜单") + @AssertTrue(message = "上级菜单不能为空") public boolean isParentMenuIdValid() { // 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的 return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene()) From 5c0e695f344db4a0a91940b97e839ea1a870837c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Mar 2022 15:02:53 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=97=B6=EF=BC=8Ctenant=5Fid=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=9C=80=E8=A6=81=E4=BC=A0=E9=80=92=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/infra/service/codegen/inner/CodegenBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java index afa7c0686..4c7ba479f 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java @@ -51,6 +51,8 @@ public class CodegenBuilder { .put("image", CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE) .put("file", CodegenColumnHtmlTypeEnum.UPLOAD_FILE) .put("content", CodegenColumnHtmlTypeEnum.EDITOR) + .put("description", CodegenColumnHtmlTypeEnum.EDITOR) + .put("demo", CodegenColumnHtmlTypeEnum.EDITOR) .put("time", CodegenColumnHtmlTypeEnum.DATETIME) .put("date", CodegenColumnHtmlTypeEnum.DATETIME) .build(); @@ -58,7 +60,7 @@ public class CodegenBuilder { /** * 多租户编号的字段名 */ - public static final String TENANT_ID_FIELD = "tenant_id"; + public static final String TENANT_ID_FIELD = "tenantId"; /** * {@link cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO} 的字段 */ From dae1f79e5e6f99adaec911058cd955900518277e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Mar 2022 16:00:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20serviceTest.vm=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=9A=84=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=20@Disabled=20=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/codegen/java/test/serviceTest.vm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/java/test/serviceTest.vm b/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/java/test/serviceTest.vm index 53b7429ec..67ea47d2c 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/java/test/serviceTest.vm +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/resources/codegen/java/test/serviceTest.vm @@ -1,5 +1,6 @@ package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -135,7 +136,8 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); } - @Test // TODO 请修改 null 为需要的值 + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGet${simpleClassName}Page() { #getPageCondition("PageReqVO") @@ -147,7 +149,8 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0)); } - @Test // TODO 请修改 null 为需要的值 + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGet${simpleClassName}List() { #getPageCondition("ExportReqVO") From 446f601c8a6030839e66b4711ad0709c62a6cadd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 12 Mar 2022 18:02:28 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=85=E6=9C=AC?= =?UTF-8?q?=E4=BA=BA=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E4=BC=9A=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/controller/admin/auth/AuthController.java | 2 -- .../system/controller/admin/user/UserProfileController.java | 2 ++ .../datapermission/config/DataPermissionConfiguration.java | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java index 30e527571..fe31c20b4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.collection.SetUtils; -import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; @@ -64,7 +63,6 @@ public class AuthController { @GetMapping("/get-permission-info") @ApiOperation("获取登录用户的权限信息") - @DataPermission(enable = false) // 标记不使用数据权限,避免【SELF】权限范围报错 public CommonResult getPermissionInfo() { // 获得用户信息 AdminUserDO user = userService.getUser(getLoginUserId()); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java index f3a8c2c61..d68fa96cc 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; @@ -58,6 +59,7 @@ public class UserProfileController { @GetMapping("/get") @ApiOperation("获得登录用户信息") + @DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 public CommonResult profile() { // 获得用户基本信息 AdminUserDO user = userService.getUser(getLoginUserId()); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/datapermission/config/DataPermissionConfiguration.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/datapermission/config/DataPermissionConfiguration.java index 0be6684c8..d7246f242 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/datapermission/config/DataPermissionConfiguration.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/framework/datapermission/config/DataPermissionConfiguration.java @@ -17,8 +17,11 @@ public class DataPermissionConfiguration { @Bean public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() { return rule -> { + // dept rule.addDeptColumn(AdminUserDO.class); rule.addDeptColumn(DeptDO.class, "id"); + // user + rule.addUserColumn(AdminUserDO.class, "id"); }; }