Skip to main content

报表 API

获取API

  • 在设置-统计分析-报表 新建报表并保存
  • 在设置-统计分析-报表 报表详细页,开发标签下复制API

API 格式: {ROOT_URL}/analytics/api/amis/question/{questionId}

获取结果

  • 在浏览器访问API,获取报表数据
  • 返回结果为JSON格式

报表数据结构

{
"status": 0, // 0 表示成功
"msg": "ok",
"data": {
"count": {count}, // 数据行数
"rows": [ // 数据
{
"{key}": "{value}",
...
},
],
"cols": [ // 数据列定义
{
"id": "",
"name": "",
"display_name": "",
"base_type": "",
"effective_type": "",
"semantic_type": null,
"field_ref": [
"field",
"",
null
],
"source": "",
"visibility_type": "",
"table_id": "",
...
},
]
}
}

报表数据示例

{
"status": 0,
"msg": "ok",
"data": {
"count": 10,
"rows": [
{
"_id": "65d6a69b1b9cab05bf584fc5_65a49dca55d1b305bf065324",
"category": "65d6a69b1b9cab05bf584fc5_659cb4a972192405bf822170",
"type": "火车票",
"invoice_date": "2023-07-05T00:00:00.000Z",
"invoice_num": "149Z058272",
"invoice_amount": 91.5,
"seller_name": null,
"purchaser_name": null,
"name": "Demo-FP-00001",
"verify_status": "不查验",
"created": "2024-02-22T09:42:52.159Z",
"external_category": "交通费"
},
{
"_id": "65d6a69b1b9cab05bf584fc5_65a49e1f55d1b305bf06532a",
"category": "65d6a69b1b9cab05bf584fc5_659cb4a972192405bf822170",
"type": "出租车票",
"invoice_date": "2023-06-07T00:00:00.000Z",
"invoice_num": "02833771",
"invoice_amount": 26,
"seller_name": null,
"purchaser_name": null,
"name": "Demo-FP-00002",
"verify_status": "不查验",
"created": "2024-02-22T09:42:52.159Z",
"external_category": "交通费"
},
],
"cols": [
{
"description": null,
"database_type": "java.lang.String",
"semantic_type": "type/PK", // 主键
"table_id": "invoices",
"coercion_strategy": null,
"name": "_id",
"fingerprint_version": 0,
"has_field_values": "search",
"settings": null,
"caveats": null,
"fk_target_field_id": null,
"dimensions": [],
"dimension_options": [],
"updated_at": "2023-08-04T05:39:33.039939",
"custom_position": 0,
"effective_type": "type/Text",
"active": true,
"nfc_path": null,
"parent_id": null,
"id": "invoices._id",
"last_analyzed": null,
"database_is_auto_increment": false,
"position": 0,
"visibility_type": "normal",
"default_dimension_option": null,
"target": null,
"preview_display": true,
"display_name": "ID",
"database_position": 0,
"database_required": false,
"fingerprint": null,
"created_at": "2023-08-04T05:39:33.039939",
"base_type": "type/Text",
"points_of_interest": null
},
{
"id": "invoices.category",
"name": "category",
"display_name": "费用类别",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": "type/FK", // 外键
"field_ref": [
"field",
"invoices.category",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices",
"remapped_to": "external_category"
},
{
"id": "invoices.type",
"name": "type",
"display_name": "发票类型",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.type",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.invoice_date",
"name": "invoice_date",
"display_name": "发票日期",
"base_type": "type/Date",
"effective_type": "type/Date",
"semantic_type": null,
"field_ref": [
"field",
"invoices.invoice_date",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.invoice_num",
"name": "invoice_num",
"display_name": "发票号码",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.invoice_num",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.invoice_amount",
"name": "invoice_amount",
"display_name": "发票含税金额",
"base_type": "type/Float",
"effective_type": "type/Float",
"semantic_type": "type/Score",
"field_ref": [
"field",
"invoices.invoice_amount",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.seller_name",
"name": "seller_name",
"display_name": "销售方名称",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.seller_name",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.purchaser_name",
"name": "purchaser_name",
"display_name": "购方名称",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.purchaser_name",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.name",
"name": "name",
"display_name": "发票编号",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.name",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.verify_status",
"name": "verify_status",
"display_name": "查验状态",
"base_type": "type/Text",
"effective_type": "type/Text",
"semantic_type": null,
"field_ref": [
"field",
"invoices.verify_status",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"id": "invoices.created",
"name": "created",
"display_name": "创建时间",
"base_type": "type/DateTime",
"effective_type": "type/DateTime",
"semantic_type": null,
"field_ref": [
"field",
"invoices.created",
null
],
"source": "fields",
"visibility_type": "normal",
"table_id": "invoices"
},
{
"description": null,
"semantic_type": "type/Name",
"table_id": "expense_category",
"coercion_strategy": null,
"name": "external_category",
"settings": null,
"source": "fields",
"remapped_from": "category",
"fk_field_id": "category",
"field_ref": [
"field",
"expense_category.name",
{
"source-field": "invoices.category"
}
],
"effective_type": "type/Text",
"nfc_path": null,
"parent_id": null,
"id": "expense_category.name",
"visibility_type": "normal",
"display_name": "费用类别"
}
]
}
}

API应用示例

使用devextreme-datagrid控件展示数据,以feikongwang项目的发票对象为例:

  • 在设置-统计分析-报表 新建报表发票并保存
  • 在设置-统计分析-报表 发票报表详细页,开发标签下复制API 留作备用
  • 在设置-自定义应用-微页面 新建类型为应用程序页面的微页面
  • 进入设计器可在自定义组件标签下查看到DataGrid组件

如果没看到组件,说明组件未加载,需要在项目的.env文件中配置环境变量STEEDOS_WIDGETS_ADDITIONAL=@steedos-widgets/devextreme

  • 将以下示例代码拷贝至代码框中,并修改service组件的数据接口地址为发票报表中复制的API,最后保存并发布微页面
{
"type": "page",
"title": "Welcome to Steedos",
"body": [
{
"type": "service",
"body": [
{
"type": "devextreme-datagrid",
"className": "",
"config": {
"keyExpr": "_id",
"columns": [
{
"dataField": "_id",
"caption": "ID",
"name": "_id"
},
{
"dataField": "name",
"name": "name"
}
],
"allowColumnResizing": true,
"columnAutoWidth": true,
"groupPanel": {
"visible": true
},
"columnChooser": {
"enabled": true
},
"filterRow": {
"visible": true
},
"searchPanel": {
"visible": true
}
},
"id": "u:a38c09bec4a6",
"dataFilter": "config.dataSource = data.rows;\nconfig.columns = [];\n\ndata.cols.forEach((col) => {\n if (\"type/FK\" === col.semantic_type || \"type/PK\" === col.semantic_type) { \n return\n }\n config.columns.push({\n name: col.name,\n caption: col.display_name,\n dataField: col.name\n })\n})\nconsole.log(config)\nreturn config;"
}
],
"id": "u:70563d1bcdba",
"messages": {},
"api": {
"url": "https://5000-sapphire-felidae-9bexhf1x.ws.vscode.steedos.cn/analytics/api/amis/question/65d6a9b81b9cab05bf584fc6",
"method": "get",
"messages": {},
"requestAdaptor": "",
"adaptor": ""
},
"initFetch": true
}
],
"regions": [
"body"
],
"data": {
"initialValues": {},
"appId": "builder",
"title": "",
"context": {
"rootUrl": "https://5000-fuchsia-mackerel-vjg1ha6z.ws.vscode.steedos.cn",
"userId": "222dcc20-1adf-49c0-83e6-8eb7b4df673e",
"tenantId": "65b9c01273b2ae064641fc81",
"authToken": ""
}
},
"id": "u:b84e5ec519fa"
}
  • 在设置-自定义应用-选项卡中新建选项卡
  • 在设置-自定义应用-应用程序中新建应用程序,在选项卡-设置选项卡中选择刚刚新建的选项卡
  • 点击左上角应用程序启动器进入刚刚新建的应用即可看到发票数据。