企业组织管理系统
模块概述
版本: v1.0.0 状态: ✅ 已实现 IPC处理器: 10个 最后更新: 2026-03-05
企业级组织架构管理系统,支持多层级部门树结构、审批工作流引擎和团队成员管理。提供部门 CRUD、人员调动、三种审批模式和超时处理。
核心特性
- 树形组织架构: 多层级部门结构,支持循环引用检测
- 审批工作流: 三种模式 (顺序/并行/任一) + 超时处理
- 团队管理: 部门成员 CRUD + 角色分配
- 审批请求: 完整的发起/批准/拒绝/升级流程
- 企业组织层级: 组织→部门→团队→成员
1. 架构设计
1.1 整体架构图
┌──────────────────────────────────────────────────────────────────┐
│ 前端 (Vue3) │
├──────────────────────────────────────────────────────────────────┤
│ Pinia Store: enterprise-org.ts (478行) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ 组织树 │ │ 部门管理 │ │ 审批流程 │ │ 团队管理 │ │
│ └──────────┘ └──────────┘ └──────────┘ └───────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
↕ IPC (10个通道)
┌──────────────────────────────────────────────────────────────────┐
│ 主进程 (Electron) │
├──────────────────────────────────────────────────────────────────┤
│ enterprise-ipc.js (235行) │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ EnterpriseOrgManager (718行, extends EventEmitter) │ │
│ │ ┌──────────────────┐ ┌──────────────────┐ │ │
│ │ │ 部门树管理 │ │ 循环引用检测 │ │ │
│ │ │ _buildTree() │ │ move validation │ │ │
│ │ └──────────────────┘ └──────────────────┘ │ │
│ └────────────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ ApprovalWorkflowManager (595行) │ │
│ │ ┌────────────┐ ┌────────────┐ ┌────────────────────┐ │ │
│ │ │ sequential │ │ parallel │ │ any_one │ │ │
│ │ │ 顺序审批 │ │ 并行审批 │ │ 任一通过 │ │ │
│ │ └────────────┘ └────────────┘ └────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ TeamManager (301行) │ SQLite Database │ │
│ │ 部门成员 CRUD + 角色分配 │ 5 tables │ │
│ └────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘1.2 审批流程
创建工作流 (定义审批步骤和类型)
↓
发起审批请求
↓
┌─────────────────────────────────────┐
│ sequential: 逐步审批 │
│ 审批人1 → 审批人2 → ... → 审批人N │
│ 任一拒绝 = 请求拒绝 │
│ │
│ parallel: 并行审批 │
│ 所有审批人同时收到请求 │
│ 全部通过 = 请求通过 │
│ │
│ any_one: 任一通过 │
│ 任何一个审批人通过 = 请求通过 │
└─────────────────────────────────────┘
↓
超时处理 (approve/reject/escalate)
↓
完成 → 通知发起人1.3 核心组件
| 组件 | 文件 | 行数 | 说明 |
|---|---|---|---|
| EnterpriseOrgManager | enterprise-org-manager.js | 718 | 组织架构管理 |
| ApprovalWorkflowManager | approval-workflow-manager.js | 595 | 审批工作流引擎 |
| TeamManager | team-manager.js | 301 | 团队成员管理 |
| Enterprise IPC | enterprise-ipc.js | 235 | 10个IPC处理器 |
| Pinia Store | enterprise-org.ts | 478 | 前端状态管理 |
2. 核心模块
2.1 EnterpriseOrgManager
javascript
class EnterpriseOrgManager extends EventEmitter {
async initialize(database)
// 部门管理
async createDepartment(orgId, name, parentId?, metadata?)
async updateDepartment(deptId, updates)
async deleteDepartment(deptId)
async getDepartment(deptId)
async getDepartmentTree(orgId)
async moveDepartment(deptId, newParentId)
// 查询
async searchDepartments(orgId, query)
async getDepartmentMembers(deptId)
async getDepartmentPath(deptId) // 从根到当前部门的路径
// 内部方法
_buildTree(departments) // 构建部门树
_detectCircularReference(deptId, newParentId) // 循环引用检测
}2.2 ApprovalWorkflowManager
javascript
class ApprovalWorkflowManager extends EventEmitter {
async initialize(database)
// 工作流管理
async createWorkflow(orgId, config)
async updateWorkflow(workflowId, updates)
async deleteWorkflow(workflowId)
async getWorkflow(workflowId)
async listWorkflows(orgId)
// 审批请求
async submitRequest(workflowId, requestData)
async approveRequest(requestId, approverId, comment?)
async rejectRequest(requestId, approverId, reason?)
async getRequestStatus(requestId)
async listRequests(orgId, options?)
// 超时处理
_checkTimeouts() // 定时检查超时
_handleTimeout(request, action) // 执行超时动作
}审批工作流配置:
javascript
{
name: '请假审批',
type: 'sequential', // sequential | parallel | any_one
steps: [
{ approverRole: 'team-lead', timeoutMs: 86400000 },
{ approverRole: 'manager', timeoutMs: 172800000 },
],
timeoutAction: 'escalate', // approve | reject | escalate
}2.3 TeamManager
javascript
class TeamManager extends EventEmitter {
async initialize(database)
// 团队操作
async createTeam(orgId, deptId, name, metadata?)
async deleteTeam(teamId)
async getTeam(teamId)
async listTeams(orgId, deptId?)
// 成员管理
async addMember(teamId, userId, role?)
async removeMember(teamId, userId)
async updateMemberRole(teamId, userId, newRole)
async getMembers(teamId)
}3. 数据模型
3.1 org_teams
| 字段 | 类型 | 说明 |
|---|---|---|
| id | TEXT PK | 部门/团队ID |
| org_id | TEXT | 组织ID |
| parent_id | TEXT | 父部门ID |
| name | TEXT | 部门名称 |
| type | TEXT | 类型 (department/team) |
| metadata | TEXT(JSON) | 附加元数据 |
| created_at | INTEGER | 创建时间 |
| updated_at | INTEGER | 更新时间 |
3.2 org_team_members
| 字段 | 类型 | 说明 |
|---|---|---|
| id | TEXT PK | 记录ID |
| team_id | TEXT FK | 团队ID |
| user_id | TEXT | 用户ID |
| role | TEXT | 角色 (admin/member/viewer) |
| joined_at | INTEGER | 加入时间 |
3.3 approval_workflows
| 字段 | 类型 | 说明 |
|---|---|---|
| id | TEXT PK | 工作流ID |
| org_id | TEXT | 组织ID |
| name | TEXT | 工作流名称 |
| type | TEXT | 类型 (sequential/parallel/any_one) |
| steps | TEXT(JSON) | 审批步骤配置 |
| timeout_action | TEXT | 超时动作 |
| enabled | INTEGER | 是否启用 |
| created_at | INTEGER | 创建时间 |
3.4 approval_requests
| 字段 | 类型 | 说明 |
|---|---|---|
| id | TEXT PK | 请求ID |
| workflow_id | TEXT FK | 工作流ID |
| requester_id | TEXT | 发起人ID |
| title | TEXT | 请求标题 |
| content | TEXT(JSON) | 请求内容 |
| status | TEXT | 状态 (pending/approved/rejected/expired) |
| current_step | INTEGER | 当前步骤 |
| created_at | INTEGER | 创建时间 |
| completed_at | INTEGER | 完成时间 |
3.5 approval_responses
| 字段 | 类型 | 说明 |
|---|---|---|
| id | TEXT PK | 响应ID |
| request_id | TEXT FK | 请求ID |
| approver_id | TEXT | 审批人ID |
| step_index | INTEGER | 步骤序号 |
| action | TEXT | 动作 (approve/reject) |
| comment | TEXT | 审批意见 |
| created_at | INTEGER | 响应时间 |
4. IPC接口 (10个)
4.1 组织管理 (5个)
| 通道 | 说明 | 参数 |
|---|---|---|
enterprise:create-department | 创建部门 | orgId, name, parentId?, metadata? |
enterprise:get-department-tree | 获取组织树 | orgId |
enterprise:update-department | 更新部门 | deptId, updates |
enterprise:delete-department | 删除部门 | deptId |
enterprise:move-department | 移动部门 | deptId, newParentId |
4.2 审批管理 (3个)
| 通道 | 说明 | 参数 |
|---|---|---|
enterprise:create-workflow | 创建审批流程 | orgId, config |
enterprise:submit-approval | 发起审批请求 | workflowId, requestData |
enterprise:respond-approval | 审批响应 | requestId, approverId, action, comment? |
4.3 团队管理 (2个)
| 通道 | 说明 | 参数 |
|---|---|---|
enterprise:add-member | 添加成员 | teamId, userId, role? |
enterprise:remove-member | 移除成员 | teamId, userId |
5. 事件
| 事件 | 负载 | 说明 |
|---|---|---|
department:created | 部门创建 | |
department:moved | 部门移动 | |
approval:submitted | 审批发起 | |
approval:approved | 审批通过 | |
approval:rejected | 审批拒绝 | |
approval:timeout | 审批超时 | |
member:added | 成员添加 | |
member:removed | 成员移除 |
6. 前端页面
6.1 Pinia Store: enterprise-org.ts
typescript
interface EnterpriseOrgState {
departmentTree: DepartmentNode[];
currentDepartment: Department | null;
workflows: ApprovalWorkflow[];
approvalRequests: ApprovalRequest[];
teamMembers: TeamMember[];
loading: boolean;
error: string | null;
}
// Getters
flatDepartments; // 扁平化部门列表
pendingApprovals; // 待审批数量
myApprovals; // 我的审批请求
// Actions
fetchDepartmentTree(); // 获取组织树
createDepartment(); // 创建部门
moveDepartment(); // 移动部门
submitApproval(); // 发起审批
respondApproval(); // 审批响应
addTeamMember(); // 添加成员7. 文件结构
desktop-app-vue/src/main/enterprise/
├── enterprise-org-manager.js # 组织架构管理 (718行)
├── enterprise-ipc.js # 10个IPC处理器 (235行)
desktop-app-vue/src/main/permission/
├── approval-workflow-manager.js # 审批工作流引擎 (595行)
├── team-manager.js # 团队管理 (301行)
desktop-app-vue/src/renderer/
└── stores/enterprise-org.ts # 企业组织状态管理 (478行)8. 相关文档
文档版本: 1.0 最后更新: 2026-03-05
