mirror of https://gitee.com/stylefeng/roses
【7.6.0】【sys】【permission】增加更新用户激活的组织机构接口
parent
e76085124e
commit
92ace892a4
|
@ -40,4 +40,15 @@ public interface SysUserOrgServiceApi {
|
|||
*/
|
||||
List<Long> getOrgUserIdList(Long orgId, Boolean containSubOrgFlag);
|
||||
|
||||
/**
|
||||
* 判断用户是否有指定组织机构的权限
|
||||
*
|
||||
* @param orgId 组织机构id
|
||||
* @param userId 用户id
|
||||
* @return true-用户有所属该机构的权限,false-用户不属于该机构
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/21 16:11
|
||||
*/
|
||||
boolean validateUserOrgAuth(Long orgId, Long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,12 @@ public enum OrgExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* 删除机构失败,该机构下有绑定员工
|
||||
*/
|
||||
DELETE_ORGANIZATION_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10002", "删除机构失败,该机构下有绑定员工");
|
||||
DELETE_ORGANIZATION_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10002", "删除机构失败,该机构下有绑定员工"),
|
||||
|
||||
/**
|
||||
* 用户没有该组织机构的权限,无法切换组织机构
|
||||
*/
|
||||
UPDATE_LOGIN_USER_ORG_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "用户没有该组织机构的权限,无法切换组织机构");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -195,6 +195,14 @@ public class SysUserOrgServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUser
|
|||
return list.stream().map(SysUserOrg::getUserId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateUserOrgAuth(Long orgId, Long userId) {
|
||||
LambdaQueryWrapper<SysUserOrg> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
queryWrapper.eq(SysUserOrg::getOrgId, orgId);
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
|
|
|
@ -4,9 +4,12 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
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.modular.login.pojo.UpdateUserOrgAppRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.UserIndexInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.service.UserIndexInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -36,4 +39,16 @@ public class UserIndexInfoController {
|
|||
return new SuccessResponseData<>(userIndexInfoService.getUserIndexInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换当前用户激活的组织机构id或当前激活的应用id
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/21 16:03
|
||||
*/
|
||||
@PostResource(name = "切换当前用户激活的组织机构id或当前激活的应用id", path = "/updateUserOrgOrApp")
|
||||
public ResponseData<?> updateUserOrgOrApp(@RequestBody UpdateUserOrgAppRequest updateUserOrgAppRequest) {
|
||||
userIndexInfoService.updateUserOrgOrApp(updateUserOrgAppRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.login.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 切换当前用户激活的组织机构id或者应用id
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/21 16:05
|
||||
*/
|
||||
@Data
|
||||
public class UpdateUserOrgAppRequest {
|
||||
|
||||
/**
|
||||
* 切换后的组织机构id
|
||||
*/
|
||||
@ChineseDescription("切换后的组织机构id")
|
||||
private Long newOrgId;
|
||||
|
||||
/**
|
||||
* 切换后的应用id
|
||||
*/
|
||||
@ChineseDescription("切换后的应用id")
|
||||
private Long newAppId;
|
||||
|
||||
}
|
|
@ -6,18 +6,17 @@ import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
|
|||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.SimpleUserDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserOrgDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.expander.WebSocketConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.IndexUserAppInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.IndexUserMenuInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.IndexUserOrgInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.UserIndexInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.login.pojo.*;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
|
@ -100,6 +99,39 @@ public class UserIndexInfoService {
|
|||
return userIndexInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换当前登录用户的组织机构id或者当前激活的appId
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/21 16:04
|
||||
*/
|
||||
public void updateUserOrgOrApp(UpdateUserOrgAppRequest updateUserOrgAppRequest) {
|
||||
|
||||
// 获取当前登录用户
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
|
||||
if (updateUserOrgAppRequest.getNewOrgId() != null) {
|
||||
|
||||
// 判断当前用户是否有指定的组织机构id
|
||||
boolean result = sysUserOrgServiceApi.validateUserOrgAuth(updateUserOrgAppRequest.getNewOrgId(), loginUser.getUserId());
|
||||
if (!result) {
|
||||
throw new ServiceException(OrgExceptionEnum.UPDATE_LOGIN_USER_ORG_ERROR);
|
||||
}
|
||||
|
||||
loginUser.setCurrentOrgId(updateUserOrgAppRequest.getNewOrgId());
|
||||
}
|
||||
|
||||
if (updateUserOrgAppRequest.getNewAppId() != null) {
|
||||
|
||||
// 判断当前用户是否有该应用id
|
||||
|
||||
|
||||
loginUser.setCurrentAppId(updateUserOrgAppRequest.getNewAppId());
|
||||
}
|
||||
|
||||
sessionManagerApi.updateSession(loginUser.getToken(), loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充用户的基本姓名和头像信息
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue