支持多层级租户,租户父子关系依托与组织机构的父子关系
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,12 +10,12 @@ import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -52,13 +52,15 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
// 准备参数
|
||||
RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class)
|
||||
.setId(null) // 防止 id 被赋值
|
||||
.setStatus(randomCommonStatus());
|
||||
.setStatus(randomCommonStatus())
|
||||
.setType(RoleTypeEnum.CUSTOM.getType()) // 设置为自定义角色;
|
||||
.setParentId(0L);
|
||||
|
||||
// 调用
|
||||
Long roleId = roleService.createRole(reqVO, null);
|
||||
// 断言
|
||||
RoleDO roleDO = roleMapper.selectById(roleId);
|
||||
assertPojoEquals(reqVO, roleDO, "id");
|
||||
assertPojoEquals(reqVO, roleDO, "id", "parentName");
|
||||
assertEquals(RoleTypeEnum.CUSTOM.getType(), roleDO.getType());
|
||||
assertEquals(DataScopeEnum.ALL.getScope(), roleDO.getDataScope());
|
||||
}
|
||||
@@ -77,7 +79,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
roleService.updateRole(reqVO);
|
||||
// 断言
|
||||
RoleDO newRoleDO = roleMapper.selectById(id);
|
||||
assertPojoEquals(reqVO, newRoleDO);
|
||||
assertPojoEquals(reqVO, newRoleDO, "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,7 +186,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
// 调用
|
||||
RoleDO dbRoleDO = roleService.getRole(id);
|
||||
// 断言
|
||||
assertPojoEquals(roleDO, dbRoleDO);
|
||||
assertPojoEquals(roleDO, dbRoleDO, "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -198,7 +200,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
// 调用
|
||||
RoleDO dbRoleDO = roleService.getRoleFromCache(id);
|
||||
// 断言
|
||||
assertPojoEquals(roleDO, dbRoleDO);
|
||||
assertPojoEquals(roleDO, dbRoleDO, "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,7 +216,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
assertPojoEquals(dbRole01, list.get(0), "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,8 +231,8 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
List<RoleDO> list = roleService.getRoleList();
|
||||
// 断言
|
||||
assertEquals(2, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
assertPojoEquals(dbRole02, list.get(1));
|
||||
assertPojoEquals(dbRole01, list.get(0), "parentName");
|
||||
assertPojoEquals(dbRole02, list.get(1), "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +249,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
List<RoleDO> list = roleService.getRoleList(ids);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
assertPojoEquals(dbRole01, list.get(0), "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -268,7 +270,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
List<RoleDO> list = roleService.getRoleListFromCache(ids);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole, list.get(0));
|
||||
assertPojoEquals(dbRole, list.get(0), "parentName");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +302,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRole, pageResult.getList().get(0));
|
||||
assertPojoEquals(dbRole, pageResult.getList().get(0), "parentName");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,6 +34,8 @@ mybatis-plus:
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: AUTO # H2 主键递增
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS "system_dept" (
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint not null default '0',
|
||||
"is_tenant" bit NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '部门表';
|
||||
|
||||
@@ -50,6 +51,7 @@ CREATE TABLE IF NOT EXISTS "system_role" (
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint not null default '0',
|
||||
"parent_id" bigint NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '角色信息表';
|
||||
|
||||
@@ -612,3 +614,17 @@ CREATE TABLE IF NOT EXISTS "system_notify_message" (
|
||||
"tenant_id" bigint not null default '0',
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '站内信消息表';
|
||||
|
||||
CREATE TABLE if not exists `system_role_menu_exclusion` (
|
||||
`id` BIGINT PRIMARY KEY COMMENT '主键ID',
|
||||
`role_id` BIGINT NOT NULL COMMENT '角色ID',
|
||||
`menu_id` BIGINT NOT NULL COMMENT '菜单ID',
|
||||
`remark` VARCHAR(2000) COMMENT '备注',
|
||||
`creator` VARCHAR(256) DEFAULT '' COMMENT '创建者',
|
||||
`create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
|
||||
`updater` VARCHAR(256) DEFAULT '' COMMENT '更新者',
|
||||
`update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '更新时间',
|
||||
`deleted` TINYINT DEFAULT 0 NOT NULL COMMENT '是否删除',
|
||||
`tenant_id` BIGINT DEFAULT 0 NOT NULL COMMENT '租户编号',
|
||||
UNIQUE KEY `idx_role_menu_exclusion_id` (`id`)
|
||||
) COMMENT='角色菜单剔除表';
|
||||
|
||||
Reference in New Issue
Block a user