Data collection method based on primary key mapping
Through the data aggregation method based on primary key mapping, the primary key mapping of different systems of the same data table is recorded. Relying on the data update time, it solves the problem of data synchronization between systems deployed in multiple places, achieves efficient data fusion and aggregation, and avoids repeated coding. , maintaining the independence between systems.
Patent Information
- Application Number
- CN202410896619.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-05
AI Technical Summary
When establishing a unified parent system between the same systems deployed in multiple places, it is difficult to efficiently synchronize data with existing technology and requires repeated coding to achieve data association synchronization.
Using the data collection method based on primary key mapping, by recording the primary key mapping of the same data table in different systems and relying on the data update time, the integration and collection of data between systems is achieved, including the creation of new synchronization system tables, synchronization table information tables, and synchronization table field tables. and primary key mapping tables. Through the configuration and query of these tables, data synchronization and mapping are completed.
It realizes the synchronous collection of data between systems, ensures the independence between systems, and does not require excessive development at the business level. The synchronization table information is directly configured through the synchronization service to complete the synchronous collection of database tables.
Smart Images

Figure CN118733676A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a data collection method based on primary key mapping. Background Art
[0002] In the early stages of grassroots data governance projects, in order to meet the personalized and security needs of various locations, the same system is often deployed in multiple locations. When a unified parent system is to be established later, the parent system often needs to synchronize and aggregate subsystem data.
[0003] In order to complete the data association synchronization between two systems and reduce duplicate coding, the present invention proposes a data collection method based on primary key mapping. Summary of the invention
[0004] In order to make up for the defects of the prior art, the present invention provides a simple and efficient data collection method based on primary key mapping.
[0005] The present invention is achieved through the following technical solutions:
[0006] A data collection method based on primary key mapping, which records the primary key mapping of different systems in the same data table and completes data fusion collection while ensuring the independence between systems based on data update time;
[0007] The following steps are involved:
[0008] Step S1, the parent system creates a synchronization system table, a synchronization table information table, a synchronization table field table and a primary key mapping table; the subsystem creates a synchronization primary key table;
[0009] Step S2: After the synchronization service starts, the library of the system to be synchronized is connected according to the synchronization system table, the synchronization table information table data is read, the synchronization table information is obtained, and the data is synchronized in sequence according to the synchronization order of the synchronization table;
[0010] Step S3: Compare the subsystem data table and the synchronization primary key table to obtain the primary key of the deleted data, query the parent system primary key in the primary key mapping table according to the subsystem primary key, delete the corresponding parent system data, and delete the corresponding primary key mapping table data and synchronization primary key table data at the same time;
[0011] Step S4: Compare the subsystem data table and the synchronization primary key table to obtain the newly added data, and process the data according to the field information in the synchronization table field table;
[0012] After the processing is completed, the data is inserted into the parent system, and the primary key of the parent system is obtained at the same time. The table name, subsystem primary key and parent system primary key are recorded in the primary key mapping table, and finally the newly added primary key data is inserted into the synchronization primary key table;
[0013] Step S5, obtaining the last update time according to the synchronization table information table, obtaining the synchronization table update data according to the update time increment, and processing the data according to the field information in the synchronization table field table;
[0014] After the modification is completed, query the parent system primary key in the primary key mapping table based on the data primary key and modify the data;
[0015] Step S6: After each synchronization, the latest data update time of the current synchronization table is recorded in the synchronization table information table.
[0016] The synchronization system table is used to record the system information to be synchronized, including the system name to be synchronized and the database connection information.
[0017] The synchronization table information table is used to record the information of the table to be synchronized, including the system name, table name, table primary key field name, table data update time field name, table last update time and table synchronization order;
[0018] The synchronization order of tables is configured according to the association relationship between tables, and the associated tables are synchronized first. During synchronization, the updated data is read incrementally according to the update time field name and the last update time value of the table.
[0019] After the synchronization is completed, get the latest update time of the synchronization table and update the last update time field of the table.
[0020] The synchronization table field table is used to record all field information of the synchronization table, including system name, table name, field name, whether the field is associated with the primary key of another table, and the table name of the associated table;
[0021] During synchronization, the field information of the table to be synchronized is obtained according to the table name. When the field is the primary key field of the record-related table, the primary key mapping is modified during the synchronization process;
[0022] The primary key mapping table is used to record the mapping information of the primary keys of the tables of the subsystem and the parent system during the synchronization process, including the system name, table name, primary key value of the parent system data and primary key value of the subsystem data;
[0023] During synchronization, for the field values associated with the primary keys of other tables, the new primary key value is queried from the primary key mapping table based on the primary key value and the associated table name, and the field value is modified;
[0024] When adding new data, obtain the parent system primary key and save it to the primary key mapping table. When updating or deleting data, perform corresponding operations based on the query parent system primary key value.
[0025] The synchronization primary key table is used to record the primary key information of the currently synchronized table, including the table name and the primary key value;
[0026] When synchronizing data, compare the primary key data of the synchronization table with the primary key data of the corresponding table in the synchronization primary key table, obtain the added and deleted data, and synchronize these two types of data separately.
[0027] A data collection device based on primary key mapping, characterized in that it includes a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the above method steps when executing the computer program.
[0028] A readable storage medium, characterized in that: a computer program is stored on the readable storage medium, and the computer program implements the above method steps when executed by a processor.
[0029] The beneficial effect of the present invention is that the data collection method based on primary key mapping does not affect the independence between systems, and does not require excessive development at the business level. Through synchronization services, the synchronization collection of database tables is directly realized by configuring synchronization table information. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Attached Figure 1 It is a schematic diagram of the data collection method based on primary key mapping of the present invention. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a 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 should fall within the scope of protection of the present invention.
[0033] In the database, the auto-increment primary key can be used to ensure the uniqueness of the data table records, improve query efficiency, and facilitate data maintenance. At the same time, the primary key is often used for association design between multiple tables. In the process of data fusion and collection between systems, for the same system deployed in multiple locations, the data table structure is the same. Data collection mainly solves the association and conflict of the auto-increment primary key of the data table.
[0034] In the database, the auto-increment primary key can be used to ensure the uniqueness of the data table records, improve query efficiency, and facilitate data maintenance. At the same time, the primary key is often used for association design between multiple tables. In the process of data fusion and collection between systems, for the same system deployed in multiple locations, the data table structure is the same. Data collection mainly solves the association and conflict of the auto-increment primary key of the data table.
[0035] In this scenario, the data table structures are the same, and synchronization mainly resolves conflicts in primary keys between systems. Therefore, by recording the primary key mapping of data between systems, during the synchronization process, the primary keys between systems are associated when adding data, and the data is associated through the primary key mapping information when updating and deleting data, thereby achieving synchronous data collection.
[0036] This data collection method based on primary key mapping records the primary key mapping of different systems in the same data table and completes data fusion collection while ensuring the independence between systems based on data update time.
[0037] The information of the synchronization table in the synchronization service is configured through the synchronization table information table B and the synchronization table field table C, the data of the tables between systems is associated through the primary key mapping table D, and the addition and deletion are determined by the synchronization primary key table E.
[0038] The following steps are involved:
[0039] Step S1, the parent system creates a synchronization system table A, a synchronization table information table B, a synchronization table field table C and a primary key mapping table D; the subsystem creates a synchronization primary key table E;
[0040] Step S2: After the synchronization service starts, the library of the system to be synchronized is connected according to the synchronization system table A, the data of the synchronization table information table B is read, the synchronization table information is obtained, and the data is synchronized in sequence according to the synchronization order of the synchronization table;
[0041] Step S3: Compare the subsystem data table and the synchronization primary key table E to obtain the primary key of the deleted data, query the parent system primary key in the primary key mapping table D according to the subsystem primary key, delete the corresponding parent system data, and delete the corresponding primary key mapping table D data and the synchronization primary key table E data at the same time;
[0042] Step S4: Compare the subsystem data table and the synchronization primary key table E, obtain the newly added data, and process the data according to the field information in the synchronization table field table C;
[0043] After the processing is completed, the data is inserted into the parent system, and the primary key of the parent system is obtained at the same time. The table name, subsystem primary key and parent system primary key are recorded in the primary key mapping table D. Finally, the newly added primary key data is inserted into the synchronization primary key table E.
[0044] Step S5, obtaining the last update time according to the synchronization table information table B, obtaining the synchronization table update data according to the update time increment, and processing the data according to the field information in the synchronization table field table C;
[0045] After the modification is completed, query the parent system primary key in the primary key mapping table D according to the data primary key, and modify the data;
[0046] Step S6: After each synchronization, the latest data update time of the current synchronization table is recorded in the synchronization table information table B.
[0047] The synchronization system table A is used to record the system information to be synchronized, including the system name to be synchronized and the database connection information.
[0048] The synchronization table information table B is used to record the information of the table to be synchronized, including the system name, table name, table primary key field name, table data update time field name, table last update time and table synchronization order;
[0049] The synchronization order of tables is configured according to the association relationship between tables, and the associated tables are synchronized first. During synchronization, the updated data is read incrementally according to the update time field name and the last update time value of the table.
[0050] After the synchronization is completed, get the latest update time of the synchronization table and update the last update time field of the table.
[0051] The synchronization table field table C is used to record all field information of the synchronization table, including system name, table name, field name, whether the field is associated with the primary key of another table, and the table name of the associated table;
[0052] During synchronization, the field information of the table to be synchronized is obtained according to the table name. When the field is the primary key field of the record-related table, the primary key mapping is modified during the synchronization process;
[0053] The primary key mapping table D is used to record the mapping information of the primary keys of the tables of the subsystem and the parent system during the synchronization process, including the system name, table name, primary key value of the parent system data and primary key value of the subsystem data;
[0054] During synchronization, for the field values associated with the primary keys of other tables, the new primary key value is queried from the primary key mapping table D according to the primary key value and the associated table name, and the field value is modified;
[0055] When adding new data, obtain the parent system primary key and save it to the primary key mapping table D. When updating and deleting data, perform corresponding operations based on the query parent system primary key value.
[0056] The synchronization primary key table E is used to record the primary key information of the currently synchronized table, including the table name and the primary key value;
[0057] When synchronizing data, compare the primary key data of the synchronization table with the primary key data of the corresponding table in the synchronization primary key table E, obtain the added and deleted data, and synchronize these two types of data separately.
[0058] The data collection device based on primary key mapping includes a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the above method steps when executing the computer program.
[0059] The readable storage medium stores a computer program, and when the computer program is executed by a processor, the above method steps are implemented.
[0060] Compared with the prior art, the data collection method based on primary key mapping has the following characteristics:
[0061] First, synchronize data periodically through an intermediate service, directly synchronizing data at the database level without the business layer being aware of it.
[0062] Second, the synchronization content can be directly configured, avoiding repeated coding work.
[0063] The embodiment described above is only one specific implementation of the present invention. Common changes and substitutions made by those skilled in the art within the scope of the technical solution of the present invention should be included in the protection scope of the present invention.
Claims
1. A data collection method based on primary key mapping, Features: By recording the primary key mapping of different systems in the same data table and relying on the data update time, data fusion and aggregation are completed while ensuring the independence between systems; The following steps are involved: Step S1, the parent system creates a synchronization system table, a synchronization table information table, a synchronization table field table and a primary key mapping table; the subsystem creates a synchronization primary key table; Step S2: After the synchronization service starts, the library of the system to be synchronized is connected according to the synchronization system table, the synchronization table information table data is read, the synchronization table information is obtained, and the data is synchronized in sequence according to the synchronization order of the synchronization table; Step S3: Compare the subsystem data table and the synchronization primary key table to obtain the primary key of the deleted data, query the parent system primary key in the primary key mapping table according to the subsystem primary key, delete the corresponding parent system data, and delete the corresponding primary key mapping table data and synchronization primary key table data at the same time; Step S4: Compare the subsystem data table and the synchronization primary key table to obtain the newly added data, and process the data according to the field information in the synchronization table field table; After the processing is completed, the data is inserted into the parent system, and the primary key of the parent system is obtained at the same time. The table name, subsystem primary key and parent system primary key are recorded in the primary key mapping table, and finally the newly added primary key data is inserted into the synchronization primary key table; Step S5, obtaining the last update time according to the synchronization table information table, obtaining the synchronization table update data according to the update time increment, and processing the data according to the field information in the synchronization table field table; After the modification is completed, query the parent system primary key in the primary key mapping table according to the data primary key and modify the data; Step S6: After each synchronization, the latest data update time of the current synchronization table is recorded in the synchronization table information table.
2. The data collection method based on primary key mapping according to claim 1, Features: The synchronization system table is used to record the system information to be synchronized, including the system name to be synchronized and the database connection information.
3. The data collection method based on primary key mapping according to claim 1, Features: The synchronization table information table is used to record the information of the table to be synchronized, including the system name, table name, table primary key field name, table data update time field name, table last update time and table synchronization order; The synchronization order of tables is configured according to the association relationship between tables, and the associated tables are synchronized first; During synchronization, the updated data is incrementally read based on the table's update time field name and the last update time value; After the synchronization is completed, get the latest update time of the synchronization table and update the last update time field of the table.
4. The data collection method based on primary key mapping according to claim 1, Features: The synchronization table field table is used to record all field information of the synchronization table, including system name, table name, field name, whether the field is associated with the primary key of another table, and the table name of the associated table; During synchronization, the field information of the table to be synchronized is obtained according to the table name. When the field is the primary key field of the record-related table, the primary key mapping is modified during the synchronization process.
5. The data collection method based on primary key mapping according to claim 1, Features: The primary key mapping table is used to record the mapping information of the primary keys of the tables of the subsystem and the parent system during the synchronization process, including the system name, table name, primary key value of the parent system data and primary key value of the subsystem data; During synchronization, for the field values associated with the primary keys of other tables, the new primary key value is queried from the primary key mapping table based on the primary key value and the associated table name, and the field value is modified; When adding new data, obtain the parent system primary key and save it to the primary key mapping table. When updating or deleting data, perform corresponding operations based on the query parent system primary key value.
6. The data collection method based on primary key mapping according to claim 1, Features: The synchronization primary key table is used to record the primary key information of the currently synchronized table, including the table name and the primary key value; When synchronizing data, compare the primary key data of the synchronization table with the primary key data of the corresponding table in the synchronization primary key table, obtain the added and deleted data, and synchronize these two types of data separately.
7. A data collection device based on primary key mapping, Features: The method comprises a memory and a processor; the memory is used to store a computer program, and the processor is used to implement the method according to any one of claims 1 to 6 when executing the computer program.
8. A readable storage medium, Features: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Data synchronization method and device based on update time and primary key and medium
CN114741401A
Relational database synchronization method and a recording medium storing a program therefore
US6374262B1
