mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	!97 修复仅本人数据权限时,个人中心会报错的问题
Merge pull request !97 from 芋道源码/feature/1.6.1
This commit is contained in:
		| @@ -1,7 +1,9 @@ | |||||||
| package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo; | 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.column.CodegenColumnBaseVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO; | 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.ApiModel; | ||||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| @@ -9,6 +11,7 @@ import lombok.EqualsAndHashCode; | |||||||
| import lombok.ToString; | import lombok.ToString; | ||||||
|  |  | ||||||
| import javax.validation.Valid; | import javax.validation.Valid; | ||||||
|  | import javax.validation.constraints.AssertTrue; | ||||||
| import javax.validation.constraints.NotNull; | import javax.validation.constraints.NotNull; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| @@ -28,11 +31,19 @@ public class CodegenUpdateReqVO { | |||||||
|     @Data |     @Data | ||||||
|     @EqualsAndHashCode(callSuper = true) |     @EqualsAndHashCode(callSuper = true) | ||||||
|     @ToString(callSuper = true) |     @ToString(callSuper = true) | ||||||
|  |     @Valid | ||||||
|     public static class Table extends CodegenTableBaseVO { |     public static class Table extends CodegenTableBaseVO { | ||||||
|  |  | ||||||
|         @ApiModelProperty(value = "编号", required = true, example = "1") |         @ApiModelProperty(value = "编号", required = true, example = "1") | ||||||
|         private Long id; |         private Long id; | ||||||
|  |  | ||||||
|  |         @AssertTrue(message = "上级菜单不能为空") | ||||||
|  |         public boolean isParentMenuIdValid() { | ||||||
|  |             // 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的 | ||||||
|  |             return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene()) | ||||||
|  |                     || getParentMenuId() != null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ApiModel("更新表定义") |     @ApiModel("更新表定义") | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.service.codegen; | |||||||
|  |  | ||||||
| import cn.hutool.core.collection.CollUtil; | import cn.hutool.core.collection.CollUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | 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.CodegenUpdateReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.convert.codegen.CodegenConvert; | 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.SchemaColumnMapper; | ||||||
| import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaTableMapper; | 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.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.framework.codegen.config.CodegenProperties; | ||||||
| import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; | 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.CodegenEngine; | ||||||
| import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser; | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser; | ||||||
| import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 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.apache.commons.collections4.KeyValue; | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||||
|  |  | ||||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||||
| import java.util.ArrayList; | import java.util.*; | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.Set; |  | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||||
| @@ -266,27 +264,8 @@ public class CodegenServiceImpl implements CodegenService { | |||||||
|         // TODO 强制移除 Quartz 的表,未来做成可配置 |         // TODO 强制移除 Quartz 的表,未来做成可配置 | ||||||
|         tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); |         tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); | ||||||
|         tables.removeIf(table -> table.getTableName().startsWith("ACT_")); |         tables.removeIf(table -> table.getTableName().startsWith("ACT_")); | ||||||
|  |         tables.removeIf(table -> table.getTableName().startsWith("FLW_")); | ||||||
|         return tables; |         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("树名称字段不能为空"); |  | ||||||
| //            } |  | ||||||
| //        } |  | ||||||
| //    } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -51,6 +51,8 @@ public class CodegenBuilder { | |||||||
|                     .put("image", CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE) |                     .put("image", CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE) | ||||||
|                     .put("file", CodegenColumnHtmlTypeEnum.UPLOAD_FILE) |                     .put("file", CodegenColumnHtmlTypeEnum.UPLOAD_FILE) | ||||||
|                     .put("content", CodegenColumnHtmlTypeEnum.EDITOR) |                     .put("content", CodegenColumnHtmlTypeEnum.EDITOR) | ||||||
|  |                     .put("description", CodegenColumnHtmlTypeEnum.EDITOR) | ||||||
|  |                     .put("demo", CodegenColumnHtmlTypeEnum.EDITOR) | ||||||
|                     .put("time", CodegenColumnHtmlTypeEnum.DATETIME) |                     .put("time", CodegenColumnHtmlTypeEnum.DATETIME) | ||||||
|                     .put("date", CodegenColumnHtmlTypeEnum.DATETIME) |                     .put("date", CodegenColumnHtmlTypeEnum.DATETIME) | ||||||
|                     .build(); |                     .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} 的字段 |      * {@link cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO} 的字段 | ||||||
|      */ |      */ | ||||||
| @@ -121,14 +123,13 @@ public class CodegenBuilder { | |||||||
|     private void initTableDefault(CodegenTableDO table) { |     private void initTableDefault(CodegenTableDO table) { | ||||||
|         // 以 system_dept 举例子。moduleName 为 system、businessName 为 dept、className 为 SystemDept |         // 以 system_dept 举例子。moduleName 为 system、businessName 为 dept、className 为 SystemDept | ||||||
|         // 如果不希望 System 前缀,则可以手动在【代码生成 - 修改生成配置 - 基本信息】,将实体类名称改为 Dept 即可 |         // 如果不希望 System 前缀,则可以手动在【代码生成 - 修改生成配置 - 基本信息】,将实体类名称改为 Dept 即可 | ||||||
|         table.setModuleName(StrUtil.subBefore(table.getTableName(), |         table.setModuleName(subBefore(table.getTableName(), '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 | ||||||
|                 '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 |  | ||||||
|         table.setBusinessName(toCamelCase(subAfter(table.getTableName(), |         table.setBusinessName(toCamelCase(subAfter(table.getTableName(), | ||||||
|                 '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰 |                 '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰 | ||||||
|         table.setClassName(upperFirst(toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写 |         table.setClassName(upperFirst(toCamelCase( // 驼峰 + 首字母大写 | ||||||
|  |                 subAfter(table.getTableName(), '_', false)))); // 第一个 _ 前缀的前面,作为 class 名字 | ||||||
|         table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 |         table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 | ||||||
|                 '表', true)); |                 '表', true)); | ||||||
|         table.setAuthor("芋艿"); // TODO 稍后改成创建人 |  | ||||||
|         table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); |         table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -157,7 +158,7 @@ public class CodegenBuilder { | |||||||
|         column.setJavaField(toCamelCase(column.getColumnName())); |         column.setJavaField(toCamelCase(column.getColumnName())); | ||||||
|         // 处理 dictType 字段,暂无 |         // 处理 dictType 字段,暂无 | ||||||
|         // 处理 javaType 字段 |         // 处理 javaType 字段 | ||||||
|         String dbType = StrUtil.subBefore(column.getColumnType(), '(', false); |         String dbType = subBefore(column.getColumnType(), '(', false); | ||||||
|         javaTypeMappings.entrySet().stream() |         javaTypeMappings.entrySet().stream() | ||||||
|                 .filter(entry -> entry.getValue().contains(dbType)) |                 .filter(entry -> entry.getValue().contains(dbType)) | ||||||
|                 .findFirst().ifPresent(entry -> column.setJavaType(entry.getKey())); |                 .findFirst().ifPresent(entry -> column.setJavaType(entry.getKey())); | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; | package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; | ||||||
|  |  | ||||||
|  | import org.junit.jupiter.api.Disabled; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| import org.springframework.boot.test.mock.mockito.MockBean; | 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); |         assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test // TODO 请修改 null 为需要的值 |     @Test | ||||||
|  |     @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||||||
|     public void testGet${simpleClassName}Page() { |     public void testGet${simpleClassName}Page() { | ||||||
|        #getPageCondition("PageReqVO") |        #getPageCondition("PageReqVO") | ||||||
|  |  | ||||||
| @@ -147,7 +149,8 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest { | |||||||
|        assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0)); |        assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test // TODO 请修改 null 为需要的值 |     @Test | ||||||
|  |     @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | ||||||
|     public void testGet${simpleClassName}List() { |     public void testGet${simpleClassName}List() { | ||||||
|        #getPageCondition("ExportReqVO") |        #getPageCondition("ExportReqVO") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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.enums.UserTypeEnum; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
| import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | 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.framework.operatelog.core.annotations.OperateLog; | ||||||
| import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; | ||||||
| import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; | import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; | ||||||
| @@ -64,7 +63,6 @@ public class AuthController { | |||||||
|  |  | ||||||
|     @GetMapping("/get-permission-info") |     @GetMapping("/get-permission-info") | ||||||
|     @ApiOperation("获取登录用户的权限信息") |     @ApiOperation("获取登录用户的权限信息") | ||||||
|     @DataPermission(enable = false) // 标记不使用数据权限,避免【SELF】权限范围报错 |  | ||||||
|     public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() { |     public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() { | ||||||
|         // 获得用户信息 |         // 获得用户信息 | ||||||
|         AdminUserDO user = userService.getUser(getLoginUserId()); |         AdminUserDO user = userService.getUser(getLoginUserId()); | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; | |||||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||||
| import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 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.UserProfileRespVO; | ||||||
| import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; | ||||||
| import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; | ||||||
| @@ -58,6 +59,7 @@ public class UserProfileController { | |||||||
|  |  | ||||||
|     @GetMapping("/get") |     @GetMapping("/get") | ||||||
|     @ApiOperation("获得登录用户信息") |     @ApiOperation("获得登录用户信息") | ||||||
|  |     @DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 | ||||||
|     public CommonResult<UserProfileRespVO> profile() { |     public CommonResult<UserProfileRespVO> profile() { | ||||||
|         // 获得用户基本信息 |         // 获得用户基本信息 | ||||||
|         AdminUserDO user = userService.getUser(getLoginUserId()); |         AdminUserDO user = userService.getUser(getLoginUserId()); | ||||||
|   | |||||||
| @@ -17,8 +17,11 @@ public class DataPermissionConfiguration { | |||||||
|     @Bean |     @Bean | ||||||
|     public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() { |     public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() { | ||||||
|         return rule -> { |         return rule -> { | ||||||
|  |             // dept | ||||||
|             rule.addDeptColumn(AdminUserDO.class); |             rule.addDeptColumn(AdminUserDO.class); | ||||||
|             rule.addDeptColumn(DeptDO.class, "id"); |             rule.addDeptColumn(DeptDO.class, "id"); | ||||||
|  |             // user | ||||||
|  |             rule.addUserColumn(AdminUserDO.class, "id"); | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,13 @@ | |||||||
|       </el-col> |       </el-col> | ||||||
|  |  | ||||||
|       <el-col :span="12"> |       <el-col :span="12"> | ||||||
|         <el-form-item label="实体类名称" prop="className"> |         <el-form-item prop="className"> | ||||||
|  |           <span slot="label"> | ||||||
|  |             实体类名称 | ||||||
|  |             <el-tooltip content="默认去除表名的前缀。如果存在重复,则需要手动添加前缀,避免 MyBatis 报 Alias 重复的问题。" placement="top"> | ||||||
|  |               <i class="el-icon-question"></i> | ||||||
|  |             </el-tooltip> | ||||||
|  |           </span> | ||||||
|           <el-input placeholder="请输入" v-model="info.className" /> |           <el-input placeholder="请输入" v-model="info.className" /> | ||||||
|         </el-form-item> |         </el-form-item> | ||||||
|       </el-col> |       </el-col> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 芋道源码
					芋道源码