案例分享:金蝶云星空数据集成到吉客云
在企业信息系统之间实现高效、无缝的数据对接是业务顺利运作的关键之一。在此次案例中,我们将详细探讨如何利用轻易云数据集成平台,将金蝶云星空的物料数据成功集成到吉客云货品,实现跨系统间的数据同步和共享。为了确保整个过程中的数据完整性与准确性,多个技术细节需要精准把控。
金蝶云星空API调用与初步处理
我们首先通过调用金蝶云星空提供的executeBillQuery
接口,来获取最新的物料信息。这个步骤至关重要,因为它直接决定了传递给吉客云的数据源质量。考虑到API响应可能会涉及分页和限流问题,通过优化查询和接口请求策略,有效解决了潜在障碍:
def fetch_material_data():
# 调用金蝶云星空 executeBillQuery API 获取物料数据
response = requests.post("https://api.kingdee.com/executeBillQuery", data=query_params)
if response.status_code == 200:
material_data = response.json()
handle_pagination(material_data['total_pages'])
数据格式转换及映射
由于金蝶云和吉客云的数据格式存在天然差异,需要进行相应的映射转换。这一步不仅仅是简单字段对应,更要保证各个领域值的一致性。例如,将金蝶中的“物料代码”转化为吉客相应字段并保持逻辑一致。
def transform_material_to_goods(material_data):
goods_data = []
for item in material_data:
transformed_item = {
"sku": item["materialCode"],
"name": item["materialName"],
...
}
goods_data.append(transformed_item)
return goods_data
批量写入与异常处理机制
为了实现大量数据快速而可靠地写入吉客,我们通过批量导入的方法使用erp.goods.skuimportbatch
API。同时,针对可能出现的网络或服务异常,引入错误重试机制,并记录日志以便后续监控分析。
def import_to_jike(goods_data):
try:
response = requests.post("https://api.jike.com/erp.goods.skuimportbatch", json=goods_data)
if response.status_code != 200:
raise Exception("Failed to import data")
except Exception as e:
log_error(e)
retry_import(goods.data)
以上步骤展示了从接口获取、数据转换,到最终上传的一系列操作,以及关键节点上的技术难点及其解决方案。在下文中将进一步详述每一个环节所采用的方法论及实践经验,包括实时
调用源系统金蝶云星空接口executeBillQuery获取并加工数据
在数据集成的生命周期中,调用源系统接口获取数据是至关重要的一步。本文将详细探讨如何通过轻易云数据集成平台调用金蝶云星空的executeBillQuery
接口,获取物料信息并进行初步加工。
接口配置与请求参数
首先,我们需要配置调用金蝶云星空接口的元数据。根据提供的元数据配置,可以看到我们需要使用POST方法来调用executeBillQuery
接口,并传递一系列请求参数。
{
"api": "executeBillQuery",
"method": "POST",
"number": "FNumber",
"id": "FMATERIALID",
"pagination": {
"pageSize": 100
},
"idCheck": true,
"request": [
{"field":"FMATERIALID","label":"实体主键","type":"string","value":"FMATERIALID"},
{"field":"FNumber","label":"编码","type":"string","value":"FNumber"},
{"field":"FName","label":"名称","type":"string","value":"FName"},
{"field":"FSpecification","label":"规格型号","type":"string","value":"FSpecification"},
{"field":"FOldNumber","label":"旧物料编码","type":"string","value":"FOldNumber"},
{"field":"FBARCODE","label":"条码","type":"string","value":"FBARCODE"},
{"field":"FDescription","label":"描述","type":"string","value":"FDescription"},
{"field":"FMaterialGroup_FNumber","label":"物料分组","type":"string","value":"FMaterialGroup.FNumber"},
{"field":"FErpClsID","label":"物料属性","type":"string","value":"FErpClsID"},
{"field":"FDocumentStatus","label":"数据状态","type":"string","value":"FDocumentStatus"},
{"field":"FForbidStatus","label":"禁用状态","type":"string","value":"FForbidStatus"},
{"field":...}
],
"otherRequest": [
{"field": "Limit", "label": "最大行数", "type": "string", "describe": "金蝶的查询分页参数", "value": "{PAGINATION_PAGE_SIZE}"},
{"field": "StartRow", "label": "开始行索引", "type": "string", "describe": "金蝶的查询分页参数", "value": "{PAGINATION_START_ROW}"},
{"field":...}
]
}
请求示例
为了更好地理解如何调用该接口,以下是一个具体的请求示例:
{
"FormId": "BD_MATERIAL",
"FieldKeys": [
"FMATERIALID",
"FNumber",
...
],
"FilterString": "( FUseOrgId.fnumber='103' and FAPPROVEDATE>='2023-01-01')",
...
}
在这个请求中,我们指定了表单ID为BD_MATERIAL
,并通过FieldKeys
字段列出了需要查询的字段。此外,通过FilterString
字段设置了过滤条件,以确保只获取符合条件的数据。
数据清洗与转换
获取到原始数据后,需要对其进行清洗和转换。以下是一些常见的数据清洗与转换操作:
- 字段映射:将源系统中的字段映射到目标系统中的相应字段。例如,将金蝶云星空中的
FMATERIALID
映射到目标系统中的MaterialID
。 - 数据格式转换:将日期、数值等字段转换为目标系统所需的格式。例如,将日期格式从
YYYY-MM-DD
转换为目标系统所需的格式。 - 数据过滤:剔除不符合业务规则的数据。例如,过滤掉禁用状态(
FForbidStatus = 'B'
)的物料。
示例代码
以下是一个示例代码片段,用于展示如何在轻易云平台上实现上述操作:
import requests
import json
# 定义API URL和请求头
url = 'https://api.kingdee.com/executeBillQuery'
headers = {'Content-Type': 'application/json'}
# 定义请求体
payload = {
'FormId': 'BD_MATERIAL',
'FieldKeys': 'FMATERIALID,FNumber,FName,FSpecification,FOldNumber,FBARCODE,FDescription,...',
'FilterString': "( FUseOrgId.fnumber='103' and FAPPROVEDATE>='2023-01-01')",
'Limit': '100',
'StartRow': '0'
}
# 发起POST请求
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查响应状态码
if response.status_code == 200:
data = response.json()
# 数据清洗与转换
cleaned_data = []
for item in data:
cleaned_item = {
'MaterialID': item['FMATERIALID'],
'Code': item['FNumber'],
...
}
cleaned_data.append(cleaned_item)
# 输出清洗后的数据
print(cleaned_data)
else:
print(f"Error: {response.status_code}")
通过上述步骤,我们成功地调用了金蝶云星空的接口获取物料信息,并对其进行了初步加工,为后续的数据写入和进一步处理奠定了基础。
使用轻易云数据集成平台进行ETL转换并写入吉客云API接口
在数据集成的生命周期中,第二步是将已经集成的源平台数据进行ETL(Extract, Transform, Load)转换,并最终写入目标平台。在本案例中,我们将金蝶云星空物料的数据转换为吉客云货品的格式,并通过吉客云API接口进行写入。以下是详细的技术实现过程。
1. 数据提取与清洗
首先,我们从金蝶云星空提取物料数据。假设我们已经完成了数据请求与清洗阶段,获得了如下结构的原始数据:
{
"FName": "物料A",
"FNumber": "001",
"FPurchaseUnitId_FName": "个",
"F_ora_Assistant4_FDataValue": "电子产品",
"FExpPeriod": "12",
"FExpUnit": "月",
"FIsBatchManage": "1",
"FIsKFPeriod": "1"
}
2. 数据转换
在数据转换阶段,我们需要根据吉客云API接口要求,将上述数据转换为目标格式。吉客云API erp.goods.skuimportbatch
接口要求的数据结构如下:
{
"goodsName": "{FName}",
"goodsNo": "{FNumber}",
"goodsAlias": "{FName}",
"unitName": "{FPurchaseUnitId_FName}",
"outSkuCode": "{FNumber}",
"skuBarcode": "{FNumber}",
"skuName": "默认规格",
"cateCode": "_findCollection find cateCode from collection_id where cateName={F_ora_Assistant4_FDataValue}",
"cateName": "{F_ora_Assistant4_FDataValue}",
"shelfLife": "{FExpPeriod}",
"shelfLiftUnit": "{FExpUnit}",
"isBatchManagement": "{FIsBatchManage}",
"isPeriodManage": "{FIsKFPeriod}",
"isSerialManagement": "",
"goodsAttr": "1",
"ownerCode": "103"
}
具体的字段映射关系如下:
goodsName
映射到FName
goodsNo
映射到FNumber
goodsAlias
映射到FName
unitName
映射到FPurchaseUnitId_FName
outSkuCode
映射到FNumber
skuBarcode
映射到FNumber
skuName
固定值为"默认规格"
cateCode
映射并查找分类编号cateName
映射到F_ora_Assistant4_FDataValue
shelfLife
映射到FExpPeriod
shelfLiftUnit
映射到FExpUnit
isBatchManagement
映射到FIsBatchManage
isPeriodManage
映射到FIsKFPeriod
isSerialManagement
留空goodsAttr
固定值为"1"
ownerCode
固定值为"103"
3. 元数据配置
根据上述映射关系,我们在轻易云数据集成平台上进行元数据配置:
{
"api":"erp.goods.skuimportbatch",
"method":"POST",
"idCheck":true,
"request":[
{"field":"goodsName","label":"货品名称","type":"string","value":"{FName}"},
{"field":"goodsNo","label":"货品编码","type":"string","value":"{FNumber}"},
{"field":"goodsAlias","label":"货品别名","type":"string","value":"{FName}"},
{"field":"unitName","label":"单位名称","type":"string","value":"{FPurchaseUnitId_FName}"},
{"field":"outSkuCode","label":"SKU","type":"string","value":"{FNumber}"},
{"field":"skuBarcode","label":"条码","type":"string","value":"{FNumber}"},
{"field":"skuName","label":"规格名称","type":"string","value":"默认规格"},
{
"field":"cateCode",
"label":"货品分类码",
"type":"string",
"_findCollection find cateCode from collection_id where cateName={F_ora_Assistant4_FDataValue}"
},
{"field":"cateName","label":"货品的分类名称","type":"string","value":"{F_ora_Assistant4_FDataValue}"},
{"field":"shelfLife","label":"保质期","type":"string","value":"{FExpPeriod}"},
{"field":"shelfLiftUnit","label":"质保期的单位","type":"string","value":"{FExpUnit}"},
{"field":"isBatchManagement","label":"是否批次管理","type":"string","value\":\"{ FIsBatchManage }\"},
{"field\":\"isPeriodManage\",\"label\":\"有效期管理\",\"type\":\"string\",\"value\":\"{ FIsKFPeriod }\"},
{\" field \ ": \" isSerialManagement \ ", \" label \ ": \" 是否序列号管理 \ ", \" type \ ": \" string \ ", \" describe \ ": \" 是否序列号管理(1=是,0= 否)\"},
{\" field \ ": \" goodsAttr \ ", \" label \ ": \"货品属性\", \" type \ ": \" string\", \" describe \ ": \"货品属性1 - 成品2 - 半成品3 - 原料4 - 包装材料\", \" value\": \"1\"},
{\" field\": \" ownerCode\", \" label\": \"货主编码\", \" type\": \" string\", \" describe\": \"货品属性1 - 成品2 - 半成品3 - 原料4 - 包装材料\", \" value\": \"103\"}
]
}
4. 数据加载
最后一步是将转换后的数据通过吉客云API接口写入目标平台。我们使用HTTP POST方法调用API,并传递经过ETL转换后的JSON对象。
POST /erp.goods.skuimportbatch HTTP/1.1
Host: api.jikecloud.com
Content-Type: application/json
{
...
}
通过这种方式,我们可以确保从金蝶云星空提取的数据经过清洗和转换后,准确无误地写入吉客云,实现不同系统间的数据无缝对接。这种方法不仅提高了数据处理效率,还保证了业务流程的透明度和可追溯性。