Electronic invoice batch processing and storage method and system based on data encryption
By using a random forest model to encrypt in electronic invoice data processing and intelligent classification and storage combined with clustering models, the security risks and inefficiency of solid key encryption in the existing technology are solved, and efficient and secure data management and storage are achieved.
Patent Information
- Application Number
- CN202411689696.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-03-14
AI Technical Summary
The existing data encryption algorithm uses fixed keys, which poses security risks, and complex encryption algorithms increase data storage space and low query efficiency.
The electronic invoice data is encrypted by constructing a random forest model of multiple decision trees, and the encrypted data is intelligently classified and stored in combination with the clustering model. The distance between the Mahayana distance is used to calculate the distance between the clusters to determine the storage scheme.
It improves the security and immutability of data, reduces data storage space, improves query efficiency, and realizes intelligent classification and efficient management of data.
Smart Images

Figure CN119622769A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of invoice data processing, and in particular to a method and system for batch processing and storing electronic invoices based on data encryption. Background Art
[0002] With the rapid development of digital technology, electronic invoices have become an important part of financial records and business transactions. Compared with traditional paper invoices, electronic invoices offer many significant advantages, such as easy transmission, storage and processing, and can generally provide richer transaction-related information than traditional invoices. These features enable companies to manage financial processes more efficiently, reduce errors, and support modern working modes such as remote working. However, since electronic invoice data is not only of high value, it often contains sensitive information, such as company name, address, tax registration number, and detailed financial data.
[0003] In order to ensure the data security of electronic invoices, data encryption algorithms are usually used to encrypt electronic invoices to prevent data from being unauthorized access or malicious use. Common encryption methods include symmetric encryption algorithms (such as AES) and asymmetric encryption algorithms (such as RSA). Symmetric encryption algorithms use the same key for encryption and decryption operations. Its advantage is that it is fast and suitable for encryption of large amounts of data; while asymmetric encryption algorithms use a pair of public and private keys, the public key is used for encryption, and the private key is used for decryption. Although this method has a large amount of calculation, it is more secure and is particularly suitable for scenarios such as key exchange. However, existing data encryption algorithms usually use fixed keys, which simplifies the key management process to a certain extent, but also brings significant security risks. Once the fixed key is obtained by an attacker through brute force or social engineering attacks, all data encrypted with the key will face the risk of being decrypted. This will not only lead to the exposure of sensitive information, but also threaten the data integrity of the entire electronic invoice processing process, thereby seriously affecting the financial security and compliance of the enterprise. The encryption method using fixed keys is not very secure in the face of increasingly complex and changeable network security threats, and as the amount of data increases, complex encryption algorithms will increase data storage space and cause low query efficiency. Summary of the invention
[0004] The present invention provides a method and system for batch processing and storing electronic invoices based on data encryption, so as to reduce data storage space and improve query efficiency.
[0005] In the first aspect, in order to solve the above technical problems, the present invention provides a method for batch processing and storage of electronic invoices based on data encryption, comprising:
[0006] Obtain original electronic invoice data;
[0007] Inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions;
[0008] Convert the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences;
[0009] All the binary sequences are connected into a long binary sequence, and the long binary sequence is segmented and encrypted by a random forest model including multiple decision trees to obtain encrypted electronic invoice data; wherein, when constructing each decision tree, the random forest extracts samples from the original data set using a bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node is split;
[0010] Inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type, and a cluster density;
[0011] The cluster distance between each cluster is calculated by using a distance formula according to the cluster center;
[0012] Different storage schemes are adopted for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
[0013] In an optional implementation, the obtaining of original electronic invoice data includes:
[0014] Acquire the original electronic invoice data stored in a preset database;
[0015] The original electronic invoice data includes the invoice code, invoice number, issue date, issuer, issuer taxpayer identification number and issue address.
[0016] In an optional implementation, the decision tree construction process includes:
[0017] Using the original data set as the data column in the random forest model to construct an empty initial decision tree;
[0018] When each node is split, some features are randomly selected to calculate all possible split points, and the split point with the maximum information gain or the minimum Gini index is selected as the current split point corresponding to the current node; the current split point divides the data set into two subsets, each subset is used to construct a subtree;
[0019] The splitting process is repeated for each subset until the preset maximum tree depth is reached or the number of samples in the subset is less than the preset threshold or further splitting is impossible. The leaf nodes are determined to obtain the completed decision tree.
[0020] In an optional implementation, the training process of the clustering model includes:
[0021] Randomly generate original model parameters as parameters of clustering model;
[0022] Inputting the original electronic invoice data into the clustering model as a training set to train the clustering model;
[0023] The silhouette coefficient in the clustering model is calculated according to the following formula:
[0024]
[0025] Among them, S(C) is the silhouette coefficient, C is the number of samples, b(i) is the minimum average distance from sample i to all samples in the nearest cluster, and a(i) is the average distance from sample i to other samples in the same cluster;
[0026] When the silhouette coefficient is the smallest, the corresponding current model parameters are used as parameters of the clustering model to obtain a trained clustering model, wherein the model parameters include the number of classifications of the clustering model.
[0027] In an optional implementation, the encrypted electronic invoice data is input into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type, and a cluster density, including:
[0028] The cluster density is calculated using the following formula:
[0029]
[0030] Among them, f(x) is the cluster density, h is the bandwidth, M is the number of sample points, is the kernel function, satisfying x is the cluster center vector, x i is the sample point vector of cluster i.
[0031] In an optional implementation, the calculating the cluster distance between each cluster by using a distance formula according to the cluster center includes:
[0032] The cluster distance is defined by Mahalanobis distance;
[0033] The distance formula is as follows:
[0034]
[0035] Among them, D M (x,y) is the cluster distance, x,y are two different cluster center vectors, Σ -1is the inverse of the covariance matrix of the cluster, (xy) T is the transpose of the vector (xy).
[0036] In an optional implementation, the adopting different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold includes:
[0037] When the cluster distance is less than a preset distance threshold, for the sample point corresponding to the cluster distance, the encrypted electronic invoice data of the sample point is stored in a preset encryption database;
[0038] When the cluster distance is greater than a preset distance threshold, for the sample point corresponding to the cluster distance, the original electronic invoice data of the sample point is stored in a preset encryption database.
[0039] In a second aspect, the present invention provides an electronic invoice batch processing and storage system based on data encryption, comprising:
[0040] A data acquisition module, used to acquire original electronic invoice data;
[0041] A data encryption module, used for inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; converting the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences; connecting all the binary sequences into a long binary sequence, and performing segmentation and encryption operations on the long binary sequence through a random forest model including multiple decision trees to obtain encrypted electronic invoice data;
[0042] When constructing each decision tree, the random forest extracts samples from the original data set using the bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node splits;
[0043] An encrypted clustering module, used for inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density;
[0044] A cluster distance module, used to calculate the cluster distance between various clusters using a distance formula based on the cluster center;
[0045] The data storage module is used to adopt different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
[0046] In a third aspect, the present invention also provides an electronic device comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the electronic invoice batch processing and storage method based on data encryption as described above is implemented.
[0047] In a fourth aspect, the present invention further provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned electronic invoice batch processing and storage methods based on data encryption.
[0048] Compared with the prior art, the present invention has the following beneficial effects:
[0049] The present invention discloses a method and system for batch processing and storing electronic invoices based on data encryption, the method comprising obtaining original electronic invoice data; calculating encrypted electronic invoice data through a data encryption algorithm for the original electronic invoice data; inputting the encrypted electronic invoice data into a clustering model to obtain clustering results, the clustering results including cluster centers, cluster types and cluster densities; calculating cluster distances between clusters through a distance formula according to the cluster centers; and adopting different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distances and a preset distance threshold. The present invention encrypts the electronic invoice data by constructing a data encryption algorithm, and the data encryption algorithm converts the sensitive information of the electronic invoice into a digital sequence, which makes the data difficult to crack. At the same time, the encryption makes the electronic invoice data more difficult to be tampered with or forged, thereby improving the data's non-tamperability and data security. Furthermore, the present invention introduces a clustering algorithm to perform cluster analysis on the encrypted electronic invoice data to achieve intelligent classification of the data. Under the classified storage scheme, the data is stored independently according to categories and attributes. This organizational method makes data retrieval faster and more accurate, thereby improving the management efficiency of electronic invoices. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a flow chart of a method for batch processing and storing electronic invoices based on data encryption provided by the first embodiment of the present invention;
[0051] Figure 2 It is a structural diagram of an electronic invoice batch processing and storage system based on data encryption provided by the second embodiment of the present invention. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0053] With the rapid development of digital technology, electronic invoices have become an important part of financial records and business transactions. Compared with traditional paper invoices, electronic invoices offer many significant advantages, such as easy transmission, storage and processing, and can generally provide richer transaction-related information than traditional invoices. These features enable companies to manage financial processes more efficiently, reduce errors, and support modern working modes such as remote working. However, since electronic invoice data is not only of high value, it often contains sensitive information, such as company name, address, tax registration number, and detailed financial data.
[0054] In order to ensure the data security of electronic invoices, data encryption algorithms are usually used to encrypt electronic invoices to prevent data from being unauthorized access or malicious use. Common encryption methods include symmetric encryption algorithms (such as AES) and asymmetric encryption algorithms (such as RSA). Symmetric encryption algorithms use the same key for encryption and decryption operations. Its advantage is that it is fast and suitable for encryption of large amounts of data; while asymmetric encryption algorithms use a pair of public and private keys, the public key is used for encryption, and the private key is used for decryption. Although this method has a large amount of calculation, it is more secure and is particularly suitable for scenarios such as key exchange. However, existing data encryption algorithms usually use fixed keys, which simplifies the key management process to a certain extent, but also brings significant security risks. Once the fixed key is obtained by an attacker through brute force or social engineering attacks, all data encrypted with the key will face the risk of being decrypted. This will not only lead to the exposure of sensitive information, but also threaten the data integrity of the entire electronic invoice processing process, thereby seriously affecting the financial security and compliance of the enterprise. The encryption method using fixed keys is not very secure in the face of increasingly complex and changeable network security threats, and as the amount of data increases, complex encryption algorithms will increase data storage space and cause low query efficiency.
[0055] To solve the above problems, refer to Figure 1 The first embodiment of the present invention provides a method for batch processing and storing electronic invoices based on data encryption, comprising the following steps:
[0056] S11, obtaining original electronic invoice data;
[0057] S12, inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; converting the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences; connecting all the binary sequences into a long binary sequence, and performing segmentation and encryption operations on the long binary sequence through a random forest model including multiple decision trees to obtain encrypted electronic invoice data;
[0058] When constructing each decision tree, the random forest extracts samples from the original data set using the bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node splits;
[0059] S13, inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type, and a cluster density;
[0060] S14, calculating the cluster distance between each cluster using a distance formula according to the cluster center;
[0061] S15, adopting different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
[0062] In step S11, original electronic invoice data is obtained.
[0063] In one embodiment, the original electronic invoice data stored in a preset database is obtained; this can be done automatically through an API interface or by manually uploading a file. Further, after obtaining the original data, the data needs to be preprocessed to ensure the quality of the data. The preprocessing steps include: deleting illogical or obviously erroneous data entries and removing outliers; for certain fields where reasonable values can be inferred, using intelligent methods to fill in missing values; and converting data from different sources into a consistent format.
[0064] It is worth noting that the original electronic invoice data includes the invoice code, invoice number, issue date, issuer, issuer taxpayer identification number and issue address. The invoice code is the code used to uniquely identify the invoice, the invoice number is the serial number of each invoice, and the issuer taxpayer identification number is the tax registration number of the issuer.
[0065] In another embodiment, obtaining data requires defining one or more API interfaces for obtaining the original electronic invoice data from a preset database. These interfaces can be designed based on a RESTful architecture and support HTTP GET requests. At the same time, in order to ensure the security of the data, the API interface should include an authentication mechanism, such as OAuth 2.0, API keys, etc., to ensure that only authorized users can access the data. Furthermore, the API interface should allow the passing of some query parameters, such as time range, invoice number, customer ID, etc., so as to obtain the required data more flexibly. When the client sends a GET request to the API interface, it is accompanied by the necessary authentication information and query parameters. After receiving the request, the server verifies the authentication information and then retrieves the corresponding electronic invoice data from the preset database according to the query parameters. The server then returns the query results to the client in JSON format or other suitable data formats. If an error occurs during the request (such as authentication failure, database connection problem, etc.), the server should return an appropriate error code and error message for the client to process.
[0066] In step S12, the original electronic invoice data is calculated using a data encryption algorithm to obtain encrypted electronic invoice data.
[0067] Specifically, the original electronic invoice data is input into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; the elements of each dimension of the original electronic invoice vector are converted into binary to obtain n binary sequences; all the binary sequences are connected into a long binary sequence, and the long binary sequence is segmented and encrypted by a random forest model including multiple decision trees to obtain encrypted electronic invoice data;
[0068] When constructing each decision tree, the random forest extracts samples from the original data set using the bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node splits.
[0069] It is worth noting that the normalization model is used to convert data of different sizes into the same range. The normalization model of this method adjusts the information in the invoice to [0,1]. Since the original electronic invoice data includes invoice code, invoice number, issue date, issuer, issuer taxpayer identification number and issue address. Through the normalization model, all of this information can be converted into numerical values to ensure that the features input into the subsequent model are comparable. The normalization model can be a minimum-maximum scaling based on statistical methods, or a more complex machine learning-based technology. The original electronic invoice vector refers to the electronic invoice data after normalization represented in the form of an n-dimensional vector, where n represents the number of elements in the vector, that is, the number of features. The conversion into a binary sequence is to prepare the data format for a specific type of encryption algorithm. The long binary sequence is a single continuous binary string formed by connecting all the binary sequences obtained by the above steps. The purpose of creating such a continuous binary string is to conveniently input it as a whole into the random forest model to be used next.
[0070] In one embodiment, the decision tree construction process includes:
[0071] Using the original data set as the data column in the random forest model to construct an empty initial decision tree;
[0072] When each node is split, some features are randomly selected to calculate all possible split points, and the split point with the maximum information gain or the minimum Gini index is selected as the current split point corresponding to the current node; the current split point divides the data set into two subsets, each subset is used to construct a subtree;
[0073] The splitting process is repeated for each subset until the preset maximum tree depth is reached or the number of samples in the subset is less than the preset threshold or further splitting is impossible. The leaf nodes are determined to obtain the completed decision tree.
[0074] Exemplarily, the specific implementation steps for constructing each decision tree are as follows. First, initialize the decision tree by creating an empty initial decision tree, including nodes and leaf nodes. A node contains a splitting attribute, a splitting threshold, and pointers to child nodes, while a leaf node contains a class or a value. Next, when splitting each node, the random forest randomly selects a subset of features. Specifically, assuming the original dataset has n features, the random forest randomly selects m features (m < n) from these features to reduce the risk of overfitting. Subsequently, for each selected feature, all possible splitting points are calculated. Here, a splitting point refers to a threshold of a feature used to divide the dataset into two parts. The splitting point with the maximum information gain or the minimum Gini index is selected as the current splitting point corresponding to the current node, and the current splitting point divides the dataset into two subsets, each subset being used to construct a subtree. Then, recursive splitting is performed, repeating the above process for each subset until a stopping condition is met. The stopping condition can be reaching a preset maximum tree depth, or the number of samples in the subset being less than a preset quantity threshold, or being unable to split further. Then, when a node meets the stopping condition, it becomes a leaf node, and the value of the leaf node can be the most common class in the subset. Repeat the above steps until a sufficient number of decision trees are constructed, and these decision trees together form the random forest model.
[0075] Optionally, the calculation formula for information gain is as follows:
[0076]
[0077] where D is the dataset, A is an attribute in dataset D, H(D) is the entropy of dataset D; values(A) is the set of all possible values of attribute A; D v is the subset of dataset D where the value of attribute A is v; |D| is the total number of samples in dataset D; |D v | is the number of samples in subset D v ; H(D v ) is the entropy of subset D v , and the calculation formula for entropy H(D) is:
[0078]
[0079] where n is the number of classes in dataset D; p i is the proportion of samples of the i-th class in dataset D.
[0080] Optionally, the calculation formula for the Gini index is as follows:
[0081]
[0082] where n is the number of classes in dataset D, p iis the proportion of samples of the i-th category in the dataset D.
[0083] Optionally, for a split point, the Gini index is calculated as:
[0084]
[0085]
[0086] where values(A) is the set of all possible values of attribute A; v is the subset of the dataset D whose attribute A takes the value v; |D| is the total number of samples in the dataset D; |D v | is a subset D v The number of samples in ;
[0087] Where n is the dataset D v The number of categories in , p i It is the dataset D v The proportion of samples in the i-th category, Gini(D v ) is a subset D v The Gini index.
[0088] Random forest is an ensemble learning method that uses multiple decision trees to improve prediction performance. Each tree is built based on a different subset of the training set. The random forest model is used to perform encryption operations on long binary sequences and finally output encrypted electronic invoice data. When building each tree, the random forest uses a bootstrap sampling method to extract samples from the original data set to form a new sub-dataset. In addition to random sample selection, the random forest also randomly selects a portion of features for optimal segmentation at each node split. Further, each tree builds a complete decision tree based on the randomly selected samples and features without pruning. Finally, the complexity and irreversibility of the random forest are used to achieve confidentiality. For example, the long binary sequence is 10000100001000001100001. The scikit-learn library can be used in python to build and train the random forest model. After training with a preset data set, the random forest model can output the prediction result for the input digital sequence. The result is in the form of an integer, and the integer range can be set as needed. This method uses 0,1,2,3. For the long binary sequence, the random forest model will divide it into 4 small segments, and the prediction result for 1000 is 0, the prediction result for 0100 is 1, the prediction result for 0010 is 2, and the prediction result for 0001 is 3. Then the encrypted result is 1234.
[0089] In another embodiment, the encryption method for electronic invoices can adopt the Advanced Encryption Standard method, which is a symmetric encryption algorithm, which means that the same key is used for encryption and decryption. Each byte is replaced by a nonlinear substitution table, and then each row in the state matrix is cyclically shifted left in a specific way, and each column of the state matrix is mixed to achieve data diffusion, and finally the current state is XORed with the round key to obtain the encrypted data. Furthermore, this encryption method requires the generation of a key of sufficient strength, at least 128 bits. At the same time, the key should be kept confidential and should be changed regularly to improve security. For structured data such as electronic invoices, the cipher block chaining mode is used.
[0090] In another embodiment, the encryption method for the electronic invoice can use a hash function, which is an algorithm that maps data of any length to a fixed-length string. Among them, SHA-256 (Secure Hash Algorithm 256-bit) is an example of a hash function and is part of the SHA-2 family. It can generate a 256-bit (32-byte) hash value, which is almost unique for different inputs. After creating an electronic invoice, a hash value of the invoice data is calculated using a hash function such as SHA-256. This hash value serves as a digital fingerprint of the invoice data. The calculated hash value is stored or sent to the recipient together with the invoice data. After the recipient receives the invoice and the corresponding hash value, the hash value of the received data is calculated again using the same hash function. Then compare the newly calculated hash value with the hash value provided with the invoice to see if they are consistent. If the two hash values are the same, it means that the data has not been tampered with; otherwise, it means that the data has been changed and is no longer credible.
[0091] In step S13, the encrypted electronic invoice data is input into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density.
[0092] In one implementation, the cluster density is calculated using the following formula:
[0093]
[0094] Among them, f(x) is the cluster density, h is the bandwidth, M is the number of sample points, is a kernel function that satisfies x is the cluster center vector, x i is the sample point vector numbered i in the cluster.
[0095] In one implementation, the clustering model training process includes:
[0096] Randomly generate original model parameters as parameters of clustering model;
[0097] Inputting the original electronic invoice data into the clustering model as a training set to train the clustering model;
[0098] The silhouette coefficient in the clustering model is calculated according to the following formula:
[0099]
[0100] Among them, S(C) is the silhouette coefficient, C is the number of samples, b(i) is the minimum average distance from sample i to all samples in the nearest cluster, and a(i) is the average distance from sample i to other samples in the same cluster;
[0101] When the silhouette coefficient is the smallest, the corresponding current model parameters are used as parameters of the clustering model to obtain a trained clustering model, wherein the model parameters include the number of classifications of the clustering model.
[0102] It is worth mentioning that the silhouette coefficient is a commonly used indicator for evaluating clustering effects. It combines the cohesion and separation of clusters and is used to measure the closeness of data points in a cluster and the degree of separation from other clusters. The value range of the silhouette coefficient is [-1, 1]. When the value of the silhouette coefficient is close to -1, it means that the sample point is well assigned to the correct cluster and the cluster is clearly separated from other clusters. When the value of the silhouette coefficient is close to 0, it means that the sample point is on the boundary of two or more clusters, that is, it is suitable for more than one cluster. When the value of the silhouette coefficient is close to 1, it means that the sample point is incorrectly assigned to an inappropriate cluster. Therefore, when choosing the optimal number of clusters, you should look for the value of the number of clusters that minimizes the average silhouette coefficient.
[0103] It is worth noting that kernel density estimation is a non-parametric probability density function estimation method, which can estimate the probability density function of data without knowing the distribution form of the data. Features are extracted from the target image, and the features of all images are merged into a large feature set to form a high-dimensional feature space. Kernel density estimation is used to estimate the probability density in the feature space. The appropriate bandwidth controls the smoothness of the estimation. According to the results of kernel density estimation, different cluster centers can be defined by finding local maximum points. Alternatively, each feature point can be directly assigned to the nearest high-density area to achieve clustering. If you know which categories the template belongs to, you can also classify it by comparing the density distribution of the target data features with the template features. Finally, based on the clustering or classification results, the data is sorted. For example, if the purpose is to find the target data that is most similar to a specific template, the similarity between the target data features and the density distribution of each template category can be calculated and sorted accordingly. Furthermore, the kernel function is a symmetric smooth function with an area of 1, and a Gaussian kernel function can be used. For each observed data point, the kernel function is applied as the cluster density value, and all these kernel functions are superimposed to form an overall probability density estimate. If the bandwidth is too small, the estimate will be too volatile and capture a lot of noise; if the bandwidth is too large, the estimate will be too smooth and lose important details. The bandwidth can be automatically determined by statistical methods such as cross-validation, or set according to empirical rules.
[0104] It is worth noting that for a given cluster, the cluster center is the arithmetic mean of all sample points in the cluster in each feature dimension. If the data point is described by multiple features, the cluster center is also a vector with the same number of features. Before the K-means algorithm starts, k initial cluster centers need to be randomly selected. In each iteration, the data point is assigned to the cluster corresponding to the nearest cluster center according to the distance between each data point and all current cluster centers. The commonly used distance metric here is Euclidean distance, but other distance metrics can also be used. Once all data points are assigned to the corresponding clusters, the new cluster center of each cluster needs to be recalculated. The new cluster center is the mean of all data points in the cluster. This process will be repeated until the cluster center no longer changes significantly or the preset maximum number of iterations is reached. Further, in order to improve the selection of the initial cluster center, the K-means++ algorithm was proposed. Its main idea is to select cluster centers more dispersedly in the initialization stage, thereby reducing the probability of the algorithm falling into a local optimal solution. Specifically, the first center point is randomly selected, and subsequent center points tend to be selected away from the existing center points.
[0105] In another embodiment, DBSCAN clustering can be used for the selection of clustering models. This density-based clustering algorithm can automatically identify clusters of any shape and can handle noisy data. DBSCAN does not need to pre-specify the number of clusters, but determines clusters by setting neighborhood distances and a minimum number of points. Mark all points as unvisited as initialization. Randomly select an unvisited point as the starting point. Check whether the point is a core point. If so, find all the points in its neighborhood. This core point and all reachable points in its neighborhood are grouped into the same cluster. Then, repeat this process for each core point newly added to the cluster until no new points can be added. Once all points have been examined and assigned to the corresponding clusters or marked as noise, the entire clustering process ends.
[0106] It is worth noting that the DBSCAN clustering algorithm has several significant advantages over K-means when processing electronic invoice data. These advantages mainly come from DBSCAN's adaptability to data distribution and its ability to handle noise points. The K-means algorithm requires the user to specify the number of clusters k to be formed in advance. Especially in electronic invoice data, since the categories of invoices in different business scenarios are unknown or dynamically changing, pre-setting a fixed number of clusters will lead to inaccurate results. DBSCAN does not need to specify the number of clusters in advance. It can automatically discover naturally existing clusters based on the density characteristics of the data itself. K-means tends to generate spherical or nearly circular clusters because it assigns data points to the nearest center point based on distance metrics. However, in real-world data, such as consumption patterns or supplier relationships in electronic invoices, they often do not present simple geometric shapes. DBSCAN is not limited by cluster shape and can identify more complex and irregular structures. Furthermore, electronic invoice datasets contain a large number of abnormal records, such as incorrect entries, fraudulent behavior, or special one-time transactions. K-means will try to classify all data points into a cluster, even if these points do not actually belong to any meaningful group. In contrast, DBSCAN can clearly distinguish core points, boundary points, and noise points, and mark those data points far away from dense areas as noise, thus more accurately reflecting the true situation of the data. At the same time, electronic invoices contain information in multiple dimensions. As the dimensions increase, the effect of K-means tends to decrease because it relies on a metric such as Euclidean distance, which is no longer effective in high-dimensional space. DBSCAN determines density by defining the number of points in the neighborhood. This method has less impact on the dimension, so it is more suitable for processing electronic invoice data with rich multi-dimensional features.
[0107] In step S14, the cluster distances between the clusters are calculated using a distance formula based on the cluster centers.
[0108] In one implementation, the cluster distance is defined using Mahalanobis distance;
[0109] The distance formula is as follows:
[0110]
[0111] Among them, D M (x, y) is the cluster distance, x, y are two different cluster center vectors, ∑ -1 is the inverse of the covariance matrix of the cluster, (xy) T is the transpose of the vector (xy).
[0112] It is worth mentioning that the Mahalanobis distance is a method to measure the distance between multivariate data points, which takes into account the covariance structure of the data. Unlike the Euclidean distance, the Mahalanobis distance not only considers the differences between the features, but also the correlation between these features and their scale. Therefore, the Mahalanobis distance is more effective when dealing with data with correlated features. If the variables in the data set are highly correlated, some elements of the covariance matrix will be large. By multiplying by the inverse of the covariance matrix, the distance can be effectively shortened, thereby reducing the impact of correlation. Furthermore, the Mahalanobis distance is scale-independent, which means that even if the units or scales of the features are different, it will not affect the calculation results of the distance. In clustering, the Mahalanobis distance can help to better understand the relationship between data points, especially when there is correlation between features.
[0113] In step S15, different storage schemes are adopted for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
[0114] In one embodiment, when the cluster distance is less than a preset distance threshold, for the sample point corresponding to the cluster distance, the encrypted electronic invoice data of the sample point is stored in the preset encryption database; when the cluster distance is greater than the preset distance threshold, for the sample point corresponding to the cluster distance, the original electronic invoice data of the sample point is stored in the preset encryption database.
[0115] It is worth noting that for those data points that belong to similar clusters, that is, the distance between clusters is less than the preset threshold, they contain more sensitive information or represent certain specific patterns. Encrypting this data can provide an additional layer of security to ensure that the data content will not be easily leaked even if the database is illegally accessed. For those data points that do not belong to similar clusters, that is, the distance between clusters is greater than the preset threshold, they are not so sensitive or not easy to form obvious patterns. In this case, the original data can be stored directly to simplify the processing flow and improve access efficiency.
[0116] In another embodiment, the present invention provides a visual user interface that uses a scatter plot to display the distribution of electronic invoice data after cluster analysis. By calling the interface, the system visualizes the clustering results. Each point in the scatter plot represents an electronic invoice data sample, and different colors or marks represent different clusters. Users can intuitively see the distribution pattern of the data through the scatter plot, such as the density of data points, the distance between clusters, etc. Auditors can quickly identify abnormal data through the visual interface for further review; data analysts can use the visualization results to discover hidden patterns in the data to provide support for business decisions; security managers can monitor the distribution of data to promptly identify potential security risks and take preventive measures; users can directly export data reports from the interface for internal reporting or external communication.
[0117] In summary, this method proposes a method and system for batch processing and storage of electronic invoices based on data encryption, aiming to achieve efficient data management and classified storage by enhancing data security and automatically analyzing data distribution in combination with clustering technology. The core of this method is to build a powerful data encryption algorithm and intelligently classify the encrypted electronic invoice data in combination with a clustering model. First, the system obtains the electronic invoice data and stores the data in a preset database. Then, the original electronic invoice data is preprocessed to remove outliers and missing values to ensure the integrity and accuracy of the data. On this basis, an innovative data encryption algorithm is introduced, which generates encrypted data by defining the numerical range of the electronic invoice data and mapping the numerical values to the preset range. The encryption process includes constructing a random forest, calculating the impurity of each root node based on the tree Gini impurity, and continuing to construct child nodes until the impurity is less than the threshold, and finally forming a random forest. This method not only enhances the security of the data, but also improves the immutability of the data, preventing the data from being illegally accessed and abused. After completing the data encryption, the system uses the clustering model to perform clustering analysis on the encrypted electronic invoice data. The clustering model randomly selects a preset number of tree nodes as samples, calculates the mean of each sample, and divides the samples into a preset number of clusters. The center point of each cluster represents the average characteristics of all samples in the cluster, and the quality of the clustering results is evaluated by calculating the cluster density and silhouette coefficient. When the silhouette coefficient is the largest, the optimal number of clusters is determined. Finally, the electronic invoice data is classified and stored based on the clustering results. For sample points whose inter-cluster distance is less than the preset distance threshold, it means that these data points have high similarity and potential high risk, so the encrypted electronic invoice data of these data points are stored in the preset encrypted database to provide an additional layer of security. For sample points whose inter-cluster distance is greater than the preset distance threshold, it means that these data points are more different and have lower risk, so they are directly stored in the preset encrypted database in the original format, simplifying the processing process and improving access efficiency. This method not only significantly improves the security and privacy protection level of the data, but also optimizes the data management process, reduces storage space, and improves query efficiency.
[0118] Reference Figure 2 The second embodiment of the present invention provides an electronic invoice batch processing and storage system based on data encryption, including:
[0119] A data acquisition module, used to acquire original electronic invoice data;
[0120] A data encryption module, used for inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; converting the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences; connecting all the binary sequences into a long binary sequence, and performing segmentation and encryption operations on the long binary sequence through a random forest model including multiple decision trees to obtain encrypted electronic invoice data;
[0121] When constructing each decision tree, the random forest extracts samples from the original data set using the bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node splits;
[0122] An encrypted clustering module, used for inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density;
[0123] A cluster distance module, used to calculate the cluster distance between various clusters using a distance formula based on the cluster center;
[0124] The data storage module is used to adopt different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
[0125] Preferably, the data acquisition module is used to:
[0126] Obtain original electronic invoice data, including:
[0127] Acquire the original electronic invoice data stored in a preset database;
[0128] The original electronic invoice data includes the invoice code, invoice number, issue date, issuer, issuer taxpayer identification number and issue address.
[0129] Preferably, the encrypted clustering module is used to:
[0130] The encrypted electronic invoice data is input into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density, including:
[0131] The cluster density is calculated using the following formula:
[0132]
[0133] Among them, f(x) is the cluster density, h is the bandwidth, M is the number of sample points, is a kernel function that satisfies x is the cluster center vector, x iis the sample point vector of cluster i.
[0134] Preferably, the training process of the clustering model includes:
[0135] Randomly generate original model parameters as parameters of clustering model;
[0136] Inputting the original electronic invoice data into the clustering model as a training set to train the clustering model;
[0137] The silhouette coefficient in the clustering model is calculated according to the following formula:
[0138]
[0139] Among them, S(C) is the silhouette coefficient, C is the number of samples, b(i) is the minimum average distance from sample i to all samples in the nearest cluster, and a(i) is the average distance from sample i to other samples in the same cluster;
[0140] When the silhouette coefficient is the smallest, the corresponding current model parameters are used as parameters of the clustering model to obtain a trained clustering model, wherein the model parameters include the number of classifications of the clustering model.
[0141] Preferably, the cluster distance module is used to:
[0142] The cluster distances between the clusters are calculated using the distance formula according to the cluster center, including:
[0143] The cluster distance is defined by Mahalanobis distance;
[0144] The distance formula is as follows:
[0145]
[0146] Among them, D M (x, y) is the cluster distance, x, y are two different cluster center vectors, ∑- 1 is the inverse of the covariance matrix of the cluster, (xy) T is the transpose of the vector (xy).
[0147] Preferably, the data storage module is used for:
[0148] According to the cluster distance and the preset distance threshold, different storage schemes are adopted for the original electronic invoice data and the encrypted electronic invoice data, including:
[0149] When the cluster distance is less than a preset distance threshold, for the sample point corresponding to the cluster distance, the encrypted electronic invoice data of the sample point is stored in a preset encryption database;
[0150] When the cluster distance is greater than a preset distance threshold, for the sample point corresponding to the cluster distance, the original electronic invoice data of the sample point is stored in a preset encryption database.
[0151] It should be noted that the electronic invoice batch processing and storage system based on data encryption provided in an embodiment of the present invention is used to execute all the process steps of the electronic invoice batch processing and storage method based on data encryption in the above embodiment. The working principles and beneficial effects of the two correspond one to one, and therefore will not be repeated here.
[0152] The embodiment of the present invention also provides an electronic device. The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a data encryption program. When the processor executes the computer program, the steps in the above-mentioned embodiments of the electronic invoice batch processing and storage method based on data encryption are implemented, such as Figure 1 Alternatively, when the processor executes the computer program, the functions of each module / unit in the above-mentioned device embodiments are implemented, such as the data acquisition module.
[0153] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.
[0154] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, and a smart tablet. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. The electronic device may include more or fewer components than the above components, or may combine certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0155] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device.
[0156] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0157] Wherein, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0158] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.
[0159] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for batch processing and storage of electronic invoices based on data encryption, characterized in that: include: Obtain original electronic invoice data; Inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; Convert the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences; All the binary sequences are connected into a long binary sequence, and the long binary sequence is segmented and encrypted by a random forest model including multiple decision trees to obtain encrypted electronic invoice data; wherein, when constructing each decision tree, the random forest extracts samples from the original data set using a bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node is split; Inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type, and a cluster density; The cluster distance between each cluster is calculated by using a distance formula according to the cluster center; Different storage schemes are adopted for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
2. The method for batch processing and storing electronic invoices based on data encryption according to claim 1 is characterized in that: The obtaining of original electronic invoice data includes: Acquire the original electronic invoice data stored in a preset database; The original electronic invoice data includes the invoice code, invoice number, issue date, issuer, issuer taxpayer identification number and issue address.
3. The method for batch processing and storing electronic invoices based on data encryption according to claim 1 is characterized in that: The decision tree construction process includes: Using the original data set as the data column in the random forest model to construct an empty initial decision tree; When each node is split, some features are randomly selected to calculate all possible split points, and the split point with the maximum information gain or the minimum Gini index is selected as the current split point corresponding to the current node; the current split point divides the data set into two subsets, each subset is used to construct a subtree; The splitting process is repeated for each subset until the preset maximum tree depth is reached or the number of samples in the subset is less than the preset threshold or further splitting is impossible. The leaf nodes are determined to obtain the completed decision tree.
4. The method for batch processing and storing electronic invoices based on data encryption according to claim 1 is characterized in that: The training process of the clustering model includes: Randomly generate original model parameters as parameters of clustering model; Inputting the original electronic invoice data into the clustering model as a training set to train the clustering model; The silhouette coefficient in the clustering model is calculated according to the following formula: Among them, S(C) is the silhouette coefficient, C is the number of samples, b(i) is the minimum average distance from sample i to all samples in the nearest cluster, and a(i) is the average distance from sample i to other samples in the same cluster; When the silhouette coefficient is the smallest, the corresponding current model parameters are used as parameters of the clustering model to obtain a trained clustering model, wherein the model parameters include the number of classifications of the clustering model.
5. The method for batch processing and storing electronic invoices based on data encryption according to claim 1 is characterized in that: The encrypted electronic invoice data is input into the clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density, including: The cluster density is calculated using the following formula: Among them, f(x) is the cluster density, h is the bandwidth, M is the number of sample points, is a kernel function that satisfies x is the cluster center vector, x i is the sample point vector numbered i in the cluster.
6. The method for batch processing and storing electronic invoices based on data encryption according to claim 2 is characterized in that: The cluster distances between the clusters are calculated by using a distance formula according to the cluster centers, including: The cluster distance is defined by Mahalanobis distance; The distance formula is as follows: Among them, D M (x,y) is the cluster distance, x,y are two different cluster center vectors, Σ -1 is the inverse of the covariance matrix of the cluster, (xy) T is the transpose of the vector (xy).
7. The method for batch processing and storing electronic invoices based on data encryption according to claim 1 is characterized in that: The adopting different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold includes: When the cluster distance is less than a preset distance threshold, for the sample point corresponding to the cluster distance, the encrypted electronic invoice data of the sample point is stored in a preset encryption database; When the cluster distance is greater than a preset distance threshold, for the sample point corresponding to the cluster distance, the original electronic invoice data of the sample point is stored in a preset encryption database.
8. An electronic invoice batch processing and storage system based on data encryption, characterized in that: include: A data acquisition module, used to acquire original electronic invoice data; A data encryption module, used for inputting the original electronic invoice data into a normalization model to obtain an original electronic invoice vector, wherein the original electronic invoice vector has n dimensions; converting the elements of each dimension of the original electronic invoice vector into binary to obtain n binary sequences; connecting all the binary sequences into a long binary sequence, and performing segmentation and encryption operations on the long binary sequence through a random forest model including multiple decision trees to obtain encrypted electronic invoice data; When constructing each decision tree, the random forest extracts samples from the original data set using the bootstrap sampling method to form a new sub-data set, and randomly selects features for optimal segmentation when each node splits; An encrypted clustering module, used for inputting the encrypted electronic invoice data into a clustering model to obtain a clustering result, wherein the clustering result includes a cluster center, a cluster type and a cluster density; A cluster distance module is used to calculate the cluster distance between each cluster using a distance formula based on the cluster center; The data storage module is used to adopt different storage schemes for the original electronic invoice data and the encrypted electronic invoice data according to the cluster distance and the preset distance threshold.
9. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the method for batch processing and storage of electronic invoices based on data encryption as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the electronic invoice batch processing and storage method based on data encryption as described in any one of claims 1 to 7.
Citation Information
Cited By
Trusted data storage method and system based on supply chain collaboration
CN120128190A
Invoice anomaly detection method and system based on vector weighting and density clustering
CN120954015A