Recursive traversal-based tree structure data introduction method and system
Through the recursive traversal of tree structure data introduction method, the inefficiency and error-prone problems of traditional methods when dealing with complex hierarchical relational data is solved, efficient and accurate data introduction is achieved, stack overflow is avoided, and data integrity and system stability are ensured.
Patent Information
- Application Number
- CN202510557578.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-07-29
AI Technical Summary
Traditional tree structure data introduction methods are inefficient and prone to errors when processing complex hierarchical relational data. Iterative methods may cause stack overflow, while manual configuration is time-consuming and labor-intensive and prone to human errors.
Using a recursive traversal method, select the target node, judge its parent node relationship, split the top-level and leaf nodes, adjust the tree information, and insert it into the target tree in batches to avoid stack overflow and ensure data integrity and accuracy.
It improves the efficiency of data introduction, avoids stack overflow problems, ensures data integrity and accuracy, improves the stability and reliability of the system, and realizes the precise construction of hierarchical relationships and the clarity of data structures.
Smart Images

Figure CN120386784A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for introducing tree structured data based on recursive traversal. Background Art
[0002] The statements in this section merely provide background art related to the present invention and do not necessarily constitute prior art.
[0003] The tree structure intuitively displays the hierarchical relationships between data, much like a lush tree with its trunk, branches, and leaves corresponding to different levels of data. In a file system, it clearly depicts the inclusion relationship between folders and files; in an organizational structure, it accurately presents the subordinate relationships between departments and positions. This structure is not only easy to understand and operate, but also provides a clear logical framework for computer data processing, making data storage, retrieval, and management more efficient and organized.
[0004] However, iteration and manual configuration, two common import methods, can barely cope with small-scale, simple-level data. However, once the data scale increases and the hierarchical relationships become complex, they will show significant limitations, specifically in the following aspects: (1) The iterative method gradually builds a tree structure through cyclic recursion. When the amount of data is small, it can complete the task in an orderly manner according to the preset rules. However, when the data scale expands rapidly, reaching tens of thousands or even more nodes, the iterative process has no end. Each recursive call consumes a certain amount of system resources. As the recursive depth increases, the stack space is gradually filled up, which is very likely to cause a stack overflow and cause the program to crash. (2) Manual configuration relies entirely on manual operation. Workers need to input data nodes one by one and clarify the hierarchical relationship between them. This is not only an extremely time-consuming and labor-intensive task, but also prone to human errors. When faced with large amounts of data, workers may easily miss certain data nodes or repeatedly introduce the same data due to fatigue or negligence. In addition, manual configuration makes it difficult to ensure the consistency and integrity of the data. Once an error occurs in a certain link, it may cause chaos in the entire tree structure, thereby affecting subsequent data processing and analysis. Summary of the Invention
[0005] In order to address the deficiencies of the prior art, the present invention provides a method and system for introducing tree-structured data based on recursive traversal. Through recursive traversal, tree-structured data is introduced efficiently and accurately, solving the problems of low efficiency and proneness to errors in traditional methods when processing complex hierarchical relationship data, avoiding the stack overflow problem that may be caused by traditional iterative methods, and improving the efficiency of data introduction.
[0006] To achieve the above object, the present invention adopts the following technical solutions: In the first aspect, the present invention provides a method for introducing tree - structured data based on recursive traversal.
[0007] A method for introducing tree - structured data based on recursive traversal includes the following processes: Select a node of the target tree as the target node; When the tree - structured data to be introduced is a lower - level of the target node, use the target node as the target parent node; When the tree - structured data to be introduced is at the same level as the target node and the target node is not the top - level node, use the parent node of the target node as the target parent node; Traverse the tree - structured data to be introduced, split the top - level node and leaf nodes of the tree - structured data to be introduced, according to the determined target parent node, adjust the tree information of the top - level node of the tree - structured data to be introduced, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top - level node; Batch - insert the adjusted tree information of the top - level node and the adjusted tree information of the leaf nodes into the target tree.
[0008] As a further limitation of the first aspect of the present invention, determining whether the target node is the top - level node includes: determining whether the target node has a parent node. When there is a parent node, the target node is not the top - level node; when there is no parent node, the target node is the top - level node.
[0009] As a further limitation of the first aspect of the present invention, the tree - structured data to be introduced includes three types, namely: continuously - connected branch - structured data, non - continuously - connected branch - structured data, and a combination of multiple branch - structured data including cross - level branches and cross - branch branches; For cross - level nodes, choose to find the grandfather node upward to build a tree connection, or choose to be directly the top - level node of the tree - structured data to be introduced.
[0010] As a further limitation of the first aspect of the present invention, when the tree - structured data to be introduced is a lower - level of the target node, adjusting the tree information of the top - level node of the tree - structured data to be introduced according to the determined target parent node includes: The level number of the top - level node is the level number of the target node plus 1, the parent ID of the top - level node is the ID of the target node, the sequence number of the top - level node is the increment of the sequence number of the next - level node of the target node, the classification code of the top - level node is the increment of the classification code of the next - level node of the target node, and if the top - level node is a terminal node, the identifier of the terminal node is 1.
[0011] As a further limitation of the first aspect of the present invention, when the tree - structured data to be introduced is at the same level as the target node, according to the determined target parent node, adjust the tree information of the top - level node of the tree - structured data to be introduced, including: The level number of the top - level node is the level number of the target node, the parent ID of the top - level node is the parent ID of the target node, the sequence number of the top - level node is incremented from the sequence number of the target node, the classification code of the top - level data is incremented from the classification code of the target node, and if the top - level node is a leaf node, the identifier of the leaf node is 1.
[0012] As a further limitation of the first aspect of the present invention, recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top - level node, including: Adjust each node in the first level of the leaf node according to the top - level node. The level number of each node in the first level is the level of the top - level node plus 1, the parent node ID of each node in the first level is the top - level node ID, the sequence number of each node in the first level is the sorting of the level data, the classification code of each node in the first level is incremented from the classification code of the parent node, and if the node in the first level is a leaf node, the leaf node identifier is 1; Adjust the next level according to the first level, and so on recursively until the adjustment of each level is completed.
[0013] In the second aspect, the present invention provides a tree - structured data introduction system based on recursive traversal.
[0014] A tree - structured data introduction system based on recursive traversal includes: A target node selection unit, configured to: select a node of the target tree as the target node; A subordinate node judgment unit, configured to: when the tree - structured data to be introduced is a subordinate of the target node, use the target node as the target parent node; A same - level node judgment unit, configured to: when the tree - structured data to be introduced is at the same level as the target node and the target node is not the top - level node, use the parent node of the target node as the target parent node; A tree information adjustment unit, configured to: traverse the tree - structured data to be introduced, split the top - level node and leaf nodes of the tree - structured data to be introduced, adjust the tree information of the top - level node of the tree - structured data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top - level node; A tree batch insertion unit, configured to: batch - insert the adjusted tree information of the top - level node and the adjusted tree information of the leaf nodes into the target tree.
[0015] In a third aspect, the present invention provides a tree structure data introduction system based on recursive traversal.
[0016] A tree structure data introduction system based on recursive traversal, comprising: a front end and a back end that communicate with each other; The front end is configured to: select a node of a target tree as a target node, select the tree structure data to be introduced, provide interactive selection options for cross-level nodes, support selecting to find the grandfather node upward to build a tree connection, and also support directly selecting as the top node of the tree structure data to be introduced; The back end is configured to: traverse the tree structure data to be introduced, split the top node and leaf nodes of the tree structure data to be introduced, adjust the tree information of the top node of the tree structure data to be introduced according to the determined target parent node, recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top node, and batch insert the adjusted tree information of the top node and the adjusted tree information of the leaf nodes into the target tree.
[0017] In a fourth aspect, the present invention provides a computer device, comprising: a processor and a computer-readable storage medium; The processor is adapted to execute a computer program; The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, it implements the tree structure data introduction method based on recursive traversal as described in the first aspect of the present invention.
[0018] In a fifth aspect, the present invention provides a computer-readable storage medium that stores a computer program, and the computer program is adapted to be loaded and executed by a processor to implement the tree structure data introduction method based on recursive traversal as described in the first aspect of the present invention.
[0019] Compared with the prior art, the beneficial effects of the present invention are: 1. The present invention innovatively proposes a tree structure data introduction method based on recursive traversal, traverses the tree structure data to be introduced, splits the top node and leaf nodes of the tree structure data to be introduced, adjusts the tree information of the top node of the tree structure data to be introduced according to the determined target parent node, recursively traverses and adjusts the tree information of each leaf node according to the adjusted tree information of the top node, and realizes the depth traversal and introduction of tree structure data through recursive traversal, avoiding the stack overflow problem that may be caused by traditional iterative methods and improving the efficiency of data introduction.
[0020] 2. The present invention innovatively proposes a tree-structured data introduction method based on recursive traversal. By checking the parent node identifier and child node list of the node, the integrity and accuracy of the data are ensured, and the problems of data omission or repeated introduction are avoided. Through exception handling logic and batch processing logic, the stability and reliability of the system are improved, ensuring the smooth progress of the data introduction process.
[0021] 3. The present invention innovatively proposes a method for introducing tree-structured data based on recursive traversal. When the tree-structured data to be introduced is the subordinate of the target node, the level number of the top-level node is the level number of the target node plus 1, the parent ID of the top-level node is the ID of the target node, the sequence number of the top-level node is self-incremented by the sequence number of the next-level node of the target node, and the classification code of the top-level node is self-incremented by the classification code of the next-level node of the target node. If the top-level node is the end node, the identifier of the end node is 1, which realizes the precise construction of hierarchical relationships, ensures the clarity of data structure, dynamically adjusts the sequence number and classification code, optimizes the orderliness of data organization, and achieves significant technical effects in hierarchical relationship construction, parent-child relationship connection, data orderliness and data operation flexibility. It provides strong technical support for the dynamic introduction and efficient management of tree-structured data, and strongly promotes the improvement of software development and data management levels in related fields.
[0022] 4. The present invention innovatively proposes a method for introducing tree-structured data based on recursive traversal. When the tree-structured data to be introduced is at the same level as the target node, the number of levels of the top-level node is the number of levels of the target node, the parent ID of the top-level node is the parent ID of the target node, the sequence number of the top-level node is the self-incrementing sequence number of the target node, the classification code of the top-level class data is the self-incrementing classification code of the target node, and if the top-level node is the terminal node, the identifier of the terminal node is 1, which realizes precise alignment of the hierarchical relationship, ensures structural consistency, seamless inheritance of the parent-child relationship, and maintains the logical integrity of the data.
[0023] 5. The present invention innovatively proposes a tree structure data introduction method based on recursive traversal, which adjusts each node in the first level of the leaf node according to the top-level node. The level number of each node in the first level is the level of the top-level node plus 1, the parent node ID of each node in the first level is the top-level node ID, the sequence number of each node in the first level is the sorting of the hierarchical data, and the hierarchical code of each node in the first level is the self-incrementing hierarchical code of the parent node. If the node in the first level is the end node, the end node is identified as 1, and the next level is adjusted according to the first level. This recursion is repeated until the adjustment of each level is completed, thereby ensuring the accuracy of the parent-child relationship, strengthening the data association link, adapting to dynamic business changes, being able to quickly respond to demand adjustments, and improving data processing efficiency and stability.
[0024] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0026] Figure 1 A schematic diagram of a flow chart of a method for importing tree-structured data based on recursive traversal provided in Example 1 of the present invention; Figure 2 A schematic diagram of a tree structure data import system based on recursive traversal provided in Example 2 of the present invention; Figure 3 A schematic diagram illustrating the working principle of a tree structure data introduction system based on recursive traversal provided in Example 3 of the present invention; Figure 4 A schematic diagram of a computer device provided in Example 4 of the present invention. DETAILED DESCRIPTION
[0027] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0028] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which the present invention belongs.
[0029] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0030] Example 1: As described in the background technology, traditional tree-structured data introduction methods often use iterative or manual configuration methods. These methods are inefficient and error-prone when processing large amounts of data or complex hierarchical relationships. Especially when the data scale is large, iterative methods may cause problems such as stack overflow, while manual configuration is time-consuming and labor-intensive and prone to omission or repeated introduction of data.
[0031] In view of the problems existing in the existing solutions, this implementation method proposes a method for introducing tree-structured data based on recursive traversal, which is used to traverse tree-structured data. This method realizes the depth traversal of tree-structured data by defining the base case (i.e., the termination condition) and the recursive case (i.e., the recursive process). During the traversal process, the algorithm will check the child nodes of each node and continue to recursively call itself as needed until all nodes are traversed. More specifically, it includes: adjusting the tree information of the top-level nodes and leaf nodes of the tree-structured data to be introduced according to the target parent node, and continuously recursively calling through a method encapsulated internally to adjust the tree information level by level until the last level is adjusted.
[0032] This implementation method defines the node attributes of tree-structured data, such as attributes including node ID, parent node ID, list of child nodes (a list composed of each child node), etc. Through these attributes, the hierarchical relationship between data can be clearly expressed; during the traversal process, according to the parent node ID and list of child nodes of the node, the recursive introduction of data is realized. When a certain node is traversed, first check whether the node already exists in the target tree. If not, add it to the target tree and continue to recursively introduce its child nodes; during the recursive process, add exception handling logic to handle possible error situations, such as data inconsistency, a department cannot be the parent level of a unit, etc.
[0033] More specifically, the method for introducing tree-structured data, as Figure 1 shown, includes the following process: S1: Select a node of the target tree as the target node; S2: When the tree-structured data to be introduced is at a lower level of the target node, use the target node as the target parent node; S3: When the tree-structured data to be introduced is at the same level as the target node and the target node is not the top-level node, use the parent node of the target node as the target parent node; S4: Traverse the tree-structured data to be introduced, split the top-level nodes and leaf nodes of the tree-structured data to be introduced, adjust the tree information of the top-level nodes of the tree-structured data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level nodes; S5: Batch insert the adjusted tree information of the top-level nodes and the adjusted tree information of the leaf nodes into the target tree.
[0034] In step S1 of this implementation method, the tree to which the tree-structured data to be introduced belongs is tree A, the target tree is tree B, and the target node of this implementation method is a node in tree B; it should be noted that when tree B is empty, this target node may not exist (for example, it can be a virtual node).
[0035] In step S3 of this implementation method, determining whether the target node is a top-level node includes: determining whether the target node has a parent node. When there is a parent node, the target node is not a top-level node. When there is no parent node, the target node is a top-level node.
[0036] In steps S2 and S3 of this implementation method, the tree-structured data to be introduced includes three types, namely: (1) vertically coherent branch structure data; (2) vertically incoherent branch structure data; (3) a combination of multiple branch structure data, including cross-level branches and cross-branch branches; for the nodes of cross-level branches, choose to find the grandfather node upward to build a tree connection, or choose to directly be the top-level node of the tree-structured data to be introduced.
[0037] In steps S2 and S3 of this implementation method, based on business needs, two sets of tree information are defined for each node: (1) including hierarchical code (four-digit separation), level, and whether it is a terminal node; (2) parent node ID, level, whether it is a terminal node, and sequence number.
[0038] In step S4 of this implementation method, traverse the tree-structured data to be introduced, and split the top-level node and leaf nodes (leaf nodes include sub-level nodes and cross-level sub-level nodes) of the tree-structured data to be introduced; among them, in the tree-structured data to be introduced, the node that cannot find a parent node is the top-level node; in the tree-structured data to be introduced, the node that can find a direct parent node is the sub-level node; in the tree-structured data to be introduced, the node that cannot find a direct parent node but can find a grandfather node is the cross-level sub-level node.
[0039] In steps S4 and S5 of this implementation method, use JPA (Java Persistence API) transaction management to ensure data consistency. And business checks are added, such as a department must have a unit as its superior node, and a unit cannot be the subordinate node of a department (department and unit are business concepts). When a business exception or system exception occurs (such as not meeting business requirements or data inconsistency), an exception is thrown, the JPA transaction automatically rolls back, the introduction is terminated, and the exception information is recorded using the log.
[0040] In step S4 of this implementation manner, when the tree-structured data to be introduced is a lower level of the target node, according to the determined target parent node, adjust the tree information of the top-level node of the tree-structured data to be introduced, including: The level number of the top-level node is the level number of the target node plus 1, the parent ID of the top-level node is the ID of the target node, the sequence number of the top-level node is incremented from the sequence number of the next-level node of the target node, the classification code of the top-level node is incremented from the classification code of the next-level node of the target node. If the top-level node is a leaf node (not the parent node of any node), the identifier of the leaf node is 1.
[0041] In step S4 of this implementation manner, when the tree-structured data to be introduced is at the same level as the target node, according to the determined target parent node, adjust the tree information of the top-level node of the tree-structured data to be introduced, including: The level number of the top-level node is the level number of the target node, the parent ID of the top-level node is the parent ID of the target node, the sequence number of the top-level node is incremented from the sequence number of the target node, the classification code of the top-level data is incremented from the classification code of the target node. If the top-level node is a leaf node (not the parent node of any node), the identifier of the leaf node is 1.
[0042] In step S4 of this implementation manner, recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level node, including: Adjust each node in the first level of the leaf node according to the top-level node. The level number of each node in the first level is the level of the top-level node plus 1, the parent node ID of each node in the first level is the ID of the top-level node, the sequence number of each node in the first level is the sorting of the level data, the classification code of each node in the first level is incremented from the classification code of the parent node. If the node in the first level is a leaf node, the identifier of the leaf node is 1; Adjust the next level according to the first level, and so on recursively until the adjustment of each level is completed.
[0043] In step S5 of this implementation manner, batch insert the data to be introduced into the table corresponding to Tree B. After the introduction is successful, perform asynchronous record security auditing (that is, record this action in the audit table according to the format required by the business).
[0044] Embodiment 2: As Figure 2 shown, this implementation manner provides a tree-structured data introduction system based on recursive traversal, including: A target node selection unit, configured to: select a node of the target tree as the target node; The lower - level node judgment unit is configured to: when the tree - structured data to be introduced is a lower - level node of the target node, use the target node as the target parent node; The same - level node judgment unit is configured to: when the tree - structured data to be introduced is a same - level node of the target node and the target node is not the top - level node, use the parent node of the target node as the target parent node; The tree - structure information adjustment unit is configured to: traverse the tree - structured data to be introduced, split the top - level node and leaf nodes of the tree - structured data to be introduced, adjust the tree - structure information of the top - level node of the tree - structured data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree - structure information of each leaf node according to the adjusted tree - structure information of the top - level node; The tree - structure batch insertion unit is configured to: batch - insert the tree - structure information of the adjusted top - level node and the tree - structure information of the adjusted leaf nodes into the target tree.
[0045] The specific working processes of the above - mentioned units are described in the introduction of Embodiment 1 and will not be elaborated here.
[0046] It can be understood that the above - mentioned units can be separately or all combined into one or several other units to form, or some of them can be further split into multiple smaller units with more specific functions to form, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above - mentioned units are divided based on logical functions. In actual applications, the function of one unit can also be realized by multiple units, or the functions of multiple units can be realized by one unit. In other embodiments of the present application, the system can also include other units. In actual applications, these functions can also be assisted by other units and can be realized by the cooperation of multiple units.
[0047] According to another embodiment of the present application, the system of this embodiment can be constructed and the method of Embodiment 1 of the present application can be realized by running a computer program (including program code) that can execute the respective steps involved in the corresponding method described in Embodiment 1 on a general - purpose computing device such as a computer including processing elements such as a central processing unit (CPU), an access storage medium (Random Access Memory, RAM), a read - only storage medium (ReadOnly Memory, ROM), etc. and storage elements. The computer program can be recorded on a computer - readable recording medium, for example, and loaded into the above - mentioned computing device through the computer - readable recording medium and run therein.
[0048] Embodiment 3: As Figure 3As shown in the figure, a tree - structured data introduction system based on recursive traversal includes a front - end and a back - end that communicate with each other; The front - end is configured to: select a node of the target tree as the target node, select the tree - structured data to be introduced, provide interactive selection options for cross - level nodes, support selecting to find the grandfather node upward to build a tree connection, and also support directly selecting it as the top - level node of the tree - structured data to be introduced; The back - end is configured to: traverse the tree - structured data to be introduced, split the top - level nodes and leaf nodes of the tree - structured data to be introduced, adjust the tree information of the top - level nodes of the tree - structured data to be introduced according to the determined target parent node, recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top - level nodes, and batch - insert the adjusted tree information of the top - level nodes and the adjusted tree information of the leaf nodes into the target tree.
[0049] For the detailed working process, see the introduction in Embodiment 1, which will not be elaborated here.
[0050] Embodiment 3: As Figure 4 shown in the figure, this implementation provides an electronic device, which includes a processor 1001, a communication interface 1002, and a computer - readable storage medium 1003. Among them, the processor 1001, the communication interface 1002, and the computer - readable storage medium 1003 can be connected through a bus or other means.
[0051] Among them, the communication interface 1002 is used for receiving and sending data, the computer - readable storage medium 1003 can be stored in the memory of the electronic device, the computer - readable storage medium 1003 is used for storing computer programs, the computer programs include program instructions, and the processor 1001 is used for executing the program instructions stored in the computer - readable storage medium 1003.
[0052] The processor 1001 (or CPU (Central Processing Unit, central processor)) is the computing core and control core of the electronic device, which is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to implement the corresponding method flow or corresponding function.
[0053] The processor 1001 is configured to execute the following process: Select a node of the target tree as the target node; When the tree - structured data to be introduced is the subordinate of the target node, use the target node as the target parent node; When the tree-structured data to be introduced is at the same level as the target node and the target node is not the top-level node, use the parent node of the target node as the target parent node; Traverse the tree-structured data to be introduced, split the top-level node and leaf nodes of the tree-structured data to be introduced, adjust the tree information of the top-level node of the tree-structured data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level node; Batch insert the adjusted tree information of the top-level node and the adjusted tree information of the leaf nodes into the target tree.
[0054] For the specific process, see the introduction in Embodiment 1 and will not be elaborated here.
[0055] Embodiment 4: This implementation provides a computer-readable storage medium (Memory). A computer-readable storage medium is a memory device in an electronic device for storing programs and data. It can be understood that the computer-readable storage medium here can include both the built-in storage medium in the electronic device and, of course, the extended storage medium supported by the electronic device. The computer-readable storage medium provides a storage space, and this storage space stores the processing system of the electronic device.
[0056] Moreover, one or more instructions suitable for being loaded and executed by the processor are also stored in this storage space. These instructions can be one or more computer programs (including program codes). It should be noted that the computer-readable storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory; optionally, it can also be at least one computer-readable storage medium located far from the aforementioned processor.
[0057] In one embodiment, one or more instructions are stored in the computer-readable storage medium; the processor loads and executes one or more instructions stored in the computer-readable storage medium to implement the following process: Select a node of the target tree as the target node; When the tree-structured data to be introduced is at the lower level of the target node, use the target node as the target parent node; When the tree-structured data to be introduced is at the same level as the target node and the target node is not the top-level node, use the parent node of the target node as the target parent node; Traverse the tree-structured data to be introduced, split the top-level nodes and leaf nodes of the tree-structured data to be introduced, adjust the tree information of the top-level nodes of the tree-structured data to be introduced according to the determined target parent nodes, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level nodes; Batch insert the adjusted tree information of the top-level nodes and the adjusted tree information of the leaf nodes into the target tree.
[0058] For the specific process, please refer to the introduction in Embodiment 1 and will not be elaborated here.
[0059] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the present application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0060] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (for example, coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (for example, infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data processing device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, solid state disk (SSD)), etc.
[0061] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any adjustments, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for introducing tree - structured data based on recursive traversal, characterized in that, Including the following processes: Select a node of the target tree structure as the target node; When the tree structure data to be introduced is a lower level of the target node, use the target node as the target parent node; When the tree structure data to be introduced is at the same level as the target node and the target node is not the top-level node, use the parent node of the target node as the target parent node; Traverse the tree structure data to be introduced, split the top-level node and leaf nodes of the tree structure data to be introduced, adjust the tree information of the top-level node of the tree structure data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level node; Batch insert the adjusted tree information of the top-level node and the adjusted tree information of the leaf nodes into the target tree structure.
2. The method for introducing tree structure data based on recursive traversal according to claim 1, wherein Determining whether the target node is the top-level node includes: determining whether the target node has a parent node. When there is a parent node, the target node is not the top-level node. When there is no parent node, the target node is the top-level node.
3. The method for introducing tree structure data based on recursive traversal according to claim 1, wherein The tree structure data to be introduced includes three types, namely: continuously connected branch structure data, discontinuously connected branch structure data, and a combination of multiple branch structure data including cross-level branches and cross-branch branches; For cross-level nodes, select to find the grandparent node upward to build a tree connection, or select to directly be the top-level node of the tree structure data to be introduced.
4. The method for introducing tree structure data based on recursive traversal according to claim 1, wherein When the tree structure data to be introduced is a lower level of the target node, adjusting the tree information of the top-level node of the tree structure data to be introduced according to the determined target parent node includes: The level number of the top-level node is the level number of the target node plus 1, the parent ID of the top-level node is the ID of the target node, the sequence number of the top-level node is incremented by the sequence number of the next-level node of the target node, the classification code of the top-level node is incremented by the classification code of the next-level node of the target node, and if the top-level node is a terminal node, the identifier of the terminal node is 1.
5. The method for introducing tree structure data based on recursive traversal according to claim 1, wherein When the tree structure data to be introduced is at the same level as the target node, adjusting the tree information of the top-level node of the tree structure data to be introduced according to the determined target parent node includes: The level number of the top-level node is the level number of the target node, the parent ID of the top-level node is the parent ID of the target node, the sequence number of the top-level node is incremented by the sequence number of the target node, the classification code of the top-level data is incremented by the classification code of the target node, and if the top-level node is a terminal node, the identifier of the terminal node is 1.
6. The method for introducing tree structure data based on recursive traversal according to any one of claims 1-5, wherein Recursively traverse and adjust the tree information of each leaf node according to the tree information of the adjusted top-level node, including: Adjust each node in the first level of the leaf node according to the top-level node. The level number of each node in the first level is the level of the top-level node plus 1. The parent node ID of each node in the first level is the top-level node ID. The sequence number of each node in the first level is the sorting of the level data. The classification code of each node in the first level is the increment of the classification code of the parent node. If the node in the first level is a terminal node, the terminal node flag is 1; Adjust the next level according to the first level, and so on recursively until the adjustment of each level is completed.
7. A tree structure data introduction system based on recursive traversal, characterized in that, Including: A target node selection unit, configured to: select a node of the target tree as the target node; A subordinate node judgment unit, configured to: when the tree structure data to be introduced is a subordinate of the target node, use the target node as the target parent node; A sibling node judgment unit, configured to: when the tree structure data to be introduced is a sibling of the target node and the target node is not a top-level node, use the parent node of the target node as the target parent node; A tree information adjustment unit, configured to: traverse the tree structure data to be introduced, split the top-level node and leaf nodes of the tree structure data to be introduced, adjust the tree information of the top-level node of the tree structure data to be introduced according to the determined target parent node, and recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level node; A tree batch insertion unit, configured to: batch insert the adjusted tree information of the top-level node and the adjusted tree information of the leaf nodes into the target tree.
8. A tree - structured data introduction system based on recursive traversal, characterized in that, Including: A front end and a back end that communicate with each other; The front end is configured to: select a node of the target tree as the target node, select the tree structure data to be introduced, provide interactive selection options for cross-level nodes, support selecting to find the grandfather node upward to build a tree connection, and also support directly selecting as the top-level node of the tree structure data to be introduced; The back end is configured to: traverse the tree structure data to be introduced, split the top-level node and leaf nodes of the tree structure data to be introduced, adjust the tree information of the top-level node of the tree structure data to be introduced according to the determined target parent node, recursively traverse and adjust the tree information of each leaf node according to the adjusted tree information of the top-level node, and batch insert the adjusted tree information of the top-level node and the adjusted tree information of the leaf nodes into the target tree.
9. A computer device, characterized in that, Including: A processor and a computer-readable storage medium; The processor is adapted to execute a computer program; The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, it implements the method for introducing tree structure data based on recursive traversal according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program is adapted to be loaded and executed by a processor to perform the method for introducing tree-structured data based on recursive traversal according to any one of claims 1 to 6.