diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserRoleServiceApi.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserRoleServiceApi.java index 9ab66bb21..a7d53faab 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserRoleServiceApi.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysUserRoleServiceApi.java @@ -70,4 +70,12 @@ public interface SysUserRoleServiceApi { */ Set findCurrentUserRoleLimitScope(); + /** + * 清楚用户在本组织机构下的角色绑定 + * + * @author fengshuonan + * @since 2024-01-18 14:06 + */ + void removeUserOrgRoleLink(Long userId, Long orgId); + } diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/user/newrole/request/DeleteRequest.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/user/newrole/request/DeleteRequest.java index 1b7492ba9..6273331ef 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/user/newrole/request/DeleteRequest.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/pojo/user/newrole/request/DeleteRequest.java @@ -13,10 +13,16 @@ import javax.validation.constraints.NotNull; @Data public class DeleteRequest { + /** + * 用户id + */ + @NotNull(message = "所操作的机构id不能为空,请检查orgId参数") + private Long userId; + /** * 所操作的机构id */ @NotNull(message = "所操作的机构id不能为空,请检查orgId参数") private Long orgId; -} +} \ No newline at end of file diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/controller/UserRoleAssignPageController.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/controller/UserRoleAssignPageController.java index ab79af67e..61088e39a 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/controller/UserRoleAssignPageController.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/controller/UserRoleAssignPageController.java @@ -6,6 +6,7 @@ import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindResponse; +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.modular.user.service.SysRoleAssignService; @@ -66,5 +67,16 @@ public class UserRoleAssignPageController { return new SuccessResponseData<>(); } + /** + * 删除用户机构的绑定 + * + * @author fengshuonan + * @since 2024-01-18 13:38 + */ + @PostResource(name = "删除用户机构的绑定", path = "/sysRoleAssign/removeUserOrgBind") + public ResponseData removeUserOrgBind(@RequestBody @Validated DeleteRequest deleteRequest) { + sysRoleAssignService.removeUserOrgBind(deleteRequest); + return new SuccessResponseData<>(); + } } diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysRoleAssignService.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysRoleAssignService.java index 9f0704fa0..a9762810d 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysRoleAssignService.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysRoleAssignService.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.sys.modular.user.service; import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindResponse; +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; @@ -38,4 +39,12 @@ public interface SysRoleAssignService { */ void changeRoleSelect(RoleControlRequest roleControlRequest); + /** + * 删除机构的绑定 + * + * @author fengshuonan + * @since 2024-01-18 13:39 + */ + void removeUserOrgBind(DeleteRequest deleteRequest); + } \ No newline at end of file diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysUserOrgService.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysUserOrgService.java index 7f4131ab3..8cc41cd24 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysUserOrgService.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/SysUserOrgService.java @@ -90,4 +90,12 @@ public interface SysUserOrgService extends IService, SysUserOrgServi */ SysUserOrg getUserOrgInfo(Long userId, Long orgId); + /** + * 删除用户机构的关联 + * + * @author fengshuonan + * @since 2024-01-18 13:42 + */ + void removeUserOrgLink(Long userId, Long orgId); + } \ No newline at end of file diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysRoleAssignServiceImpl.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysRoleAssignServiceImpl.java index 443a62fc9..0f5568a2a 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysRoleAssignServiceImpl.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysRoleAssignServiceImpl.java @@ -7,6 +7,7 @@ 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.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.modular.user.entity.SysUserOrg; @@ -17,6 +18,7 @@ import cn.stylefeng.roses.kernel.sys.modular.user.service.SysRoleAssignService; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -108,4 +110,15 @@ public class SysRoleAssignServiceImpl implements SysRoleAssignService { } } + @Override + @Transactional(rollbackFor = Exception.class) + public void removeUserOrgBind(DeleteRequest deleteRequest) { + + // 1. 删除用户机构关联信息 + this.sysUserOrgService.removeUserOrgLink(deleteRequest.getUserId(), deleteRequest.getOrgId()); + + // 2. 删除用户在机构下的所有角色信息 + this.sysUserRoleService.removeUserOrgRoleLink(deleteRequest.getUserId(), deleteRequest.getOrgId()); + } + } \ No newline at end of file diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserOrgServiceImpl.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserOrgServiceImpl.java index 662bb744f..af383ca0a 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserOrgServiceImpl.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserOrgServiceImpl.java @@ -21,6 +21,7 @@ import cn.stylefeng.roses.kernel.sys.modular.user.mapper.SysUserOrgMapper; import cn.stylefeng.roses.kernel.sys.modular.user.pojo.request.SysUserOrgRequest; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -105,6 +106,14 @@ public class SysUserOrgServiceImpl extends ServiceImpl sysUserOrgLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); + sysUserOrgLambdaUpdateWrapper.eq(SysUserOrg::getUserId, userId); + sysUserOrgLambdaUpdateWrapper.eq(SysUserOrg::getOrgId, orgId); + this.remove(sysUserOrgLambdaUpdateWrapper); + } + @Override public List findList(SysUserOrgRequest sysUserOrgRequest) { LambdaQueryWrapper wrapper = this.createWrapper(sysUserOrgRequest); diff --git a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserRoleServiceImpl.java b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserRoleServiceImpl.java index 10e4b5137..97bd12bb0 100644 --- a/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserRoleServiceImpl.java +++ b/kernel-s-system/system-business-hr/src/main/java/cn/stylefeng/roses/kernel/sys/modular/user/service/impl/SysUserRoleServiceImpl.java @@ -242,6 +242,14 @@ public class SysUserRoleServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysUserRole::getUserId, userId); + queryWrapper.eq(SysUserRole::getRoleOrgId, orgId); + this.remove(queryWrapper); + } + @Override public SysUserRole getPointUserRole(Long userId, Long roleId, Long orgId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -310,9 +318,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl getUserCompanyPermissionRole(List paramRoles, Long userCurrentOrgId) { // 1. 先获取最基本的用户角色,不分公司的,每个人都有的角色 - Set baseRoleIdList = paramRoles.stream() - .filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() == null) - .map(SysUserRole::getRoleId) + Set baseRoleIdList = paramRoles.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() == null).map(SysUserRole::getRoleId) .collect(Collectors.toSet()); // 没传当前公司id,则只返回最基本的角色 @@ -322,10 +328,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl currentCompanyRoleIdList = paramRoles.stream() - .filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType()) - && i.getRoleOrgId() != null - && i.getRoleOrgId().equals(userCurrentOrgId)) - .map(SysUserRole::getRoleId) + .filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() != null && i.getRoleOrgId().equals(userCurrentOrgId)).map(SysUserRole::getRoleId) .collect(Collectors.toSet()); // 3. 合并两个集合并返回