【7.6.0】【sys】新增用户添加一个默认角色

pull/57/head
fengshuonan 2023-06-25 00:39:40 +08:00
parent 9cc38738ec
commit ec1f1764d8
7 changed files with 96 additions and 4 deletions

View File

@ -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.
*
* GunsAPACHE 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 {
/**
* idemployeeid
* <p>
*
*
* @author fengshuonan
* @since 2023/6/25 0:35
*/
Long getDefaultRoleId();
}

View File

@ -52,6 +52,11 @@ public interface SysConstants {
*/
String SUPER_ADMIN_ROLE_CODE = "superAdmin";
/**
*
*/
String DEFAULT_ROLE_CODE = "employee";
/**
*
*/

View File

@ -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);
}

View File

@ -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);

View File

@ -70,8 +70,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 更新用户的任职信息
sysUserOrgService.updateUserOrg(sysUser.getUserId(), sysUserRequest.getUserOrgList());
// 添加用户一个默认角色 todo
// 添加用户一个默认角色
sysUserRoleService.bindUserDefaultRole(sysUser.getUserId());
}
@Override

View File

@ -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 {
/**
*

View File

@ -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);
}
}