跳转至

智能搜索提示框(SuggestFieldController)

为表单「智能搜索提示框(SuggestField)」字段提供按关键字的服务端候选项查询:从请求体解析 parentId/fieldName/keyword,找到表单中对应字段,运行其选项脚本生成候选项 JSON。

  • 接口类型:REST 资源(@Component + 类级 @RequestMapping(未声明 produces,由 Spring 视方法返回值协商;本控制器继承自 @RestControllerAbstractRuntimeController,方法返回值由 Spring 以 JSON 序列化输出))
  • 基址${myapps.context-path.runtime:}/api
  • Tag:智能搜索提示框执行模块

公共说明

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

1. 服务器返回搜索提示相关的信息

按表单 Id、字段名、关键字运行该字段的选项脚本,返回匹配候选项集合。

  • 接口类型:REST 资源
  • 请求方式POST
  • 请求路径/runtime/{applicationId}/forms/{formid}/documents/{docid}/querySuggest(完整:{runtime-context}/api/runtime/{applicationId}/forms/{formid}/documents/{docid}/querySuggest
  • 鉴权:是(需 accessToken,据源码)
  • Tag:智能搜索提示框执行模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 软件Id(DES 加密密文)
formid path string 表单Id(原值,不解密)
docid path string 文档Id(DES 加密密文)
content body string(JSON) 请求包体(见下)

请求体

JSON 字符串(被当作 JsonPath 文档解析),支持字段:

字段 类型 必填 说明
parentId string 父文档Id;等于解密后的 docid 时被置空
fieldName string 表单中 SuggestField 字段名
keyword string 搜索关键字;非空时去除单引号 '
{
  "parentId": "__PARENTID__",
  "fieldName": "customerName",
  "keyword": "张"
}

请求示例

POST /api/runtime/__APPID__/forms/__FORMID__/documents/__DOCID__/querySuggest HTTP/1.1
Content-Type: application/json
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

{
  "parentId": "__PARENTID__",
  "fieldName": "customerName",
  "keyword": "张"
}

响应

结构:统一 ResourcedataJSONArray,候选项集合,元素结构由 Options.toJsonSuggest() 决定(一般为 { "value", "text" } 形式);字段无选项脚本时为 null

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [ { "value": "001", "text": "张三" } ],
  "errors": null
}

说明:当字段的 optionsScript 为空、或私有空间中按 docid/parentId 取不到文档且字段无选项脚本时,控制器返回 data: null