Qeasy Cloud
Get Started

Refund Inbound Sync in Practice: Incremental Landing from Wangdiantong to MySQL

· 系统管理员· Integration Solutions· 25 views· 3 min read
MySQLWDT退货入库单Incremental Sync轻易云供应链集成

What This Strategy Solves

A retail enterprise needs refund inbound orders from its ERP (Wangdiantong) consolidated into a self-built MySQL as the source for downstream BI and reconciliation. Once a document passes the ERP internal review, it must appear downstream within an 11-minute granularity; otherwise, store inventory and headquarters reconciliation start to drift. We use the Qeasy Data Integration Platform to host this strategy, packaging "incremental retrieval by time window + pagination + phased header/detail loading" into a stable scheduled job.

Data Flow and Field Mapping

Overall flow: Wangdiantong (QUERY) → Qeasy (intermediate layer) → MySQL (EXECUTE). The source is the wdt.stockin.order.query.refund API; the target is two REPLACE INTO statements writing the master table and the detail table.

Key field mapping (excerpt):

DimensionWangdiantong FieldIntermediate SemanticsMySQL Master FieldMySQL Detail Field
Document No.order_noMaster document numberorder_no-
Primary Keystockin_idDocument unique IDstockin_idstockin_id
Warehousewarehouse_no / warehouse_nameWarehouse code and namewarehouse_no / warehouse_name-
Shopshop_no / shop_nameShop code and nameshop_no / shop_name-
Statusstatus / process_statusDocument statusstatus / process_status-
Timecreated_time / stockin_time / modifiedCreate/inbound/update timecreated_time / stockin_time / modifiedmodified / created
Detail PKrec_idDetail row ID-rec_id
Goodsspec_no / goods_no / goods_nameSpec and goods code-spec_no / goods_no / goods_name
Quantity/Amountgoods_count / cost_price / total_costQuantity and cost-goods_count / cost_price / total_cost

Code mapping is where this strategy is most prone to issues. We centralize management in Qeasy: the shop code shop_no, warehouse code warehouse_no, and goods spec spec_no all go into a unified code table; source fields pass through mapping before being written to the database, preventing dirty data from landing directly.

How to Configure on Qeasy

Source configuration: select the wdt.stockin.order.query.refund API, method POST; the incremental parameter start_time uses {{LAST_SYNC_TIME|datetime}}, and end_time uses {{CURRENT_TIME|datetime}}; by default only status=80 completed documents are queried; pagination page_size is controlled by the variable {{PAGINATION_PAGE_SIZE}}, defaulting to 40, range 1~50.

Target configuration: the id field is stockin_id, with idCheck enabled for primary-key deduplication; the master statement uses REPLACE INTO to implement "update if exists, insert if not"; the detail table likewise uses REPLACE INTO, receiving the details_list array via extend_sql_1. buildModel is off, autoFillResponse is on, automatically landing responses into the database.

Scheduling: source */11 * * * *, target 3-59/11 * * * *, staggered by 3 minutes to leave time for retrieval and assembly.

Implementation Steps

  1. Baseline Full Load: Manually run a full load the day before launch, writing all current status=80 documents into MySQL as the reconciliation starting point.
  2. Incremental Start Point: Anchor LAST_SYNC_TIME to the launch time, rolling forward by time window for the first run.
  3. Phased Loading: Write the master table first, then the detail table; any failure rolls back the entire batch to avoid orphan details.
  4. Scheduling Frequency: Pull every 11 minutes; keep a full-compensation task during off-peak hours at night to cover missed pulls.
  5. Reconciliation Mechanism: At 02:00 daily, compare MySQL's modified against the ERP-side update time; differences exceeding a threshold trigger automatic alerts.

Lessons from the Trenches

  1. Don't use database time directly for the time window: Using {{CURRENT_TIME}} as end_time looks stable, but across time zones it produces a "future time" and the source returns empty. The safe approach is to uniformly use the integration platform server time and fix the format as yyyy-MM-dd HH:mm:ss.
  2. Don't omit the status default: A typical mistake is not passing status and expecting everything back, but the API may also bring back "in editing" records. Explicitly querying only 80 gives stronger controllability.
  3. REPLACE is not omnipotent: It relies on a unique primary key; if the source produces two different details under the same stockin_id, they are silently overwritten. Adding a business unique-key check on the detail table is recommended.
  4. Staggered scheduling is non-negotiable: Scheduling source and target at the same minute means that if the source slows down, the target runs empty. A 3-minute stagger is the empirical value.
  5. Bigger pagination is not always better: When pulled to 50, some timeout scenarios lose pages; 40 by default is safer, with automatic retry on failure.

Suitable and Unsuitable Scenarios

Suitable: retail chains with stable refund volume, a need for status filtering, and high reconciliation requirements. Unsuitable: scenarios requiring real-time second-level push, where the source writes back modified at high frequency, or where the detail table exceeds 10,000 rows — for the latter, splitting the detail strategy or switching to a streaming channel is recommended.

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/solutions/strat-mysql-wdt-5427-mysql-ec520e17

Comments