A lightweight approval process control method and system based on batch pre-allocation of tasks
By optimizing batch pre-creating of approval task records and memory grouping queries, the problem of frequent database queries in traditional approval processes has been solved, achieving efficient and secure lightweight approval process control and improving response speed and throughput.
Patent Information
- Application Number
- CN202611306159.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies require frequent database queries when querying approval processes, leading to performance bottlenecks and poor user experience, especially with excessively long loading times in scenarios with tens of thousands of instances.
By pre-creating approval task records for all nodes in batches when the process starts, and using three batch SQL queries plus memory grouping to reduce the number of database interactions, combined with lazy parsing and optimistic locking control, high concurrency safety and smooth transition of process configuration changes are achieved.
It significantly improves the response speed and throughput of the approval process, reduces database query latency, supports process configuration changes and security in high-concurrency scenarios, and enhances the user experience.
Smart Images

Figure CN123118022A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of enterprise information management and process control technology, and in particular to a lightweight approval process control method and system based on batch pre-allocation of tasks. Background Technology
[0002] With the deepening development of enterprise informatization, business process management systems have become an important support platform for daily operations. Approval processes, as one of the core functions of business process management, handle the flow control of various business matters, such as work hour adjustment applications, travel scheduling approvals, expense reimbursement processes, and material requisition approvals. Currently, the mainstream implementation methods for approval processes mainly utilize workflow engine technologies such as Activiti, Flowable, and Camunda.
[0003] However, existing technologies have significant performance deficiencies in approval list queries and process progress display. Specifically, traditional workflow engines need to query the corresponding process node configuration, approval operation records, and approval task information for each approval instance when querying the approval list page. When the page displays N approval instances, the system needs to perform N×3 independent database query operations (i.e., querying the node table, record table, and task table once for each instance). Taking 20 instances per page as an example, a single list loading requires 60 database queries; when the number of approval instances reaches tens of thousands, the query-by-item mode will generate tens of thousands of database round trips, resulting in an approval list loading time of several seconds, seriously affecting the user experience and the overall system throughput. The root cause of this deficiency is that traditional solutions store approval tasks and process node configurations separately and do not pre-generate task records for each node when the process starts. This results in the need to query multiple related tables in real time and item by item every time the process progress is displayed, making it impossible to reduce the frequency of database interactions through batch operations. Summary of the Invention
[0004] This invention provides a lightweight approval process control method and system based on batch pre-allocation of tasks, which enables a smooth transition of configuration changes.
[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows: Firstly, a lightweight approval process control method based on batch pre-allocated tasks, the method comprising: Construct a process definition table and a process node table to store metadata information of the approval process; the process definition table records the process identifier, process name and process status; the process node table records the node identifier, node order, node name, approval type, approver identifier or role identifier and department scope of each approval node; When a user initiates an approval process, the validity of the process definition is verified, and the configuration information of all approval nodes under that process is obtained. Create an approval instance, and based on the configuration information of all approval nodes, pre-create approval task records for all nodes in batches using a single multi-value INSERT statement; each approval task record includes instance identifier, node identifier, node name, node order, approver identifier, approver name, and task status; When an approver processes an approval task, they perform permission verification based on the task status and node configuration. After approval, the approver information is directly retrieved from the pre-created next node task record, and the current node and current approver of the approval instance are updated without additional database queries to obtain the approver. For tasks marked with placeholders, lazy resolution is triggered when the task is transferred to that node, and the approver is re-matched and the corresponding task record is updated based on the latest node configuration. When the last node is approved, the process ends, and the approval result is automatically updated to the business table associated with the business identifier and business type fields.
[0006] Secondly, a lightweight approval process control system based on batch pre-allocated tasks includes: The process definition management module is used to build and maintain process definition tables and process node tables, and store metadata information of approval processes, including process identifier, process name, process status, as well as node identifier, node order, node name, approval type, approver identifier or role identifier and department scope for each approval node. The batch pre-allocation module is used to verify the validity of the process definition when a user initiates an approval process, obtain the configuration of all approval nodes, and pre-create the approval task records of all nodes in batches using a single multi-value INSERT statement. The batch pre-allocation module includes a placeholder parsing unit, which is used to use the actual approver identifier for the first node, set placeholder markers for subsequent nodes when matching fails, and trigger lazy parsing to update the approver information when the flow reaches the placeholder node. The batch pre-allocation module also includes a signature addition / reduction adaptation unit, which is used to dynamically insert or cancel node tasks and partially update the node order during process execution. The approval workflow module is used to perform permission verification when the approver processes the approval task. After the approval is approved, the approver information is directly obtained from the pre-created next node task record and the current node and current approver of the approval instance are updated. The approval workflow module includes a concurrency control unit, which is used to achieve approval security in high-concurrency scenarios through transaction-level implicit mutual exclusion and optimistic locking version number control.
[0007] The above-described solution of the present invention has at least the following beneficial effects: By pre-creating approval task records for all nodes in batches at the start of the process, and employing three batch SQL queries plus memory grouping during list queries, the traditional N×3 database interactions are reduced to a fixed 3, independent of the number of instances. Real-world testing shows that the end-to-end list response time for 20 instances per page is reduced from 4.2 seconds to 0.35 seconds, a 91.7% improvement; and the memory grouping time in a scenario with tens of thousands of instances is reduced from 1200ms to 95ms, a 92% improvement.
[0008] The approval workflow requires zero additional queries, reducing latency per operation. Since approval tasks for all nodes are pre-assigned at workflow initiation, the next approver is retrieved directly from the pre-created task records during workflow transition, eliminating the need for real-time queries to node configuration tables or user role tables. The number of database queries per approval workflow is reduced from 5-8 times in the traditional method to 2-3 times, and the approval workflow response time is reduced from an average of 200ms to 50ms, an improvement of 75%.
[0009] For subsequent nodes where the approver cannot be determined at the start of the process, placeholders are used instead of skipping creation to ensure the integrity of the task structure. Lazy resolution is triggered when the workflow reaches that node, and the approver is dynamically matched according to the latest configuration. This mechanism retains the performance advantages of batch pre-allocation while being compatible with runtime change scenarios such as undetermined conditional branches, approver changes, and dynamic addition and subtraction of signatures.
[0010] By implementing transaction-level implicit mutual exclusion to protect against duplicate approvals in CAS semantics, and combining optimistic locking version number control to achieve instance-level concurrent conflict detection, the system achieves zero dirty reads and zero duplicate approvals in a scenario with 100 concurrent approvals of the same instance, with a throughput of 85 TPS, which is 27% higher than the traditional row-level locking solution.
[0011] Through node identifier anchoring mapping, real-time configuration resolution, and a three-level display name priority backtracking mechanism, the system supports changes to process definitions during runtime. Historically pre-assigned tasks automatically adapt to the new version's node configuration, and completed approval records retain historical snapshots for auditing, achieving a smooth transition of configuration changes. Attached Figure Description
[0012] Figure 1 This is a flowchart illustrating a lightweight approval process control method based on batch pre-allocation of tasks provided in an embodiment of the present invention.
[0013] Figure 2 This is a schematic diagram of a lightweight approval process control system based on batch pre-allocation of tasks provided by an embodiment of the present invention. Detailed Implementation
[0014] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0015] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0016] This embodiment provides a lightweight approval process control method based on batch pre-allocation of tasks. This method can be applied to enterprise-level business process management platforms to achieve efficient flow control of multi-node approval processes. Figure 1 As shown, the overall system architecture in this embodiment adopts a front-end and back-end separation deployment approach. The front-end is responsible for rendering the user interface and submitting operation commands, while the back-end is responsible for the logical processing of the approval process and data persistence. The database is responsible for storing data such as process definitions, approval instances, approval tasks, and approval records. The back-end service integrates a process definition management module, a batch pre-allocation module, and an approval workflow module. These modules interact with each other through internal interfaces to jointly complete the full lifecycle management of the approval process.
[0017] like Figure 2 As shown, the approval process control method in this embodiment includes the following steps: Step 1: Process definition and node configuration.
[0018] During system initialization or when adding a new approval process, administrators construct a process definition table and a process node table through the process definition management module to store metadata information for the approval process. The process definition table records the basic attributes of each approval process, including fields such as process identifier, process name, and process status. The process identifier serves as a unique identifier for each approval process, ensuring it is not repeated globally within the system; the process name displays the name of the business matter corresponding to the approval process to the user; and the process status indicates whether the process definition is currently enabled. Only process definitions in the enabled state can be used by users to initiate approval instances.
[0019] The process node table records the configuration information of each approval node under each approval process, including fields such as node identifier, node order, node name, approval type, approver identifier or role identifier, and department scope. The node identifier serves as a unique identifier for each approval node, used in conjunction with the process identifier to uniquely locate a specific approval node within a given process. The node order is an integer value indicating the execution sequence of the node in the approval process; the system flows sequentially from smallest to largest node order. The node name displays the business meaning of the approval node to the user. The approval type distinguishes the method of determining the approver for this node, including two values: specified personnel type and specified role type. When the approval type is specified personnel type, the approver identifier field stores the unique identifier of the specific approver user. When the approval type is specified role type, the role identifier field stores the unique identifier of the corresponding role; the system dynamically matches the specific approver user based on this role identifier during runtime. The department scope field controls the query scope of the approver for each role type, including two values: department scope and company-wide scope.
[0020] The process definition table and the process node table establish a one-to-many relationship through the process identifier field, meaning that one process definition corresponds to multiple process node configurations. When an administrator modifies a process definition or node configuration, the system updates the records in the corresponding tables and triggers the cache invalidation mechanism, which will be described in detail later, to ensure that running approval instances can obtain the latest configuration information.
[0021] Step 2: Create approval instances and pre-allocate tasks in batches.
[0022] When a user initiates an approval request through the front-end interface, the system first verifies the validity of the selected process definition. Specifically, the system queries the process definition table based on the process identifier submitted by the user, checking if the process definition exists and if the process status is enabled. If the process definition does not exist or has been disabled, the system returns an error message to the front-end and terminates the initiation operation. If the process definition is valid, the system queries the process node table based on the process identifier for all approval node configuration information under that process, and sorts them in ascending order according to the node sequence field to obtain an ordered list of node configurations.
[0023] After obtaining the configuration information for all approval nodes, the system creates approval instance records. These records are stored in the approval instance table and include fields such as instance identifier, process identifier, initiator identifier, initiator name, business identifier, business type, current node identifier, current approver identifier, current approver name, instance status, version number, and creation time. Specifically, the instance identifier serves as a unique identifier for each approval instance; the business identifier and business type associate the approval instance with a specific business table record, with the business type distinguishing different types of business items, and the business identifier pointing to the primary key record in the corresponding business table; the current node identifier and current approver identifier record the current position of the approval instance; the instance status includes values such as in progress, approved, rejected, withdrawn, and canceled; and the version number field is used for optimistic locking concurrency control, which will be described in detail later.
[0024] After creating an approval instance, the system uses a single multi-value insert statement to pre-create approval task records for all nodes under that instance, based on the previously obtained approval node configuration information. Approval task records are stored in the approval task table. Each record includes fields such as task identifier, instance identifier, node identifier, node name, node order, approver identifier, approver name, and task status. Specifically, the task identifier is a unique identifier for each approval task; the instance identifier associates the task with its respective approval instance; the node identifier and node order anchor the task to the corresponding process node configuration; the approver identifier and approver name pre-assign the approver for that node; and the task status includes values such as pending, completed, returned, and canceled. Initially, all node task statuses except the first node are set to the pending state, while the first node's task status is set to the pending state.
[0025] During the batch pre-creation of approval task records, the system employs a placeholder resolution mechanism to handle nodes where the approver cannot be determined at the start of the process. Specifically, for the first node, the system uses the actual approver identifier determined by the initiator when submitting the application on the front end for pre-assignment, ensuring that the task at the first node can be processed immediately by the corresponding approver. For subsequent nodes, the system attempts to match the approver according to the node configuration: when the approval type is a specified personnel type, the approver identifier in the node configuration is used directly; when the approval type is a specified role type, the system calls the approver matching method to query the corresponding approver user based on the initiator's department and the role identifier configured in the node. If the match is successful, the retrieved approver identifier and approver name are filled into the task record; if the match fails, for example, if there is no user with the specified role in the department, the system sets the approver identifier of the task record to zero as a placeholder, leaves the approver name field blank, and preserves the structural integrity of the task record.
[0026] Task records marked with placeholders trigger lazy resolution when the workflow reaches that node. When the approval workflow reaches a node with a placeholder, the system pauses the workflow, calls the approver information population method, and re-executes the approver matching logic based on the latest node configuration. After matching is complete, the system writes the matched approver identifier and approver name into the corresponding fields of the task record using the task update method, updates the task status to pending, and then resumes normal workflow. This lazy resolution mechanism ensures that pre-assigned tasks can still correctly point to the actual approver in scenarios such as undetermined conditional branches, approver changes, or departmental personnel adjustments, rather than blindly skipping nodes where the approver cannot be determined when the workflow starts.
[0027] The batch pre-creation of approval task records is implemented using a loop-based tag-based single multi-value insert statement within an Object-Relational Mapping (ORM) framework. The system combines all task records from all nodes into a single COMMIT statement, separated by commas, and submits it to the database for execution in one go, thus completing the insertion of all task records in a single database round trip. At the database connection level, the system is configured with batch rewrite parameters, enabling the database driver to automatically rewrite received multiple insert statements into a single multi-value insert statement, further reducing network round trips. To prevent single statements from exceeding the database's maximum data packet limit, the system sets a batch size threshold. When the number of task records to be inserted exceeds this threshold, the system submits the task records in batches, with each batch containing no more than the threshold.
[0028] Building upon the batch pre-allocation mechanism, the system further supports dynamic signature addition and removal operations during workflow execution. When a signature addition operation occurs during the approval process—that is, when the approver requests the insertion of a new approval node between the current node and the next node—the system inserts a new pending task record at the target node position. The node order of this new task record is set to the order value of the target position, and the node order values of all subsequent task records are sequentially incremented to ensure the continuity and uniqueness of the node order. When a signature removal operation occurs—that is, when the approver requests to skip an unprocessed approval node—the system sets the task status of the target node to the canceled state, then directly activates the task of the next node, updates the task status of the next node to the pending state, and updates the current node information of the approval instance. Since the pre-created task records support the creation of a composite index based on instance identifier and node order, signature addition and removal operations only need to update the relevant local task records, without affecting the integrity of the overall pre-allocated task structure.
[0029] Step 3: Synchronize the approval process and status.
[0030] After the approver finds their assigned approval task in the front-end to-do list, they click to enter the approval processing page. When the system loads the approval processing page, it queries the approval task table based on the task identifier, verifies whether the task status is "pending," and checks whether the task's node identifier matches the current node identifier of the approval instance. It also verifies whether the approval instance's status is "in progress." These three checks ensure the legality of the current operation and data consistency. If any check fails, the system returns a corresponding error message to the front-end.
[0031] After the approver fills in their approval comments and selects "Approved" on the approval processing page, the system executes the approval workflow logic. First, the system updates the task status of the current node's approval task record to "Completed" and adds a new approval operation record to the approval record table. The approval record table includes fields such as record identifier, instance identifier, node identifier, node name, approver identifier, approver name, approval comments, approval result, and approval time. This table is used to completely retain the approval operation history of each node, supporting subsequent auditing and traceability.
[0032] Subsequently, the system queries the pre-created approval task record for the next node based on the node sequence value of the current node. Since the approval tasks for all nodes have been pre-created in batches when the process starts, the system directly obtains the approver identifier and approver name for the next node from the pre-created task record, without needing to additionally query the process node configuration table or user role table to obtain approver information. If the next node task record contains a placeholder marker, the system triggers the aforementioned lazy resolution mechanism, re-matches the approver according to the latest configuration, and updates the task record.
[0033] After obtaining the approver information for the next node, the system updates the current node identifier of the approval instance to the node identifier of the next node, updates the current approver identifier and current approver name to the corresponding values in the task record of the next node, and updates the task status of the task record of the next node to pending status. At this point, a single approval workflow is completed, and the approval instance enters the waiting approval state for the next node.
[0034] When an approver processes the last approval task in the workflow and selects "Approve," the system determines that all nodes in that approval instance have been completed. The system updates the task status of the last node to "Completed," adds a new approval operation record to the approval record table, and then updates the instance status of the approval instance to "Approved." Simultaneously, based on the business identifier and business type fields in the approval instance, the system locates the associated business table record and automatically updates the corresponding status field in that business table with the approval result. This achieves tight integration between the approval process and business data, eliminating the need for additional callback mechanisms or message queues for status synchronization.
[0035] Step 4: Batch query optimization mechanism.
[0036] For scenarios where the approval list page needs to display the progress information of multiple approval instances simultaneously, this embodiment designs a batch query optimization mechanism based on memory grouping and multi-level indexes, which optimizes the traditional solution of querying one instance at a time into a batch query mode with a fixed number of queries.
[0037] When a user accesses the approval list page, the system first performs a pagination query to retrieve the list of approval instances to be displayed on the current page from the approval instance table. The pagination query uses a backend pagination method, limiting the query scope through pagination statements and returning only the instance records corresponding to the current page, avoiding full data transmission. After obtaining the instance list for the current page, the system collects the instance identifier set and process identifier set for all instances. The process identifier set is obtained by deduplicating the process identifier field in the instance list.
[0038] Next, the system executes three batch structured query language queries. The first query retrieves all process node configurations by process identifier set, i.e., it searches the process node table for all node records whose process identifiers belong to the specified process identifier set. The second query retrieves all approval records by instance identifier set, i.e., it searches the approval record table for all records whose instance identifiers belong to the specified instance identifier set. The third query retrieves all approval tasks by instance identifier set, i.e., it searches the approval task table for all task records whose instance identifiers belong to the specified instance identifier set. All three queries use a batch input clause approach, passing multiple identifier values from the set as query conditions all at once. This reduces the interaction mode from three separate queries per instance in the traditional solution to a fixed three database interactions, regardless of the number of instances displayed on the page.
[0039] After three batch queries return results, the system groups the results in memory. Using the instance identifier as the grouping key, the system constructs three mapping indexes: instance identifier to node list, instance identifier to record list, and instance identifier to task list. When constructing the mapping indexes, the system uses an on-demand computation method: when an instance identifier appears for the first time, a corresponding list is created and added to the mapping; subsequent occurrences of the same instance identifier directly retrieve the already created list and append elements, avoiding redundant mapping lookup operations.
[0040] For grouping process node configurations, since multiple approval instances may share the same process definition, the system performs a deep copy operation on the process node object when assigning node configurations to each instance. This ensures that each approval instance has an independent copy of the node object. This deep copy operation avoids data overwriting issues caused by modifying node object attributes when multiple instances share the same node object, guaranteeing data isolation when each instance independently assembles progress information subsequently.
[0041] During the memory grouping phase, when the number of instances is large, the system employs a parallel streaming grouping approach to improve grouping processing efficiency. The system utilizes a parallel streaming processing framework to break down the grouping task into multiple subtasks, which are then executed in parallel by multiple worker threads in a thread pool. The grouping results are merged using a concurrent mapping collector. This parallel grouping method fully leverages the computing power of multi-core processors, significantly reducing the time consumption of memory grouping when the instance scale is large.
[0042] After completing the memory grouping, the system assembles progress information for each approval instance on the current page. For each instance, the system retrieves the corresponding node list, record list, and task list in constant time complexity using the aforementioned three mapping indexes. Then, it matches and associates these three lists according to node identifiers and node order to construct a complete workflow progress view for that instance. Specifically, the system iterates through the node list of the instance. For each node, it checks the record list for completed approval records and the task list for pre-assigned tasks, thereby determining the node's approval status, approver information, and approval comments. Since the lookup time complexity of the mapping indexes is constant, the progress assembly operation for each instance does not require further database access and is entirely completed in memory.
[0043] At the Structured Query Language (SCL) level, the system creates covering indexes for the instance identifier field of the approval task table and the process identifier field of the approval instance table. These covering indexes contain all fields required for the query, enabling batch input clause queries to directly retrieve data through the index without needing to access the main data from the table, further reducing query input / output overhead. Simultaneously, the system creates a composite index for the instance identifier and task status fields of the approval task table, optimizing the query performance of the pending task list.
[0044] Step 5: Return and Withdrawal Processing Mechanism.
[0045] This embodiment supports two abnormal workflow operations: approval rejection and initiator withdrawal.
[0046] When an approver selects the "return" operation on the approval processing page, the system first verifies whether the current node is the first node in the process. If the current node is not the first node, the system executes the following return processing logic: Set the task status of all unprocessed task records after the current node to "cancelled," including the next node and all pre-assigned tasks of subsequent nodes; create a new pending task record for the previous node, inheriting the node identifier, node name, and node order information of the previous node, and re-determine the approver information based on the configuration of the previous node; update the current node identifier of the approval instance to the node identifier of the previous node, and update the current approver identifier and current approver name to the corresponding values in the newly created pending task; simultaneously, add a new return operation record to the approval record table, recording the returner's identifier, return comments, and return time.
[0047] If the current node is the first node in the process, and the approver selects a return operation, the system determines that the return is equivalent to a rejection. The system updates the task status of the current node to "completed," adds a rejection operation record to the approval record table, updates the instance status of the approval instance to "rejected," and synchronously updates the status field of the associated business table according to the business identifier and business type fields. The process then ends.
[0048] When an initiator chooses to withdraw an approval instance while it is in the "Approval in Progress" state, the system first verifies whether the operator is the initiator of the approval instance and whether the instance status is "Approval in Progress." Only processes in the "Approval in Progress" state are allowed to be withdrawn. After successful verification, the system executes the following withdrawal processing logic: sets the task status of all unprocessed task records under this instance to "Cancelled"; updates the instance status of the approval instance to "Withdrawn"; adds a new withdrawal operation record to the approval record table; and synchronously updates the status field of the associated business table with the withdrawal result based on the business identifier and business type fields. If the approval instance is already in a final state such as "Approved," "Rejected," or "Withdrawn," the system rejects the withdrawal operation and returns a corresponding prompt.
[0049] Step six: Dynamic approver matching mechanism.
[0050] For nodes with approval type specified role type, this embodiment adopts a three-level dynamic approver matching strategy. Based on the organizational structure information of the initiator and the role identifier configured in the node, the query scope is narrowed down level by level to determine the specific approval user.
[0051] In the first level of matching, the system queries the department leader table based on the initiator's department identifier and the role identifier configured for the node. The department leader table stores information about the heads of each department, including fields such as department identifier, head user identifier, and head name. If a record for the head of the corresponding department exists in the department leader table, the system identifies that head as the approver for that node, and the matching process ends.
[0052] For the second level of matching, if no matching record is found in the department leader table, the system queries users under that department who have the role specified in the node configuration. The system searches the user role association table for user records where the department ID equals the initiator's department ID and the role ID equals the node configuration role ID. If a matching user is found, the system designates that user as the approver for that node, and the matching process ends. If multiple users with the specified role exist under that department, the system can select one as the approver according to preset selection rules.
[0053] In the third level of matching, if no matching user is found within the department, the system expands the query scope to the entire company, searching for users across the company who have the role specified in the node configuration. The system queries the user role association table for all user records whose role identifier equals the role identifier in the node configuration, regardless of department. If a user matching the criteria is found, the system designates that user as the approver for that node.
[0054] The department scope field in the node configuration controls the execution scope of the above three-level matching. When the department scope is configured as "this department," the system only performs the first and second levels of matching. If no approver is matched at either level, the matching is considered a failure and a placeholder is set. When the department scope is configured as "the entire company," the system performs all three levels of matching. If no approver is matched at any of the three levels, the matching is considered a failure. This hierarchical matching strategy satisfies both the conventional approval requirements of department-by-department reporting and the cross-departmental role-based approval scenarios.
[0055] Step 7: High-concurrency approval control mechanism.
[0056] To address the scenario where multiple users simultaneously approve the same node or instance in high-concurrency situations, this embodiment designs a multi-layered concurrency control mechanism that combines transaction-level implicit mutual exclusion with optimistic locking version number control.
[0057] Transaction-level implicit mutual exclusion is achieved through the atomicity of database transactions and the conditional update features of Structured Query Language (SCL). All approval operation methods are annotated with transaction annotations to ensure that multiple database update actions within an approval operation are atomically committed within the same transaction. During the execution of the approval method, the system first queries for task records whose current user status is "pending." This query condition simultaneously specifies that the task status is "pending," the approver identifier is the current user identifier, and the instance identifier is the target instance identifier. Then, the system verifies whether the node identifier of the queried task matches the current node identifier of the approval instance and checks whether the instance status of the approval instance is "in progress." Through these triple constraints of query conditions and verification logic, implicit mutual exclusion is achieved.
[0058] When multiple users simultaneously approve the same task, the user who submits their transaction first updates the task status to "completed." When a user who submits their transaction later performs a query for the pending task within their own transaction, the query condition will return an empty result because the task status has already been updated to "completed" by the earlier submitter. The system then triggers a "no pending task found" exception, and the current transaction is rolled back, thus avoiding duplicate approvals. This mechanism does not require explicit locking; it naturally achieves comparison and exchange semantics through the condition updates in Structured Query Language, ensuring concurrency safety while avoiding the performance overhead of lock contention.
[0059] Optimistic locking version number control uses a version number field set in the approval instance table. Each time an approval instance is updated, the system's update statement includes a version number condition; that is, the update operation only takes effect if the current version number of the approval instance equals the version number read at the start of the operation. After executing the update, the system checks the number of affected rows. If the number of affected rows is zero, it determines that the approval instance has been modified by other concurrent transactions, the current operation is rolled back, and the user is prompted to retry. If the number of affected rows is one, the update is successful, and the system increments the version number field, providing a new version baseline for subsequent operations. The optimistic locking mechanism is suitable for concurrent scenarios with a low probability of conflict, achieving lock-free concurrent conflict detection through version number comparison.
[0060] For batch approval scenarios, where users submit multiple approval instances at once, the system employs a memory-level concurrency optimization strategy. The system first queries all pending approval instances in batches, then queries the current user's pending tasks within these instances in batches. A mapping collector is used to construct a mapping relationship between instance identifiers and tasks, avoiding querying the database line by line in a loop. Simultaneously, the system uses a node caching structure to cache the node configuration list for the same process. For multiple instances with the same process identifier, their node configuration is queried from the database only once and cached in memory. Subsequent instances retrieve the configuration directly from the cache, optimizing multiple node queries into queries based on the number of deduplicated processes.
[0061] The system also introduces a local caching mechanism to cache frequently accessed workflow node configurations and approver information. The local cache employs a write-on-failure strategy. When a workflow node configuration changes, the system first updates the configuration record in the database, and then clears the corresponding old configuration from the local cache through a cache key invalidation operation. To prevent data inconsistency caused by cache invalidation failures, the system sets a cache expiration time as a fallback strategy. Even if write-on-failure fails, the old configuration in the cache will automatically expire after the expiration time. During the approval process, the system prioritizes reading node configurations from the local cache. If the cache misses, it queries the source database and writes the result to the cache, significantly reducing database access pressure in high-frequency configuration read scenarios.
[0062] Step 8: Define the process for version compatibility and hot migration mechanisms.
[0063] When the process definition undergoes version changes during runtime, such as adding or deleting approval nodes, modifying node approver configurations, or adjusting node order, this embodiment ensures that created approval instances and their pre-assigned tasks can smoothly adapt to the new version of the process configuration through node identifier anchoring mapping, real-time configuration parsing, and a three-level display name priority backtracking mechanism.
[0064] Node identifier anchoring mapping refers to the process of anchoring pre-created approval task records to specific workflow node configurations through a node identifier field. When the workflow definition is changed, the system maintains a mapping table of old and new node identifiers, recording the correspondence between the old and new version node identifiers. When the approval workflow reaches a certain node, the system first looks up the corresponding node configuration for the current version in the mapping table using the node identifier of that node. If a corresponding relationship exists in the mapping table and the node is still valid in the new version, the system continues the workflow using the new version's node configuration; if the node has been deleted in the new version, the system automatically skips that node and directly activates the task for the next valid node; if a new node is added in the new version, the system dynamically creates a new pending task record when the workflow reaches the new node position and incorporates the new node into the approval workflow.
[0065] The real-time configuration parsing strategy means that the system always parses approver information from the latest version of the process configuration during the approval workflow, rather than using the approver snapshot saved at the time of process startup. In the workflow logic of the approval method, when it is necessary to determine the approver for the next node, the system calls the approver information population method, dynamically matching the approver based on the latest node configuration and the initiator's department information. If the approver information saved in the pre-assigned task is inconsistent with the latest configuration parsing result, the system updates the approver identifier and approver name fields of the pre-assigned task to the latest parsing result through the task update method. This strategy ensures that after a change in the process configuration, the running approval instance can use the latest approver configuration, rather than the old configuration fixed at the time of process startup.
[0066] When displaying the approval progress, the system employs a three-tiered display name priority backtracking mechanism to determine the approver's display name for each node. The first priority is the instance-level current approver name, reflecting the latest configuration resolution result and used to display the approver for the currently processing node. The second priority is the task-level pre-assigned approver name, a snapshot of the approvers pre-assigned when the process starts, used to display pre-assigned approvers for nodes that have not yet reached their destination. The third priority is the record-level historical approver name, a snapshot of the approvers recorded when the approval operation occurred, used to display historical approvers for completed nodes. When a change in process configuration leads to a change in approvers, the system uses the above priority overriding mechanism to ensure the front-end displays the latest approver information, while retaining snapshots of approvers from historical approval records for auditing and traceability, achieving compatibility and coexistence between configuration changes and historical data.
[0067] The steps and specific implementations of the method of the present invention have been described in detail above. This embodiment also provides a lightweight approval process control system based on batch pre-allocation tasks, which is used to execute the above method. Figure 1 As shown, the system includes a process definition management module, a batch pre-allocation module, and an approval workflow module.
[0068] The process definition management module is used to build and maintain process definition tables and process node tables, storing metadata information for approval processes. This module provides CRUD (Create, Read, Update, Delete) functionality for adding, modifying, enabling, and disabling process definitions, as well as configuring nodes. It manages process identifiers, process names, process status, and configuration information for each approval node, including node identifier, node order, node name, approval type, approver identifier or role identifier, and department scope. The process definition management module also triggers cache invalidation when configuration changes occur, ensuring that running approval instances receive the latest configuration.
[0069] The batch pre-allocation module validates the process definition when a user initiates an approval process, retrieves the configuration of all approval nodes, and pre-creates approval task records for all nodes in batches using a single multi-value insertion statement. The batch pre-allocation module includes a placeholder parsing unit and a signature / reduction adaptation unit. The placeholder parsing unit uses the actual approver identifier for the first node, sets placeholder markers for subsequent nodes when matching fails, and triggers lazy parsing to update approver information when the flow reaches a placeholder node. The signature / reduction adaptation unit dynamically inserts or cancels node tasks during process execution and maintains the integrity of the pre-allocated task structure by locally updating node order values.
[0070] The approval workflow module performs permission checks when approvers process approval tasks. Upon approval, it directly retrieves approver information from the pre-created next-node task record and updates the current node and current approver of the approval instance. The module includes a concurrency control unit, which uses transaction-level implicit mutual exclusion and optimistic locking version number control to ensure approval security in high-concurrency scenarios. The module also handles synchronizing the approval result to the associated business table at the end of the process and processing abnormal workflow operations such as rejection and withdrawal.
[0071] Those skilled in the art should understand that the scope of protection of this invention is not limited to the specific embodiments described above. Various modifications and variations made to this invention without departing from its spirit and scope should be included within its protection scope. For example, the batch pre-allocation insertion method can be replaced by other batch operation techniques, the parallel processing framework for memory grouping can be replaced by other concurrent computing frameworks, and the query order in the three-level approver matching strategy can be adjusted according to actual business needs. These equivalent substitutions and modifications should all fall within the protection scope of this invention.
[0072] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A lightweight approval process control method based on batch pre-allocation of tasks, characterized in that, The method includes: Construct a process definition table and a process node table to store metadata information of the approval process; the process definition table records the process identifier, process name and process status; the process node table records the node identifier, node order, node name, approval type, approver identifier or role identifier and department scope of each approval node; When a user initiates an approval process, the validity of the process definition is verified, and the configuration information of all approval nodes under that process is obtained. Create an approval instance, and based on the configuration information of all approval nodes, pre-create approval task records for all nodes in batches using a single multi-value INSERT statement; each approval task record includes instance identifier, node identifier, node name, node order, approver identifier, approver name, and task status; When an approver processes an approval task, they perform permission verification based on the task status and node configuration. After approval, the approver information is directly retrieved from the pre-created next node task record, and the current node and current approver of the approval instance are updated without additional database queries to obtain the approver. For tasks marked with placeholders, lazy resolution is triggered when the task is transferred to that node, and the approver is re-matched and the corresponding task record is updated based on the latest node configuration. When the last node is approved, the process ends, and the approval result is automatically updated to the business table associated with the business identifier and business type fields.
2. The method according to claim 1, characterized in that, Batch pre-creation also includes dynamic signature addition and subtraction adaptation mechanisms: When a signature-adding operation occurs during the process, a new pending task record is inserted at the target node position, and the node order values of the original subsequent nodes are sequentially extended. When a signature-removing operation occurs during the process, the task status of the target node is set to the canceled state, and the task of the next node is directly activated. The pre-created task record supports querying by instance identifier and node order combined index, so that signature-adding and signature-removing operations only require local updates and do not affect the overall pre-allocated task structure.
3. The method according to claim 1 or 2, characterized in that, The method also includes a batch query optimization step: When querying the process progress information of multiple approval instances, collect the instance identifier set and process identifier set of all instances on the current page; execute three batch SQL queries: batch query all process nodes by process identifier set, batch query all approval records by instance identifier set, and batch query all approval tasks by instance identifier set; group the results of the three queries in memory by instance identifier, and construct a mapping index from instance identifier to node list, record list and task list; for each approval instance, complete the matching and assembly of nodes, records and tasks in O(1) time complexity through the mapping index, reducing the query operation of N instances from N×3 database interactions to a fixed 3 database interactions.
4. The method according to claim 1, characterized in that, The batch query optimization steps also include: During the memory grouping phase, a parallel streaming grouping method is adopted, using ForkJoinPool to process the grouping tasks in parallel; at the same time, a deep copy operation is performed on the process node objects to ensure that each instance has an independent node copy when multiple instances share the same process definition, avoiding data overwriting. At the SQL level, covering indexes are created for instance identifier fields and process identifier fields, enabling batch IN clause queries to be completed directly through the indexes without needing to look up the table. A two-stage strategy is adopted, which involves querying the instance list in pagination on the backend and batch filling the progress information in the backend. First, the instances on the current page are queried through pagination SQL, and then the progress information of the instances on the current page is filled through the three batch SQL queries.
5. The method according to claim 3, characterized in that, When the approval type is a specified role type, a three-level dynamic approver matching strategy is adopted: At the first level, based on the department identifier of the initiator and the role identifier configured in the node, the department leader table is queried to obtain the department head as the approver; At the second level, if there is no matching record in the department leader table, then query the users with the specified roles under that department as approvers. At the third level, if there are still no matching users under the department, then query users with the specified roles throughout the company as approvers; The department scope field configured in the node controls the query scope: when the department scope is the current department, only the first and second level matches are performed; when the department scope is the entire company, all third level matches are performed.
6. The method according to claim 4 or 5, characterized in that, The method also includes a high-concurrency approval control mechanism: Transaction-level implicit mutual exclusion: Approval operations are executed within a transaction. Implicit mutual exclusion is achieved through three checks: querying the current user's task status as pending, verifying that the task node matches the current node of the instance, and verifying the process status. When multiple users approve the same node at the same time, the user who submits the transaction first updates the task status to completed. The user who submits the transaction later will trigger an exception because the pending status query condition is not met. CAS semantics are implemented through SQL condition updates to avoid duplicate approvals. Optimistic locking version number control: Set a version number field in the approval instance table. Each time the instance is updated, execute an UPDATE statement with version number conditions. If the number of rows affected by the update is zero, it is determined that the instance has been modified by other transactions, the current operation is rolled back and a retry is prompted.
7. The method according to claim 1, characterized in that, The method also includes a rollback mechanism and a withdrawal mechanism: When the approver chooses to return the application, the system cancels all unprocessed tasks after the current node, creates a new pending task for the previous node, and updates the current node and current approver of the approval instance. If the current node is the first node, the return operation is equivalent to rejection, the process ends, and the business table status is updated synchronously. When the initiator chooses to withdraw, the system verifies the initiator's identity and the process status. Only processes in the approval stage are allowed to be withdrawn. When withdrawing, all unprocessed tasks are canceled, the instance status is updated to withdrawn, and the status of the associated business table is updated synchronously.
8. The method according to claim 1, characterized in that, The method also includes a process definition version compatibility mechanism: Node identifier anchoring mapping: Pre-created task records are anchored to specific process node configurations through the node identifier field; when the process definition is changed, the system maintains a mapping table of old and new node identifiers, and when the process flows to that node, it looks up the node configuration corresponding to the current version through the mapping table; if the node has been deleted in the new version, it is automatically skipped and the next valid node is activated; if a new node is added in the new version, a new to-do task is dynamically created during the process flow. During the approval process, the system parses the approver in real time from the latest version of the process configuration, rather than using the snapshot of the approver when the process starts; When displaying the approval progress, the display name is determined according to the priority order of the current approver name at the instance level, the pre-assigned approver name at the task level, and the historical approver name at the record level. This ensures that the latest approver is displayed after the configuration changes, while retaining historical snapshots for audit traceability.
9. The method according to claim 1, characterized in that, The batch pre-creation of approval task records for all nodes specifically includes: The ORM framework uses the foreach tag to concatenate single multi-value INSERT statements, separating all task records in a single SQL statement with commas, enabling the insertion of all task records in a single database round trip. Batch rewrite parameters are configured at the JDBC connection level, allowing the database driver to automatically rewrite multiple INSERT statements into a single multi-value INSERT statement. A batch size threshold is set, and when the number of task records exceeds the threshold, they are submitted in batches. The method also includes a local caching mechanism: a local caching component is used to cache frequently accessed process node configurations and approver information, and a write-once invalidation strategy is adopted. When the process node configuration changes, the database is updated first and then the corresponding cache key is invalidated. A cache expiration time is set as a fallback strategy. When the approval process is in progress, the node configuration is read from the local cache first. If the cache is not hit, the source database is retrieved and the result is written to the cache.
10. A lightweight approval process control system based on batch pre-assignment of tasks, wherein the system implements the method as described in any one of claims 1 to 9, characterized in that, include: The process definition management module is used to build and maintain process definition tables and process node tables, and store metadata information of approval processes, including process identifier, process name, process status, as well as node identifier, node order, node name, approval type, approver identifier or role identifier and department scope for each approval node. The batch pre-allocation module is used to verify the validity of the process definition when a user initiates an approval process, obtain the configuration of all approval nodes, and pre-create the approval task records of all nodes in batches using a single multi-value INSERT statement. The batch pre-allocation module includes a placeholder parsing unit, which is used to use the actual approver identifier for the first node, set placeholder markers for subsequent nodes when matching fails, and trigger lazy parsing to update the approver information when the flow reaches the placeholder node. The batch pre-allocation module also includes a signature addition / reduction adaptation unit, which is used to dynamically insert or cancel node tasks and partially update the node order during process execution. The approval workflow module is used to perform permission verification when the approver processes the approval task. After the approval is approved, the approver information is directly obtained from the pre-created next node task record and the current node and current approver of the approval instance are updated. The approval workflow module includes a concurrency control unit, which is used to ensure approval security in high-concurrency scenarios through transaction-level implicit mutual exclusion and optimistic locking version number control.
