【8.1.0】【user-org】更新删除用户机构绑定

pull/60/head
fengshuonan 2024-01-18 14:17:11 +08:00
parent 9574e0cc2a
commit 4b79abc297
8 changed files with 76 additions and 8 deletions

View File

@ -70,4 +70,12 @@ public interface SysUserRoleServiceApi {
*/ */
Set<Long> findCurrentUserRoleLimitScope(); Set<Long> findCurrentUserRoleLimitScope();
/**
*
*
* @author fengshuonan
* @since 2024-01-18 14:06
*/
void removeUserOrgRoleLink(Long userId, Long orgId);
} }

View File

@ -13,10 +13,16 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class DeleteRequest { public class DeleteRequest {
/**
* id
*/
@NotNull(message = "所操作的机构id不能为空请检查orgId参数")
private Long userId;
/** /**
* id * id
*/ */
@NotNull(message = "所操作的机构id不能为空请检查orgId参数") @NotNull(message = "所操作的机构id不能为空请检查orgId参数")
private Long orgId; private Long orgId;
} }

View File

@ -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.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; 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.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.RoleControlRequest;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest; import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysRoleAssignService; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysRoleAssignService;
@ -66,5 +67,16 @@ public class UserRoleAssignPageController {
return new SuccessResponseData<>(); 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<>();
}
} }

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.user.service; 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.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.RoleControlRequest;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest; import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
@ -38,4 +39,12 @@ public interface SysRoleAssignService {
*/ */
void changeRoleSelect(RoleControlRequest roleControlRequest); void changeRoleSelect(RoleControlRequest roleControlRequest);
/**
*
*
* @author fengshuonan
* @since 2024-01-18 13:39
*/
void removeUserOrgBind(DeleteRequest deleteRequest);
} }

View File

@ -90,4 +90,12 @@ public interface SysUserOrgService extends IService<SysUserOrg>, SysUserOrgServi
*/ */
SysUserOrg getUserOrgInfo(Long userId, Long orgId); SysUserOrg getUserOrgInfo(Long userId, Long orgId);
/**
*
*
* @author fengshuonan
* @since 2024-01-18 13:42
*/
void removeUserOrgLink(Long userId, Long orgId);
} }

View File

@ -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.UserOrgDTO;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.NewUserRoleBindResponse; 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.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.RoleControlRequest;
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest; import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.request.StatusControlRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.entity.SysUserOrg; 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.SysUserOrgService;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; 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());
}
} }

View File

@ -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.pojo.request.SysUserOrgRequest;
import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService; import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserOrgService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -105,6 +106,14 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
return this.getOne(wrapper, false); return this.getOne(wrapper, false);
} }
@Override
public void removeUserOrgLink(Long userId, Long orgId) {
LambdaUpdateWrapper<SysUserOrg> sysUserOrgLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
sysUserOrgLambdaUpdateWrapper.eq(SysUserOrg::getUserId, userId);
sysUserOrgLambdaUpdateWrapper.eq(SysUserOrg::getOrgId, orgId);
this.remove(sysUserOrgLambdaUpdateWrapper);
}
@Override @Override
public List<SysUserOrg> findList(SysUserOrgRequest sysUserOrgRequest) { public List<SysUserOrg> findList(SysUserOrgRequest sysUserOrgRequest) {
LambdaQueryWrapper<SysUserOrg> wrapper = this.createWrapper(sysUserOrgRequest); LambdaQueryWrapper<SysUserOrg> wrapper = this.createWrapper(sysUserOrgRequest);

View File

@ -242,6 +242,14 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
return this.findUserRoleLimitScope(userId); return this.findUserRoleLimitScope(userId);
} }
@Override
public void removeUserOrgRoleLink(Long userId, Long orgId) {
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserRole::getUserId, userId);
queryWrapper.eq(SysUserRole::getRoleOrgId, orgId);
this.remove(queryWrapper);
}
@Override @Override
public SysUserRole getPointUserRole(Long userId, Long roleId, Long orgId) { public SysUserRole getPointUserRole(Long userId, Long roleId, Long orgId) {
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>();
@ -310,9 +318,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
private List<Long> getUserCompanyPermissionRole(List<SysUserRole> paramRoles, Long userCurrentOrgId) { private List<Long> getUserCompanyPermissionRole(List<SysUserRole> paramRoles, Long userCurrentOrgId) {
// 1. 先获取最基本的用户角色,不分公司的,每个人都有的角色 // 1. 先获取最基本的用户角色,不分公司的,每个人都有的角色
Set<Long> baseRoleIdList = paramRoles.stream() Set<Long> baseRoleIdList = paramRoles.stream().filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() == null).map(SysUserRole::getRoleId)
.filter(i -> RoleTypeEnum.SYSTEM_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() == null)
.map(SysUserRole::getRoleId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// 没传当前公司id则只返回最基本的角色 // 没传当前公司id则只返回最基本的角色
@ -322,10 +328,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
// 2. 获取用户当前登录公司下的角色id集合 // 2. 获取用户当前登录公司下的角色id集合
Set<Long> currentCompanyRoleIdList = paramRoles.stream() Set<Long> currentCompanyRoleIdList = paramRoles.stream()
.filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType()) .filter(i -> RoleTypeEnum.COMPANY_ROLE.getCode().equals(i.getRoleType()) && i.getRoleOrgId() != null && i.getRoleOrgId().equals(userCurrentOrgId)).map(SysUserRole::getRoleId)
&& i.getRoleOrgId() != null
&& i.getRoleOrgId().equals(userCurrentOrgId))
.map(SysUserRole::getRoleId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// 3. 合并两个集合并返回 // 3. 合并两个集合并返回