Logging method, device, equipment and medium for data synchronization between systems
By using preset string data types and relational databases for logging during data synchronization between systems, the problem of lack of complete logging for data synchronization between systems is solved, flexible and accurate logging is achieved, and the reliability and traceability of data synchronization are improved.
Patent Information
- Application Number
- CN202411669885.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2044-11-21
AI Technical Summary
In the existing technology, data synchronization between systems lacks a complete logging mechanism, which makes it difficult to quickly locate and solve problems during the data synchronization process, affecting the accuracy and reliability of data synchronization.
The preset string data type is used to obtain the request parameters in the synchronization request message, and the preset relational database is used for log recording. Through data conversion and conditional judgment, various information in the data synchronization process is recorded, including the number of successful and failed synchronizations, changes in important attributes, etc.
It enables flexible and accurate logging of data synchronization processes between systems, making it easier to troubleshoot abnormal information and synchronization failures, and improving the reliability and traceability of data synchronization.
Smart Images

Figure CN119474235B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of JAVA backend technology, and in particular to a log recording method, device, equipment and medium for data synchronization between systems. Background Art
[0002] In today's digital age, data synchronization between systems has become a critical link in data interaction and sharing. However, current data synchronization between systems suffers from shortcomings in logging. The lack of a comprehensive logging mechanism makes it difficult to quickly locate and resolve issues that arise during data synchronization, complicating subsequent data analysis and troubleshooting. Furthermore, it's difficult to ensure the accuracy and reliability of data synchronization.
[0003] To sum up, how to implement a complete logging mechanism during data synchronization is a technical problem that needs to be solved urgently. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a log recording method, apparatus, device, and medium for data synchronization between systems, which can implement a complete log recording mechanism during the data synchronization process. The specific solution is as follows:
[0005] In a first aspect, the present application provides a log recording method for data synchronization between systems, comprising:
[0006] Obtaining a request parameter in the current synchronization request message based on a preset string data type, and logging the request parameter based on a preset relational database to complete a first logging operation;
[0007] Performing data conversion on the request parameters based on a preset statement, and logging each piece of information to be synchronized in the obtained data conversion result using the preset relational database to complete a second logging operation;
[0008] During the data synchronization process, each piece of information to be synchronized is judged to determine whether it meets the preset data synchronization conditions to obtain a corresponding judgment result;
[0009] If the judgment result indicates that the condition is satisfied, after triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories and the obtained post-synchronization information and performing log recording to complete the third log recording operation;
[0010] If the judgment result indicates that the condition is not satisfied, synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and the synchronization failure information is logged using the preset relational database to complete a fourth log recording operation.
[0011] Optionally, obtaining a request parameter in the current synchronization request message based on a preset string data type, and logging the request parameter based on a preset relational database includes:
[0012] Get the request parameters in the current synchronization request message based on the string data type;
[0013] Generate log record information corresponding to the request parameter based on a first log table in a preset relational database to obtain a corresponding first system log;
[0014] The first system log includes a batch information synchronization identifier as a primary key, the request parameters, the synchronization type, the first log generation time, the number of batch information synchronization items, the number of successful information synchronization items, and the number of failed information synchronization items.
[0015] Optionally, the log recording method for data synchronization between the systems further includes:
[0016] After all the data synchronization operations are completed based on the judgment results corresponding to the respective pieces of information to be synchronized, the number of successfully executed data synchronization operations and the number of failed data synchronization operations are counted to obtain the corresponding number of successfully synchronized pieces of information and the number of failed synchronized pieces of information;
[0017] Determine the number of pieces of information to be synchronized in batches based on the number of pieces of information that have been successfully synchronized and the number of pieces of information that have failed to be synchronized;
[0018] The first system log in the first log table is updated using the number of successful information synchronization items, the number of failed information synchronization items, and the number of batch information synchronization items.
[0019] Optionally, performing data conversion on the request parameters based on a preset statement, and using the preset relational database to log each piece of information to be synchronized in the obtained data conversion result, includes:
[0020] Convert each piece of information to be synchronized in the request parameter into a preset object based on a preset statement, and determine a corresponding list to be synchronized according to each converted piece of information;
[0021] Based on the second log table in the preset relational database, log each of the converted information in the to-be-synchronized list one by one to obtain a second system log corresponding to each of the converted information;
[0022] The second system log includes corresponding identity information, second log generation time, corresponding character string information of the converted information, and the batch information synchronization identifier.
[0023] Optionally, after triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories and the obtained post-synchronization information and recording them in a log, including:
[0024] triggering a data synchronization operation for the corresponding information to be synchronized, and after the data synchronization operation is completed, analyzing changes in the important attribute information based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information to obtain a first analysis result;
[0025] Generating log record information corresponding to the first analysis result in a third log table in the preset relational database based on the first analysis result to obtain a corresponding third system log;
[0026] The third system log includes the identity information, the batch information synchronization identifier, the third log generation time, the target important attribute name, and the corresponding initial target important attribute value and updated target important attribute value.
[0027] Optionally, after triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories and the obtained post-synchronization information and recording them in a log, including:
[0028] After the corresponding data synchronization operation is completed, analyzing the changes of the information to be synchronized based on the preset relational database and the obtained post-synchronization information to obtain a second analysis result;
[0029] Generating log record information corresponding to the second analysis result in a fourth log table in the preset relational database based on the second analysis result to obtain a corresponding fourth system log;
[0030] The fourth system log includes the corresponding batch information synchronization identifier, the identity identifier information, and the initial information and changed information of the information to be synchronized.
[0031] Optionally, determining synchronization failure information corresponding to the information to be synchronized based on the judgment result, and logging the synchronization failure information using the preset relational database includes:
[0032] The synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and the fifth log table in the preset relational database is used to generate log record information corresponding to the synchronization failure information to obtain a corresponding fifth system log.
[0033] In a second aspect, the present application provides a log recording device for data synchronization between systems, including:
[0034] A first log recording module is used to obtain a request parameter in the current synchronization request message based on a preset string data type, and log the request parameter based on a preset relational database to complete a first log recording operation;
[0035] A second log recording module is used to perform data conversion on the request parameters based on a preset statement, and log each piece of information to be synchronized in the obtained data conversion result using the preset relational database to complete a second log recording operation;
[0036] The data judgment module is used to judge whether each piece of information to be synchronized meets the preset data synchronization conditions during the data synchronization process to obtain a corresponding judgment result;
[0037] A third log recording module is configured to, if the judgment result indicates that the condition is satisfied, analyze changes in the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information, and perform log recording to complete a third log recording operation after triggering and completing the data synchronization operation of the corresponding information to be synchronized;
[0038] The fourth log recording module is used to determine the synchronization failure information of the corresponding information to be synchronized based on the judgment result if the judgment result shows that it is not satisfied, and use the preset relational database to log the synchronization failure information to complete the fourth log recording operation.
[0039] In a third aspect, the present application provides an electronic device, comprising:
[0040] Memory, used to store computer programs;
[0041] The processor is used to execute the computer program to implement the aforementioned log recording method for data synchronization between systems.
[0042] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the log recording method for data synchronization between the aforementioned systems is implemented.
[0043] In this application, the request parameters in the current synchronization request message are obtained based on the preset string data type, and the request parameters are logged based on the preset relational database to complete the first log recording operation; the request parameters are converted based on the preset statement, and the preset relational database is used to log each piece of information to be synchronized in the obtained data conversion result to complete the second log recording operation; in the process of data synchronization, each piece of information to be synchronized is judged to see whether it meets the preset data synchronization condition to obtain the corresponding judgment result; if the judgment result shows that it meets the condition, then after triggering and completing the data synchronization operation of the corresponding information to be synchronized, the important attribute information and the change of the information to be synchronized are analyzed based on the preset relational database, the preset important attribute category and the obtained post-synchronization information and log it to complete the third log recording operation; if the judgment result shows that it does not meet the condition, then the synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and the synchronization failure information is logged using the preset relational database to complete the fourth log recording operation. As can be seen from the above, this application obtains the request parameters in the synchronization request message and uses the preset relational database for log recording. After the request parameter data is converted, the information to be synchronized in the data conversion result is logged. During the data synchronization process, it is determined whether the information to be synchronized meets the conditions. If it does, the synchronization operation is completed and the changes in important attributes are analyzed and logged. If it does not meet the conditions, the synchronization failure information is determined and logged. In this way, this application flexibly and accurately records the complete changes during the data synchronization process between systems, making it convenient to investigate abnormal information during the data synchronization process, the cause of synchronization failure, and changes in important attribute information. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0045] Figure 1 This is a flow chart of a log recording method for data synchronization between systems disclosed in this application;
[0046] Figure 2 This is a log recording flow chart for synchronizing user data disclosed in this application;
[0047] Figure 3 This is a schematic diagram of the structure of a log recording device for data synchronization between systems disclosed in this application;
[0048] Figure 4 This is a structural diagram of a log recording device for data synchronization between systems disclosed in this application. DETAILED DESCRIPTION
[0049] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0050] Currently, data synchronization between systems has shortcomings in logging. The lack of a comprehensive logging mechanism makes it difficult to quickly locate and resolve issues that arise during data synchronization, complicating subsequent data analysis and troubleshooting. This also makes it difficult to ensure the accuracy and reliability of data synchronization. To address this, this application provides a logging solution for data synchronization between systems, enabling a comprehensive logging mechanism during data synchronization.
[0051] See also Figure 1 As shown, an embodiment of the present invention discloses a log recording method for data synchronization between systems, including:
[0052] Step S11: obtaining request parameters in the current synchronization request message based on a preset character string data type, and logging the request parameters based on a preset relational database to complete a first logging operation.
[0053] In this embodiment, it is necessary to obtain the request parameters in the current synchronization request message based on the string data type. In the data synchronization scenario, the request parameters are the relevant information sent to the server to clarify the specific operation and the data involved when performing data synchronization related operations. It can be understood that in the data synchronization process, the formats of the request parameters may vary. Obtaining the request parameters with the string data type can completely save the synchronization request message. Among them, the request parameter message is generally JSON (JavaScript Object Notation) array format data. If the request parameters are not received as a string data type, but are directly parsed into a specific data structure, some additional information may be lost. Because in this direct parsing process, only the properties defined in the object can be received, while using the string type to receive can save the complete request message, including those non-standard properties that may be needed in subsequent analysis.
[0054] It should be noted that after obtaining the request parameters, log record information corresponding to the request parameters is generated based on a first log table in a preset relational database to obtain a corresponding first system log. In this embodiment, the preset relational database may be a MySQL (My Structured Query Language, a relational database management system) database. MySQL databases are capable of efficiently storing and managing large amounts of log data and can provide reliable support for log recording during data synchronization. The first system log includes a batch information synchronization identifier (primary key), the request parameters, the current synchronization type, the time the first record was generated, the number of batch information synchronized, the number of successfully synchronized information, and the number of failed synchronizations.
[0055] Specifically, in this embodiment, the batch synchronization identifier, serving as the primary key, is unique and clearly distinguishes different batches of data synchronization operations, enabling quick and accurate location and retrieval of synchronization records for a specific batch within a large volume of system logs. The synchronization type helps administrators understand the purpose of the data synchronization operation, including but not limited to addition, update, and deletion. The first record time provides a temporal reference for the data synchronization process. The number of batch synchronization entries is the sum of the number of successful synchronization entries and the number of failed synchronization entries. These two numbers are key indicators for measuring the quality and effectiveness of synchronization operations. They directly reflect the execution status of the synchronization task and are crucial for promptly identifying and resolving issues during the synchronization process.
[0056] Step S12: performing data conversion on the request parameters based on a preset statement, and using the preset relational database to log each piece of information to be synchronized in the obtained data conversion result, so as to complete a second logging operation.
[0057] In this embodiment, each piece of information to be synchronized in the request parameters is converted into a preset object based on a preset statement, and a corresponding list to be synchronized is determined based on the converted information. The preset object can be a specific data structure defined based on system design and business requirements. The preset object can store various attribute information in a structured manner. For example, if the information to be synchronized is user data, the preset object may include attributes such as the user ID (identity document), username, and age, facilitating subsequent operations and management.
[0058] After determining the list to be synchronized, each piece of converted information in the list to be synchronized is logged one by one based on a second log table in a preset relational database to obtain a second system log corresponding to each piece of converted information; wherein the second system log includes corresponding identity information, the time when the second record was generated, the string information corresponding to the converted information, and the batch information synchronization identifier. Specifically, the identity information can be a code used to uniquely identify each piece of information to be synchronized; the string information of the converted information stores the detailed content of the converted information in string form, making it convenient to directly view the specific content of the converted information when there is a specific need;
[0059] Step S13: During the data synchronization process, it is determined whether each piece of information to be synchronized meets a preset data synchronization condition to obtain a corresponding determination result.
[0060] In this embodiment, a conditional judgment is performed on each piece of information to be synchronized to determine whether data synchronization can be performed on each piece of information to be synchronized. For example, the presence of identity information, the lack of necessary information in the request parameters, and the compliance of the format of certain request parameters can all be used as preset data synchronization conditions.
[0061] Step S14: If the judgment result indicates that it is satisfied, after triggering and completing the corresponding data synchronization operation of the information to be synchronized, the important attribute information and the changes of the information to be synchronized are analyzed based on the preset relational database, the preset important attribute category and the obtained post-synchronization information, and log records are performed to complete the third log recording operation.
[0062] In this embodiment, it is necessary to analyze changes to important attribute information. Therefore, if each piece of information to be synchronized meets the preset data synchronization conditions, a data synchronization operation for the corresponding information to be synchronized is triggered. After the data synchronization operation is completed, the changes to the important attribute information are analyzed based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information to obtain a first analysis result. The preset important attribute categories are pre-set during the data synchronization process between systems based on business needs, data characteristics, and key factors in system operation. They are used to identify and distinguish attribute categories with significant significance and influence.
[0063] After obtaining the first analysis result, log record information corresponding to the first analysis result is generated in the third log table in the preset relational database based on the first analysis result to obtain the corresponding third system log; wherein, the third system log includes identity identification information, batch information synchronization identification, third log generation time, target important attribute name, and corresponding initial target important attribute value and updated target important attribute value. Among them, recording the initial target important attribute value and updated target important attribute value of the target important attribute in the third system log can clearly present the changes of the target important attribute during the data synchronization process, which is convenient for subsequent data comparison and analysis. For example, in business data synchronization, you can intuitively understand the changes before and after a key indicator, which helps to evaluate the impact of data synchronization on the business.
[0064] In this embodiment, a comprehensive analysis of all changes to the information to be synchronized is also required. Therefore, if each piece of information to be synchronized meets the preset data synchronization conditions, a data synchronization operation is triggered for the corresponding information to be synchronized. After the data synchronization operation is completed, the changes to the information to be synchronized are analyzed based on the preset relational database and the obtained post-synchronization information to obtain a second analysis result. In other words, a comprehensive comparison is performed on the entire information to be synchronized based on the preset relational database and the obtained post-synchronization information to determine all changes that occurred during the data synchronization process. This change analysis not only covers important attributes but also includes other information that may affect data integrity and consistency. This comprehensive analysis results in the second analysis result.
[0065] After obtaining the second analysis result, log record information corresponding to the second analysis result is generated in a fourth log table in a preset relational database based on the second analysis result to obtain a corresponding fourth system log; wherein, the fourth system log includes the corresponding batch information synchronization identifier, the identity identification information, and the initial information and changed information of the information to be synchronized.
[0066] The functions of the batch synchronization flag and identity information are as described above. The initial information of the information to be synchronized records the original state of the data before synchronization, and the modified information details the final state of the data after synchronization. This complete recording method can fully record the data change process.
[0067] Step S15: If the judgment result indicates that the condition is not satisfied, the synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and the synchronization failure information is logged using the preset relational database to complete the fourth log recording operation.
[0068] In this embodiment, if a piece of information to be synchronized does not meet the preset data synchronization conditions, synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and log record information corresponding to the synchronization failure information is generated using the fifth log table in the preset relational database to obtain the corresponding fifth system log. The preset data synchronization conditions and synchronization failure information are closely linked. For example, the absence of identity information, the lack of necessary information in the request parameters, and the format of certain request parameters that do not meet the requirements can all be used as synchronization failure information. Recording synchronization failure information in the fifth log table is of great guiding significance for subsequent analysis of the root cause of the problem and the development of solutions. Administrators can make targeted adjustments and corrections to the data to be synchronized based on the synchronization failure information to improve the success rate of data synchronization.
[0069] In this embodiment, in order to count and feedback the results of batch data synchronization and monitor and manage the execution of data synchronization operations from a holistic perspective, after completing all the data synchronization operations based on the judgment results corresponding to each piece of information to be synchronized, the number of successful data synchronization operations and the number of failed data synchronization operations can be counted to obtain the corresponding number of successful information synchronizations and the number of failed information synchronizations.
[0070] Specifically, in this embodiment, the number of successful and failed data synchronization operations must first be counted to obtain the corresponding number of successful and failed information synchronizations. The number of batch synchronizations is then determined based on the number of successful and failed information synchronizations. Finally, the first system log in the first log table is updated using the number of successful information synchronizations, the number of failed information synchronizations, and the number of batch synchronizations. Specifically, the updated first system log can display the overall status of this batch synchronization, which not only facilitates subsequent tracing and analysis of the data synchronization process, but also provides system administrators with timely and accurate information so that administrators can make corresponding decisions based on the data synchronization results, such as troubleshooting and repairing failed synchronization operations.
[0071] As can be seen from the above, this application obtains the request parameters in the synchronization request message and uses a preset relational database for log recording. After the request parameter data is converted, the information to be synchronized in the data conversion result is logged. During the data synchronization process, it is determined whether the information to be synchronized meets the conditions. If it meets the conditions, the important attribute changes are analyzed after the synchronization operation is completed and logged. If it does not meet the conditions, the synchronization failure information is determined and logged. In this way, this application flexibly and accurately records the complete changes in the data synchronization process between systems, which is convenient for troubleshooting abnormal information in the data synchronization process, the cause of synchronization failure, and changes in important attribute information.
[0072] The following combination Figure 2 As shown, taking synchronization of user data as an example, the technical solution of the embodiment of the present application is specifically described.
[0073] In this example, we first need to obtain the request parameters in the current synchronization request message. To speed up data synchronization, data synchronization is performed in batches. The interface provider generally provides three interfaces: a batch add user interface, a batch update user interface, and a batch delete user interface. The specific code snippet can be as follows:
[0074] @PostMapping(" / addUserList")
[0075] public ResponseBean addUserList(@RequestBody String param){
[0076] ResponseBean responseBean = syncUserService.addUserList(param);
[0077] return responseBean;
[0078] }
[0079] @PostMapping(" / updateUserList")
[0080] public ResponseBean updateUserList(@RequestBody String param){
[0081] ResponseBean responseBean = syncUserService.updateUserList(param);
[0082] return responseBean;
[0083] }
[0084] @PostMapping(" / deleteUserList")
[0085] public ResponseBean deleteUserList(@RequestBody String param){
[0086] ResponseBean responseBean = syncUserService.deleteUserList(param);
[0087] return responseBean;
[0088] }
[0089] In this embodiment, after obtaining the request parameters, the request parameters need to be recorded in the first log table, that is, the batch data request parameter log table sync_data_batch_log. This table mainly stores the following information: the randomly generated serial number batch_id (i.e., batch information synchronization identifier) as the primary key, the request parameter content (i.e., request parameters), the current synchronization type, the time when the log was created (i.e., the first log generation time), the number of batch data synchronizations (i.e., the number of information batch synchronizations), the number of successful data synchronizations (i.e., the number of successful information synchronizations), and the number of failed data synchronizations (i.e., the number of failed information synchronizations). Among them, the current synchronization type can include adding, updating, and deleting, and if the amount of request parameter data is relatively large, it can be stored in text. The specific code segment can be as follows:
[0090] SyncBatchBean syncBatchBean = new SyncBatchBean();
[0091] syncBatchBean.setId(batchId);
[0092] syncBatchBean.setContent(param);
[0093] syncBatchBean.setType(type);
[0094] syncBatchBean.setErrorType(0);
[0095] syncBatchMapper.insertSyncBatch(syncBatchBean);
[0096] In this embodiment, next, each piece of user information in the request parameter is converted into a UserBean object to obtain a user list userList containing multiple UserBean objects. By traversing the user list userList, the converted information is recorded one by one in the second log table, that is, the single record log table sync_data_single_log. The information saved in the sync_data_single_log table includes: user code (that is, identity information), string information of the converted information, batch information id (that is, batch information synchronization identifier), time of creating the log (that is, second log generation time) and other information. It should be emphasized that when adding data to the single record log table, exception handling should be added to ensure that the exception of a single piece of data does not affect the processing of other data. The specific code segment can be shown as follows:
[0097] List <userbeanbean>userList = JSONArray.parseArray(param,UserBeanBean.class);
[0098] for(UserBean userBean : userList){
[0099] try{
[0100] SyncSingleRecordBean syncSingleRecordBean = new SyncSingleRecordBean();
[0101] syncSingleRecordBean.setId(id);
[0102] syncSingleRecordBean.setType(type);
[0103] syncSingleRecordBean.setBatchId(batchId);
[0104] syncSingleRecordBean.setUserCode(userBean.getUserCode());
[0105] syncSingleRecordBean.setContent(JSON.toJSONString(userBean));
[0106] syncSingleRecordMapper.insertSyncSingleRecord(syncSingleRecordBean);
[0107] }catch (Exception e) {
[0108] log.error(e);
[0109] / / Other processing
[0110] …
[0111] }
[0112] }
[0113] Taking the update interface as an example, write the updateUser method to update the user information to the system's business table user table. The specific code segment can be as follows:
[0114] for(UserBean userBean : userList){
[0115] ResponseBean responseBean = null;
[0116] try{
[0117] responseBean = updateUser(userBean);
[0118] }catch (Exception e){
[0119] log.error("Failed to update user information", e);
[0120] try{
[0121] SyncErrorLogBean logBean = new SyncErrorLogBean();
[0122] logBean.setId(UUID.randomUUID().toString());
[0123] logBean.setUserCode(userBean.getUserCode());
[0124] logBean.setSyncType(syncType);
[0125] logBean.setContent(JSON.toJSONString(userBean));
[0126] logBean.setBatchId(batchId);
[0127] logBean.setErrorMsg(errorMsg);
[0128] syncErrorLogMapper.addSyncErrorLog(logBean);
[0129] }catch (Exception e) {
[0130] log.error("failed log error for saving synchronized users", e);
[0131] }
[0132] continue;
[0133] }
[0134] }
[0135] In this embodiment, during the data synchronization process, the data will be checked to see if it meets the requirements. For example, if the user code is used to query whether the user table contains the user, an exception will be thrown if the user does not exist. The exception information will clearly state that the user corresponding to the user code does not exist, that required information is not filled in the parameters, or that some parameter formats do not meet the requirements. These exceptions can be thrown and captured outside the call to the updateUser method. The exception information is saved to the fifth log table, that is, the sync_error_log table in the synchronization failure list. The specific code segment can be as follows:
[0136] @Transactional(rollbackFor = Exception.class, propagation =Propagation.REQUIRES_NEW)
[0137] public ResponseBean updateUser(UserBean newUserBean){
[0138] / / Get the original user information
[0139] UserBean oldUserBean = userMapper.getUserByUserCode(newUserBean.getUserCode());
[0140] / / Other processing ......
[0142] / / Data verification for newUserBean
[0143] checkParam(newUserBean);
[0144] / / After passing the parameter verification, update the data of the business table
[0145] userMapper.update(newUserBean);
[0146] / / Save the value changes of important attributes and report errors
[0147] addAttrChanged(newUserBean, oldUserBean);
[0148] / / Save complete record information before and after the change
[0149] addRecordChanged(newUserBean, oldUserBean);
[0150] / / Other processing ......
[0152] }
[0153] public void checkParam(UserBean userBean){
[0154] List <string>errorList = new ArrayList<>();
[0155] if(StringUtils.isEmpty(userBean.getUserName())){
[0156] errorList.add("User name cannot be empty");
[0157] }
[0158] / / Other checks ......
[0160] if(!CollectionUtils.isEmpty(errorList)){
[0161] / / Throw the checked problem as an exception
[0162] throw new RuntimeException(listToStr(errorList));
[0163] }
[0164] }
[0165] It is understandable that in this embodiment, after the data verification is passed, it is sometimes necessary to log the changes of important information. For example, when updating a user's information, the user's title in the original user table is a, and it becomes b when updating. When comparing the value of the attribute, it is found that there is a change. At this time, it is necessary to make a record in the third log table, that is, the important attribute value change log table sync_attr_changed_log. The important attribute information change log table mainly contains the following information: user code (that is, identity identification information), the name of the important attribute (that is, the target important attribute name), the original value of the important attribute (that is, the initial target important attribute value), the synchronized value of the important attribute (that is, the updated target important attribute value), batch_id (that is, batch information synchronization identifier), the time when the log was created (that is, the third log generation time), etc. The specific code segment can be shown as follows:
[0166] public void addAttrChanged(UserBean newUserBean, UserBeanoldUserBean){
[0167] / / Compare job titles
[0168] if(!StringUtils.equals(oldUserBean.getTitle(),newUserBean.getTitle())){
[0169] SyncAttrChangedBean syncAttrChangedBean = new SyncAttrChangedBean();
[0170] syncAttrChangedBean.setId(id);
[0171] syncAttrChangedBean.setUserCode(oldUserBean.getUserCode());
[0172] syncAttrChangedBean.setBatchId(batchId);
[0173] syncAttrChangedBean.setAttrKey("title");
[0174] syncAttrChangedBean.setAttrName("Job Title");
[0175] syncAttrChangedBean.setAttrValueOld(oldUserBean.getTitle());
[0176] syncAttrChangedBean.setAttrValueNew(newUserBean.getTitle());
[0177] syncAttrChangedMapper.insertSyncAttrChanged(attrChangedBean);
[0178] }
[0179] / / Compare other attributes ......
[0181] }
[0182] It should be noted that in this embodiment, the important attribute value change log table records only critical attribute information. To fully record user information before and after synchronization, a fourth log table, the user record change log table sync_record_changed_log, is required to record the complete content before and after synchronization. The main fields of this table include: batch_id (i.e., batch information synchronization identifier), user code (i.e., identity information), all information recorded by the user before synchronization (i.e., the initial information of the information to be synchronized), and all information recorded by the user after synchronization (i.e., the changed information of the information to be synchronized). The specific code segment can be shown as follows:
[0183] public void addRecordChanged(UserBean newUserBean, UserBeanoldUserBean){
[0184] SyncRecordChangedBean bean = new SyncRecordChangedBean();
[0185] bean.setId(id);
[0186] bean.setUserCode(userBean.getUserCode());
[0187] bean.setOldContent(JSON.toJSONString(oldUserBean));
[0188] bean.setNewContent(JSON.toJSONString(newUserBean));
[0189] bean.setType(type);
[0190] bean.setBatchId(batchId);
[0191] syncRecordChangedMapper.insertSyncRecordChanged(bean);
[0192] }
[0193] It's important to emphasize that during data synchronization, exception handling is implemented for each data entry without affecting the processing of other data in the batch. Exception information can also be assembled for problematic data and returned to the caller after processing, allowing them to record processing results and troubleshoot issues. Finally, the number of successful and failed data synchronization records must be counted to update the batch data request parameter log table, sync_data_batch_log. As can be seen above, all logs are recorded during user data synchronization.
[0194] Accordingly, see Figure 3 As shown, the embodiment of the present application also provides a log recording device for data synchronization between systems, including:
[0195] A first log recording module 11 is configured to obtain a request parameter in the current synchronization request message based on a preset string data type, and log the request parameter based on a preset relational database to complete a first log recording operation;
[0196] The second log recording module 12 is used to perform data conversion on the request parameters based on a preset statement, and log each piece of information to be synchronized in the obtained data conversion result using the preset relational database to complete a second log recording operation;
[0197] The data judgment module 13 is used to judge whether each piece of information to be synchronized meets the preset data synchronization conditions during the data synchronization process to obtain a corresponding judgment result;
[0198] A third log recording module 14 is configured to, if the judgment result indicates that the condition is satisfied, analyze changes in the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information, and perform log recording to complete a third log recording operation after triggering and completing the corresponding data synchronization operation of the information to be synchronized;
[0199] The fourth log recording module 15 is used to determine the synchronization failure information of the corresponding information to be synchronized based on the judgment result if the judgment result shows that it is not satisfied, and use the preset relational database to log the synchronization failure information to complete the fourth log recording operation.
[0200] As can be seen from the above, this application obtains the request parameters in the synchronization request message and uses a preset relational database for log recording. After the request parameter data is converted, the information to be synchronized in the data conversion result is logged. During the data synchronization process, it is determined whether the information to be synchronized meets the conditions. If it meets the conditions, the important attribute changes are analyzed after the synchronization operation is completed and logged. If it does not meet the conditions, the synchronization failure information is determined and logged. In this way, this application flexibly and accurately records the complete changes in the data synchronization process between systems, which is convenient for troubleshooting abnormal information in the data synchronization process, the cause of synchronization failure, and changes in important attribute information.
[0201] In a specific implementation, the first log recording module 11 may specifically include:
[0202] A parameter acquisition unit is used to obtain the request parameters in the current synchronization request message based on the string data type;
[0203] A first log generation unit is used to generate log record information corresponding to the request parameters based on a first log table in a preset relational database to obtain a corresponding first system log; wherein, the first system log includes a batch information synchronization identifier as a primary key, the request parameters, the type of this synchronization, the first log generation time, the number of information batch synchronization items, the number of information successful synchronization items, and the number of information synchronization failures.
[0204] In a specific embodiment, the log recording device for data synchronization between the systems may further include:
[0205] a number counting unit, configured to count the number of successful data synchronization operations and the number of failed data synchronization operations after all the data synchronization operations are completed based on the judgment results corresponding to the respective pieces of information to be synchronized, so as to obtain the corresponding number of successful information synchronizations and the number of failed information synchronizations;
[0206] A quantity determining unit, configured to determine the number of pieces of information to be synchronized in batches based on the number of pieces of information that were successfully synchronized and the number of pieces of information that failed to be synchronized;
[0207] The log updating unit is configured to update the first system log in the first log table by using the number of successful information synchronization entries, the number of failed information synchronization entries, and the number of batch information synchronization entries.
[0208] In a specific implementation, the second log recording module 12 may specifically include:
[0209] a list determination unit, configured to convert each piece of information to be synchronized in the request parameter into a preset object based on a preset statement, and determine a corresponding list to be synchronized according to each converted piece of information;
[0210] The second log generation unit is used to log each of the converted information in the list to be synchronized one by one based on the second log table in the preset relational database, so as to obtain a second system log corresponding to each of the converted information; wherein, the second system log includes corresponding identity information, second log generation time, corresponding character string information of the converted information and the batch information synchronization identifier.
[0211] In a specific implementation, the third log recording module 14 may specifically include:
[0212] an information analysis unit, configured to trigger a data synchronization operation corresponding to the information to be synchronized, and after the data synchronization operation is completed, analyze changes in the important attribute information based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information to obtain a first analysis result;
[0213] A third log generation unit is used to generate log record information corresponding to the first analysis result in a third log table in the preset relational database based on the first analysis result to obtain a corresponding third system log; wherein the third system log includes the identity information, the batch information synchronization identifier, the third log generation time, the target important attribute name, and the corresponding initial target important attribute value and the updated target important attribute value.
[0214] In a specific implementation, the third log recording module 14 may specifically include:
[0215] an information analysis unit, configured to analyze changes to the information to be synchronized based on the preset relational database and the obtained post-synchronization information after the corresponding data synchronization operation is completed, so as to obtain a second analysis result;
[0216] A fourth log generation unit is used to generate log record information corresponding to the second analysis result in a fourth log table in the preset relational database based on the second analysis result to obtain a corresponding fourth system log; wherein the fourth system log includes the corresponding batch information synchronization identifier, the identity identification information, and the initial information and changed information of the information to be synchronized.
[0217] In a specific implementation, the fourth log recording module 15 may specifically include:
[0218] The fifth log generating unit is used to determine the synchronization failure information of the corresponding information to be synchronized based on the judgment result, and use the fifth log table in the preset relational database to generate log record information corresponding to the synchronization failure information to obtain a corresponding fifth system log.
[0219] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be considered as any limitation on the scope of use of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the log recording method for data synchronization between systems disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0220] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0221] In addition, the memory 22 as a carrier for resource storage can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0222] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, and can be Windows Server, NetWare, Unix, Linux, etc. In addition to including a computer program capable of implementing the logging method for inter-system data synchronization performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include computer programs capable of performing other specific tasks.
[0223] Furthermore, this application discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the aforementioned method for logging data synchronization between systems. The specific steps of this method can be found in the corresponding contents disclosed in the aforementioned embodiments and will not be further described here.
[0224] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0225] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0226] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0227] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprise," "include," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a set of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not preclude the presence of additional identical elements in the process, method, article, or apparatus comprising the element.
[0228] The above is a detailed introduction to the technical solution provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.< / string> < / userbeanbean>
Claims
1. A log recording method for data synchronization between systems, characterized in that: include: Obtaining a request parameter in the current synchronization request message based on a preset string data type, and logging the request parameter based on a preset relational database to complete a first logging operation; Performing data conversion on the request parameters based on a preset statement, and logging each piece of information to be synchronized in the obtained data conversion result using the preset relational database to complete a second logging operation; During the data synchronization process, each piece of information to be synchronized is judged to determine whether it meets the preset data synchronization conditions to obtain a corresponding judgment result; If the judgment result indicates that the condition is satisfied, after triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories and the obtained post-synchronization information and performing log recording to complete the third log recording operation; If the judgment result indicates that the condition is not satisfied, determining synchronization failure information of the corresponding information to be synchronized based on the judgment result, and logging the synchronization failure information using the preset relational database to complete a fourth logging operation; Wherein, after triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute category and the obtained post-synchronization information and recording them in a log, including: triggering a data synchronization operation for the corresponding information to be synchronized, and after the data synchronization operation is completed, analyzing changes in the important attribute information based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information to obtain a first analysis result; Generating log record information corresponding to the first analysis result in a third log table in the preset relational database based on the first analysis result to obtain a corresponding third system log; The third system log includes identity information, batch information synchronization identifier, third log generation time, target important attribute name, and corresponding initial target important attribute value and updated target important attribute value; After triggering and completing the data synchronization operation of the corresponding information to be synchronized, analyzing the changes of the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories and the obtained post-synchronization information and recording them in a log, including: After the corresponding data synchronization operation is completed, analyzing the changes of the information to be synchronized based on the preset relational database and the obtained post-synchronization information to obtain a second analysis result; Generating log record information corresponding to the second analysis result in a fourth log table in the preset relational database based on the second analysis result to obtain a corresponding fourth system log; The fourth system log includes the corresponding batch information synchronization identifier, identity information, and the initial information and changed information of the information to be synchronized.
2. The log recording method for data synchronization between systems according to claim 1, characterized in that: The obtaining of request parameters in the current synchronization request message based on a preset string data type, and logging the request parameters based on a preset relational database, includes: Get the request parameters in the current synchronization request message based on the string data type; Generate log record information corresponding to the request parameter based on a first log table in a preset relational database to obtain a corresponding first system log; The first system log includes a batch information synchronization identifier as a primary key, the request parameters, the synchronization type, the first log generation time, the number of batch information synchronization items, the number of successful information synchronization items, and the number of failed information synchronization items.
3. The log recording method for data synchronization between systems according to claim 2, characterized in that: Also includes: After all the data synchronization operations are completed based on the judgment results corresponding to the respective pieces of information to be synchronized, the number of successfully executed data synchronization operations and the number of failed data synchronization operations are counted to obtain the corresponding number of successfully synchronized pieces of information and the number of failed synchronized pieces of information; Determine the number of pieces of information to be synchronized in batches based on the number of pieces of information that have been successfully synchronized and the number of pieces of information that have failed to be synchronized; The first system log in the first log table is updated using the number of successful information synchronization items, the number of failed information synchronization items, and the number of batch information synchronization items.
4. The log recording method for data synchronization between systems according to claim 2, characterized in that: The performing data conversion on the request parameters based on the preset statement, and using the preset relational database to log each piece of information to be synchronized in the obtained data conversion result, includes: Convert each piece of information to be synchronized in the request parameter into a preset object based on a preset statement, and determine a corresponding list to be synchronized according to each converted piece of information; Based on the second log table in the preset relational database, log each of the converted information in the to-be-synchronized list one by one to obtain a second system log corresponding to each of the converted information; The second system log includes corresponding identity information, second log generation time, corresponding character string information of the converted information, and the batch information synchronization identifier.
5. The log recording method for data synchronization between systems according to claim 1, characterized in that: The determining synchronization failure information corresponding to the information to be synchronized based on the judgment result, and logging the synchronization failure information using the preset relational database, includes: The synchronization failure information of the corresponding information to be synchronized is determined based on the judgment result, and the fifth log table in the preset relational database is used to generate log record information corresponding to the synchronization failure information to obtain a corresponding fifth system log.
6. A log recording device for data synchronization between systems, characterized in that: include: A first log recording module is used to obtain a request parameter in the current synchronization request message based on a preset string data type, and log the request parameter based on a preset relational database to complete a first log recording operation; A second log recording module is used to perform data conversion on the request parameters based on a preset statement, and log each piece of information to be synchronized in the obtained data conversion result using the preset relational database to complete a second log recording operation; The data judgment module is used to judge whether each piece of information to be synchronized meets the preset data synchronization conditions during the data synchronization process to obtain a corresponding judgment result; A third log recording module is configured to, if the judgment result indicates that the condition is satisfied, analyze changes in the important attribute information and the information to be synchronized based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information, and perform log recording to complete a third log recording operation after triggering and completing the data synchronization operation of the corresponding information to be synchronized; a fourth log recording module, configured to determine synchronization failure information of the corresponding information to be synchronized based on the judgment result if the judgment result indicates that the condition is not satisfied, and log the synchronization failure information using the preset relational database to complete a fourth log recording operation; The third log recording module includes: an information analysis unit, configured to trigger a data synchronization operation corresponding to the information to be synchronized, and after the data synchronization operation is completed, analyze changes in the important attribute information based on the preset relational database, the preset important attribute categories, and the obtained post-synchronization information to obtain a first analysis result; A third log generating unit is configured to generate log record information corresponding to the first analysis result in a third log table in the preset relational database based on the first analysis result, so as to obtain a corresponding third system log; wherein the third system log includes identity information, batch information synchronization identifier, third log generation time, target important attribute name, and corresponding initial target important attribute value and updated target important attribute value; The third logging module includes: The information analysis unit is further configured to analyze changes to the information to be synchronized based on the preset relational database and the obtained post-synchronization information after the corresponding data synchronization operation is completed, so as to obtain a second analysis result; A fourth log generation unit is used to generate log record information corresponding to the second analysis result in a fourth log table in the preset relational database based on the second analysis result to obtain a corresponding fourth system log; wherein the fourth system log includes a corresponding batch information synchronization identifier, identity identification information, and the initial information and changed information of the information to be synchronized.
7. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the log recording method for data synchronization between systems as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that Used to store computer programs; wherein, when the computer program is executed by a processor, it implements the log recording method for data synchronization between systems as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Database synchronization method, database synchronization equipment and readable storage medium
CN116932649A
Application infrastructure configuration based on annotated API schemas
US11237889B1