oms/backend/app/model/principalUser.js
liufumingren 85938c81ec feat: 组织架构、权限管理与员工档案
- 组织架构:主体管理改为组织架构页(左侧 tab:集团设置 / 下属公司),主体列表仅保留顶部下拉切换
  - 新增下属公司表 principal_subsidiaries、接口与页面,按当前主体隔离
  - 集团设置读取/编辑当前主体基础信息,补所属主体校验与更新字段白名单
- 权限管理:新增 permissions / roles / role_permissions 表
  - 权限以现有顶级菜单为分类,每个菜单两种范围:集团全部 / 所在公司
  - 系统预设角色:系统管理员(全部集团权限)、货主权限(全部所在公司权限)
  - 权限管理页只展示角色组,支持按菜单勾选权限;系统预设角色只读
- 员工档案:账号菜单改为员工档案
  - 新增员工-下属公司多对多关联(principal_user_companies)
  - 创建/编辑员工必须选择角色组;除所有者外必须至少关联一家公司
- 菜单重命名与旧地址重定向;账号导出新增角色组、所属公司

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-04 20:52:43 +08:00

34 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 主体用户关联模型,对应 principal_users 表
* @param {Egg.Application} app egg application
* @return {object} principalUser model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const PrincipalUser = app.model.define('principal_user', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '主体ID' },
user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '用户ID' },
name: { type: STRING(50), allowNull: true, comment: '该账号在此主体下的显示名称(推送单据操作人取此值)' },
avatar: { type: STRING(255), allowNull: true, comment: '该账号在此主体下的头像 URL' },
role: { type: STRING(50), comment: '该主体下的角色标识' },
role_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '角色组ID(roles.id)' },
is_default: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否默认主体:1是 0否' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
PrincipalUser.associate = () => {
app.model.PrincipalUser.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
app.model.PrincipalUser.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.PrincipalUser.belongsTo(app.model.Role, { foreignKey: 'role_id', as: 'roleGroup' });
app.model.PrincipalUser.hasMany(app.model.PrincipalUserCompany, { foreignKey: 'principal_user_id', as: 'companies' });
};
return PrincipalUser;
};