mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 00:39:20 +08:00
feat: 组织架构重构 - 公司成员与部门成员模块,登录逻辑及权限改造
- 新增 org_company_member 表及模块(公司成员:owner/member 角色) - 新增 org_department_member 表及模块(部门成员:一用户可属多部门) - 移除 sys_user 的 companyId/departmentId/positionId 字段 - 重构 UserMenuServiceImpl 权限逻辑:super→全系统 / owner→公司菜单 / member→职位菜单 - 修复 RoleAspect 中 role='company' 应为 'admin' 的 BUG - CurrentUserContext 注入 CompanyMemberService,新增 getCurrentMemberRole() - 登录时公司选择逻辑:优先 lastCompanyId,需状态可用且未过期 - 超管(super)登录跳过公司校验 - 创建公司时自动创建拥有者账号并写入 org_company_member(role=owner) - 联系人字段替换为拥有者姓名+拥有者电话 - org_company 表新增 owner_name/owner_phone 字段 - sys_user.phone 唯一约束修正 - 同步更新 SQL 设计文件(31张表 DDL)
This commit is contained in:
+34
-1
@@ -1,9 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.utils;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
|
||||
/**
|
||||
* 当前用户上下文工具类
|
||||
@@ -13,9 +16,11 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
public class CurrentUserContext {
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
|
||||
public CurrentUserContext(JwtUtils jwtUtils) {
|
||||
public CurrentUserContext(JwtUtils jwtUtils, @Lazy CompanyMemberService companyMemberService) {
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.companyMemberService = companyMemberService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +45,7 @@ public class CurrentUserContext {
|
||||
|
||||
/**
|
||||
* 获取当前用户公司ID
|
||||
* 改为从 org_company_member 表查(用当前 userId + 当前 token 中的 companyId)
|
||||
*
|
||||
* @return 公司ID
|
||||
* @throws BusinessException 如果无法获取公司信息
|
||||
@@ -103,4 +109,31 @@ public class CurrentUserContext {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return authentication != null && authentication.isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户在公司中的成员信息
|
||||
*
|
||||
* @return CompanyMemberPO
|
||||
* @throws BusinessException 如果无法获取成员信息
|
||||
*/
|
||||
public CompanyMemberPO getCurrentMember() {
|
||||
Long userId = getCurrentUserId();
|
||||
Long companyId = getCurrentCompanyId();
|
||||
CompanyMemberPO member = companyMemberService.getByUserIdAndCompanyId(userId, companyId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("用户不属于当前公司");
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户在公司中的成员角色
|
||||
*
|
||||
* @return "owner" 或 "member"
|
||||
* @throws BusinessException 如果无法获取成员信息
|
||||
*/
|
||||
public String getCurrentMemberRole() {
|
||||
CompanyMemberPO member = getCurrentMember();
|
||||
return member.getRole().getCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user