Data verification method, data verification system, electronic device and storage medium
By extracting the validation interface and performing validation on multiple fields, the problem of low efficiency in uploading Excel files was solved, achieving efficient and accurate data writing and validation.
Patent Information
- Application Number
- CN202210587389.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-26
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2042-05-26
AI Technical Summary
In existing technologies, the validation module needs to be rewritten for different Excel files before they can be uploaded to the database, resulting in low data writing efficiency.
By extracting the validation interface, the table structure definition of the target Excel file is obtained, and field empty validation, type validation, format validation, length validation, and uniqueness constraint validation are performed. Data is only uploaded when all validations pass.
It improves the efficiency of data writing and the accuracy of verification, reduces repetitive code writing, and enhances the flexibility and speed of data verification.
Smart Images

Figure CN114936227B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and particularly relates to a data verification method, a data verification system, an electronic device and a storage medium. BACKGROUND
[0002] At present, data uploaded by an Excel file table needs to be verified before being written into a database. Since the Excel file tables written in are different, the corresponding verification rules in the tables are also different, and each uploading function needs to re-write a new verification module, thereby reducing the work efficiency of data writing. SUMMARY
[0003] The main purpose of the embodiments of the present application is to provide a data verification method, a data verification system, an electronic device and a storage medium, which can improve the work efficiency of data writing.
[0004] To achieve the above purpose, a first aspect of the embodiments of the present application provides a data verification method, which comprises the following steps.
[0005] Obtaining a target Excel file to be verified, determining a table structure definition according to the target Excel file, wherein the table structure definition comprises a table name corresponding to the target Excel file and a plurality of field names corresponding to the table name;
[0006] Performing field verification on data corresponding to each field name in the target Excel file according to the table structure definition, wherein the field verification comprises one or more of the following verification items: field null verification, field type verification, field format verification, field length verification and field uniqueness constraint verification;
[0007] In a case where the results of all the verification items are verification passed, uploading the data in the target Excel file into a preset database.
[0008] In some embodiments, before the step of obtaining a target Excel file to be verified and determining a table structure definition according to the target Excel file, the method further comprises the following steps.
[0009] Obtaining an initial Excel file and a preset verification interface;
[0010] According to a parameter transmission rule pre-set in the verification interface, performing data transmission on corresponding data in the initial Excel file to obtain a target Excel file to be verified;
[0011] Performing field verification on the target Excel file by calling the verification interface.
[0012] In some embodiments, the check process of the field null check comprises:
[0013] According to the table name corresponding to the target Excel file, determine the field null setting information corresponding to each field name in the target Excel file;
[0014] According to the field null setting information, perform field null check on the data corresponding to each field name to obtain a field check result;
[0015] According to the field null setting information, perform field null check on the data corresponding to each field name to obtain a field check result;
[0016] When the field null setting information is that the to-be-checked data corresponding to the to-be-checked field name includes a null value, the field check result is obtained as a check pass;
[0017] Or,
[0018] When the field null setting information is that the to-be-checked data corresponding to the to-be-checked field name does not include a null value, and the to-be-checked field name includes a pre-set data default value, the field null check is performed on the to-be-checked data, when the to-be-checked data is a null value, the data default value is replaced to the to-be-checked data, and the field check result is obtained as a check pass;
[0019] When the to-be-checked data is not a null value, the field check result is obtained as a check pass;
[0020] Or,
[0021] When the field null setting information is that the to-be-checked data corresponding to the to-be-checked field name does not include a null value, and the to-be-checked field name does not include a pre-set data default value, the field null check is performed on the to-be-checked data, when the to-be-checked data is not a null value, the field check result is obtained as a check pass;
[0022] When the to-be-checked data is a null value, the field check result is obtained as a check fail.
[0023] In some embodiments, the check process of the field format check comprises:
[0024] According to the table structure definition, determine the data format corresponding to each field name;
[0025] According to the data format, perform field format check on the to-be-checked data corresponding to the to-be-checked field name to obtain a field format check result;
[0026] When the field format verification result is that the to-be-verified data does not match the corresponding data format, the to-be-verified data is format-converted according to the data format, and a data format conversion result is obtained;
[0027] When the data format conversion result is conversion failure, position information of the to-be-verified data in the target Excel file is obtained, and format error information corresponding to the to-be-verified data is generated according to the position information.
[0028] In some embodiments, after the above-mentioned when the field format verification result is that the to-be-verified data does not match the data format, the to-be-verified data is format-converted according to the data format, and a data format conversion result is obtained, the method further includes:
[0029] When the data format conversion result is conversion success, format conversion data corresponding to the to-be-verified data is obtained;
[0030] The to-be-verified data is updated according to the format conversion data.
[0031] In some embodiments, the verification process of the field uniqueness constraint verification includes:
[0032] The uniqueness constraint information corresponding to each field name is determined according to the table structure definition;
[0033] When the to-be-verified field name to be verified includes a uniqueness constraint, to-be-verified data corresponding to the to-be-verified field name is obtained;
[0034] The to-be-verified data and the data that has been verified in the to-be-verified field name are subjected to field uniqueness constraint verification, and a field uniqueness constraint verification result is obtained;
[0035] When the field uniqueness constraint verification result indicates that the to-be-verified data does not satisfy the uniqueness constraint, position information of the to-be-verified data in the target Excel file is obtained, and uniqueness constraint violation prompt information corresponding to the to-be-verified data is generated according to the position information.
[0036] In some embodiments, the method further includes:
[0037] In a case where the result of any one of the verification items is verification failure, position information of to-be-verified data to be verified in the target Excel file is obtained, and error prompt information of the to-be-verified data is generated according to the position information and the corresponding verification item.
[0038] To achieve the above-mentioned purpose, a second aspect of the embodiments of the present application proposes a data verification system, the system includes:
[0039] a table structure definition determination module, configured to obtain a target Excel file to be verified, and determine a table structure definition according to the target Excel file, the table structure definition comprising a table name corresponding to the target Excel file and a plurality of field names corresponding to the table name;
[0040] a field verification module, configured to perform field verification on data corresponding to each field name in the target Excel file according to the table structure definition, the field verification comprising one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification;
[0041] a data uploading module, configured to upload the data in the target Excel file to a preset database when the results of all the verification items are passed.
[0042] To achieve the above object, a third aspect of embodiments of the present application provides an electronic device, comprising:
[0043] at least one memory;
[0044] at least one processor;
[0045] at least one computer program;
[0046] The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to implement the data verification method of the first aspect.
[0047] To achieve the above object, a fourth aspect of embodiments of the present application provides a storage medium, which is a computer readable storage medium, and stores a computer program, the computer program being used to make a computer execute the data verification method of the first aspect.
[0048] The data verification method, system, electronic device, and storage medium proposed in this application obtain the target Excel file to be verified and determine the table structure definition based on the target Excel file. The table structure definition includes the table name and multiple field names corresponding to the table name. To improve the efficiency of data writing and the accuracy of data verification, field verification is performed on the data corresponding to each field name in the target Excel file according to the table structure definition. Field verification includes one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification. If all verification items pass, the data in the target Excel file is uploaded to a preset database. This application obtains the uploaded target Excel file to be verified by calling a verification interface and verifies the data in the target Excel file through multiple verification items, thereby improving the efficiency of data writing and the accuracy of data verification. Attached Figure Description
[0049] Figure 1 This is a first flowchart of the data verification method provided in the embodiments of this application;
[0050] Figure 2 This is a second flowchart of the data verification method provided in the embodiments of this application;
[0051] Figure 3 This is a flowchart of the field null check process provided in the embodiments of this application;
[0052] Figure 4 This is the first flowchart of the field format validation process provided in the embodiments of this application;
[0053] Figure 5 This is a second flowchart of the field format validation process provided in the embodiments of this application;
[0054] Figure 6 This is a flowchart of the field uniqueness constraint verification process provided in the embodiments of this application;
[0055] Figure 7 This is a schematic diagram of the structure of the data verification system provided in the embodiments of this application;
[0056] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0057] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not intended to limit the present application.
[0058] It should be noted that although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described can be performed in a manner different from the module division in the device or the order in the flowchart. The terms "first", "second", and the like in the specification and claims and the above-described drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the present application only and is not intended to limit the present application.
[0060] At present, the data uploaded by the Excel file table needs to be checked before being written into the database. Since the Excel file tables written are different, the corresponding checking rules in the tables are also different, and a new checking module needs to be re-written for each uploading function, which reduces the work efficiency of data writing.
[0061] Based on this, the embodiments of the present application provide a data checking method, a data checking system, an electronic device and a storage medium, which can improve the work efficiency of data writing and the accuracy of data checking.
[0062] The data checking method, the data checking system, the electronic device and the storage medium provided by the embodiments of the present application are specifically described by the following embodiments. First, the data checking method in the embodiments of the present application is described.
[0063] The data checking method provided by the embodiments of the present application can be applied in a terminal, can be applied in a server end, and can also be software running in the terminal or the server end. In some embodiments, the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, etc.; the server end can be configured as an independent physical server, can be configured as a server cluster or a distributed system composed of multiple physical servers, can also be configured as a cloud server providing basic cloud computing services such as cloud service, cloud database, cloud computing, cloud function, cloud storage, network service, cloud communication, middleware service, domain name service, security service, CDN, and big data and artificial intelligence platform; and the software can be an application for implementing the data checking method, but is not limited to the above forms.
[0064] The application is operable with numerous general purpose or special purpose computer system environments or configurations. Examples of well-known computing systems, environments, and / or configurations that can be suitable for use with the application include personal computers, server computers, handheld or laptop devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application can be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and the like, that perform particular tasks or implement particular abstract data types. The application can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules can be located in both local and remote computer storage media including memory storage devices.
[0065] Please refer to Figure 1 , Figure 1 is an optional flowchart of the data verification method provided by the embodiments of the application, Figure 1 The method in the method can include but is not limited to including steps S110 to S130, and the following will be described in detail. Figure 1 The three steps are described in detail.
[0066] Step S110, obtaining a target Excel file to be verified, determining a table structure definition according to the target Excel file, the table structure definition including a table name corresponding to the target Excel file and a plurality of field names corresponding to the table name;
[0067] Step S120, performing field verification on data corresponding to each field name in the target Excel file according to the table structure definition, the field verification including one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification;
[0068] Step S130, in the case that the results of all the verification items are passed, uploading the data in the target Excel file to a preset database.
[0069] In step S110 to step S130 of some embodiments, the application obtains the target Excel file to be verified, and determines the table structure definition according to the target Excel file, wherein the table structure definition includes the table name corresponding to the target Excel file and the plurality of field names corresponding to the table name. In order to improve the work efficiency of data writing and the accuracy of data verification, the data corresponding to each field name in the target Excel file is subjected to field verification according to the table structure definition, wherein the field verification includes one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification. In the case where the results of all verification items are verified, the data in the target Excel file is uploaded to the preset database. The application can improve the work efficiency of data writing and the accuracy of data verification by calling the verification interface to obtain the uploaded target Excel file to be verified, and verifying the data in the target Excel file through multiple verification items.
[0070] In step S110 of some embodiments, in order to reduce the verification module to save development time, thereby improving the work efficiency of data writing, the upload data verification function is extracted into a verification interface, the target Excel file to be verified is obtained, and the table structure definition is determined according to the target Excel file. The table structure definition includes the table name corresponding to the target Excel file and the plurality of field names corresponding to the table name. The verification interface defines the interface name corresponding to the execution of different verification functions and the table structure definition of the target Excel file to be transmitted when the verification interface is designed in advance. Specifically, when the interface calling party calls the verification interface for data verification, the interface name corresponding to the target Excel file to be verified is called through the written program, and the parameter value corresponding to the target Excel file is transmitted according to the set table structure definition, wherein the parameter value includes the table name corresponding to the target Excel file to be stored, the plurality of field names corresponding to the table name, and the data corresponding to the field name, thereby realizing the data verification of the target Excel file.
[0071] It should be noted that the extraction of the verification interface is to extract the fixed part of the code corresponding to the same type of function to be implemented, and to convert the variable part corresponding to the implemented function into the parameter value to be transmitted, and to transmit the corresponding data when the verification interface is called. Therefore, the application embodiment can realize the function by calling the verification interface and transmitting the specific parameter value corresponding to the target Excel file, without repeatedly writing the specific code of this type of function, thereby improving the work efficiency of data writing.
[0072] In step S120 of some embodiments, in order to improve the accuracy of data verification, the data corresponding to each field name in the target Excel file is verified according to the table structure definition, and the field verification includes one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification. Specifically, the target Excel file to be verified uploaded by the verification interface is obtained, and the corresponding table structure definition is determined according to the target Excel file, and then the data corresponding to each field name in the target Excel file is sequentially verified by one or more verification items. When the data corresponding to the target Excel file is verified under the current verification item, the verification result is not passed, and the subsequent verification item is not verified, thereby effectively improving the work efficiency of data verification.
[0073] It should be noted that the verification order of the plurality of verification items is not specifically limited, and can be adjusted according to actual needs.
[0074] In step S130 of some embodiments, in the case where the results of all verification items are verified, the data in the target Excel file is uploaded to the preset database. Specifically, when the data corresponding to each field name in the target Excel file is verified by all verification items, the target Excel file is written into the preset database by the set program through the SQL statement. The database stores all field names corresponding to the table name in the written target Excel file, and all field value data corresponding to the field name. The data verification method can make data verification more easy, flexible and fast, thereby improving the work efficiency of data writing.
[0075] It should be noted that the data verification method of the embodiments of the present application can be applied to different business scenarios, including but not limited to project development, salary calculation and other business scenarios that require data verification of Excel files.
[0076] Please refer to Figure 2 , Figure 2 is another optional flowchart of the data verification method provided by some embodiments of the present application. In some embodiments of the present application, before step S110, the data verification method specifically further includes but is not limited to steps S210 to S230, which will be described in detail below. Figure 2 The three steps are described in detail.
[0077] Step S210, obtaining an initial Excel file and a preset verification interface;
[0078] In step S220, data in the initial Excel file is transmitted according to the preset parameter transmission rule in the verification interface, and a target Excel file to be verified is obtained.
[0079] In step S230, the target Excel file is verified by calling the verification interface.
[0080] In step S210 of some embodiments, the initial Excel file and the preset verification interface are first obtained. The initial Excel file is an original file for data verification, and the preset verification interface is an interface name defined when different verification functions are performed and a table structure definition of the target Excel file to be transmitted. Therefore, the function can be realized by calling the verification interface and transmitting the specific parameter value of the target Excel file, without repeatedly writing the specific code of the function, thereby improving the work efficiency of data writing.
[0081] In step S220 of some embodiments, in order to improve the work efficiency of data writing, the parameter transmission rule under different file verification types is set in the verification interface. When the file verification type corresponding to the initial Excel file is determined, the data in the initial Excel file is transmitted according to the parameter transmission rule corresponding to the file verification type, and a target Excel file to be verified is obtained. Therefore, the table structure definition corresponding to the target Excel file can be determined, and the table structure definition includes the table name corresponding to the target Excel file and the plurality of field names corresponding to the table name.
[0082] In step S230 of some embodiments, the function of data verification can be realized by calling the verification interface and transmitting the specific parameter value of the target Excel file. Specifically, when the interface calling party calls the verification interface for data verification, the data in the initial Excel file is transmitted according to the preset parameter transmission rule in the verification interface, and a target Excel file to be verified is obtained. The interface name corresponding to the target Excel file to be verified is called by the program, and the parameter value corresponding to the target Excel file is transmitted according to the set table structure definition, wherein the parameter value includes the table name corresponding to the target Excel file to be stored, the plurality of field names corresponding to the table name, and the data corresponding to the field name, thereby realizing the data verification of the target Excel file.
[0083] Please refer to Figure 3 , Figure 3 is a flowchart of a verification process of field null verification provided by some embodiments of the present application. In some embodiments of the present application, the verification process of field null verification specifically includes but is not limited to step S310 and step S320, which will be described below in combination withFigure 3 The two steps are described in detail.
[0084] In step S310, the field null setting information corresponding to each field name in the target Excel file is determined according to the table name corresponding to the target Excel file.
[0085] In step S320, the data corresponding to each field name is verified according to the field null setting information, and a field verification result is obtained.
[0086] In step S310 of some embodiments, in order to improve the work efficiency of data verification, the present application automatically determines the verification rule of the corresponding field under the generated table name from the preset database according to the table name corresponding to the target Excel file, specifically, according to the table name corresponding to the table structure definition of the target Excel file, that is, determines the field null setting information corresponding to each field name in the target Excel file to be verified.
[0087] In step S320 of some embodiments, the data corresponding to each field name is verified according to the field null setting information, and a field verification result is obtained. The definition of the field null setting information in the preset database includes three cases, which are: the data corresponding to the field name can be null, the data corresponding to the field name cannot be null and the field name includes a data default value, and the data corresponding to the field name cannot be null and the field name does not include a default value.
[0088] Specifically, when the field null setting information is that the to-be-verified data corresponding to the to-be-verified field name includes a null value, the data corresponding to the current field name uploaded by the target Excel file is verified, regardless of whether there is a field value, and the obtained field verification result is verified. Or, when the field null setting information is that the to-be-verified data corresponding to the to-be-verified field name does not include a null value, and the to-be-verified field name includes a preset data default value, the data corresponding to each field name is verified according to the field null setting information, then the to-be-verified data corresponding to the current to-be-verified field name uploaded by the target Excel file is verified, regardless of whether there is a field value, and the obtained field verification result is verified. At the same time, when the to-be-verified data corresponding to the to-be-verified field name is a null value, the field value at the to-be-verified data is filled with the data default value. Or, when the field null setting information is that the to-be-verified data corresponding to the to-be-verified field name does not include a null value, and the to-be-verified field name does not include a preset data default value, then the data corresponding to each field name is verified according to the field null setting information, when the to-be-verified data corresponding to the to-be-verified field name is not a null value, the obtained field verification result is verified. When the to-be-verified data corresponding to the to-be-verified field name is a null value, the obtained field verification result is not verified.
[0089] It should be noted that when the field null check is performed, the first row of data uploaded from the target Excel file is checked column by column, and the next row of data is checked after the first row of data is checked. Therefore, the position of the current data to be checked in the target Excel file can be obtained when the field null check is performed. It should be noted that the checking order of the field null check is not limited to the above-mentioned manner of checking column by column from the first row, and can be adjusted according to actual needs.
[0090] Please refer to Figure 4 , Figure 4 is a flowchart of a checking process of the field format check provided by some embodiments of the present application. In some embodiments of the present application, the checking process of the field format check specifically includes but is not limited to steps S410 to S440, which will be described below in combination with Figure 4 The four steps will be described in detail.
[0091] Step S410, determining the data format corresponding to each field name according to the table structure definition;
[0092] Step S420, performing field format check on the to-be-checked data corresponding to the to-be-checked field name according to the data format, to obtain a field format check result;
[0093] Step S430, when the field format check result is that the to-be-checked data does not match the corresponding data format, performing format conversion on the to-be-checked data according to the data format, to obtain a data format conversion result;
[0094] Step S440, when the data format conversion result is conversion failure, obtaining position information of the to-be-checked data in the target Excel file, and generating format error information corresponding to the to-be-checked data according to the position information.
[0095] In step S410 of some embodiments, in order to improve the work efficiency of data checking and writing, the data format corresponding to each field name is determined according to the table structure definition, that is, the data format corresponding to each field name is automatically determined and generated from a preset database according to the table name corresponding to the table structure definition of the target Excel file. It should be noted that when the database is constructed, the types of fields in the table and the data format stored in the fields under different table structure definitions have been set, so that data checking is performed according to the data format corresponding to each field name.
[0096] In steps S420 to S440 of some embodiments, the field format of the to-be-verified data corresponding to the to-be-verified field name is verified according to the data format, and a field format verification result is obtained. Specifically, the data corresponding to each field name in the target Excel file is obtained, and the column data stored for each uploaded field name is verified row by row, that is, the column data of the first row corresponding to each field name is verified, and it is verified whether the current to-be-verified data conforms to the corresponding data format. When the to-be-verified data conforms to the set data format, the data format verification result is that the verification is passed. When the to-be-verified data does not conform to the set data format, the to-be-verified data is automatically converted according to the set data format, and a data format conversion result is obtained. When the data format conversion result is conversion failure, the position information of the to-be-verified data in the target Excel file is obtained, and the format error information corresponding to the to-be-verified data is generated according to the position information.
[0097] In a specific embodiment, the field format verification is to judge whether the to-be-verified data corresponding to the to-be-verified field name conforms to the set data format. For example, the current to-be-verified field name corresponds to a date type field, and the corresponding data format is set as "mmmm-nn-dd", where m, n, and d represent integers from 0 to 9. It is judged whether the current to-be-verified data conforms to the set data format. When the to-be-verified data conforms to the set data format, the field data format verification result is that the verification is passed. When the to-be-verified data does not conform to the set data format, the to-be-verified data is automatically converted according to the set data format. When the data format conversion result is conversion failure, the position information of the to-be-verified data in the target Excel file is obtained, and the format error information corresponding to the to-be-verified data is generated according to the position information, such as "Data format error in row x column y!", where x and y represent the position coordinates of the to-be-verified data in the target Excel.
[0098] In a specific embodiment, the field type verification of the embodiments of the present application is to perform field type verification on the to-be-verified data corresponding to the to-be-verified field name according to the field type, and obtain a field type verification result. Specifically, the data corresponding to each field name in the target Excel file is obtained, and the column data stored for each uploaded field name is verified row by row, that is, the column data of the first row corresponding to each field name is verified, and it is verified whether the current to-be-verified data conforms to the corresponding field type. The verification process of the field type verification is to obtain the field type corresponding to the current to-be-verified field name, to judge whether the to-be-verified data corresponding to the to-be-verified field name conforms to the set field type, and when the to-be-verified data conforms to the set field type, the result of the field type verification is that the verification is passed; and when the to-be-verified data does not conform to the set field type, the result of the field type verification is that the verification is failed, and the prompt information of the field type error is generated according to the position information of the current to-be-verified data in the target Excel.
[0099] For example, when the set field type is that the to-be-verified data corresponding to the to-be-verified field name needs to keep two decimal places, the regular expression for which the to-be-verified data needs to be verified and matched is: “^(([1-9]{1}\d*)|([0]{1}))(\.(\d){0,2})?$”, wherein ^ represents the character start type, $ represents the character end type, [·] represents the metacharacter in the regular expression, which can match all characters in the square brackets, | represents the selector in the regular expression, which selects one of the data on both sides,. represents the metacharacter in the regular expression, which can match any character except the line feed character. Therefore, ([1-9]{1}\d*) represents that the number between 1 and 9 appears only once, that is, the first digit of the matched data is not 0 value, \d* represents that the number between 0 and 9 can appear any times, that is, 0 times or multiple times, 0 times means one digit integer, and multiple times means multiple digit integer; ([0]{1}) represents that the number 0 can appear only once, that is, the first digit of the value is 0 value, and there can be only one 0 value. When the to-be-verified data does not conform to the set field type, the prompt information “Data type error in the xxx row yyy column!” is returned, wherein x and y represent the position coordinates of the to-be-verified data in the target Excel.
[0100] Please refer to Figure 5 , Figure 5 is another optional flowchart of the verification process of the field format verification provided by some embodiments of the present application. In some embodiments of the present application, after step S430, the verification process of the field format verification can further include but is not limited to step S510 and step S520, which will be described in detail below. Figure 5 The two steps are described in detail.
[0101] Step S510, when the data format conversion result is conversion success, obtaining the format conversion data corresponding to the to-be-verified data;
[0102] Step S520, updating the to-be-verified data according to the format conversion data.
[0103] Specifically, in some embodiments, when the to-be-verified data does not conform to the set data format, the to-be-verified data is automatically subjected to format conversion according to the set data format, when the data format conversion result is conversion success, the format conversion data corresponding to the to-be-verified data is obtained, and the to-be-verified data is updated according to the format conversion data, then in the case that the results of all the verification items are all passed, the data in the target Excel file, i.e., the to-be-verified data updated at this time, is uploaded to the preset database.
[0104] In a specific embodiment, the field length verification of the embodiments of the present application is to perform field length verification on the to-be-verified data corresponding to the to-be-verified field name according to the set field length, and obtain the field length verification result. Specifically, the data corresponding to each field name in the target Excel file is obtained, and the column data stored for each uploaded field name is subjected to line-by-line verification, i.e., starting from the column data of the first row corresponding to each field name, the current to-be-verified data is verified to see whether it conforms to the set field length. The length bit number occupied by the to-be-verified data is compared with the field length bit number defined for the corresponding to-be-verified field, when the to-be-verified data does not exceed the set field length, the result of the field length verification is passed; and when the to-be-verified data exceeds the set field length, the result of the field length verification is failed, and the prompt information of the field length error is generated according to the position information of the current to-be-verified data in the target Excel, for example, the returned prompt information is "the data in the xxxth row yyyth column field is too long!", wherein x and y represent the position coordinates of the to-be-verified data in the target Excel.
[0105] Please refer to Figure 6 , Figure 6 is the flowchart of the verification process of the field uniqueness constraint verification provided by some embodiments of the present application. In some embodiments of the present application, the verification process of the field uniqueness constraint verification specifically includes but is not limited to steps S610 to S640, which will be described in detail below in combination with Figure 6 The four steps are described in detail.
[0106] Step S610, determining the uniqueness constraint information corresponding to each field name according to the table structure definition;
[0107] Step S620, when the to-be-verified field name to be verified includes uniqueness constraint, obtaining the to-be-verified data corresponding to the to-be-verified field name;
[0108] Step S630, performing a field uniqueness constraint check on the to-be-verified data and the verified data in the to-be-verified field name, to obtain a field uniqueness constraint check result.
[0109] Step S640, when the field uniqueness constraint check result indicates that the to-be-verified data does not satisfy the uniqueness constraint, obtaining position information of the to-be-verified data in the target Excel file, and generating violation-of-uniqueness-constraint prompt information corresponding to the to-be-verified data according to the position information.
[0110] Specifically, in steps S610 to S640 of some embodiments, in order to improve the accuracy of data verification, it is determined according to the table structure definition whether the uniqueness constraint information is set for each field name, that is, the uniqueness constraint information corresponding to each field name is determined. When the to-be-verified field name to be verified includes a uniqueness constraint, the to-be-verified data corresponding to the to-be-verified field name is obtained, and it is queried whether the current to-be-verified data already exists in the data that has been verified in the field name. When the field uniqueness constraint check result indicates that the to-be-verified data does not satisfy the uniqueness constraint, that is, it is indicated that the to-be-verified data does not exist in the data that has been verified in the current to-be-verified field name, the result of the field uniqueness constraint check is that the verification is passed. When the field uniqueness constraint check result indicates that the to-be-verified data does not satisfy the uniqueness constraint, that is, it is indicated that the to-be-verified data already exists in the data that has been verified in the current to-be-verified field name, the position information of the to-be-verified data in the target Excel file is obtained, and violation-of-uniqueness-constraint prompt information corresponding to the to-be-verified data is generated according to the position information. For example, when the field name corresponding to the target Excel file is stored by row, the returned prompt information is "the data in the aaa row violates the uniqueness constraint!", where a represents the row position information corresponding to the to-be-verified field name in the target Excel.
[0111] In a specific embodiment, for example, when there are three fields A, B, and C in the table T, and the uniqueness constraint is set for the three field names, and there is already data with the field values 1, 2, and 3 in the table T, then the to-be-verified data corresponding to the three field names in the newly added data in the subsequent table cannot appear the values 1, 2, and 3, otherwise it is equivalent to violating the uniqueness constraint.
[0112] In some embodiments, the data verification method of the present application further includes: in the case where the result of any one verification item is verification failure, obtaining position information of the to-be-verified data in the target Excel file, and generating error prompt information of the to-be-verified data according to the position information and the corresponding verification item.
[0113] Specifically, in order to quickly locate the abnormal data in the data verification, so as to improve the efficiency of data writing, in the case that the result of any one of the verification items is not passed, the position information of the to-be-verified data in the target Excel file is obtained, and the error prompt information of the to-be-verified data is generated according to the position information and the corresponding verification item. For example, when the to-be-verified data does not conform to the set data format, the returned error prompt information is "the data format error of the xxx row yyy column!"; when the to-be-verified data does not conform to the set field type, the returned error prompt information is "the data type error of the xxx row yyy column!"; when the to-be-verified data exceeds the set field length, the returned error prompt information is "the field length of the data of the xxx row yyy column is too long!", wherein x and y represent the position coordinates of the to-be-verified data in the target Excel. It should be noted that the generated error prompt information of the to-be-verified data can be flexibly adjusted according to the to-be-verified data in the target Excel file, the position information and the corresponding verification item.
[0114] The data verification method, the data verification system, the electronic device and the storage medium provided in the embodiments of the present application can obtain a target Excel file to be verified, and determine a table structure definition according to the target Excel file, wherein the table structure definition includes a table name corresponding to the target Excel file and a plurality of field names corresponding to the table name. In order to improve the working efficiency of data writing and the accuracy of data verification, the data corresponding to each field name in the target Excel file is subjected to field verification according to the table structure definition, wherein the field verification includes one or more of the following verification items: field null verification, field type verification, field format verification, field length verification, and field uniqueness constraint verification. In the case that the results of all the verification items are passed, the data in the target Excel file is uploaded to a preset database. The present application can improve the working efficiency of data writing and the accuracy of data verification by calling a verification interface to obtain the uploaded target Excel file to be verified, and verifying the data in the target Excel file through multiple verification items.
[0115] Please refer to Figure 7 The embodiments of the present application also provide a data verification system, which can implement the above-mentioned data verification method. The system includes a table structure definition determination module 710, a field verification module 720 and a data uploading module 730.
[0116] The table structure definition determination module 710 is configured to obtain a target Excel file to be verified, and determine a table structure definition according to the target Excel file, wherein the table structure definition includes a table name corresponding to the target Excel file and a plurality of field names corresponding to the table name.
[0117] The field checking module 720 is configured to perform field checking on data corresponding to each field name in the target Excel file according to the table structure definition, and the field checking includes one or more of the following checking items: field null checking, field type checking, field format checking, field length checking, and field uniqueness constraint checking.
[0118] The data uploading module 730 is configured to upload the data in the target Excel file to a preset database when the results of all the checking items are passed.
[0119] It should be noted that the data checking system provided in the embodiments of the present application is used to implement the data checking method described above, and the data checking system corresponds to the data checking method described above. For the specific processing process, please refer to the data checking method described above, which will not be described here.
[0120] The embodiments of the present application also provide an electronic device, which includes at least one memory, at least one processor, and at least one computer program stored in the at least one memory. The at least one processor executes the at least one computer program to implement the data checking method of any one of the above embodiments. The electronic device can be any intelligent terminal including a tablet computer, a vehicle-mounted computer, etc.
[0121] For details, please refer to Figure 8 , Figure 8 The hardware structure of the electronic device of another embodiment is illustrated, which includes:
[0122] The processor 810 can be implemented in the form of a general-purpose CPU (Central Processing Unit), a microprocessor, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits, and is used to execute related programs to implement the technical solutions provided in the embodiments of the present application.
[0123] The memory 820 can be implemented in the form of a ROM (ReadOnly Memory), a static storage device, a dynamic storage device, or a RAM (Random Access Memory). The memory 820 can store an operating system and other application programs. When the technical solutions provided in the embodiments of the present application are implemented by software or firmware, the related program codes are stored in the memory 820 and are called and executed by the processor 810 to implement the data checking method of the present application.
[0124] The input / output interface 830 is used to realize information input and output.
[0125] The communication interface 840 is configured to realize the communication interaction between the device and other devices. The communication can be realized in a wired manner (for example, a USB, a network cable, or the like) or in a wireless manner (for example, a mobile network, WIFI, Bluetooth, or the like).
[0126] The bus 850 is configured to transmit information between various components (for example, the processor 810, the memory 820, the input / output interface 830, and the communication interface 840) of the device.
[0127] The processor 810, the memory 820, the input / output interface 830, and the communication interface 840 are connected to each other through the bus 850 to realize the communication connection between the device.
[0128] The embodiments of the present application also provide a storage medium, which is a computer readable storage medium, and stores a computer program. The computer program is configured to enable a computer to execute the data verification method of any one of the above-described embodiments.
[0129] The memory is a non-transitory computer readable storage medium, and can be used to store a non-transitory software program and a non-transitory computer executable program. In addition, the memory can include a high-speed random access memory, and can also include a non-transitory memory, for example, at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory remotely arranged relative to the processor, and the remote memory can be connected to the processor through a network. Examples of the network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0130] The embodiments described in the embodiments of the present application are used to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those skilled in the art can know that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0131] Those skilled in the art can understand that, Figures 1 to 6 The technical solutions shown in the foregoing embodiments do not constitute a limitation on the embodiments of the present application, and can include more or fewer steps than those shown in the figures, or combine certain steps, or different steps.
[0132] The device embodiments described above are only schematic, and the units described as separate components can or can not be physically separate, that is, can be located in one place, or can be distributed on multiple network units. According to actual needs, part or all of the modules can be selected to realize the purpose of the embodiments of the present application.
[0133] Those skilled in the art can understand that all or some of the steps in the method disclosed above, the functional modules / units in the system and the device can be implemented by software, firmware, hardware or a combination thereof.
[0134] The terms "first", "second", "third", "fourth" and the like in the description of the application and in the claims, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the use of these terms herein is to be construed to cover a changeable order, arrangement, grouping, composition or structure. Also, the use of the terms first, second, third, fourth, and / or the like in the description of the application and in the claims can not necessarily indicate that the corresponding element will necessarily be executed in that order. Additionally, the terms "comprising", "having", "including", and "containing" and any variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, system, product or apparatus that comprises, has, includes or contains a list of elements is not necessarily limited to those elements, but can include other elements not expressly listed or inherent to such process, method, system, product or apparatus.
[0135] It should be understood that, in the present application, "at least one" means one or more, and "multiple" means two or more. "And / or" is used to describe the relationship between associated objects, which means that there can be three relationships, for example, "A and / or B" can mean that there are three cases: only A, only B, and A and B at the same time, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects. "At least one of the following" or similar expressions means any combination of these items, including single or multiple combinations. For example, at least one of a, b or c can mean a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be singular or plural.
[0136] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the above units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed objects can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0137] The units described as separate components above can or can not be physically separate, and the components shown as units can or can not be physical units, that is, can be located in one place, or can be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0138] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0139] If the integrated unit is realized in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical scheme of the present application or the part that contributes to the prior art or the whole or part of the technical scheme can be embodied in the form of a software product. The computer software product is stored in a storage medium, including multiple instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of each embodiment of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program storage media.
[0140] The preferred embodiments of the embodiments of the present application are described above with reference to the accompanying drawings, but this does not limit the scope of the rights of the embodiments of the present application. Any modifications, equivalent replacements and improvements made by those skilled in the art without departing from the scope and essence of the embodiments of the present application shall be within the scope of the rights of the embodiments of the present application.
Claims
1. A data verification method, characterized in that, The method includes: Obtain the initial Excel file and the pre-defined verification interface. The verification interface predefines the interface name corresponding to different verification functions and the table structure definition of the target Excel file to be passed in. The verification interface is used to extract the fixed part corresponding to the code that needs to be implemented for the same type of function, and convert the variable part corresponding to the implementation function into the parameter value to be passed in, and pass in the corresponding data when the verification interface is called. According to the parameter input rules preset in the verification interface, the corresponding data in the initial Excel file is input to obtain the target Excel file to be verified; The parameter values passed into the target Excel file are validated by calling the validation interface. Obtain the target Excel file to be verified, and determine the table structure definition based on the target Excel file. The table structure definition includes the table name corresponding to the target Excel file and multiple field names corresponding to the table name. According to the table structure definition, the data corresponding to each field name in the target Excel file is validated. The field validation includes one or more of the following validation items: field empty validation, field type validation, field format validation, field length validation, and field uniqueness constraint validation. If all the verification items pass the verification, the data in the target Excel file is uploaded to the preset database.
2. The data verification method according to claim 1, characterized in that, The validation process for the field null check includes: Based on the table name corresponding to the target Excel file, determine the field empty setting information corresponding to each field name in the target Excel file; Based on the field empty setting information, perform field empty validation on the data corresponding to each field name to obtain the field validation result; Specifically, the step of performing field null validation on the data corresponding to each field name based on the field null setting information to obtain the field validation result includes: When the field empty setting information is such that the data to be verified corresponding to the field name to be verified includes an empty value, the field verification result is that the verification is passed. or, When the field empty setting information is that the data to be verified corresponding to the field name to be verified does not include empty values, and the field name to be verified includes a preset data default value, the field empty verification is performed on the data to be verified. When the data to be verified is empty, the data default value is replaced in the data to be verified, and the field verification result is verified as passed. If the data to be verified is not empty, the field verification result is "verification passed". or, When the field empty setting information is that the data to be verified corresponding to the field name to be verified does not include empty values, and the field name to be verified does not include the preset default value, the field empty verification is performed on the data to be verified. When the data to be verified is not empty, the field verification result is verified as passed. When the data to be verified is empty, the verification result of the field is "verification failed".
3. The data verification method according to claim 1, characterized in that, The field format validation process includes: The data format corresponding to each field name is determined based on the table structure definition; Based on the data format, perform field format validation on the data corresponding to the field name to be validated, and obtain the field format validation result. When the field format validation result indicates that the data to be validated does not match the corresponding data format, the data to be validated is converted according to the data format to obtain the data format conversion result; If the data format conversion result is a conversion failure, obtain the location information of the data to be verified in the target Excel file, and generate the format error information corresponding to the data to be verified based on the location information.
4. The data verification method according to claim 3, characterized in that, After the field format validation result indicates that the data to be validated does not match the data format, and the data to be validated is format-converted according to the data format to obtain the data format conversion result, the method further includes: When the data format conversion result is successful, the format conversion data corresponding to the data to be verified is obtained; The data to be verified is updated based on the format conversion data.
5. The data verification method according to claim 1, characterized in that, The validation process for the field uniqueness constraint includes: The unique constraint information corresponding to each field name is determined based on the table structure definition; When the field name to be verified includes a unique constraint, obtain the data to be verified corresponding to the field name; Perform field uniqueness constraint verification on the data to be verified and the verified data in the field name to be verified to obtain the field uniqueness constraint verification result; When the field uniqueness constraint verification result indicates that the data to be verified does not meet the uniqueness constraint, the location information of the data to be verified in the target Excel file is obtained, and a violation of uniqueness constraint prompt message corresponding to the data to be verified is generated based on the location information.
6. The data verification method according to any one of claims 1 to 5, characterized in that, The method further includes: If any of the verification items fails, the location information of the data to be verified in the target Excel file is obtained, and an error message for the data to be verified is generated based on the location information and the corresponding verification item.
7. A data verification system, characterized in that, The system includes: The table structure definition determination module is used to obtain an initial Excel file and a pre-defined verification interface. The verification interface pre-defines the interface name corresponding to different verification functions and the table structure definition of the target Excel file to be passed in. The verification interface extracts the fixed parts of the code required to implement the same type of function, and converts the variable parts corresponding to the implementation function into parameter values to be passed in, which are then passed in when the verification interface is called. According to the pre-defined parameter passing rules in the verification interface, the corresponding data in the initial Excel file is passed in to obtain the target Excel file to be verified. The parameter values passed in the target Excel file are verified by calling the verification interface. The target Excel file to be verified is obtained, and the table structure definition is determined based on the target Excel file. The table structure definition includes the table name corresponding to the target Excel file and multiple field names corresponding to the table name. The field validation module is used to perform field validation on the data corresponding to each field name in the target Excel file according to the table structure definition. The field validation includes one or more of the following validation items: field empty validation, field type validation, field format validation, field length validation, and field uniqueness constraint validation. The data upload module is used to upload the data in the target Excel file to a preset database when all the verification items pass the verification.
8. An electronic device, characterized in that, include: At least one memory; At least one processor; At least one computer program; The at least one computer program is stored in the at least one memory, and the at least one processor executes the at least one computer program to perform: The data verification method as described in any one of claims 1 to 6.
9. A storage medium, said storage medium being a computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is used to cause the computer to execute: The data verification method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for importing Excel data into database, computer equipment and storage medium
CN108491510A
Data import method and system
CN111581210A