跳转至

部门选择框(DepartmentSelectboxController)

为前台「部门选择框」组件提供部门树、部门下用户分页、部门搜索、按父级递归取子部门等能力。所有端点共享以 {applicationId} 起头的路径前缀。

  • 接口类型:REST 资源(@Component + 类级 @RequestMapping(produces = APPLICATION_JSON_VALUE),继承自 @RestControllerAbstractRuntimeController,方法返回值由 Spring 以 JSON 序列化输出)
  • 基址${myapps.context-path.runtime:}/api/runtime/{applicationId}/departments/selectbox
  • Tag:部门执行模块

公共说明

  • 鉴权(据源码 RuntimeMvcConfig + RestSecurityHandlerInterceptor:基址位于 /api/runtime/**不在豁免名单(豁免规则详见 login.md「公共说明 · 鉴权」)。拦截器走 Security.getUserIdFromToken(request),未取到再尝试 Security.getDebugUserIdFromToken(request),两者皆无则拒绝访问。所有端点均需 accessToken(或 debugToken),可通过 Cookie / 请求头 / query 参数任一方式传递。
  • 路径变量 {applicationId}经 DES 加密(按当前执行用户密钥),服务端 DesUtil.decryptTextByUserId(applicationId, getUser().getId()) 解密。
  • 响应结构:统一 Resource(见 ../index.md「统一响应结构」)。
  • HTTP 状态码:所有端点类级标注 @ResponseStatus(HttpStatus.OK),成功统一返回 200。

1. 获取部门树形集合

按部门 Id(及是否限定为本部门及下属)获取部门树形节点集合。

  • 接口类型:REST 资源
  • 请求方式GET
  • 请求路径/department(完整:{runtime-context}/api/runtime/{applicationId}/departments/selectbox/department
  • 鉴权:是(需 accessToken,据源码)
  • Tag:部门执行模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 软件Id(DES 加密密文)
deptId query string 部门Id(方法签名无 @RequestParam,Spring 默认按名称绑定且必填)
belong query boolean 是否只显示当前用户及下属部门(true/false

请求示例

GET /api/runtime/__APPID__/departments/selectbox/department?deptId=__DEPTID__&belong=false HTTP/1.1
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

响应

结构:统一 ResourcedataList<Node>,部门树节点集合。

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [ { "id": "...", "name": "研发部", "parentId": "..." } ],
  "errors": null
}

2. 根据父级部门id获取部门用户集合

按父级部门 Id 分页获取该部门下的子部门与用户集合(可标记邮件场景调用)。

  • 接口类型:REST 资源
  • 请求方式GET
  • 请求路径/user(完整:{runtime-context}/api/runtime/{applicationId}/departments/selectbox/user
  • 鉴权:是(需 accessToken,据源码)
  • Tag:部门执行模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 软件Id(DES 加密密文)
deptId query string 父级部门Id
pageSize query string 每页显示数据数(默认 5;空值/"null" 回退为 5
pageNum query string 当前页(默认 1;空值/"null" 回退为 1
isFromMail query boolean 是否邮件调用

请求示例

GET /api/runtime/__APPID__/departments/selectbox/user?deptId=__DEPTID__&pageNum=1&pageSize=5 HTTP/1.1
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

响应

结构:统一 ResourcedataMap<String, Object>,部门与用户集合(含分页信息),结构由 DepartmentRunTimeService.getDepartmentAndUsers 决定。

{
  "errcode": 0,
  "errmsg": "ok",
  "data": { "...": "部门与用户结构(含分页)" },
  "errors": null
}

3. 部门搜索

按关键字搜索部门树节点;关键字为空时返回当前用户企业域的根部门作为初始节点。

  • 接口类型:REST 资源
  • 请求方式GET
  • 请求路径/search(完整:{runtime-context}/api/runtime/{applicationId}/departments/selectbox/search
  • 鉴权:是(需 accessToken,据源码)
  • Tag:部门执行模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 软件Id(DES 加密密文)
keyword query string 关键字;为空时返回根部门

请求示例

GET /api/runtime/__APPID__/departments/selectbox/search?keyword=研发 HTTP/1.1
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

响应

结构:统一 ResourcedataList<Node>,命中的部门节点集合(关键字为空时仅含根部门 DepartmentNode)。

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [ { "id": "...", "name": "研发部", "code": "RD", "level": 1 } ],
  "errors": null
}

4. 根据父级获取部门集合

按父级部门 Id 获取下一级有效部门集合(含各部门的用户数与是否还有下级);parentId 为空时返回当前用户企业域的根部门。

  • 接口类型:REST 资源
  • 请求方式GET
  • 请求路径/childs(完整:{runtime-context}/api/runtime/{applicationId}/departments/selectbox/childs
  • 鉴权:是(需 accessToken,据源码)
  • Tag:部门执行模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 软件Id(DES 加密密文)
parentId query string 父级部门Id;为空时取根部门

请求示例

GET /api/runtime/__APPID__/departments/selectbox/childs?parentId=__PARENTID__ HTTP/1.1
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

响应

结构:统一 ResourcedataList<JSONObject>,每个元素 { "id", "name", "userCount", "hasChilds" }

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [
    { "id": "...", "name": "研发部", "userCount": 12, "hasChilds": true }
  ],
  "errors": null
}