A method for incremental synchronization of financial accounting data across multiple terminals

By coordinating change logs and associated templates of account data between the cloud and the terminal, the problem of missing associated data and version mismatch caused by inconsistent terminal caching is solved, and efficient and reliable incremental synchronization of account data across multiple terminals is achieved.

CN123115273APending Publication Date: 2026-11-17大连账羚羊科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611392410.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-09
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

When the local account cache range and cache version are inconsistent across different terminals, the existing incremental synchronization method is unable to accurately supplement the referenced previous records, which can easily lead to problems such as missing associated data, mismatched associated versions, or excessive transmission.

Method used

The cloud-based accounting database stores authoritative accounting data and change logs arranged in the order of submission. Each terminal sets up a local cache database to store a portion of the accounting data and configures a correlation template for each data type to identify the preceding related records. When generating change logs, the minimum required version of the preceding related records is determined based on the reference field of the correlation template. The missing versions are then determined by combining the local cache version of the target terminal, and the missing records are recursively supplemented to form a closed incremental set of correlations. This set is then written to the local cache database within the same transaction.

Benefits of technology

It enables accurate supplementation of previous associated records when the terminal cache state is inconsistent, avoiding missing associated data and version mismatch, reducing the overhead of irrelevant data transmission and local database writing, and improving the reliability and consistency of incremental synchronization of multi-terminal account data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115273A_ABST
    Figure CN123115273A_ABST
Patent Text Reader

Abstract

This invention relates to the field of cloud database data synchronization technology, and discloses a method for incremental synchronization of financial account data across multiple terminals. The invention stores authoritative account data and change logs in the cloud, records the preceding associated records and minimum required versions actually read by business transactions based on associated templates, and upon receiving a synchronization request from the target terminal, determines the available version by combining the local cached version and the version to be written with the same key, recursively supplements missing records with insufficient versions, forming a closed incremental set of associations, and selects incremental or complete data for each field, setting the write level according to the association order to form an incremental synchronization package. The target terminal writes and verifies within the same transaction, and the cloud updates the confirmed change sequence number after receiving confirmation information. This invention can avoid data inconsistencies caused by missing preceding associated records or insufficient versions, reduce irrelevant data transmission and duplicate writing, and improve the reliability of multi-terminal incremental synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data synchronization technology for cloud databases, and in particular to an incremental synchronization method for financial accounting data across multiple terminals. Background Technology

[0002] Financial management systems typically use a cloud-based accounting database to centrally store basic accounting information, accounting periods, accounting subjects, voucher headers, voucher details, and voucher attachments, while setting up a local cache database on computers, tablets, or mobile terminals to improve the response speed for voucher queries, document entry, and offline browsing. Each terminal generally retrieves newly added, modified, or deleted accounting records since the last confirmed position from the cloud by saving the cloud change sequence number, update time, or data version, and writes the retrieved incremental data to the local cache database.

[0003] However, the local cache range of different terminals is usually inconsistent due to factors such as accounting period, operation permissions, business tasks, cache clearing or terminal reconstruction. A voucher detail, voucher attachment or modification record directly issued by the cloud may reference previous records such as voucher header, accounting subject, and accounting period that are not cached or are outdated on the target terminal, resulting in problems such as missing reference records, mismatched reference versions, or incomplete local account set data association after the terminal writes the data. Even if the target terminal has cached the relevant previous records, if the local cache version is lower than the version that the cloud business transaction relies on, the data may still form an inconsistent association state with the cloud after writing the data.

[0004] Existing processing methods typically include re-downloading the entire data when the terminal cache is incomplete, preloading according to a fixed association type, or repeatedly sending data according to the cloud change order without distinguishing the terminal cache state. Re-downloading the entire data will result in a large amount of irrelevant data transmission and local write overhead. Preloading according to a fixed type and repeatedly sending data according to the change order cannot dynamically determine the association data that actually needs to be supplemented in this synchronization based on the local cache state of the target terminal at the time of synchronization, which can easily lead to missing association data or excessive transmission. Summary of the Invention

[0005] The technical problem to be solved by this invention is: how to solve the problem that existing incremental synchronization methods are difficult to accurately supplement the referenced previous records when the local account set cache range and cache version are inconsistent across different terminals, which can easily lead to missing related data, mismatched related versions, or excessive transmission. To this end, an incremental synchronization method for financial account set data across multiple terminals is proposed.

[0006] To achieve the above objectives, this application adopts the following technical solution: a method for incremental synchronization of multi-terminal financial accounting data, comprising: S1. The cloud-based accounting database stores authoritative accounting data and change logs arranged in the order of submission. Each terminal sets up a local cache database to store a portion of the accounting data and configures association templates for each data type to identify the preceding associated records. S2. Receive the synchronization request sent by the target terminal, which carries the terminal identifier, account identifier, confirmed change sequence number and cache generation, and obtain the direct incremental record from the change log based on the confirmed change sequence number. S3. When generating change logs, determine the preceding associated record based on the reference field of the associated template, record the version when the business transaction reads the record as the minimum required version, and record its record key and minimum required version; obtain the local cache version of the direct incremental record and its preceding associated record on the target terminal. S4. Take the higher of the local cache version of the previous associated record and the version to be written with the same key in the record to be synchronized as the available version. If it is not cached or not included, the corresponding version is considered to be lower than any valid version. If the available version is lower than the minimum required version, the corresponding previous associated record is identified as a missing record. Obtain the missing record with a version no lower than the minimum required version from the cloud and add it to the record to be synchronized. Repeat the above process for the added record until there are no missing records, and obtain the associated closed incremental set for the target terminal. S5. For newly added or modified records, incremental data is generated when the version before the change is consistent with the local cache version; otherwise, complete data is generated. The write hierarchy is set according to the order that the preceding related records precede the referenced records when adding or modifying, and the referenced records precede the preceding related records when deleting, to form an incremental synchronization package. S6. The target terminal writes the incremental synchronization packet to the temporary storage area, writes it to the local cache database according to the writing level within the same transaction, and returns confirmation information after verifying the writing result. S7. The cloud will only update the confirmed change sequence number of the target terminal to the end change sequence number of the incremental synchronization package after receiving the confirmation information.

[0007] Preferably, the record key is determined by the account set identifier, data type identifier, and business primary key; the association template includes the record key field, version field, reference field, and the referenced data type corresponding to the reference field; when the cloud submits a business transaction of the account set data, it determines the preceding associated record based on the reference field, determines the version of the preceding associated record read by the business transaction as the minimum required version, and records the change sequence number, transaction identifier, operation type, record key, version before change, version after change, and the record key and minimum required version of each preceding associated record in the change log.

[0008] Preferably, the data types include basic account records, accounting period records, accounting subject records, voucher header records, voucher detail records, and voucher attachment records; in the associated template, accounting period records and accounting subject records are associated with basic account records in a forward manner, voucher header records are associated with basic account records and accounting period records in a forward manner, voucher detail records are associated with voucher header records and accounting subject records in a forward manner, and voucher attachment records are associated with voucher header records in a forward manner.

[0009] Preferably, the local cache database is provided with a cache metadata table, which records at least the record key, the current cache version, and a logical deletion flag. The cloud sends the record keys extracted from the direct incremental records and subsequently added records to the target terminal after deduplication. The target terminal queries the cache metadata table in batches and returns the corresponding local cache version. In the case where the same record key has multiple minimum required versions, the highest version is taken as the required version threshold. The higher version between the local cache version and the version to be written for the same record key in the record to be synchronized is taken as the available version. When the available version is lower than the required version threshold, the preceding associated record corresponding to the record key is determined as a missing record. The same record key is added only once in a recursive supplementation process.

[0010] Preferably, the process involves obtaining a valid version of the missing record from the cloud-based accounting database, including obtaining a currently valid record with a version not lower than the required version threshold. When the cloud-based accounting database does not contain a currently valid record that meets the required version threshold, the direct incremental record that directly or indirectly references the missing record is marked as a blocked record. The blocked record with the smallest change sequence number is determined, and only the direct incremental records preceding the blocked record and their missing records are included in the current incremental synchronization package. Furthermore, the confirmed change sequence number of the target terminal is prohibited from exceeding the change sequence number of the blocked record.

[0011] Preferably, the incremental data of the field includes the record key, operation type, version before change, version after change, and the field identifier and field value that have changed; the complete data includes the record key, operation type, version after change, and all persistent fields of the corresponding record; the missing record added in step S4 uses the complete data; each record to be synchronized in the incremental synchronization package also carries the write level and transaction identifier, and records to be synchronized belonging to the same business transaction are set as the same transaction write unit.

[0012] Preferably, a reference relationship graph is established based on the associated closed incremental set, with the record to be synchronized as the node, and directed edges are established from the preceding associated record to the reference record; the writing level of the newly added record and the modified record is determined according to the directed edges, and the writing level of the deleted record is determined according to the opposite direction of the directed edges; when there is a circular reference in the reference relationship graph, the records constituting the circular reference are divided into the same circular reference group, local record identifiers are pre-assigned to the records in the circular reference group, the circular reference group is written in the same database transaction, and reference integrity verification is performed uniformly after all records in the group have been written.

[0013] Preferably, the incremental synchronization package further includes a synchronization package identifier, an account set identifier, a cache generation, a starting change sequence number, an ending change sequence number, and a record count. Before writing, the target terminal verifies the cache generation and the record count. When writing modified or deleted records, it performs conditional database operations using the record key and the previous version as conditions. If the actual number of records affected by any conditional database operation does not meet expectations, the current database transaction is rolled back, and the record key with the version inconsistency and its current cache version are returned to the cloud. The cloud then regenerates the associated closed incremental set and the incremental synchronization package based on the returned current cache version.

[0014] Preferably, the deletion operation in the change log is encapsulated as a deletion record containing a record key, a deletion version, and a logical deletion flag. When the target terminal executes the deletion record, it queries the local cache database to see if there is an associated record that has not been deleted and references the deletion record. If the associated record exists and the current incremental synchronization package has not removed the corresponding reference relationship, the record key and deletion version are retained and a logical deletion flag is set to form a placeholder record used only for reference integrity verification. After the corresponding reference relationship is removed, the placeholder record is physically deleted.

[0015] Preferably, when the target terminal clears, restores, or rebuilds its local cache database, it updates the cache generation and resets the confirmed change sequence number. The cloud compares the cache generation in the synchronization request with the cache generation previously confirmed by the target terminal. If they are inconsistent, the synchronization state saved based on the previous cache generation is canceled, and the record key of the target terminal that has not returned a valid cache version is determined to be uncached. After receiving the first confirmation information returned by the target terminal for the new cache generation, the cloud associates and saves the new cache generation with the corresponding confirmed change sequence number.

[0016] The technical effects and advantages of this invention are as follows: This invention determines the minimum required version based on the version of the preceding associated record actually read in the cloud business transaction, and combines the local cache version of the corresponding record on the target terminal and the version to be written of the record to be synchronized this time to make a deficiency judgment, and then recursively supplements the deficient records, so that the resulting incremental synchronization package satisfies the association closure condition that the preceding associated record is available before the referenced record. This can avoid the problem that the reference relationship is suspended and the associated version is mismatched after the voucher details, voucher attachments and other records are written due to the absence or insufficient version of the preceding record, which will lead to the local account set data not being able to be correctly associated or the data inconsistency during subsequent processing.

[0017] This invention generates associated closed incremental sets for the local cache status of different terminals, supplementing only the preceding associated records that are not cached by the target terminal, have insufficient cache versions, or are not provided with a sufficient version by the record to be synchronized this time. It does not require repeated downloading of the complete set of account data, nor does it require preloading all associated data according to a fixed type. For the preceding associated records that need to be supplemented after the deficiency judgment, they are included in the same incremental synchronization package with the record to be synchronized that references the preceding associated record. This avoids repeated waiting or repeated requests due to the arrival of associated data in batches, thereby reducing the overhead of irrelevant data transmission and local database writing while ensuring the integrity of the local set of account data association.

[0018] This invention improves the reliability and consistency of incremental data synchronization across multiple terminals by employing methods such as selecting incremental and complete data for fields, setting write levels, writing within the same transaction, version condition verification, and advancing change sequence numbers after confirmation. These methods prevent terminals from incorrectly advancing synchronization progress to incomplete change records during network interruptions, duplicate transmissions, version inconsistencies, or cache cleanup. Furthermore, when a previously associated record is temporarily unavailable, the cloud does not skip the corresponding blocked record to advance the confirmed change sequence number. When the terminal's local cache state changes or write verification fails, the cloud can regenerate the associated closed incremental set and incremental synchronization package based on the terminal's actual cache state. Attached Figure Description

[0019] The disclosure of this invention is illustrated with reference to the accompanying drawings. It should be understood that the drawings are for illustrative purposes only and are not intended to limit the scope of protection of this invention. In the drawings, the same reference numerals are used to refer to the same parts: Figure 1 This is a schematic diagram of the architecture of the present invention; Figure 2 This is a flowchart of the method of the present invention; Figure 3 This is a schematic diagram of the incremental synchronization packet data structure of the present invention. Detailed Implementation

[0020] It is readily understood that, based on the technical solution of this invention, those skilled in the art can propose various interchangeable structural methods and implementations without altering the essential spirit of the invention. Therefore, the following detailed embodiments and accompanying drawings are merely illustrative examples of the technical solution of this invention and should not be considered as the entirety of the invention or as limitations or restrictions on the technical solution of this invention.

[0021] Example 1: Refer to Figures 1-3 As shown, this embodiment provides an incremental synchronization method for financial accounting data across multiple terminals. This method is jointly executed by a cloud server and multiple terminals. The cloud server sets up a cloud accounting database, a change log service, a correlation resolution service, an incremental package generation service, and a terminal synchronization status table. Each terminal sets up a local cache database, a cache metadata table, a synchronization temporary storage area, and a synchronization package receiving record table. The terminals include computers, tablets, or mobile terminals.

[0022] The cloud-based accounting database serves as the authoritative data source for accounting data. The local cache database of each terminal only stores a portion of the accounting data that is needed within the current business scope of the corresponding terminal. The business scope is determined based on the accounting period, terminal operation permissions, voucher processing tasks, or recent access range. Therefore, different terminals may store different types of data, number of records, and record versions for the same accounting set.

[0023] The terminal first submits the new, modified or deleted requests to the cloud server, which then performs business verification on the requests and writes them into the cloud account database. The account draft data that the terminal has not yet submitted is stored in a draft area separate from the local cache database and is not used as the local cache data for version comparison in this invention.

[0024] Each record in the cloud-based accounting database is assigned a record key and a record version. The record key is determined by the accounting database identifier, data type identifier, and business primary key, and is stored using a combination key or unambiguous standard encoding. The record version is a positive integer that increments from the beginning. Each valid addition, modification, or logical deletion of a record corresponding to the same record key creates a new record version.

[0025] The higher version of the same record key contains the complete valid state of the record under the corresponding version. When the record version saved by the terminal is not lower than a certain minimum required version, it is determined that the record saved by the terminal can meet the corresponding reference requirements. For upgrades that cause data structure incompatibility, the original record version is not used for comparison. Instead, the cache generation is changed and the corresponding cache data is rebuilt.

[0026] The cloud-based accounting database includes at least the following tables: basic accounting data table, accounting period data table, accounting subject data table, voucher header data table, voucher detail data table, and voucher attachment data table. The cloud-based change log includes at least the following: accounting database identifier, change sequence number, transaction identifier, data type identifier, business primary key, record key, operation type, version before change, version after change, set of changed fields, and description of preceding associations.

[0027] The change sequence number monotonically increases in the order of business transaction submission within the same account set. The operation types include add, modify, and delete. The preceding association description includes the record key and minimum required version of each preceding associated record referenced by the current change record.

[0028] The cloud terminal synchronization status table includes at least the terminal identifier, account set identifier, bound cache generation, confirmed change sequence number, most recent synchronization package identifier, and most recent confirmation time. The terminal identifier and account set identifier are used together to determine a terminal synchronization status, so that different terminals can maintain synchronization progress for the same account set.

[0029] The terminal cache metadata table includes at least a record key, the current cache version, a logical deletion flag, a local record identifier, and a recently written synchronization package identifier. Each account set business table in the local cache database corresponds to the cache metadata table through a record key or a local record identifier, so that the terminal can perform batch queries to check whether a record exists and its current cache version without reading all business fields.

[0030] The terminal synchronization temporary storage area stores the data to be written according to the synchronization packet identifier. The temporary storage data includes at least the record key, operation type, data form, version before change for condition verification, version after change, field data, writing level, transaction identifier, and processing status. The temporary storage data is only written to the local cache database after the corresponding incremental synchronization packet is fully received and passes verification.

[0031] The cloud server configures association templates for each data type. The association template includes at least the current record key field, version field, reference field, the data type of the referenced field, whether the reference can be null, and the business primary key value retrieval method of the referenced record.

[0032] Accounting period records and accounting subject records are linked to the basic records of the accounting system in a forward manner. Voucher header records are linked to the basic records of the accounting system and accounting period records in a forward manner. Voucher detail records are linked to voucher header records and accounting subject records in a forward manner. Voucher attachment records are linked to voucher header records in a forward manner.

[0033] For example, in the voucher details record, a voucher header identifier field and an accounting subject identifier field are set. The association template maps the voucher header identifier field to the voucher header data type and the accounting subject identifier field to the accounting subject data type. The association parsing service combines the current account set identifier to generate the record key of the corresponding voucher header record and accounting subject record.

[0034] When the cloud server processes a request to write account data, it initiates a business transaction. In the business transaction, it reads the preceding associated record referenced by the record to be written, and verifies whether the preceding associated record exists and whether it belongs to the same account set according to the association template. At the same time, it obtains the version of the preceding associated record actually read by the business transaction.

[0035] When a business transaction is committed, the cloud server writes the changes to the account set data and the corresponding change logs into the same business transaction. It also determines the version of the preceding associated record when the business transaction reads it as the minimum required version, and then writes the record key of the preceding associated record and the minimum required version into the preceding associated description of the current change record. This allows the changes to the account set data and the corresponding preceding associated description to be committed or rolled back simultaneously.

[0036] When the same business transaction adds a preceding associated record and a subsequent record that references the preceding associated record, the minimum required version is the modified version of the preceding associated record formed in this business transaction. For example, when the same business transaction adds a voucher header record and a voucher detail record at the same time, the preceding associated description record of the voucher detail record contains the record key of the voucher header record and its added version.

[0037] When a business transaction reads a preceding associated record and that preceding associated record is concurrently modified, the cloud-based accounting database determines the actual record version used in this business transaction through a transaction isolation mechanism or a commit verification based on the record version, and sets the actual record version used as the minimum required version.

[0038] When the target terminal initiates synchronization, it reads the terminal identifier, the target account identifier, the current cache generation, and the confirmed change sequence number, and sends the above data as a synchronization request to the cloud server. The confirmed change sequence number indicates the last cloud change sequence number that the target terminal has completely written and confirmed.

[0039] After receiving a synchronization request, the cloud server queries the corresponding terminal synchronization status and reads the change logs with change sequence numbers greater than the confirmed change sequence numbers from the change logs of the target account set. Then, based on the account set access permissions of the target terminal and the current cached business scope, it obtains the direct incremental record from the change logs.

[0040] To control the amount of data in a single synchronization, the cloud server determines the candidate end position according to the preset number of records or data capacity. When the candidate end position is in the middle of a business transaction, the candidate end position is extended to the last change log of the business transaction or rolled back to the previous change log of the business transaction, so as to avoid the same business transaction being split into two incremental synchronization packages.

[0041] When multiple change logs correspond to the same record key, the cloud server processes the change logs sequentially according to the change sequence number, or merges consecutive modification logs into a single direct incremental record. During merging, the version before the change of the first modification log is used as the version before the change of the merged record, and the version after the change of the last modification log is used as the version after the change of the merged record. A set of changed fields is generated according to the field value after the last modification of the same field.

[0042] The cloud server extracts the record key of the direct incremental record itself and the record key in the preceding association description from the direct incremental record. After deduplicating the extracted record keys, it forms a version query list and sends the version query list to the target terminal.

[0043] The target terminal queries the cache metadata table in batches according to the version query list. For normal cached records, it returns the current cached version; for non-existent records, it returns the uncached status; and for placeholder records with a logical deletion flag, it returns the logical deletion status and the deleted version. The logical deletion status is treated as the uncached status when determining whether it can be used as a valid preceding associated record.

[0044] The cloud server extracts the record key and minimum required version of the preceding associated record from the preceding associated description of each direct incremental record based on the association template, and obtains the local cached version returned by the target terminal for the direct incremental record and its preceding associated record.

[0045] Let the target terminal be The set of direct incremental records obtained from the change log is Initial set of records to be synchronized Take as For any record to be synchronized ,by This represents the set of preceding association descriptions corresponding to this record, where each preceding association description is represented as a record key. and minimum required version The combination of .

[0046] by Indicates the target terminal's record key The returned valid local cached version, in Indicates the first Record keys in the waiting synchronization record set The highest modified version of the corresponding newly added or modified record, when the target terminal does not cache the record key. The corresponding record is in a logically deleted state or the current set of records to be synchronized does not contain the record key. At that time, or the current set of records to be synchronized contains only record keys. When deleting a record, the corresponding version is set to zero.

[0047] No. The set of missing records for a round is determined by the following formula: ; in, The recursive iterations are numbered starting from zero. For the first The set of missing records that will be received in turn. For the target terminal, For recording key, For the record key The corresponding minimum required version, This means taking the higher version value. Before executing the formula, for multiple minimum required versions corresponding to the same record key, the highest minimum required version is retained as the required version threshold.

[0048] In the formula, the higher of the local cache version and the highest version to be written for the same record key is the available version. When the same record key corresponds to multiple minimum required versions, the highest version among the multiple minimum required versions is taken as the required version threshold, and then the available version is compared with the required version threshold.

[0049] For the record keys in the missing record set The cloud server retrieves records from the cloud account database that have the same key and whose current version is not lower than the minimum required version. The current valid record, and with If a missing record is found, and no valid record exists, the recursive supplementation corresponding to that record key will not be performed. Instead, the direct incremental record referencing that record key will be marked as a blocked record. The set of records to be synchronized in the next round will be updated according to the following formula: ; The cloud server continues to extract the record keys and minimum required versions of the preceding related records from the newly added missing records, and sends the record keys that have not yet been queried to the target terminal for batch querying. Then, it re-executes the missing record judgment based on the returned local cache version until the missing record set is empty.

[0050] During the recursive processing, a set of processed record keys and a queue of record keys to be processed are set. When the same record key is first identified as a missing record, it is added to the queue of record keys to be processed. After the corresponding record is retrieved from the cloud account database, it is written to the set of processed record keys. When the same record key appears again, only the corresponding required version threshold is increased, and the same record is not added again.

[0051] Since the recursive process only adds the previous associated records that the target terminal has not yet cached enough versions of and the current set of records to be synchronized does not provide enough versions of the previous associated records, the final associated closed incremental set does not include the previous associated records that the target terminal has already saved and that meet the reference requirements, nor does it repeatedly include the previous associated records that have been provided with enough versions by the current set of records to be synchronized.

[0052] When the corresponding record in the cloud accounting database has been physically deleted, transferred to an archive area that has not yet been restored, or the current valid version is lower than the required version threshold due to data anomalies, the cloud server will mark the direct incremental record that directly or indirectly references the missing record as a blocked record.

[0053] The cloud server identifies the blocked record with the smallest change sequence number from the blocked records and uses it as the truncation point for this round of synchronization. Only the direct incremental records located before the truncation point and the missing records that supplement these direct incremental records are included in the current incremental synchronization package. The change sequence number at the end of the incremental synchronization package must not reach or exceed the change sequence number of the blocked record.

[0054] For newly added records, missing records added recursively, and modified records not cached on the target terminal, the cloud server generates complete data, which includes the record key, operation type, changed version, and all persistent fields of the corresponding record.

[0055] For modification records, the cloud server directly compares the version before the change recorded in the change log with the local cached version returned by the target terminal. When the two are consistent, incremental field data is generated. The incremental field data includes the record key, operation type, version before the change, version after the change, and the field identifier and field value that have changed.

[0056] When the version of the modified record in the change log is inconsistent with the local cache version of the target terminal, the cloud server reads the currently valid record in the cloud account database and generates complete data, enabling the target terminal to restore the current record state in the cloud based on the complete data.

[0057] The version before the change in the change log is used as the source version before the change to select incremental or complete data for fields. The version before the change used for condition validation in the synchronization package adopts the local cached version actually returned by the target terminal when the synchronization package is generated by the cloud. In the incremental field mode, the source version before the change and the version before the change used for condition validation are the same. In the complete data mode, even if the two are different, the version before the change used for condition validation is used as the version condition for the terminal to perform database operations.

[0058] The cloud server establishes a reference relationship graph based on the associated closed incremental set, with the record to be synchronized as the node, and establishes directed edges from the preceding associated record to the reference record. Then, it determines the writing level of the new record and the modified record in the manner of prioritizing the absence of a preceding node, and determines the writing level of the deleted record in the opposite direction of the directed edges.

[0059] When a circular reference exists in the reference graph, the cloud server determines the circular reference record by maintaining the access state and performing a depth-first traversal of the current path stack. Records that constitute the same circular reference are divided into circular reference groups, and the same write level is set for records in the same circular reference group.

[0060] The cloud server determines the synchronization package identifier based on the terminal identifier, account set identifier, cache generation, start change sequence number, end change sequence number, and generation batch. The synchronization package identifier, account set identifier, cache generation, start change sequence number, end change sequence number, and number of records are written in the header of the incremental synchronization package. The data format, field data, pre-change version, post-change version, write level, and transaction identifier of each record to be synchronized are written in the package body.

[0061] Records to be synchronized belonging to the same business transaction are set to the same transaction writing unit, so that when the target terminal processes the records to be synchronized according to the writing level, the records in the same business transaction are executed continuously and cannot form an acknowledgment state in the middle of the transaction writing unit.

[0062] After receiving the incremental synchronization packet, the target terminal queries the synchronization packet reception record table. If the same synchronization packet identifier has been successfully processed, it will not write the business record again, but will return the original confirmation information. If the same synchronization packet identifier has not been processed, the record to be synchronized in the packet body will be written to the corresponding synchronization temporary storage area.

[0063] The target terminal verifies the account set identifier, cache generation, and number of records in the incremental synchronization package. After the verification is successful, a local database transaction is started, and new records and modified records are processed in order of writing level from low to high. Then, the deletion operation is performed according to the writing level of the deleted record.

[0064] For circular reference groups, the target terminal pre-assigns local record identifiers to each record in the group and establishes a mapping between record keys and local record identifiers before the actual writing. All records in the group are written within the same local database transaction, and reference integrity checks are performed uniformly after all records in the group have been written.

[0065] When the local cache database supports deferred reference constraints, reference constraint verification is triggered uniformly after all circular reference groups are written. When the local cache database does not support deferred reference constraints, the local record identifier pre-allocation and reference field parsing of records within the group are completed in the synchronous temporary storage area, and the circular reference group is written to the formal cache table after all reference fields can be parsed.

[0066] When the target terminal writes incremental data to a field, the database operation conditions are the record key and the version before the change used for condition validation. If the local record exists and the current cached version is equal to the version before the change used for condition validation, the changed field is updated, and the current cached version in the cache metadata table is updated to the changed version.

[0067] When the target terminal writes the complete data corresponding to the modification operation, it also uses the record key and the version before the change as the database operation condition for condition validation. When the condition is met, it replaces the persistent field of the corresponding record with the complete data and updates the current cached version to the changed version.

[0068] When the target terminal writes a new record, the condition for writing is that the same record key does not exist in the local cache database. If the same record key already exists locally and the cache version is not lower than the version to be written, the record is skipped idempotently as already written data. If the same record key exists locally but the cache version is lower than the version to be written, the conditional write is performed according to the complete data modification method.

[0069] When any modification or deletion operation fails to reach the expected number of affected records due to a missing record key, a difference between the current cache version and the version used for conditional validation before the change, or a change in the cache generation, the target terminal rolls back the local database transaction corresponding to the current incremental synchronization package and returns the record key, current cache version, and current cache generation that are inconsistent to the cloud server.

[0070] After receiving the version inconsistency information, the cloud server replaces the local cache version used when generating the original incremental synchronization package with the current cache version newly returned by the target terminal, and re-executes the missing record judgment, data format selection, write level determination and incremental synchronization package generation.

[0071] When the target terminal processes the deletion of a record, it queries the local cache database to see if there are any related records that have not been deleted but still reference the record to be deleted, and determines whether the current incremental synchronization package contains a modification record for deleting the related record or removing the corresponding reference relationship.

[0072] When there are no remaining reference relationships or the current incremental synchronization package can remove all reference relationships before the deletion operation, the target terminal performs physical deletion of the record to be deleted and retains the processed deletion version in the cache metadata table or deletion history table.

[0073] When there are still local records that have not been deleted referencing the record to be deleted and the current incremental synchronization package has not removed the corresponding reference relationship, the target terminal retains the record key and deletion version of the record to be deleted, removes unnecessary fields used for account set business queries, and sets a logical deletion flag to form a placeholder record.

[0074] The placeholder record is excluded by the logical deletion condition in the ordinary account set business query and is treated as an uncached record in the missing record judgment. However, when performing local reference integrity verification, the record key of the placeholder record is still used to maintain the existing reference relationship. The placeholder record is physically deleted after the corresponding reference relationship is released in the subsequent synchronization.

[0075] Once all records to be synchronized have been successfully written and passed the referential integrity check, the target terminal updates the cache metadata table in the same local database transaction, writes the synchronization packet identifier, end change sequence number, cache generation, and processing success status into the synchronization packet receiving record table, and then submits the local database transaction and returns confirmation information to the cloud server.

[0076] The cloud server updates the confirmed change number in the terminal synchronization status table to the end change number only when the synchronization packet identifier, cache generation, and end change sequence number in the confirmation information are consistent with the sent incremental synchronization packet. When the confirmation information is lost during communication, the cloud server resends the same synchronization packet, and the target terminal returns the original confirmation information according to the synchronization packet reception record table.

[0077] When the local cache database is cleared, restored, or rebuilt, the terminal generates a new cache generation and resets the confirmed change sequence number to the initial change sequence number that the cloud allows for resynchronization or the change sequence number corresponding to the cache backup.

[0078] When the cloud server discovers that the cache generation in the synchronization request is inconsistent with the bound cache generation in the terminal synchronization status table, it will discard the unconfirmed synchronization package and version query results saved under the previous cache generation, and treat the record key of the target terminal that does not return a valid cache version under the new cache generation as an uncached state.

[0079] After the first incremental synchronization packet corresponding to the new cache generation is fully written by the target terminal and a confirmation message is returned, the cloud server will associate and save the new cache generation with the corresponding confirmed change sequence number. Before receiving the confirmation message, the new cache generation will not be used to update the original synchronization progress.

[0080] Example 2: Based on Example 1, this example illustrates the specific process of generating a related closed incremental set for different terminals by synchronizing voucher details records in the same account set between two terminals.

[0081] The cloud-based accounting database stores the following records corresponding to accounting set A001: version 1 basic accounting set record A, version 3 accounting period record P, version 4 accounting subject record S, version 5 voucher header record H, and version 1 voucher detail record L. The voucher header record H references the basic accounting set record A and the accounting period record P, while the voucher detail record L references the voucher header record H and the accounting subject record S.

[0082] When the cloud server generates the change log for voucher detail record L, the corresponding business transaction reads version five of voucher header record H and version four of accounting subject record S. Therefore, the record key of voucher header record H and the minimum required version five are recorded in the preceding association description of voucher detail record L, and the record key of accounting subject record S and the minimum required version four are recorded.

[0083] Terminal A's local cache database saves version one basic account record A, version three accounting period record P, and version four accounting subject record S, but does not save the voucher header record H. Terminal B's local cache database saves version one basic account record A, version two accounting period record P, and version four voucher header record H, but does not save the accounting subject record S.

[0084] When the voucher detail record L is determined to be a direct incremental record for terminal A and terminal B, the cloud server queries the local cache versions of the voucher detail record L, voucher header record H, and accounting subject record S from the two terminals respectively, and performs the missing record judgment according to the local cache versions returned by each terminal.

[0085] For terminal A, the local cache version of accounting subject record S is four and not lower than the minimum required version four. Therefore, accounting subject record S is not a missing record. The voucher header record H is not cached by terminal A, so its available version is lower than the minimum required version five. The cloud server adds version five voucher header record H to the records to be synchronized of terminal A.

[0086] The cloud server continues to extract the preceding associated records of the voucher header record H, and determines that the voucher header record H references version one account set basic record A and version three accounting period record P. Since the account set basic record A and accounting period record P saved by terminal A both meet the corresponding minimum required versions, no other records are added. Finally, a closed incremental set of associations including voucher header record H and voucher detail record L is formed for terminal A.

[0087] For terminal B, the local cache version of the voucher header record H is four, which is lower than the minimum required version five, and the accounting subject record S is in an uncached state. Therefore, the cloud server adds the version five voucher header record H and the version four accounting subject record S to the records to be synchronized for terminal B.

[0088] The cloud server continues to extract the preceding associated records of voucher header record H of version 5, and determines that the version 2 accounting period record P saved by terminal B is lower than the minimum required version 3. Therefore, the version 3 accounting period record P is added to the records to be synchronized, while the version 1 account set basic record A already meets the minimum required version requirement and will not be added again.

[0089] The associated closed incremental set corresponding to terminal B ultimately includes version three accounting period record P, version four accounting subject record S, version five voucher header record H, and version one voucher detail record L. The cloud server sets the accounting period record P and accounting subject record S as the first writing level, sets the voucher header record H as the second writing level, and sets the voucher detail record L as the third writing level.

[0090] The incremental synchronization packet received by terminal A only includes the voucher header record H and the voucher detail record L, while the incremental synchronization packet received by terminal B includes the accounting period record P, the accounting subject record S, the voucher header record H, and the voucher detail record L. Therefore, the same direct incremental record can form different data supplement ranges based on the actual cached content of the two terminals.

[0091] Terminal B sequentially writes the accounting period record P, the accounting subject record S, the voucher header record H, and the voucher detail record L in the same local database transaction. After all records are written, it verifies whether the voucher header record H and the accounting subject record S referenced by the voucher detail record L exist and whether their versions meet the requirements.

[0092] If the cloud server subsequently changes the voucher detail record L from version one to version two, and the voucher detail record L saved by terminal A is still version one, then the cloud server will send incremental data containing the changed fields, the original version one, and the new version two to terminal A.

[0093] If terminal B does not cache credential detail record L or its local cache version is not version one, the cloud server sends the complete data of credential detail record L of version two to terminal B, and sets the local cache version or uncached state actually returned by terminal B to the version before the change for conditional validation, so that the complete data can be conditionally written based on the actual cache state of terminal B.

[0094] After terminal A and terminal B complete the transaction writing of their respective incremental synchronization packages and return confirmation information, the cloud server updates the confirmed change sequence number of the two terminals respectively, so that each terminal can obtain the account set incremental data that meets the local reference integrity requirements while maintaining independent synchronization progress.

[0095] The technical scope of this invention is not limited to the content described above. Those skilled in the art can make various modifications and variations to the above embodiments without departing from the technical concept of this invention, and all such modifications and variations should fall within the protection scope of this invention.

Claims

1. A method for incremental synchronization of financial accounting data across multiple terminals, characterized in that, include: S1. The cloud-based accounting database stores authoritative accounting data and change logs arranged in the order of submission. Each terminal sets up a local cache database to store a portion of the accounting data and configures association templates for each data type to identify the preceding associated records. S2. Receive the synchronization request sent by the target terminal, which carries the terminal identifier, account identifier, confirmed change sequence number and cache generation, and obtain the direct incremental record from the change log based on the confirmed change sequence number. S3. When generating change logs, determine the preceding associated record based on the reference field of the associated template, record the version when the business transaction reads the record as the minimum required version, and record its record key and minimum required version; obtain the local cache version of the direct incremental record and its preceding associated record on the target terminal. S4. Take the higher of the local cache version of the previous associated record and the version to be written with the same key in the record to be synchronized as the available version. If it is not cached or not included, the corresponding version is considered to be lower than any valid version. If the available version is lower than the minimum required version, the corresponding previous associated record is identified as a missing record. Obtain the missing record with a version no lower than the minimum required version from the cloud and add it to the record to be synchronized. Repeat the above process for the added record until there are no missing records, and obtain the associated closed incremental set for the target terminal. S5. For newly added or modified records, incremental data is generated when the version before the change is consistent with the local cache version; otherwise, complete data is generated. The write hierarchy is set according to the order that the preceding related records precede the referenced records when adding or modifying, and the referenced records precede the preceding related records when deleting, to form an incremental synchronization package. S6. The target terminal writes the incremental synchronization packet to the temporary storage area, writes it to the local cache database according to the writing level within the same transaction, and returns confirmation information after verifying the writing result. S7. The cloud will only update the confirmed change sequence number of the target terminal to the end change sequence number of the incremental synchronization package after receiving the confirmation information.

2. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, The record key is determined by the account set identifier, the data type identifier, and the business primary key; the association template includes the record key field, the version field, the reference field, and the referenced data type corresponding to the reference field. When a business transaction is submitted in the cloud, the preceding associated record is determined based on the reference field. The version of the preceding associated record read by the business transaction is determined as the minimum required version. The change sequence number, transaction identifier, operation type, record key, version before change, version after change, record key and minimum required version of each preceding associated record are recorded in the change log.

3. The incremental synchronization method for multi-terminal financial accounting data according to claim 2, characterized in that, The data types include basic account records, accounting period records, accounting subject records, voucher header records, voucher detail records, and voucher attachment records. In the associated template, accounting period records and accounting subject records are associated with basic account records in a forward manner, voucher header records are associated with basic account records and accounting period records in a forward manner, voucher detail records are associated with voucher header records and accounting subject records in a forward manner, and voucher attachment records are associated with voucher header records in a forward manner.

4. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, The local cache database is equipped with a cache metadata table, which records at least the record key, the current cache version, and a logical deletion flag. The cloud sends the record keys extracted from the direct incremental records and subsequently added records to the target terminal after deduplication. The target terminal queries the cache metadata table in batches and returns the corresponding local cache version. In the case where the same record key has multiple minimum required versions, the highest version is taken as the required version threshold. The higher version between the local cache version and the version to be written for the same record key in the record to be synchronized is taken as the available version. When the available version is lower than the required version threshold, the preceding associated record corresponding to the record key is determined as a missing record. The same record key is added only once in a recursive supplementation process.

5. The incremental synchronization method for multi-terminal financial accounting data according to claim 4, characterized in that, Obtain a valid version of the missing record from the cloud-based accounting database, including obtaining a currently valid record with a version not lower than the required version threshold; when there is no currently valid record in the cloud-based accounting database that meets the required version threshold, mark the direct incremental record that directly or indirectly references the missing record as a blocked record, determine the blocked record with the smallest change sequence number, and only include the direct incremental record and its missing record located before the blocked record in the current incremental synchronization package, and prohibit the confirmed change sequence number of the target terminal from exceeding the change sequence number of the blocked record.

6. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, The incremental data of the fields includes the record key, operation type, version before change, version after change, and the field identifier and field value that have changed; the complete data includes the record key, operation type, version after change, and all persistent fields of the corresponding record; the missing records added in step S4 use complete data; each record to be synchronized in the incremental synchronization package also carries the write level and transaction identifier, and records to be synchronized belonging to the same business transaction are set as the same transaction write unit.

7. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, A reference relationship graph is established based on the associated closed incremental set, with the record to be synchronized as the node, and a directed edge is established from the previous associated record to the reference record; the writing level of the new record and the modified record is determined according to the directed edge, and the writing level of the deleted record is determined according to the opposite direction of the directed edge. When a circular reference exists in the reference graph, the records constituting the circular reference are divided into the same circular reference group. Local record identifiers are pre-assigned to the records in the circular reference group. The circular reference group is written within the same database transaction, and a reference integrity check is performed uniformly after all records in the group have been written.

8. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, The incremental synchronization package also includes a synchronization package identifier, an account set identifier, a cache generation, a starting change sequence number, an ending change sequence number, and a record count. Before writing, the target terminal verifies the cache generation and the record count. When writing, modifying, or deleting a record, it performs conditional database operations using the record key and the previous version as conditions. If the actual number of records affected by any conditional database operation does not meet expectations, the current database transaction is rolled back, and the record key with the version inconsistency and its current cache version are returned to the cloud. The cloud then regenerates the associated closed incremental set and the incremental synchronization package based on the returned current cache version.

9. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, The deletion operation in the change log is encapsulated as a deletion record containing a record key, deletion version, and logical deletion flag. When the target terminal executes the deletion record, it queries the local cache database to see if there is an associated record that has not been deleted and references the deletion record. If the associated record exists and the current incremental synchronization package has not removed the corresponding reference relationship, the record key and deletion version are retained and a logical deletion flag is set to form a placeholder record used only for reference integrity verification. After the corresponding reference relationship is removed, the placeholder record is physically deleted.

10. The incremental synchronization method for multi-terminal financial accounting data according to claim 1, characterized in that, When the target terminal's local cache database is cleared, restored, or rebuilt, the cache generation is updated and the confirmed change sequence number is reset. The cloud compares the cache generation in the synchronization request with the cache generation previously confirmed by the target terminal. If the two are inconsistent, the synchronization state saved based on the previous cache generation is canceled, and the record key of the target terminal that has not returned a valid cache version is determined to be uncached. After receiving the initial confirmation information from the target terminal for the new cache generation, the cloud will associate and save the new cache generation with the corresponding confirmed change sequence number.