Rules engine-based clearing and settlement accounting methods, devices, equipment, and program products
By adopting a clearing, settlement, and revenue sharing method based on a rules engine, the problem of deep coupling between billing logic and business code in existing technologies is solved. This enables flexible configuration and dynamic activation of billing rules, improves the system's flexibility and maintainability, supports canary releases and idempotent control, and ensures data consistency and reliability.
Patent Information
- Application Number
- CN202610864306.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-15
- Publication Date
- 2026-11-10
AI Technical Summary
The existing clearing and settlement system's billing logic is deeply coupled with the business code, making it impossible to flexibly configure and dynamically deploy clearing and settlement rules without modifying the code. This results in high maintenance costs, the inability to support gray-scale verification and version rollback of rules, and difficulty in meeting the needs of rapid business iteration.
The system adopts a clearing and settlement accounting method based on a rule engine. By converting clearing and settlement requests into clearing vouchers, it dynamically matches target billing rules from the rule base based on business dimension information, and calls the rule engine to input billing factors into the decision chain to generate billing bills. This enables configurable management and dynamic activation of billing rules, and supports canary release and idempotent control.
It enables flexible configuration and dynamic deployment of billing rules, allowing rate adjustments and new fee items to be added without restarting the service. This significantly improves the system's flexibility and maintainability, reduces the online risks associated with rule changes, and ensures data consistency and reliability.
Smart Images

Figure CN123070904A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of revenue sharing technology, specifically to a clearing and settlement revenue sharing method, apparatus, equipment, and program product based on a rule engine. Background Technology
[0002] In platform-based businesses such as ride-hailing services, the clearing and settlement system is responsible for calculating order fees and distributing revenue among the various parties. The traditional approach involves directly writing the specific billing formulas into the business code, with different order types corresponding to their own independent processing flows. However, with frequent adjustments to billing rules and the increasing number of business types, this hard-coded approach has gradually revealed problems such as maintenance difficulties and poor scalability.
[0003] The billing logic of the existing clearing and settlement system is deeply coupled with the business code. Whenever the rate parameters are adjusted or a new fee item is added, the source code must be modified and the entire process of development, testing and release must be completed again. This makes it impossible to achieve dynamic configuration and rapid deployment of billing rules, resulting in low system efficiency in responding to business changes, high maintenance costs, and the inability to support gray-scale verification and version rollback of rules, which makes it difficult to meet the needs of rapid business iteration. Summary of the Invention
[0004] This invention provides a clearing and settlement accounting method, apparatus, equipment, and program product based on a rule engine to solve the problem that the billing logic and business code of existing clearing and settlement systems are deeply coupled, making it impossible to flexibly configure and dynamically deploy clearing and settlement rules without modifying the code.
[0005] In a first aspect, the present invention provides a clearing, settlement, and accounting method based on a rules engine, the method comprising: Receive a clearing and settlement request and convert the clearing and settlement request into a clearing voucher; Based on the business dimension information of the clearing certificate, the currently effective target billing rule is matched from the rule base; The rule engine is invoked, and the billing factor in the clearing certificate is input into the decision chain corresponding to the target billing rule. The decision chain is executed sequentially to generate at least one billing statement. Based on the at least one billing statement, a sub-settlement statement corresponding to each clearing and settlement entity is generated, and an account operation is performed on the clearing and settlement entity according to the sub-settlement statement, and the settlement status of the sub-settlement statement is updated.
[0006] This invention provides a technical solution that converts clearing and settlement requests into standardized clearing vouchers, dynamically matches target billing rules from the rule base based on business dimension information, and calls the rule engine to input billing factors into the decision chain to execute multiple sub-billing rules to generate billing statements. This, in turn, generates sub-settlement statements corresponding to each clearing and settlement entity and executes accounting operations. This solution solves the problem in existing technologies where billing logic and business code are deeply coupled, making it impossible to flexibly configure and dynamically deploy clearing and settlement rules without modifying the code. It achieves configurable management and dynamic activation of billing rules, and allows for rate adjustments and the addition of new fee items without restarting the service, significantly improving the flexibility and maintainability of the clearing and settlement system.
[0007] In one optional implementation, matching the currently effective target billing rule from the rule base includes: A multi-dimensional rule positioning key is constructed based on the business line identifier, scenario identifier, and event identifier in the clearing certificate; Query the rule set in the rule base that matches the multidimensional rule locating key, wherein the rule set contains multiple versions of billing rules corresponding to the same business logic; Obtain the rule version that is currently in effect, and determine whether the canary release switch corresponding to the rule version is enabled; If the gray-scale release switch is not turned on, the default version rule will be selected as the target billing rule. If the grayscale release switch is turned on, it is determined whether the tenant corresponding to the clearing and settlement request is in the grayscale whitelist associated with the grayscale release switch; if the tenant corresponding to the clearing and settlement request is in the grayscale whitelist, the new version of the rule is selected as the target billing rule for the tenant; if the tenant corresponding to the clearing and settlement request is not in the grayscale whitelist, the old version of the rule is selected as the target billing rule.
[0008] This invention provides a technical solution that addresses the problems in existing technologies where billing rule changes cannot be verified on a small scale and can only be deployed to a full scale, leading to uncontrollable risks. It achieves refined gray-scale deployment of billing rules, allowing for gradual verification of new rules at the tenant level, significantly reducing online risks associated with rule changes, and supporting smooth rollback and version traceability. The solution utilizes a multi-dimensional rule positioning key constructed based on the business line identifier, scenario identifier, and event identifier in the clearing certificate. This query retrieves a matching rule set containing multiple versions of billing rules in the rule base, obtains the currently effective rule version, and determines the gray-scale release status. Based on the switch status and whether the tenant is on the gray-scale whitelist, the solution selects the default version, new version, or old version rule as the target billing rule.
[0009] In one optional implementation, converting the clearing request into a clearing voucher includes: The clearing and settlement request is converted into a clearing voucher, and a globally unique identifier is assigned to the clearing voucher. The globally unique identifier is used as an idempotent key to query the local message table to determine whether the idempotent key already exists. If the idempotent key already exists and the association status of the idempotent key is in processing or completed, then it is determined that the clearing voucher has been processed, the existing processing result is returned directly, and the clearing and settlement splitting processing of the clearing and settlement request is ended. If the idempotent key does not exist, the globally unique identifier is written into the local message table, the status of the corresponding record in the local message table is marked as processing, and the clearing and settlement processing of the clearing and settlement request continues.
[0010] This invention addresses the problems in existing technologies, such as the lack of a global idempotency control mechanism and the tendency for repeated processing of the same clearing and settlement request in high-concurrency scenarios, leading to fund settlement errors or inconsistent status. It achieves idempotency protection for clearing and settlement requests, ensuring that the same request is processed only once, significantly improving data consistency and reliability in high-concurrency environments.
[0011] In one optional implementation, the step of inputting the billing factor in the clearing voucher into the decision chain corresponding to the target billing rule, and sequentially executing the decision chain to generate at least one billing statement, includes: The billing factor in the clearing document is input into the decision chain corresponding to the target billing rule, and the decision chain contains at least one sub-billing rule; The decision chain is executed sequentially according to the billing factors to generate at least one billing statement; Record the intermediate variables and execution results generated during the execution of each sub-billing rule in the decision chain; The billing factor, the intermediate variable, the execution result, and the version number of the target billing rule are associated with the globally unique identifier of the clearing certificate to generate an execution log.
[0012] This invention addresses the problems of lack of traceability in the clearing and settlement execution process, difficulty in locating the root cause of problems when anomalies occur, and inability to reconstruct the calculation process in existing technologies. It achieves complete recording and traceability of the entire clearing and settlement calculation process. Each billing order can trace its calculation basis, intermediate results, and the version of the rule used, significantly improving the system's auditability and anomaly detection efficiency.
[0013] In one optional implementation, the method further includes performing an account adjustment operation on the clearing and settlement entity based on the sub-settlement statement and updating the settlement status of the sub-settlement statement: Call the account interface corresponding to the clearing and settlement entity of the sub-settlement statement to perform an account operation on the clearing and settlement entity; After the transaction is completed, determine whether the transaction was successfully executed. If the transaction is successfully executed, the settlement status of the sub-settlement statement is updated to the first settlement status, which indicates that the sub-settlement statement has been settled. If the transaction operation fails, the settlement status of the sub-settlement statement is marked as the second settlement status, and the transaction operation is retried until the transaction operation is successful. The second settlement status is used to indicate that the sub-settlement statement has not been settled.
[0014] This invention addresses the problems in existing technologies where settlement actions directly call the funds interface, lacking status tracking and retry mechanisms, and easily leading to fund omissions or inconsistent statuses that are difficult to automatically recover from. It achieves reliable recording of the execution results of account movement and automated failure retry compensation, ensuring that each sub-settlement order can ultimately complete fund transfers successfully, significantly improving the fault tolerance and eventual data consistency of the clearing and settlement system.
[0015] In an optional implementation, the method further includes: Iterate through the settlement status of the sub-settlement statements corresponding to each clearing and settlement entity; If the settlement status of all sub-settlement orders is the first settlement status, then the settlement status of the main settlement order corresponding to the sub-settlement order is updated to the third settlement status, and a settlement completion event is pushed to the business party corresponding to the clearing and settlement request, wherein the third settlement status is used to indicate that the main settlement order has been settled; If any sub-settlement statement has the second settlement status, a settlement anomaly alarm will be triggered.
[0016] This invention addresses the problems of fragmented status between master and sub-settlement orders, inability to uniformly perceive the settlement progress of all sub-settlement orders, and lack of timely notification mechanisms for abnormal situations in existing technologies. It achieves unified management and closed-loop monitoring of the entire clearing and settlement process, ensuring that business parties can promptly obtain settlement completion status and quickly intervene in case of abnormalities. This significantly improves the observability and operational efficiency of the clearing and settlement system. The invention also addresses the issue of traversing the settlement status of sub-settlement orders across all clearing and settlement entities. If all sub-settlement orders are in the first settlement state (representing settlement completion), a settlement anomaly alarm is triggered.
[0017] In one optional implementation, if the transaction is successfully executed, updating the settlement status of the sub-settlement statement to the first settlement status includes: Determine whether the settlement status of the sub-settlement statement has been successfully updated to the first settlement status; After the settlement status of all sub-settlement statements is successfully updated, the status of the globally unique identifier of the clearing voucher is updated to the completed status in the local message table, and a confirmation message is sent to the message queue. If the settlement status update of any sub-settlement document fails, the status of the globally unique identifier of the clearing voucher is maintained as processing in the local message table, and the status of the sub-settlement document whose settlement status update failed is re-updated until the settlement status of all sub-settlement documents is successfully updated to the first settlement status.
[0018] This invention addresses the problems in existing technologies, such as the lack of linkage between the local message table and settlement status updates, the inability to correctly synchronize the global status when some sub-settlement documents fail to update, and the lack of an automatic repair mechanism. It achieves eventual consistency between the local message table status and the sub-settlement document status, ensuring that the globally unique identifier accurately reflects the processing progress of all sub-settlement documents and significantly improving the data consistency and automated recovery capabilities of the clearing and settlement system. This is achieved by determining whether the settlement status of a sub-settlement document has been successfully updated to the first settlement status. After all sub-settlement documents have been successfully updated, the status of the globally unique identifier in the local message table is updated to the completed status, and a confirmation message is sent to the message queue. If the settlement status update of any sub-settlement document fails, the processing status in the local message table is maintained, and the status of the failed sub-settlement documents is re-updated until all are successfully updated.
[0019] Secondly, the present invention provides a clearing, settlement, and accounting device based on a rules engine, the device comprising: The request receiving module is used to receive clearing and settlement requests and convert the clearing and settlement requests into clearing vouchers. The rule matching module is used to match the currently effective target billing rule from the rule base based on the business dimension information of the clearing certificate; The rule execution module is used to call the rule engine, input the billing factor in the clearing certificate into the decision chain corresponding to the target billing rule, and execute the decision chain in sequence to generate at least one billing statement. The billing settlement module is used to generate sub-settlement statements corresponding to each clearing entity based on the at least one billing statement, perform accounting operations on the clearing entity according to the sub-settlement statements, and update the settlement status of the sub-settlement statements.
[0020] Thirdly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the rule engine-based clearing and settlement accounting method of the first aspect or any corresponding embodiment described above.
[0021] Fourthly, the present invention provides a computer program product, including computer instructions for causing a computer to execute the rule engine-based clearing and settlement accounting method described in the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0022] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating the clearing, settlement, and accounting method based on a rule engine according to an embodiment of the present invention. Figure 2 This is a schematic diagram of the architecture of the clearing and settlement middleware system according to an embodiment of the present invention; Figure 3(a) is another flowchart of the clearing, settlement and accounting method based on a rule engine according to an embodiment of the present invention; Figure 3(b) is another flowchart of the clearing, settlement and accounting method based on the rule engine according to an embodiment of the present invention; Figure 4 This is a structural block diagram of a clearing, settlement, and accounting device based on a rule engine according to an embodiment of the present invention; Figure 5 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0025] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.
[0026] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0027] In platform-based businesses such as ride-hailing services, the clearing and settlement system is responsible for calculating order fees and distributing revenue among the various parties. The traditional approach involves directly writing the specific billing formulas into the business code, with different order types corresponding to their own independent processing flows. However, with frequent adjustments to billing rules and the increasing number of business types, this hard-coded approach has gradually revealed problems such as maintenance difficulties and poor scalability.
[0028] The billing logic of the existing clearing and settlement system is deeply coupled with the business code. Whenever the rate parameters are adjusted or a new fee item is added, the source code must be modified and the entire process of development, testing and release must be completed again. This makes it impossible to achieve dynamic configuration and rapid deployment of billing rules, resulting in low system efficiency in responding to business changes, high maintenance costs, and the inability to support gray-scale verification and version rollback of rules, which makes it difficult to meet the needs of rapid business iteration.
[0029] Based on this, according to an embodiment of the present invention, a clearing, settlement and accounting method based on a rule engine is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0030] This embodiment provides a clearing, settlement, and revenue sharing method based on a rules engine, which can be used in a clearing and settlement middleware system. Figure 1 This is a flowchart of a clearing, settlement, and accounting method based on a rule engine according to an embodiment of the present invention, such as... Figure 1 As shown, the process includes the following steps: Step S101: Receive the clearing and settlement request and convert the clearing and settlement request into a clearing voucher.
[0031] Step S102: Based on the business dimension information of the clearing certificate, match the currently effective target billing rule from the rule base.
[0032] Step S103: Invoke the rule engine, input the billing factor in the clearing voucher into the decision chain corresponding to the target billing rule, and execute the decision chain in sequence to generate at least one billing order.
[0033] Step S104: Based on at least one billing statement, generate sub-settlement statements corresponding to each clearing and settlement entity, perform accounting operations on the clearing and settlement entity according to the sub-settlement statements, and update the settlement status of the sub-settlement statements.
[0034] The clearing and settlement accounting method provided in this embodiment converts clearing and settlement requests into standardized clearing vouchers, dynamically matches target billing rules from the rule base based on business dimension information, and calls the rule engine to input billing factors into the decision chain to execute multiple sub-billing rules to generate billing statements. This generates sub-settlement statements corresponding to each clearing and settlement entity and performs accounting operations. This technical solution solves the problem in the prior art where billing logic and business code are deeply coupled, and clearing and settlement rules cannot be flexibly configured and dynamically deployed without modifying the code. It realizes the configurable management and dynamic activation of billing rules, and can complete rate adjustments and add new fee items without restarting the service, significantly improving the flexibility and maintainability of the clearing and settlement system.
[0035] Figure 2 A schematic diagram of the clearing and settlement middleware system provided in an embodiment of the present invention is shown below. Figure 2 The architecture of the system is described in detail.
[0036] like Figure 2 As shown, the clearing, settlement and accounting system is divided into five functional layers: access layer, voucher layer, rule engine layer, settlement core and security mechanism.
[0037] The access layer is responsible for receiving settlement requests from upstream business systems. Upstream business systems send these requests to the access layer via HTTP or a message queue (MQ). The access layer provides a unified HTTP interface and MQ consumer, supporting requests from different protocol types. Upon receiving a request, the access layer validates and standardizes the request parameters, converting raw requests from different business systems and in different formats into a unified, standardized request format for easier processing by subsequent layers.
[0038] The voucher layer is responsible for creating and persistently storing clearing vouchers. After the access layer standardizes the requests, the voucher layer creates the corresponding clearing voucher for each clearing and settlement request. A clearing voucher is a standard data structure that carries the original input information for clearing and settlement, recording complete information from business documents as the entry point for the clearing process. The voucher layer persistently stores clearing vouchers to ensure data is not lost, and also supports idempotency checks based on globally unique identifiers to prevent the same request from being processed repeatedly.
[0039] The rules engine layer is responsible for dynamic cost calculation. It interacts with the rules configuration center to obtain billing rules matching the current clearing voucher. The rules configuration center centrally manages all billing rules, supporting versioned storage, canary releases, and dynamic configuration. After obtaining the rules, the rules engine layer inputs the billing factors from the clearing voucher into the decision chain, executes multiple sub-billing rules in the decision chain, completes the dynamic cost calculation, and finally outputs a billing statement. The billing statement records the income and expenditure amounts of each clearing entity for each cost item.
[0040] The settlement core is responsible for generating settlement statements and processing account updates. It receives billing statements from the rules engine layer, summarizes the income and expenditure amounts for each clearing entity, and generates a master settlement statement and corresponding sub-settlement statements for each entity. The settlement core uses an asynchronous account update mechanism, sequentially calling the fund account interfaces of each clearing entity to complete fund transfers and driving status changes in the sub-settlement statements based on the account update results.
[0041] The safeguard mechanism includes components such as message persistence, a full-process state machine, and end-to-end tracing. Among them, message persistence ensures that clearing and settlement requests are not lost during transmission and processing; the full-process state machine records the state changes of each clearing and settlement request from access to completion, supporting state backtracking and anomaly recovery; and end-to-end tracing generates a unique tracing identifier for each clearing and settlement request, linking log information from each stage such as access, voucher creation, rule calculation, and settlement activity, facilitating problem localization and performance analysis.
[0042] The steps described above will be explained in detail below.
[0043] In step S101, a clearing and settlement request is received and converted into a clearing voucher.
[0044] In one alternative implementation, converting a clearing request into a clearing document includes: Convert the clearing and settlement request into a clearing voucher, assign a globally unique identifier to the clearing voucher, and use the globally unique identifier as an idempotent key to query the local message table to determine whether the idempotent key already exists. If an idempotent key already exists and its association status is in progress or completed, it is determined that the clearing voucher has been processed, the existing processing result is returned directly, and the clearing and settlement sub-accounting processing of the clearing and settlement request is terminated. If the idempotent key does not exist, the globally unique identifier is written to the local message table, the status of the corresponding record in the local message table is marked as processing, and the clearing and settlement splitting processing of the clearing and settlement request continues to be executed.
[0045] In this embodiment, the clearing and settlement request is the original business data sent by the upstream business system through a message queue, which requires cost calculation and fund allocation. The message queue is middleware used to asynchronously transmit messages between upstream and downstream systems. The clearing voucher is a standard data structure that carries the original clearing and settlement business data and forms a one-to-one binding relationship with the business document.
[0046] In this embodiment, after converting the clearing and settlement request into a clearing voucher, a globally unique identifier is assigned to the resulting clearing voucher. This globally unique identifier is a unique string number that will not be repeated throughout the clearing and settlement system, used to uniquely identify the current clearing and settlement processing task. Next, this globally unique identifier is used as an idempotent key to query the local message table to determine if the idempotent key already exists in the local message table. The idempotent key is a unique index value used to determine whether the same request has already been processed. The local message table is a table stored in the clearing and settlement system database used to record the message processing status. This table uses the globally unique identifier as the primary key, and each record corresponds to the processing progress of a clearing and settlement request.
[0047] If the idempotent key already exists in the local message table, and the associated status value is "processing" or "completed," then it is determined that the current clearing voucher has already been processed. The "processing" status indicates that the clearing request is being processed but not yet completed, while the "completed" status indicates that the clearing request has been completed. At this point, the previously processed result is returned directly, and subsequent clearing processes are not triggered again. The clearing and settlement accounting processing for this clearing request ends, thus preventing the same order from being settled repeatedly in high-concurrency scenarios.
[0048] If the idempotent key does not exist in the local message table, it means that this is the first time the clearing and settlement request has been processed. In this case, the globally unique identifier is written to the local message table as a new record, and the status of the record is marked as "processing," indicating that the clearing and settlement request has started processing but has not yet been completed. After completing the above write operation, subsequent clearing and settlement accounting processing steps such as rule matching and account movement are executed to ensure that the request is processed normally.
[0049] This embodiment solves the problems in existing technologies, such as the lack of a global idempotency control mechanism and the tendency to process the same clearing and settlement request repeatedly in high-concurrency scenarios, leading to fund settlement errors or inconsistent status. It achieves idempotency protection for clearing and settlement requests, ensuring that the same request is processed only once, and significantly improves the data consistency and reliability of the system in high-concurrency environments.
[0050] In step S102, based on the business dimension information of the clearing certificate, the currently effective target billing rule is matched from the rule base.
[0051] The business dimension information of clearing vouchers refers to the key attributes extracted from raw business data used to locate billing rules, such as business line identifiers, scenario identifiers, and event identifiers. The rule base is a database in the clearing and settlement system used to centrally store and manage all billing rules, supporting versioned storage and dimension-based retrieval of rules. The target billing rule is a rule object used to guide the current clearing and settlement calculation process after a successful match.
[0052] In one alternative implementation, matching the currently effective target billing rule from the rule base includes: A multi-dimensional rule positioning key is constructed based on the business line identifier, scenario identifier, and event identifier in the clearing document; Query the rule set in the rule base that matches the multidimensional rule locator key. The rule set contains multiple versions of billing rules corresponding to the same business logic. Get the rule version that is currently in effect, and determine whether the canary release switch corresponding to the rule version is enabled; If the canary release switch is not enabled, the default version rule will be selected as the target billing rule. If the canary release switch is enabled, determine whether the tenant corresponding to the settlement request is in the canary whitelist associated with the canary release switch; if the tenant corresponding to the settlement request is in the canary whitelist, select the new version of the rule as the target billing rule for the tenant; if the tenant corresponding to the settlement request is not in the canary whitelist, select the old version of the rule as the target billing rule.
[0053] In this embodiment, a multi-dimensional rule locating key is constructed based on the business line identifier, scenario identifier, and event identifier in the clearing voucher. The business line identifier distinguishes different business types, such as ride-hailing, freight, or food delivery; the scenario identifier distinguishes different service scenarios within the same business line, such as airport pick-up / drop-off, carpooling, or express ride; and the event identifier distinguishes different triggering events within the same scenario, such as trip completion, order cancellation, or rescheduling. The multi-dimensional rule locating key combines these three identifiers into a composite query condition, used to accurately locate the applicable set of billing rules in the rule base.
[0054] Because billing rules are constantly iterated and updated as business develops, the rule base retains each historical version to support version rollback and canary releases. Therefore, the rule base can be queried using this multidimensional rule locator key to obtain a set of rules that match the multidimensional rule locator key. This set of rules contains multiple versions of billing rules corresponding to the same business logic.
[0055] Next, the currently active rule version is retrieved from the matched rule set, and it is determined whether the canary release switch corresponding to that rule version is enabled. The canary release switch is a configuration item that controls whether a new version of a rule is implemented according to a canary release strategy, and is used to implement small-scale verification of new rules.
[0056] If the canary release switch is not enabled, it means that canary release verification is not required, and the default version rule will be directly selected as the target billing rule. The default version rule is the stable version used as the benchmark in the rule set, which is usually the mainstream version that has been fully deployed.
[0057] If the canary release switch is enabled, it indicates that the current rule version uses a canary release strategy. Further verification is needed to determine whether the tenant corresponding to the clearing and settlement request is within the canary whitelist associated with this release switch. A tenant is a business entity using the clearing and settlement system; in a SaaS multi-tenant architecture, each channel or business entity corresponds to one tenant. The canary whitelist is a pre-configured list of tenants; only tenants on this list can use the new rules.
[0058] After evaluation, if the tenant corresponding to the clearing and settlement request is within the gray-scale whitelist, it means that the tenant has been selected to participate in the new rule verification, and the new version of the rule is selected as the target billing rule for that tenant. The new version of the rule refers to a rule version that has been modified or optimized compared to the default version, and usually includes new billing logic or rate adjustments. If the tenant corresponding to the clearing and settlement request is not within the gray-scale whitelist, it means that the tenant has not been selected to participate in the verification, and the system selects the old version of the rule as the target billing rule. The old version of the rule refers to the rule version used in full deployment before the gray-scale release, and is usually the same version as the default rule. In this way, the scope of the new rule can be precisely controlled at the tenant level, realizing a gray-scale release process of small-volume verification and gradual scaling.
[0059] This embodiment solves the problem in existing technologies where billing rule changes cannot be verified on a small scale and can only be deployed to a full scale, leading to uncontrollable risks. It achieves refined gray-scale deployment of billing rules, allowing for gradual verification of new rules by tenant, significantly reducing the online risk of rule changes, and supporting smooth rollback and version traceability of rules.
[0060] In step S103, the rule engine is invoked, and the billing factor in the clearing voucher is input into the decision chain corresponding to the target billing rule. The decision chain is executed sequentially to generate at least one billing order.
[0061] In one optional implementation, the billing factor in the clearing document is input into the decision chain corresponding to the target billing rule, and the decision chain is executed sequentially to generate at least one billing statement, including: Input the billing factor in the clearing document into the decision chain corresponding to the target billing rule. The decision chain contains at least one sub-billing rule. The decision chain is executed sequentially based on the billing factors to generate at least one billing bill. Record the intermediate variables and execution results generated during the execution of each sub-billing rule in the decision chain; The execution log is generated by associating the billing factor, intermediate variables, execution results, and version number of the target billing rule with the globally unique identifier of the clearing voucher.
[0062] A rule engine is a programmable logic execution framework used to parse and run pre-defined calculation scripts; a billing factor is an input variable on which a certain calculation result depends, such as order amount, commission rate, surcharge, etc.; a decision chain is an execution process composed of multiple sub-billing rules in sequence, used to control the priority and path jump of billing calculation under different conditions; a billing bill is a record of the results of the settlement output, and each billing bill corresponds to the income or expenditure amount of a settlement entity on a fee item.
[0063] In this embodiment, the software development kit (SDK) provided by the rules engine is first invoked to encapsulate the billing factors extracted from the clearing voucher into a context object that the rules engine can recognize. After encapsulation, the context object is then passed to the rules engine, triggering the rules engine to execute the calculation process. The rules engine SSD is a collection of programming interfaces provided by the rules engine to enable interaction between the business system and the rules engine. The context object is a data container that carries input parameters; the rules engine reads the billing factors from this container for subsequent calculations.
[0064] Next, after receiving the context object, the rule engine parses the decision chain corresponding to the target billing rule. Each decision chain contains at least one sub-billing rule, and each sub-billing rule corresponds to an independent calculation step, such as calculating the driver's commission ratio, calculating the driver's actual income, or determining whether to trigger the income cap logic. Multiple sub-billing rules are chained together in a preset order, and the execution result of the previous rule can be used as the input for the next rule.
[0065] The rule engine executes each sub-billing rule sequentially according to the decision chain, based on the billing factors in the context object. Each sub-billing rule can use AviatorScript expressions to describe its specific calculation logic; for example, driver income equals order amount multiplied by driver commission percentage. After executing all sub-billing rules in the decision chain, the rule engine assembles the final execution results into at least one billing statement. Each billing statement records the income and expenditure amount of a clearing entity for a specific fee item; for example, a driver's income of forty yuan for the trip fee item.
[0066] During the execution of the decision chain, the rule engine also records the intermediate variables generated during the execution of each sub-billing rule and the final execution result. Intermediate variables refer to temporary values calculated during the execution of the sub-billing rule, such as the initially calculated driver commission rate of 0.8%, which will be referenced by other sub-billing rules later. The execution result refers to the final amount or judgment result output by the sub-billing rule.
[0067] Finally, the billing factor, intermediate variables, execution results, and the version number of the target billing rule are associated with the globally unique identifier of the clearing voucher to generate a complete execution log. This log records the entire clearing and settlement calculation process, including the input data, calculation steps, intermediate results, and rule version used. When billing anomalies occur or financial reconciliation is required, the corresponding execution log can be retrieved using the globally unique identifier to reconstruct the entire calculation process and pinpoint the root cause of the problem.
[0068] This embodiment solves the problems of lack of traceability in the clearing and settlement execution process, difficulty in locating the root cause of problems when anomalies occur, and inability to restore the calculation process in the existing technology. It achieves complete recording and traceability of the entire clearing and settlement calculation process. Each billing order can trace back its calculation basis, intermediate results, and the version of the rule used, which significantly improves the auditability and anomaly detection efficiency of the system.
[0069] In step S104, based on at least one billing statement, a sub-settlement statement corresponding to each clearing and settlement entity is generated, and an accounting operation is performed on the clearing and settlement entity according to the sub-settlement statement, and the settlement status of the sub-settlement statement is updated.
[0070] In one optional implementation, the method further includes performing an account adjustment operation on the clearing and settlement entity based on the sub-settlement statement and updating the settlement status of the sub-settlement statement: Call the account interface corresponding to the clearing and settlement entity of the sub-settlement statement to perform the account operation on the clearing and settlement entity; After the accounting operation is completed, determine whether the operation was successful. If the transaction is successfully executed, the settlement status of the sub-settlement statement will be updated to the first settlement status, which indicates that the sub-settlement statement has been settled. If the transaction operation fails, the settlement status of the sub-settlement statement will be marked as the second settlement status, and the transaction operation will be retried until the transaction operation is successful. The second settlement status is used to indicate that the sub-settlement statement has not been settled.
[0071] In this embodiment, the revenue amounts of each clearing entity in the billing statement are summarized to generate a master settlement statement and multiple sub-settlement statements corresponding to the master settlement statement. The master settlement statement is an overall document that summarizes all accounting records under the entire clearing and settlement request, while the sub-settlement statements are detailed documents broken down according to the clearing and settlement entity. Each sub-settlement statement corresponds to a specific amount of revenue or expenditure required by a clearing and settlement entity.
[0072] Next, the fund account interface corresponding to the clearing entity in the sub-settlement statement is called to perform an account operation for that clearing entity. An account operation refers to the process of triggering account operations based on the clearing results to complete the transfer of fund information flow, such as transferring the calculated driver's income amount to the driver's e-wallet account. The fund account interface is an application programming interface provided by a bank or third-party payment platform for operating account balances.
[0073] After the transaction is completed, it can be determined whether the transaction was successful. For example, the status code returned by the funds account interface can be used to determine whether the transaction was successful. If a success status code is returned, it means that the fund transfer has been completed. If a failure status code is returned, it means that the fund transfer was unsuccessful.
[0074] If the transaction is successfully executed, the settlement status of the corresponding sub-settlement statement will be updated to the first settlement status. The first settlement status is a predefined enumeration value used to indicate that the funds corresponding to the sub-settlement statement have been successfully transferred to the clearing entity's account, i.e., the sub-settlement statement has been settled.
[0075] If the transaction operation fails, the settlement status of the corresponding sub-settlement statement is marked as the second settlement status. After marking, the transaction operation is retried, and the fund transfer is re-invoked through the clearing entity's fund account interface. This retrying continues until the transaction operation succeeds, ensuring that each sub-settlement statement can eventually complete fund settlement. The second settlement status is a predefined enumeration value used to indicate that the funds corresponding to the sub-settlement statement have not yet been successfully transferred, i.e., the sub-settlement statement is unsettled.
[0076] This embodiment executes the transaction operation by calling the account interface of the clearing and settlement entity corresponding to the sub-settlement order. After completion, it determines whether the transaction operation was successful. If successful, the settlement status of the sub-settlement order is updated to the first settlement status, indicating that it has been settled. If it fails, the settlement status of the sub-settlement order is marked to the second settlement status, indicating that it has not been settled. The transaction operation is then retried until it succeeds. This technical solution solves the problems in the prior art where settlement actions directly call the funds interface but lack status tracking and failure retry mechanisms. Once the transaction operation fails, it is easy to cause funds to be missed or the status to be inconsistent and difficult to recover automatically. It realizes reliable recording of the execution result of the transaction operation and automated failure retry compensation, ensuring that each sub-settlement order can eventually complete the fund transfer successfully, which significantly improves the fault tolerance and eventual data consistency of the clearing and settlement system.
[0077] In one alternative implementation, the method further includes: Iterate through the settlement status of the sub-settlement statements corresponding to each clearing and settlement entity; If all sub-settlement orders are in the first settlement state, then the settlement state of the main settlement order corresponding to the sub-settlement order will be updated to the third settlement state, and a settlement completion event will be pushed to the business party corresponding to the clearing and settlement request. The third settlement state is used to indicate that the main settlement order has been settled. If any sub-settlement statement has a settlement status of "second settlement status", a settlement anomaly alarm will be triggered.
[0078] After all sub-settlement statements have completed their transaction processing, the settlement status of each sub-settlement statement corresponding to each clearing entity is iterated through. This iteration involves checking the current status value of each sub-settlement statement one by one. The settlement status of a sub-settlement statement includes a first settlement status and a second settlement status. The first settlement status indicates that the funds corresponding to the sub-settlement statement have been successfully transferred to the clearing entity's account, meaning the sub-settlement statement has been settled. The second settlement status indicates that the funds corresponding to the sub-settlement statement have not yet been successfully transferred, meaning the sub-settlement statement has not yet been settled.
[0079] Next, the settlement status of all sub-settlement statements is determined. If all sub-settlement statements are in the first settlement status, it means that each clearing entity under the entire clearing and settlement request has successfully completed the fund transfer, and the clearing and settlement sub-account processing has been successfully completed. At this time, the settlement status of the master settlement statement corresponding to the sub-settlement statement is updated to the third settlement status. The master settlement statement is the overall document that summarizes all sub-account records under the entire clearing and settlement request, and each sub-settlement statement belongs to one master settlement statement. The third settlement status is a predefined enumerated value used to indicate that all sub-settlement statements corresponding to this master settlement statement have been successfully settled, that is, the entire clearing and settlement request has been processed.
[0080] After updating the status of the master settlement statement, a settlement completion event is pushed to the business party corresponding to the settlement request. The business party refers to the upstream business system that initially initiated the settlement request, such as the order system. The settlement completion event is a notification message used to inform the business party that the settlement and revenue sharing for this transaction has been fully processed. The business party can trigger subsequent business processes based on this event, such as updating the order status to "completed".
[0081] If any sub-settlement document is in the second settlement status, it indicates that at least one clearing entity's fund transfer has not yet been successful, and the current clearing and settlement accounting process is not yet fully completed. This triggers a settlement anomaly alarm. The settlement anomaly alarm can be sent to operations and maintenance personnel via SMS, email, or instant messaging from the monitoring system. The alarm content includes the globally unique identifier of the clearing voucher and information about the specific sub-settlement document that failed to settle, facilitating rapid problem location and intervention by operations and maintenance personnel.
[0082] This embodiment solves the problems of disconnected main and sub-settlement status, inability to uniformly perceive the settlement progress of all sub-settlement orders, and lack of timely notification mechanism for abnormal situations in the existing technology. It achieves unified management and closed-loop monitoring of the entire clearing and settlement process, ensuring that the business party can promptly learn about the settlement completion status and quickly intervene in case of abnormalities, thus significantly improving the observability and operational efficiency of the clearing and settlement system.
[0083] In one optional implementation, if the transaction is successfully executed, the settlement status of the sub-settlement statement is updated to the first settlement status, including: Determine whether the settlement status of the sub-settlement statement has been successfully updated to the first settlement status; After the settlement status of all sub-settlement documents is successfully updated, the status of the globally unique identifier of the clearing voucher is updated to the completed status in the local message table, and a confirmation message is sent to the message queue. If the settlement status update of any sub-settlement document fails, the status of the globally unique identifier of the clearing voucher will be maintained as the processing status in the local message table, and the status of the sub-settlement document whose settlement status update failed will be re-updated until the settlement status of all sub-settlement documents is successfully updated to the first settlement status.
[0084] In this embodiment, after completing the fund account interface call and confirming successful transaction, an attempt is made to update the settlement status of the corresponding sub-settlement order to the first settlement status. The first settlement status indicates that the funds corresponding to the sub-settlement order have been successfully transferred to the clearing and settlement entity's account. At this point, it is necessary to determine whether the settlement status of the sub-settlement order has been successfully updated to the first settlement status, that is, to check whether the database update operation has been completed normally and whether the status value has been correctly written.
[0085] After the settlement status of all sub-settlement documents is successfully updated, the status of the globally unique identifier of the clearing voucher is updated to "Completed" in the local message table. The local message table is a table stored in the clearing and settlement system database used to record message processing status. This table uses the globally unique identifier as its primary key, and each record corresponds to the processing progress of a clearing and settlement request. The "Completed" status indicates that all sub-settlement documents corresponding to this clearing and settlement request have been successfully settled, and the entire clearing and settlement accounting process has been completed. After updating the status in the local message table, an acknowledgment message is sent to the message queue. The message queue is middleware used for asynchronous message transmission between upstream and downstream systems. The acknowledgment message notifies the message queue that the clearing and settlement request has been successfully processed, allowing the message queue to remove the corresponding message from the queue and avoid duplicate delivery.
[0086] If the settlement status update for any sub-settlement document fails, for example due to a database write error or the status value update operation not taking effect, the status of the globally unique identifier of the clearing document will be maintained as "processing" in the local message table. The processing status indicates that the clearing request has begun processing but has not yet been fully completed, unlike the completed status. Maintaining the processing status means that no modifications are made to the status value in the local message table; the original "processing" marker is retained.
[0087] At the same time, for sub-settlement orders whose settlement status update failed, a status re-update is performed, that is, the settlement status of the sub-settlement order is retried to the first settlement status. The status re-update operation is continuously executed until the settlement status of all sub-settlement orders is successfully updated to the first settlement status, ensuring that the status of all sub-settlement orders is eventually correctly updated to the first settlement status, thereby ensuring that the globally unique identifier status in the local message table is ultimately consistent with the actual settlement status of the sub-settlement orders.
[0088] This embodiment solves the problems in the prior art, such as the lack of linkage between the local message table and the settlement status of the settlement document, the inability to correctly synchronize the global status when some sub-settlement documents fail to update, and the lack of an automatic repair mechanism. It achieves the final consistency between the local message table status and the sub-settlement document status, ensuring that the status of the globally unique identifier accurately reflects the processing progress of all sub-settlement documents, and significantly improves the data consistency and automated recovery capability of the clearing and settlement system.
[0089] Figure 3(a) shows another flowchart of the clearing, settlement, and accounting method based on a rule engine according to an embodiment of the present invention. The process of the method will be described in detail below with reference to Figure 3(a).
[0090] As shown in Figure 3(a), the clearing, settlement, and revenue sharing method first receives an MQ request from the business system. The business system refers to the upstream system that generates the business order, such as the ride-hailing order system. The MQ request is an asynchronous message sent by the business system through a message queue. This message carries the business data that needs to be cleared, settled, and revenue shared, including key information such as the order number, total order amount, driver identifier, and channel identifier.
[0091] Upon receiving an MQ request, parameter validation and anti-duplicate operations are performed. Parameter validation checks whether required fields in the request are complete and whether the data format is correct, such as whether the order number is empty and whether the amount is a valid number. Anti-duplicate operations use a unique index mechanism to determine whether the request has already been processed, preventing the same order from being repeatedly processed in the clearing and settlement process.
[0092] After parameter verification and anti-duplicate verification are passed, a clearing voucher is created. The clearing voucher is a standard data structure that carries the original input information of clearing and settlement. The business data in the request is filled into the clearing voucher, and the status of the clearing voucher is initialized to "processing", indicating that the clearing and settlement request has started processing but has not yet been completed.
[0093] After creating a clearing certificate, a rule matching and loading operation is performed. Based on the business dimension information in the clearing certificate, applicable billing rules are searched from the rule base. Business dimension information includes business line identifiers, scenario identifiers, and event identifiers, which are used to accurately locate billing rules.
[0094] The system checks if a rule exists, as there may be no billing rule in the rule base that matches the current business dimension. If the rule does not exist, a rule-not-found error is returned, and the current clearing and settlement process is terminated. If the rule exists, the currently effective rule version is retrieved.
[0095] After obtaining the rule version, determine whether the canary release strategy is enabled. The canary release strategy is a mechanism used to control the limited-scale verification of new rule versions. If the canary release strategy is not enabled, directly load the rule configuration and proceed to the subsequent rule execution phase. If the canary release strategy is enabled, further check the canary release status of the tenant to which the current clearing and settlement request belongs.
[0096] After checking the tenant's grayscale status, determine whether the tenant is in the grayscale whitelist. The grayscale whitelist is a pre-configured list of tenants allowed to use the new rules. If the tenant is in the grayscale whitelist, load the rule configuration for the new rules; if the tenant is not in the grayscale whitelist, load the rule configuration for the old rules.
[0097] After the rule configuration is loaded, the rule engine parameters are encapsulated. Specifically, the billing factor in the clearing certificate is extracted and encapsulated into a context object that the rule engine can recognize, which serves as the input for the rule engine to perform calculations.
[0098] After encapsulation, the rules engine SDK is invoked, triggering the rules engine to perform calculations. The rules engine SDK is the programming interface provided by the rules engine, used to invoke the rules engine's capabilities within business systems. After receiving the context object, the rules engine executes a pre-configured AviatorScript script to perform dynamic cost calculations.
[0099] After the rules engine executes the script, it generates a billing statement. The billing statement is the output of the settlement process. Each billing statement records the income and expenditure amount of a settlement entity on a certain fee item, such as the driver's income amount on the trip fee. The generated billing statement will be passed to the subsequent settlement process to generate a settlement statement and trigger the transaction operation.
[0100] Figure 3(b) shows another flowchart of the clearing and settlement accounting method based on the rule engine according to an embodiment of the present invention. This process follows the billing statement generated in Figure 3(a) and describes the complete execution process from billing statement generation to clearing and settlement accounting completion. The process will be described in detail below with reference to Figure 3(b).
[0101] As shown in Figure 3(b), the billing statement is the output of the clearing process, recording the income and expenditure amounts of each clearing entity for each fee item. After obtaining the billing statement, the process of generating a summary settlement statement is performed, which summarizes all billing statements under the same clearing request and merges the receivables or payables of each entity according to the clearing entity dimension.
[0102] After the summary is completed, a master settlement statement is created, and multiple sub-settlement statements are generated according to the clearing and settlement entity. The master settlement statement is the overall document that summarizes all accounting records under the entire clearing and settlement request. Sub-settlement statements are detailed documents broken down according to the clearing and settlement entity. Each clearing and settlement entity corresponds to one sub-settlement statement, which records the specific amount of income or expenditure required by that entity.
[0103] After the main settlement statement and sub-settlement statements are created, the sub-settlement statements are traversed, and the processing status of each sub-settlement statement is checked in turn to determine whether there are any sub-settlement statements that have not yet completed the accounting process.
[0104] If any unprocessed sub-settlement statements exist, an accounting operation is performed on those sub-settlement statements. Specifically, the fund account interface corresponding to the clearing entity for that sub-settlement statement is invoked to execute the fund transfer. The fund account interface is an application programming interface provided by the bank or third-party payment platform for operating account balances.
[0105] After calling the account interface, the system checks whether the transaction was successful based on the status code returned by the funds account interface. If the transaction was successful, the status of the sub-settlement statement is updated to "settled," indicating that the funds corresponding to the sub-settlement statement have been successfully transferred to the clearing entity's account. After updating the status, the system returns to the step of traversing sub-settlement statements and continues processing the next unprocessed sub-settlement statement.
[0106] If a transaction fails, the sub-statement is marked as failed, and an error message is recorded. The error message includes key data such as the reason for failure, the time of failure, and the API return code, facilitating subsequent troubleshooting. After marking the failure, the process returns to the step of traversing sub-statements and continues processing the next unprocessed sub-statement. Even if a sub-statement transaction fails, the remaining sub-statements continue to be processed, ensuring that all sub-statements are attempted to be processed.
[0107] Once all sub-settlement orders have been processed, meaning there are no unprocessed sub-settlement orders, the traversal loop exits, and the summary judgment phase begins. This involves determining whether all sub-settlement orders have been successfully processed, i.e., checking if the status of each sub-settlement order is "settled".
[0108] If all sub-settlement statements are in the "settled" state, it means that each clearing entity under the entire clearing and settlement request has successfully completed the fund transfer, and the entire clearing and settlement accounting process has been successfully completed. At this time, the status of the master settlement statement is updated to "successful," indicating that all sub-settlement statements corresponding to the master settlement statement have been successfully settled. After completing the master settlement statement status update, a settlement completion event is pushed to the business party to inform the upstream business system that the entire clearing and settlement accounting process has been completed.
[0109] If any sub-settlement document shows a "failed transaction" status, it indicates that at least one clearing entity's fund transfer has not yet been successful, and there is an anomaly in this clearing and settlement process. This triggers an anomaly alarm, notifying operations and maintenance personnel to investigate. Anomaly alarms can be sent via SMS, email, or instant messaging from the monitoring system, and the alarm content includes detailed information about the failed sub-settlement document. After an anomaly alarm is triggered, a manual investigation process begins, where operations and maintenance personnel analyze the cause of the failure and perform corresponding recovery operations. The end of this process marks the end of the entire clearing and settlement process, regardless of whether all transactions are successful or if an anomaly exists, thus completing the processing of this clearing and settlement request.
[0110] This embodiment also provides a clearing and settlement accounting device based on a rules engine, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0111] This embodiment provides a clearing, settlement, and accounting device based on a rules engine, such as... Figure 4 As shown, it includes: The request receiving module 401 is used to receive clearing and settlement requests and convert them into clearing vouchers.
[0112] The rule matching module 402 is used to match the currently effective target billing rule from the rule base based on the business dimension information of the clearing certificate.
[0113] The rule execution module 403 is used to call the rule engine, input the billing factor in the clearing voucher into the decision chain corresponding to the target billing rule, and execute the decision chain in sequence to generate at least one billing order.
[0114] The billing settlement module 404 is used to generate sub-settlement bills corresponding to each clearing and settlement entity based on at least one billing bill, perform accounting operations on the clearing and settlement entity according to the sub-settlement bills, and update the settlement status of the sub-settlement bills.
[0115] In some alternative implementations, the rule matching module 402 includes: The locator key construction unit is used to construct multi-dimensional rule locator keys based on the business line identifier, scenario identifier, and event identifier in the clearing document.
[0116] The rule query unit is used to query the rule set in the rule base that matches the multidimensional rule locator key. The rule set contains multiple versions of billing rules corresponding to the same business logic.
[0117] The rule matching unit is used to obtain the currently effective rule version and determine whether the canary release switch corresponding to the rule version is enabled. If the canary release switch is not enabled, the default version rule is selected as the target billing rule. If the canary release switch is enabled, it determines whether the tenant corresponding to the settlement request is in the canary whitelist associated with the canary release switch. If the tenant corresponding to the settlement request is in the canary whitelist, the new version rule is selected as the target billing rule for the tenant. If the tenant corresponding to the settlement request is not in the canary whitelist, the old version rule is selected as the target billing rule.
[0118] In some alternative implementations, the request receiving module 401 includes: The identifier allocation unit is used to convert clearing and settlement requests into clearing vouchers, assign globally unique identifiers to clearing vouchers, and use the globally unique identifiers as idempotent keys to query the local message table to determine whether the idempotent key already exists.
[0119] The settlement termination unit is used to determine that the clearing voucher has been processed if the idempotent key already exists and the association status of the idempotent key is in processing or completed. It then directly returns the existing processing result and ends the settlement settlement settlement processing for the clearing settlement request.
[0120] The accounting execution unit is used to write a globally unique identifier into the local message table if the idempotent key does not exist, mark the status of the corresponding record in the local message table as "processing", and continue to execute the clearing and settlement accounting processing of the clearing and settlement request.
[0121] In some alternative implementations, the rule enforcement module 403 includes: The input unit is used to input the billing factor in the clearing document into the decision chain corresponding to the target billing rule, and the decision chain contains at least one sub-billing rule.
[0122] The billing bill generation unit is used to execute the decision chain sequentially according to the billing factors to generate at least one billing bill.
[0123] The recording unit is used to record the intermediate variables and execution results generated during the execution of each sub-billing rule in the decision chain.
[0124] The log generation unit is used to associate the billing factor, intermediate variables, execution results, and version number of the target billing rule with the globally unique identifier of the settlement certificate to generate an execution log.
[0125] In some alternative implementations, the billing module 404 includes: The account movement execution unit is used to call the account interface of the clearing and settlement entity corresponding to the sub-settlement statement and perform account movement operations on the clearing and settlement entity.
[0126] The execution judgment unit is used to determine whether the accounting operation was successfully executed after the accounting operation is completed.
[0127] The first update unit is used to update the settlement status of the sub-settlement statement to the first settlement status if the accounting operation is successfully executed. The first settlement status is used to indicate that the sub-settlement statement has been settled.
[0128] The second update unit is used to mark the settlement status of the sub-settlement statement as the second settlement status if the transaction operation fails, and to retry the transaction operation until the transaction operation is successful. The second settlement status is used to represent unsettled sub-settlement statements.
[0129] In some alternative implementations, the billing module 404 further includes: The sub-settlement statement traversal unit iterates through the settlement status of the sub-settlement statements corresponding to each clearing and settlement entity.
[0130] The third update unit is used to update the settlement status of the main settlement order corresponding to the sub-settlement order to the third settlement status if the settlement status of all sub-settlement orders is the first settlement status, and to push the settlement completion event to the business party corresponding to the clearing and settlement request. The third settlement status is used to represent the main settlement order that has been settled.
[0131] The anomaly alarm unit is used to trigger a settlement anomaly alarm if any sub-settlement order has a settlement status of the second settlement status.
[0132] In some optional implementations, the first updating unit includes: The update judgment sub-unit is used to determine whether the settlement status of the sub-settlement document has been successfully updated to the first settlement status.
[0133] The identifier status update sub-unit is used to update the status of the globally unique identifier of the clearing voucher to the completed status in the local message table after the settlement status of all sub-settlement documents has been successfully updated, and to send a confirmation message to the message queue.
[0134] The re-update sub-unit is used to maintain the status of the globally unique identifier of the clearing voucher as "processing" in the local message table if the settlement status update of any sub-settlement document fails, and to re-update the status of the sub-settlement document whose settlement status update failed, until the settlement status of all sub-settlement documents is successfully updated to the first settlement status.
[0135] The rule-engine-based clearing and settlement accounting device provided in this embodiment of the invention can execute the rule-engine-based clearing and settlement accounting method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the method. Further functional descriptions of the above modules and units are the same as in the corresponding embodiments described above, and will not be repeated here.
[0136] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0137] The following is a detailed reference. Figure 5 The diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes based on a program stored in a read-only memory (i.e., ROM 502) or a program loaded from memory 508 into random access memory (i.e., RAM 503). The RAM 503 also stores various programs and data required for the operation of the electronic device. The processor 501, ROM 502, and RAM 503 are interconnected via a bus 504. Input / output (i.e., I / O interface 505) is also connected to the bus 504.
[0138] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0139] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a memory 508, or installed from a ROM 502. When the computer program is executed by the processor 501, it performs the functions defined in the rule engine-based clearing and settlement accounting method of the embodiments of the present invention.
[0140] Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0141] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium after being downloaded via a network. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the rule engine-based clearing and settlement accounting method shown in the above embodiments is implemented.
[0142] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0143] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A clearing, settlement, and revenue sharing method based on a rules engine, characterized in that, The method includes: Receive a clearing and settlement request and convert the clearing and settlement request into a clearing voucher; Based on the business dimension information of the clearing certificate, the currently effective target billing rule is matched from the rule base; The rule engine is invoked, and the billing factor in the clearing certificate is input into the decision chain corresponding to the target billing rule. The decision chain is executed sequentially to generate at least one billing statement. Based on the at least one billing statement, a sub-settlement statement corresponding to each clearing and settlement entity is generated, and an account operation is performed on the clearing and settlement entity according to the sub-settlement statement, and the settlement status of the sub-settlement statement is updated.
2. The method according to claim 1, characterized in that, The process of matching the currently effective target billing rule from the rule base includes: A multi-dimensional rule positioning key is constructed based on the business line identifier, scenario identifier, and event identifier in the clearing certificate; Query the rule set in the rule base that matches the multidimensional rule locating key, wherein the rule set contains multiple versions of billing rules corresponding to the same business logic; Obtain the rule version that is currently in effect, and determine whether the canary release switch corresponding to the rule version is enabled; If the gray-scale release switch is not turned on, the default version rule will be selected as the target billing rule. If the grayscale release switch is turned on, it is determined whether the tenant corresponding to the clearing and settlement request is in the grayscale whitelist associated with the grayscale release switch; if the tenant corresponding to the clearing and settlement request is in the grayscale whitelist, the new version of the rule is selected as the target billing rule for the tenant; if the tenant corresponding to the clearing and settlement request is not in the grayscale whitelist, the old version of the rule is selected as the target billing rule.
3. The method according to claim 1, characterized in that, The step of converting the clearing and settlement request into a clearing voucher includes: The clearing and settlement request is converted into a clearing voucher, and a globally unique identifier is assigned to the clearing voucher. The globally unique identifier is used as an idempotent key to query the local message table to determine whether the idempotent key already exists. If the idempotent key already exists and the association status of the idempotent key is in processing or completed, then it is determined that the clearing voucher has been processed, the existing processing result is returned directly, and the clearing and settlement splitting processing of the clearing and settlement request is ended. If the idempotent key does not exist, the globally unique identifier is written into the local message table, the status of the corresponding record in the local message table is marked as processing, and the clearing and settlement processing of the clearing and settlement request continues.
4. The method according to claim 1, characterized in that, The step of inputting the billing factor in the clearing voucher into the decision chain corresponding to the target billing rule, and sequentially executing the decision chain to generate at least one billing statement, includes: The billing factor in the clearing document is input into the decision chain corresponding to the target billing rule, and the decision chain contains at least one sub-billing rule; The decision chain is executed sequentially according to the billing factors to generate at least one billing statement; Record the intermediate variables and execution results generated during the execution of each sub-billing rule in the decision chain; The billing factor, the intermediate variable, the execution result, and the version number of the target billing rule are associated with the globally unique identifier of the clearing certificate to generate an execution log.
5. The method according to claim 1, characterized in that, The method further includes performing an account adjustment operation on the clearing and settlement entity based on the sub-settlement statement and updating the settlement status of the sub-settlement statement. Call the account interface corresponding to the clearing and settlement entity of the sub-settlement statement to perform an account operation on the clearing and settlement entity; After the transaction is completed, determine whether the transaction was successfully executed. If the transaction is successfully executed, the settlement status of the sub-settlement statement is updated to the first settlement status, which indicates that the sub-settlement statement has been settled. If the transaction operation fails, the settlement status of the sub-settlement statement is marked as the second settlement status, and the transaction operation is retried until the transaction operation is successful. The second settlement status is used to indicate that the sub-settlement statement has not been settled.
6. The method according to claim 5, characterized in that, The method further includes: Iterate through the settlement status of the sub-settlement statements corresponding to each clearing and settlement entity; If the settlement status of all sub-settlement orders is the first settlement status, then the settlement status of the main settlement order corresponding to the sub-settlement order is updated to the third settlement status, and a settlement completion event is pushed to the business party corresponding to the clearing and settlement request, wherein the third settlement status is used to indicate that the main settlement order has been settled; If any sub-settlement statement has the second settlement status, a settlement anomaly alarm will be triggered.
7. The method according to claim 5, characterized in that, If the transaction is successfully executed, the settlement status of the sub-settlement statement will be updated to the first settlement status, including: Determine whether the settlement status of the sub-settlement statement has been successfully updated to the first settlement status; After the settlement status of all sub-settlement statements is successfully updated, the status of the globally unique identifier of the clearing voucher is updated to the completed status in the local message table, and a confirmation message is sent to the message queue. If the settlement status update of any sub-settlement document fails, the status of the globally unique identifier of the clearing voucher is maintained as processing in the local message table, and the status of the sub-settlement document whose settlement status update failed is re-updated until the settlement status of all sub-settlement documents is successfully updated to the first settlement status.
8. A clearing, settlement, and accounting device based on a rules engine, characterized in that, The device includes: The request receiving module is used to receive clearing and settlement requests and convert the clearing and settlement requests into clearing vouchers. The rule matching module is used to match the currently effective target billing rule from the rule base based on the business dimension information of the clearing certificate; The rule execution module is used to call the rule engine, input the billing factor in the clearing certificate into the decision chain corresponding to the target billing rule, and execute the decision chain in sequence to generate at least one billing statement. The billing settlement module is used to generate sub-settlement statements corresponding to each clearing entity based on the at least one billing statement, perform accounting operations on the clearing entity according to the sub-settlement statements, and update the settlement status of the sub-settlement statements.
9. An electronic device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the rule engine-based clearing and settlement accounting method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer program product, characterized in that, Includes computer instructions for causing a computer to execute the clearing, settlement, and accounting method based on a rule engine as described in any one of claims 1 to 7.
