diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/controller/common/LoginController.java b/agileboot-admin/src/main/java/com/agileboot/admin/controller/common/LoginController.java
index f64e230..5d8e8ad 100644
--- a/agileboot-admin/src/main/java/com/agileboot/admin/controller/common/LoginController.java
+++ b/agileboot-admin/src/main/java/com/agileboot/admin/controller/common/LoginController.java
@@ -109,8 +109,8 @@ public class LoginController {
*/
@GetMapping("/getRouters")
public ResponseDTO> getRouters() {
- Long userId = AuthenticationUtils.getUserId();
- List routerTree = menuApplicationService.getRouterTree(userId);
+ LoginUser loginUser = AuthenticationUtils.getLoginUser();
+ List routerTree = menuApplicationService.getRouterTree(loginUser);
return ResponseDTO.ok(routerTree);
}
diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/system/menu/MenuApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/system/menu/MenuApplicationService.java
index b3fce5e..4d3d587 100644
--- a/agileboot-domain/src/main/java/com/agileboot/domain/system/menu/MenuApplicationService.java
+++ b/agileboot-domain/src/main/java/com/agileboot/domain/system/menu/MenuApplicationService.java
@@ -121,12 +121,12 @@ public class MenuApplicationService {
}
- public List> buildMenuEntityTree(Long userId) {
+ public List> buildMenuEntityTree(LoginUser loginUser) {
List allMenus;
- if (LoginUser.isAdmin(userId)) {
+ if (loginUser.isAdmin()) {
allMenus = menuService.list();
} else {
- allMenus = menuService.getMenuListByUserId(userId);
+ allMenus = menuService.getMenuListByUserId(loginUser.getUserId());
}
List noButtonMenus = allMenus.stream()
@@ -184,8 +184,8 @@ public class MenuApplicationService {
}
- public List getRouterTree(Long userId) {
- List> trees = buildMenuEntityTree(userId);
+ public List getRouterTree(LoginUser loginUser) {
+ List> trees = buildMenuEntityTree(loginUser);
return buildRouterTree(trees);
}
diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/system/user/model/UserModel.java b/agileboot-domain/src/main/java/com/agileboot/domain/system/user/model/UserModel.java
index 7c9a1bb..1323417 100644
--- a/agileboot-domain/src/main/java/com/agileboot/domain/system/user/model/UserModel.java
+++ b/agileboot-domain/src/main/java/com/agileboot/domain/system/user/model/UserModel.java
@@ -114,7 +114,7 @@ public class UserModel extends SysUserEntity {
public void checkCanBeDelete(LoginUser loginUser) {
if (Objects.equals(getUserId(), loginUser.getUserId())
- || LoginUser.isAdmin(getUserId())) {
+ || this.getIsAdmin()) {
throw new ApiException(ErrorCode.Business.USER_CURRENT_USER_CAN_NOT_BE_DELETE);
}
}
@@ -137,7 +137,7 @@ public class UserModel extends SysUserEntity {
@Override
public boolean updateById() {
- if (LoginUser.isAdmin(this.getUserId()) && AgileBootConfig.isDemoEnabled()) {
+ if (this.getIsAdmin() && AgileBootConfig.isDemoEnabled()) {
throw new ApiException(Business.USER_ADMIN_CAN_NOT_BE_MODIFY);
}
diff --git a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/domain/login/LoginUser.java b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/domain/login/LoginUser.java
index 605c1e9..dd9085a 100644
--- a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/domain/login/LoginUser.java
+++ b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/domain/login/LoginUser.java
@@ -34,14 +34,17 @@ public class LoginUser implements UserDetails {
*/
private Long expireTime;
+ private boolean isAdmin;
+
/**
* 登录信息
*/
private LoginInfo loginInfo = new LoginInfo();
- public LoginUser(Long userId) {
+ public LoginUser(Long userId, Boolean isAdmin) {
this.userId = userId;
+ this.isAdmin = isAdmin;
}
public RoleInfo getRoleInfo() {
@@ -118,17 +121,5 @@ public class LoginUser implements UserDetails {
return null;
}
- /**
- * 是否为管理员
- * @return 结果
- */
- public boolean isAdmin() {
- return isAdmin(getUserId());
- }
-
- // TODO 多租户需要做改动
- public static boolean isAdmin(Long userId) {
- return userId != null && 1L == userId;
- }
}
diff --git a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/service/UserDetailsServiceImpl.java b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/service/UserDetailsServiceImpl.java
index 912a675..ceba764 100644
--- a/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/service/UserDetailsServiceImpl.java
+++ b/agileboot-infrastructure/src/main/java/com/agileboot/infrastructure/web/service/UserDetailsServiceImpl.java
@@ -11,15 +11,12 @@ import com.agileboot.orm.common.enums.UserStatusEnum;
import com.agileboot.orm.common.util.BasicEnumUtil;
import com.agileboot.orm.system.entity.SysMenuEntity;
import com.agileboot.orm.system.entity.SysRoleEntity;
-import com.agileboot.orm.system.entity.SysRoleMenuEntity;
import com.agileboot.orm.system.entity.SysUserEntity;
import com.agileboot.orm.system.service.ISysMenuService;
-import com.agileboot.orm.system.service.ISysRoleMenuService;
import com.agileboot.orm.system.service.ISysRoleService;
import com.agileboot.orm.system.service.ISysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -48,9 +45,6 @@ public class UserDetailsServiceImpl implements UserDetailsService {
@NonNull
private ISysUserService userService;
- @NonNull
- private ISysRoleMenuService roleMenuService;
-
@NonNull
private ISysMenuService menuService;
@@ -70,7 +64,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
throw new ApiException(ErrorCode.Business.USER_IS_DISABLE, username);
}
- return new LoginUser(userEntity.getUserId());
+ return new LoginUser(userEntity.getUserId(), userEntity.getIsAdmin());
}
public RoleInfo getRoleInfo(Long roleId) {
@@ -113,60 +107,5 @@ public class UserDetailsServiceImpl implements UserDetailsService {
}
- /**
- * 获取角色数据权限
- * @param userId 用户信息
- * @return 角色权限信息
- */
- public String getRoleKey(Long userId) {
- // 管理员拥有所有权限
- if (LoginUser.isAdmin(userId)) {
- return "admin";
- }
-
- SysRoleEntity roleEntity = userService.getRoleOfUser(userId);
- return roleEntity == null ? "" : roleEntity.getRoleKey();
- }
-
- /**
- * 获取菜单数据权限
- *
- * @param userId 用户信息
- * @return 菜单权限信息
- */
- public Set getMenuPermissions(Long userId) {
- Set perms = new HashSet<>();
- // 管理员拥有所有权限
- if (LoginUser.isAdmin(userId)) {
- perms.add("*:*:*");
- } else {
- perms.addAll(userService.getMenuPermissionsForUser(userId));
- }
- return perms;
- }
-
- /**
- * 获取菜单数据权限
- *
- * @param userId 用户信息
- * @return 菜单权限信息
- */
- public Set getMenuIds(Long userId, Long roleId) {
- // 管理员拥有所有菜单
- if (LoginUser.isAdmin(userId)) {
- LambdaQueryWrapper menuQuery = Wrappers.lambdaQuery();
- menuQuery.select(SysMenuEntity::getMenuId);
- List menuList = menuService.list(menuQuery);
-
- return menuList.stream().map(SysMenuEntity::getMenuId).collect(Collectors.toSet());
- } else {
- LambdaQueryWrapper menuQuery = Wrappers.lambdaQuery();
- menuQuery.select(SysRoleMenuEntity::getMenuId).eq(SysRoleMenuEntity::getRoleId, roleId);
- List menuList = roleMenuService.list(menuQuery);
-
- return menuList.stream().map(SysRoleMenuEntity::getMenuId).collect(Collectors.toSet());
- }
- }
-
}
diff --git a/agileboot-infrastructure/src/main/resources/h2sql/agileboot_data.sql b/agileboot-infrastructure/src/main/resources/h2sql/agileboot_data.sql
index 75f6669..78e07bb 100644
--- a/agileboot-infrastructure/src/main/resources/h2sql/agileboot_data.sql
+++ b/agileboot-infrastructure/src/main/resources/h2sql/agileboot_data.sql
@@ -217,6 +217,6 @@ INSERT INTO `sys_role_menu` VALUES ('3', '1');
-- ----------------------------
-- Records of sys_user
-- ----------------------------
-INSERT INTO `sys_user` VALUES ('1', '1', '1', '4', 'admin', 'valarchie1', '0', 'agileboot@163.com', '15888888889', '0', '', '$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy', '1', '127.0.0.1', '2022-10-06 17:00:06', null, '2022-05-21 08:30:54', '1', '2022-10-06 17:00:06', '管理员', '0');
-INSERT INTO `sys_user` VALUES ('2', '2', '2', '5', 'ag1', 'valarchie2', '0', 'agileboot1@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', null, '2022-05-21 08:30:54', null, null, '测试员1', '0');
-INSERT INTO `sys_user` VALUES ('3', '2', '0', '5', 'ag2', 'valarchie3', '0', 'agileboot2@qq.com', '15666666667', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', null, '2022-05-21 08:30:54', null, null, '测试员2', '0');
+INSERT INTO `sys_user` VALUES ('1', '1', '1', '4', 'admin', 'valarchie1', '0', 'agileboot@163.com', '15888888889', '0', '', '$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy', '1', '127.0.0.1', '2022-10-06 17:00:06', 1, null, '2022-05-21 08:30:54', '1', '2022-10-06 17:00:06', '管理员', '0');
+INSERT INTO `sys_user` VALUES ('2', '2', '2', '5', 'ag1', 'valarchie2', '0', 'agileboot1@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员1', '0');
+INSERT INTO `sys_user` VALUES ('3', '2', '0', '5', 'ag2', 'valarchie3', '0', 'agileboot2@qq.com', '15666666667', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员2', '0');
diff --git a/agileboot-infrastructure/src/main/resources/h2sql/agileboot_schema.sql b/agileboot-infrastructure/src/main/resources/h2sql/agileboot_schema.sql
index 1758490..e08750d 100644
--- a/agileboot-infrastructure/src/main/resources/h2sql/agileboot_schema.sql
+++ b/agileboot-infrastructure/src/main/resources/h2sql/agileboot_schema.sql
@@ -175,6 +175,7 @@ create table sys_user
status smallint default 0 not null comment '帐号状态(1正常 2停用 3冻结)',
login_ip varchar(128) default '' null comment '最后登录IP',
login_date datetime null comment '最后登录时间',
+ is_admin tinyint default 0 not null comment '超级管理员标志(1是,0否)',
creator_id bigint null comment '更新者ID',
create_time datetime null comment '创建时间',
updater_id bigint null comment '更新者ID',
diff --git a/agileboot-orm/src/main/java/com/agileboot/orm/system/entity/SysUserEntity.java b/agileboot-orm/src/main/java/com/agileboot/orm/system/entity/SysUserEntity.java
index 1418859..76a58d3 100644
--- a/agileboot-orm/src/main/java/com/agileboot/orm/system/entity/SysUserEntity.java
+++ b/agileboot-orm/src/main/java/com/agileboot/orm/system/entity/SysUserEntity.java
@@ -18,7 +18,7 @@ import lombok.Setter;
*
*
* @author valarchie
- * @since 2022-10-02
+ * @since 2023-02-27
*/
@Getter
@Setter
@@ -88,6 +88,10 @@ public class SysUserEntity extends BaseEntity {
@TableField("login_date")
private Date loginDate;
+ @ApiModelProperty("超级管理员标志(1是,0否)")
+ @TableField("is_admin")
+ private Boolean isAdmin;
+
@ApiModelProperty("备注")
@TableField("remark")
private String remark;
diff --git a/sql/agileboot_20221007.sql b/sql/agileboot_20221007.sql
index 54a7e5a..853efb2 100644
--- a/sql/agileboot_20221007.sql
+++ b/sql/agileboot_20221007.sql
@@ -410,6 +410,7 @@ CREATE TABLE `sys_user` (
`status` smallint NOT NULL DEFAULT '0' COMMENT '帐号状态(1正常 2停用 3冻结)',
`login_ip` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '最后登录IP',
`login_date` datetime DEFAULT NULL COMMENT '最后登录时间',
+ `is_admin` tinyint(1) NOT NULL DEFAULT '0' COMMENT '超级管理员标志(1是,0否)',
`creator_id` bigint DEFAULT NULL COMMENT '更新者ID',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`updater_id` bigint DEFAULT NULL COMMENT '更新者ID',
@@ -422,6 +423,6 @@ CREATE TABLE `sys_user` (
-- ----------------------------
-- Records of sys_user
-- ----------------------------
-INSERT INTO `sys_user` VALUES ('1', '1', '1', '4', 'admin', 'valarchie1', '0', 'agileboot@163.com', '15888888889', '0', '', '$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy', '1', '127.0.0.1', '2022-10-06 17:00:06', null, '2022-05-21 08:30:54', '1', '2022-10-06 17:00:06', '管理员', '0');
-INSERT INTO `sys_user` VALUES ('2', '2', '2', '5', 'ag1', 'valarchie2', '0', 'agileboot1@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', null, '2022-05-21 08:30:54', null, null, '测试员1', '0');
-INSERT INTO `sys_user` VALUES ('3', '2', '0', '5', 'ag2', 'valarchie3', '0', 'agileboot2@qq.com', '15666666667', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', null, '2022-05-21 08:30:54', null, null, '测试员2', '0');
+INSERT INTO `sys_user` VALUES ('1', '1', '1', '4', 'admin', 'valarchie1', '0', 'agileboot@163.com', '15888888889', '0', '', '$2a$10$rb1wRoEIkLbIknREEN1LH.FGs4g0oOS5t6l5LQ793nRaFO.SPHDHy', '1', '127.0.0.1', '2022-10-06 17:00:06', 1, null, '2022-05-21 08:30:54', '1', '2022-10-06 17:00:06', '管理员', '0');
+INSERT INTO `sys_user` VALUES ('2', '2', '2', '5', 'ag1', 'valarchie2', '0', 'agileboot1@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员1', '0');
+INSERT INTO `sys_user` VALUES ('3', '2', '0', '5', 'ag2', 'valarchie3', '0', 'agileboot2@qq.com', '15666666667', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '1', '127.0.0.1', '2022-05-21 08:30:54', 0, null, '2022-05-21 08:30:54', null, null, '测试员2', '0');