A rule engine execution method, storage medium and server
By setting event trigger points in the rule engine and separating business logic and event rules, the problem of scattered and reconstructed risk in the rule engine call logic is solved, and development efficiency and accuracy are improved.
Patent Information
- Application Number
- CN201811181899.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-10-11
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2038-10-11
AI Technical Summary
In the existing technology, the calling logic of the rule engine is scattered and the risk of reconstruction is high, resulting in low development efficiency.
By setting event trigger points, query operations are triggered when business logic is called, business logic and event rules are separated, and only updated when event rules are modified, avoiding modifications to business logic code and reducing reconstruction risks.
It improves development efficiency, reduces development difficulty and reconstruction risks, and ensures the accuracy and effectiveness of event rules.
Smart Images

Figure CN109542935B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to an execution method, storage medium and server of a rule engine. Background Art
[0002] The development and maintenance of complex enterprise-level projects face the problem that software must "change as needed." Since business decisions and business logic that often change with external conditions and needs are solidified in the code, software development and maintenance become extremely difficult, consuming a lot of time and cost. Therefore, there is an urgent need to separate the decision logic of enterprise decision makers and the technical decisions of application developers, and put the decision logic of these enterprise decision makers in a central database or other places so that they can be dynamically managed and modified at runtime, thereby improving the flexibility and adaptability of the software system. In such a dynamic environment, rule engines came into being. Rule engines can increase the maintainability of software and provide software with the function of allowing users to directly modify business logic, so that software projects will not be difficult to run due to high maintenance costs.
[0003] In the past, when using rule engines, they were often explicitly called in the code and the rules were executed. What rules needed to be called at each point was hard-coded in the code. The disadvantage of this is that the logic of calling the rule engine is relatively scattered, and the risk of refactoring is high, resulting in low development efficiency. Summary of the invention
[0004] The embodiments of the present invention provide a rule engine execution method, storage medium and server to solve the problem in the prior art that the logic of calling the rule engine is relatively scattered, the reconstruction risk is high, and thus the development efficiency is low.
[0005] A first aspect of an embodiment of the present invention provides a method for executing a rule engine, comprising:
[0006] Monitor the calling interface of business logic;
[0007] If it is detected that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed;
[0008] Based on the first event trigger point, querying the first engine rule base whether there is a corresponding event rule for the business logic;
[0009] Execute the business logic according to the query result in the first engine rule base;
[0010] If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed;
[0011] Based on the second event trigger point, searching in the second engine rule base whether there is a corresponding event rule for the business logic;
[0012] The execution result of the business logic is returned according to the query result in the second engine rule base.
[0013] A second aspect of an embodiment of the present invention provides a server, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, the following steps are implemented:
[0014] Monitor the calling interface of business logic;
[0015] If it is detected that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed;
[0016] Based on the first event trigger point, querying the first engine rule base whether there is a corresponding event rule for the business logic;
[0017] Execute the business logic according to the query result in the first engine rule base;
[0018] If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed;
[0019] Based on the second event trigger point, searching in the second engine rule base whether there is a corresponding event rule for the business logic;
[0020] The execution result of the business logic is returned according to the query result in the second engine rule base.
[0021] A third aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0022] Monitor the calling interface of business logic;
[0023] If it is detected that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed;
[0024] Based on the first event trigger point, querying the first engine rule base whether there is a corresponding event rule for the business logic;
[0025] Execute the business logic according to the query result in the first engine rule base;
[0026] If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed;
[0027] Based on the second event trigger point, searching in the second engine rule base whether there is a corresponding event rule for the business logic;
[0028] The execution result of the business logic is returned according to the query result in the second engine rule base.
[0029] In an embodiment of the present invention, by setting an event trigger point, the event rules corresponding to the business logic are queried and executed when the event trigger point is triggered, and the event rules of the engine are separated from the business logic. When the event rules need to be modified, the developer does not need to modify all the business logic codes, but only needs to directly modify the event rules, which reduces the development difficulty and the risk of engine reconstruction. At the same time, this scheme sets two event trigger points. The first event trigger point is used to trigger the query operation of the event rules in the first engine rule base before the business logic is executed, and the second event trigger point is used to trigger the event rule query in the second engine rule base after the business logic is executed. The event rules are searched and executed before and after the business logic is executed, respectively, to ensure the accuracy and effectiveness of the event rule execution, thereby improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0031] Figure 1 is a flow chart of an implementation method of a rule engine provided by an embodiment of the present invention;
[0032] Figure 2is a specific implementation flow chart of the rule engine execution method S102 provided in an embodiment of the present invention;
[0033] Figure 3 is a specific implementation flow chart of the rule engine execution method S104 provided in an embodiment of the present invention;
[0034] Figure 4 is a specific implementation flow chart of step B1 of the rule engine execution method provided in an embodiment of the present invention;
[0035] Figure 5 is a structural block diagram of an execution device of a rule engine provided by an embodiment of the present invention;
[0036] Figure 6 It is a schematic diagram of a server provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only 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.
[0038] Figure 1 The implementation process of the rule engine execution method provided by the embodiment of the present invention is shown, and the method flow includes steps S101 to S107. The specific implementation principle of each step is as follows:
[0039] S101: Monitoring the calling interface of business logic.
[0040] Specifically, different projects have different functions, and different functions require different implementations. The business logic refers to the code that implements the core functions. In an embodiment of the present invention, the business logic is provided with a calling interface, and whether the business logic is called is determined by monitoring the calling interface.
[0041] Optionally, since the codes for implementing different functions are different, that is, the business logics for implementing different functions are also different, in an embodiment of the present invention, the business logic has a business identifier, and the business identifier is used to uniquely identify the business logic. Furthermore, if there are multiple business logics, a calling interface is allocated to each business logic, and the business identifier of the business logic corresponds to the interface number of the calling interface.
[0042] S102: If it is monitored that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in a first engine rule base before the business logic is executed.
[0043] Specifically, an event trigger point is set to trigger the query of event rules. The event trigger point may include but is not limited to one or more of the following: adding rules, updating rules, querying rules, adding rule groups, adding rules to rule groups, deleting rules from rule groups, obtaining operator lists according to data types, obtaining all data types and operator lists supported by each data type, querying the rule list contained in the rule group according to the rule group ID, querying all rule groups, verifying the rules under the specified rule group, judging whether the input data meets the specified rules, verifying the input rules in turn, and obtaining the specified rule data item list.
[0044] In an embodiment of the present invention, if it is detected that the calling interface is called and the event trigger point is triggered, the calling of the rule engine is triggered. The event trigger point includes a first event trigger point and a second event trigger point. The first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed. If it is detected that the calling interface of the business logic is called, the first event trigger point is triggered, that is, the query operation of querying the event rules in the first engine rule base is triggered before the business logic is executed.
[0045] In an embodiment of the present invention, the event rules that need to be processed before the business logic is executed are stored in the first engine rule base, the business logic is separated from the event rules of the engine, and a first event trigger point is set to trigger the query of the event rules corresponding to the business logic. The first event trigger point is triggered when it is detected that the calling interface of the business logic is called.
[0046] Exemplarily, in an embodiment of the present invention, a call request for an event rule of the business logic sent by a rule engine client is received by a rule engine server, and the call request may be a request sent through a corresponding interface of the rule engine client, wherein the number of rule engine clients may be one or more, for example, greater than or equal to 2. In some embodiments, the client calls an application programming interface (Application Programming Interface, API) through a client Jar package provided by the rule engine, and calls the rule engine server through a remote procedure call (Remote Procedure Call, RPC) protocol, for example, the call may be based on the HessianRPC call communication technology, or may be based on other RPC call technologies according to application needs.
[0047] As an embodiment of the present invention, Figure 2 As shown, the above S102 specifically includes:
[0048] A1: Obtain the service identifier of the service logic. The service identifier is used to identify the service logic. Different service identifiers correspond to service logics and implement different functions.
[0049] A2: Determine whether the business identifier of the business logic exists in the preset event trigger set.
[0050] A3: If the service identifier exists in the event trigger set, triggering the first event trigger point corresponding to the service identifier.
[0051] Specifically, not all business logics have corresponding first event trigger points, and therefore, not all business logics will trigger the first event trigger point when called. The preset event trigger set stores the business identifier of the business logic corresponding to the first event trigger point. In an embodiment of the present invention, if it is detected that the business identifier of the business logic of the called interface is in the preset event trigger set, the first event trigger point corresponding to the business identifier is triggered, thereby screening the business logic that triggers the first event trigger point.
[0052] S103: Based on the first event trigger point, query the first engine rule base to see whether there is a corresponding event rule for the business logic.
[0053] Specifically, the event rules stored in the first engine rule base are executed before the business logic is executed. According to the business identifier of the business logic, the event rules corresponding to the business identifier are searched in the first engine rule base.
[0054] S104: Execute the business logic according to the query result in the first engine rule base.
[0055] The query result includes whether the event rule corresponding to the business logic exists in the first engine rule base or not.
[0056] As an embodiment of the present invention, Figure 3 The specific implementation process of the rule engine execution method S104 provided in the embodiment of the present invention is shown, and is described in detail as follows:
[0057] B1: If the event rule corresponding to the business logic is found in the first engine rule base, the processing logic defined by the event rule is executed.
[0058] B2: After executing the processing logic defined by the event rule, execute the business logic.
[0059] B3: If the event rule corresponding to the business logic is not found in the first engine rule base, the business logic is directly executed.
[0060] In an embodiment of the present invention, if the event rule corresponding to the business logic is found in the first engine rule base, the processing logic defined by the event rule is executed first, and then the business logic is executed; if the event rule corresponding to the business logic is not found in the first engine rule base, the business logic is executed directly.
[0061] As an embodiment of the present invention, Figure 4 The specific implementation process of step B1 of the rule engine execution method provided by the embodiment of the present invention is shown, and is described in detail as follows:
[0062] B11: If there are multiple event rules corresponding to the business logic in the first engine rule base, obtain the priority index of the event rule corresponding to the business logic. The priority index is used to identify the processing order of the event rules corresponding to the business logic. The priority index can be pre-defined by the user or determined based on the statistical information of the historical execution records of the multiple event rules.
[0063] B12: Execute the processing logic defined by the event rule corresponding to the business logic in order from high to low according to the priority index.
[0064] In an embodiment of the present invention, when there are multiple event rules corresponding to the business logic in the first engine rule base, the multiple event rules are processed in sequence according to the sorting results of the priority indexes of the event rules, thereby avoiding execution conflicts.
[0065] Optionally, if there are multiple event rules corresponding to the business logic in the first engine rule base, the dependency relationship between the multiple event rules corresponding to the business logic is obtained, and the dependency relationship means that the execution trigger of one event rule depends on the execution of another event rule. The dependency relationship includes the number of event rules that the event rule depends on and the number of event rules that are depended on. Optionally, the greater the number of event rules that the event rule depends on, the higher the priority index of the event rule.
[0066] Optionally, the priority index PriDeg of the event rule is calculated according to the following formula: i :
[0067]
[0068] Among them, ω i represents the preset weight corresponding to the event rule i, L is an integer, representing the number of event rules that the event rule i relies on, L≥0, rely_λl It represents the dependency weight corresponding to the event rule i when the number of event rules it depends on is l, 0≤l≤L, N is the number of event rules corresponding to the business logic, N is a positive integer, and Func is any monotonically increasing function that realizes the mapping from [0,+∞) to [0,1).
[0069] Specifically, the preset weight corresponding to the event rule can be defined according to the type of the event rule. In this embodiment, the types of event rules include adding, modifying and deleting, wherein the priority of adding is higher than the priority of modifying, and the priority of modifying is higher than the priority of deleting. Therefore, it is defined that the preset weight of adding is higher than the preset weight of modifying, and the preset weight of modifying is higher than the preset weight of deleting.
[0070] S105: If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in a second engine rule library after the business logic is executed.
[0071] In an embodiment of the present invention, the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed. If it is detected that the business logic is executed, the second event trigger point is triggered, thereby triggering a query operation of querying event rules in the second engine rule base.
[0072] S106: Based on the second event trigger point, search the second engine rule base to see whether there is a corresponding event rule for the business logic.
[0073] Specifically, the event rules stored in the second engine rule base are executed after the business logic is executed. According to the business identifier of the business logic, the event rules corresponding to the business identifier are searched in the second engine rule base.
[0074] S107: Return the execution result of the business logic according to the query result in the second engine rule base.
[0075] Specifically, if the event rule corresponding to the business logic is found in the second engine rule base, then after executing the business logic, the processing logic defined by the event rule is executed, and the execution result of the processing logic is returned. If the event rule corresponding to the business logic is not found in the second engine rule base, the execution result of the business logic is directly returned.
[0076] For example, the condition is the store number (640100001), and the conclusion is the store company segment (job) (092801) and the store cost center (job) (1201). If the store number of an order is 640100001, the rule engine automatically updates the store company segment (job) and store cost center (job) fields to 092801 and 1201 respectively. In this way, the business logic is separated from the code, allowing the rule engine to automatically match.
[0077] In an embodiment of the present invention, by monitoring the calling interface of the business logic, if it is detected that the calling interface is called, the first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger the query operation of the event rule in the first engine rule base before the business logic is executed. Based on the first event trigger point, the first engine rule base is queried whether there is a corresponding event rule for the business logic, and the business logic is executed according to the query result in the first engine rule base. If the business logic is executed, the second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger the query operation of the event rule in the second engine rule base after the business logic is executed. Event trigger point, searches the second engine rule base for corresponding event rules for the business logic, and returns the execution result of the business logic according to the query result in the second engine rule base. This solution sets event trigger points, and queries and executes event rules corresponding to the business logic only when the event trigger point is triggered, thereby separating the engine's event rules from the business logic. When the event rules need to be modified, developers do not need to modify all business logic codes, but only need to modify the event rules directly, reducing the development difficulty and the risk of engine reconstruction. At the same time, two event trigger points are set to search and execute event rules before and after the execution of the business logic, respectively, to ensure the accuracy and effectiveness of event rule execution, thereby improving development efficiency.
[0078] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0079] Corresponding to the execution method of the rule engine described in the above embodiment, Figure 5 A structural block diagram of an execution device of a rule engine provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0080] Reference Figure 5The execution device of the rule engine includes: an interface monitoring unit 51, a first event trigger point unit 52, a first rule query unit 53, a first execution unit 54, a second event trigger point unit 55, a second rule query unit 56, and a second execution unit 57, wherein:
[0081] An interface monitoring unit 51 is used to monitor the calling interface of the business logic;
[0082] A first event trigger point unit 52, used to trigger a first event trigger point of the business logic if it is detected that the calling interface is called, and the first event trigger point is used to trigger a query operation of event rules in a first engine rule base before the business logic is executed;
[0083] A first rule query unit 53, configured to query the first engine rule base for the business logic based on the first event trigger point to determine whether there is a corresponding event rule;
[0084] A first execution unit 54, configured to execute the business logic according to the query result in the first engine rule base;
[0085] A second event trigger point unit 55, used to trigger a second event trigger point of the business logic if the business logic is executed, and the second event trigger point is used to trigger a query operation of event rules in a second engine rule base after the business logic is executed;
[0086] A second rule query unit 56, configured to search the second engine rule base for a corresponding event rule for the business logic based on the second event trigger point;
[0087] The second execution unit 57 is used to return the execution result of the business logic according to the query result in the second engine rule base.
[0088] Optionally, the first event trigger point unit 52 includes:
[0089] A business identification acquisition module, used to acquire the business identification of the business logic;
[0090] A first judgment module is used to judge whether a business identifier of the business logic exists in a preset event trigger set;
[0091] The first trigger point module is used to trigger the first event trigger point corresponding to the service identifier if the service identifier exists in the event trigger set.
[0092] Optionally, the first execution unit 54 includes:
[0093] A first rule execution module, configured to execute the processing logic defined by the event rule if an event rule corresponding to the business logic is found in the first engine rule base;
[0094] The first business execution module is used to execute the business logic after executing the processing logic defined by the event rule; if the event rule corresponding to the business logic is not found in the first engine rule library, the business logic is directly executed.
[0095] Optionally, the first rule execution module includes:
[0096] A priority index determination submodule, used for obtaining the priority index of the event rule corresponding to the business logic if there are multiple event rules corresponding to the business logic in the first engine rule base;
[0097] The first rule execution submodule is used to execute the processing logic defined by the event rule corresponding to the business logic in order from high to low according to the priority index.
[0098] Optionally, the priority index determination submodule includes:
[0099] A dependency determination submodule, used to obtain the dependency between multiple event rules corresponding to the business logic, wherein the dependency refers to whether the execution trigger of one event rule depends on the execution of another event rule;
[0100] The priority index determination submodule is used to calculate the priority index PriDeg of the event rule according to the following formula i :
[0101]
[0102] Among them, ω i represents the preset weight corresponding to the event rule i, L is an integer, representing the number of event rules that the event rule i relies on, L≥0, rely_λ l It represents the dependency weight corresponding to the event rule i when the number of event rules it depends on is l, 0≤l≤L, N is the number of event rules corresponding to the business logic, N is a positive integer, and Func is any monotonically increasing function that realizes the mapping from [0,+∞) to [0,1).
[0103] In an embodiment of the present invention, by monitoring the calling interface of the business logic, if it is detected that the calling interface is called, the first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed. Based on the first event trigger point, the first engine rule base is queried whether there is a corresponding event rule for the business logic, and the business logic is executed according to the query result in the first engine rule base. If the business logic is executed, the second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed. The event trigger point is used to search the second engine rule base for corresponding event rules of the business logic, and the execution result of the business logic is returned according to the query result in the second engine rule base. This solution sets an event trigger point, and queries and executes the event rules corresponding to the business logic only when the event trigger point is triggered, thereby separating the event rules of the engine from the business logic. When the event rules need to be modified, the developer does not need to modify all the business logic codes, but only needs to modify the event rules directly, thereby reducing the development difficulty and the risk of engine reconstruction. At the same time, two event trigger points are set to search and execute the event rules before and after the execution of the business logic, respectively, to ensure the accuracy and effectiveness of the execution of the event rules, thereby improving the development efficiency.
[0104] Figure 6 FIG. 1 is a schematic diagram of a server provided by an embodiment of the present invention. Figure 6 As shown, the server 6 of this embodiment includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as an execution program of a rule engine. When the processor 60 executes the computer program 62, the steps of the above-mentioned execution method of each rule engine are implemented, such as Figure 1 Alternatively, when the processor 60 executes the computer program 62, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 5 The functions of the units 51 to 57 are shown.
[0105] Exemplarily, the computer program 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program 62 in the server 6.
[0106] The server 6 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The server may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will appreciate that Figure 6 It is only an example of server 6 and does not constitute a limitation on server 6. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the server may also include input and output devices, network access devices, buses, etc.
[0107] The processor 60 may be a central processing unit (CPU), or 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 any conventional processor, etc.
[0108] The memory 61 may be an internal storage unit of the server 6, such as a hard disk or memory of the server 6. The memory 61 may also be an external storage device of the server 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the server 6. Further, the memory 61 may also include both an internal storage unit of the server 6 and an external storage device. The memory 61 is used to store the computer program and other programs and data required by the server. The memory 61 may also be used to temporarily store data that has been output or is to be output.
[0109] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0110] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0111] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for executing a rule engine, characterized in that: include: Monitor the calling interface of business logic; Storing event rules that need to be processed before the business logic is executed in the first engine rule base; If it is detected that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed; Based on the first event trigger point, querying the first engine rule base whether there is a corresponding event rule for the business logic; If the event rule corresponding to the business logic is found in the first engine rule base, the processing logic defined by the event rule is executed; After executing the processing logic defined by the event rule, executing the business logic; If the event rule corresponding to the business logic is not found in the first engine rule base, the business logic is directly executed, including: if there are multiple event rules corresponding to the business logic in the first engine rule base, obtain the priority index of the event rule corresponding to the business logic; execute the processing logic defined by the event rule corresponding to the business logic in order from high to low according to the priority index; if there are multiple event rules corresponding to the business logic in the first engine rule base, obtain the priority index of the event rule corresponding to the business logic, including: Obtaining a dependency relationship between a plurality of event rules corresponding to the business logic, wherein the dependency relationship refers to that the execution trigger of one event rule depends on the execution of another event rule; The priority index of the event rule is calculated according to the following formula: PriDeg i : ; in, ω i Indicates the event rule i The corresponding preset weights, L is an integer representing the event rule i The number of event rules that are relied on, L ≥ 0, rely_ λ l Indicates the event rule i The number of dependent event rules is l The corresponding dependency weight is 0≤ l ≤ L, N is the number of event rules corresponding to the business logic, N is a positive integer, For any implementation from arrive A monotonically increasing function of the mapping; If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed. The event rules stored in the second engine rule base are executed after the business logic is executed; Based on the second event trigger point, searching the second engine rule base for whether there is a corresponding event rule for the business logic; The execution result of the business logic is returned according to the query result in the second engine rule base.
2. The execution method according to claim 1, characterized in that: If it is detected that the calling interface is called, the first event triggering point of the business logic is triggered, including: Obtaining a business identifier for the business logic; Determine whether the business identification of the business logic exists in the preset event trigger set; If the service identifier exists in the event trigger set, the first event trigger point corresponding to the service identifier is triggered.
3. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the execution method of the rule engine as claimed in any one of claims 1 to 2 are implemented.
4. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: Monitor the calling interface of business logic; Storing event rules that need to be processed before the business logic is executed in the first engine rule base; If it is detected that the calling interface is called, a first event trigger point of the business logic is triggered, and the first event trigger point is used to trigger a query operation of event rules in the first engine rule base before the business logic is executed; Based on the first event trigger point, querying the first engine rule base whether there is a corresponding event rule for the business logic; If the event rule corresponding to the business logic is found in the first engine rule base, the processing logic defined by the event rule is executed; After executing the processing logic defined by the event rule, executing the business logic; If the event rule corresponding to the business logic is not found in the first engine rule base, the business logic is directly executed, including: if there are multiple event rules corresponding to the business logic in the first engine rule base, obtain the priority index of the event rule corresponding to the business logic; execute the processing logic defined by the event rule corresponding to the business logic in order from high to low according to the priority index; if there are multiple event rules corresponding to the business logic in the first engine rule base, obtain the priority index of the event rule corresponding to the business logic, including: Obtaining a dependency relationship between a plurality of event rules corresponding to the business logic, wherein the dependency relationship refers to that the execution trigger of one event rule depends on the execution of another event rule; The priority index of the event rule is calculated according to the following formula: PriDeg i : ; in, ω i Indicates the event rule i The corresponding preset weights, L is an integer representing the event rule i The number of event rules that are relied on, L ≥ 0, rely_ λ l Indicates the event rule i The number of dependent event rules is l The corresponding dependency weight is 0≤ l ≤ L, N is the number of event rules corresponding to the business logic, N is a positive integer, For any implementation from arrive A monotonically increasing function of the mapping; If the business logic is executed, a second event trigger point of the business logic is triggered, and the second event trigger point is used to trigger a query operation of event rules in the second engine rule base after the business logic is executed. The event rules stored in the second engine rule base are executed after the business logic is executed; Based on the second event trigger point, searching the second engine rule base for whether there is a corresponding event rule for the business logic; The execution result of the business logic is returned according to the query result in the second engine rule base.
5. The server according to claim 4, characterized in that: If it is detected that the calling interface is called, the first event triggering point of the business logic is triggered, including: Obtaining a business identifier for the business logic; Determine whether the business identification of the business logic exists in the preset event trigger set; If the service identifier exists in the event trigger set, the first event trigger point corresponding to the service identifier is triggered.
Citation Information
Patent Citations
Form verification method and apparatus
CN105404620A
Data quality centralized-monitoring method and device based on electric power enterprise ERP
CN105893214A
Business data verification method and device, storage medium, and electronic equipment
CN107818509A
