Skip to content

企业组织管理系统

模块概述

版本: 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 核心组件

组件文件行数说明
EnterpriseOrgManagerenterprise-org-manager.js718组织架构管理
ApprovalWorkflowManagerapproval-workflow-manager.js595审批工作流引擎
TeamManagerteam-manager.js301团队成员管理
Enterprise IPCenterprise-ipc.js23510个IPC处理器
Pinia Storeenterprise-org.ts478前端状态管理

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

字段类型说明
idTEXT PK部门/团队ID
org_idTEXT组织ID
parent_idTEXT父部门ID
nameTEXT部门名称
typeTEXT类型 (department/team)
metadataTEXT(JSON)附加元数据
created_atINTEGER创建时间
updated_atINTEGER更新时间

3.2 org_team_members

字段类型说明
idTEXT PK记录ID
team_idTEXT FK团队ID
user_idTEXT用户ID
roleTEXT角色 (admin/member/viewer)
joined_atINTEGER加入时间

3.3 approval_workflows

字段类型说明
idTEXT PK工作流ID
org_idTEXT组织ID
nameTEXT工作流名称
typeTEXT类型 (sequential/parallel/any_one)
stepsTEXT(JSON)审批步骤配置
timeout_actionTEXT超时动作
enabledINTEGER是否启用
created_atINTEGER创建时间

3.4 approval_requests

字段类型说明
idTEXT PK请求ID
workflow_idTEXT FK工作流ID
requester_idTEXT发起人ID
titleTEXT请求标题
contentTEXT(JSON)请求内容
statusTEXT状态 (pending/approved/rejected/expired)
current_stepINTEGER当前步骤
created_atINTEGER创建时间
completed_atINTEGER完成时间

3.5 approval_responses

字段类型说明
idTEXT PK响应ID
request_idTEXT FK请求ID
approver_idTEXT审批人ID
step_indexINTEGER步骤序号
actionTEXT动作 (approve/reject)
commentTEXT审批意见
created_atINTEGER响应时间

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

基于 MIT 许可发布