A complex structure data assembly method and system based on interface componentization
Patent Information
- Application Number
- CN202211632034.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-19
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2042-12-19
AI Technical Summary
[0005]本发明所要解决的技术问题是:传统的接口数据装配方法不够灵活且无法适用于结构复杂的数据,本发明目的在于提供一种基于接口组件化的复杂结构数据装配方法及系统,基于JsonPath的二次封装开发,通过构建数据结构模板在接口组件结构化的前提下,对数据进行配置化装配,能够灵活配置数据来源,取值路径,处理逻辑,支持数组套数组,数组套实体等各种的复杂数据结构,装配的模板化更能直观反映出数据的准确处理逻辑
[0040]本发明提供的一种基于接口组件化的复杂结构数据装配方法及系统;基于JsonPath的二次封装开发,通过构建数据结构模板在接口组件结构化的前提下,对数据进行配置化装配,能够灵活配置数据来源,取值路径,处理逻辑,支持数组套数组,数组套实体等各种的复杂数据结构,装配的模板化更能直观反映出数据的准确处理逻辑;本方案不仅能够灵活配置最终输出数据的格式,字段,还能够支持数组中存在数组,数组中包含实体等的复杂结构。本方案整个数据结构模板和待装配数据均按层级存入redis中,减少与数据库交互,减少耗时,提升性能。
Smart Images

Figure CN116302046B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software development technology, and specifically to a method and system for assembling complex structured data based on interface componentization. Background Technology
[0002] In existing technologies, interface data assembly methods generally fall into two categories:
[0003] One approach is to assign values to individual entities: if the input parameter of the interface is an entity or an object class, the value is assigned directly by hard coding to each individual attribute. The disadvantage of this approach is that it is not flexible enough; when a single attribute value needs to be modified, it can only be solved by hard coding.
[0004] Another method is to assign values by configuring the retrieval path: assigning values by configuring specific key values. The principle of this method is to place the entire data in the form of key-value pairs in a container, and retrieve the corresponding value by configuring the key value for assembly. The disadvantage of this method is that it cannot be applied to data with complex structures. When the data contains arrays within arrays, this method cannot modify and assemble specific keys under the array. Summary of the Invention
[0005] The technical problem this invention aims to solve is that traditional interface data assembly methods are not flexible enough and cannot be applied to complex data structures. The purpose of this invention is to provide a complex data assembly method and system based on interface componentization. Based on secondary encapsulation development of JsonPath, by constructing data structure templates under the premise of interface component structuring, data is assembled in a configurable manner. It can flexibly configure data sources, value paths, and processing logic, and supports various complex data structures such as arrays nested within arrays and arrays nested within entities. The templated assembly can more intuitively reflect the accurate data processing logic.
[0006] This invention is achieved through the following technical solution:
[0007] This solution provides a method for assembling complex structured data based on interface components, including:
[0008] Construct a data structure template;
[0009] Store the data structure template and the data to be assembled into Redis;
[0010] Extract the data structure template from Redis and assemble the data to be assembled based on the data structure template.
[0011] The working principle of this solution: Traditional interface data assembly methods are not flexible enough and cannot be applied to complex data structures. The purpose of this invention is to provide a method and system for assembling complex data structures based on interface componentization. Based on secondary encapsulation development of JsonPath, by constructing data structure templates under the premise of interface component structuring, data is assembled in a configurable manner. It can flexibly configure data sources, value paths, and processing logic, and supports various complex data structures such as arrays containing arrays and arrays containing entities. The templated assembly can more intuitively reflect the accurate data processing logic. This solution can not only flexibly configure the format and fields of the final output data, but also support complex structures such as arrays containing arrays and arrays containing entities.
[0012] Traditional methods require interaction with the database to complete data assembly, which takes a long time. This solution stores the entire data structure template and the data to be assembled in Redis hierarchically, reducing interaction with the database, reducing time consumption, and improving performance.
[0013] A further optimization is to use fields as attributes when constructing the data structure template. These fields include: field name, field type, field meaning, validity, default value, interface name, value retrieval path, parent field, template identifier, and mapping rules.
[0014] A further optimization involves storing the data to be assembled in Redis using the following methods:
[0015] Obtain the data to be assembled and its interface data, wherein the interface data includes the interface and the value retrieval path;
[0016] Each interface data to be assembled is numbered, and the number and interface are used as the primary key to store it in Redis.
[0017] Further optimizations include methods for storing data structure templates in Redis, such as:
[0018] Obtain the template data and identifier data of each data structure template, and store the template data and identifier data in Redis according to their correspondence; the template data includes one or more single template data.
[0019] A further optimized approach involves assembling the data to be assembled, including:
[0020] S1, extract the corresponding template data based on the template identifier;
[0021] S2, retrieve the relevant data in the data to be assembled where the parent field is empty;
[0022] S3 assembles data for each individual template data entry.
[0023] The further optimized solution is that S3 includes the following sub-steps:
[0024] S31, determine whether the field type of the current single template data is array type, object type or basic data type;
[0025] S32, For array-type data, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and retrieve the data attribute under the interface as the new data source;
[0026] Using the parent field as the current field, retrieve a list of all child fields of the current field; check if the child field list is empty. If it is, add the corresponding value A to the parent field name; otherwise, return S31 and use the child fields and the new data source as the current single template data. (For array-type data, if the objects within it are still array data, the data assembly can be completed by looping down from the top level according to the above method.)
[0027] For object-type data, retrieve a list of all subfields of the current field, return S31, and use the subfields as the current single template data;
[0028] For basic data classes, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and put the corresponding value A into the field name to be sent.
[0029] A further optimization scheme is that the basic data classes include: Integer integer data, Bigdecimal monetary data, and String string data.
[0030] A further optimization scheme includes a process for basic data classes: if the interface of the data to be assembled has an input data source, then the corresponding value A is retrieved based on the input data source and the value retrieval path.
[0031] This solution provides a complex structure data assembly system based on interface componentization, used to implement the complex structure data assembly method based on interface componentization described above, including:
[0032] The template building module is used to build data structure templates;
[0033] The storage module is used to store data structure templates and data to be assembled into Redis;
[0034] The assembly module is used to extract data structure templates from Redis and assemble the data to be assembled based on the data structure templates.
[0035] A further optimized solution is that the assembly module includes:
[0036] The first extraction unit is used to extract the corresponding template data based on the template identifier;
[0037] The second extraction unit is used to extract relevant data from the data to be assembled where the parent field is empty.
[0038] Assembly unit is used to assemble individual template data one by one.
[0039] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0040] This invention provides a method and system for assembling complex data structures based on interface components. Based on secondary encapsulation of JsonPath, it constructs data structure templates and, under the premise of structured interface components, configurably assembles data. This allows for flexible configuration of data sources, value paths, and processing logic, supporting various complex data structures such as arrays containing arrays and arrays containing entities. The template-based assembly more intuitively reflects the accurate data processing logic. This solution not only allows for flexible configuration of the format and fields of the final output data but also supports complex structures such as arrays containing arrays and arrays containing entities. The entire data structure template and the data to be assembled are stored hierarchically in Redis, reducing database interaction, reducing time consumption, and improving performance. Attached Figure Description
[0041] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be considered as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort. In the drawings:
[0042] Figure 1 This is a flowchart illustrating a method for assembling complex structured data based on interface components.
[0043] Figure 2 Configure template example A-1;
[0044] Figure 3 Configure template example A-2;
[0045] Figure 4 The result of assembling the data is shown in the figure. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.
[0047] Traditional interface data assembly methods are not flexible enough and cannot be applied to complex data structures. The present invention provides the following embodiments to solve the problems of the prior art:
[0048] Example 1
[0049] This embodiment provides a method for assembling complex structured data based on interface components, such as... Figure 1 As shown, it includes:
[0050] I. Constructing a data structure template;
[0051] When constructing a data structure template, fields are used as attributes. These fields include: field name, field type, field meaning, validity, default value, interface name, value retrieval path, parent field, template identifier, and mapping rules.
[0052] As shown in the table below:
[0053] his_field Send field name field_type Field type field_mean Field meaning Is_effective Is it effective? default_value default value Interface_name Interface Name source_field value path superior_field Parent field template_identy Template identifier mapping_rules Mapping rules
[0054] 2. Store the data structure template and the data to be assembled into Redis;
[0055] Methods for storing data to be assembled into Redis include:
[0056] Obtain the data to be assembled and its interface data, wherein the interface data includes the interface and the value retrieval path;
[0057] Each interface data to be assembled is numbered, and the number and interface are used as the primary key to store it in Redis.
[0058] Methods for storing data structure templates in Redis include:
[0059] Obtain the template data and identifier data of each data structure template, and store the template data and identifier data in Redis according to their correspondence; the template data includes one or more single template data.
[0060] 3. Extract the data structure template from Redis and assemble the data to be assembled according to the data structure template.
[0061] Methods for assembling data to be assembled include:
[0062] S1, extract the corresponding template data based on the template identifier;
[0063] S2, retrieve the relevant data in the data to be assembled where the superior field is empty; (an empty superior_field indicates that the data will be at the top level)
[0064] S3 assembles data for each individual template data entry.
[0065] S3 includes the following sub-steps:
[0066] S31, determine whether the field type of the current single template data is array type, object type or basic data type;
[0067] S32, for array-type data List, retrieve the corresponding value A according to the interface and value path of the data to be assembled, and retrieve the data property under the interface as the new data source;
[0068] Using the parent field as the current field, retrieve a list of all child fields of the current field; check if the list of child fields is empty. If it is, put the corresponding value A into the parent field name his_field; otherwise, return S31 and use the child fields and the new data source as the current single template data.
[0069] For object-type data, retrieve the list of all subfields of the current field, return S31, and use the subfields as the current single template data;
[0070] For basic data classes, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and put the corresponding value A into the field name his_field.
[0071] The basic data classes include: Integer (integer type), Bigdecimal (amount type), and String (string type).
[0072] For basic data classes, the process also includes: if the interface of the data to be assembled has an input data source, then the corresponding value A is retrieved based on the input data source and the value retrieval path.
[0073] Traditional interface data assembly methods are inflexible and unsuitable for complex data structures. This invention aims to provide a method and system for assembling complex data structures based on interface componentization. Developed using secondary encapsulation of JsonPath, it constructs data structure templates to configurate data assembly within the structured interface components. This allows for flexible configuration of data sources, value paths, and processing logic, supporting various complex data structures such as nested arrays and arrays containing entities. The template-based assembly more intuitively reflects the accurate data processing logic. This solution not only allows for flexible configuration of the final output data format and fields but also supports complex structures such as arrays containing arrays and arrays containing entities.
[0074] Example 2
[0075] This embodiment provides a complex structure data assembly system based on interface componentization, used to implement the complex structure data assembly method based on interface componentization described in the previous embodiment, including:
[0076] The template building module is used to build data structure templates;
[0077] The storage module is used to store data structure templates and data to be assembled into Redis;
[0078] The assembly module is used to extract data structure templates from Redis and assemble the data to be assembled based on the data structure templates.
[0079] The assembly module includes:
[0080] The first extraction unit is used to extract the corresponding template data based on the template identifier;
[0081] The second extraction unit is used to extract relevant data from the data to be assembled where the parent field is empty.
[0082] Assembly unit is used to assemble individual template data one by one.
[0083] The data structure template uses fields as attributes. These fields include: field name, field type, field meaning, validity status, default value, interface name, value retrieval path, parent field, template identifier, and mapping rules. Example template configuration A implemented according to this embodiment is as follows: Figure 2 and Figure 3 As shown in the figure, the data related to the submitted field names, field types, field meanings, validity status, default values, interface names, value retrieval paths, parent fields, template identifiers, and mapping rules in the data structure template are as follows:
[0084] The list of fields to be sent includes: kehu_classification, kehu_classification_type, kehu_classification_result, kehu_classification_tips, Qvdaoshuxing, channel_cp_code, channel_pp_code, and channel_sq_type.
[0085] The corresponding field types are: list, String, String, String, Object, String, String, String.
[0086] The corresponding field meanings are as follows: Customer Category Array, Customer Category Type, Customer Category Result, Category Hints, Channel Attribute Information, Product Code, Channel Code, and Call Type.
[0087] The corresponding valid list is: 1, 1, 1, 1, 1, 1, 1, 1.
[0088] The corresponding default values are: -, -, -, -, -, -1234567, -1234567, -1234567.
[0089] The corresponding interface names are: Interface 1, -, -, -, -, Interface 2, Interface 2 and Interface 2.
[0090] The corresponding value path list includes: $.kehuClassification.(*), $.Classification_type, $.classification_result, $.classification_tips, -, $.productCode, $.channel, and $.unionLoanRouteType.
[0091] The corresponding parent field list is: shengqingxinxi, kehu_classification, kehu_classification, kehu_classification, -, Qvdaoshuxing, Qvdaoshuxing, and Qvdaoshuxing.
[0092] The corresponding template identifiers are: union_ilog, union_ilog, union_ilog, union_ilog, union_ilog, union_ilog, union_ilog, union_ilog, and union_ilog.
[0093] The assembly unit performs the following process:
[0094] S31, determine whether the field type of the current single template data is array type, object type or basic data type;
[0095] S32, for array-type data List, retrieve the corresponding value A according to the interface and value path of the data to be assembled, and retrieve the data property under the interface as the new data source;
[0096] Using the parent field as the current field, retrieve a list of all child fields of the current field; check if the list of child fields is empty. If it is, put the corresponding value A into the parent field name his_field; otherwise, return S31 and use the child fields and the new data source as the current single template data.
[0097] For object-type data, retrieve the list of all subfields of the current field, return S31, and use the subfields as the current single template data;
[0098] For basic data classes, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and put the corresponding value A into the field name his_field.
[0099] Assembly result sample Figure 4 As shown.
[0100] This solution implements data assembly templates, which can flexibly configure data sources, value retrieval paths, field names sent, and special processing methods. Through templates, the various situations of data assembly can be clearly reflected. Data is assembled from the top level down, which can support complex data structures and complex situations such as arrays containing arrays and arrays containing objects.
[0101] The entire template data is stored in Redis hierarchically, reducing database interactions, reducing time consumption, and improving performance.
[0102] Those skilled in the art will understand that all or part of the steps in the above facts and methods can be implemented by a program instructing related hardware. The program or the program described herein can be stored in a computer-readable storage medium. When the program is executed, it includes the following steps: constructing a data structure template; storing the data structure template and the data to be assembled in Redis; extracting the data structure template from Redis and assembling the data to be assembled according to the data structure template. The storage medium can be ROM / RAM, magnetic disk, optical disk, etc.
[0103] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for assembling complex structured data based on interface componentization, characterized in that, include: Construct a data structure template; Store the data structure template and the data to be assembled into Redis; Extract the data structure template from Redis and assemble the data to be assembled based on the data structure template; When constructing a data structure template, fields are used as attributes. These fields include: field name, field type, field meaning, validity, default value, interface name, value retrieval path, parent field, template identifier, and mapping rules. Methods for assembling data to be assembled include: S1, extract the corresponding template data based on the template identifier; S2, retrieve the relevant data in the data to be assembled where the parent field is empty; the empty parent field indicates that the data is at the top level. S3, assembles data for each individual template data item; S3 includes the following sub-steps: S31, determine whether the field type of the current single template data is array type, object type or basic data type; S32, For array-type data, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and retrieve the data attribute under the interface as the new data source; Using the parent field as the current field, retrieve a list of all child fields of the current field; check if the child field list is empty. If it is, put the corresponding value A into the parent field name; otherwise, return S31 and use the child fields and the new data source as the current single template data. For object-type data, retrieve a list of all subfields of the current field, return S31, and use the subfields as the current single template data; For basic data classes, retrieve the corresponding value A based on the interface and value path of the data to be assembled, and put the corresponding value A into the field name to be sent.
2. The method for assembling complex structure data based on interface componentization according to claim 1, characterized in that, Methods for storing data to be assembled into Redis include: Obtain the data to be assembled and its interface data, wherein the interface data includes the interface and the value retrieval path; Each interface data to be assembled is numbered, and the number and interface are used as the primary key to store it in Redis.
3. The method for assembling complex structure data based on interface componentization according to claim 2, characterized in that, Methods for storing data structure templates in Redis include: Obtain the template data and identifier data of each data structure template, and store the template data and identifier data in Redis according to their correspondence; the template data includes one or more single template data.
4. The method for assembling complex structure data based on interface componentization according to claim 1, characterized in that, The basic data classes include: Integer (integer type), Bigdecimal (amount type), and String (string type).
5. The method for assembling complex structure data based on interface componentization according to claim 1, characterized in that, For basic data classes, the process also includes: if the interface of the data to be assembled has an input data source, then the corresponding value A is retrieved based on the input data source and the value retrieval path.
6. A complex structure data assembly system based on interface componentization, characterized in that, The method for assembling complex structured data based on interface componentization as described in any one of claims 1-5 includes: The template building module is used to build data structure templates; The storage module is used to store data structure templates and data to be assembled into Redis; The assembly module is used to extract data structure templates from Redis and assemble the data to be assembled based on the data structure templates.
7. A complex structure data assembly system based on interface componentization according to claim 6, characterized in that, The assembly module includes: The first extraction unit is used to extract the corresponding template data based on the template identifier; The second extraction unit is used to extract relevant data from the data to be assembled where the parent field is empty. Assembly unit is used to assemble individual template data one by one.
Citation Information
Patent Citations
XML (extensible markup language) message processing method and XML message processing device
CN102622444A