A budget process state synchronization method and system based on event sequence verification

By employing event sequence verification in a microservice architecture, the data consistency problem in asynchronous event processing is solved, ensuring the orderliness and accuracy of the budget process, and achieving effective binding between task instances and budget versions and data consistency.

CN123157337APending Publication Date: 2026-11-24PANSOFT
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611663514.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-27
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

In a microservice architecture, the lack of state write-back constraints corresponding to the instance creation phase and valid data snapshot in asynchronous event processing can lead to duplicate, out-of-order, or invalid related records, affecting the data consistency of the budget process.

Method used

By using an event sequence verification-based budget process status synchronization method, an association is established between task instance identifiers and budget version identifiers. Local transactions are used to commit status updates and event records, generating continuously incrementing event sequence numbers. The consumer verifies and persists buffered events according to the sequence number, ensuring the orderliness and effective binding of the event sequence. When locking the version status, the budget service checks the data fingerprint and binding to ensure data consistency.

Benefits of technology

It achieves adaptation between the event consumption process and the instance establishment phase under asynchronous communication conditions, reduces the impact of duplicate, out-of-order, and invalid events on associated records, and ensures data consistency and accuracy in the budget process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157337A_ABST
    Figure CN123157337A_ABST
Patent Text Reader

Abstract

This invention discloses a budget process status synchronization method and system based on event sequence verification, involving distributed data consistency processing. The method establishes a submission association between tasks and budget versions, locking the versions. After consuming the submission event, the approval service generates an approval instance and an approval start fingerprint, completing the valid binding with the approval initiation event. The source service generates continuous event sequences according to tasks and sources respectively. The consumer performs deduplication, sequence, and phased binding verification, persistently buffering out-of-order events. The budget service verifies complete binding, lock ownership, version status, and snapshot fingerprint, submitting the status, processing records, progress, and writing confirmation events in a local transaction. The task flow completes tasks based on confirmation events; exceptions are handled as pullbacks, final rejections, and dead-letter branches, restricting the writing back of status for duplicate, out-of-order, and invalid events.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data consistency processing technology for distributed computer systems, and specifically to a budget process state synchronization method and system based on event sequence verification. Background Technology

[0002] The comprehensive budget management system records budget preparation tasks, approval instances, and data on different budget versions via computer. When using a microservice architecture, the task flow engine service stores task instances and worker nodes, the approval flow engine service stores approval instances and approval decisions, and the budget service stores budget data and version status. Each service maintains its own local database and exchanges recorded status changes through synchronization interfaces and an event bus.

[0003] In an event-driven implementation, a commit event is generated after a task is submitted, and the approval service creates an approval instance accordingly. After the approval service generates an approval result, a result event is generated, the budget service writes the version status, and the task service advances subsequent work nodes. Because local transactions and asynchronous delivery are separated for each service, message arrival order may change due to network latency, duplicate delivery, or service restarts. Before an approval instance is created, the initial commit event cannot contain the approval instance identifier; if a complete approval binding is required beforehand for such events, the initialization itself may not be possible.

[0004] Message brokers can provide sequential delivery, retry, and persistence capabilities under certain configuration and usage conditions, but these capabilities do not directly determine whether the approval instance and budget data snapshot corresponding to the application layer event are still valid. If the application layer only updates local records according to the message arrival order, delayed old approval results may be written to already recompiled records; if the task service only completes the task based on the approval notification, it may also terminate the task before the budget service actually submits the write. Therefore, the main problem with the existing implementation is that asynchronous event processing lacks state write-back constraints corresponding to the instance establishment phase and valid data snapshot, and associated records may be incorrectly advanced by duplicate, out-of-order, or invalid events. Summary of the Invention

[0005] The technical problem to be solved by this invention is how to adapt the event consumption process to the effective binding of the instance establishment phase and budget version under the condition that each service stores independently and communicates asynchronously, and restrict the write-back of the state of the associated records by duplicate, out-of-order and invalid events.

[0006] This invention provides a budget process status synchronization method based on event sequence verification, comprising the following steps.

[0007] S1. Establish a submission association between the task instance identifier and the budget version identifier, and lock the corresponding budget version in the budget service; S2. The source service commits the state update, event record, and corresponding count increment in the same local transaction, and then publishes the event record; using the combination of the task instance identifier and the source service identifier as the sequence key, the event sequence number is generated in a continuously increasing manner according to the sequence key; S3. The consumer deduplicates events by event identifier, compares the event sequence number with the expected sequence number by the consumer identifier and the sequence key, and persists events with a greater than the expected sequence number in the buffer. For initialization events at the expected sequence position, the submission association is checked. After the approval flow engine service consumes the task submission event, it creates an approval instance, saves the budget snapshot fingerprint at the start of the approval, and generates an approval initiation event according to S2. The task flow engine service establishes a valid binding containing the task instance identifier, approval instance identifier, budget version identifier, and the budget snapshot fingerprint. The budget service consumes the approval initiation event and completes the lock attribution. S4. For approved events at the expected sequence position, the budget service verifies the valid binding, lock ownership, and version status, and compares the budget snapshot fingerprint carried by the event, the budget snapshot fingerprint saved in the valid binding, and the current data fingerprint; after verification, it submits the version status update, processed event record, consumption progress, and write confirmation event record in the same local transaction. S5. After publishing the write confirmation event, the task flow engine service verifies the source and valid binding, and submits the task completion status, processed event records and consumption progress in the same local transaction; each consumer continues to process the next consecutive buffer event after advancing the expected sequence number.

[0008] Furthermore, the task flow engine service stores the submission association corresponding to the task instance identifier and the budget version identifier in the local task record. After receiving the approval initiation event and verifying the submission association, it writes the task instance identifier, approval instance identifier, budget version identifier, budget snapshot fingerprint, and validity flag into the local association table. The same task instance and the same budget version can correspond to at most one valid approval instance at any given time. The budget lock event and task submission event before the approval instance is created do not carry the approval instance identifier, while the approval initiation event, approval result event, and write confirmation event carry the three identifiers.

[0009] Furthermore, each consumer receives all state change events corresponding to the subscribed sequence key and persistently saves the expected sequence number; for events without local state transition actions, the processing results are saved and the corresponding consumption progress is advanced; the same event that is resent, re-delivered, or re-pulled retains the original event identifier, event sequence number, and payload; the event identifier and the delivery identifier of the message middleware are independent of each other.

[0010] Furthermore, the generation of the budget snapshot fingerprint includes: reading the complete data set of the locked budget version, sorting it according to the record key composed of budget version identifier, budget organization identifier, period identifier, currency code and report item code, normalizing and serializing the above fields and budget values ​​according to the preset field order and field type, and performing a hash operation on the serialization result; task status, approval status, version status, event time and operation logs are not involved in the serialization.

[0011] Furthermore, the consumer persistently stores events with sequence numbers greater than the expected sequence number and their missing positions. After a timeout, it retrieves the events from the local event table from the source service using the sequence key and the missing sequence number, and re-executes the verification. Events with sequence numbers less than the expected sequence number are expired. For events that are clearly invalid, the rejection result is saved and the expected sequence number is advanced. For events where the association has not been established, the preceding record has not been synchronized, or the transaction has failed, the original expected sequence number is retained. When different event identifiers or different payloads appear at the same sequence position, a conflict record is saved and the sequence is paused. When the number of failed retrieval attempts reaches a preset number, a dead letter record is saved and the missing position is retained.

[0012] Furthermore, the budget service locks the corresponding version record in the local transaction that executes the write of the approval result, calculates the current data fingerprint within the consistent read range of the same transaction, verifies that the budget version is in a locked state and that the three binding identifiers match, updates the version status to approved, saves the accepted approval identity and budget snapshot fingerprint, and clears the lock ownership; the write confirmation event has an independent event identifier and carries the original approval result event identifier, the three binding identifiers, and the accepted budget snapshot fingerprint; unpublished events in the local event table continue to be published after the service is restored.

[0013] Furthermore, when an approval is rejected, the budget service verifies the original lock ownership, revokes the write qualification of the original approval instance, and unlocks it in the local transaction of the corresponding version record. When an approved version that has not been published and archived is restarted, the accepted approval identity is verified in the local transaction and the write qualification of the original approval instance is revoked. The budget service publishes a corresponding confirmation event. The task flow engine service invalidates the original binding and creates a new task instance based on the confirmation event. After resubmission, a new approval instance and budget snapshot fingerprint are formed. For rejection feedback of historical tasks that have expired, only the historical processing record is saved, and the current valid task and its budget version are not updated.

[0014] Furthermore, the budget service writes the task instance identifier to the lock ownership of the corresponding budget version and sets the approval instance identifier to null in the lock transaction submission. When a consumption approval event is initiated, a complete and valid binding is obtained. The locked status and the task instance identifier are checked in the local transaction of the lock version record. The approval instance identifier carried by the event is added to the lock ownership, and the processed event record and consumption progress are saved together. Ownership completion, approval writing, writing qualification revocation, and relocking are all submitted in the local transaction of the lock version record. The published or archived budget version retains the original data, and the recompiled data is saved in the new budget version. Switching display dimensions does not change the binding identifier carried by the event.

[0015] The present invention also provides a budget process status synchronization system and a computer-readable storage medium. The system includes a task flow engine service, an approval flow engine service, and a budget service that communicate via an event bus, as well as a processor and a memory; the processor implements the above-described method when executing a computer program in the memory. The computer-readable storage medium stores the computer program.

[0016] Due to the adoption of the above technical solution, the beneficial effects achieved by this application are as follows: 1. By handling the submission association before the approval instance is created and the complete and valid binding after creation separately, the initial event can be initialized based on the existing task and version information. The approval result still needs to be written after complete binding and snapshot verification, avoiding waiting for the approval identifier that has not yet been generated at the initialization entry point. 2. By maintaining event sequences separately for task instances and source services, out-of-order events from the same source and pre-dependencies from different sources are distinguished; by using unique constraints on event identifiers and processing records, and local transaction commits for consumption progress and status, duplicate deliveries and duplicate status updates caused by consumer restarts are reduced. 3. By comparing the approval start fingerprint, the valid binding fingerprint, and the current normalized data fingerprint, and submitting a status update when the budget service holds the version record row lock, the approval result is made consistent with its corresponding data content and lock ownership. The fingerprint reflects the data differences under the preset normalization rules; null values ​​and zero values, etc., are normalized according to the rules and have the same representation. 4. After the write result is submitted through the budget service, an independent confirmation event is generated. Then, the task flow engine service completes the task, connecting the approval decision with the actual database write. Through persistent buffering, timeout retrieval, explicit final rejection of failure events, and retention of dead-letter positions, the anomaly recovery process does not need to treat unprocessed events as successes; historical rejection feedback is only recorded in the past, reducing repeated intervention in the new round of valid tasks. Attached Figure Description

[0017] Figure 1 This is a diagram illustrating the system composition and the local storage relationships of each service. Figure 2 Flowchart for the budget process status synchronization method; Figure 3 A flowchart for phased verification and exception handling on the consumer side; Figure 4 A diagram illustrating the submission initialization, approval instance creation, and confirmation process; Figure 5 This diagram illustrates the budget version state transition and old binding failure handling. Detailed Implementation

[0018] The embodiments of the present invention are described below with reference to the accompanying drawings. The method processes events, instance associations, data fingerprints, consumption progress, and status records persistently stored in the computer. Task status, approval status, and budget version status are managed by their respective services. The source status and target status in an event describe the current change in the source service. The consumer performs the conversion of its local records according to the event type.

[0019] like Figure 1 As shown, the system includes a task flow engine service, an approval flow engine service, a budget service, and an event bus. Each service communicates via a network interface and has its own local logical database; compute nodes include processors and memory. Synchronous query and control interfaces between services can use REST or gRPC, the event bus can use RocketMQ, the database can be an independent logical database within TiDB, and Redis serves as an acceleration layer for hot queries or buffered indexes. Events, processing results, counters, and consumption progress are based on persistent database records.

[0020] The task flow engine service stores the worker node, TaskInstanceID, BudgetVersionID, and initialization status of the submission association in the task_instance task record, and the complete binding in the task_approval_binding association table; this document refers to this association table as TaskApprovalBinding. A complete binding includes TaskInstanceID, ApprovalInstanceID, BudgetVersionID, SnapshotFingerprint, and the is_valid flag. A complete binding is not required before a submission association is initialized; after the original association ends, its invalidation status and processing reason are retained. The approval flow engine service stores the approval instance and approval start fingerprint, while the budget service stores the budget version, complete dataset, version status, lock ownership, and accepted approval records.

[0021] The budget service's `budget_version` record is located using `BudgetVersionID`, `lock_task_id` stores the identifier of the occupying task instance, and `lock_approval_id` stores the identifier of the occupying approval instance. After a lock is committed, `lock_task_id` is set to `T` and `lock_approval_id` is empty; after a successful approval initiation event, it is set to `T` and `A`; after a successful write or controlled revocation, both lock ownership fields are cleared. Lock ownership indicates the current eligibility for occupancy; accepted tasks, approval identities, and fingerprints are retained separately and are not deleted when the lock is released.

[0022] Each service also has its own local event table, source count record, processed event table, consumption progress table, ordered buffer table, and anomaly audit record. The local event table retains submitted events awaiting publication and events required for re-pull; the processed event table stores the final processing results of this consumer; the consumption progress table stores the expected sequence number according to the consumer and source sequence; and the ordered buffer table stores events arriving after the gap and the retry context.

[0023] like Figure 2 Step S1 and Figure 4 As shown, after the user fills in and saves the data, the budget service first generates a BudgetVersionID, which is in draft form. Upon the first submission, the task flow engine service creates and persists a TaskInstanceID and its submission association with the BudgetVersionID. If a new task instance has already been created for this compilation cycle due to a previous rejection confirmation, this submission acquires and reuses that new task instance, preventing duplicate instance generation for the same cycle. Approval instances are generated after the task submission event is consumed, without pre-allocation of approval identifiers.

[0024] The task flow engine service first saves the task identifier and commit association in a local transaction, and then synchronously calls the locking interface of the budget service via REST or gRPC. The budget service locks the corresponding version record, verifies the draft status and that the version is not occupied by other commit associations, sets the version to locked, sets lock_task_id to TaskInstanceID, and sets lock_approval_id to null. In this local transaction, it increments the source count and saves the BUDGET_LOCKED event. If the version is already locked by the same commit association, it returns the existing lock result and does not generate a duplicate lock event; if it is occupied by other associations, it does not overwrite the lock ownership.

[0025] After the task flow engine service confirms a successful lock, it marks the task as committed and saves the TASK_SUBMITTED event and source count in its local transaction, then asynchronously publishes the event. The persistence associated with the commit, the locking transaction of the budget service, and the saving of the task commit event are sequentially linked; services do not share cross-database transactions. If a synchronous response is lost, it should be queried or retried based on the original task and version identifier; the lock should not be released or a new task generated simply because the request timed out. The approval instance identifier for both the budget lock event and the task commit event is null, and it is also null if the approval start fingerprint for the task commit event has not yet been formed.

[0026] When the approval flow engine service consumes TASK_SUBMITTED, it first performs deduplication and task source sequence verification. Then, based on the source, TaskInstanceID, and BudgetVersionID, it checks the submission associations that are still in the initialization or submission state, without requiring the approval instance identifier to already exist. This service serially checks approval records with the same submission association within a local transaction. If no approval record exists, it generates an ApprovalInstanceID and synchronously calls the read-only snapshot fingerprint interface of the budget service to obtain the approval start fingerprint F for the version locked by the task. The approval instance, fingerprint F, APPROVAL_INITIATED event, source count, processed event records, and task source consumption progress are submitted together within this local transaction. After submission, the approval initiation event is published asynchronously.

[0027] The read-only snapshot fingerprint interface verifies the locked version and lock task ownership using TaskInstanceID and BudgetVersionID, reads the complete version data according to the unified encoding rules of this embodiment, and returns the fingerprint; this interface does not write the approval instance identifier to the budget service. When the interface fails or the previous commit record is not yet visible, the approval service rolls back the current consumption transaction and retains the event retry, without advancing the expected sequence number of the task source. If the transaction is interrupted before commit, the instance and the initiating event are rolled back together; if it is resubmitted after commit, the original consumption result is returned. If the same commit is associated with an existing approval record, its approval identifier and saved fingerprint should be reused. If the initiating event is not delivered, the original local event is resent, without creating a second approval instance or reassigning the already submitted event sequence number.

[0028] When the task flow engine service reads back its own TASK_SUBMITTED, its node status has been changed from the source transaction to committed. It only saves the processing results without local update actions and advances the consumption progress of the task source. When the budget service consumes this event, it checks the commit association and version ownership, and does not lock the version repeatedly. If the approval initiation event has been processed first, it checks the approval ownership that has been completed under the same task and version. If the approval round has been completed, it checks the accepted approval records and only performs historical processing. This branch without local update actions does not revert the version to the previous state, nor does it wait for the approval ownership to be empty again because another source has completed initialization first.

[0029] APPROVAL_INITIATED carries TaskInstanceID, ApprovalInstanceID, BudgetVersionID, and a fixed fingerprint F. When the task flow engine service consumes this event, it verifies in the local transaction that the commit association in task_instance is still valid and that the three identifiers correspond to the same compilation cycle. It then writes a complete binding to TaskApprovalBinding and sets is_valid to 1, moving the task from committed to approval. It also saves the processed event record and the consumption progress of the approval source. When the same event is resubmitted, the original result is returned; if a complete binding already exists and the identifier and fingerprint match, the original binding is reused; if the original commit association is explicitly canceled or invalidated, the event is ultimately rejected, and a valid binding is not re-established. Temporarily invisible and explicitly invalid events are handled separately; the initialization entry does not wait for a complete binding that has not yet been generated.

[0030] When the budget service consumes APPROVAL_INITIATED, it first obtains a complete and valid binding through the task flow engine service's association query interface, verifies the three identifiers and fingerprint F of the event, then starts a local transaction and locks the corresponding version and consumption progress record. After verifying that the version is locked, lock_task_id equals the event TaskInstanceID, lock_approval_id is empty, and the current data fingerprint matches F, it fills lock_approval_id with the event ApprovalInstanceID, saves the complete binding and approval start fingerprint, writes them to the processed event record, and advances the consumption progress of the approval source. After submission, it confirms delivery. If the task flow engine has not yet completed the complete binding, it retains the event retry option but does not advance the source sequence.

[0031] For duplicate deliveries with the same EventID, the processed result is returned first. If the lock approval ownership is already the same A, it is treated as a duplicate under the condition that the version status, task ownership, complete binding, and fingerprint still match, and the current consumption record is supplemented without modifying the ownership again. If the lock is already held by another valid approval A′, the final rejection and audit reason are saved and an alarm is issued, but A′ is not overwritten. The consumption progress of this source is advanced in the rejection transaction. If the version status or task ownership has been clearly changed, it is also treated as an invalid branch. When the approval flow engine reads back its own APPROVAL_INITIATED, it only saves the result without local update action and advances the progress.

[0032] Within the same task, `APPROVAL_INITIATED` and its subsequent `APPROVAL_PASSED` belong to the same approval source sequence. In this example, the initiating event is sequence number 1, and the passing event is sequence number 2. The budget service only allows sequence number 2 to enter verification after sequence number 1 completes final processing and submits the consumption progress; subsequent approval writes still require complete and valid binding, locked ownership, version status, and fingerprint verification. If sequence number 1 temporarily fails, the expected value 1 is retained, and sequence number 2 enters the ordered buffer; if sequence number 1 is rejected by final processing, subsequent events must still re-execute the above verifications, and the consumption progress itself does not generate approval write eligibility.

[0033] When submitting repeatedly, the task flow engine service first reads the persistent tasks and commit associations corresponding to the current worker node and budget version; if there are records in the same period that are still being initialized or are already valid, the TaskInstanceID is reused. Only after confirming that the transaction that previously created the task has not been committed is a task identifier regenerated. Network request timeout is not itself a criterion for determining whether a transaction has not been committed. Concurrently committed tasks with the same association need to be checked serially within the local transaction; the budget service's verification of version occupancy and lock ownership is also performed under version record row locks.

[0034] After an initialization interruption, the recovery process reads the saved commit associations: if the version is not yet locked, it retryes locking with the original identifier; if it already belongs to the same commit association, it continues publishing or processing the original commit event; if an approval instance has been created but the event submission failed, the original event is resent from the local event table. If a version is already occupied by another commit association, its lock is not overwritten, but the occupancy result is returned for task flow verification. This recovery process does not modify the committed identifier simply because the client clicks the button again.

[0035] like Figure 2As shown in step S2, the common fields of the event record include EventID, SourceService, SourceNode, TaskInstanceID, BudgetVersionID, EventType, SequenceNo, SourceState, TargetState, Timestamp, and Payload. Whether ApprovalInstanceID and SnapshotFingerprint are required depends on the event type and processing stage. SourceService represents the source service identifier and has the same meaning as SourceServiceID; this document uses SourceService uniformly.

[0036] The EventID is a unique identifier for application-layer events, such as a UUID, independent of the delivery identifier assigned by the message middleware. Retransmissions, re-deliveries, and pulls all retain the original EventID, SequenceNo, and payload; the application-layer EventID cannot be replaced with a new delivery identifier. The Timestamp stores the generation time but does not establish a global order between different sources.

[0037] Table 1 Event Type and Stage Fields Event Type Identification and Processing Rules BUDGET_LOCKED Initialization event; includes task and version identifiers, approval identifier can be empty; does not write back approval results based on this. TASK_SUBMITTED Initialization event; includes task and version identifier, approval identifier and approval start fingerprint (optional); triggers the creation of approval instance. APPROVAL_INITIATED Association establishment event; carrying three identifiers and approval start fingerprint, completing valid binding and lock ownership. APPROVAL_PASSED Formal approval event; three identifiers and the fingerprint indicating the start of approval are required fields; budget service execution approval is written into the verification. APPROVAL_REJECTED The formal approval process for the returned case has commenced; after verifying the validity of the case and the original lock ownership, the controlled qualification revocation and unlocking process begins. BUDGET_APPROVAL_APPLIED Write confirmation; has an independent EventID, carrying the original approval result event identifier, three identifiers, and the accepted fingerprint. BUDGET_APPROVAL_REFUSED Refuse to provide feedback; retain the original event identifier, original binding, and reason, and do not replace the old fingerprint with the new fingerprint. BUDGET_UNLOCKED Unlocking and qualification revocation confirmation; in the locked stage, the original lock ownership is verified; in the approved restart stage, the accepted approval identity is verified; does not directly affect new bindings.

[0038] The combination of TaskInstanceID and SourceService is used as the SequenceKey. For task T1, the task flow engine sequence is K_T, the approval flow engine sequence is K_A, and the budget service sequence is K_B, each starting from 1. The consumer maintains an independent NextSequenceNo based on the combination of ConsumerID and SequenceKey, with an initial value of 1 for each. Sequence numbers 2 from different sources under the same task do not represent the same sequence position, and their numerical values ​​cannot be used to compare the order of occurrence across sources.

[0039] The status updates of the source service, the incrementing of the persistent counter, and the writing of the local event table are all performed within the same local transaction. Locking the corresponding counter records or conditional updates prevents multiple service replicas from assigning duplicate sequence numbers to the same sequence; during transaction rollback, all three are rolled back together, leaving no gaps in the counters for events that have been assigned but not yet committed. Committed events are scanned and published by the asynchronous publisher; if publication is successful but the result record fails, the same event can be resent.

[0040] The task flow engine service subscribes to K_T, K_A, and K_B; the approval flow engine service subscribes to K_T and K_A; and the budget service subscribes to K_T, K_A, and K_B. Each consumer receives all state change events for a subscribed sequence key, without further filtering by event type. For events without local state transition actions, only the final processing result is recorded, and the sequence is advanced. When a service receives an event that it has already executed in the source transaction, it does not repeat the source action or generate the same type of event again.

[0041] The approval flow engine service does not maintain consumption progress based on unsubscribed budget source sequences. Control results such as the failure of the original approval instance can be passed by the task flow engine service through a synchronous interface. Control calls still verify the original instance and bindings, and retain control records and retry when they fail; this call is not interpreted as the approval flow engine having subscribed to all budget source events.

[0042] This embodiment employs full version locking. Only one valid approval instance can occupy a budget version at any given time, and all version data write interfaces verify and lock the same version record. During the locking period, normal data editing is prohibited, even if the editing request comes from the same service that initially initiated the locking. The lock is released after successful approval writing, but the approved status is not allowed to be edited normally simply because the lock field is empty; the editing entry must simultaneously verify the version status; subsequent editing requires completing the controlled restart process described below. The approval result only changes the approval status and associated processing records of that version; it does not overwrite the data content of another version.

[0043] The snapshot's data fields are BudgetVersionID, BudgetOrgID, PeriodID, CurrencyCode, ReportItemCode, and BudgetAmount, corresponding to the budget version, budget organization, period, currency, report item, and budget value, respectively. Task status, approval status, version status, event time, and operation logs are not included in the data fingerprint. Data records are sorted sequentially by the record key composed of the first five fields. The record key is unique within the data set; duplicate record keys are handled during data submission validation, and the fingerprint is not determined by the database's random return order.

[0044] Records are serialized according to the fixed order and field types described above. Strings are encoded using UTF-8, and empty string fields are normalized to empty strings. Budget values ​​are represented using fixed-point numbers to two decimal places, and empty values ​​are normalized to 0.00; floating-point representation is not used. The same value, 150000000, is encoded as the same fixed-point content as 1500000000.00. An encoding method is used to concatenate records according to field type, content byte length, and content, while preserving record boundaries to ensure the connection relationship of consecutive fields is deterministic. SHA-256 operations are performed on the serialized bytes of the sorted records to generate a budget snapshot fingerprint.

[0045] For example, a set of budget records for version V2026_01_001, organization ORG-HQ-001, period 2026-Y, and currency CNY would be: REV-001 corresponds to 150,000,000.00, REV-002 corresponds to 80,000,000.00, and COST-001 corresponds to 95,000,000.00. After sorting by record key, the item order is COST-001, REV-001, REV-002, and then fingerprints are calculated according to the same field range and encoding rules. The following uses F1, F2, or F-abc123 as symbols to represent fingerprint values; the actual record stores the complete fingerprint value obtained from the SHA-256 calculation.

[0046] The budget service calculates a data fingerprint when the data is locked. The approval flow engine saves the fingerprint of the locked data at the start of the approval process and keeps it unchanged throughout the approval process. The approval result event copies the fingerprint from the start of the approval process and does not change it to the fingerprint of the current new data at the end of the approval process. When the budget service writes data, it recalculates the current fingerprint within the consistent read scope of the local transaction. It compares the event fingerprint, the fingerprint saved in the valid binding, and the current fingerprint. Only when all three are consistent, and the version identity, allowed status, and lock ownership are consistent, is the version status updated.

[0047] Fingerprint comparison follows the above-mentioned normalized semantics: null values ​​and 0.00, and null strings and empty strings are identical after normalization, and this is not considered a data conflict; when budget values, record additions / deletions, or other participating fields undergo changes that are distinguishable after normalization, the serialized input changes accordingly. Normalization does not grant any write-back eligibility to erroneous versions or invalid approvals; the event identifier and valid binding are still checked separately.

[0048] like Figure 3As shown, after receiving an event, the consumer first queries the processed event table using ConsumerID and EventID. If there are final results such as executed, rejected, or no local action, the consumer verifies that the source, sequence number, and payload of the saved event are consistent, returns the original result, and confirms the delivery. If the same event identifier corresponds to different sources, sequence numbers, or payloads, a conflict record is saved and the corresponding sequence is paused; this is not considered a normal re-delivery of the same event. If only buffered or pending retry records exist, they cannot be considered successfully processed and should be merged into existing pending records. The processed event table sets unique constraints on ConsumerID and EventID, and the buffer table sets unique constraints on the consumption progress key and SequenceNo.

[0049] For unprocessed events, read the corresponding NextSequenceNo. If the event sequence number is greater than the expected value, persist the buffer and record the missing position and start waiting time, and do not execute its state action; if it is less than the expected value, process it as expired and do not write back to the target state. If different EventIDs or the same event identifier corresponds to different payloads at the same sequence position, save the conflict record and pause the sequence, and do not overwrite the conflict content with the first one to arrive.

[0050] When the sequence number equals the expected value, the processing branch is entered according to EventType. BUDGET_LOCKED and TASK_SUBMITTED are associated with existing tasks and budget versions; APPROVAL_INITIATED enters the valid binding establishment or completion branch; official results such as APPROVAL_PASSED enter the complete valid binding and snapshot verification branch. Initial events lacking an approval identifier that has not yet been created do not constitute historical invalidity; official approval results lacking a required approval identifier or inconsistent with valid bindings cannot be written back.

[0051] Dependencies between events from different sources are verified based on persistent records, not through cross-source sequence number comparisons. For example, if the budget service processes an approval initiation event before the task flow engine service, the complete association may not be visible temporarily. The budget service maintains the expected value of the approval source unchanged and saves for retry; once the association is formed, processing continues, and approval events from the same source are then allowed. The explicit invalidation of an old record and the absence of a new record represent different processing outcomes.

[0052] When the consumer processes events requiring local state transitions, it initiates a local transaction, locks the consumption progress record, re-verifies the expected sequence number and processing record, and commits the local state update, processed event records, and expected value advancement within the same transaction. When derived state events are needed, the local event record and corresponding source count are saved together. Messages are only acknowledged after the transaction is committed. After successful processing or final rejection, the next consecutive buffer position is checked, and processing continues until there are no consecutive events or a temporary condition is not met.

[0053] In the event of a failure before transaction commit, the status, logs, and progress are rolled back together and reprocessed after resubmission. If a failure occurs after transaction commit but before delivery confirmation, the resubmission event reads the original final result and does not update the status again. For historical events that are clearly invalid, have incorrect version identities, or are no longer allowed to execute, the target record is not modified; the rejection record, audit reason, and consumption progress are saved along with the transaction. For events where the preceding record has not been synchronized, the service is unreachable, or the database transaction has failed, the original expected value is maintained, the event is retained, and retrying is performed.

[0054] like Figure 4 As shown, after the approval flow engine forms an approval decision, it issues an APPROVAL_PASSED. When the task flow engine receives this event, it only saves the associated information and does not directly complete the task. The budget service sequentially performs deduplication, source sequence verification, full binding, and snapshot verification, locks the corresponding version record in the local transaction, and verifies TaskInstanceID, ApprovalInstanceID, BudgetVersionID, locked status, and data fingerprint.

[0055] Other data writes, lock ownership completion, and eligibility revocation in the budget service also lock the version record, therefore data cannot be modified by bypassing the version lock after fingerprint reading and before approval status writing. Upon successful verification, the budget service sets the version to approved, saves the accepted task, approval instance, and fingerprint, and clears lock_task_id and lock_approval_id; within the same transaction, it saves processed event records, consumption progress, and BUDGET_APPROVAL_APPLIED local event records and source counts. Lock release only ends the current round of holding; accepted approval records and valid bindings continue to be used for confirmation, verification, and historical auditing. Confirmation events include a unique EventID, the original approval result event identifier, three binding identifiers, the accepted fingerprint, and the write result.

[0056] Confirmation events are published asynchronously through the local event table. Scanning for unpublished records continues even if publication is incomplete or the service restarts. If a message was successfully sent but the result was not recorded, the same confirmation event is resent. Upon receiving a confirmation event, the task flow engine verifies the budget service source, source sequence, currently valid tasks, and complete bindings. Within the local transaction, it marks the task as completed, records the processing result, advances the consumption progress, and then schedules subsequent worker nodes.

[0057] If the version, fingerprint, or lock attribution does not match, the budget service will not write the approved status, but will save the reason and BUDGET_APPROVAL_REFUSED record in the final rejection transaction. Rejection feedback retains the original event and binding information, and does not replace the old event's version or fingerprint with the new value. Control events that only notify the rejection reason do not perform budget data writing, and do not require the current fingerprint, which has already clashed, to be equal to the old fingerprint again, but still verify the notification source and the original event attribution.

[0058] When handling rejection feedback, the task flow engine first distinguishes between current and historical tasks: if the feedback belongs to a currently valid approval and not yet completed task, the task's incomplete status is retained and it enters the verification or controlled return process, and the rejection handling for the same original event is only established once; if the feedback belongs to an old task that has expired, an old approval that has been processed, or an association that has been replaced by a new task, only the historical processing is recorded, the version of the new task is not unlocked, the currently valid binding is not modified, and the next round of tasks is not created again.

[0059] Sequence number gap detection only identifies missing sequences when a larger sequence number is received. If the write acknowledgment is the last event in the source sequence and no subsequent events arrive, the acknowledgment event cannot be considered delivered solely based on the absence of a gap. Recovery relies on unpublished event scanning, retransmission of unsuccessfully consumed messages by the message middleware, and dead-letter handling of failed messages. The task will not enter the completed state until acknowledgment is obtained at the task end. If retries still fail to recover, the incomplete state and exception record are retained, an alarm is triggered, and the process transitions to dead-letter handling recovery.

[0060] When the waiting time stored on the consumer side exceeds the threshold, the event query interface of the source service is called by TaskInstanceID, SourceService, and missing SequenceNo to query the committed events from the current expected sequence number to the current maximum received sequence number, without reading across tasks or sources. The original EventID, SequenceNo, and payload are returned, and the consumption verification is restarted. Version or binding verification is not exempted because the data comes from the pull interface.

[0061] For example, the budget service expects K_A to be 1, but receives approval event number 2 first, buffering event 2. If it still hasn't received sequence number 1 after 30 seconds, it pulls APPROVAL_INITIATED, obtains the complete association according to the phase rules, completes the local lock ownership, advances the expected value to 2, and then processes approval event 2. 30 seconds is a configuration example; if the pull fails a certain number of times, such as 3 times, a dead letter record is saved and an alarm is triggered.

[0062] Dead-letter logs store the consumer's information, sequence key, missing position, buffered events, number of pull attempts, cause of failure, and handling result. If a threshold is reached, missing positions are not skipped, and subsequent events are not marked as executed. If the source event is recovered, the original event is retrieved, and processing continues from the original position; if the original event cannot be recovered, the sequence remains paused, and maintenance personnel check the source event table and version records to determine the recovery operation. When the original controlled binding fails and a new task is created, the new task uses a new sequence key, and the original dead-letter log and progress are saved as history.

[0063] When the service restarts, buffered events are restored from the ordered buffer table, timers are restored from the missing positions and start wait times, and expected values ​​are restored from the consumption progress table. The event retention period covers the maximum retry cycle and the pull window; if there are still unprocessed consumption events or unresolved exceptions, the corresponding events and historical bindings are retained. The only retrievable record should not be deleted simply because the fixed retention period has expired. Loss of Redis cached data does not change the processed results and progress in the database.

[0064] like Figure 5 As shown, the normal budget version status is in the following order: Draft, Locked, Approved, Published, and Archived. Submitting a version lock establishes a complete association, keeping the entire version data unchanged. Once the approval result is successfully written, it becomes "Approved." After the corresponding task is completed, it can be published, and after archiving, it becomes a read-only historical file. Re-compiling after publishing or archiving creates a new BudgetVersionID, and does not unconditionally restore the draft version from the original.

[0065] Upon receiving a valid rejection decision, the budget service verifies the original valid bindings, locked status, and task and approval lock ownership. In the local transaction of the version record, it revokes the write eligibility for the approval, clears the two lock ownership fields, and reverts the version to draft. It also saves the BUDGET_UNLOCKED confirmation event and source count. After obtaining confirmation, the task flow engine invalidates the original bindings and creates a new task instance T2 for the rejected work node. This new task is reused upon resubmission, and the approval flow engine consumes its submission event before generating a new approval instance A2.

[0066] When canceling the compilation during the initialization phase, verify that the original TaskInstanceID, BudgetVersionID, locked status, and lock_approval_id are empty, and confirm that the submission association has not yet entered a valid approval process. The budget service clears the ownership within the version record line lock, returns a draft, and saves confirmation; the task flow engine closes the submission association based on the confirmation, retaining the cancellation result. It cannot be concluded that the approval instance was never created simply because lock_approval_id is empty; if approval has started but lock ownership has not been completed, it should be handled according to the controlled termination process for the corresponding approval. Delayed approval initiation events still require verification of the submission association's valid status, version status, and original task ownership; they cannot restore already closed associations, nor can they re-occupy versions that have been released or locked by new tasks.

[0067] Cancellation, attribution completion, approval write, and controlled revocation all lock the same budget version record: If cancellation is submitted first, a late attribution completion will be rejected because the version is no longer in the locked state of the original task; if attribution completion is submitted first, a normal cancellation is no longer applicable because the approval attribution is no longer empty, and controlled termination or rollback must be performed after verifying complete binding. If the version is already locked by a new task or new approval when an old unlock request arrives, the task or approval attribution is inconsistent, and the new lock cannot be released.

[0068] When an approved version that has not been published or archived is restarted, the original lock has already been released in the successful approval write transaction. The budget service verifies that the version is still approved, and that the saved accepted tasks, approval instances, and original valid bindings match. In the local transaction of the version record, it revokes the original approval write qualification, restores the version to draft, and saves the confirmation event. After the task flow engine obtains confirmation, it invalidates the original binding and creates a new task. This branch verifies the original approval as an accepted approval, and does not require that the cleared lock field be equal to the old approval identifier again. Historical acceptance records and original processing results are retained, and subsequent old results cannot regain write qualification.

[0069] Attribution completion, approval write, qualification revocation, and relocking are all committed sequentially to the same version record. When an old approval write is committed first, its historical acceptance results are saved, and then the branch is restarted for processing as an approved version. When qualification revocation is committed first, the old write is rejected due to version status or attribution mismatch. Published or archived versions are not included in the above-mentioned original version restart branch; the original binding is invalidated when it ends, and subsequent adjustments create a new budget version.

[0070] When recompiling on an unreleased or archived version V1, the BudgetVersionID is retained. New tasks, approvals, and data content form new bindings T2, A2, V1, and F2. Other tasks independently create V2, or users only switch display versions, without automatically invalidating the original T1 binding; only when V2 actually replaces the same pending approval object is the old binding controlled to be invalidated and a new binding established for the new task. Switching front-end dimensions only changes the query conditions; write requests continue to explicitly carry their target budget version.

[0071] The following example of events and data states illustrates the processing procedure of this method. For T1 and V1, the budget service first publishes BUDGET_LOCKED with K_B sequence number 1, where the approval identifier is empty; the task flow engine publishes TASK_SUBMITTED with K_T sequence number 1, where the approval identifier and approval start fingerprint can be empty. Based on this, the approval flow engine generates A1 and F1, and publishes APPROVAL_INITIATED with K_A sequence number 1; after the complete association is formed, the approval event is K_A sequence number 2. The budget service accepts this event, sets V1 as approved in the same transaction, retains the accepted T1, A1, F1, clears lock ownership, and saves the confirmation event of K_B sequence number 2, and then publishes this event. The task flow engine finally completes T1.

[0072] If the same event arrives repeatedly, the consumer returns the original final processing result. If the approved event arrives at the budget service before the initiating event, the approved event is buffered first, and the initiating position is filled in. Even if the task receives the approved event first, the task remains incomplete while the confirmation event has not yet arrived. The sequence number 1 for each source exists separately and is not merged into a global sequence number 1.

[0073] The example of intercepting old approvals assumes that the original approval has been controlled and expired, and the old event has not yet been finalized on the consumer side: When the old event arrives late for the first time, it is rejected according to the old binding, and the rejection record and historical feedback are saved. If the same EventID has been processed before, the idempotent branch is hit first to return the original result, and the binding and fingerprint verification are not repeated for the processed event. If T2 is already valid when the old feedback arrives, only the history of T1 is retained, and T3 is not created again.

[0074] Annual budgets, budget adjustments, and N+3 rolling forecasts can all serve as data sources. N represents the number of months that have occurred, and 3 represents the forecast period of three months. Months that have occurred can display actual figures and are read-only. Future forecast results are saved as independent versions and then undergo the same submission, approval, and confirmation process. Specific trend forecast formulas, deviation warning ratios, and business approval permissions are not considered necessary technical features for the synchronization of event status in this case.

[0075] The system's processors execute programs stored in memory, performing tasks such as submission association management, approval instance management, budget version management, event verification, exception compensation, and auditing. The task service manages pending associations and ensures complete and valid bindings; the approval service generates instances based on submission events and fixes the approval start fingerprint; the budget service verifies lock ownership and persists the results after snapshotting; each consumer performs event deduplication, source sequence comparison, stage branching, and progress submission based on its local table. Each processing unit is deployed as a software module within its corresponding service and communicates via an event bus and synchronization interface.

[0076] The computer-readable storage medium can be a disk, solid-state drive, or other media for storing programs; when the processor reads and executes the program, steps S1 to S5 and the corresponding recovery process are implemented. The output includes instance associations, version status, consumption progress, write acknowledgments, and exception records in the database. Local transaction results are reliably linked between services, and it is not required that three independent databases share a single cross-database transaction.

Claims

1. A budget process state synchronization method based on event sequence verification, comprising passing events between a task flow engine service, an approval flow engine service and a budget service communicating through an event bus, characterized in that, Includes the following steps: S1. Establish a submission association between the task instance identifier and the budget version identifier, and lock the corresponding budget version in the budget service; S2. The source service commits the state update, event record, and corresponding count increment in the same local transaction, and then publishes the event record; using the combination of the task instance identifier and the source service identifier as the sequence key, the event sequence number is generated in a continuously increasing manner according to the sequence key; S3. On the consumer side, deduplication is performed by event identifier. The event sequence number and the expected sequence number are compared by the consumer identifier and the sequence key. Events with a greater than the expected sequence number are persisted in the buffer. For the initialization event at the expected sequence position, verify the submission association. After the approval flow engine service consumes the task submission event, create an approval instance, save the budget snapshot fingerprint at the start of the approval and generate an approval initiation event according to S2. Based on this, the task flow engine service establishes a valid binding including the task instance identifier, approval instance identifier, budget version identifier and the budget snapshot fingerprint. The budget service consumes the approval initiation event and completes the lock ownership. S4. For approval events at the expected sequence position, the budget service verifies the valid binding, lock ownership and version status, and compares the budget snapshot fingerprint carried by the event, the budget snapshot fingerprint saved in the valid binding and the current data fingerprint. After the verification is successful, commit the version status update, processed event records, consumption progress and write confirmation event records in the same local transaction; S5. After publishing the write confirmation event, the task flow engine service verifies the source and valid binding, and submits the task completion status, processed event records and consumption progress in the same local transaction; each consumer continues to process the next consecutive buffer event after advancing the expected sequence number.

2. The budget flow state synchronization method of claim 1, wherein, The task flow engine service stores the submission association corresponding to the task instance identifier and the budget version identifier in the local task record. After receiving the approval initiation event and verifying the submission association, it writes the task instance identifier, approval instance identifier, budget version identifier, budget snapshot fingerprint, and validity flag into the local association table. The same task instance and the same budget version can correspond to at most one valid approval instance at any given time. The budget lock event and task submission event before the approval instance is created do not carry the approval instance identifier, while the approval initiation event, approval result event, and write confirmation event carry the three identifiers.

3. The budget process status synchronization method according to claim 1, characterized in that, Each consumer receives all state change events corresponding to a subscribed sequence key and persists the expected sequence number for each. For events without local state transition actions, the processing results are saved and the corresponding consumption progress is advanced. The same event that is resent, re-delivered, or re-pulled retains the original event identifier, event sequence number, and payload. Event identifiers and message middleware delivery identifiers are independent of each other.

4. The budget process status synchronization method according to claim 1, characterized in that, The generation of the budget snapshot fingerprint includes: reading the complete data set of the locked budget version, sorting it according to the record key composed of budget version identifier, budget organization identifier, period identifier, currency code and report item code, normalizing and serializing the above fields and budget values ​​according to the preset field order and field type, and performing a hash operation on the serialization result; task status, approval status, version status, event time and operation log are not involved in the serialization.

5. The budget process status synchronization method according to claim 1, characterized in that, The consumer persists events with serial numbers greater than the expected sequence number and their missing locations. After a timeout, it retrieves the events from the local event table from the source service using the sequence key and the missing sequence number, and then re-executes the validation. Events with serial numbers less than the expected sequence number are expired. For events that are clearly invalid, save the rejection result and advance the expected sequence number. For events where the association has not been established, the preceding record has not been synchronized, or the transaction has failed, retain the original expected sequence number. When different event identifiers or different loads appear at the same sequence position, save the conflict record and pause the sequence. When the number of failed pulls reaches a preset number, save the dead letter record and retain the missing position.

6. The budget process status synchronization method according to claim 1, characterized in that, The budget service locks the corresponding version record in the local transaction that executes the approval result writing, calculates the current data fingerprint within the consistent read range of the same transaction, verifies that the budget version is in a locked state and that the three binding identifiers match, updates the version status to approved, saves the accepted approval identity and budget snapshot fingerprint, and clears the lock ownership; the write confirmation event has an independent event identifier and carries the original approval result event identifier, the three binding identifiers, and the accepted budget snapshot fingerprint; Unpublished events in the local event table will continue to be published after the service is restored.

7. The budget process status synchronization method according to claim 1, characterized in that, When an approval is rejected, the budget service verifies the original lock ownership, revokes the write privileges of the original approval instance, and unlocks the file in the local transaction of the corresponding version record. When an approved version that has not been published or archived is restarted, the accepted approval identity is verified in the local transaction and the write qualification of the original approval instance is revoked. The budget service issues a corresponding confirmation event; the task flow engine service invalidates the original binding and creates a new task instance based on the confirmation event, and after resubmission, a new approval instance and budget snapshot fingerprint are formed; for rejection feedback of historical tasks that have expired, only the historical processing record is saved, and the current valid task and its budget version are not updated.

8. The budget process status synchronization method according to claim 2, characterized in that, In the lock submission transaction, the budget service writes the task instance identifier to the lock ownership of the corresponding budget version and sets the approval instance identifier to null. When the consumption approval initiates an event, it obtains a complete and valid binding, checks the locked status and the task instance identifier in the local transaction of the lock version record, adds the approval instance identifier carried by the event to the lock ownership, and saves the processed event record and consumption progress. Ownership completion, approval writing, write qualification revocation, and relocking are all submitted in the local transaction of the lock version record. The published or archived budget version retains the original data, and the recompiled data is saved in the new budget version; switching display dimensions does not change the binding identifier carried by the event.

9. A budget process status synchronization system based on event sequence verification, comprising a task flow engine service, an approval flow engine service, and a budget service communicating via an event bus, characterized in that: Each service has its own local data storage. The local data storage includes a local event table, processed event records, consumption progress records, and an ordered buffer table. The task flow engine service's database is set up to store task records associated with submissions and a table to store validly bound associations. The system includes one or more processors and a memory, wherein a computer program stored in the memory, when executed by the processor, implements the budget process state synchronization method as described in any one of claims 1 to 8.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the budget process state synchronization method as described in any one of claims 1 to 8.