轻易云在金蝶云星空与旺店通数据对接中的应用实践

  • 轻易云集成顾问-钟家寿
### 金蝶云星空与旺店通·企业奇门数据集成案例:调拨单对接到旺店通其他出库 在现代化业务环境中,跨系统的数据流转和实时处理已成为企业提升运营效率的关键之一。本案例探讨了如何通过轻易云数据集成平台,将金蝶云星空的调拨单数据无缝对接到旺店通·企业奇门,实现库存管理的自动化,并确保各环节数据准确性和及时性。 #### 背景与挑战 该方案核心任务是将金蝶云星空中的调拨单高效、可靠地写入到旺店通·企业奇门对应的出库订单。问题主要体现在以下几个方面: - **API接口调用及分页处理**:需要解决从金蝶云星空获取大量调拨单数据时的分页和限流问题,通过调用`executeBillQuery`接口。 - **数据格式转换**:两套系统之间存在显著的数据结构差异,需在集成过程中实现自定义的数据转换逻辑,以适应双方特定需求。 - **异常处理与稳定性保障**:实时监控每一个集成环节,并实现在发生异常时能够快速响应和重试机制,如调用`wdt.stockout.order.push`接口进行写入操作。 #### 方案设计 基于上述背景,我们使用轻易云的一系列功能,包括集中监控、可视化设计工具以及强大的数据质量监控能力,有针对性地设计并实施了解决方案。具体步骤如下: 1. 调用金蝶云星空API `executeBillQuery`按需抓取符合条件的调拨单数据,同时设置合适的分页参数以控制请求次数并防止触发限流机制。 2. 使用轻易云提供的数据转换工具,将获取到的信息映射为旺店通·企业奇门所需的字段格式,并进行必要的数据清洗和规范化处理。 3. 对于批量写入部分,通过制定详细的流程,在保证吞吐量达标同时,不丢失任何一条关键信息。借助错误重试机制,当推送过程中出现故障或异常时,可以自动恢复并重新尝试发送未成功记录。 4. 利用平台提供的一致性校验功能,对打包上传前后的内容进行双向核对,确保所有传递的信息无误且完整。 以上初步讨论涵盖了整个项目在技术层面的要点。在后续文章中,我们会进一步深入具体操作细节及代码示例,展示全流程配置方法,以及实际应用过程中遇到的小贴士与最佳实践总结。 ![如何开发用友BIP接口](https://pic.qeasy.cloud/D16.png~tplv-syqr462i7n-qeasy.image) ### 调用金蝶云星空接口executeBillQuery获取并加工数据 在数据集成过程中,调用源系统的API接口是至关重要的一步。本文将详细探讨如何通过轻易云数据集成平台调用金蝶云星空的`executeBillQuery`接口,以获取并加工调拨单数据,并对接到旺店通其他出库系统。 #### 接口配置与请求参数 在轻易云数据集成平台中,我们首先需要配置元数据,以便正确调用金蝶云星空的API接口。以下是元数据配置的关键部分: ```json { "api": "executeBillQuery", "effect": "QUERY", "method": "POST", "number": "FID", "id": "FBillNo", "idCheck": true, "request": [ {"field":"FBillEntry_FEntryID","label":"FBillEntry_FEntryID","type":"string","describe":"111","value":"FBillEntry_FEntryID"}, {"field":"FID","label":"FID","type":"string","describe":"111","value":"FID"}, {"field":"FBillNo","label":"FBillNo","type":"string","describe":"111","value":"FBillNo"}, {"field":"FDocumentStatus","label":"FDocumentStatus","type":"string","describe":"111","value":"FDocumentStatus"}, {"field":"FStockOrgId_FNumber","label":"FStockOrgId_FNumber","type":"string","describe":"111","value":"FStockOrgId.FNumber"}, {"field":"FDate","label":"FDate","type":"string","describe":"111","value":"FDate"}, {"field":"FBillTypeID_FNumber","label":"FBillTypeID_FNumber","type":"string","describe":"111","value":"FBillTypeID.FNumber"}, {"field":"FTransferBizType","label":"FTransferBizType","type":"string","describe":"111","value":"FTransferBizType"}, {"field":"FStockOutOrgId_FNumber","label":"FStockOutOrgId_FNumber","type":"","describe":"","value":""}, // ... 其他字段省略 ], "otherRequest": [ {"field": "Limit", "label": "Limit", "type": "string", "describe": "金蝶的查询分页参数", "value": "{PAGINATION_PAGE_SIZE}"}, {"field": "FieldKeys", "label": "FieldKeys", "type": "array", "describe": "", "value": "{MAIN_REQUEST}"}, {"field": "TopRowCount", "label": "", "type": "", "describe": ""}, {"field": "FilterString", "label": "", "type": "", "describe":"","value":"'{{LAST_SYNC_TIME|datetime}}' and FSrcStockId.FNumber='007' and FStockOutOrgId.FNumber='102'"}, {"field": "", "", "", ""}, // ... 其他字段省略 ], // ... } ``` #### 请求参数解析 1. **基本字段**:如`FBillEntry_FEntryID`、`FID`、`FBillNo`等,这些字段用于标识和过滤调拨单的数据。 2. **分页参数**:包括`Limit`、`TopRowCount`、`StartRow`等,用于控制查询结果的分页。 3. **过滤条件**:通过`FilterString`字段指定,如示例中的条件 `'{{LAST_SYNC_TIME|datetime}}' and FSrcStockId.FNumber='007' and FStockOutOrgId.FNumber='102'`,确保只获取符合条件的数据。 #### 调用API并处理响应 在配置好元数据后,通过轻易云平台发起HTTP POST请求,调用金蝶云星空的API接口。以下是一个简化的示例代码: ```python import requests import json url = 'https://api.kingdee.com/executeBillQuery' headers = {'Content-Type': 'application/json'} payload = { # 根据元数据配置构建请求体 } response = requests.post(url, headers=headers, data=json.dumps(payload)) if response.status_code == 200: data = response.json() # 数据处理逻辑 else: print(f"Error: {response.status_code}") ``` #### 数据清洗与转换 获取到原始数据后,需要进行清洗和转换,以便适配目标系统(如旺店通)的需求。常见的数据清洗操作包括: 1. **字段映射**:将金蝶云返回的数据字段映射到目标系统所需的字段。 2. **格式转换**:如日期格式、数值类型等转换。 3. **数据过滤**:剔除不必要的数据,确保只保留有效信息。 例如,将金蝶云返回的调拨单号(`FBillNo`)映射为旺店通系统中的订单号: ```python def map_fields(data): mapped_data = [] for entry in data: mapped_entry = { 'order_no': entry['FBillNo'], 'status': entry['FDocumentStatus'], # ...其他字段映射 } mapped_data.append(mapped_entry) return mapped_data cleaned_data = map_fields(response.json()) ``` #### 写入目标系统 最后,将清洗和转换后的数据写入目标系统(如旺店通)。这一步通常通过调用目标系统的API接口实现。 ```python target_url = 'https://api.wangdiantong.com/orders' target_headers = {'Content-Type': 'application/json'} for entry in cleaned_data: target_response = requests.post(target_url, headers=target_headers, data=json.dumps(entry)) if target_response.status_code != 200: print(f"Failed to write entry: {entry['order_no']}") ``` 通过上述步骤,我们完成了从金蝶云星空获取调拨单数据,并将其对接到旺店通其他出库系统的全过程。这不仅提高了数据处理效率,还确保了不同系统间的数据一致性和准确性。 ![打通金蝶云星空数据接口](https://pic.qeasy.cloud/S7.png~tplv-syqr462i7n-qeasy.image) ### 使用轻易云数据集成平台实现调拨单对接到旺店通其他出库 在数据集成生命周期的第二步,我们需要将已经集成的源平台数据进行ETL转换,使其符合目标平台旺店通·企业奇门API接口所能够接收的格式,并最终写入目标平台。以下是具体的技术实现过程。 #### 1. API接口配置 首先,我们需要配置旺店通·企业奇门API接口,以便能够接收和处理调拨单数据。根据提供的元数据配置,我们需要调用`wdt.stockout.order.push`接口,使用POST方法提交数据。 ```json { "api": "wdt.stockout.order.push", "effect": "EXECUTE", "method": "POST", "idCheck": true, "request": [ { "field": "outer_no", "label": "外部单号", "type": "string", "value": "{FBillNo}" }, { "field": "warehouse_no", "label": "仓库编号", "type": "string", "value": "{FSrcStockId_FNumber}" }, { "field": "remark", "label": "备注", "type": "string", "value": "金蝶调拨单" }, { "field": "is_check", "label": "是否审核", "type": "string", "value": "1" }, { "field": "detail_list", "label": `货品明细节点{FBillEntry_FEntryID}`, `type`: `array`, `value`: `detail_listss`, `children`: [ { `field`: `spec_no`, `label`: `商家编码`, `type`: `string`, `value`: `{detail_listss.FMaterialId_FNumber}` }, { `field`: `num`, `label`: `出库数量`, `type`: `string`, `value`: `{detail_listss.FQty}` }, { `field`: `price`, `label`: `原价`, `type`: `string`, “value”: “1” } ] } ], “otherRequest”: [ { “field”: “stockout_info”, “label”: “stockout_info”, “type”: “string”, “describe”: “111”, “value”: “1” } ], “operation”: { “method”: “merge”, “field”: “FBillNo”, “bodyName”: “detail_listss”, “bodySum”: [“FQty”], “header”: [“FBillNo”,“FSrcStockId_FNumber”], “body”: [“FMaterialId_FNumber”,“FQty”] } } ``` #### 2. 数据请求与清洗 在这个阶段,我们从源系统中获取调拨单数据,并进行必要的数据清洗和预处理。例如,确保每个字段的数据类型和格式都符合目标API的要求。以下是一个示例代码片段,用于从源系统获取数据并进行初步清洗: ```python import requests # 从源系统获取调拨单数据 source_data = requests.get('source_system_api_url').json() # 数据清洗和预处理 cleaned_data = [] for entry in source_data: cleaned_entry = { 'FBillNo': entry['bill_no'], 'FSrcStockId_FNumber': entry['warehouse_code'], 'detail_listss': [ { 'FMaterialId_FNumber': item['material_code'], 'FQty': item['quantity'] } for item in entry['items'] ] } cleaned_data.append(cleaned_entry) ``` #### 3. 数据转换与写入 接下来,我们将清洗后的数据转换为目标平台所需的格式,并通过API接口写入目标平台。以下是一个示例代码片段,用于将清洗后的数据转换并写入旺店通·企业奇门: ```python import json # 转换数据为目标平台格式 def transform_data(cleaned_data): transformed_data = [] for entry in cleaned_data: transformed_entry = { 'outer_no': entry['FBillNo'], 'warehouse_no': entry['FSrcStockId_FNumber'], 'remark': '金蝶调拨单', 'is_check': '1', 'detail_list': [ { 'spec_no': item['FMaterialId_FNumber'], 'num': item['FQty'], 'price': '1' } for item in entry['detail_listss'] ] } transformed_data.append(transformed_entry) return transformed_data # 写入目标平台 def write_to_target_platform(transformed_data): api_url = 'https://api.wangdian.cn/erp_open' for data in transformed_data: response = requests.post(api_url, json=data) if response.status_code == 200: print(f"Data written successfully: {data}") else: print(f"Failed to write data: {data}, Response: {response.text}") transformed_data = transform_data(cleaned_data) write_to_target_platform(transformed_data) ``` 通过上述步骤,我们实现了从源系统获取调拨单数据、进行ETL转换,并最终将其写入目标平台旺店通·企业奇门。这一过程不仅确保了数据的一致性和准确性,还极大提升了业务流程的自动化程度。 ![钉钉与MES系统接口开发配置](https://pic.qeasy.cloud/T19.png~tplv-syqr462i7n-qeasy.image)