mirror of https://gitee.com/stylefeng/roses
【7.6.0】【sys】新增用户添加一个默认角色
parent
9cc38738ec
commit
ec1f1764d8
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.api;
|
||||
|
||||
/**
|
||||
* 角色信息相关的Api
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/25 0:35
|
||||
*/
|
||||
public interface SysRoleServiceApi {
|
||||
|
||||
/**
|
||||
* 获取系统默认角色id,查询方式为找到角色编码为employee的角色id
|
||||
* <p>
|
||||
* 一般在添加用户时用到
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/25 0:35
|
||||
*/
|
||||
Long getDefaultRoleId();
|
||||
|
||||
}
|
|
@ -52,6 +52,11 @@ public interface SysConstants {
|
|||
*/
|
||||
String SUPER_ADMIN_ROLE_CODE = "superAdmin";
|
||||
|
||||
/**
|
||||
* 默认用户的初始角色编码
|
||||
*/
|
||||
String DEFAULT_ROLE_CODE = "employee";
|
||||
|
||||
/**
|
||||
* 初始化超级管理员的监听器顺序
|
||||
*/
|
||||
|
|
|
@ -80,4 +80,12 @@ public interface SysUserRoleService extends IService<SysUserRole>, SysUserRoleSe
|
|||
*/
|
||||
void bindRoles(SysUserRoleRequest sysUserRoleRequest);
|
||||
|
||||
/**
|
||||
* 给用户添加默认的角色
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/25 0:34
|
||||
*/
|
||||
void bindUserDefaultRole(Long userId);
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
|||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveUserCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserRole;
|
||||
|
@ -19,6 +20,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
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.Set;
|
||||
|
@ -34,6 +36,9 @@ import java.util.stream.Collectors;
|
|||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService,
|
||||
RemoveUserCallbackApi, RemoveRoleCallbackApi {
|
||||
|
||||
@Resource
|
||||
private SysRoleServiceApi sysRoleServiceApi;
|
||||
|
||||
@Override
|
||||
public void add(SysUserRoleRequest sysUserRoleRequest) {
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
|
@ -86,6 +91,19 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
this.saveBatch(newUserRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindUserDefaultRole(Long userId) {
|
||||
|
||||
// 查询默认角色的角色id
|
||||
Long defaultRoleId = sysRoleServiceApi.getDefaultRoleId();
|
||||
|
||||
// 给用户绑定默认角色
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
sysUserRole.setUserId(userId);
|
||||
sysUserRole.setRoleId(defaultRoleId);
|
||||
this.save(sysUserRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserRole> findList(SysUserRoleRequest sysUserRoleRequest) {
|
||||
LambdaQueryWrapper<SysUserRole> wrapper = this.createWrapper(sysUserRoleRequest);
|
||||
|
|
|
@ -70,8 +70,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
// 更新用户的任职信息
|
||||
sysUserOrgService.updateUserOrg(sysUser.getUserId(), sysUserRequest.getUserOrgList());
|
||||
|
||||
// 添加用户一个默认角色 todo
|
||||
|
||||
// 添加用户一个默认角色
|
||||
sysUserRoleService.bindUserDefaultRole(sysUser.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.role.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
@ -13,7 +14,7 @@ import java.util.List;
|
|||
* @author fengshuonan
|
||||
* @date 2023/06/10 21:29
|
||||
*/
|
||||
public interface SysRoleService extends IService<SysRole> {
|
||||
public interface SysRoleService extends IService<SysRole>, SysRoleServiceApi {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
|
|
|
@ -12,6 +12,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.enums.exception.SysRoleExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.mapper.SysRoleMapper;
|
||||
|
@ -117,6 +118,21 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDefaultRoleId() {
|
||||
|
||||
LambdaQueryWrapper<SysRole> sysRoleLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleLambdaQueryWrapper.eq(SysRole::getRoleCode, SysConstants.DEFAULT_ROLE_CODE);
|
||||
sysRoleLambdaQueryWrapper.select(SysRole::getRoleId);
|
||||
SysRole sysRole = this.getOne(sysRoleLambdaQueryWrapper, false);
|
||||
|
||||
if (sysRole != null) {
|
||||
return sysRole.getRoleId();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
|
@ -174,5 +190,4 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
// 删除角色
|
||||
this.removeBatchByIds(roleIdList);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue