mirror of https://gitee.com/stylefeng/roses
【8.1.0】【user-org】更新同步绑定角色业务
parent
ef8be70758
commit
3dd43b8d23
|
@ -33,6 +33,16 @@ public interface SysUserOrgServiceApi {
|
|||
*/
|
||||
List<UserOrgDTO> getUserOrgList(Long userId, boolean getTotalOrg);
|
||||
|
||||
/**
|
||||
* 获取用户所有的所属组织机构的id信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param getTotalOrg 是否获取用户所属的所有组织机构,true-获取所有,false-只获取启用的部门
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 17:48
|
||||
*/
|
||||
List<Long> getUserOrgIdList(Long userId, boolean getTotalOrg);
|
||||
|
||||
/**
|
||||
* 获取某个机构下的所有用户id集合
|
||||
*
|
||||
|
@ -79,4 +89,15 @@ public interface SysUserOrgServiceApi {
|
|||
*/
|
||||
Set<Long> getOrgUserIdList(Set<Long> orgIdList);
|
||||
|
||||
/**
|
||||
* 更新其他公司的启用禁用状态,排除掉某个公司
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param excludeOrgId 排除的公司id,传空则是更新所有
|
||||
* @param statusFlag 状态标识,1-启用,2-禁用
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 17:20
|
||||
*/
|
||||
void updateOtherOrgStatus(Long userId, Long excludeOrgId, Integer statusFlag);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindItem;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 同步到其他公司的绑定的请求参数
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 17:12
|
||||
*/
|
||||
@Data
|
||||
public class SyncBindRequest {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ChineseDescription("用户id")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户所属机构id
|
||||
*/
|
||||
@ChineseDescription("用户所属机构id")
|
||||
@NotNull(message = "用户所属机构id不能为空")
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 用户所属机构的状态,true-启用
|
||||
*/
|
||||
@ChineseDescription("用户所属机构的状态,true-启用")
|
||||
@NotNull(message = "用户所属机构的状态不能为空")
|
||||
private Boolean statusFlag;
|
||||
|
||||
/**
|
||||
* 角色绑定的详情
|
||||
*/
|
||||
@ChineseDescription("角色绑定的详情")
|
||||
private List<NewUserRoleBindItem> roleBindItemList;
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindRespon
|
|||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.DeleteRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.RoleControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.SyncBindRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserOrgRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysRoleAssignService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
|
||||
|
@ -121,4 +122,16 @@ public class UserRoleAssignPageController {
|
|||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步到其他公司绑定信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 15:47
|
||||
*/
|
||||
@PostResource(name = "同步到其他公司绑定信息", path = "/sysRoleAssign/syncOtherOrgStatusAndBusinessRole")
|
||||
public ResponseData<?> syncOtherOrgStatusAndBusinessRole(@RequestBody @Validated SyncBindRequest syncBindRequest) {
|
||||
sysRoleAssignService.syncOtherOrgStatusAndBusinessRole(syncBindRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindRespon
|
|||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.DeleteRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.RoleControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.SyncBindRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserOrgRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -64,4 +65,12 @@ public interface SysRoleAssignService {
|
|||
*/
|
||||
void disableAllOrgStatus(SysUserOrgRequest sysUserOrgRequest);
|
||||
|
||||
/**
|
||||
* 同步用户的指定机构的绑定状态和基础业务角色,到其他的组织机构中
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 17:16
|
||||
*/
|
||||
void syncOtherOrgStatusAndBusinessRole(SyncBindRequest syncBindRequest);
|
||||
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindItem;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserRoleRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户角色关联 服务类
|
||||
*
|
||||
|
@ -45,4 +48,15 @@ public interface SysUserRoleService extends IService<SysUserRole>, SysUserRoleSe
|
|||
*/
|
||||
void addBusinessAndCompanyBindRole(SysUserRole sysUserRole);
|
||||
|
||||
/**
|
||||
* 更新用户其他公司的基础业务角色
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param excludeOrgId 排除的公司id
|
||||
* @param currentOrgBindRoleList 当前公司绑定的角色列表
|
||||
* @author fengshuonan
|
||||
* @since 2024-01-18 17:41
|
||||
*/
|
||||
void updateOtherOrgBusinessRole(Long userId, Long excludeOrgId, List<NewUserRoleBindItem> currentOrgBindRoleList);
|
||||
|
||||
}
|
|
@ -1,16 +1,20 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.role.RoleTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.SysRoleDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserOrgDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindItem;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindResponse;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.UserRoleDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.DeleteRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.RoleControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.SyncBindRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserOrgExceptionEnum;
|
||||
|
@ -23,6 +27,7 @@ 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.stream.Collectors;
|
||||
|
||||
|
@ -53,6 +58,11 @@ public class SysRoleAssignServiceImpl implements SysRoleAssignService {
|
|||
// 1. 获取用户的所有绑定的组织机构信息
|
||||
List<UserOrgDTO> userOrgList = sysUserOrgService.getUserOrgList(userId, true);
|
||||
|
||||
// 用户没绑定机构,直接返回
|
||||
if (ObjectUtil.isEmpty(userOrgList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 2. 组装NewUserRoleBindResponse
|
||||
List<NewUserRoleBindResponse> baseResponse = RoleAssignFactory.createBaseResponse(userOrgList);
|
||||
|
||||
|
@ -148,4 +158,21 @@ public class SysRoleAssignServiceImpl implements SysRoleAssignService {
|
|||
sysUserOrgService.disableAllOrgStatus(sysUserOrgRequest.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncOtherOrgStatusAndBusinessRole(SyncBindRequest syncBindRequest) {
|
||||
|
||||
// 1. 获取当前指定公司的同步状态
|
||||
Boolean statusFlag = syncBindRequest.getStatusFlag();
|
||||
|
||||
// 2. 更新用户所属其他组织机构的状态
|
||||
sysUserOrgService.updateOtherOrgStatus(syncBindRequest.getUserId(), syncBindRequest.getOrgId(), statusFlag ? StatusEnum.ENABLE.getCode() : StatusEnum.DISABLE.getCode());
|
||||
|
||||
// 3. 筛选出当前公司的业务角色
|
||||
List<NewUserRoleBindItem> currentOrgBindRoleList = syncBindRequest.getRoleBindItemList().stream().filter(i -> i.getRoleType().equals(RoleTypeEnum.BUSINESS_ROLE.getCode()))
|
||||
.filter(NewUserRoleBindItem::getCheckedFlag).collect(Collectors.toList());
|
||||
|
||||
// 4. 更新用户所属其他组织机构的业务角色
|
||||
sysUserRoleService.updateOtherOrgBusinessRole(syncBindRequest.getUserId(), syncBindRequest.getOrgId(), currentOrgBindRoleList);
|
||||
}
|
||||
|
||||
}
|
|
@ -226,6 +226,22 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
|
|||
return userOrgDTOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getUserOrgIdList(Long userId, boolean getTotalOrg) {
|
||||
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
if (!getTotalOrg) {
|
||||
queryWrapper.eq(SysUserOrg::getStatusFlag, StatusEnum.ENABLE.getCode());
|
||||
}
|
||||
queryWrapper.select(SysUserOrg::getOrgId);
|
||||
List<SysUserOrg> sysUserOrgList = this.list(queryWrapper);
|
||||
if (ObjectUtil.isEmpty(sysUserOrgList)) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
return sysUserOrgList.stream().map(SysUserOrg::getOrgId).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag) {
|
||||
|
||||
|
@ -305,6 +321,17 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
|
|||
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOtherOrgStatus(Long userId, Long excludeOrgId, Integer statusFlag) {
|
||||
LambdaUpdateWrapper<SysUserOrg> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
if (ObjectUtil.isNotEmpty(excludeOrgId)) {
|
||||
updateWrapper.ne(SysUserOrg::getOrgId, excludeOrgId);
|
||||
}
|
||||
updateWrapper.set(SysUserOrg::getStatusFlag, statusFlag);
|
||||
this.update(updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
|
|
|
@ -13,11 +13,13 @@ import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
|||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveUserCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.role.RoleTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindItem;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.UserRoleDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.enums.SysUserExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserRoleMapper;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
@ -55,6 +57,9 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
@Resource
|
||||
private SysRoleLimitServiceApi sysRoleLimitServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysUserOrgService sysUserOrgService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void bindRoles(SysUserRoleRequest sysUserRoleRequest) {
|
||||
|
@ -289,6 +294,51 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
this.save(sysUserRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateOtherOrgBusinessRole(Long userId, Long excludeOrgId, List<NewUserRoleBindItem> currentOrgBindRoleList) {
|
||||
|
||||
// 1. 清空用户在其他公司的业务角色
|
||||
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserRole::getUserId, userId);
|
||||
queryWrapper.eq(SysUserRole::getRoleType, RoleTypeEnum.BUSINESS_ROLE.getCode());
|
||||
queryWrapper.ne(SysUserRole::getRoleOrgId, excludeOrgId);
|
||||
this.remove(queryWrapper);
|
||||
|
||||
// 清空角色缓存
|
||||
userRoleCache.remove(userId.toString());
|
||||
|
||||
// 2. 获取用户有几个机构
|
||||
List<Long> userOrgIdList = sysUserOrgService.getUserOrgIdList(userId, true);
|
||||
if (ObjectUtil.isEmpty(userOrgIdList)) {
|
||||
return;
|
||||
}
|
||||
List<Long> excludeAfterOrgIds = userOrgIdList.stream().filter(orgId -> !orgId.equals(excludeOrgId)).collect(Collectors.toList());
|
||||
if (ObjectUtil.isEmpty(excludeAfterOrgIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 给这些机构,绑定上当前公司的业务角色
|
||||
if (ObjectUtil.isEmpty(currentOrgBindRoleList)) {
|
||||
return;
|
||||
}
|
||||
ArrayList<SysUserRole> sysUserRoles = new ArrayList<>();
|
||||
for (Long userOrgId : excludeAfterOrgIds) {
|
||||
for (NewUserRoleBindItem newUserRoleBindItem : currentOrgBindRoleList) {
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
sysUserRole.setUserId(userId);
|
||||
sysUserRole.setRoleId(newUserRoleBindItem.getRoleId());
|
||||
sysUserRole.setRoleType(RoleTypeEnum.BUSINESS_ROLE.getCode());
|
||||
sysUserRole.setRoleOrgId(userOrgId);
|
||||
sysUserRoles.add(sysUserRole);
|
||||
}
|
||||
}
|
||||
this.saveBatch(sysUserRoles);
|
||||
|
||||
// 清空角色缓存
|
||||
userRoleCache.remove(userId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空用户绑定的所有系统角色,这个界面只管分配系统角色
|
||||
*
|
||||
|
|
|
@ -349,6 +349,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
|
||||
@Override
|
||||
public List<SysRoleDTO> getBusinessRoleAndCompanyRole(List<Long> companyIdList) {
|
||||
if (ObjectUtil.isEmpty(companyIdList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
LambdaQueryWrapper<SysRole> sysRoleLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleLambdaQueryWrapper.eq(SysRole::getRoleType, RoleTypeEnum.BUSINESS_ROLE.getCode());
|
||||
sysRoleLambdaQueryWrapper.or().nested(i -> i.eq(SysRole::getRoleType, RoleTypeEnum.COMPANY_ROLE.getCode()).and(j -> j.in(SysRole::getRoleCompanyId, companyIdList)));
|
||||
|
|
Loading…
Reference in New Issue