Data processing methods, devices, and storage media based on rule engines

By adopting a data processing method based on rules engine in the business system, the system maintenance and R&D efficiency problems caused by changing rules are solved, and efficient system maintenance and cost reduction are achieved.

CN114020372BActive Publication Date: 2025-05-13CHONGQING ZHUBAJIE NETWORK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111388682.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-22
Publication Date
2025-05-13
Estimated Expiration
2041-11-22

AI Technical Summary

Technical Problem

The existing business systems are difficult to maintain when the rules are changing, and the R&D efficiency and cost are high.

Method used

The data processing method based on the rule engine is adopted, by setting custom rule objects and conditional object data, initializing rule groups and rule engine objects, forming target rule groups, and executing rule engine programs to achieve automatic execution of rules.

Benefits of technology

It effectively solves the system maintenance problems, R&D efficiency problems and R&D cost problems caused by changing business system rules, and improves the system's maintainability and R&D efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114020372B_ABST
    Figure CN114020372B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a data processing method, device and storage medium based on a rule engine. The method includes: setting multiple custom rule objects and condition object data; multiple custom rule objects inherit the same parent rule class; initializing the custom rule object; initializing the rule group collection object, and passing in the initialized custom rule object; initializing the rule engine object, and injecting the condition object data and the initialized rule group collection object into the method of the rule engine object to form a target rule group; executing the rule engine program, executing each rule in turn according to the execution order in the target rule group, and obtaining a processing result of successful execution or failed execution. The implementation of the embodiment of the present invention effectively solves the system maintainability problems, R&D efficiency problems and R&D cost problems caused by the changeable rules of the business system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a data processing method, device and storage medium based on a rule engine. Background Art

[0002] As business scenarios become increasingly complex, involving many scenarios, rules, changes, and objects, the fixed business rules of the business system are difficult to adapt to the rapid iteration speed and changes. It is often necessary to add a lot of judgment logic code and changes in the rule judgment, resulting in the system becoming increasingly complex and bloated, difficult to maintain, and greatly increasing the system's R&D efficiency and cost. Summary of the invention

[0003] In view of the technical defects in the prior art, the purpose of the embodiments of the present invention is to provide a data processing method, device and storage medium based on a rule engine to solve the system maintainability problems, R&D efficiency problems and R&D cost problems caused by the changing rules of the business system.

[0004] To achieve the above objectives, in a first aspect, an embodiment of the present invention provides a data processing method based on a rule engine, comprising:

[0005] Setting multiple custom rule objects and condition object data; multiple custom rule objects inherit the same parent rule class;

[0006] Initialize the custom rule object;

[0007] Initialize the rule group set object and pass in the initialized custom rule object;

[0008] Initialize the rule engine object, and inject the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group;

[0009] The rule engine program is executed, and each rule is executed in turn according to the execution order in the target rule group to obtain a processing result of execution success or execution failure.

[0010] As a specific implementation of the present application, multiple custom rule objects are set as follows:

[0011] Abstract the matching object data and encapsulate it into a data generic object;

[0012] The data generic object can implement an iterative interface and include a set collection, and the data generic object encapsulates add, remove and traverse methods.

[0013] In some specific implementations of the present application, the setting condition object data is specifically:

[0014] Encapsulate the matched rule object to obtain a rule group object; the rule group object can implement an iteration interface and contain a set collection, and the rule group object encapsulates injection, removal and traversal methods;

[0015] Encapsulate custom annotations; the custom annotations include conditional annotations, execution action annotations, and rule class annotations;

[0016] Encapsulation interface; the interface includes rule engine interface and rule interface;

[0017] Encapsulates the basic rule implementation class; this class can implement the rule engine interface and override the doRun method;

[0018] Encapsulates the basic case rule class; this class encapsulates the when(Boolean flag) method and adds method annotations.

[0019] In certain preferred embodiments of the present application, the method further comprises:

[0020] If the execution fails, the failure reason is obtained and the log is printed.

[0021] In a second aspect, an embodiment of the present invention further provides a rule-based data processing device, comprising:

[0022] A setting unit, used to set multiple custom rule objects and condition object data; multiple custom rule objects inherit the same parent rule class;

[0023] An initialization unit, used to initialize the custom rule object;

[0024] The initialization unit is also used to initialize the rule group set object and pass in the initialized custom rule object;

[0025] The initialization unit is also used to initialize the rule engine object, and inject the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group;

[0026] The execution unit is used to execute the rule engine program, execute each rule in turn according to the execution order in the target rule group, and obtain a processing result of execution success or execution failure.

[0027] In a third aspect, an embodiment of the present invention provides a data processing device based on a rule engine, comprising a processor, an input device, an output device, and a memory, wherein the processor, the input device, the output device, and the memory are interconnected via a bus, and the memory is used to store a computer program, wherein the computer program includes program instructions. The processor is configured to call the program instructions to execute the method steps described in the first aspect above.

[0028] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, the method steps described in the first aspect are implemented.

[0029] The implementation of the embodiments of the present invention effectively solves the system maintainability problem, the R&D efficiency problem and the R&D cost problem caused by the changeable rules of the business system. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the specific implementation of the present invention or the technical solution in the prior art, the drawings required for use in the specific implementation or the description of the prior art are briefly introduced below.

[0031] Figure 1 is a flow chart of a data processing method based on a rule engine provided by a first embodiment of the present invention;

[0032] Figure 2 is a flow chart of a data processing method based on a rule engine provided by a second embodiment of the present invention;

[0033] Figure 3 is a structural diagram of a data processing device based on a rule engine provided by an embodiment of the present invention;

[0034] Figure 4 This is another structural diagram of a data processing device based on a rule engine provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0036] The inventive concept of the present invention is: based on the rule engine, it uses the existing jexl expression language engine to highly abstract the objects to be matched and the matching rules, forming four basic core class libraries: execution engine, execution rules, execution data, and execution interface. The execution rules are traversed in the execution engine class, and the execution data is matched at the same time. Different execution interfaces are called according to different execution rule types to finally obtain the desired results.

[0037] Please refer to Figure 1 The data processing method based on the rule engine provided by the first embodiment of the present invention includes:

[0038] S1, prepare the rule object and its condition object data.

[0039] S2, initialize the pre-selected custom rule object.

[0040] S3, initialize the rule group collection object and inject the above prepared rule object.

[0041] S4, initialize the rule engine environment and its objects and pass the above prepared condition object data and rule group set into the rule engine object method.

[0042] S5, execute the rule engine program. The rule engine program will execute each rule in the order of rule execution in the rule group. If the execution is successful, the result will be given according to the respective defined rule logic. If the execution fails, the failure reason will be thrown and the log will be printed. This execution program ends.

[0043] Please refer to Figure 2 , is another embodiment of the data processing method of the present invention, comprising the following steps:

[0044] S201, setting a plurality of custom rule objects and condition object data.

[0045] Among them, multiple custom rule objects inherit the same parent rule class; setting multiple custom rule objects is specifically as follows:

[0046] Abstract the matching object data and encapsulate it into a data generic object;

[0047] The data generic object can implement an iterative interface and include a set collection. The data generic object encapsulates add, remove and traverse methods.

[0048] Furthermore, the condition object data includes rule combination objects, custom annotations, interfaces, basic rule implementation classes, and basic case rule classes; setting the condition object data specifically includes:

[0049] Encapsulate the matched rule object to obtain a rule group object; the rule group object can implement an iteration interface and contain a set collection, and the rule group object encapsulates injection, removal and traversal methods;

[0050] Encapsulate custom annotations; the custom annotations include conditional annotations, execution action annotations, and rule class annotations;

[0051] Encapsulation interface; the interface includes rule engine interface and rule interface;

[0052] Encapsulates the basic rule implementation class; this class can implement the rule engine interface and override the doRun method;

[0053] Encapsulates the basic case rule class; this class encapsulates the when(Boolean flag) method and adds method annotations.

[0054] S202: Initialize the custom rule object.

[0055] S203, initializing the rule group set object, and passing in the initialized custom rule object.

[0056] S204, initializing the rule engine object, and injecting the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group.

[0057] S205, executing the rule engine program, executing each rule in turn according to the execution order in the target rule group, and obtaining a processing result of execution success or execution failure.

[0058] S206: If the execution fails, the failure reason is obtained and a log is printed.

[0059] It can be seen from the above description that the embodiments of the present invention effectively solve the system maintainability problem, the R&D efficiency problem and the R&D cost problem caused by the changeable rules of the business system.

[0060] Furthermore, the data processing method provided in the embodiment of the present invention abstracts the matching rules and matching objects. The matching rules can be any customized matching rules. These customized rules all inherit the same parent rule class. The matching data objects can be objects, collections, and their basic data types, ensuring that the rule engine supports matching the above data types according to customized rules and obtaining the desired results. Therefore, with this rule engine method component, each system only needs to reference the component. There is no need to change the code for matching business rules that meet the component. Only simple data configuration is required to obtain the desired effect, and there is no need for each business system to develop its own rule system, thereby greatly improving R&D efficiency and cost, and the maintainability of the system will also be greatly improved.

[0061] In order to better understand the above method embodiment, an example is given below:

[0062] 1. Abstract the matching object data and encapsulate a data generic object Targets (a custom-named Java class) that implements the Iterable interface and contains a Set (a type of collection). All rule conditional data can be added to the Targets, which encapsulates methods such as adding, removing, and traversing to operate conditional data.

[0063] 2. Encapsulate the matched rule objects to obtain the rule group object RuleGroup (a custom-named Java class) that implements the Iterable interface and contains the Set collection. The rule group encapsulates methods such as injection, removal, and traversal to operate the rule objects.

[0064] 3. Encapsulate custom annotations: @DoCondition (conditional annotation, custom-named java annotation interface class), @DoAction (action execution annotation, custom-named java annotation interface class), @DoRule (rule class annotation, custom-named java annotation interface class);

[0065] Encapsulation interface: DoRulesEngine (rule engine interface, custom-named java interface class), DoRule (rule interface, custom-named java interface class);

[0066] Encapsulates BaseRulesEngine (basic rule implementation class, custom named java implementation class), which implements DoRulesEngine interface and overrides doRun method, which will traverse all rules and execute the conditional methods and action methods of the rules. This method calls DoRuleProxy (rule call proxy class, custom named java class) to execute the method of the rule class, because DoRuleProxy will obtain the annotation of the ordinary rule class according to the reflection principle to identify and call the conditional method (DoCondition) and execution action method (DoAction) of the ordinary rule class, and finally achieve the effect of proxy execution of the rule class.

[0067] 4. Encapsulate a basic case rule class (CaseRule) and add the class annotation DoRule. This class encapsulates two methods, namely the when(Boolean flag) method and adds the method annotation DoCondition and the doPrint() method. This method adds the annotation DoAction. The when method determines whether the input flag is true and returns the judgment result. According to the return result value, it determines whether to execute the doPrint method and execute the business rules in the doPrint method. Since it is just a case relationship, this method only prints a sentence "hello rule!".

[0068] 5. Initialize the Targets object and add a boolean parameter flag with a value of true.

[0069] 6. Initialize CaseRule and RuleGroup objects, and inject CaseRule into RuleGroup.

[0070] 7. Initialize the BaseRulesEngine object and pass in the initialized Targets object and CaseRule.

[0071] 8. Start executing the doRun method of BaseRulesEngine. The execution program will execute the rule code of CaseRule according to the logic designed by the rule engine, and finally get the desired result. According to the condition setting of this case, since the flag satisfies true, the doPrint method will be executed, so "hello rule!" is printed in the console, and the program ends.

[0072] This method can be further expanded based on this design framework method to adapt to a variety of business scenarios, effectively reduce the multiple logic and rule codes in the business, and improve R&D efficiency and system maintainability.

[0073] Based on the same invention concept, please refer to Figure 3 , an embodiment of the present invention provides a data processing device based on a rule engine. As shown in the figure, the data processing device includes:

[0074] A setting unit 10 is used to set a plurality of custom rule objects and condition object data; the plurality of custom rule objects inherit the same parent rule class;

[0075] An initialization unit 11, used to initialize the custom rule object;

[0076] The initialization unit 11 is also used to initialize the rule group set object and pass in the initialized custom rule object;

[0077] The initialization unit 11 is also used to initialize the rule engine object, and inject the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group;

[0078] The execution unit 12 is used to execute the rule engine program, and execute each rule in sequence according to the execution order in the target rule group to obtain a processing result of execution success or execution failure.

[0079] Furthermore, the setting unit 10 is specifically used for:

[0080] Abstract the matched object data and encapsulate it into a data generic object; the data generic object can implement an iterative interface and contain a set collection, and the data generic object encapsulates methods such as adding, removing and traversing;

[0081] Encapsulate the matched rule object to obtain a rule group object; the rule group object can implement an iteration interface and contain a set collection, and the rule group object encapsulates injection, removal and traversal methods;

[0082] Encapsulate custom annotations; the custom annotations include conditional annotations, execution action annotations, and rule class annotations;

[0083] Encapsulation interface; the interface includes rule engine interface and rule interface;

[0084] Encapsulates the basic rule implementation class; this class can implement the rule engine interface and override the doRun method;

[0085] Encapsulates the basic case rule class; this class encapsulates the when(Boolean flag) method and adds method annotations, etc.

[0086] Furthermore, the execution unit 12 is also used for:

[0087] If the execution fails, the failure reason is obtained and the log is printed.

[0088] Optionally, in another preferred embodiment of the present application, Figure 4 As shown, the data processing apparatus may include: one or more processors 101, one or more input devices 102, one or more output devices 103 and a memory 104, wherein the processors 101, the input devices 102, the output devices 103 and the memory 104 are interconnected via a bus 105. The memory 104 is used to store a computer program, wherein the computer program includes program instructions, and the processor 101 is configured to call the program instructions to execute the aforementioned method steps.

[0089] It should be understood that in the embodiment of the present invention, the processor 101 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0090] The input device 102 may include a keyboard, etc., and the output device 103 may include a display (LCD, etc.), a speaker, etc.

[0091] The memory 104 may include a read-only memory and a random access memory, and provides instructions and data to the processor 101. A portion of the memory 104 may also include a non-volatile random access memory. For example, the memory 104 may also store information on the device type.

[0092] In a specific implementation, the processor 101, input device 102, and output device 103 described in the embodiment of the present invention can execute the implementation method described in the embodiment of the method provided by the embodiment of the present invention, which will not be repeated here.

[0093] It should be noted that, for a more specific working process of the data processing device, please refer to the aforementioned method embodiment part, which will not be repeated here.

[0094] Furthermore, corresponding to the above-mentioned rule engine-based data processing method, an embodiment of the present invention also provides a readable storage medium on which a computer program / instruction is stored, and when the computer program / instruction is executed by a processor, the method of the above-mentioned method embodiment part is implemented.

[0095] The computer-readable storage medium may be an internal storage unit of the client described in the foregoing embodiment, such as a hard disk or memory of the system. The computer-readable storage medium may also be an external storage device of the system, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the system. Further, the computer-readable storage medium may also include both an internal storage unit of the system and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the system. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0096] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0097] In the several embodiments provided in the present application, it should be understood that the disclosed units and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.

[0098] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A data processing method based on a rule engine, characterized in that: include: Setting multiple custom rule objects and condition object data; multiple custom rule objects inherit the same parent rule class; Initialize the custom rule object; Initialize the rule group set object and pass in the initialized custom rule object; Initialize the rule engine object, and inject the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group; Execute the rule engine program, execute each rule in turn according to the execution order in the target rule group, and obtain a processing result of execution success or execution failure; The specific data of the condition object is: Encapsulate the matched rule objects to obtain the rule group object; the rule group object can implement the iteration interface and contains the data generic object Targets of the set collection. All the conditional data of the rules are added to the Targets. The rule group object encapsulates the injection, removal and traversal methods; Encapsulate custom annotations; the custom annotations include conditional annotations, execution action annotations, and rule class annotations; Encapsulation interface; The interface includes a rule engine interface and a rule interface; Encapsulates the basic rule implementation class; this class can implement the rule engine interface and override the doRun method; Encapsulates the basic case rule class; this class encapsulates the when (Boolean flag) method and adds method annotations; To set multiple custom rule objects: Abstract the matching object data and encapsulate it into a data generic object; The data generic object can implement an iterative interface and contains a set collection, and the data generic object encapsulates add, remove and traverse methods.

2. The data processing method according to claim 1, characterized in that: The condition object data includes rule combination objects, custom annotations, interfaces, basic rule implementation classes and basic case rule classes.

3. The data processing method according to any one of claims 1 to 2, characterized in that: The method further comprises: If the execution fails, the failure reason is obtained and the log is printed.

4. A data processing device based on a rule engine, characterized in that: include: A setting unit, used to set multiple custom rule objects and condition object data; multiple custom rule objects inherit the same parent rule class; An initialization unit, used to initialize the custom rule object; The initialization unit is also used to initialize the rule group set object and pass in the initialized custom rule object; The initialization unit is also used to initialize the rule engine object, and inject the condition object data and the initialized rule group set object into the method of the rule engine object to form a target rule group; An execution unit, used to execute the rule engine program, execute each rule in turn according to the execution order in the target rule group, and obtain a processing result of execution success or execution failure; The setting unit is specifically used for: Encapsulate the matched rule objects to obtain the rule group object; the rule group object can implement the iteration interface and contains the data generic object Targets of the set collection. All the conditional data of the rules are added to the Targets. The rule group object encapsulates the injection, removal and traversal methods; Encapsulate custom annotations; the custom annotations include conditional annotations, execution action annotations, and rule class annotations; Encapsulation interface; The interface includes a rule engine interface and a rule interface; Encapsulates the basic rule implementation class; this class can implement the rule engine interface and override the doRun method; Encapsulates the basic case rule class; this class encapsulates the when (Boolean flag) method and adds method annotations; Abstract the matching object data and encapsulate it into a data generic object; The data generic object can implement an iterative interface and contains a set collection, and the data generic object encapsulates add, remove and traverse methods.

5. A data processing device based on a rule engine, comprising a processor, an input device, an output device and a memory, wherein the processor, the input device, the output device and the memory are interconnected via a bus, the memory is used to store a computer program, and the computer program includes program instructions, characterized in that: The processor is configured to call program instructions to execute the method steps of claim 3.

6. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the method steps as claimed in claim 3 are implemented.

Citation Information

Patent Citations

  • Distributed rule engine system and construction method thereof

    CN106777029A

  • Business processing method, system and related equipment based on visualization rule engine

    CN109144374A