Data verification method and device, computer device, and storage medium
Patent Information
- Application Number
- CN202311354282.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-18
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2043-10-18
AI Technical Summary
其中一项为校验受科目影响字段是否满足于配置规则,其中,同一实体中需要校验的字段值非常多,并且配置项繁琐,校验规则也并不是单一存在;在该校验的过程中,将会使得系统中的代码十分冗余,代码可读性差,可扩展性弱,出现后期难于维护的问题;
[0007]一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述一种数据校验方法。
Smart Images

Figure CN117421313B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of data processing and financial technology, and in particular discloses a data verification method, apparatus, computer equipment, and storage medium. Background Technology
[0002] Currently, in the financial sector, the complete process of financial voucher creation involves a series of data processing steps after data is retrieved from the data retrieval table. After the data undergoes price and tax splitting and price and tax splitting verification, the data will go through the account entry matching stage. After the account matching is completed, the matched data needs to be re-verified for fields such as non-empty, business segment, currency, and OF segment value. One of the tasks is to verify whether the fields affected by the subject meet the configuration rules. In this case, there are many field values that need to be verified in the same entity, the configuration items are cumbersome, and the verification rules are not unique. This verification process will make the code in the system very redundant, with poor code readability, weak scalability, and problems that are difficult to maintain in the later stage. Therefore, those skilled in the art urgently need to find a new technical solution to address the aforementioned problems. Summary of the Invention
[0003] Therefore, it is necessary to provide a data verification method, apparatus, computer equipment, and storage medium to address the aforementioned technical problems, thereby improving the readability and scalability of code in the data verification system.
[0004] A data verification method, the method comprising: Obtain the data to be validated and the enumeration type with parameters; The check value in the parameterized enumeration type is used to verify whether it is equal to the first data value in the data to be checked; When the verification value is equal to the first data value, all the second data values are obtained from the data to be verified using the parameterized enumeration type, and each second data value is verified sequentially according to the preset verification logic to obtain the verification result.
[0005] A data verification device, the device comprising: The acquisition module is used to acquire the data to be verified and the enumeration type with parameters; The first verification module is used to verify whether the verification value in the parameterized enumeration type is equal to the first data value in the data to be verified. The second verification module is used to obtain all the second data values from the data to be verified using the parameterized enumeration type when the verification value is equal to the first data value, and to verify each of the second data values in sequence according to the preset verification logic to obtain the verification result.
[0006] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the aforementioned data verification method.
[0007] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned data verification method.
[0008] The aforementioned data verification method, apparatus, computer equipment, and storage medium, in the field of data processing, utilize a reflection mechanism that obtains the second data value corresponding to the data to be verified and a parameterized enumeration type to perform multiple judgments on the fields in the data to be verified. This enhances the readability and scalability of the code and facilitates subsequent code maintenance. Furthermore, by using a parameterized enumeration type, the intent of the code can be clearly indicated, enhancing its readability and maintainability. Moreover, the reflection mechanism eliminates the need for direct dependence on specific classes and methods, thus facilitating system expansion and upgrades. Attached Figure Description
[0009] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 This is a schematic diagram of an application environment for a data verification method according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating a data verification method according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a data verification device according to an embodiment of the present invention; Figure 4 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0011] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0012] The data verification method provided by this invention can be applied to, for example... Figure 1 In this application environment, the client communicates with the server via a network. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0013] In one embodiment, such as Figure 2 As shown, a data verification method is provided, which is applied to... Figure 1 Taking the server as an example, the following steps S10-S30 are used for illustration: S10, obtain the data to be verified and the enumeration type with parameters; Understandably, data requiring validation refers to fields that need to be verified. These fields are influenced by account categories. In financial data within the financial sector, fields can be related to business, currency, and numerical aspects. Furthermore, data requiring validation corresponds to field attributes, meaning it contains field values corresponding to those attributes. Field attributes can include validation values (system-sourced values), flag names, and validation field names. In Java programming, parameterized enumeration types are a basic data type, not a constructed data type. They are used to declare a set of named constants. When a variable has several possible values, it can be defined as an enumeration type, and the corresponding variable can be understood as a parameter. Parameterized enumeration types validate data through field attributes. Therefore, an enumeration type includes validation values (system-sourced values), flag names, validation field names, and default values. The data corresponding to these types are the parameters of the enumeration type. The aforementioned enumeration types can be extended according to specific scenarios, such as extracting field data belonging to the same time range.
[0014] S20, verify whether the verification value in the parameterized enumeration type is equal to the first data value in the data to be verified; Understandably, the parameters set in the enumeration type include a check value, which is the sysSource value. In this embodiment, the same field attribute is first found, and then the attribute values corresponding to the two field attributes are determined to be the same. That is, it is determined whether the check value in the enumeration type is equal to the first data value in the data to be checked. For example, if the sysSource value corresponding to the check value is A, and the sysSource value corresponding to the first data value is B, it can be determined that they are not equal. This embodiment uses a check value to verify whether the field corresponding to the data to be checked needs to be forcibly checked. If forced check is required, the result returned is true; otherwise, the result returned is false.
[0015] S30, when the verification value is equal to the first data value, all the second data values are obtained from the data to be verified using the parameterized enumeration type, and each second data value is verified in sequence according to the preset verification logic to obtain the verification result.
[0016] Understandably, the second data value refers to all the data that needs to be verified, including the field names and attribute values corresponding to the default values of the fields mentioned above. The preset verification logic is to sequentially judge whether the attribute values corresponding to the field names and default values meet the specified values. The verification result refers to the comprehensive result obtained after the judgment, such as the result of judging whether the default value in the data to be verified is empty and whether the field value is equal to the default value, and the result is true or false. Specifically, when the check value is equal to the first data value, the returned result is true. After obtaining this check result, the system uses the flag name configured by the enumeration type (flagName) and the value of the flag bit ("Y" or "N") determined from the configuration value after reflection. Based on the value of the flag bit, the system obtains the second data value from the data to be checked, and then checks the default value and the field value corresponding to the field value check field name in the second data value in turn to obtain the check result.
[0017] Using the complete financial voucher creation process in the financial field as an example, after the data undergoes price and tax splitting and price and tax splitting verification, the data will go through the account entry matching stage. After the account matching is completed, the matched data needs to be verified multiple times, including field non-empty, business segment, currency, OF segment value, etc. Specifically, firstly, it is checked whether the fields in the data to be verified need to be forcibly verified (checking whether the verification value in the enumerated type with parameters is equal to the first data value in the data to be verified). If not, the result is returned as true. Then, based on the return result of true, it continues to check whether the default value in the data to be verified is empty. If it is determined that the default value is empty, it checks whether the field value corresponding to the data to be verified is empty. If it is determined that the field value is not empty, it finally checks whether the default value and the field value are equal.
[0018] In the embodiments of steps S10 to S30, in the field of data processing, the problem of redundant code, poor readability, weak scalability, and difficulty in maintenance during data verification using conditional statements such as if-else or switch is addressed. Specifically, multiple judgments can be made on fields in the data to be verified by using JAVA reflection mechanism and parameterized enumeration types to obtain the second data value from the data to be verified. This enhances the readability and scalability of the code and facilitates its maintenance. At the same time, by using parameterized enumeration types, the intent of the code can be clearly indicated, enhancing its readability and maintainability. Furthermore, the reflection mechanism eliminates the need to directly depend on specific classes and methods, thus facilitating system expansion and upgrades.
[0019] Furthermore, before obtaining the parameterized enumeration type, the process also includes: Establish field attributes corresponding to the parameterized enumeration type, and define the attribute values corresponding to the field attributes respectively; the field attributes include verification value, flag name, verification field name and default value.
[0020] Understandably, the process of creating an enumeration type involves defining an ordered set by predefining identifiers corresponding to all field attribute values. The order of these field attribute values matches the order of the identifiers in the enumeration type specification. The form of the enumeration type is: (identifier 1, ..., identifier n), where the field attribute values corresponding to the check value, flag name, check field name, and default value can be replaced by identifier 1, ..., identifier n, respectively. Enumeration elements can only be identifiers and cannot be numeric constants or character constants. The same enumeration element cannot appear in two or more enumeration type definitions. Furthermore, the definition of an enumeration type can be combined with the definition of a variable, such as var a:(identifier 1, identifier 2, identifier 3). Enumeration types are ordinal types, and the sequence of the enumeration type is determined by the order in which the enumeration elements are arranged when defining the type. The sequence number can start from 0. It should be noted that after the creation is complete, the attribute values corresponding to the parameters and fields are passed in via Java methods.
[0021] Further, the step of sequentially verifying each of the second data values according to a preset verification logic to obtain a verification result includes: Retrieve the default value from the enumeration type with parameters, and determine whether the default value is null; If the default value is empty, then check whether the second data value is not empty; If the default value is not empty, then check whether the second data value is equal to the default value.
[0022] Understandably, the default value is assigned to the enumeration type variable during use. Based on this assignment, the values of the enumeration members (in text order) can be incremented by one. For example, if the default value is 0, the subsequent variable assignment can be 1. The second data value is determined in two different ways depending on whether the default value is empty. When the default value is empty, the second data value may be empty. However, when the default value is not empty, the corresponding value in the second data value may be equal to the default value. That is, the second data value corresponding to the default value can be determined in the variable.
[0023] Further, the step of checking whether the second data value is non-empty includes: If the flag bit in the second data value takes the first value, then the second data value is determined to be non-empty. If the flag bit in the second data value takes the second value, then the second data value is determined to be empty.
[0024] Understandably, the flag value is determined based on the value of flag, and the first value can be "Y" or "N". Specifically, the label value is the flag name configured by the enumeration type (flagName name) and the value of the label obtained from the configuration value by reflection. Furthermore, the getDeclaredFields() syntax is used to obtain all declared fields of a class, including the field declaration type field.getType().
[0025] Further, the step of verifying whether the second data value is equal to the default value includes: If both the second data value and the flag value in the default value are the first value, then the second data value is determined to be equal to the default value; If both the second data value and the flag bit in the default value are the second value, then it is determined that the second data value is not equal to the default value.
[0026] Understandably, when the flag bit of two data values is set to "Y", the field value corresponding to the second data value must be equal to the default value; when the flag bit of two data values is set to "N", the field value corresponding to the second data value must be different from the default value.
[0027] Furthermore, the acquisition of the data to be verified and the parameterized enumeration type includes: Use a preset method to obtain the field attributes corresponding to the data to be verified, and obtain the data to be verified based on the field attributes; Use a preset method to obtain the field attributes corresponding to the enumeration type, and obtain the parameterized enumeration type based on the field attributes.
[0028] Understandably, the default method uses the getDeclaredFields() syntax to obtain all declared fields of a class, including the declared type of a field (field.getType()). This method can simultaneously obtain the field attributes corresponding to the data to be validated and the field attributes corresponding to the enumeration type. For example, during the process of obtaining data using the getDeclaredFields() syntax, the field name can be obtained through field.getName(), and after obtaining the field name, the string returned by the object can be obtained through field.get(this).toString(), etc.
[0029] Furthermore, after verifying each of the second data values sequentially according to the preset verification logic and obtaining the verification result, the process further includes: Create a new parameter in the enumeration type; After assigning a value to the new parameter, the addition of the enumeration type is completed in the enumeration type with parameters through the preset attribute value return method.
[0030] Understandably, a new parameter refers to one of the enumeration types that needs to be expanded and added. The steps for creating an enumeration class include: providing a new object (parameter) of the enumeration class; adding the new object to the original object; separating objects with commas; declaring object properties and using `private final` to modify the object properties; assigning values to the object properties; and finally returning the assigned property values through a preset property value return method - getter method, thus completing the addition of the enumeration type to the original parameterized enumeration type. This embodiment only requires adding new enumeration types; the code for validating the logic rules does not need to be changed, which facilitates system maintenance.
[0031] In summary, the above provides a data validation method that addresses the problems of redundant code, poor readability, weak scalability, and difficulty in maintenance associated with data validation methods using conditional statements such as if-else or switch. Specifically, it leverages Java reflection to obtain the second data value from the data to be validated and uses parameterized enumeration types to perform multiple checks on fields within the data to be validated. This enhances code readability and scalability, facilitating later maintenance. Furthermore, using parameterized enumeration types clearly indicates the code's intent, improving readability and maintainability. The reflection mechanism eliminates the need for direct dependencies on specific classes and methods, allowing for easy system expansion and upgrades. If future business requirements necessitate adding new configuration validations to fields affected by journal entries, this can be achieved directly by adding a new configuration enumeration type, eliminating the need to rewrite validation logic rules, reducing error rates, improving development efficiency, and simplifying system maintenance.
[0032] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0033] In one embodiment, the present invention also provides a data verification device, which corresponds one-to-one with a data verification method described in the above embodiments. For example... Figure 3 As shown, this data verification device includes an acquisition module 11, a first verification module 12, and a second verification module 13. Detailed descriptions of each functional module are as follows: Module 11 is used to obtain the data to be verified and the enumeration type with parameters; The first verification module 12 is used to verify whether the verification value in the parameterized enumeration type is equal to the first data value in the data to be verified. The second verification module 13 is used to obtain all the second data values from the data to be verified using the parameterized enumeration type when the verification value is equal to the first data value, and to verify each of the second data values in sequence according to the preset verification logic to obtain the verification result.
[0034] Furthermore, the data verification device further includes: A module is established to create field attributes corresponding to the parameterized enumeration type and define the attribute values corresponding to the field attributes respectively; the field attributes include a check value, a flag name, a check field name, and a default value.
[0035] Furthermore, the second verification module includes: The first acquisition submodule is used to acquire the default value in the enumeration type with parameters, and determine whether the default value is empty; The first verification submodule is used to verify whether the second data value is non-empty if the default value is empty. The second verification submodule is used to verify whether the second data value is equal to the default value if the default value is not empty.
[0036] Furthermore, the first inspection submodule includes: The first determining unit is configured to determine that the second data value is not empty if the flag bit in the second data value takes the first value. The second determining unit is used to determine that the second data value is null if the flag bit in the second data value takes the second value.
[0037] Furthermore, the second verification submodule includes: The third determining unit is used to determine that the second data value is equal to the default value if both the second data value and the flag bit value in the default value are the first value. The fourth determining unit is used to determine that the second data value is not equal to the default value if both the flag bit in the second data value and the default value are the second value.
[0038] Furthermore, the acquisition module includes: The second acquisition submodule is used to acquire the field attributes corresponding to the data to be verified using a preset method, and to acquire the data to be verified based on the field attributes. The third acquisition submodule is used to acquire the field attributes corresponding to the enumeration type using a preset method, and to acquire the parameterized enumeration type based on the field attributes.
[0039] Furthermore, the data verification device further includes: Create a module to create new parameters in the enumeration type; The assignment module is used to assign values to the new parameters and then complete the addition of the enumeration type in the parameterized enumeration type through a preset attribute value return method.
[0040] For specific limitations regarding a data verification device, please refer to the limitations of a data verification method described above, which will not be repeated here. Each module in the aforementioned data verification device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0041] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, interface, and database connected via a system bus. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores data involved in a data verification method. The interface is used for communication with an external terminal. When the processor executes the computer program, it implements a data verification method.
[0042] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of a data verification method described in the above embodiment, for example... Figure 2 Steps S10 to S30 are shown. Alternatively, when the processor executes a computer program, it implements the functions of each module / unit of the data verification device in the above embodiments, for example... Figure 3 The functions of modules 11 to 13 are shown. To avoid repetition, they will not be described again here.
[0043] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program implements the steps of a data verification method described in the above embodiments, for example... Figure 2 Steps S10 to S30 are shown. Alternatively, when a computer program is executed by a processor, it implements the functions of each module / unit of a data verification device in the above embodiments, for example... Figure 3 The functions of modules 11 to 13 are shown. To avoid repetition, they will not be described again here.
[0044] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0045] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0046] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A data verification method, characterized in that, The method includes: Obtain the data to be validated and the enumeration type with parameters; The check value in the parameterized enumeration type is used to verify whether it is equal to the first data value in the data to be checked; When the verification value is equal to the first data value, all the second data values are obtained from the data to be verified using the parameterized enumeration type, and each second data value is verified in turn according to the preset verification logic to obtain the verification result; The step of sequentially verifying each of the second data values according to a preset verification logic to obtain verification results includes: Retrieve the default value from the enumeration type with parameters, and determine whether the default value is null; If the default value is empty, then check whether the second data value is not empty; If the default value is not empty, then check whether the second data value is equal to the default value.
2. The data verification method according to claim 1, characterized in that, Before obtaining the parameterized enumeration type, the process also includes: Establish field attributes corresponding to the parameterized enumeration type, and define the attribute values corresponding to the field attributes respectively; the field attributes include verification value, flag name, verification field name and default value.
3. The data verification method according to claim 1, characterized in that, The step of checking whether the second data value is non-empty includes: If the flag bit in the second data value takes the first value, then the second data value is determined to be non-empty. If the flag bit in the second data value takes the second value, then the second data value is determined to be empty.
4. The data verification method according to claim 1, characterized in that, The step of verifying whether the second data value is equal to the default value includes: If both the second data value and the flag value in the default value are the first value, then the second data value is determined to be equal to the default value; If both the second data value and the flag bit in the default value are the second value, then it is determined that the second data value is not equal to the default value.
5. The data verification method according to claim 1, characterized in that, The process of obtaining the data to be verified and the enumeration type with parameters includes: Use a preset method to obtain the field attributes corresponding to the data to be verified, and obtain the data to be verified based on the field attributes; Use a preset method to obtain the field attributes corresponding to the enumeration type, and obtain the parameterized enumeration type based on the field attributes.
6. The data verification method according to claim 1, characterized in that, After verifying each of the second data values sequentially according to the preset verification logic and obtaining the verification result, the method further includes: Create a new parameter in the enumeration type; After assigning a value to the new parameter, the addition of the enumeration type is completed in the enumeration type with parameters through the preset attribute value return method.
7. A data verification device, characterized in that, include: The acquisition module is used to acquire the data to be verified and the enumeration type with parameters; The first verification module is used to verify whether the verification value in the parameterized enumeration type is equal to the first data value in the data to be verified. The second verification module is used to obtain all the second data values from the data to be verified using the parameterized enumeration type when the verification value is equal to the first data value, and to verify each of the second data values in sequence according to the preset verification logic to obtain the verification result. The second verification module is also used for: Retrieve the default value from the enumeration type with parameters, and determine whether the default value is null; If the default value is empty, then check whether the second data value is not empty; If the default value is not empty, then check whether the second data value is equal to the default value.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements a data verification method as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements a data verification method as described in any one of claims 1 to 6.
