轻易云平台如何实现ETL数据转换及马帮API写入

  • 轻易云集成顾问-何语琴

金蝶云星空数据集成到马帮的技术案例分享

在企业日常运营中,库存管理效率和准确性至关重要。为了实现这一目标,我们将金蝶云星空系统中的“其他入库单”无缝集成到马帮系统,通过定制化的数据对接方案,实现手工入库单的高效处理。本次技术案例即聚焦于如何利用轻易云数据集成平台,完成这种跨系统的数据同步。

确保不漏单的关键技术措施

在本案例中,为了确保金蝶云星空入库数据不漏单,在设计初期便引入了一系列可靠的抓取机制。我们采用的是调用金蝶云星空API executeBillQuery 方法进行接口数据抓取,并结合定时任务保证了获取过程中的稳定性和一致性。同时,为应对分页和限流问题,特别设置了分段查询策略,以避免大批量请求导致接口压力过大或超时。

数据快速写入与格式转换

针对从金蝶云星空抓取的大量库存信息,需要快速且精确地写入到马帮系统。这一步使用的是调用马帮API warehouse-do-add-storage-in 接口。在实际操作中,由于两套系统的数据格式存在一定差异,我们采取自定义字段映射规则,对原始数据进行预处理,确保其符合目标格式要求。

异常处理及重试机制

为保障整个数据传输过程的顺利进行,还设置了一整套异常处理与错误重试机制。当遇到网络波动、接口超时或其它意外情况导致的数据传输失败时,可通过自动重试功能重新发起请求,从而最大程度降低因偶发故障带来的影响。此外,每个环节均配置详细日志记录,可实时监控并追溯问题根源,提高后续维护效率。

通过这些核心技术措施,本实施方案不仅成功实现了从金蝶云星空到马帮间的数据流畅转移,同时也保证了数据的全部生命周期透明可视。在下文,将进一步介绍各具体步骤及代码示例,以供参考实践。 如何开发用友BIP接口

调用金蝶云星空接口executeBillQuery获取并加工数据

在数据集成的生命周期中,调用源系统接口获取数据是至关重要的一步。本文将详细探讨如何通过轻易云数据集成平台调用金蝶云星空的executeBillQuery接口来获取并加工数据。

接口配置与调用

首先,我们需要配置接口的元数据。以下是针对executeBillQuery接口的元数据配置:

{
  "api": "executeBillQuery",
  "effect": "QUERY",
  "method": "POST",
  "number": "FBillNo",
  "id": "FEntity_FEntryID",
  "idCheck": true,
  "request": [
    {"field":"FEntity_FEntryID","label":"FEntity_FEntryID","type":"string","describe":"111","value":"FEntity_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","label":"FBillTypeID","type":"string","describe":"111","value":"FBillTypeID"},
    {"field":"FSUPPLIERID_FNumber","label":"FSUPPLIERID_FNumber","type":"string","describe":"111","value":"FSUPPLIERID.FNumber"},
    {"field":"FNOTE","label":"FNOTE","type":"string","describe":"111","value":"FNOTE"},
    {"field": "FMATERIALID_FNumber", "label": "FMATERIALID_FNumber", "type": "string", "describe": "111", "value": "FMATERIALID.FNumber"},
    {"field": "FSTOCKID_FNumber", "label": "FSTOCKID", "type": "string", "describe": "111", "value": "FSTOCKID.FNumber"},
    {"field": "FQty", "label": "FQty", "type": "string", "describe": "111", "value": "FQty"},
    {"field": "FPrice", "label": "FPrice", "type": "string", "describe": 111, value: FPrice},
    {"field": FAmount, label: FAmount, type: string, describe: 111, value: FAmount},
    {"field" : FBOMID, label : FBOMID, type : string, describe : 111, value : FBOMID},
    {"field" : FPRODUCEDATE, label : FPRODUCEDATE, type : string, describe : 111, value : FPRODUCEDATE},
    {"field" : FEXPIRYDATE, label : FEXPIRYDATE, type : string, describe : 111, value : FEXPIRYDATE},
    {"field" : FMTONO, label : FMTONO, type : string, describe : 111, value : FMTONO},
    {"field" : FProjectNo, label: FProjectNo,type:string , describe: 111,value:FProjectNo},
    {"field" :"FSTOCKSTATUSID" , label:"FSTOCKSTATUSID" , type:"string" , describe:"111" , value:"FSOTCKSTATUSD"} ,
    {" field ":"FOwnerId "," label ":"FOwnerId "," type ":" string "," describe ":" 11 "," value ":"FOwnerId"} ,
    {" field ":" STOCKFLAG "," label ":" STOCKFLAG "," type ":" string "," describe ":" 11 "," value ":" STOCKFLAG "} ,
    {" field ":" JoinQty "," label ":" JoinQty "," type ":" string "," describe ":" 11 "," value ":" JoinQty "} ,
    {" field ": Expperiod," label ": Expperiod," type ": string," describe ": 11," value ": Expperiod} ,
    {" field ": ExpUnit," label ": ExpUnit," type ": string," describe ": 11," value ": ExpUnit} ,
    {" field ": FSRCBILLTYPEID," label ": FSRCBILLTYPEID," type ": string," describe ": 11," value ": FSRCBILLTYPEID} ,
    {" field ": FSRCBILLNO," label ": FSRCBILLNO," type ": string," describe ": 11," value ": FSRCBILLNO} ,
    {" field ": FLot ," label ": FLot ," type ": string ," describe ": 11 ," value ": FLot } ,
    {" field ":" EntryNote "," label ":" EntryNote "," type ":" string "," describe ":" EntryNote "} ,
    {" field :" StockLocId ," label :" StockLocId ," type :" StockLocId ," description :" StockLocId "} ,
    {" field :"FCMKBarCode ", Label :"FCMKBarCode ", Type :" String ", Description :"FCMKBarCode ", Value :"FCMKBarCode "} ,
    {" FieldName :", LabelName :", TypeName :", DescriptionName :", ValueName :", ValueName :", ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueName :, ValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue}
],

请求参数解析

在请求参数中,我们需要特别关注以下几个字段:

  • FormId: 必须填写金蝶的表单 ID,例如 STK_MISCELLANEOUS
  • FieldKeys: 用于指定查询返回的字段列表,格式为数组。
  • FilterString: 用于设置查询条件,例如 FSupplierId.FNumber = 'VEN00010' and FApproveDate>= '2023-01-01'
  • Limit, StartRow, TopRowCount: 用于分页查询。

以下是一个示例请求体:

{
   FormId: STK_MISCELLANEOUS,
   FieldKeys: ["FID", “FBillNo”, “FMATERIAL_ID”],
   FilterString: “FSupplierId.FNumber = 'VEN00010' and FApproveDate>= '2023-01-01'”,
   Limit: “100”,
   StartRow: “0”
}

数据清洗与转换

在获取到原始数据后,我们需要对其进行清洗和转换。以下是一些常见的数据清洗和转换操作:

  1. 字段映射:将金蝶系统中的字段映射到目标系统中的字段。例如,将 FMATERIAL_ID 映射为目标系统中的 MaterialCode
  2. 数据类型转换:将字符串类型的数据转换为日期、数值等其他类型。例如,将 2023-01-01 转换为日期类型。
  3. 数据过滤:根据业务需求过滤掉不需要的数据。例如,只保留状态为“已审核”的记录。

实际案例

假设我们需要从金蝶云星空中获取所有状态为“已审核”的入库单,并将其导入到马帮手工入库单中。具体步骤如下:

  1. 配置请求参数

    {
      FormId: STK_MISCELLANEOUS,
      FieldKeys: ["FID", “FBillNo”, “FMATERIAL_ID”, “FAmount”],
      FilterString: “FDocumentStatus = 'C'”,
      Limit: “100”,
      StartRow: “0”
    }
  2. 发送请求: 使用轻易云平台提供的 POST 方法发送请求,并接收响应。

  3. 处理响应数据: 对响应数据进行清洗和转换,例如将金额字段从字符串转换为数值类型。

  4. 写入目标系统: 将处理后的数据写入马帮手工入库单中,确保每个字段都正确映射。

通过上述步骤,我们可以高效地实现从金蝶云星空到马帮手工入库单的数据集成。这不仅提高了业务透明度和效率,还确保了数据的一致性和准确性。 金蝶与WMS系统接口开发配置

使用轻易云数据集成平台进行ETL转换与写入马帮API接口

在数据集成生命周期的第二步,我们需要将已经集成的源平台数据进行ETL(Extract, Transform, Load)转换,并最终写入目标平台——马帮API接口。以下是一个详细的技术案例,展示如何利用轻易云数据集成平台完成这一过程。

元数据配置解析

我们使用的元数据配置如下:

{
  "api": "warehouse-do-add-storage-in",
  "effect": "EXECUTE",
  "method": "POST",
  "idCheck": true,
  "operation": {
    "method": "merge",
    "field": "FBillNo",
    "bodyName": "goods_list",
    "header": ["FBillNo", "FNOTE", "FSTOCKID_FNumber"],
    "body": ["FMATERIALID_FNumber", "FQty"]
  },
  "request": [
    {
      "field": "warehouseName",
      "label": "仓库名称",
      "type": "string",
      "value": "_findCollection find name from edd9129b-4566-36f5-b5f0-84e12a4414fd where finance_code={FSTOCKID_FNumber}"
    },
    {
      "field": "employeeName",
      "label": "员工名称",
      "type": "string",
      "value": "金蝶单据同步"
    },
    {
      "field": "remark",
      "label": "备注",
      "type": "string",
      "value": "{FNOTE}"
    },
    {
      "field": "data",
      "label": "出库商品",
      "type": "array",
      "value": "goods_list",
      ...

数据转换与写入过程

  1. 提取数据: 从源系统(金蝶)中提取需要的数据,包括单据编号(FBillNo)、备注(FNOTE)、库存编号(FSTOCKID_FNumber)以及商品明细列表(goods_list)。

  2. 转换数据: 根据目标平台马帮API接口的要求,对提取的数据进行转换。具体步骤如下:

    • 仓库名称:通过_findCollection函数从指定集合中查找仓库名称,依据finance_code匹配FSTOCKID_FNumber
    • 员工名称:固定值“金蝶单据同步”。
    • 备注:直接映射源系统中的FNOTE字段。
    • 出库商品:将商品明细列表中的字段映射为目标系统所需格式,包括库存SKU(stockSku)和数量(quantity)。
  3. 构建请求体: 根据元数据配置,构建符合马帮API接口要求的请求体。示例如下:

{
  ...
  {
    field: 'warehouseName',
    value: '仓库A'
  },
  {
    field: 'employeeName',
    value: '金蝶单据同步'
  },
  {
    field: 'remark',
    value: '测试备注'
  },
  {
    field: 'data',
    value: [
        {
            stockSku: 'SKU12345',
            quantity: '100'
        },
        ...
     ]
  }
}
  1. 发送请求: 使用HTTP POST方法,将构建好的请求体发送到马帮API接口warehouse-do-add-storage-in
import requests

url = 'https://api.mabang.com/warehouse-do-add-storage-in'
headers = {'Content-Type': 'application/json'}
data = {
  # 构建好的请求体
}

response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
    print("Data successfully written to Mabang")
else:
    print("Failed to write data to Mabang")

注意事项

  • 异步处理:确保在发送请求时,采用异步处理方式,以提高效率和响应速度。
  • 错误处理:对可能出现的错误进行捕获和处理,如网络问题、数据格式不匹配等。
  • 实时监控:利用轻易云平台提供的实时监控功能,跟踪数据流动和处理状态,确保每个环节都透明可控。

通过以上步骤,我们成功地将源平台的数据进行了ETL转换,并写入了目标平台马帮API接口。这一过程不仅提升了业务效率,还保证了数据的一致性和准确性。 打通企业微信数据接口

更多系统对接方案