Transaction statistics method and apparatus
By generating configuration objects and utilizing reflection mechanisms and parallel processing techniques, financial transaction statistical variables are dynamically configured, solving the problem of high-cost variable modification in existing technologies and achieving low-cost and efficient statistical variable management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WEBANK (CHINA)
- Filing Date
- 2021-12-22
- Publication Date
- 2026-05-15
AI Technical Summary
In existing technologies, adding, modifying, and deleting statistical variables in financial transactions requires modifying software code, resulting in high costs and low efficiency.
By generating configuration objects, the calculation type and condition objects of the target statistical variables are parsed according to the user's configuration operations. By using reflection mechanisms and parallel processing technology, the statistical results are dynamically configured and updated, reducing the dependence on software code.
It enables the addition, modification, and deletion of statistical variables at low cost, improving the efficiency of transaction statistics and database performance, while reducing manpower and time costs.
Smart Images

Figure CN114282996B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of financial technology, and in particular to a transaction statistics method and device. Background Technology
[0002] With the development of computer technology, more and more technologies are being applied in the financial field. The traditional financial industry is gradually transforming into Fintech, and financial transaction statistics technology is no exception. However, due to the security and real-time requirements of the financial industry, higher demands are being placed on the technology. In the field of Fintech, a common need is to perform statistical analysis on transaction data along a specific dimension based on certain conditions, obtaining statistical results. For example, counting the number of transactions with a deposit amount of 10,000 yuan within 20 days, where the conditions include 20 days, deposit amount of 10,000 yuan, and the dimension being the number of transactions. It can be seen that multiple combinations of conditions can correspond to a statistical variable, and the resulting statistical result can be called the value of that statistical variable. In practical applications, it is necessary to add, modify, and delete statistical variables. Therefore, how to achieve the addition, modification, and deletion of statistical variables at low cost is an urgent problem to be solved. Summary of the Invention
[0003] This disclosure provides a transaction statistics method and device to achieve the addition, modification, and deletion of statistical variables at low cost.
[0004] Firstly, this disclosure provides a transaction statistics method, the method comprising:
[0005] Obtain the configuration object of the target statistical variable. The configuration object is generated based on the user's configuration operation on the configuration page, and the configuration object corresponds to a preset data structure.
[0006] The calculation type of the target statistical variable and a condition object of at least one condition type are obtained from the configuration object according to the preset data structure. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object.
[0007] Obtain at least one transaction record;
[0008] For each piece of transaction data, the transaction data is matched with each condition object of the target statistical variable, and when the transaction data is successfully matched with each condition object, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type.
[0009] Optionally, the at least one conditional attribute includes: data type, logical operator, target value, and transaction attribute, and the matching of the transaction data with each conditional object of the target statistical variable includes:
[0010] For each of the aforementioned condition objects, the values of the corresponding transaction attributes are obtained from the transaction data using a reflection mechanism.
[0011] Convert the values of the transaction attributes to the data type corresponding to the condition object;
[0012] The value of the data type, the target value corresponding to the condition object, and the logical operator corresponding to the condition object are input into the matching function corresponding to the data type for matching.
[0013] Optionally, the at least one conditional attribute includes: calculation tag information, the calculation tag information being used to indicate whether the conditional object participates in the calculation; the step of matching the transaction data with each conditional object of the target statistical variable, and updating the statistical result of the target statistical variable according to the transaction data and the calculation type when the transaction data successfully matches each conditional object, includes:
[0014] The transaction data is matched with the target condition object of the target statistical variable, wherein the target condition object is the condition object participating in the calculation represented by the calculation tag information;
[0015] When all the target condition objects are successfully matched, the statistical results of the target statistical variable are updated according to the transaction data and the calculation type.
[0016] Optionally, the step of matching each piece of transaction data with each condition object of the target statistical variable, and updating the statistical result of the target statistical variable according to the transaction data and the calculation type when the transaction data matches each condition object successfully, includes:
[0017] At least one thread is started to run in parallel. Each thread is used to match a transaction data with each condition object of the target statistical variable for a given transaction data, and when the transaction data is successfully matched with each condition object, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type.
[0018] Optionally, the configuration object further includes persistence information, which indicates whether the target statistical variable needs to be persisted. The configuration object includes an index field, and the method further includes:
[0019] If the persistence information of the target statistical variable indicates that the target statistical variable needs to be persisted, then after each thread has updated the statistical results of the target statistical variable, the statistical results of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database. Different target statistical variables correspond to different data tables.
[0020] Optionally, the method further includes:
[0021] Create a counter based on the number of transaction data entries;
[0022] Each thread updates the counter after matching the transaction data;
[0023] After each thread has updated the statistical results of the target statistical variable, the statistical results of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database, including:
[0024] When the counter reaches the target count value, the statistical result of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database.
[0025] Optionally, the condition object of the at least one condition type includes a time condition object. When there are multiple target statistical variables, obtaining at least one transaction data point includes:
[0026] Obtain the start and end times of the target statistical variable from the time condition object of each target statistical variable;
[0027] Retrieve at least one transaction whose transaction time falls between the minimum start time and the maximum end time.
[0028] Secondly, this disclosure provides a transaction statistics device, comprising:
[0029] The configuration object acquisition module is used to acquire the configuration object of the target statistical variable. The configuration object is generated based on the user's configuration operation on the configuration page, and the configuration object corresponds to a preset data structure.
[0030] The configuration object parsing module is used to parse the calculation type of the target statistical variable and at least one condition object of condition type from the configuration object according to the preset data structure. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object.
[0031] The transaction data acquisition module is used to acquire at least one transaction data item.
[0032] The variable statistics module is used to match each transaction data with each condition object of the target statistical variable for each transaction data, and when the transaction data matches each condition object successfully, update the statistical result of the target statistical variable according to the transaction data and the calculation type.
[0033] Optionally, the at least one conditional attribute includes: data type, logical operator, target value, and transaction attribute; the variable statistics module is further used for:
[0034] When matching the transaction data with each condition object of the target statistical variable, for each condition object, the value of the transaction attribute corresponding to the condition object is obtained from the transaction data through a reflection mechanism;
[0035] Convert the values of the transaction attributes to the data type corresponding to the condition object;
[0036] The value of the data type, the target value corresponding to the condition object, and the logical operator corresponding to the condition object are input into the matching function corresponding to the data type for matching.
[0037] Optionally, the at least one conditional attribute includes: calculation marker information, which indicates whether the conditional object participates in the calculation; the variable statistics module is further used for:
[0038] The transaction data is matched with the target condition object of the target statistical variable, wherein the target condition object is the condition object participating in the calculation represented by the calculation tag information;
[0039] When all the target condition objects are successfully matched, the statistical results of the target statistical variable are updated according to the transaction data and the calculation type.
[0040] Optionally, the variable statistics module is further used for:
[0041] At least one thread is started to run in parallel. Each thread is used to match a transaction data with each condition object of the target statistical variable for a given transaction data, and when the transaction data is successfully matched with each condition object, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type.
[0042] Optionally, the configuration object further includes persistence information, which indicates whether the target statistical variable needs to be persisted. The configuration object includes an index field, and the device further includes:
[0043] The persistence module is used to write the statistical results of the target statistical variable and the value of the index field in the transaction data into the data table corresponding to the target statistical variable in the database after all threads have updated the statistical results of the target statistical variable. Different target statistical variables correspond to different data tables.
[0044] Optionally, the device further includes:
[0045] A counter creation module is used to create a counter based on the number of transaction data entries.
[0046] A counter update module is used for each thread to update the counter after matching the transaction data;
[0047] The persistence module is also used for:
[0048] When the counter reaches the target count value, the statistical result of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database.
[0049] Optionally, the condition object of the at least one condition type includes a time condition object. When there are multiple target statistical variables, the transaction data acquisition module is further configured to:
[0050] Obtain the start and end times of the target statistical variable from the time condition object of each target statistical variable;
[0051] Retrieve at least one transaction whose transaction time falls between the minimum start time and the maximum end time.
[0052] Thirdly, this disclosure provides an electronic device, including: at least one processor and a memory;
[0053] The memory stores computer-executed instructions;
[0054] The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to implement the method described in the first aspect above.
[0055] Fourthly, this disclosure provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, cause a computing device to implement the method described in the first aspect above.
[0056] Fifthly, this disclosure provides a computer program for implementing the method described in the first aspect above.
[0057] The transaction statistics method and apparatus disclosed herein include: obtaining a configuration object of a target statistical variable, wherein the configuration object is generated based on user configuration operations on a configuration page, and the configuration object corresponds to a preset data structure; parsing the configuration object to obtain the calculation type of the target statistical variable and a condition object of at least one condition type according to the preset data structure, wherein the condition object includes at least one condition attribute, the condition attribute being used to define the matching rules of the condition object; obtaining at least one transaction data; for each transaction data, matching the transaction data with each condition object of the target statistical variable, and updating the statistical result of the target statistical variable according to the transaction data and the calculation type when a match is successful with each condition object. This application can generate configuration objects of statistical variables based on user input, and all configuration objects of statistical variables have the same data structure, thus allowing the configuration objects to be parsed according to this data structure for statistical variable statistics. Therefore, when adding, modifying, or deleting statistical variables, only re-entry is required. Since the data structures of different statistical variables are the same, the parsing process of the configuration object is fixed, requiring no modification to software code or testing, thereby reducing the cost of adding, modifying, or deleting statistical variables. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is a schematic diagram illustrating a transaction data statistics scenario applicable to the embodiments of this application;
[0060] Figure 2 This is a flowchart illustrating the specific steps of the transaction statistics method provided in the embodiments of this application;
[0061] Figure 3 This is a schematic diagram of the configuration interface provided in an embodiment of this application;
[0062] Figure 4 This is a schematic diagram of the preset data structure of the configuration object provided in the embodiments of this application;
[0063] Figure 5 This is a schematic diagram of the statistical process for each target statistical variable provided in the embodiments of this application;
[0064] Figure 6 This is a schematic diagram of the matching process for each thread provided in an embodiment of this application;
[0065] Figure 7 This is a structural block diagram of a transaction statistics device provided in an embodiment of this application;
[0066] Figure 8 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0067] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0068] The embodiments of this application can be applied to statistical scenarios of transaction data. Figure 1 This is a schematic diagram illustrating a transaction data statistics scenario applicable to the embodiments of this application. (Refer to...) Figure 1 As shown in the figure, there are 5 transaction records TX1 to TX5. TX1 = {Inflow amount 10000, Account information USR1, Transaction time January 11, 2020}, TX2 = {Inflow amount 1000, Account information USR2, Transaction time February 20, 2020}, TX3 = {Outflow amount 1000, Account information USR1, Transaction time March 1, 2020}, TX4 = {Outflow amount 8000, Account information USR1, Transaction time October 8, 2020}, TX5 = {Inflow amount 1100, Account information USR3, Transaction time October 11, 2020}.
[0069] in addition, Figure 1 The table shows two statistical variables, SV1 and SV2. SV1 represents the total amount of transactions with outgoing amounts greater than 5000, and SV2 represents the number of transactions with incoming amounts greater than 500 in October 2020. It can be seen that the values of the statistical variables obtained using SV1 and SV2 are 8000 and 1, respectively.
[0070] In existing technologies, the statistical analysis of the aforementioned variables is implemented through hard-coding, meaning the conditions are set in the software code. Therefore, adding, modifying, or deleting statistical variables requires modifying the software code and testing its functionality.
[0071] It can be seen that the above modification and testing process requires a lot of manpower, resulting in high costs for adding, modifying, and deleting statistical variables.
[0072] To address the aforementioned issues, this application embodiment generates configuration objects for statistical variables based on user input. All configuration objects for statistical variables share the same data structure, allowing for parsing of the configuration objects according to this data structure to perform statistical analysis. Thus, when adding, modifying, or deleting statistical variables, only re-entry is required. Since the data structures of different statistical variables are identical, the parsing process for the configuration objects is fixed, requiring no modification to software code or testing, thereby reducing the cost of adding, modifying, or deleting statistical variables.
[0073] Figure 2 This is a flowchart illustrating the specific steps of the transaction statistics method provided in this application. (Refer to...) Figure 2 As shown, the method may include:
[0074] S101: Obtain the configuration object of the target statistical variable. This configuration object is generated based on the user's configuration operation on the configuration page and corresponds to a preset data structure.
[0075] Specifically, users can... Figure 3 The configuration interface shown allows you to configure one or more statistical variables; that is, you enter the relevant information for the statistical variables in the configuration interface. (Refer to...) Figure 3 As shown, the relevant information that can be entered may include, but is not limited to: product, description, name, calculation type, whether it takes effect immediately, target value, deposit / withdrawal, hourly range, XX hour / group, transfer from non-bound card, transfer from other bank, transfer from bound card, transfer out to bound card, quick payment, product type, ledger type, transaction source, transaction source, card number, customer name, system call serial number, primary transaction object number, primary transaction object name, secondary transaction object number, secondary transaction object name, transaction result, transaction result rejection code, anti-fraud rule code, anti-fraud result, verification method, verification result, and verification rejection code.
[0076] The aforementioned statistical variables can be divided into basic variables and multiple conditional objects used to filter transaction data.
[0077] After the user configures the statistical variables, the backend software generates a configuration object for the statistical variables based on the aforementioned relevant information and a preset data structure, and stores the statistical variables in the database. The preset data structure indicates the position of each piece of information within the configuration object, allowing the information to be written into its corresponding position, ultimately resulting in the configuration object. Here, "position" refers to the sequential and containment relationships between the various pieces of information within the configuration object. Figure 4 This is a schematic diagram of the preset data structure of the configuration object provided in the embodiments of this application. (Refer to...) Figure 4As shown, the configuration object includes basic information and conditional information.
[0078] Among them, basic information can be Figure 3 The information includes the product, description, name, calculation type, and whether it takes effect immediately. The product, description, and name are used to inform the user. The calculation type indicates the type of the statistical result for the statistical variable; for example, the calculation type may include... Figure 3 The terms "Quantity" and "Amount" indicate whether the statistical result is the number of transactions when the calculation type is "Quantity" or "Amount." "Immediately Effective" indicates whether the statistical result for this variable should be generated immediately.
[0079] As you can see, the basic information is not used to match transaction data. The conditional information below is used to match transaction data; in other words, it's used to filter the transaction data.
[0080] Reference Figure 4 As shown, the condition information may include a list of condition objects, which may contain multiple condition objects of multiple types. Figure 4 The example shows two condition objects, one or both of which correspond to the same type. Each condition object can include multiple condition properties (…). Figure 4 Two conditional attributes are illustrated in the example.
[0081] Among them, condition objects can be used to store Figure 3 The following information is used to filter transaction data: target value, deposit / withdrawal, hourly range, XX hour / group, transfer from non-bound card, transfer from other bank, transfer from bound card, transfer out to bound card, quick payment, product type, ledger type, transaction source, transaction source, card number, customer name, system call serial number, primary transaction object number, primary transaction object name, secondary transaction object number, secondary transaction object name, transaction result, transaction result rejection code, anti-fraud rule code, anti-fraud result, identity verification method, identity verification result, and identity verification rejection code.
[0082] It should be noted that the configuration interface provides the same types of information to be entered by the user, as well as the same selectable values for each type of information, for different statistical variables. However, the different values selected by the user for different statistical variables lead to different statistical results.
[0083] In the embodiments of this application, the target statistical variable can be one or more arbitrary statistical variables in the database. For example, the target statistical variable can be all statistical variables in the database, or it can be a specified subset of statistical variables.
[0084] S102: According to the above-mentioned preset data structure, the calculation type of the target statistical variable and at least one condition object of condition type are parsed from the configuration object. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object.
[0085] Specifically, first, basic information and condition information are obtained from the configuration object; then, the calculation type is obtained from the address used to store the calculation type in the basic information, and a list of condition objects is obtained from the condition information, and the list of condition objects is split into multiple condition objects of multiple types; finally, a list of condition attributes is obtained from each condition object, and the list of condition attributes is split into multiple condition attributes.
[0086] In this embodiment of the application, to facilitate user operation on the configuration interface, the information can be divided into multiple types. For example, Figure 3 The types include: statistical variable attributes, statistical attributes, deposits and withdrawals, time range, calculation type, shortcuts, transaction-related attributes, and effective. Among these, the product and description belong to statistical variable attributes; the name and target value belong to statistical attributes; the hourly range and XX hours / groups belong to time ranges; quantity and amount belong to calculation types; transfers from non-bound cards, transfers from bound cards, transfers from other banks, transfers to bound cards, and quick payments belong to shortcuts; product type, ledger type, transaction source, transaction source, card number, customer name, system call serial number, first-level transaction object number, first-level transaction object name, second-level transaction object number, second-level transaction object name, transaction result, transaction result rejection code, anti-fraud rule code, anti-fraud result, verification method, verification result, and verification rejection code belong to transaction-related attributes; and whether it takes effect immediately belongs to effective.
[0087] S103: Obtain at least one transaction record.
[0088] The transaction data is stored in a database, so obtaining transaction data refers to reading transaction data from the database. In this embodiment, there are two strategies for reading transaction data.
[0089] In the first strategy, when obtaining statistical results for each target statistical variable, firstly, based on the start and end times corresponding to the target statistical variable, at least one transaction data is obtained from the database, and the transaction time of the obtained transaction data is within the start and end times; then, the condition object is matched with the transaction data through S104.
[0090] As can be seen, the first strategy described above requires establishing a connection to the database for each target statistical variable to obtain statistical results. Therefore, if there are N target statistical variables, N connections to the database are needed. This approach leads to frequent database connections, reducing database performance. Furthermore, multiple connections consume significant time, resulting in a longer transaction statistics processing time.
[0091] To avoid frequent connections to the database, this application embodiment uses a second strategy to obtain transaction data.
[0092] In the second strategy, firstly, the start and end times of each target statistical variable are obtained; then, the minimum start time and the maximum end time are selected; finally, a connection is made to the database to read all transaction data between the minimum start time and the maximum end time; finally, the transaction data and condition objects are matched through step S104 to obtain the statistical results.
[0093] When at least one condition type of condition object includes a time condition object, the start and end times of the target statistical variable can be obtained from the time condition object of each target statistical variable.
[0094] As can be seen, the embodiments of this application only require establishing a single connection with the database for multiple target statistical variables, thereby helping to improve database performance. Furthermore, the time consumed by a single connection is relatively short, thus reducing the time required for transaction statistics.
[0095] S104: For each transaction data, match the transaction data with each condition object of the target statistical variable, and when the transaction data matches each condition object successfully, update the statistical result of the target statistical variable according to the transaction data and the calculation type.
[0096] Specifically, the statistical results of each target statistical variable can be obtained through... Figure 5 The following steps are implemented:
[0097] S1041: Set the first transaction data as the current transaction data, and set the first condition object of the target statistical variable as the current condition object.
[0098] S1042: Match the current transaction data with the current condition object of the target statistical variable based on the condition attributes of the current condition object.
[0099] S1043: The current transaction data matches the current condition object successfully.
[0100] If the match is successful, proceed to S1044; otherwise, proceed to S1047.
[0101] S1044: Determine whether the current condition object is the last condition object for the target statistical variable.
[0102] If yes, proceed to S1045; otherwise, proceed to S1046.
[0103] S1045: Update the statistical results of the target statistical variable based on the current transaction data and the calculation type of the target statistical variable.
[0104] Understandably, if the last condition object matches the current transaction data, it means that all condition objects of the target statistical variable match the current transaction data. At this point, the statistical result of the target statistical variable can be updated.
[0105] S1046: Update the next condition object to the current condition object and proceed to S1042.
[0106] S1047: Determine whether the current transaction data is the last transaction data.
[0107] If yes, proceed to S1048; otherwise, proceed to S1049.
[0108] S1048: Determine the end of the statistical analysis for the target statistical variable.
[0109] S1049: Update the current transaction data to the next transaction data and proceed to S1042.
[0110] exist Figure 5 In step S1042, the current condition object includes one or more condition attributes, which define how to match the current condition object with transaction data. For example, at least one of the condition attributes includes: data type, logical operators, target value, and transaction attribute. The data type indicates the type of data used when matching the condition object, including but not limited to: numeric type, time type, and string type. Logical operators include but are not limited to: greater than, equal to, and less than. The target value is a preset value used when matching the condition object, and the transaction attribute is the attribute in the transaction data used when matching the condition object. Therefore, the process in S1042 is used to determine whether the value of the transaction attribute in the transaction data and the target value satisfy the correspondence indicated by the logical operators.
[0111] For example, the data type can be a numeric type, the logical operator can be greater than, the target value can be 100, and the transaction attribute can be the amount received. Thus, S1042 is used to determine whether the amount received in the transaction data is greater than 100.
[0112] For example, the data type can be a character type, the logical operator can be equal to, the target value can be "deposit", and the transaction attribute can be the transaction type. Thus, S1042 is used to determine whether the transaction type in the transaction data is "deposit".
[0113] for Figure 5 In step S1045, the calculation type can include, but is not limited to, quantity and amount. When the calculation type is quantity, S1045 is used to increment the current transaction quantity by 1. When the calculation type is amount, S1045 is used to sum the transaction amount in the transaction data with the current transaction amount as the new current transaction amount.
[0114] It can be seen that the above Figure 5 It is a statistical process for a target statistical variable, which can be followed according to Figure 5 The process shown involves performing the statistical process for each target statistical variable one by one.
[0115] When the aforementioned transaction attributes, data types, target values, and logical operators are the various condition attributes of a condition object, the above S1042 process may include the following steps:
[0116] First, the values of the transaction attributes corresponding to the condition object are obtained from the transaction data through reflection. Then, the values of the transaction attributes are converted into the data type corresponding to the condition object. Finally, the values of the above data type, the target value corresponding to the above condition object, and the logical operators corresponding to the condition object are input into the matching function corresponding to the above data type for matching.
[0117] The matching function is used to determine whether the value of the data type and the target value satisfy the correspondence indicated by the logical operator.
[0118] This application embodiment can obtain transaction attributes through a reflection mechanism, so the backend software does not need to know the specific transaction attributes in advance. In this scenario, the transaction attributes can be flexibly modified by the user in the configuration interface, and the backend software can obtain the values of the transaction attributes, thereby improving the dynamic configuration of transaction attributes.
[0119] Furthermore, to enable the deletion of condition objects, a calculation marker can be used to indicate whether the condition object participates in the calculation. Thus, the condition objects participating in the calculation, indicated by the calculation marker, can be identified as target condition objects. This allows for matching transaction data with target condition objects of target statistical variables based on the condition attributes of the target condition objects. When all target condition objects match successfully, the statistical results of the target statistical variables are updated based on the transaction data and the calculation type.
[0120] The aforementioned calculation tag information can be one of the conditional attributes. Users can set this calculation tag information for each conditional object of the statistical variable in the configuration interface. Therefore, when generating the configuration object for the statistical variable, the calculation tag information is added to each conditional object, and each conditional object is added to the configuration object.
[0121] This application embodiment allows users to flexibly configure the calculation tag information for each condition object to control whether the condition object needs to be matched when determining the statistical result of a statistical variable. If the calculation tag information indicates that the condition object does not participate in the calculation, then when generating the statistical result of the statistical variable, it is not necessary to match the condition attribute of the condition object with the transaction data, which is equivalent to deleting the condition object, that is, deleting a condition that needs to be judged for the statistical calculation of the statistical variable. For example, refer to Figure 3 As shown, users can set the calculation flag information of the condition object "product type" to not participate in the calculation. Then, when generating statistical results for statistical variables, it is no longer necessary to determine whether the product type in the transaction data is the product type preset in the configuration interface.
[0122] Conversely, users can also set the calculation marker information as a condition object in the configuration interface to participate in the calculation, which is equivalent to adding a condition that needs to be judged in the statistics of statistical variables. For example, users can set the calculation marker information of the condition object "product type" to participate in the calculation and set the product type to product type A. Then, when generating statistical results for statistical variables, it is necessary to further determine whether the product type in the transaction data is product type A.
[0123] The embodiments of this application can flexibly delete or add statistical conditions for statistical variables by calculating the marker information, without requiring changes to the software code, thus further reducing the cost of modifying statistical variables.
[0124] The aforementioned target statistical variables can be one or more. When there are multiple target statistical variables, the statistical results of each statistical variable can be determined one by one. That is, after determining the statistical results of one statistical variable, the statistical results of the next statistical variable are determined. The statistical processes of different statistical variables are carried out sequentially.
[0125] However, since each statistical variable needs to be matched for each transaction data point, if the transaction data volume is large, then according to... Figure 5The matching method shown results in low efficiency. To improve the statistical efficiency of each statistical variable, multiple threads can be used to perform the statistics for each variable. Specifically, at least one thread is started running in parallel. Each thread is used to match a transaction with each condition object of the target statistical variable for a given transaction. When the transaction matches each condition object successfully, the statistical result of the target statistical variable is updated according to the transaction and the calculation type.
[0126] Figure 6 This is a schematic diagram of the matching process for each thread provided in the embodiments of this application, refer to... Figure 6 As shown, the operation process of each thread may include the following steps:
[0127] S1141: Set the first condition object of the target statistical variable as the current condition object.
[0128] S1142: Match the corresponding transaction data with the current condition object of the target statistical variable based on the condition attributes of the current condition object.
[0129] S1143: Transaction data successfully matched the current condition object.
[0130] If a match is found, proceed to S1144; otherwise, proceed to S1147.
[0131] S1144: Determine whether the current condition object is the last condition object for the target statistical variable.
[0132] Specifically, if yes, proceed to S1145. If not, proceed to S1146.
[0133] S1145: Update the statistical results of the target statistical variable based on the transaction data and the calculation type of the target statistical variable.
[0134] S1146: Update the next condition object to the current condition object.
[0135] S1147: The matching of the transaction data with the target statistical variable has ended.
[0136] Each thread can be ordered according to Figure 6 The process involves matching the corresponding transaction data with each conditional object of the target statistical variable. Therefore, if there are N transaction data points, the statistical efficiency will increase by N times.
[0137] The statistical results generated in this application embodiment can be stored in a database so that any subsequent device can access the database to use the statistical results. Specifically, after each thread has finished updating the statistical results of a target statistical variable, the statistical results of the target statistical variable and the value of the index field in the transaction data are written to the data table corresponding to the target statistical variable in the database. Different target statistical variables correspond to different data tables.
[0138] The index field is a key field used for retrieval in the data table, and its specific value is obtained from the transaction data. There are two strategies for setting the index field.
[0139] In the first setup strategy, the index field can be fixed. For example, the index field can be set to account information, meaning that the index field for all statistical variables is account information.
[0140] In the second setup strategy, the index field can be flexibly configured. For example, users can configure the index field in the configuration interface, so that when the configuration object of the statistical variable is generated, the index field is written into the configuration object of the statistical variable.
[0141] As can be seen, the second setting strategy described above can set the same or different index fields for different statistical variables to ensure different retrieval needs for different statistical variables.
[0142] Optionally, the persistence of the target statistical variable described above is configurable. Specifically, the configuration object may also include persistence information, which indicates whether the target statistical variable needs to be persisted. If the persistence information indicates that the target statistical variable needs to be persisted, the statistical results and index field values of the target statistical variable in the transaction data can be written to the corresponding data table in the database. If the persistence information indicates that the target statistical variable does not need to be persisted, then the statistical results and index field values of the target statistical variable in the transaction data do not need to be written to the corresponding data table in the database. In this way, users can modify the persistence information to adjust the target statistical variables that need to be persisted and those that do not need to be persisted, improving the flexibility of persistence.
[0143] Understandably, the aforementioned persistent target statistical variables are used to store the statistical results of the target statistical variables in the database.
[0144] Optionally, when multiple threads separately match multiple transaction data to update the statistical results of the target statistical variable, it is necessary to consider how to know when all threads have finished updating the statistical results in order to proceed with subsequent processing. For example, when all threads have finished updating the statistical results, the statistical results of the target statistical variable can be stored in the database, and the condition object of the next target statistical variable can be matched with the transaction data to obtain the statistical results of the next target statistical variable.
[0145] This application embodiment can use a counter to determine whether all threads have updated the statistical results of the target statistical variable. Specifically, before matching transaction data, a counter is created based on the number of transaction data entries; then, each thread updates the counter after matching the transaction data.
[0146] The initial count of the counter is determined by the number of transaction data entries. For example, the initial count could be the number of transaction data entries, and then it would decrement by 1 with each update. When the counter reaches 0, it indicates that all threads have completed the update. Alternatively, the initial count could be twice the number of transaction data entries, and then it would decrement by 2 with each update, until the counter reaches 0, indicating that all threads have completed the update. Yet another example: the initial count could be twice the number of transaction data entries, and then it would decrement by 1 with each update, until the counter reaches the number of transaction data entries, indicating that all threads have completed the update.
[0147] Of course, to reduce computational complexity, the initial count can be the number of transaction data entries, and then it can be decremented by 1 each time it is updated.
[0148] Based on the aforementioned counter, when the counter reaches the target count value, it indicates that all threads have completed the update. At this point, the statistical results of the target statistical variable and the values of the index fields in the transaction data can be written to the corresponding data table of the target statistical variable in the database.
[0149] Specifically, the target writing process described above can be performed by the main thread or by the last thread that completes the matching and updates the counter to the target count value. This application embodiment does not impose any restrictions on it.
[0150] Corresponding to the transaction statistics device method in the above embodiments, Figure 7 This is a structural block diagram of a transaction statistics device provided in an embodiment of this application. For ease of explanation, only the parts relevant to the embodiment of this application are shown. (Refer to...) Figure 7 The aforementioned transaction statistics device 200 includes: a configuration object acquisition module 201, a configuration object parsing module 202, a transaction data acquisition module 203, and a variable statistics module 204.
[0151] The configuration object acquisition module 201 is used to acquire the configuration object of the target statistical variable. The configuration object is generated based on the user's configuration operation on the configuration page, and the configuration object corresponds to a preset data structure.
[0152] The configuration object parsing module 202 is used to parse the calculation type of the target statistical variable and at least one condition object of condition type from the configuration object according to the preset data structure. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object.
[0153] The transaction data acquisition module 203 is used to acquire at least one transaction data.
[0154] The variable statistics module 204 is used to match each transaction data with each condition object of the target statistical variable for each transaction data, and when the transaction data is successfully matched with each condition object, update the statistical result of the target statistical variable according to the transaction data and the calculation type.
[0155] Optionally, the at least one conditional attribute includes: data type, logical operator, target value, and transaction attribute, and the variable statistics module 204 is further used for:
[0156] When matching the transaction data with each condition object of the target statistical variable, for each condition object, the value of the transaction attribute corresponding to the condition object is obtained from the transaction data through reflection mechanism; the value of the transaction attribute is converted into the data type corresponding to the condition object; the value of the data type, the target value corresponding to the condition object, and the logical operator corresponding to the condition object are input into the matching function corresponding to the data type for matching.
[0157] Optionally, the at least one conditional attribute includes: calculation marker information, which indicates whether the conditional object participates in the calculation; the variable statistics module 204 is further used for:
[0158] The transaction data is matched with the target condition object of the target statistical variable, wherein the target condition object is the condition object participating in the calculation represented by the calculation tag information;
[0159] When all the target condition objects are successfully matched, the statistical results of the target statistical variable are updated according to the transaction data and the calculation type.
[0160] Optionally, the variable statistics module 204 is further configured to:
[0161] At least one thread is started to run in parallel. Each thread is used to match a transaction data with each condition object of the target statistical variable for a given transaction data, and when a match is successful with each condition object of the transaction data, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type.
[0162] Optionally, the configuration object further includes persistence information, which indicates whether the target statistical variable needs to be persisted. The configuration object includes an index field, and the device further includes:
[0163] The persistence module is used to write the statistical results of the target statistical variable and the value of the index field in the transaction data into the data table corresponding to the target statistical variable in the database after all threads have updated the statistical results of the target statistical variable. Different target statistical variables correspond to different data tables.
[0164] Optionally, the device further includes:
[0165] The counter creation module is used to create a counter based on the number of transaction data entries.
[0166] A counter update module is used for each thread to update the counter after matching the transaction data.
[0167] Based on the aforementioned counter creation module and counter update module, the persistence module is further used for:
[0168] When the counter reaches the target count value, the statistical result of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database.
[0169] Optionally, the condition object of the at least one condition type includes a time condition object. When there are multiple target statistical variables, the transaction data acquisition module is further configured to:
[0170] Obtain the start and end times of the target statistical variable from the time condition object of each target statistical variable; obtain at least one transaction data point whose transaction time is between the minimum start time and the maximum end time.
[0171] The transaction statistics device provided in this embodiment can be used to perform the above-mentioned... Figure 2 The technical solutions of the method embodiments shown are similar in implementation principle and technical effect, and will not be described again here.
[0172] Figure 8 This is a structural block diagram of an electronic device provided in an embodiment of this application. The electronic device 600 includes a memory 602 and at least one processor 601.
[0173] The memory 602 stores computer-executable instructions. At least one processor 601 executes the computer-executable instructions stored in the memory 602, causing the electronic device 601 to perform... Figure 2 The method in the middle.
[0174] In addition, the electronic device may also include a receiver 603 and a transmitter 604, wherein the receiver 603 is used to receive information from other devices or equipment and forward it to the processor 601, and the transmitter 604 is used to send information to other devices or equipment.
[0175] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, enable a computing device to implement the aforementioned transaction statistics method.
[0176] This application also provides a computer program for implementing the aforementioned transaction statistics method.
[0177] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit them. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this disclosure.
Claims
1. A transaction statistics method, characterized in that, The method includes: Obtain the configuration object of the target statistical variable. The configuration object is generated based on the user's configuration operation on the configuration page, and the configuration object corresponds to a preset data structure. The calculation type of the target statistical variable and a condition object of at least one condition type are obtained from the configuration object according to the preset data structure. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object. Obtain at least one transaction record; For each piece of transaction data, the transaction data is matched with each condition object of the target statistical variable. When the transaction data matches each condition object successfully, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type. The at least one condition attribute includes: data type, logical operator, target value, and transaction attribute. Matching the transaction data with each condition object of the target statistical variable includes: For each of the aforementioned condition objects, the values of the corresponding transaction attributes are obtained from the transaction data using a reflection mechanism. Convert the values of the transaction attributes to the data type corresponding to the condition object; The values of the data type, the target values corresponding to the condition objects, and the logical operators corresponding to the condition objects are input into the matching function corresponding to the data type for matching; the at least one condition attribute includes: calculation marker information, which indicates whether the condition object participates in the calculation; the step of matching the transaction data with each condition object of the target statistical variable, and updating the statistical result of the target statistical variable according to the transaction data and the calculation type when the transaction data matches each condition object successfully, includes: The transaction data is matched with the target condition object of the target statistical variable, wherein the target condition object is the condition object indicated by the calculation tag information to participate in the calculation; When the transaction data and the target condition object are both successfully matched, the statistical results of the target statistical variable are updated according to the transaction data and the calculation type.
2. The method according to claim 1, characterized in that, For each piece of transaction data, matching the transaction data with each condition object of the target statistical variable, and updating the statistical result of the target statistical variable according to the transaction data and the calculation type when the transaction data matches each condition object successfully, includes: At least one thread is started to run in parallel. Each thread is used to match a transaction data with each condition object of the target statistical variable for a given transaction data, and when the transaction data is successfully matched with each condition object, the statistical result of the target statistical variable is updated according to the transaction data and the calculation type.
3. The method according to claim 2, characterized in that, The configuration object also includes persistence information, which indicates whether the target statistical variable needs to be persisted. The configuration object includes an index field, and the method further includes: If the persistence information of the target statistical variable indicates that the target statistical variable needs to be persisted, then after each thread has updated the statistical results of the target statistical variable, the statistical results of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database. Different target statistical variables correspond to different data tables.
4. The method according to claim 3, characterized in that, The method further includes: Create a counter based on the number of transaction data entries; Each thread updates the counter after matching the transaction data; After each thread has updated the statistical results of the target statistical variable, the statistical results of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database, including: When the counter reaches the target count value, the statistical result of the target statistical variable and the value of the index field in the transaction data are written into the data table corresponding to the target statistical variable in the database.
5. The method according to any one of claims 1 to 4, characterized in that, The condition object of the at least one condition type includes a time condition object. When there are multiple target statistical variables, obtaining at least one transaction data point includes: Obtain the start and end times of the target statistical variable from the time condition object of each target statistical variable; Retrieve at least one transaction whose transaction time falls between the minimum start time and the maximum end time.
6. A transaction statistics device, characterized in that, The device includes: The configuration object acquisition module is used to acquire the configuration object of the target statistical variable. The configuration object is generated based on the user's configuration operation on the configuration page, and the configuration object corresponds to a preset data structure. The configuration object parsing module is used to parse the calculation type of the target statistical variable and at least one condition object of condition type from the configuration object according to the preset data structure. The condition object includes at least one condition attribute, which is used to define the matching rules of the condition object. The transaction data acquisition module is used to acquire at least one transaction data item. The variable statistics module is used to match each piece of transaction data with each condition object of the target statistical variable, and when the transaction data matches each condition object successfully, update the statistical result of the target statistical variable according to the transaction data and the calculation type. The at least one conditional attribute includes: data type, logical operator, target value, and transaction attribute; the variable statistics module is further used for: When matching the transaction data with each condition object of the target statistical variable, for each condition object, the value of the transaction attribute corresponding to the condition object is obtained from the transaction data through reflection mechanism; the value of the transaction attribute is converted into the data type corresponding to the condition object; the value of the data type, the target value corresponding to the condition object, and the logical operator corresponding to the condition object are input into the matching function corresponding to the data type for matching. The at least one conditional attribute includes: calculation marker information, which indicates whether the conditional object participates in the calculation; the variable statistics module is further used for: The transaction data is matched with the target condition object of the target statistical variable, wherein the target condition object is the condition object participating in the calculation represented by the calculation tag information; When all the target condition objects are successfully matched, the statistical results of the target statistical variable are updated according to the transaction data and the calculation type.
7. An electronic device, characterized in that, The electronic device includes: at least one processor and a memory; The memory stores computer-executed instructions; The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, cause a computing device to implement the method as described in any one of claims 1 to 5.