A method, device and equipment for implementing business logic
By building a decision system in the blockchain and using decision definition files instead of chain code, the complex problem of blockchain business logic update in the existing technology is solved, simple business logic update and deployment is realized, and high real-time business performance is reduced The difficulty of deploying logic.
Patent Information
- Application Number
- CN202110950565.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-18
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-08-18
AI Technical Summary
In the prior art, blockchain-based applications need to upgrade the chain code when business logic changes. This complex process and high real-time business logic is difficult to deploy in the blockchain.
By building a decision system, using decision definition files instead of chain codes, the business logic in the blockchain is realized. When the business logic needs to be updated, you only need to reload the updated decision definition file to the decision system, avoiding the complex process of collaborative completion of various nodes in the blockchain.
It realizes simple updates and deployment of business logic in blockchain, reducing the difficulty of deploying real-time high-service logic in blockchain.
Smart Images

Figure CN113656351B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a method, device and equipment for implementing business logic. Background Art
[0002] Blockchain is a distributed shared ledger and database with the characteristics of decentralization, immutability, full traceability, traceability, collective maintenance, openness and transparency. Based on these characteristics, blockchain has been widely used in various fields such as finance, Internet of Things, and public services.
[0003] In the prior art, in order to implement the business logic of blockchain-based applications, the chain code that implements the business logic needs to be deployed in each node of the blockchain. If the business logic changes, the chain code that implements the business logic needs to be upgraded. However, the chain code upgrade process requires the collaboration of each node of the blockchain, which is complex to implement and makes it difficult to deploy high-real-time business logic in the blockchain. Summary of the invention
[0004] In view of this, the embodiments of the present application provide a method, device and equipment for implementing business logic, so that the upgrade and update of high-real-time business logic in the blockchain is simpler and easier to operate.
[0005] To solve the above problems, the technical solutions provided in the embodiments of the present application are as follows:
[0006] A method for implementing business logic, the method is applied to a decision system, the decision system is deployed in each node of a blockchain, the decision system is loaded with a decision definition file, each of the decision definition files represents the business logic of a target business, the method comprises:
[0007] Obtaining an application request, wherein the application request includes a business variable;
[0008] Read the business variable attribute value of the business variable from the node database of the current node;
[0009] Determine a first target decision definition file matching the application request from the decision definition files;
[0010] The business logic of the target business corresponding to the first target decision definition file is executed according to the business variable attribute value of the business variable.
[0011] In a possible implementation, the decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action, and determining a first target decision definition file matching the application request from the decision definition file includes:
[0012] When the application request further includes a decision identifier, a first target decision definition file whose decision identifier matches the decision identifier included in the application request is searched from the decision definition file.
[0013] In a possible implementation, the decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action, and determining a first target decision definition file matching the application request from the decision definition file includes:
[0014] When the application request does not include a decision identifier, search the decision definition file for a first target decision definition file in which a decision variable matches a business variable included in the application request and a decision variable attribute value in a decision execution condition matches a business variable attribute value corresponding to the application request.
[0015] In a possible implementation, searching the decision definition file for a first target decision definition file whose decision variables match the business variables included in the application request and whose decision variable attribute values in the decision execution condition match the business variable attribute values corresponding to the application request includes:
[0016] Searching the decision definition file for a second target decision definition file whose decision variables match the business variables included in the application request;
[0017] A first target decision definition file is searched from the second target decision definition file for a decision variable attribute value in a decision execution condition that matches a business variable attribute value corresponding to the application request.
[0018] In a possible implementation, the method further includes:
[0019] When multiple first target decision definition files are found;
[0020] According to the priority order, a first target decision definition file with the highest priority is determined as the first target decision definition file matching the application request.
[0021] In a possible implementation, the method further includes:
[0022] After executing the business logic of the target business corresponding to the first target decision definition file, if the business variable attribute value of the business variable changes, updating the business variable attribute value of the business variable in the node database;
[0023] Notify other nodes to update the business variable attribute value of the business variable.
[0024] In a possible implementation, the method further includes:
[0025] Get the newly added decision definition file;
[0026] Determine whether the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file;
[0027] If they are the same, replacing the third target decision definition file with the newly added decision definition file, wherein the third target decision definition file is a loaded decision definition file having the same decision identifier as the newly added decision definition file;
[0028] If they are not the same, the newly added decision definition file is loaded.
[0029] A device for implementing business logic, the device is applied to a decision system, the decision system is deployed in each node of a blockchain, the decision system is loaded with a decision definition file, each of the decision definition files represents the business logic of a target business, the device comprises:
[0030] An acquisition unit, configured to acquire an application request, wherein the application request includes a business variable;
[0031] A reading unit, used for reading a business variable attribute value of the business variable from a node database of a current node;
[0032] A determining unit, configured to determine a first target decision definition file matching the application request from the decision definition file;
[0033] An execution unit is used to execute the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
[0034] A method for implementing business logic includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for implementing business logic as described above is implemented.
[0035] A computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the implementation method of the business logic as described above.
[0036] It can be seen that the embodiments of the present application have the following beneficial effects:
[0037] The embodiment of the present application provides a method, device and equipment for implementing business logic, which is applied to a decision system and implemented by a decision system. Among them, the decision system is deployed in each node of the blockchain, and each decision system is loaded with a decision definition file for representing the business logic of the target business. The decision system obtains the application request received by the current node, and the application request contains business variables. According to the application request, the decision system reads the business variable attribute value of the business variable from the node database of the current node. Then, the first target decision definition file matching the application request is determined from the decision definition file. The decision system executes the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value. In the embodiment of the present application, by constructing a decision system, the decision definition file in the decision system is used to replace the chain code of the business logic, and the business logic in the blockchain is realized. When the business logic needs to be updated, it does not need to be completed by the collaboration of each node of the blockchain. It only needs to reload the updated decision definition file representing the business logic into the decision system, which is simple to implement, and even the business logic with high real-time performance is easier to deploy in the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of a scenario example provided in an embodiment of the present application;
[0039] Figure 2 A flowchart of a method for implementing business logic provided in an embodiment of the present application;
[0040] Figure 3 A schematic diagram of a business logic for determining a first target decision file and executing a corresponding target business provided by an embodiment of the present application;
[0041] Figure 4 A schematic diagram of another method for implementing business logic provided in an embodiment of the present application;
[0042] Figure 5 A schematic diagram of the structure of a device for implementing business logic provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0044] In order to facilitate understanding and explanation of the technical solutions of the embodiments of the present application, the background technology of the embodiments of the present application will be described below.
[0045] Blockchain is a distributed shared ledger and database with the characteristics of decentralization, immutability, full traceability, traceability, collective maintenance, openness and transparency. Based on these characteristics, blockchain has been widely used in various fields such as finance, Internet of Things, and public services.
[0046] In the prior art, in order to implement the business logic of blockchain-based applications, it is necessary to deploy the chain code that implements the business logic in each node of the blockchain. Among them, the chain code runs in the blockchain and is usually maintained by multiple blockchain nodes.
[0047] When the business logic changes, the chain code that implements the business logic needs to be upgraded. However, the chain code upgrade process requires the collaboration of all nodes in the blockchain, and the steps are cumbersome and the implementation is complex. As long as there is a problem in one link, the upgraded chain code deployment will fail. At the same time, this makes it difficult to deploy business logic with high real-time requirements in the blockchain.
[0048] Based on this, the embodiment of the present application provides a method, device and equipment for implementing business logic. Figure 1 See the example scenario shown. Figure 1 , Figure 1 A schematic diagram of a scenario example provided in an embodiment of the present application. The method can be applied to Figure 1 In the decision system 103 shown, the decision system 103 is deployed in a node in the blockchain. Each node in the blockchain is deployed with a decision system, and the decision system 103 is deployed in the current node of the blockchain as an example for explanation.
[0049] The terminal 101 requests to call the application server 102 to send an application request to the decision system 103. The application server 102 calls the decision system 103 through an interface and sends the application request sent by the terminal 101 to the decision system 103.
[0050] After receiving an application request including at least a business variable, the decision system 103 reads the business variable attribute value of the business variable from the node database 104 of the current node. Furthermore, the decision system 103 determines a first target decision definition file matching the application request from a decision library storing decision definition files.
[0051] Further, the decision system 103 executes the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
[0052] Therefore, by loading the decision definition file into the decision system of the blockchain, when the business logic changes, you only need to modify the decision definition file and reload it to implement the execution of the new business logic, making it easier to deploy high-real-time business logic in the blockchain.
[0053] Those skilled in the art will understand that Figure 1 The framework diagram shown is only an example in which the embodiments of the present application can be implemented. The scope of application of the embodiments of the present application is not limited by any aspect of the framework.
[0054] Based on the above description, the implementation method of the business logic provided in the embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0055] See also Figure 2 , Figure 2 The flowchart of a method for implementing a business logic provided in an embodiment of the present application. The method can be executed by the decision system 103 of the above embodiment, and the decision system is deployed in each node of the blockchain. Figure 2 As shown, the method may include S201-S204:
[0056] S201: Obtain an application request, where the application request includes a business variable.
[0057] The decision system obtains an application request sent by the terminal. The application request can be understood as a request to execute the current business. Generally, the application request can be a query request or an operation request.
[0058] The application request at least includes a business variable. A business variable can be understood as a request parameter in the application request, and its corresponding variable value is variable. For example, the application request is to query whether the account balance is sufficient to pay the credit card bill. The application request is a query request. Among them, the account balance and the credit card bill amount are both business variables.
[0059] S202: Reading a business variable attribute value of a business variable from a node database of the current node.
[0060] The business variable corresponds to a business variable attribute value, that is, a specific value corresponding to the business variable. After the decision system determines the application request, it uses the node database of the current node to read the business variable attribute value of the business variable from the node database.
[0061] For example, the application request is to check whether the account balance is sufficient to pay the credit card bill. The business variables are the account balance and the credit card bill amount. In this scenario, the specific value of the current account balance and the specific value of the credit card bill belong to the business variable attribute values. The status corresponding to the account balance and the status corresponding to the credit card bill also belong to the business variable attribute values. For example, the status corresponding to the credit card bill is unsettled, and the status corresponding to the account balance is normal.
[0062] It can be understood that the node database of the current node can be the ledger database of the current node in the blockchain.
[0063] S203: Determine a first target decision definition file that matches the application request from the decision definition files.
[0064] The decision system is loaded with a decision definition file, which can be saved in the decision library of the decision system. Each decision definition file represents the business logic of a target business. The decision definition file can include a decision identifier, a decision variable, a decision execution condition, and a decision execution action.
[0065] The decision identifier is the unique identifier of the decision definition file in the decision library. The decision variables and business variables have the same meaning. Business variables are variables in business requests, while decision variables are variables in decision definition files. Decision execution conditions and decision execution actions together constitute the business logic represented by the decision definition file.
[0066] As an example, a decision definition file is a text file with a .dd suffix, implemented through declarative programming. Its format is:
[0067]
[0068] in, <name>For decision marking, <attribute1>It is a decision variable and needs to be declared in advance in the decision definition file. <value>The variable value of the decision variable is assigned an initial value when the variable is declared. <conditions>For decision execution conditions, <actions>Execute the action for the decision. When the decision execution conditions are met, the decision execution action is implemented.
[0069] It is understandable that the decision definition file implemented by declarative programming replaces the existing chain code and implements the business logic of the business. By using the constructed decision definition file, when the business logic is updated, the cumbersome steps of chain code update in the prior art are avoided. It is only necessary to modify the decision definition file and re-enter the decision system for loading. Moreover, declarative programming makes it easier to modify the decision definition file.
[0070] After the decision system reads the business variable attribute value of the business variable from the node database, it determines the first target decision definition file that matches the application request from the loaded decision definition files. The meaning of matching can be understood as the business logic in the first target decision definition file can realize the application request, and the business logic that matches the application request is executed by the first target decision file.
[0071] In a possible implementation, the embodiment of the present application provides a specific implementation of determining a first target decision definition file matching an application request from a decision definition file, including:
[0072] When the application request further includes a decision identifier, a first target decision definition file whose decision identifier matches the decision identifier included in the application request is searched from the decision definition file.
[0073] It is understandable that when the application request includes a decision identifier, since the decision identifier is the unique identifier of the decision definition file, the decision system can directly search for the decision identifier that is the same as the decision identifier in the application request from multiple decision definition files in the decision library, and the decision definition file corresponding to the same decision identifier is the first target decision definition file. This method is direct, simple and easy to operate.
[0074] In another possible implementation, the embodiment of the present application provides another specific implementation of determining a first target decision definition file matching an application request from a decision definition file, including:
[0075] When the application request does not include a decision identifier, a first target decision definition file is searched from the decision definition file, in which the decision variables match the business variables included in the application request, and the decision variable attribute values in the decision execution conditions match the business variable attribute values corresponding to the application request.
[0076] It can be understood that when the application request does not include a decision identifier, the business variables and business variable attribute values in the application request can be used to determine the first target decision definition file from multiple decision definition files in the decision library, and the decision variables and decision variable attribute values contained therein match the business variables and business variable attribute values in the business request.
[0077] It should be noted that, in a possible implementation method, an embodiment of the present application provides a specific implementation method for searching a decision definition file from a decision definition file for a first target decision definition file in which decision variables match the business variables included in an application request, and the decision variable attribute values in the decision execution conditions match the business variable attribute values corresponding to the application request. Please see below for details.
[0078] S204: Execute the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
[0079] After determining the first target decision definition file, the decision system executes the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
[0080] The embodiment of the present application provides a method for implementing business logic, which is applied to a decision system and implemented by the decision system. Among them, the decision system is deployed in each node of the blockchain, and each decision system is loaded with a decision definition file for representing the business logic of the target business. The decision system obtains the application request received by the current node, and the application request contains business variables. According to the application request, the decision system reads the business variable attribute value of the business variable from the node database of the current node. Then, the first target decision definition file matching the application request is determined from the decision definition file. The decision system executes the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value. In the embodiment of the present application, by constructing a decision system, the decision definition file in the decision system is used instead of the chain code to realize the business logic in the blockchain. When the business logic needs to be updated, it does not need to be completed by the collaboration of each node of the blockchain. It only needs to reload the updated decision definition file representing the business logic into the decision system. It is simple to implement, and even the business logic with high real-time performance is easier to deploy in the blockchain.
[0081] In order to facilitate the understanding of S203-S204, combined Figure 3 Further explanation is given. Among them, Figure 3 A schematic diagram of a business logic for determining a first target decision file and executing a corresponding target business provided by an embodiment of the present application. It should be noted that: Figure 3 The method for determining the first target decision file shown is a method when the application request does not include a decision identifier.
[0082] Specifically, Figure 3 As shown, when the application request does not include a decision identifier, the business variables and business variable attribute values in the application request are input into a decision file matching algorithm logic through an entry for matching. If the application request includes a first business variable and a second business variable, it is necessary to search for a first target decision definition file from the decision library, wherein the first decision variable, the first decision variable attribute value corresponding to the first decision variable, the second decision variable, and the second decision variable attribute value contained in the file match the first business variable, the first business variable attribute value corresponding to the first business variable, the second business variable, and the second business variable attribute value corresponding to the second business variable, respectively.
[0083] In specific implementation, the first business variable is first matched with the first decision variable in the current decision definition file, and the decision definition file with successful matching is determined as the pre-selected decision definition file. Further, the first decision variable attribute value corresponding to the first decision variable in the pre-selected decision definition file and the first business variable attribute value corresponding to the first business variable are matched with the first attribute value. When the match is successful, the second business variable, the second business variable attribute value and the second decision variable, the second decision variable attribute value in the pre-selected decision definition file and the second attribute value matching are performed. If all matches are successful, the pre-selected decision definition file is determined to be the first target decision definition file. If any of the first variable matching, the second variable matching, the first attribute value matching and the second attribute value matching fails, the matching of the current decision definition file is terminated, and the matching of the next decision definition file is performed until the first target decision definition file is obtained.
[0084] It is understandable that there is no limit Figure 3 The order in which the first variable matches and the second variable matches.
[0085] like Figure 3 As shown, after determining the first target decision definition file, the business logic of the target business corresponding to the first target decision definition file is executed to obtain a positive result and a negative result. The positive result is the behavior when the policy result is true, and the negative result is the behavior when the policy result is false.
[0086] Understandably, Figure 3 As an example, only the decision definition file matching and business logic execution for a business request including two business variables are shown. The business request involved in the embodiment of the present application is not limited to Figure 3 .
[0087] To make it easier to understand Figure 3 The process shown is explained below through a specific example.
[0088] In this specific example, the application request is to query whether the account balance is sufficient to pay the credit card bill. The business variables in the application request are the account balance and the credit card bill. The corresponding business variable attribute values are read from the node database. For example, the attribute value corresponding to the credit card bill is 50 yuan, unsettled. The attribute value corresponding to the account balance is 100 yuan, normal. The first target decision definition file is determined based on the account balance, credit card bill, and corresponding attribute values. The following is the key logic fragment in the determined first target decision definition file:
[0089]
[0090]
[0091] Based on the above logic, the first target decision definition file includes two decision variables, one of which is bill, which is the credit card bill. The second is deposit, which is the account balance. "state==”unCharge”,fee>0” declares the decision variable attribute value corresponding to the bill decision variable, that is, unCharge and fee>0 corresponding to state are both the decision variable attribute values corresponding to the bill decision variable, which means that the decision variable attribute value of the bill decision variable is unsettled and the bill fee is greater than 0.
[0092] Correspondingly, "state="normal",balance>0" declares the decision variable attribute value corresponding to the deposit decision variable, that is, normal corresponding to state and balance>0 are both decision variable attribute values corresponding to the deposit decision variable, which means that the decision variable attribute value of the deposit decision variable is normal and the account balance is greater than 0.
[0093] Based on the above description, it can be known that the decision variables and corresponding decision variable attribute values in the first target decision definition file are matched with the business variables and business variable attribute values in the application request. That is, the decision variables and business variables are the same, and the business variable attribute values corresponding to the business variables of the account balance meet the "state=="unCharge",fee>0" in the first target decision definition file. The business variable attribute values corresponding to the business variables of the credit card bill meet the "state="normal",balance>0" in the first target decision definition file.
[0094] After determining the first target decision definition file as shown above, the business logic of the target business corresponding to the first target decision definition file can be executed according to the business variable attribute value of the business variable. The business logic of the target business corresponding to the first target decision definition file is the decision execution conditions "$deposit.balance>$bill.fee", "$deposit.balance<=$bill.fee" and the corresponding decision execution actions "fmt.Println("Sufficient balance")", "fmt.Println("Insufficient balance")". Among them, sufficient balance can be considered as a positive result, and insufficient balance as a negative result.
[0095] Since the attribute value corresponding to the credit card bill in the application request is 50 yuan, and the attribute value corresponding to the account balance is 100 yuan, the decision execution condition "$deposit.balance>$bill.fee" is met, and "fmt.Println("Sufficient balance")" is executed.
[0096] In a possible implementation, the embodiment of the present application provides a specific implementation of searching the decision definition file in S203 for a first target decision definition file whose decision variables match the business variables included in the application request and whose decision variable attribute values in the decision execution condition match the business variable attribute values corresponding to the application request, including:
[0097] A1: Searching for a second target decision definition file in which a decision variable matches a business variable included in the application request from the decision definition file.
[0098] According to the business variables requested by the application, a second target decision definition file matching the decision variables and the business variables is searched from multiple decision definition files. That is to say, first, according to the business variables requested by the application, all decision definition files that can match the business variables are screened from multiple decision definition files, and they are determined as the second target decision definition files. For example, there are 1000 decision definition files in the decision library, and 100 second target decision definition files are determined from the decision library, and the decision variables in each second target decision definition file match the business variables requested by the application.
[0099] A2: Search the second target decision definition file for a first target decision definition file whose decision variable attribute value in the decision execution condition matches the business variable attribute value corresponding to the application request.
[0100] The determined second target decision definition file satisfies the requirement that its decision variables match the business variables of the application request. Based on this, the first target decision definition file whose decision variable attribute values in the decision execution condition match the business variable attribute values corresponding to the application request is searched from the second target decision definition file.
[0101] based on Figure 3 In this embodiment, the first business variable and the second business variable included in the application request can be matched with the first decision variable and the second decision variable included in each decision definition file, respectively, without matching the business variable attribute value with the decision variable attribute value, to obtain the second target decision definition file. After determining the second target decision definition file, the first business variable attribute value corresponding to the first business variable and the second business variable attribute value corresponding to the second business variable are matched with the first decision variable attribute value and the second decision variable attribute value of each second target decision definition file, respectively, to obtain the first target decision definition file.
[0102] Based on the above description, it can be seen that by first determining the second target decision definition file according to the business variables from multiple decision definition files, and then determining the screening and searching logic of the first target decision definition file from the second target decision definition file according to the business variable attribute values, the time cost of searching can be simplified and the searching efficiency can be improved.
[0103] Since there are multiple first target decision definition files found, based on this, in a possible implementation, the embodiment of the present application also provides another method for implementing business logic, the method further includes:
[0104] B1: When multiple first target decision definition files are found.
[0105] After multiple first target decision definition files are found, a unique first target decision definition file matching the application request is determined from the multiple first target decision definition files.
[0106] B2: According to the priority order, determine the first target decision definition file with the highest priority as the first target decision definition file matching the application request.
[0107] The priority of the decision definition file is pre-set. After multiple first target decision definition files are found, the decision definition file with the highest priority is determined from the first target decision definition files according to the pre-set priority order of the decision definition files as the first target decision definition file matching the application request.
[0108] Based on the above description, it can be known that when multiple first target decision definition files are found, in order to avoid selection conflicts among multiple first target decision definition files, a first target decision definition file that matches the application request can be uniquely determined through the pre-set priority order of the decision definition files.
[0109] Since there is a case where the application request is an operation request, for example, the application request is to recharge a mobile phone account by 100 yuan. Under the operation request, after determining the first target decision definition file and executing the business logic of the target business corresponding to the first target decision definition file, there is a case where the business variable attribute value of the business variable changes. Based on this, in a possible implementation method, the embodiment of the present application also provides another method for implementing the business logic, which also includes:
[0110] C1: After executing the business logic of the target business corresponding to the first target decision definition file, if the business variable attribute value of the business variable changes, update the business variable attribute value of the business variable in the node database.
[0111] If the business variable attribute value of the business variable changes after executing the business logic of the target business corresponding to the first target decision definition file, the business variable attribute value of the business variable in the node database is updated, that is, the data in the account book corresponding to the current node (i.e., the node database) is updated.
[0112] C2: Notify other nodes to update the business variable attribute values of the business variables.
[0113] In order to ensure the consistency of data in different node databases in the blockchain, after the business variable attribute value of the business variable in the node database of the current node is updated, it is necessary to notify other nodes to update the business variable attribute value of the business variable.
[0114] Based on the above description, it can be seen that after the decision system implements the business logic according to the application request, if the business variable attribute value of the business variable changes, it can be understood that a transaction data has been generated, and the data in the ledger of the current node needs to be updated to meet the consistency of the blockchain distributed ledger data.
[0115] In addition, the decision system will receive the newly added decision definition file. In a possible implementation, for the newly added decision definition file, the embodiment of the present application also provides another method for implementing business logic, the method also includes:
[0116] D1: Get the newly added decision definition file.
[0117] The decision system obtains the newly added decision definition file.
[0118] D2: Determine whether the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file.
[0119] The decision system determines whether the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file.
[0120] D3: If they are the same, the newly added decision definition file replaces the third target decision definition file, where the third target decision definition file is a loaded decision definition file having the same decision identifier as the newly added decision definition file.
[0121] If they are the same, it indicates that the decision library of the decision system has loaded a third target decision definition file with the same decision identifier as the newly added decision definition file. The newly added decision definition file is a modified version of the third target decision definition file. At this time, the newly added decision definition file replaces the third target decision definition file.
[0122] D4: If they are not the same, load the newly added decision definition file.
[0123] If they are not the same, the newly added decision definition file is loaded directly.
[0124] In actual applications, as an example, each newly added decision definition file that has been edited and not loaded into the decision library is placed in the cache directory of the decision system. The decision system will automatically load the decision definition files in the cache directory into the decision library according to the execution logic of D2-D4.
[0125] Based on the above description, it can be seen that the decision definition file in the constructed decision system replaces the existing chain code and implements the business logic of the business. Using the constructed decision definition file, when updating the business logic, the cumbersome steps of chain code update in the existing technology are avoided. You only need to modify the decision definition file and re-enter the decision system for loading. The implementation process is simple and easy to operate.
[0126] Based on the business logic implementation method provided by the above method embodiment, the present application embodiment also provides a schematic diagram of a business logic implementation method. Figure 4 , Figure 4 A schematic diagram of a method for implementing business logic provided in an embodiment of the present application.
[0127] like Figure 4 As shown, after the decision system obtains the application request, it determines the business variables of the application request, and then obtains the business variable attribute values corresponding to the business variables from the account book (ie, the node database described in the above embodiment).
[0128] The decision system uses two methods to determine how to obtain the first target decision definition file that matches the application request, depending on whether the application request includes a decision identifier. The first target decision definition file is used to implement the application request through the business logic contained therein. The details are as follows:
[0129] When the application request includes a decision identifier, since the decision identifier is the unique identifier of the decision definition file, the decision system can directly search for a decision definition file with the same decision identifier from the decision library storing the decision definition files according to the decision identifier, and the decision definition file is the first target decision definition file matching the application request.
[0130] When the application request does not include a decision identifier, a decision matching algorithm needs to be used to search for the first target decision definition file in the decision library. Specifically, the decision matching algorithm searches for the first target decision definition file in which the decision variables match the business variables included in the application request and the decision variable attribute values in the decision execution conditions match the business variable attribute values corresponding to the application request, based on the business variables in the application request and the business variable attribute values corresponding to the business variable in the application request.
[0131] When the decision matching algorithm is used to obtain the first target decision definition file, there may be multiple first target decision definition files. At this time, it is necessary to determine the only first target decision definition file that matches the application request from the multiple first target decision definition files according to the priority of the decision definition files. If the decision matching algorithm fails to obtain the first target decision definition file that meets the requirements, the matching process ends.
[0132] After determining the first target decision definition file through the above two methods, the business logic of the target business corresponding to the first target decision definition file is executed according to the business variable attribute value of the business variable. After the execution is completed, the business variable attribute value of the business variable may change. In order to ensure the consistency of the blockchain distributed ledger data, it is necessary to update the business variable attribute value of the business variable in the ledger and notify other nodes to update the business variable attribute value of the business variable. If the ledger does not need to be updated, the process ends.
[0133] In addition, if the account book is updated during the process of obtaining the first target decision definition file, the process of obtaining the first target decision definition file needs to be re-executed.
[0134] In addition, the decision system receives the newly added decision definition file and saves the newly added decision definition file in the decision library.
[0135] In the embodiment of the present application, by building a decision system, the decision definition file in the decision system is used instead of the chain code to realize the business logic in the blockchain. When the business logic needs to be updated, it does not need to be completed by the various nodes of the blockchain. It only needs to reload the updated decision definition file representing the business logic into the decision system. The implementation is simple, and even the business logic with high real-time performance is easier to deploy in the blockchain.
[0136] Based on the service logic implementation method provided by the above method embodiment, the embodiment of the present application also provides a service logic implementation device. The device will be described below in conjunction with the accompanying drawings.
[0137] See also Figure 5 , Figure 5 A schematic diagram of a device for implementing business logic provided in an embodiment of the present application. The device is applied to a decision-making system, which is deployed in each node of the blockchain. The decision-making system is loaded with a decision definition file, and each decision definition file represents the business logic of a target business. Figure 5 As shown, the implementation device of the business logic includes:
[0138] A first acquisition unit 501 is used to acquire an application request, where the application request includes a business variable;
[0139] A reading unit 502, configured to read a business variable attribute value of the business variable from a node database of a current node;
[0140] A first determining unit 503, configured to determine a first target decision definition file matching the application request from the decision definition file;
[0141] The execution unit 504 is used to execute the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
[0142] In a possible implementation, the decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action. The first determining unit 503 is specifically configured to:
[0143] When the application request further includes a decision identifier, a first target decision definition file whose decision identifier matches the decision identifier included in the application request is searched from the decision definition file.
[0144] In a possible implementation, the decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action. The first determining unit 503 is specifically configured to:
[0145] When the application request does not include a decision identifier, search the decision definition file for a first target decision definition file in which a decision variable matches a business variable included in the application request and a decision variable attribute value in a decision execution condition matches a business variable attribute value corresponding to the application request.
[0146] In a possible implementation, the first determining unit 503 includes:
[0147] A first search subunit is used to search the decision definition file for a second target decision definition file whose decision variables match the business variables included in the application request;
[0148] The second search subunit is used to search the second target decision definition file for a first target decision definition file whose decision variable attribute value in the decision execution condition matches the business variable attribute value corresponding to the application request.
[0149] In a possible implementation manner, the device further includes:
[0150] A searching unit, configured to search for a plurality of the first target decision definition files when the plurality of the first target decision definition files are found;
[0151] The first determining unit is used to determine, in order of priority, a first target decision definition file with the highest priority as the first target decision definition file matching the application request.
[0152] In a possible implementation manner, the device further includes:
[0153] an updating unit, configured to update the business variable attribute value of the business variable in the node database if the business variable attribute value of the business variable changes after executing the business logic of the target business corresponding to the first target decision definition file;
[0154] The notification unit is used to notify other nodes to update the service variable attribute value of the service variable.
[0155] In a possible implementation manner, the device further includes:
[0156] A second acquisition unit is used to acquire a newly added decision definition file;
[0157] A judging unit, used to judge whether the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file;
[0158] A replacement unit, used for replacing a third target decision definition file with the newly added decision definition file when the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file, wherein the third target decision definition file is the loaded decision definition file having the same decision identifier as the newly added decision definition file;
[0159] The loading unit is used to load the newly added decision definition file when the decision identifier of the newly added decision definition file is different from the decision identifier of the loaded decision definition file.
[0160] In addition, an embodiment of the present application also provides a method for implementing business logic, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for implementing business logic as described in any one of the above embodiments is implemented.
[0161] In addition, an embodiment of the present application further provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes a method for implementing the business logic as described in any of the above embodiments.
[0162] The embodiment of the present application provides a device and equipment for implementing business logic, which is applied to a decision system and implemented by the decision system. Among them, the decision system is deployed in each node of the blockchain, and each decision system is loaded with a decision definition file for representing the business logic of the target business. The decision system obtains the application request received by the current node, and the application request contains business variables. According to the application request, the decision system reads the business variable attribute value of the business variable from the node database of the current node. Then, the first target decision definition file matching the application request is determined from the decision definition file. The decision system executes the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value. In the embodiment of the present application, by constructing a decision system, the decision definition file in the decision system is used instead of the chain code to realize the business logic in the blockchain. When the business logic needs to be updated, it does not need to be completed by the various nodes of the blockchain in collaboration. It only needs to reload the updated decision definition file representing the business logic into the decision system. It is simple to implement, and even the business logic with high real-time performance is easier to deploy in the blockchain.
[0163] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0164] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or plural.
[0165] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0166] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0167] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.< / actions> < / conditions> < / value> < / name>
Claims
1. A method for implementing business logic, characterized in that: The method is applied to a decision system, the decision system is deployed in each node of the blockchain, the decision system is loaded with a decision definition file, the decision definition file replaces the chain code running in the blockchain, and each decision definition file represents the business logic of a target business; When the business logic needs to be updated, the updated decision definition file is reloaded into the decision system; the method comprises: Obtaining an application request, wherein the application request includes a business variable; Read the business variable attribute value of the business variable from the node database of the current node; Determine a first target decision definition file matching the application request from the decision definition files; The business logic of the target business corresponding to the first target decision definition file is executed according to the business variable attribute value of the business variable.
2. The method according to claim 1, characterized in that The decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action. The determining a first target decision definition file matching the application request from the decision definition file includes: When the application request further includes a decision identifier, a first target decision definition file whose decision identifier matches the decision identifier included in the application request is searched from the decision definition file.
3. The method according to claim 1, characterized in that: The decision definition file includes a decision identifier, a decision variable, a decision execution condition, and a decision execution action. The determining a first target decision definition file matching the application request from the decision definition file includes: When the application request does not include a decision identifier, search the decision definition file for a first target decision definition file in which a decision variable matches a business variable included in the application request and a decision variable attribute value in a decision execution condition matches a business variable attribute value corresponding to the application request.
4. The method according to claim 3, characterized in that: The step of searching the decision definition file for a first target decision definition file whose decision variables match the business variables included in the application request and whose decision variable attribute values in the decision execution conditions match the business variable attribute values corresponding to the application request includes: Searching the decision definition file for a second target decision definition file whose decision variables match the business variables included in the application request; A first target decision definition file is searched from the second target decision definition file for a decision variable attribute value in a decision execution condition that matches a business variable attribute value corresponding to the application request.
5. The method according to claim 3 or 4, characterized in that: The method further comprises: When multiple first target decision definition files are found; According to the priority order, a first target decision definition file with the highest priority is determined as the first target decision definition file matching the application request.
6. The method according to claim 1, characterized in that The method further comprises: After executing the business logic of the target business corresponding to the first target decision definition file, if the business variable attribute value of the business variable changes, updating the business variable attribute value of the business variable in the node database; Notify other nodes to update the business variable attribute value of the business variable.
7. The method according to claim 1, characterized in that The method further comprises: Get the newly added decision definition file; Determine whether the decision identifier of the newly added decision definition file is the same as the decision identifier of the loaded decision definition file; If they are the same, replacing the third target decision definition file with the newly added decision definition file, wherein the third target decision definition file is a loaded decision definition file having the same decision identifier as the newly added decision definition file; If they are not the same, the newly added decision definition file is loaded.
8. A device for implementing business logic, characterized in that: The device is applied to a decision system, the decision system is deployed in each node of the blockchain, the decision system is loaded with a decision definition file, the decision definition file replaces the chain code running in the blockchain, and each decision definition file represents the business logic of a target business; When the business logic needs to be updated, the updated decision definition file is reloaded into the decision system; the device comprises: An acquisition unit, configured to acquire an application request, wherein the application request includes a business variable; A reading unit, used for reading a business variable attribute value of the business variable from a node database of a current node; A determining unit, configured to determine a first target decision definition file matching the application request from the decision definition file; An execution unit is used to execute the business logic of the target business corresponding to the first target decision definition file according to the business variable attribute value of the business variable.
9. A method for implementing business logic, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for implementing the business logic according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on the terminal device, the terminal device executes the method for implementing the service logic according to any one of claims 1 to 7.
Citation Information
Patent Citations
Task issuing method and device
CN110162386A
Intelligent risk control decision-making method, device and equipment and readable storage medium
CN113052676A