Qeasy Cloud
Get Started

Feishu Account Deduction Fees to MySQL Sync: A Practical Qeasy Strategy Guide

· 谢锴斌· Integration Solutions· 18 views· 5 min read

What This Strategy Solves

A retail enterprise records e-commerce channel account deduction fees in a Feishu spreadsheet, and the finance team needs to aggregate these fees by store and by month in a self-built MySQL data warehouse. On the surface, it looks like just pulling a table over, but in practice, you notice that Feishu spreadsheets are collaboration tools: row numbers drift with inserts and deletes, store codes appear in both old and new forms across different months, and if the differences between two daily pulls at the start and end of the month are not handled, the account deduction figures keep drifting away from reality. This strategy aims to use a single configuration to land the Feishu account deduction fee table stably into MySQL, so that the numbers the finance team sees each morning match what is recorded in Feishu.

Data Flow and Field Mapping

The data flow is straightforward: Feishu spreadsheet → Qeasy middleware → MySQL single table tp_fs_账扣费用. There is no header-detail separation on the source side; one row equals one account deduction fee record. The target side adopts flat single-table storage without master-detail splitting. This determines that the overall shape of the strategy is "lightweight, batch-oriented, and backed by scheduling."

Key field mapping table:

Source Field (Feishu)Target Field (MySQL)Mapping TypeConversion RuleBusiness Meaning
ididDIRECTTake the row numberPrimary key, used for upsert deduplication
电商渠道类型电商渠道类型DIRECTOriginal valueChannel category, used for aggregation by channel
店铺编码店铺编码DIRECTOriginal valueLinks to store master data
店铺名称店铺名称DIRECTOriginal valueDisplay name
经营分析店铺名称经营分析店铺名称DIRECTOriginal valueAnalytical dimension, may differ from store name
月份月份DIRECTOriginal string, e.g. "2024-01"Monthly aggregation
账扣费用账扣费用DIRECTOriginal floating pointAmount
日期日期DIRECTOriginal valueFee occurrence/entry date

All fields are DIRECT mappings without formula conversion or script logic. This is the typical hallmark of a "light strategy" — the thinner the mapping, the lower the long-term maintenance cost.

How to Configure on Qeasy

When configuring this strategy on Qeasy Data Integration Platform, the core is to complete three things: source read rules, target write rules, and the schedule.

Source (Feishu) configuration points:

  • Choose platform code FeiShu, interface type WebAPI, method GET, API path /open-apis/sheets/v2/spreadsheets/:spreadsheetToken/values/:range.
  • In the request parameters, fix valueRenderOption to ToString and dateTimeRenderOption to FormattedString. If these are not set, Feishu returns formula values and dates as serial numbers, which will misread the account deduction fee fields.
  • headers_line=1, telling the platform explicitly that the first row is the header and data parsing starts from the second row.
  • Configure the primary key field as id, i.e. the row number, but be aware that Feishu row numbers shift after row deletions, so the actual deduplication logic must be enforced on the MySQL side.

Target (MySQL) configuration points:

  • Choose platform code MySQL, interface type SQL, effect EXECUTE.
  • Choose REPLACE INTO for the write mode, implementing upsert by id. Do not use INSERT IGNORE or INSERT. A subtle point: when using REPLACE INTO, if a record with the same id already exists in the target table, it will be deleted first and then inserted, causing auto-increment primary key shifts. If you do not want to touch auto-increment IDs, a safer approach is to use INSERT ... ON DUPLICATE KEY UPDATE.
  • Set idCheck=true so the platform validates primary key existence before writing, avoiding silent data loss.
  • Single-batch write volume limit=200. Feishu tables easily run to thousands of rows and must be batched. If the batch is too large, the MySQL single transaction becomes long and easily locks tables.

Schedule configuration: source cron 0 1 * * *, target cron 30 1 * * *, with the two ends offset by 30 minutes. This step is often overlooked at many customer sites, resulting in the two ends running in the same minute, so the target starts writing before the source finishes pulling, leading to "upsert while still reading," and a difference of dozens of records when reconciling at month-end.

Implementation Steps

Implement in three phases. After a few pitfalls, we recommend all customers follow this sequence.

Phase 1: Full initialization. First, run a full sync to land all historical account deduction fees from the Feishu table into MySQL. This can be done on Qeasy using "manual trigger + full mode" once, with the goal of giving the target table a clean initial state. The full trigger is usually scheduled for the early morning of the first day of the month, avoiding the finance closing window.

Phase 2: Set the incremental starting point. After the full run completes, set the source "incremental starting point" to the maximum date or latest row id that has already been synced, and the daily scheduled task will only pull new/changed rows from then on. The Qeasy platform typically uses the "last successful timestamp" or "last maximum primary key" as the incremental starting point, depending on the stability of the source fields. Feishu id is a row number that rearranges after deletions, so a safer approach is to use a combination of date + store code for business deduplication, rather than trusting id alone.

Phase 3: Schedule frequency and monitoring. Pull source at 1:00 AM and write target at 1:30 AM daily. Once stable, hook up monitoring and alerts: if the daily write count is 0 or fluctuates abnormally, trigger a notification. A common Qeasy customer practice is to feed this strategy into the finance dashboard, producing a "yesterday's sync count vs. daily average" comparison before 8:00 AM each morning, so anomalies are visible at a glance.

Pitfall Review

  1. Misconfigured header row count on the source. The first row of a Feishu table is not always the header; some customers insert a row of explanatory text. If you directly set headers_line=1, the field names will be read as things like "Description" or "2024 Summary," breaking all subsequent mappings. The safe approach is to run a "preview" on Qeasy first, confirm the header field names, and then save the configuration.

  2. Primary key drift caused by REPLACE INTO. A typical mistake is treating REPLACE INTO as a universal upsert. It DELETEs first and then INSERTs, causing auto-increment primary key gaps and breaking foreign keys in related tables. The handling is described in the configuration section above: switch to INSERT ... ON DUPLICATE KEY UPDATE.

  3. Offset scheduling overwritten by default settings. When customers create a new strategy on Qeasy, if they directly reuse the template, the source and target crons default to the same time point, leading to "target starts writing before the source pull completes." Always manually offset by at least 20-30 minutes.

  4. id rearrangement caused by Feishu row deletions. When finance deletes a row in the Feishu table, the id of row 50 immediately becomes 49, and if the incremental logic only watches id, rows will be missed. This is a point repeatedly emphasized in "centralized encoding mapping management": collaboration tools like Feishu are not suitable as master data sources, and true deduplication must rely on business keys (store code + date).

  5. MySQL table locks caused by oversized batch writes. Writing thousands of account deduction fee rows at once keeps a single transaction open for too long, blocking queries on the business side. limit=200 is an empirical value that can be adjusted according to the target table's indexing, but do not blindly push it above 1000.

Applicable and Non-Applicable Scenarios

Applicable: the source is a collaboration tool like a Feishu spreadsheet, and the target is a single-table financial/expense/ledger dataset with few fields, a flat structure, and no complex transformation. It suits the standardized landing of a "light strategy + offset schedule." Non-applicable: when the target requires a master-detail table structure, fields need formula conversion or multi-source merging, or strong real-time (minute-level) sync is required. In those cases, you should use a master-data-style strategy or an event-driven pipeline rather than this daily batch configuration.

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/solutions/strat-mysql-feishu-1122-mysql-657b5d39

Comments