# 部门管理

> 模块标识：department  |  接口数量：7

## 1. 获取部门列表
**方法**：	GET

**路径**：				/api/departments

**功能说明**：
获取部门列表，支持按组织筛选

### 请求参数
```json
{
  "query": [
    {
      "name": "pageNum",
      "type": "number",
      "required": false,
      "description": "页码，默认1"
    },
    {
      "name": "pageSize",
      "type": "number",
      "required": false,
      "description": "每页数量，默认10"
    },
    {
      "name": "organizationId",
      "type": "string",
      "required": false,
      "description": "按组织筛选"
    },
    {
      "name": "name",
      "type": "string",
      "required": false,
      "description": "部门名称关键词"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "获取成功",
    "data": {
      "list": [
        {
          "id": 1,
          "code": "DEP0001",
          "name": "研发部",
          "organizationId": "ORG0001",
          "status": 1,
          "createTime": "2025-01-01T10:00:00.000Z"
        }
      ],
      "total": 100,
      "pageNum": 1,
      "pageSize": 10
    }
  }
}
```


## 2. 获取部门详情
**方法**：	GET

**路径**：				/api/departments/{id}

**功能说明**：
根据部门ID获取部门详细信息

### 请求参数
```json
{
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "部门ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "获取成功",
    "data": {
      "id": 1,
      "code": "DEP0001",
      "name": "研发部",
      "organizationId": "ORG0001",
      "status": 1,
      "createTime": "2025-01-01T10:00:00.000Z"
    }
  },
  "failure": {
    "code": "4040",
    "message": "部门不存在",
    "data": null
  }
}
```


## 3. 创建部门
**方法**：	POST

**路径**：				/api/departments

**功能说明**：
创建新的部门

### 请求参数
```json
{
  "body": {
    "name": "string｜必填，部门名称",
    "organizationId": "string｜必填，所属组织ID",
    "leaderId": "string｜可选，部门负责人ID",
    "status": "number｜可选，状态：1-启用，0-禁用"
  }
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "创建部门成功",
    "data": {
      "id": 1,
      "code": "DEP0001",
      "name": "研发部",
      "organizationId": "ORG0001",
      "status": 1,
      "createTime": "2025-01-01T10:00:00.000Z"
    }
  },
  "failure": {
    "code": "4000",
    "message": "创建部门失败",
    "data": null
  }
}
```


## 4. 更新部门
**方法**：	PUT

**路径**：				/api/departments/{id}

**功能说明**：
更新指定部门的信息

### 请求参数
```json
{
  "body": {
    "name": "string｜必填，部门名称",
    "organizationId": "string｜必填，所属组织ID",
    "leaderId": "string｜可选，部门负责人ID",
    "status": "number｜可选，状态：1-启用，0-禁用"
  },
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "部门ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "更新部门成功",
    "data": {
      "id": 1,
      "code": "DEP0001",
      "name": "研发部",
      "organizationId": "ORG0001",
      "status": 1,
      "createTime": "2025-01-01T10:00:00.000Z"
    }
  },
  "failure": {
    "code": "4000",
    "message": "更新部门失败",
    "data": null
  }
}
```


## 5. 删除部门
**方法**：	DELETE

**路径**：				/api/departments/{id}

**功能说明**：
删除指定的部门

### 请求参数
```json
{
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "部门ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "删除部门成功",
    "data": {
      "result": true
    }
  },
  "failure": {
    "code": "4000",
    "message": "删除部门失败",
    "data": null
  }
}
```


## 6. 获取部门关联用户
**方法**：	GET

**路径**：				/api/departments/{id}/users

**功能说明**：
获取指定部门关联的用户

### 请求参数
```json
{
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "部门ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "获取成功",
    "data": {
      "id": 1,
      "code": "DEP0001",
      "name": "研发部",
      "organizationId": "ORG0001",
      "status": 1,
      "createTime": "2025-01-01T10:00:00.000Z"
    }
  },
  "failure": {
    "code": "4040",
    "message": "部门不存在",
    "data": null
  }
}
```


## 7. 更新部门用户关联
**方法**：	PUT

**路径**：				/api/departments/{id}/users

**功能说明**：
更新指定部门的用户关联关系

### 请求参数
```json
{
  "body": {
    "name": "string｜必填，部门名称",
    "organizationId": "string｜必填，所属组织ID",
    "leaderId": "string｜可选，部门负责人ID",
    "status": "number｜可选，状态：1-启用，0-禁用"
  },
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "部门ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "更新部门成功",
    "data": {
      "id": 1,
      "code": "DEP0001",
      "name": "研发部",
      "organizationId": "ORG0001",
      "status": 1,
      "createTime": "2025-01-01T10:00:00.000Z"
    }
  },
  "failure": {
    "code": "4000",
    "message": "更新部门失败",
    "data": null
  }
}
```

