Data verification method and device, equipment, storage medium and program product
By predefining verification rules in the data structure and parsing the application, independent of business logic, the problem of complexity and maintenance difficulty of data verification rules is solved, and flexibility and efficient development are achieved.
Patent Information
- Application Number
- CN202310376284.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-10
- Publication Date
- 2024-10-15
AI Technical Summary
In the existing technology, data verification rules are complex and difficult to maintain and reuse, and are hard-coded in the business logic code, resulting in complex implementation logic and low efficiency.
Through the verification rules in the predefined data structure, the parsed data verification rules are parsed and applied for data verification, which is independent of business logic and avoids hard coding.
It simplifies the implementation logic of data verification, improves the flexibility and maintainability of data verification rules, and improves development efficiency.
Smart Images

Figure CN118778964A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information processing technology, and in particular to a data verification method, device, equipment, storage medium and program product. Background Art
[0002] With the continuous development of computer technology, computer-based business applications are becoming more and more widespread. When the business data involved in the business is transmitted between multiple parties, it is often necessary to perform data verification on the business data.
[0003] In the related art, data verification of business data is implemented as follows: developers pre-write the data verification rules for each type of business data into data verification code, and then hard-code the data verification code into the business logic code of the business data, so that by executing the business logic code, the business data is verified while executing the business logic code. However, as the data verification rules become more complicated, the implementation logic and code are also becoming more and more complicated; and because they are hard-coded in the business logic code, maintenance and reuse are more complicated. Summary of the invention
[0004] The embodiments of the present application provide a data verification method, device, electronic device, computer-readable storage medium and computer program product, which can simplify the implementation logic of data verification, improve the flexibility of data verification rules, facilitate the maintenance and reuse of data verification rules, and improve the development efficiency of data verification.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present application provides a data verification method, including:
[0007] When receiving the service data of the target service, determining the target data structure of the service data from at least one data structure, each of the data structures being predefined with a corresponding data verification rule;
[0008] Obtaining a target data verification rule predefined for the target data structure;
[0009] Parsing the target data verification rule to obtain a parsed data verification rule;
[0010] The parsed data verification rule is used to perform data verification on the business data to obtain a verification result of the business data, so as to execute the business logic of the target business on the business data based on the obtained verification result.
[0011] The present application also provides a data verification device, including:
[0012] A determination module, configured to determine, when receiving the service data of a target service, a target data structure of the service data from at least one data structure, each of the data structures being predefined with a corresponding data verification rule;
[0013] An acquisition module, used for acquiring a target data verification rule predefined for the target data structure;
[0014] A parsing module, used to parse the target data verification rule to obtain the parsed data verification rule;
[0015] The verification module is used to use the parsed data verification rule to perform data verification on the business data to obtain the verification result of the business data, so as to execute the business logic of the target business on the business data based on the obtained verification result.
[0016] In the above scheme, the target data structure includes a target field, and the target field is used to define the data verification rules of the target data structure; the acquisition module is also used to parse the business data to determine the target field value of the target field; and the target field value is used as the target data verification rule predefined for the target data structure.
[0017] In the above scheme, the target data structure includes a target field, and the target field is used to store the indication information of the data verification rule of the target data structure; the acquisition module is also used to parse the business data, determine the target field value of the target field, and the target field value is the indication information; obtain the data verification rule indicated by the indication information; use the data verification rule indicated by the indication information as the predefined target data verification rule for the target data structure.
[0018] In the above scheme, the acquisition module is also used to obtain annotation information edited for the target data structure when defining the target data structure; extract annotation data verification rules edited for the target data structure from the annotation information; and use the annotation data verification rules as predefined target data verification rules for the target data structure.
[0019] In the above scheme, the acquisition module is also used to obtain the correspondence between the data structure and the data verification rules; based on the correspondence, the data verification rules corresponding to the target data structure are obtained from a data verification rule library including a plurality of the data verification rules; and the data verification rules corresponding to the target data structure are used as predefined target data verification rules for the target data structure.
[0020] In the above scheme, when the target data verification rule includes a single verification rule, the parsing module is also used to obtain the verification rule syntax of the target data verification rule; based on the verification rule syntax, the target data verification rule is parsed to obtain the verification rule syntax tree of the target data verification rule, and the verification syntax tree includes a verification expression and a verification operator that conforms to the target data verification rule; based on the verification expression and the verification operator, the parsed data verification rule is generated.
[0021] In the above scheme, the parsing module is also used to convert the verification syntax tree into a target expression in a target form based on the verification expression and the verification operator, and use the target expression as the parsed data verification rule.
[0022] In the above scheme, when the target data verification rule includes multiple sub-verification rules, the parsing module is also used to split the target data verification rule to obtain each of the sub-verification rules, and perform the following processing on each of the sub-verification rules: obtain the verification rule syntax of the sub-verification rule; based on the verification rule syntax, parse the sub-verification rule to obtain the verification rule syntax tree of the sub-verification rule, and the verification syntax tree includes a verification expression and a verification operator that conforms to the sub-verification rule; based on the verification expression and the verification operator, generate the parsed sub-verification rule of the sub-verification rule; wherein the parsed sub-verification rules of each of the sub-verification rules constitute the parsed data verification rule.
[0023] In the above scheme, the verification module is also used to parse the business data to determine the field value of the field to be verified in the business data; use the parsed data verification rule to verify the field value of the field to be verified to obtain the verification result of the business data.
[0024] In the above scheme, the verification module is also used to parse the business data to obtain the various fields included in the business data; obtain the field name of each field; determine the field to be checked in the business data according to the field name of each field and the parsed data verification rules, and obtain the field value of the field to be checked.
[0025] In the above scheme, when the post-parsed data verification rules include multiple post-parsed verification rules and the number of the fields to be checked is multiple, the verification module is also used to perform the following processing for each of the post-parsed verification rules: determine the field group to be checked corresponding to the post-parsed verification rule, and the field group to be checked includes at least one of the fields to be checked; use the post-parsed verification rule to verify the field value of the field to be checked in the field group to be checked to obtain the field group verification result of the field group to be checked; based on the field group verification results corresponding to each of the post-parsed verification rules, determine the verification result of the business data.
[0026] In the above scheme, the verification module is also used to perform data verification on the business data using the parsed data verification rule, and after obtaining the verification result of the business data, when the verification result indicates that the business data verification fails, obtain the verification alarm strategy of the business data; based on the verification alarm strategy, perform alarm processing on the verification result.
[0027] The present application also provides an electronic device, including:
[0028] A memory for storing computer executable instructions;
[0029] The processor is used to implement the data verification method provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.
[0030] The embodiment of the present application also provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are executed by a processor, the data verification method provided by the embodiment of the present application is implemented.
[0031] The embodiment of the present application also provides a computer program product, including computer executable instructions, which, when executed by a processor, implement the data verification method provided in the embodiment of the present application.
[0032] The embodiments of the present application have the following beneficial effects:
[0033] By applying the above-mentioned embodiments of the present application, corresponding data verification rules are predefined for each data structure of the business data. When the business data of the target business is received, the target data verification rules predefined for the target data structure of the business data are obtained, and then the target data verification rules are parsed to implement the verification of the business data using the parsed data verification rules, so that the data verification of the business data can be implemented before the business logic is executed for the business data. In this way, it is only necessary to predefine the corresponding data verification rules for each data structure, and there is no need to write the verification code of the data verification rules and hard-code the verification code into the business logic code, which simplifies the implementation logic of the data verification, improves the flexibility of the data verification rules, facilitates the maintenance and reuse of the data verification rules, and improves the development efficiency of the data verification. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 1 is a schematic diagram of the architecture of a data verification system 100 provided in an embodiment of the present application;
[0035] Figure 2 is a structural diagram of an electronic device 500 for implementing a data verification method provided in an embodiment of the present application;
[0036] Figure 3 It is a flow chart of the data verification method provided in the embodiment of the present application;
[0037] Figure 4 It is a flow chart of the data verification method provided in the embodiment of the present application;
[0038] Figure 5 It is a schematic diagram of the architecture of the data verification application system provided in the embodiment of the present application;
[0039] Figure 6 It is a schematic diagram of the architecture of the data verification method provided in the embodiment of the present application;
[0040] Figure 7 It is a schematic diagram of the process of obtaining the field value of the business data provided by the embodiment of the present application;
[0041] Figure 8 It is a schematic diagram of obtaining the data verification rules provided in the embodiment of the present application;
[0042] Fig. 9 It is a schematic diagram of obtaining the data verification rules provided in the embodiment of the present application;
[0043] Fig.10 It is a processing diagram of the data verification rules provided in the embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0045] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0046] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0047] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0048] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0049] 1) Client: an application running in a terminal to provide various services, such as a client that supports target services (such as instant messaging, video, etc.).
[0050] 2) In response, it is used to indicate the conditions or states on which the executed operations depend. When the dependent conditions or states are met, one or more operations executed may be in real time or have a set delay. Unless otherwise specified, there is no restriction on the order of execution of the multiple operations executed.
[0051] 3) Data structure is a way to store, transmit and organize data. Data structure refers to a collection of data elements that have one or more specific relationships with each other. Data structure includes one or more fields, and data structure can be defined as needed.
[0052] 4) Protocol buffers (Pb protocol for short): It is an open source, cross-platform protocol for serialized data structures that can serialize structured data and can be used for data storage, communication protocols, etc. The Pb protocol contains an interface description language that is used to describe some data structures and provides programming tools to generate program codes based on these descriptions. These program codes will be used to generate or parse data streams representing these data structures. In this way, the data structure of the data can be defined through the Pb protocol, and code based on various languages can be generated. These defined data streams can be transmitted without destroying existing programs, and these data streams can also be updated without affecting existing programs.
[0053] 5) Message: The data structure defined by the Pb protocol, which is defined in the Protobuf file. A Protobuf file can contain multiple defined Messages, which can reference each other, and can also nest other Messages and enumeration classes. A Message usually contains one or more fields, and each field can contain the following parts: field descriptor (optional), field type, field name, and tag corresponding to the field. Among them, 1) The field descriptor is used to describe the frequency of occurrence of the field, with the following two optional values: (a) singular: indicates 0 or 1 occurrence; if the descriptor is not declared, the default is singular; (b) repeated: indicates 0 or more occurrences; 2) Field type. For example, double, float, bool, string, bytes, int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed32, sfixed64; reference other Message types; 3) Enumeration type: For enumeration types, Protobuf has a constraint that the value corresponding to the first item of the enumeration must be 0.
[0054] The embodiments of the present application provide a data verification method, device, electronic device, computer-readable storage medium, and computer program product, which can simplify the implementation logic of data verification, improve the flexibility of data verification rules, facilitate the maintenance and reuse of data verification rules, and improve the development efficiency of data verification. The following will be described separately.
[0055] It should be noted that when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0056] The following describes the data verification system provided by the embodiment of the present application. Figure 1 , Figure 1 It is an architectural diagram of a data verification system 100 provided in an embodiment of the present application. To support an exemplary application, a terminal (terminal 400-1 is shown as an example) is connected to a server 200 via a network 300. The network 300 may be a wide area network or a local area network, or a combination of the two, and data transmission is achieved using wireless or wired links.
[0057] The terminal (e.g., 400-1) is used to send business data of the target business to the server 200 in response to a data sending instruction for the target business; illustratively, the business data can be a business request, such as a request to obtain video data, or data uploaded by the terminal, such as image data, video data, etc.
[0058] The server 200 is used to receive the business data of the target business sent by the terminal; determine the target data structure of the business data from at least one data structure, wherein each data structure is predefined with a corresponding data verification rule; obtain the target data verification rule predefined for the target data structure; parse the target data verification rule to obtain the parsed data verification rule; use the parsed data verification rule to perform data verification on the business data to obtain the verification result of the business data; when the verification result indicates that the business data verification fails, return an alarm message to the terminal; when the verification result indicates that the business data verification passes, execute the business logic of the target business on the business data, and return the execution result of the business logic to the terminal;
[0059] The terminal (eg, 400 - 1 ) is further configured to output alarm information when receiving alarm information returned by the server 200 ; and output the execution result when receiving the execution result of the business logic returned by the server 200 .
[0060] In some embodiments, the data verification method provided in the embodiments of the present application can be implemented by various electronic devices, for example, it can be implemented by a terminal alone, it can also be implemented by a server alone, or it can be implemented by a terminal and a server in collaboration. The data verification method provided in the embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, games, audio and video, etc.
[0061] In some embodiments, the electronic device for implementing the data verification method provided in the embodiments of the present application may be various types of terminals or servers. Among them, the server (e.g., server 200) may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. The terminal (e.g., terminal 400-1) may be a laptop, a tablet computer, a desktop computer, a smart phone, an intelligent voice interaction device (e.g., an intelligent speaker), a smart home appliance (e.g., a smart TV), a smart watch, a vehicle-mounted terminal, a wearable device, a virtual reality (VR) device, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected via wired or wireless communication, and the embodiments of the present application do not limit this.
[0062] In some embodiments, the data verification method provided in the embodiment of the present application can be implemented with the aid of cloud technology (Cloud Technology). Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network in a wide area network or a local area network to realize the calculation, storage, processing, and sharing of data. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, and application technology based on the application of cloud computing business model, which can form a resource pool, which is used on demand and is flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing resources and storage resources. As an example, a server (such as server 200) can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0063] In some embodiments, multiple servers may form a blockchain, and the servers are nodes on the blockchain. Information connections may exist between each node in the blockchain, and information may be transmitted between nodes through information connections. Among them, data related to the data verification method provided in the embodiment of the present application (such as data verification rules, the correspondence between data structures and data verification rules, data verification rule bases, verification results, etc.) may be stored on the blockchain.
[0064] In some embodiments, the terminal or server can implement the data verification method provided by the embodiment of the present application by running various computer executable instructions or computer programs. For example, computer executable instructions can be commands, machine instructions or software instructions at the microprogram level. The computer program can be a native program or software module in the operating system; it can be a local (Native) application (Application, APP), that is, a program that needs to be installed in the operating system to run; it can also be a small program, that is, a program that can be run only by downloading it to a browser environment; it can also be a small program that can be embedded in any APP. In short, the above-mentioned computer executable instructions can be instructions in any form, and the above-mentioned computer program can be an application, module or plug-in in any form.
[0065] The following describes an electronic device for implementing a data verification method provided by an embodiment of the present application. Figure 2 , Figure 2 : is a schematic diagram of the structure of an electronic device 500 for implementing a data verification method provided in an embodiment of the present application. The electronic device 500 provided in an embodiment of the present application may be a terminal or a server. The electronic device 500 provided in an embodiment of the present application includes: at least one processor 510, a memory 550, at least one network interface 520 and a user interface 530. The various components in the electronic device 500 are coupled together through a bus system 540. It can be understood that the bus system 540 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 540 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, in Figure 2 Various buses are labeled as bus system 540 .
[0066] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0067] The user interface 530 includes one or more output devices 531 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0068] The memory 550 may be removable, non-removable, or a combination thereof. The memory 550 may include one or more storage devices physically located away from the processor 510. The memory 550 includes a volatile memory or a non-volatile memory, and may also include both a volatile memory and a non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 550 described in the embodiments of the present application is intended to include any suitable type of memory.
[0069] In some embodiments, the memory 550 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0070] Operating system 551, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0071] A network communication module 552, used to reach other electronic devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0072] a presentation module 553 for enabling presentation of information via one or more output devices 531 (e.g., display screen, speaker, etc.) associated with the user interface 530 (e.g., a user interface for operating peripherals and displaying content and information);
[0073] The input processing module 554 is used to detect one or more user inputs or interactions from one of the one or more input devices 532 and translate the detected inputs or interactions.
[0074] In some embodiments, the data verification device provided in the embodiments of the present application can be implemented in a software manner. Figure 2 A data verification device 555 stored in a memory 550 is shown, which may be software in the form of a program or plug-in, including the following software modules: a determination module 5551, an acquisition module 5552, a parsing module 5553, and a verification module 5554. These modules are logical, and therefore may be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0075] The following describes the data verification method provided by the embodiment of the present application. In some embodiments, the data verification method provided by the embodiment of the present application can be implemented by various electronic devices, for example, it can be implemented by a terminal alone, it can also be implemented by a server alone, or it can be implemented by a terminal and a server in collaboration. Taking the server implementation as an example, see Figure 3 , Figure 3 : is a flow chart of a data verification method provided in an embodiment of the present application. The data verification method provided in an embodiment of the present application includes:
[0076] Step 101: When the server receives service data of a target service, it determines a target data structure of the service data from at least one data structure.
[0077] Each data structure is predefined with a corresponding data verification rule. The at least one data structure is also predefined, and the data structure specifies the format in which the business data is transmitted.
[0078] In step 101, the server may be a server that provides a target service. In actual applications, the terminal held by the user may be provided with a client that supports the target service, and the user operates on the terminal through the client to trigger a sending instruction for service data. Here, the data related to the target service sent by the terminal to the server may be referred to as service data. Exemplarily, the service data may be a service request, such as a request to obtain video data, or data uploaded by the terminal, such as image data, video data, etc. The target service may be an instant messaging service, a video playback service, a music playback service, etc., which are not limited here. When the server receives the service data of the target service, it is necessary to perform data verification on the received service data, so that after the data verification passes, the service logic of the target service is executed for the service data.
[0079] In an embodiment of the present application, when business data is received, before the business logic of the target business is executed for the business data, data verification is performed on the business data. Specifically, when business data is received, a pre-built data verification module (provided with data verification logic) shared by multiple businesses can be called, and the data verification method provided by the embodiment of the present application is executed to verify the business data. In this way, the data verification logic is independent of the business logic, and there is no need to hard-code the data verification rules into the business logic code, which improves the flexibility of the data verification rules and the reusability of the data verification rules, and improves development efficiency. In actual implementation, when the server receives the business data of the target business, first from at least one predefined data structure, the target data structure of the business data is determined.
[0080] Step 102: Obtain target data verification rules predefined for the target data structure.
[0081] In step 102, since corresponding data verification rules are predefined for different data structures, after determining the target data structure of the business data, the target data verification rules predefined for the target data structure are obtained. Exemplarily, the data structure of the business data is field a, field b and field c, and the corresponding data verification rules may be:
[0082] Regarding the a field: [(validation.rules).int32 = {not_in: [0]}], the a field cannot be 0;
[0083] Regarding the b field: [(validation.rules).int32.gte=10], the b field cannot be less than 10;
[0084] Regarding the c field: [(validation.rules).int32 = {gte:1,lte:3}], the c field is between 1 and 3.
[0085] In some embodiments, the target data structure includes a target field, which is used to define data verification rules for the target data structure; the server can obtain the target data verification rules predefined for the target data structure in the following manner: parsing the business data to determine the target field value of the target field; using the target field value as the target data verification rules predefined for the target data structure.
[0086] Here, when predefining the corresponding data verification rules for the data structure, it can be implemented when defining the data structure of the business data, that is, when defining the data structure of the business data, a target field is set in the data structure to predefine the data verification rules of the business data (or the data structure of the business data) in the target field. In this way, the definition of the data structure and the definition of the data verification rules are unified in one place, which is conducive to the understanding and maintenance of the data verification rules for the business data in the later stage, and improves the development efficiency.
[0087] Based on this, when the target data verification rule predefined for the target data structure is obtained, the business data can be parsed to determine the target field in the business data, and then the target field value of the target field is obtained. The target field value of the target field is the target data verification rule predefined for the target data structure.
[0088] In some embodiments, the target data structure includes a target field, which is used to store indication information of data verification rules of the target data structure; the server can obtain the target data verification rules predefined for the target data structure in the following manner: parse the business data, determine the target field value of the target field, and the target field value is the indication information; obtain the data verification rules indicated by the indication information; use the data verification rules indicated by the indication information as the target data verification rules predefined for the target data structure.
[0089] Here, when predefining the corresponding data verification rules for the data structure, it can be implemented when defining the data structure of the business data, that is, when defining the data structure of the business data, a target field is set in the data structure to store the indication information of the data verification rules of the business data (or the data structure of the business data) in the target field; at the same time, the data verification rules of the data structure of the business data are predefined for the indication information. In this way, the business data itself does not need to carry the data verification rules, which can reduce the amount of business data, improve the utilization rate of network transmission resources and data transmission efficiency; at the same time, based on the indication information, the data verification rules of different data structures can also be quickly obtained, which is also conducive to the understanding and maintenance of the data verification rules for the business data in the later stage, and improve the development efficiency.
[0090] Based on this, when the target data verification rule predefined for the target data structure is obtained, the business data can be parsed to determine the target field in the business data, and then the target field value of the target field can be obtained, and the target field value is the indication information of the data verification rule of the business data (or the data structure of the business data). In this way, the data verification rule indicated by the indication information is used as the target data verification rule predefined for the target data structure.
[0091] The above two methods of predefining data verification rules are both implemented when defining the data structure of business data, that is, when defining the data structure of the business data, a target field is set in the data structure to store the relevant information of the predefined data verification rule through the target field. The relevant information can be the predefined data verification rule itself or the indication information of the predefined data verification rule. In this way, when the target data verification rule predefined for the target data structure is obtained, the business data can be parsed to determine the target field in the business data, and then the target data verification rule can be obtained according to the target field value of the target field.
[0092] In some embodiments, the server may obtain the target data verification rules predefined for the target data structure in the following manner: obtaining annotation information edited for the target data structure when defining the target data structure; extracting the annotation data verification rules edited for the target data structure from the annotation information; and using the annotation data verification rules as the target data verification rules predefined for the target data structure.
[0093] Here, when predefining the corresponding data verification rules for the data structure, it can also be implemented in the annotations edited for the target data structure when defining the target data structure, that is, when defining the data structure of the business data, the data verification rules of the data structure are annotated in the edited annotation information. In this way, the definition of the data structure and the definition of the data verification rules can also be unified in one place, which is conducive to the understanding and maintenance of the data verification rules for the business data in the later stage, and improves the development efficiency.
[0094] Based on this, when obtaining the target data verification rule predefined for the target data structure, the annotation information edited for the target data structure when defining the target data structure can be obtained, and then the annotation data verification rule edited for the target data structure can be extracted from the annotation information. The annotation data verification rule is the target data verification rule predefined for the target data structure.
[0095] In some embodiments, the server may obtain target data verification rules predefined for the target data structure in the following manner: obtain the correspondence between the data structure and the data verification rules; based on the correspondence, obtain the data verification rules corresponding to the target data structure from a data verification rule library including multiple data verification rules; and use the data verification rules corresponding to the target data structure as the target data verification rules predefined for the target data structure.
[0096] Here, when predefining corresponding data verification rules for data structures, corresponding data verification rules can be predefined for each data structure, and then the predefined data verification rules can be stored in a data verification rule library. Specifically, data verification rules for multiple data structures can be stored in the data verification rule library, and at the same time, the corresponding relationship between the data structure and the data verification rule can also be stored in the data verification rule library.
[0097] Based on this, when obtaining the target data verification rules predefined for the target data structure, the correspondence between the data structure and the data verification rules can be first obtained, and then based on the correspondence, the data verification rules corresponding to the target data structure can be obtained from the data verification rule library. The data verification rules corresponding to the target data structure in the data verification rule library are the target data verification rules predefined for the target data structure.
[0098] Step 103: Parse the target data verification rule to obtain the parsed data verification rule.
[0099] In step 103, after the data verification rules predefined for the target data structure are obtained, the target data verification rules need to be parsed to obtain data verification rules that can be understood by the data verification logic, that is, the parsed data verification rules.
[0100] In some embodiments, see Figure 4 , Figure 4 : is a flow chart of the data verification method provided in the embodiment of the present application. Here, Figure 4 It shows that when the target data verification rule includes a single verification rule, Figure 3 Step 103 in the above example can be implemented through the following steps: Step 201, obtaining the verification rule syntax of the target data verification rule; Step 202, parsing the target data verification rule based on the verification rule syntax to obtain the verification rule syntax tree of the target data verification rule, wherein the verification syntax tree includes verification expressions and verification operators that conform to the target data verification rule; Step 203, generating the parsed data verification rule based on the verification expression and the verification operator.
[0101] Here, if the target data verification rule only includes a single verification rule, then the verification rule syntax of the target data verification rule can be directly obtained, and the verification rule syntax is set when defining the target data verification rule. Then, based on the verification rule syntax, the composition of the target data verification rule is analyzed to obtain the verification rule syntax tree of the target data verification rule, which includes a verification expression and a verification operator that conforms to the target data verification rule. Among them, the verification expression includes references and constants to the field value according to the field name; the verification operator includes arithmetic operators, logical operators, and function calls, etc. Finally, based on the verification expression and the verification operator, the parsed data verification rule is generated.
[0102] In some embodiments, the server can generate the parsed data validation rule based on the validation expression and the validation operator in the following manner: based on the validation expression and the validation operator, the validation syntax tree is converted into a target expression in a target form, and the target expression is used as the parsed data validation rule. In practical applications, the target expression in the target form can be a reverse Polish notation. By converting the validation syntax tree into a target expression in the target form, a complex expression can be converted into a simple expression, reducing the difficulty of calculation and increasing the calculation speed, thereby improving the validation efficiency of data validation.
[0103] In some embodiments, when the target data verification rule includes multiple sub-verification rules, the server may parse the target data verification rule in the following manner to obtain the parsed data verification rule: split the target data verification rule to obtain each sub-verification rule, and perform the following processing on each sub-verification rule: obtain the verification rule syntax of the sub-verification rule; based on the verification rule syntax, parse the sub-verification rule to obtain the verification rule syntax tree of the sub-verification rule, the verification syntax tree includes the verification expression and the verification operator that conforms to the sub-verification rule; based on the verification expression and the verification operator, generate the parsed sub-verification rule of the sub-verification rule; wherein the parsed sub-verification rules of each sub-verification rule constitute the parsed data verification rule.
[0104] Here, if the target data verification rule includes multiple sub-verification rules, then when parsing the target data verification rule, it is necessary to first split the target data verification rule to obtain each sub-verification rule, and then parse each sub-verification rule separately. Specifically, for each sub-verification rule, perform the following processing respectively: obtain the verification rule syntax of the sub-verification rule; then analyze the composition of the sub-verification rule based on the verification rule syntax, and obtain the verification rule syntax tree of the sub-verification rule, which includes the verification expression and verification operator that conforms to the sub-verification rule. Among them, the verification expression includes references and constants to the field value according to the field name; the verification operator includes arithmetic operators, logical operators and function calls, etc. Finally, according to the verification expression and the verification operator, generate the parsed sub-verification rule. In this way, the parsed sub-verification rule of each sub-verification rule is obtained, and the parsed sub-verification rule of each sub-verification rule constitutes the parsed data verification rule.
[0105] Step 104: Use the parsed data verification rules to perform data verification on the business data to obtain a verification result of the business data, and execute the business logic of the target business on the business data based on the obtained verification result.
[0106] In step 104, after obtaining the parsed data verification rule, the parsed data verification rule is used to perform data verification on the business data to obtain the verification result of the business data. In this way, after obtaining the verification result of the business data, the business logic of the target business can be executed on the business data based on the verification result. Specifically, when the verification result indicates that the business data verification has passed, the business logic of the target business is executed on the business data.
[0107] In some embodiments, by adopting the post-parsed data verification rules, the server can perform data verification on the business data in the following manner to obtain the verification results of the business data: parse the business data to determine the field values of the fields to be verified in the business data; adopt the post-parsed data verification rules to verify the field values of the fields to be verified to obtain the verification results of the business data.
[0108] In some embodiments, the server may parse the business data in the following manner to determine the field value of the field to be checked in the business data: parse the business data to obtain the various fields included in the business data; obtain the field name of each field; determine the field to be checked in the business data according to the field name of each field and the parsed data verification rule, and obtain the field value of the field to be checked. Here, when defining the data structure, each field is defined with a corresponding field name. The field to be checked in the business data is determined by matching the field name of each field in the business data with the field name involved in the parsed data verification rule, that is, the field name of each field in the business data that is the same as the field name involved in the parsed data verification rule is used as the field to be checked. After the field to be checked is determined, the field value of the field to be checked is obtained at the same time.
[0109] In some embodiments, when the post-parsed data verification rules include multiple post-parsed verification rules and the number of fields to be checked is multiple, the post-parsed data verification rules are adopted, and the server can verify the field value of the field to be checked in the following manner to obtain the verification result of the business data: for each post-parsed verification rule, the following processing is performed respectively: determine the field group to be checked corresponding to the post-parsed verification rule, the field group to be checked includes at least one field to be checked; adopt the post-parsed verification rules to verify the field value of the field to be checked in the field group to be checked, and obtain the field group verification result of the field group to be checked; based on the field group verification results corresponding to each post-parsed verification rule, determine the verification result of the business data.
[0110] Here, if the post-parsed data verification rules include multiple post-parsed verification rules and the number of fields to be verified is multiple, then the post-parsed data verification rules can be split to obtain individual post-parsed verification rules, and then for each post-parsed verification rule, the following processing is performed respectively: from multiple fields to be verified, determine the field group to be verified corresponding to the post-parsed verification rule, and the field group to be verified includes at least one field to be verified. In this way, data verification of a single field can be achieved, and data verification of associated multiple fields can also be achieved, thereby supporting more complex data verification logic. Then, the post-parsed verification rules are used to verify the field values of the fields to be verified in the field group to be verified, and the field group verification results of the field group to be verified are obtained. Finally, the verification results of the business data can be determined based on the field group verification results corresponding to each post-parsed verification rule. Specifically, a mapping relationship between the verification results of each field group and the verification results of the business data can be set. For example, when the verification results of all field groups in the verification results of each field group are verification passed, the verification result is verification passed; or, when the verification results of a specific field group in the verification results of each field group are verification passed, the verification result is verification passed; or, when the verification results of some field groups in the verification results of each field group are verification passed, the verification result is verification passed; and so on.
[0111] In some embodiments, when the post-parsed data verification rule includes a single post-parsed verification rule and the number of fields to be verified is multiple, then the field group to be verified corresponding to the post-parsed data verification rule is composed of the multiple fields to be verified. In this case, the post-parsed verification rule is directly used to verify the field values of the multiple fields to be verified to obtain the verification result of the business data.
[0112] In some embodiments, if the post-parsed data verification rules include at least one post-parsed verification rule, and each post-parsed verification rule is used for data verification of a single field, then each post-parsed verification rule is directly adopted to verify the field value of the field to be verified corresponding to the post-parsed verification rule.
[0113] In some embodiments, when the parsed data verification rules are used to perform data verification on the business data and the verification results of the business data are obtained, the server can also perform the following processing: when the verification result indicates that the business data verification has failed, obtain the verification alarm strategy of the business data; based on the verification alarm strategy, perform alarm processing on the verification result.
[0114] Here, if the verification of the business data fails, the preset verification alarm strategy of the business data is obtained. The verification alarm strategy can be set according to the actual content of the business data. For example, when the business data is a verification code, the verification alarm strategy can be to return an alarm message (such as a verification code error, a verification code failure, etc.), output an alarm tone, etc. Thus, based on the obtained verification alarm strategy, the verification result is processed with an alarm to indicate that the business data verification has failed.
[0115] By applying the above-mentioned embodiments of the present application, corresponding data verification rules are predefined for each data structure of the business data. When the business data of the target business is received, the target data verification rules predefined for the target data structure of the business data are obtained, and then the target data verification rules are parsed to implement the verification of the business data using the parsed data verification rules, so that the data verification of the business data can be implemented before the business logic is executed for the business data. In this way, it is only necessary to predefine the corresponding data verification rules for each data structure, and there is no need to write the verification code of the data verification rules and hard-code the verification code into the business logic code, which simplifies the implementation logic of the data verification, improves the flexibility of the data verification rules, facilitates the maintenance and reuse of the data verification rules, and improves the development efficiency of the data verification.
[0116] The following will take the transmission of business data using the Pb protocol as an example to illustrate an exemplary application of an embodiment of the present application in an actual application scenario.
[0117] The data verification method provided in the embodiment of the present application can be applied to the access layer of the background service system of the target business, that is, the pre-processing link after the background service system receives the business request of the target business, and the business request carries business data. In the pre-processing link, the background service system first needs to perform a legitimacy check on the business request (that is, the business data carried by the business request). In practical applications, since the background system that receives the business request has the logic of verifying the business request, therefore, whether it is a background service system that interacts with the front end, or a more downstream background service system, as long as it is a background service system that receives the business request and verifies the business request, the data verification method provided in the embodiment of the present application can be applied.
[0118] As an example, see Figure 5 , Figure 5It is a schematic diagram of the architecture of the application system of data verification provided by the embodiment of the present application. Here, the application system of data verification includes: user presentation layer (providing user access interface, such as client, applet, web page, computer, etc.), general gateway layer (such as providing load balancing, protocol conversion, traffic management and other functions), data verification layer, business gateway layer (such as providing routing management, permission verification, data conversion and other functions), business logic layer (such as providing business logic encapsulation, business middle platform services and other functions), data access layer (such as providing data encapsulation and data access and other functions) and infrastructure layer (such as providing data storage, message queues, basic services, middleware services and other functions). Among them, the user presentation layer can be implemented by the front end, the general gateway layer can be implemented by company-level services, the infrastructure layer can use the implementation of general facilities, and the background service system mainly implements the business gateway layer, business logic layer, data access layer and data verification layer.
[0119] In fact, in the relevant technology, data verification is implemented at the business gateway layer. The main reason is that data verification in the relevant technology usually adopts a hard-coded implementation method, that is, the data verification code encoded according to the data verification rules is hard-coded into the business code, so as to implement data verification when the business code is running. However, the hard-coded implementation method has the following problems: 1) Complex implementation. Complex business data brings complex data verification code implementation, and business data often has multiple layers of nesting, and there are several dependencies and pointing relationships between different business data, which further increases the complexity of data verification code implementation. 2) Complex maintenance. With the development of business, business data will undergo many changes and iterations, and the resulting data verification code must also be iterated accordingly. In the case of data changes, it is easy to cause iteration failures and bugs due to the complexity of the data verification code, which will affect normal operation. 3) Complex reuse. There may be situations where the same business data is used between different businesses, but the data verification code hard-coded in the business gateway layer cannot be directly reused, which reduces the reusability of the code, increases the workload of repeated coding, and reduces efficiency.
[0120] Based on this, in the embodiment of the present application, the data verification method can be implemented as follows: add a tag to each field of the data in the Pb protocol, and specify the data verification rules of the field in the tag. For example, a data structure data has three integer fields a, b, and c. If the a field cannot be 0, the b field cannot be less than 10, and the c field is between 1 and 3, then in the Pb protocol, you can add tags to the three fields respectively, and specify the following data verification rules in the tag:
[0121] Regarding field a: [(validation.rules).int32 = {not_in: [0]}];
[0122] Regarding the b field: [(validation.rules).int32.gte=10];
[0123] Regarding the c field: [(validation.rules).int32 = {gte:1,lte:3}];
[0124] Here, the Pb protocol specifies data validation rules for the three fields respectively. The protoc-gen-validate plug-in can generate stub codes that implement the relevant data validation rules. The data validation of the three fields is implemented in the stub code. The business logic of the stub code is as follows:
[0125] If the a field is not in the range of [0], an error is returned;
[0126] If the b field is not greater than or equal to 10, an error is returned;
[0127] If the c field is not greater than or equal to 1 or less than or equal to 3, an error is returned;
[0128] In this way, the relevant stub code can be generated by the tag of the field in the Pb protocol, and then the logic in the stub code can be called to implement the verification of the three fields separately. However, this solution can only implement data verification of a single field, and this data verification only accounts for a small part of business data verification. For many business scenarios, it cannot meet the data verification requirements.
[0129] Based on this, the embodiment of the present application also provides a data verification method to at least solve the above-mentioned problems. Figure 5 Detailed description. In an embodiment of the present application, a data verification layer is added between the general gateway layer and the business gateway layer, so that when the general gateway layer transmits business data to the business gateway layer, the overall data verification can be performed through configuration (i.e., defining corresponding data verification rules for the Message data structure and configuring data verification rules in a third party). In this way, 1) the data transmitted from the general gateway layer to the business gateway layer is associated with the data of the business gateway layer, which is conducive to improving the reusability of business data verification, and merging data and data verification in design is also helpful for subsequent maintenance; 2) for the data verification layer itself, the data verification function is relatively extracted from the business gateway layer, and is no longer implemented in a hard-coded manner, reducing the complexity of implementation and maintenance.
[0130] In an embodiment of the present application, the shared Pb protocol provided in the embodiment of the present application can be referenced in the Pb protocol used by the business. The shared Pb protocol is equivalent to adding a custom field to the Message in the Pb protocol used by the business. In this way, for a specific Message in the Pb protocol used by the business, the data verification rule of the Message can be defined in the custom field corresponding to the Message. In this way, the corresponding data verification rules are defined for the Message data structure. Based on this, in the code logic, the shared package (i.e., shared Pb protocol) provided in the embodiment of the present application can be referenced, and after the access layer obtains the data structure of the business data in the business request, the data verification rules of the shared package are called to perform data verification. Specifically, the shared package will complete the following logic: 1) Determine the Message data structure of the incoming business data (i.e., which type of Message of the Pb protocol is specific), and obtain the data verification rules predefined for the Message data structure; 2) Parse the data verification rules according to the predefined data verification syntax to obtain the parsed data verification rules; 3) Verify the business data according to the parsed data verification rules to obtain the verification results.
[0131] In actual implementation, the verification results are divided into two categories. If all defined data verification rules are passed, no error will be reported. If there are data verification rules that fail, the error information corresponding to some or all of the failed data verification rules will be returned. Based on this, there is no need to hard-code data verification rules in the business code, but the above-mentioned method of calling the data verification rules of the public package is adopted to perform data verification. After the data verification is completed, the business code decides whether to return an error or continue execution, or take a series of measures such as warnings, based on the verification results (i.e., whether error information needs to be returned).
[0132] The data verification layer in the embodiment of the present application is described in detail below.
[0133] (1) Usage. Figure 6 , Figure 6 Schematic diagram of the data verification method provided in the embodiment of the present application. Figure 6 As shown, the data verification layer includes a data verification rule part and a data verification logic part. After the business gateway layer obtains the business data from the upper layer, it transfers the business data to the data verification logic part; the data verification rule part transfers the data verification rules to the data verification logic part; in this way, the data verification logic part can perform data verification on the business data based on the data verification rules.
[0134] Here, the data verification rules may come from the definition of the data structure, so that the definition of the data structure and the data verification rules can be relatively integrated; the data verification rules may also come from a third-party configuration source to achieve configuration-based changes to the data verification rules.
[0135] (2) Implementation of data verification logic. The implementation of data verification logic includes: step 1) obtaining the field value of each field in the business data; step 2) for each field, executing the logic of whether the field value of the field is legal.
[0136] Step 1) See Figure 7 , Figure 7 It is a schematic diagram of the process of obtaining the field value of the business data provided by the embodiment of the present application. Here, when obtaining the field value of each field in the business data, the reflection capability provided by the Pb protocol is used. Using the reflection capability of the Pb protocol, the field value can be obtained according to the field name of each field in the business data. Specifically, 1. Deserialize the business data to obtain the protobuf.message data structure of the Pb protocol; 2. Use the reflection interface provided by the Pb protocol to convert the protobuf.message data structure into a protoreflect.message data structure; 3. Use the MessageDescriptor interface provided by protoreflect.message to obtain the corresponding field value in combination with the field name of each field in the business data.
[0137] Step 2) is divided into two stages. 1. Parsing stage: Parse the string of the incoming data verification rule. The parsed data verification rule is logically understandable and has a preset verification rule data structure. 2. Execution stage: Execute the parsed data verification rule using the verification executor.
[0138] (3) Input of data verification rules.
[0139] First, see Figure 8 , Figure 8 : This is a schematic diagram for obtaining data verification rules provided in an embodiment of the present application. Here, in the Protobuf file, the data verification rules are written together with the Message data structure definition, so that while the Message data structure can be defined in Protobuf through the custom option function provided by Protobuf, the data verification rules can be defined in the custom option of the Message data structure. In practical applications, defining the data structure and the data verification rules in the Protobuf file at the same time can achieve the integration of the data structure definition and the data verification rule definition.
[0140] Among them, the method of adding data verification rules in the Pb protocol used by the business is as follows: 1) Reference the common Pb protocol provided in the embodiment of the present application in the Pb protocol used by the business, and define an extension field of Message named check in the common Pb protocol; 2) After referencing the common Pb protocol, an extension field named check can be defined in Mmessage, so that the data structure constructed according to this Message can obtain the extension field.
[0141] In some other embodiments, the data verification rules defined in the Pb protocol may also be implemented using the annotations of the Pb protocol, that is, the data verification rules are defined in the annotations of the Pb protocol.
[0142] Second, see Fig. 9 , Fig. 9 It is a schematic diagram for obtaining the data verification rules provided in the embodiment of the present application. Here, in the Protobuf file, only the Message data structure is defined. The data verification rules can be configured on a third party to obtain a data verification rule library, so that the required data verification rules can be obtained from the data verification rule library. In this way, the data verification rules can be flexibly modified as needed, and the business can reasonably choose according to the applicable scenario.
[0143] 4) Design of data verification rules. In some examples, the verification rule syntax for defining data verification rules provided in the embodiments of the present application may be as follows:
[0144] 1) The basic syntax of each data verification rule is: [data verification rule]: [error information returned after the data verification rule is hit]. Here, when the data verification rule is hit, it means that the business data verification fails, and the corresponding error information is returned;
[0145] 2) In the data verification rule, use the method of "$field name.subfield name" to obtain the field to be verified;
[0146] 3) Four arithmetic operations and comparison operations, such as: +, -, *, / , ==, !=, >, <;
[0147] 4) Predefined functions. Here, you need to use the @ prefix when using a predefined function, such as: @is_empty($firstSub), which means taking out the firstSub field and returning true if it is empty;
[0148] 5) AND, OR, NOT logical combination functions;
[0149] 6) Array traversal function. For example, to retrieve a specific element from an array, you can use the [serial number] method; in addition, if you need to traverse the array, you can define it in a similar way as for...range;
[0150] 7) Deserialization function. Here, the deserialization verification function receives two parameters, one is the string to be deserialized, and the other is the full name of the Message to be deserialized. The function will obtain the Message type according to the full name of the Message, deserialize the string into the Message, and obtain the data verification rules from the Message for verification.
[0151] 8) Extract verification function. Here, it is possible to support defining a data verification function in a data verification rule, and determining the function's input parameters and verification rules. The use of # at the beginning indicates that a custom data verification function is used. The specific verification rules in the data verification function are the same as the other verification rules mentioned above, except that it can use the $input parameter method to obtain the input parameters and further perform verification.
[0152] In practical applications, the definition of data validation rules may include data validation rules and error messages in form, and may include arithmetic comparison, logical operations, compound logic extraction, array processing, deserialization processing and other functions in content. Different design methods may be adopted in design. The form, content, and design method are not limited here.
[0153] (5) Analysis and execution of data verification rules.
[0154] See also Fig.10 , Fig.10 It is a processing diagram of the data verification rules provided by the embodiment of the present application. Here, the parsing and execution of the data verification rules include three steps. Among them, the first step is: to parse the multiple verification rules read in into a single verification rule, and then further parse and execute the single verification rule. The second step is: according to the grammatical design of the verification rule, analyze the composition of the single verification rule, and parse the single verification rule into a syntax tree. Specifically, the verification rule can be split into expressions and operators that conform to the verification rule to form a syntax tree. Among them, the expression includes references to field values and constants according to the field name; the operator includes arithmetic operators, logical operators and function calls. The third step is: organize the syntax tree into a reverse Polish notation, and the executor reads in the operator and the corresponding number of expressions for calculation. Among them, the arithmetic operator and the logical operator can be executed according to the logic of the arithmetic operation and the logical operation, and the function call operation needs to obtain the function to be executed according to the function name, and execute it through the function call.
[0155] Applying the above embodiments of the present application, 1) the embodiment of the present application puts the definition of the data structure and the data verification rules in the Pb protocol, which reduces the difficulty of understanding the Pb data structure, so that other users of the Pb protocol can understand the definition of the data structure and the legal form of the data structure at a glance. 2) The embodiment of the present application maintains the data verification rules of the business data in the Pb protocol. Compared with the solution of hard-coding the data verification rules into the business code, if the data verification rules change or the business content increases, etc., the data verification rules need to be modified. At this time, only the data verification rules defined in the Pb protocol need to be updated. In this way, the dispersion of the verification logic is reduced, the maintainability of the verification logic is enhanced, the development efficiency is greatly improved, the development time is saved, and the problems such as online operation bugs caused by business code changes are reduced. 3) The embodiment of the present application is based on the Message data structure of the Pb protocol, and defines the overall verification rules, which are not limited to single-field verification, and can implement the verification logic of the associated fields in the data structure, such as: and, or, non-logical combination functions, intersection and difference verification logic, definition of verification functions and verification after deserialization, etc. (see the above 4) Design of data verification rules for details). In this way, by performing overall verification on the Message data structure, complex verification logic can be supported, which greatly expands the scope of data verification rules and can implement verification logic for multi-field verification.
[0156] The following is a description of an exemplary structure of the data verification device 555 provided in the embodiment of the present application implemented as a software module. In some embodiments, Figure 2 As shown, the software modules stored in the data verification device 555 of the memory 550 may include: a determination module 5551, which is used to determine the target data structure of the business data from at least one data structure when receiving the business data of the target business, wherein different data structures are predefined with corresponding data verification rules; an acquisition module 5552, which is used to obtain the target data verification rules predefined for the target data structure; a parsing module 5553, which is used to parse the target data verification rules to obtain the parsed data verification rules; a verification module 5554, which is used to use the parsed data verification rules to perform data verification on the business data to obtain the verification result of the business data; wherein the verification result is used to execute the business logic of the target business on the business data based on the verification result.
[0157] In some embodiments, the target data structure includes a target field, which is used to define data verification rules for the target data structure; the acquisition module 5552 is also used to parse the business data to determine the target field value of the target field; and use the target field value as a target data verification rule predefined for the target data structure.
[0158] In some embodiments, the target data structure includes a target field, which is used to store indication information of the data verification rules of the target data structure; the acquisition module 5552 is also used to parse the business data, determine the target field value of the target field, and the target field value is the indication information; obtain the data verification rules indicated by the indication information; and use the data verification rules indicated by the indication information as predefined target data verification rules for the target data structure.
[0159] In some embodiments, the acquisition module 5552 is also used to obtain annotation information edited for the target data structure when defining the target data structure; extract annotation data verification rules edited for the target data structure from the annotation information; and use the annotation data verification rules as predefined target data verification rules for the target data structure.
[0160] In some embodiments, the acquisition module 5552 is also used to obtain the correspondence between the data structure and the data verification rule; based on the correspondence, the data verification rule corresponding to the target data structure is obtained from a data verification rule library including a plurality of the data verification rules; and the data verification rule corresponding to the target data structure is used as a predefined target data verification rule for the target data structure.
[0161] In some embodiments, when the target data verification rule includes a single verification rule, the parsing module 5553 is also used to obtain the verification rule syntax of the target data verification rule; based on the verification rule syntax, the target data verification rule is parsed to obtain a verification rule syntax tree of the target data verification rule, and the verification syntax tree includes a verification expression and a verification operator that conforms to the target data verification rule; based on the verification expression and the verification operator, the parsed data verification rule is generated.
[0162] In some embodiments, the parsing module 5553 is also used to convert the verification syntax tree into a target expression in a target form based on the verification expression and the verification operator, and use the target expression as the parsed data verification rule.
[0163] In some embodiments, when the target data verification rule includes multiple sub-verification rules, the parsing module 5553 is also used to split the target data verification rule to obtain each of the sub-verification rules, and perform the following processing on each of the sub-verification rules: obtain the verification rule syntax of the sub-verification rule; based on the verification rule syntax, parse the sub-verification rule to obtain the verification rule syntax tree of the sub-verification rule, and the verification syntax tree includes a verification expression and a verification operator that conforms to the sub-verification rule; based on the verification expression and the verification operator, generate the parsed sub-verification rule of the sub-verification rule; wherein the parsed sub-verification rules of each of the sub-verification rules constitute the parsed data verification rule.
[0164] In some embodiments, the verification module 5554 is also used to parse the business data to determine the field value of the field to be verified in the business data; use the parsed data verification rule to verify the field value of the field to be verified to obtain the verification result of the business data.
[0165] In some embodiments, the verification module 5554 is also used to parse the business data to obtain the various fields included in the business data; obtain the field name of each field; determine the field to be checked in the business data according to the field name of each field and the parsed data verification rules, and obtain the field value of the field to be checked.
[0166] In some embodiments, when the post-parsed data verification rules include multiple post-parsed verification rules and the number of the fields to be checked is multiple, the verification module 5554 is also used to perform the following processing for each of the post-parsed verification rules: determine the field group to be checked corresponding to the post-parsed verification rule, and the field group to be checked includes at least one of the fields to be checked; use the post-parsed verification rule to verify the field value of the field to be checked in the field group to be checked to obtain the field group verification result of the field group to be checked; based on the field group verification results corresponding to each of the post-parsed verification rules, determine the verification result of the business data.
[0167] In some embodiments, the verification module 5554 is also used to perform data verification on the business data using the post-parsed data verification rule, and after obtaining the verification result of the business data, when the verification result indicates that the business data verification has failed, obtain the verification alarm strategy of the business data; and perform alarm processing on the verification result based on the verification alarm strategy.
[0168] By applying the above-mentioned embodiments of the present application, corresponding data verification rules are predefined for each data structure of the business data. When the business data of the target business is received, the target data verification rules predefined for the target data structure of the business data are obtained, and then the target data verification rules are parsed to implement the verification of the business data using the parsed data verification rules, so that the data verification of the business data can be implemented before the business logic is executed for the business data. In this way, it is only necessary to predefine the corresponding data verification rules for each data structure, and there is no need to write the verification code of the data verification rules and hard-code the verification code into the business logic code, which simplifies the implementation logic of the data verification, improves the flexibility of the data verification rules, facilitates the maintenance and reuse of the data verification rules, and improves the development efficiency of the data verification.
[0169] The embodiment of the present application also provides a computer program product, which includes computer executable instructions, and the computer executable instructions are stored in a computer readable storage medium. The processor of the electronic device reads the computer executable instructions from the computer readable storage medium, and the processor executes the computer executable instructions, so that the electronic device executes the data verification method provided in the embodiment of the present application.
[0170] An embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the processor will execute the data verification method provided by the embodiment of the present application.
[0171] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
[0172] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0173] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0174] As an example, computer executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0175] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A data verification method, characterized in that: The method comprises: When receiving the service data of the target service, determining the target data structure of the service data from at least one data structure, each of the data structures being predefined with a corresponding data verification rule; Obtaining a target data verification rule predefined for the target data structure; Parsing the target data verification rule to obtain a parsed data verification rule; The parsed data verification rule is used to perform data verification on the business data to obtain a verification result of the business data, so as to execute the business logic of the target business on the business data based on the obtained verification result.
2. The method according to claim 1, characterized in that The target data structure includes a target field, and the target field is used to define a data verification rule of the target data structure; The obtaining of a target data verification rule predefined for the target data structure includes: Parsing the business data to determine a target field value of the target field; The target field value is used as a target data verification rule predefined for the target data structure.
3. The method according to claim 1, characterized in that The target data structure includes a target field, and the target field is used to store indication information of a data verification rule of the target data structure; The obtaining of a target data verification rule predefined for the target data structure includes: Parse the business data to determine a target field value of the target field, wherein the target field value is the indication information; Obtaining the data verification rule indicated by the instruction information; The data verification rule indicated by the indication information is used as a target data verification rule predefined for the target data structure.
4. The method according to claim 1, characterized in that The obtaining of a target data verification rule predefined for the target data structure includes: Acquire annotation information edited for the target data structure when defining the target data structure; Extracting annotation data verification rules edited for the target data structure from the annotation information; The annotation data verification rule is used as a target data verification rule predefined for the target data structure.
5. The method according to claim 1, characterized in that The obtaining of a target data verification rule predefined for the target data structure includes: Obtain the correspondence between data structure and data verification rules; Based on the corresponding relationship, obtaining a data verification rule corresponding to the target data structure from a data verification rule library including a plurality of the data verification rules; The data verification rule corresponding to the target data structure is used as a target data verification rule predefined for the target data structure.
6. The method according to claim 1, characterized in that When the target data verification rule includes a single verification rule, parsing the target data verification rule to obtain the parsed data verification rule includes: Obtaining the verification rule syntax of the target data verification rule; Based on the verification rule syntax, the target data verification rule is parsed to obtain a verification rule syntax tree of the target data verification rule, wherein the verification syntax tree includes a verification expression and a verification operator that conforms to the target data verification rule; The parsed data verification rule is generated based on the verification expression and the verification operator.
7. The method according to claim 6, characterized in that The generating the parsed data verification rule based on the verification expression and the verification operator includes: Based on the verification expression and the verification operator, the verification syntax tree is converted into a target expression in a target form, and the target expression is used as the parsed data verification rule.
8. The method according to claim 1, characterized in that When the target data verification rule includes multiple sub-verification rules, parsing the target data verification rule to obtain the parsed data verification rule includes: The target data verification rule is split to obtain each of the sub-verification rules, and the following processing is performed on each of the sub-verification rules: Obtaining the verification rule syntax of the sub-verification rule; Based on the verification rule syntax, the sub-verification rule is parsed to obtain a verification rule syntax tree of the sub-verification rule, wherein the verification syntax tree includes a verification expression and a verification operator that conforms to the sub-verification rule; Based on the verification expression and the verification operator, the parsed sub-verification rules of the sub-verification rules are generated; wherein the parsed sub-verification rules of each of the sub-verification rules constitute the parsed data verification rule.
9. The method according to claim 1, characterized in that The adopting the parsed data verification rule to perform data verification on the business data to obtain the verification result of the business data includes: Parsing the business data to determine the field value of the field to be checked in the business data; The parsed data verification rule is adopted to verify the field value of the field to be verified to obtain the verification result of the business data.
10. The method according to claim 9, characterized in that The parsing of the business data to determine the field value of the field to be checked in the business data includes: Parsing the business data to obtain various fields included in the business data; Get the field name of each of the fields; According to the field name of each field and the parsed data verification rule, the field to be verified in the business data is determined, and the field value of the field to be verified is obtained.
11. The method according to claim 9, characterized in that When the parsed data verification rule includes multiple parsed verification rules and the number of the to-be-verified fields is multiple, the parsed data verification rule is used to verify the field value of the to-be-verified field to obtain the verification result of the business data, including: For each of the post-parsed verification rules, the following processing is performed respectively: determining a field group to be verified corresponding to the post-parsed verification rule, the field group to be verified includes at least one field to be verified; using the post-parsed verification rule, verifying the field value of the field to be verified in the field group to be verified, and obtaining a field group verification result of the field group to be verified; Based on the field group verification results corresponding to each of the parsed verification rules, the verification results of the business data are determined.
12. The method according to claim 1, characterized in that After the business data is verified by using the parsed data verification rule and a verification result of the business data is obtained, the method further includes: When the verification result indicates that the business data verification fails, obtaining a verification alarm strategy for the business data; Based on the verification alarm strategy, an alarm process is performed on the verification result.
13. A data verification device, characterized in that: The device comprises: A determination module, configured to determine, when receiving the business data of a target business, a target data structure of the business data from at least one data structure, wherein different data structures are predefined with corresponding data verification rules; An acquisition module, used for acquiring a target data verification rule predefined for the target data structure; A parsing module, used to parse the target data verification rule to obtain the parsed data verification rule; The verification module is used to use the parsed data verification rule to perform data verification on the business data to obtain the verification result of the business data, so as to execute the business logic of the target business on the business data based on the obtained verification result.
14. An electronic device, characterized in that: The electronic device comprises: A memory for storing computer executable instructions; A processor, configured to implement the data verification method according to any one of claims 1 to 12 when executing the computer executable instructions stored in the memory.
15. A computer-readable storage medium storing computer-executable instructions, characterized in that: When the computer executable instructions are executed by a processor, the data verification method according to any one of claims 1 to 12 is implemented.
16. A computer program product comprising computer executable instructions, characterized in that: When the computer executable instructions are executed by a processor, the data verification method according to any one of claims 1 to 12 is implemented.
