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:
小蟑螂
2026-03-29 01:30:00 +08:00
parent 749779d452
commit 3b5e2abd43
47 changed files with 2531 additions and 561 deletions
+40
View File
@@ -0,0 +1,40 @@
-- 用户表新增最后登录公司字段
ALTER TABLE sys_user ADD COLUMN last_company_id BIGINT UNSIGNED NULL COMMENT '最后登录公司ID' AFTER last_login_date;
ALTER TABLE sys_user ADD CONSTRAINT fk_user_last_company FOREIGN KEY (last_company_id) REFERENCES org_company(id) ON DELETE SET NULL;
-- 公司成员表
CREATE TABLE IF NOT EXISTS org_company_member (
id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
company_id BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
role ENUM('owner', 'member') NOT NULL DEFAULT 'member' COMMENT '角色: owner=公司拥有者, member=成员',
position_id BIGINT UNSIGNED COMMENT '职位ID(可空)',
status TINYINT NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=正常',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
create_by BIGINT UNSIGNED,
update_by BIGINT UNSIGNED,
UNIQUE KEY uk_user_company (user_id, company_id),
INDEX idx_company (company_id),
INDEX idx_position (position_id),
CONSTRAINT fk_cm_user FOREIGN KEY (user_id) REFERENCES sys_user(id) ON DELETE CASCADE,
CONSTRAINT fk_cm_company FOREIGN KEY (company_id) REFERENCES org_company(id) ON DELETE CASCADE,
CONSTRAINT fk_cm_position FOREIGN KEY (position_id) REFERENCES org_position(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公司成员表';
-- 部门成员表
CREATE TABLE IF NOT EXISTS org_department_member (
id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
department_id BIGINT UNSIGNED NOT NULL COMMENT '部门ID',
status TINYINT NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=正常',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
create_by BIGINT UNSIGNED,
update_by BIGINT UNSIGNED,
UNIQUE KEY uk_user_department (user_id, department_id),
INDEX idx_department (department_id),
INDEX idx_user (user_id),
CONSTRAINT fk_dm_user FOREIGN KEY (user_id) REFERENCES sys_user(id) ON DELETE CASCADE,
CONSTRAINT fk_dm_department FOREIGN KEY (department_id) REFERENCES org_department(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门成员表';