跳转至

打印运行时(PrintRuntimeController)

打印设计器运行时接口:按打印模板与参数解析打印数据(hostRequestBridge.getPrintDatas 等价能力),供前端打印渲染时调用。

  • 接口类型:REST 资源(@Component 继承 AbstractRuntimeController;类级 produces = MediaType.APPLICATION_JSON_VALUE,方法返回类型为 Resource,由 Spring Jackson 序列化为 JSON,据源码)
  • 基址${myapps.context-path.runtime:}/api/runtime
  • Tag:runtime

公共说明

  • 鉴权(据源码):类级基址位于 /api/runtime/**,在 RestSecurityHandlerInterceptor 覆盖范围内,且不在豁免名单(豁免仅覆盖 /api/runtime/login.*/api/runtime/dingding/authlogin/api/runtime/synchronization.*、URI 以 /showjrxml 结尾、含 /getCustomColumnsInfos、含 /accessToken、含 /macro、以 /clear 结尾、含 /pages/ 等,详见 login.md「公共说明 · 鉴权」)。拦截器走 Security.getUserIdFromToken(request),未取到再尝试 Security.getDebugUserIdFromToken(request),两者皆无则拒绝。故需 accessToken(或 debugToken),可通过 Cookie / 请求头 / query 参数任一方式传递。控制器内 getUser() 允许为 null(仅当 null 时跳过 DES 解密),但服务层 printRuntimeService.resolvePrintData(..., getUser()) 期望非空 WebUser实际请求需携带有效 accessToken
  • 路径变量 {applicationId} / {templateId}:必填,经 DES 加密(按当前执行用户密钥);仅当 getUser() 非空时服务端 DesUtil.decryptTextByUserId(applicationId/templateId, getUser().getId()) 解密,templateId 为空时跳过解密。
  • 响应结构:本控制器响应使用统一 Resource(见 ../index.md「统一响应结构」)。异常走 error(500, e.getMessage(), null)

1. 获取打印数据

POST JSON body 提交 printTemplateIddocIds 等参数,按模板 dataSource 执行查询返回打印数据列表(PrintDataRequestUtil.buildPrintParams 合并 query 参数与 body,由 PrintRuntimeService.resolvePrintData 解析)。

  • 接口类型:REST 资源
  • 请求方式POST
  • 请求路径/{applicationId}/print/{templateId}/data(完整:{runtime-context}/api/runtime/{applicationId}/print/{templateId}/data
  • 鉴权:是(需 accessToken,据源码)
  • Tag:runtime

请求参数

参数名 位置 类型 必填 说明
applicationId path string 应用Id(DES 加密密文)
templateId path string 打印模板Id(DES 加密密文,可为空字符串——为空时跳过解密)
body body object(JSON) 打印参数 JSON,由 PrintDataRequestUtil.buildPrintParams 与 query 参数合并。常见字段:printTemplateIddocIds 等(具体由 PrintDataRequestUtil 解析)

请求示例

POST /api/runtime/__APPID__/print/__TEMPLATEID__/data HTTP/1.1
Content-Type: application/json
Cookie: accessToken=eyJhbGciOiJIUzI1NiJ9...

{
  "printTemplateId": "__TEMPLATEID__",
  "docIds": ["__DOCID__"]
}

响应

结构:统一 Resource(见 ../index.md「统一响应结构」)。 dataList<Map<String, Object>>,打印数据行集合(由 PrintRuntimeService.resolvePrintData 按模板 dataSource 查询得到)。

成功示例

{
  "errcode": 0,
  "errmsg": "ok",
  "data": [
    { "field1": "值1", "field2": "值2" }
  ],
  "errors": null
}

失败示例

{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }