闪迪采购申请单金蝶=》钉钉 集成案例
在企业管理中,跨系统的数据集成是提升工作效率和准确度的关键步骤。本文将探讨如何通过轻易云数据集成平台,实现闪迪采购申请单从金蝶云星空到钉钉的数据无缝对接。
数据获取与转换
首先,通过调用金蝶云星空的API接口executeBillQuery
,定时可靠地抓取采购申请单数据。这个过程需要处理分页和限流问题,以确保所有数据都能完整获取且不过载系统资源。同时,我们利用自定义数据转换逻辑,将金蝶云星空的数据格式调整为适合钉钉标准的结构。
{
"acctID" : "your_acct_id",
"dataEntries":[
{
"FBrNo":1,
"FBillNo":"PO2021091234",
...
}
]
}
实时监控与质量保证
在整个数据流动过程中,轻易云提供了集中化的监控和告警系统,使我们可以实时跟踪每个任务的状态及其性能表现。如果出现异常情况,可以及时响应并进行错误重试。同时,借助于全面覆盖的数据质量监控机制,有效保障了所传输数据的一致性和完整性。
# 伪示例:实时监控日志输出
2023-10-01 12:00:00 INFO TaskStarted - Fetching data from 金蝶 executeBillQuery API
2023-10-01 12:05:00 WARN DataQualityIssue - Detected data inconsistency in entry ID XYZ123, initiating re-fetch...
数据写入与映射
为了快速、高效地将大量申请单写入到钉钉,通过使用其API topapi/processinstance/create
完成批量数据创建操作。这一过程中,还需特别注意两个平台之间的数据格式差异,并实现相应的映射以确保信息准确传递。另外,对于特定业务场景下,需要依据具体需求对部分字段进行定制化处理,以满足不同部门、角色或应用场景所需。
{
"process_code": "PROC-F456",
"originator_user_id": "$USER_ID$",
...
}
至此,我们简单介绍了配置元数据并高效执行跨平台集成的一些核心技术细节。在后续内容中,将进一步深入解析具体实施方案及最佳实践方法。
调用金蝶云星空接口executeBillQuery获取并加工数据
在轻易云数据集成平台中,调用源系统接口是数据集成生命周期的第一步。本文将详细探讨如何通过调用金蝶云星空的executeBillQuery
接口获取采购申请单数据,并进行初步加工。
接口配置与请求参数
首先,我们需要配置调用executeBillQuery
接口所需的元数据。以下是元数据配置的详细内容:
{
"api": "executeBillQuery",
"effect": "QUERY",
"method": "POST",
"number": "FBillNo",
"id": "FEntity_FEntryID",
"name": "FBillNo",
"request": [
{"field": "FCreatorId", "label": "创建人", "type": "string", "value": "FCreatorId"},
{"field": "F_ora_Base1", "label": "办理人", "type": "string", "value": "F_ora_Base1"},
{"field": "FBillNo", "label": "单据编号", "type": "string", "value": "FBillNo"},
{"field": "FApplicationDate", "label": "申请日期", "type": "string", "value": "FApplicationDate"},
{"field": "F_ora_DDSQSY", "label": "申请事由", "type": "string",
"value":"F_ora_DDSQSY"},
{"field":"FApplicationOrgId","label":"申请组织","type":"string","value":"FApplicationOrgId.FName"},
{"field":"FCurrencyId","label":"币别","type":"string","value":"FCurrencyId.FName"},
{"field":"FApplicationDeptId","label":"申请部门","type":"string","value":"FApplicationDeptId.FNumber"},
{"field":"FNote","label":"备注","type":"string","value":"FNote"},
{"field":"FSUPPLIERID1","label":"供应商","type":"string","value":"FSUPPLIERID1.FName"},
{"field":"FMaterialId","label":"物料编码","type":"string","value":"FMaterialId.FName"},
{"field":"FReqQty","label":"申请数量","type":"string","value":"FReqQty"},
{"field":"FTAXPRICE","label":"含税单价","type":"string","value":"FTAXPRICE"},
{"field":"FReqAmount","label":"含税金额","type":"string","value":
"FReqAmount"},
{"field":
"FID",
"label":
"FID",
"type":
"string",
"value":
"FID"
},
{"field":
"FEntity_FEntryID",
"label":
"行内码",
"type":
"string",
"value":
"FEntity_FEntryID"
},
{"field":
"F_ora_Combo1",
"label":
"单位",
"type":
"string",
"value":
"F_ora_Combo1"
},
{"field":
"F_ora_KCSLWP",
"label":
"库存数量",
"type":
"string",
"value":
"F_ora_KCSLWP"
},
{"field":
"F_ora_BCGMSLWP",
"label":
"本次购买数量",
"type":
"string",
"value":
"F_ora_BCGMSLWP"
},
{"field":
"F_ora_XDHZSLWP",
"label":
"下单后总数量(万片)",
"type":
"string",
"value":
"F_ora_XDHZSLWP"
},
{"field":
"F_ora_BCGMJEWY",
"label":
本次购买金额,
"type:
字符串,
"value:
“ F _ ora _ BCGMJEWY ”
},
{" field ":" F _ QCSID "," label ":" 前抄送 "," type ":" string "," value ":" F _ QCSID "
},
{" field ":" F _ HCSID "," label ":" 后抄送 "," type ":" string "," value ":" F _ HCSID "
}
],
其他请求:[
{
“字段”:“限制”,“标签”:“最大行数”,“类型”:“字符串”,“描述”:“最大行数”,“值”:“{PAGINATION_PAGE_SIZE}”
},
{
“字段”:“开始行索引”,“标签”:“开始行索引”,“类型”:“字符串”,“描述”:“开始行索引”,“值”:“{PAGINATION_START_ROW}”
},
{
“字段”:“TopRowCount”,“标签”:“返回总行数”,“类型”:“int”,“描述”:“返回总行数”
},
{
“字段”:“FilterString”,“标签”:“过滤条件”,“类型”:“字符串”,“描述”:“过滤条件”,“值”: “ FModifyDate>='{{LAST_SYNC_TIME|datetime}}' 和 FDocumentStatus='B' 和 F_ora_Combo2='闪迪购货申请单' 和 F_ora_CheckBox='1' ”
},
{
“字段”: “FieldKeys”, “标签”: “需查询的字段key集合”, “类型”: “数组”, “描述”: “需查询的字段key集合”, “解析器”: {“名称”: “ArrayToString”, “参数”: “,”}
},
{
“字段”: “FormId”, “标签”: “业务对象表单Id”, “类型”: “字符串”, “描述”: “业务对象表单Id”, “值”: “PUR_Requisition”
}
],
自动填充响应:true
}
请求示例
根据上述元数据配置,我们可以构建一个请求示例:
{
"_apiMethodName": "/k3cloud/PUR_Requisition/executeBillQuery/",
"_apiMethodType": "/POST/",
"_apiRequestData":{
"_FormId":"",
"_FieldKeys":"",
"_FilterString":"",
"_Limit":"",
"_StartRow":"",
"_TopRowCount":"",
"_autoFillResponse":"",
"_otherRequest":[]
}
}
数据清洗与转换
在获取到原始数据后,需要对其进行清洗和转换,以便后续的数据处理和写入。以下是一些常见的数据清洗和转换操作:
- 字段映射:将源系统中的字段映射到目标系统中的对应字段。例如,将
FBillNo
映射为目标系统中的OrderNumber
。 - 数据格式转换:将日期格式从源系统的格式转换为目标系统所需的格式。
- 数据过滤:根据业务需求过滤掉不需要的数据。例如,只保留状态为
B
的记录。
实践案例
假设我们需要将金蝶云星空中的采购申请单数据集成到钉钉中,具体步骤如下:
-
调用接口获取数据:
import requests url = 'https://your-k3cloud-url/k3cloud/PUR_Requisition/executeBillQuery/' headers = {'Content-Type': 'application/json'} payload = { 'FormId': 'PUR_Requisition', 'FieldKeys': 'FBillNo,FApplicationDate,FNote', 'FilterString': 'FModifyDate>=\'2023-01-01\' and FDocumentStatus=\'B\'', 'Limit': '100', 'StartRow': '0' } response = requests.post(url, json=payload, headers=headers) data = response.json()
-
清洗与转换数据:
cleaned_data = [] for record in data['Result']['Response']['Data']: cleaned_record = { 'OrderNumber': record['FBillNo'], 'ApplicationDate': record['FApplicationDate'], 'Note': record['FNote'] } cleaned_data.append(cleaned_record)
-
写入钉钉:
dingding_url = 'https://your-dingding-url/api/v1/orders' for record in cleaned_data: response = requests.post(dingding_url, json=record, headers=headers) if response.status_code != 200: print(f'Failed to write record: {record}')
通过以上步骤,我们实现了从金蝶云星空获取采购申请单数据,并将其清洗、转换后写入钉钉。这只是一个简单的示例,实际项目中可能需要更复杂的数据处理逻辑和错误处理机制。
使用轻易云数据集成平台实现金蝶采购申请单到钉钉API接口的数据转换与写入
在数据集成生命周期的第二步,我们需要将已经从源平台(金蝶)获取的数据进行ETL(提取、转换、加载)处理,最终写入目标平台(钉钉)的API接口。在这个过程中,我们将详细探讨如何利用轻易云数据集成平台的元数据配置,将金蝶采购申请单的数据转换为钉钉API接口所能接收的格式,并最终写入钉钉。
1. 钉钉API接口配置
根据提供的元数据配置,我们需要将数据写入到钉钉的topapi/processinstance/create
接口。该接口用于创建审批实例,具体的请求方法为POST。以下是关键字段及其描述:
process_code
: 在审批流程编辑页面的URL网址中获取。originator_user_id
: 审批实例发起人的userid。dept_id
: 发起人所在的部门,如果发起人属于根部门,传-1。form_component_values
: 表单组件值,包含多个子字段。
2. 数据提取与清洗
首先,从金蝶系统中提取相关数据。假设我们已经通过轻易云平台完成了数据请求与清洗阶段,获取了以下字段:
{
"FCreatorId": "1001",
"F_ora_Base1": "2001",
"FBillNo": "PO20231001",
"F_ora_DDSQSY": "办公用品采购",
"FApplicationDate": "2023-10-01",
"FApplicationOrgId": "3001",
"FCurrencyId": "CNY",
"FApplicationDeptId": "4001",
"FNote": "",
"FSUPPLIERID1": "5001",
"F_ora_Combo1": "单位A",
"F_ora_KCSLWP": "100",
"F_ora_BCGMSLWP": "50",
"F_ora_XDHZSLWP": "150",
"F_ora_BCGMJEWY": "5000",
"list": [
{
"FMaterialId": "物料A",
"FReqQty": "10",
"FTAXPRICE": "100",
"FReqAmount": "1000"
},
{
"FMaterialId": "物料B",
"FReqQty": "20",
"FTAXPRICE": "200",
"FReqAmount": "4000"
}
],
"_findCollection find FStaffNumber from c51d3596-d760-3e28-968b-cd6cabbdfffb where FID={F_ora_Base1}":"12345"
}
3. 数据转换
根据元数据配置,将上述提取的数据转换为钉钉API所需的格式:
{
"_findCollection find FStaffNumber from c51d3596-d760-3e28-968b-cd6cabbdfffb where FID={F_ora_Base1}":"12345"
}
转换后的请求体如下:
{
{
"_findCollection find FStaffNumber from c51d3596-d760-3e28-968b-cd6cabbdfffb where FID={F_ora_Base1}":"12345"
}
}
示例代码
以下是一个示例代码片段,用于将上述转换后的数据通过POST请求发送到钉钉API接口:
import requests
import json
url = 'https://oapi.dingtalk.com/topapi/processinstance/create'
headers = {'Content-Type': 'application/json'}
data = {
"_findCollection find FStaffNumber from c51d3596-d760-3e28-968b-cd6cabbdfffb where FID={F_ora_Base1}":"12345"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
通过以上步骤,我们成功地将金蝶采购申请单的数据转换并写入到了钉钉API接口,实现了不同系统间的数据无缝对接。这一过程充分利用了轻易云数据集成平台的强大功能,使得整个ETL过程高效、透明且可视化。