Method and device for managing resources based on tree structure, electronic equipment and program product
By creating a tree structure template table in the database and adding tree component dependencies, the resource management performance problem of large tree structure depth and width is solved, and efficient resource management and query performance improvement is achieved.
Patent Information
- Application Number
- CN202411777612.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-03-28
AI Technical Summary
When the tree structure is deep and width is large, a multi-table scheme needs to maintain a large number of tables, resulting in an increase in data management and query complexity; while a single-table scheme requires multiple join operations, affecting data query and maintenance performance.
By creating database tables in the database based on the tree structure template, adding tree component dependencies, and inheriting the tree table entity class of the tree node's entity class, and executing management logic for resources based on the tree function class.
It realizes efficient and high-performance management of complex tree structure resources, improves data query and maintenance performance, and reduces system management complexity.
Smart Images

Figure CN119719107A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of system setting, and in particular to a method, device, electronic device and program product for managing resources based on a tree structure. Background Art
[0002] When resource grouping management is performed based on a tree structure, a multi-table solution or a single-table solution is usually used. The multi-table solution maintains each layer of the tree structure in a table and establishes the parent-child relationship between nodes in the tree structure through foreign keys; the single-table solution maintains the tree structure in a table using an adjacency list.
[0003] However, when the depth and width of the tree structure are large, for multi-table solutions, the number of tables that need to be maintained increases, resulting in increased complexity in data management and query; for single-table solutions, multiple connection operations are required to obtain the entire tree structure, affecting the query and maintenance performance of the data. Summary of the invention
[0004] According to various embodiments of the present application, a method, device, electronic device and program product for managing resources based on a tree structure are provided; efficient and high-performance management of resources in a complex tree structure table can be achieved.
[0005] In a first aspect, the present application provides a method for managing resources based on a tree structure, the method comprising: creating a database table in a database based on a tree structure template, the database table being used to store tree structure resources; adding a dependency on a tree component for the tree structure resources, the tree component being configured with management logic for the resources; after the tree table entity class in the database table inherits the entity class of the tree node, executing management logic for the resources based on the tree function class in the tree component.
[0006] Through the above method, a database table is created based on the tree structure template to store tree structure resources. For tree structure resources, tree component dependencies are added, and efficient management of resources is achieved based on the tree function class encapsulated by the tree component dependencies. For complex tree structure resources, the query and maintenance performance of data can be improved by adding tree component dependencies and the inheritance of the tree table entity class to the tree node entity class, thereby improving the system management performance. It has strong ease of use and practicality.
[0007] In a possible implementation manner of the first aspect, creating a database table in a database based on a tree structure template includes:
[0008] Based on the template of the tree structure, the attribute fields and / or index fields of each tree node in the tree structure are created in the database to obtain a database table.
[0009] In a possible implementation of the first aspect, for a resource in a tree structure, adding a dependency of a tree component includes:
[0010] For tree-structured resources, add dependencies of tree structure management components, database operation components, distributed identification components, and code generation tool library; among them, tree components include tree structure management components, database operation components, distributed identification components, and code generation tool library.
[0011] In a possible implementation manner of the first aspect, after the tree table entity class in the database table inherits the entity class of the tree node, the method further includes:
[0012] Define the characteristic attributes of the tree table entity class and add index fields; the tree table entity class supports defining characteristic attributes and adding index fields.
[0013] In a possible implementation manner of the first aspect, executing management logic on resources based on a tree function class in a tree component includes:
[0014] Based on the calling class information, the target tree table entity class corresponding to the tree function class is determined; based on the component method of the tree function class, the management logic is executed on the resources in the target tree table where the target tree table entity class is located.
[0015] In a possible implementation of the first aspect, the tree table entity class includes encapsulation of resources of the tree structure; the management logic includes at least one of querying tree node logic, adding tree node logic, updating tree node logic and deleting tree node logic; the tree function class is an encapsulation of the management logic.
[0016] In a possible implementation manner of the first aspect, before executing the management logic on the resource based on the tree function class in the tree component, the method further includes:
[0017] Based on business needs, a pre-check is performed on the resource, and the pre-check includes: at least one of a parameter check, a name check, and a distributed lock check; after executing the management logic, the method further includes:
[0018] Perform post-operation on the resource, where the post-operation includes at least one of updating characteristic attributes and releasing distributed locks.
[0019] In a second aspect, the present application provides a device for managing resources based on a tree structure, comprising:
[0020] Create a tree table unit, which is used to create a database table in the database based on the tree structure template, and the database table is used to store tree structure resources;
[0021] Add dependency unit, which is used to add tree component dependency for tree structure resources. The tree component dependency is configured with resource management logic.
[0022] The resource management unit is used to execute management logic on resources based on the tree function class in the component dependency after the tree table entity class in the database table inherits the entity class of the tree node.
[0023] In a third aspect, the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements any one of the methods described in the first aspect when executing the computer program.
[0024] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements any one of the methods described in the first aspect.
[0025] In a fifth aspect, the present application provides a computer program product, which, when executed on a device, enables the device to execute any of the methods described in the first aspect.
[0026] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0028] Figure 1 A schematic diagram of a tree structure provided in an embodiment of the present application;
[0029] Figure 2 A schematic diagram of the implementation process of the method for managing resources based on a tree structure provided in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a device for managing resources based on a tree structure provided in an embodiment of the present application;
[0031] Figure 4 A structural schematic diagram of an electronic device is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0032] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.
[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0034] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0035] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0036] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0037] The grouping management of resources based on tree structure is widely used in various management systems. Tree structure grouping management makes resource search, classification and other management operations more convenient by grouping resources according to hierarchical relationships.
[0038] At present, multi-table solutions or single-table solutions are usually used to implement tree-structured resource management. When the tree depth and width are large, there may be problems with poor management performance; the existing multi-table solutions or single-table solutions use a method of solidifying the meaning of tree nodes, which is not convenient for business expansion. In addition, different application platforms implement a set of tree-structured resource management solutions, with different structures and implementation specifications, redundant codes, and difficult maintenance.
[0039] In response to the above technical problems, the embodiments of the present application provide a method and electronic device for managing resources based on a tree structure. The implementation of the tree structure is optimized by creating a database table, and the interface of the management method is encapsulated and standardized. A tree component corresponding to the tree structure function is provided, so that each platform has good performance and scalability of the tree structure during the resource management process, reduces repetitive function development work, and improves the correctness and maintainability of the code.
[0040] like Figure 1 , a schematic diagram of a tree structure provided by an embodiment of the present application. The tree structure includes tree nodes at different levels, and each tree node (hereinafter also referred to as a node) corresponds to corresponding attribute information, such as node identification, node name, node path and other information.
[0041] Among them, nodes at each level can correspond to resources at different levels; Figure 1 As shown, tree node 1 represents the resources of the first level, such as a management system; tree nodes 11 and 12 represent the resources of the second level, such as computers, printers, surveillance cameras and other equipment. The levels and nodes can be divided based on factors such as function, location or department.
[0042] Exemplarily, the above-mentioned management system can be an integrated management platform, which can include multiple subsystems, such as network, video, broadcasting, access control, parking lot, etc.; the integrated management platform can be the root node of the tree (such as tree node 1), and each subsystem can correspond to a tree node (such as tree node 11, tree node 12 and other subnodes), and the tree node corresponding to each subsystem can also include subnodes to represent the resources under the subsystem; the integrated management platform can uniformly manage and maintain the resources of multiple subsystems.
[0043] Accordingly, as the number or types of resources to be managed increase, the tree nodes may be expanded in the direction of tree width or tree depth, which is applicable to different resource management scenarios.
[0044] The implementation process of the method for managing resources based on a tree structure is introduced below through an embodiment.
[0045] like Figure 2 As shown, a schematic diagram of the implementation process of the tree structure-based resource management method provided in an embodiment of the present application is shown. The execution subject of the method can be a management system or an electronic device that performs resource management, and the method can include the following steps:
[0046] S201, based on the tree structure template, create a database table in the database, the database table is used to store tree structure resources.
[0047] In the embodiment of the present application, the tree structure template may be a logical structure template simulating a tree shape, such as Figure 1The tree structure shown has multiple tree nodes including a root node (such as tree node 1), child nodes (such as tree node 11), and leaf nodes (such as tree node 111). Each tree node may have zero or more child nodes and one parent node (except the root node).
[0048] Among them, in actual application scenarios, the tree structure template can correspond to the architecture of a group of resources to be managed. For example, in a management system, the device can be represented by the tree node 11 of the second level of the tree structure, and the broadcast material can be represented by the tree node 12 of the second level; when there are resources such as vehicles, the second level can also be expanded to have a tree node 13 to represent the vehicle; accordingly, for the tree node 11, its child nodes (such as tree node 111 and tree node 112) can respectively represent the subordinate resources included in the device, such as printers, computers and other resources, so that various resources can be grouped and managed based on the tree structure.
[0049] Exemplarily, the database table created based on the tree structure template is a basic structure for storing data (such as resource objects to be managed) in the database, and the database table may be a table representing the tree structure in the form of an adjacency list.
[0050] In some embodiments, creating a database table in a database based on the tree structure template includes:
[0051] Based on the template of the tree structure, the attribute fields and / or index fields of each tree node in the tree structure are created in the database to obtain a database table.
[0052] Table 1
[0053] Field Name type illustrate Remark id bigint(20) Node id, primary key PRIMARY KEY name varchar(128) Node Name NOT NULL, INDEX parent_id bigint(20) Parent node id NOT NULL, INDEX level_order decimal Sequence number between sibling nodes NOT NULL, INDEX path varchar(512) Node Path NOT NULL, INDEX has_child tinyint(1) Whether there are child nodes NOT NULL DEFAULT '0' created_time bigint Creation time NOT NULL updated_time bigint Modification time NOT NULL
[0054] As shown in Table 1, the database table consists of rows and columns. Each row represents a field, including information such as field name, type, description, and remarks, and each column represents the information recorded corresponding to each attribute of each node.
[0055] Among them, id is the unique identifier of each tree node, which is generated by the distributed identification id component; the name field supports users to name according to the application scenario, which is used to implement fuzzy search functions. For example, in the management system, for the management of device resources, the node name can be named printer, etc.; the parent_id field records the parent-child relationship of the node, which is used to implement the single-layer paging query function in the database. For example, within a specific level, all node data under the level can be viewed by paging, without loading the entire data set at one time. The level_order field records the sequence number between sibling nodes, which is used to implement the sorting function, such as Figure 1wherein, when a node is moved, the sequence number is the binary value of the sequence numbers of the previous and next nodes, and asynchronous reordering cannot be performed in time-sharing, that is, the new sequence number of the node after the move is the middle value of the sequence numbers of the previous and next nodes (such as the average value, etc., a new sequence number calculated based on the sequence numbers of the previous and next two nodes).
[0056] The path field records the id path from the root node to the parent node, which is used to quickly obtain the ancestor node list and quickly query the descendant node list through prefix matching, thereby achieving good performance node deletion, movement and other functions, avoiding recursive operations on large tree structures. The has_child field records whether the node has child nodes, which is used by front-end developers to quickly determine whether the node can be expanded.
[0057] For example, bigint is used to indicate the data type that can be stored in the field, indicating that very large integers can be stored, and 20 is used to indicate the character width when the field is displayed. varchar is used to indicate the data type that can be stored in the field, indicating that variable-length strings can be stored, and 128 or 512 is the maximum number of characters that can be stored in the string type field. decimal indicates that the field can store decimal data types. tinyint(1) is used to indicate that the data type that can be stored in the field is an integer data type, and the field is used to store very small integers, and 1 indicates the minimum display character width of the field.
[0058] Exemplarily, all management objects (tree nodes) in the tree structure are collectively referred to as resources. The nodes in the same tree are maintained through the same set of interfaces. For example, resources are managed and maintained through unified and standardized management operations (such as query, create, update, delete, etc.), without setting up a separate management interface for each resource type. The above management interfaces are directly reused, thereby reducing the data dimension at the management level, reducing management complexity, and improving versatility, so that the management system can flexibly adapt to the resource management needs of different businesses.
[0059] Correspondingly, in the process of creating a database table in the database, in addition to configuring the attribute fields of the tree node, corresponding index fields can also be created. For example, when the identifier of the index name is name_idx, the corresponding index row content can be type type and name name, that is, when the database executes a query involving the two attributes, the relevant data rows can be quickly found through the index; the index path_idx of the node path can contain the index row content of the path, and the index order_idx of the node sequence number can contain the index row content of the parent node identifier and the sequence number of the level.
[0060] For example, different database tables can be created for different business needs. By configuring the storage engine, default character set and comments of the database table, the category of the database table can be defined. For example, for a device group table, the storage engine used is defined as InnoDB, the default character set is utf8mb4, and the comment is a table for storing device group data; thereby ensuring efficient storage and retrieval of the database table, while ensuring the integrity of the data and the correct representation of the characters.
[0061] Accordingly, after defining a specific category of database tables, node data can also be preset according to business needs. For example, node data representing the root node can be inserted into the device grouping database table, and various attribute fields of the root node can be defined, such as identification ID, name, order in the hierarchical structure, etc.; thereby supporting management systems with hierarchical relationships.
[0062] In the Remarks column, PRIMARY KEY is used to indicate a unique primary key consisting of one or more fields, which is used to indicate the unique identifier of a node. NOT NULL is used to indicate that the field cannot be empty; INDEX is used to indicate that an index can be created for the field; DEFAULT'0' is used to indicate the attribute of the field, which is used to set the default value of the field. If no corresponding value is provided when setting the attribute of the node corresponding to the field, the database uses 0 as the value of the field.
[0063] S202, for tree-structured resources, add tree component dependencies, and the tree component is configured with resource management logic.
[0064] In the embodiment of the present application, the tree structure resource is data or objects organized in a tree structure in the database, and the tree component is a package that provides a general node definition and operation interface. Adding a tree component dependency is to introduce a component for processing tree structure resources (i.e., a tree component) into the management system, and provide a series of general functions and tools for displaying, operating, and traversing tree structure resources.
[0065] Exemplarily, dependencies are defined in the tree component, including a unique identifier of the resource management project created by the management system, a unique identifier of the database corresponding to the resource management project, a version number of the resource management project, and a scope of dependency (such as compile time, test time, and runtime), etc.; a set of functions or databases are provided for the resource management project for use by the code of the resource management project.
[0066] In some embodiments, for a resource of a tree structure, adding a dependency of a tree component includes:
[0067] For tree-structured resources, add dependencies of tree structure management components, database operation components, distributed identification components, and code generation tool library; among them, tree components include tree structure management components, database operation components, distributed identification components, and code generation tool library.
[0068] Exemplarily, the added tree component dependencies may include a first function of providing a unified access interface related to user groups or permission groups, a second function of providing database operations, a third function of providing a distributed system to generate a unique identification ID, and a code writing tool.
[0069] Among them, the first function is used to manage the access of user groups or permission groups to database tables; the second function is used to perform related operations on the database tables created in the database; the third function is used to generate the identifier of the database table or the new node when creating a database table or adding a new tree node to the database table; the code writing tool simplifies the generation of code in the entire management system (including entity classes, service classes, etc.), making the process of the management system creating a management mechanism for database tables more efficient and convenient.
[0070] S203, after the tree table entity class in the database table inherits the entity class of the tree node, management logic is executed on the resources based on the tree function class in the tree component.
[0071] In the implementation of this application, the tree table entity class encapsulates the resources stored in the database table and the operation methods for managing these resources configured by the tree component. The entity class of the tree node is used to represent the class of the node in the tree structure, and defines the properties and indexes of the node, such as the general group entity class AbstractGroupEntity. By making the tree table entity class of the database table inherit the entity class of the tree node, the resources and operation methods of the database table inherit the properties and indexes of the tree node.
[0072] Exemplarily, the tree function class in the tree component encapsulates the management logic related to the tree structure, such as traversing the tree, finding nodes, adding or deleting nodes, etc. Based on the methods provided by the tree function class, the resources in the database table are managed, such as adding new resources (as new nodes), deleting existing resources (nodes), or reorganizing resources (moving nodes), etc.
[0073] For example, the tree component encapsulates the common implementation method for tree structure resource operations in the common grouping service CommonGroupService class. When there is a business need to process resources stored in a database table, create a business tree function class that inherits the common grouping service class; through inheritance, the new business can reuse the methods defined in the CommonGroupService class, so that additional business logic can be added according to business needs. When the business tree function class inherits the common grouping service class, add a grouping entity GroupEntity annotation to mark that the common grouping service class is associated with the specified tree table entity; for example, the annotation contains the name of the associated entity class, so that the tree function class of the tree component can know the tree table entity class to be operated, that is, the managed object.
[0074] In some embodiments, the tree table entity class includes encapsulation of resources of the tree structure; the management logic includes at least one of query tree node logic, add tree node logic, update tree node logic and delete tree node logic; the tree function class is an encapsulation of the management logic.
[0075] In some embodiments, after the tree table entity class in the database table inherits the entity class of the tree node, the method further includes: defining characteristic attributes of the tree table entity class and adding index fields; the tree table entity class supports defining characteristic attributes and adding index fields.
[0076] For example, after the tree table entity class of the database table inherits the functions and attributes of the tree node entity class, in order to meet business needs or optimize database functions, the characteristic attributes of the tree table entity class can also be configured to describe or identify the characteristic information of resources in the database table. For example, when managing the departmental organizational structure, the department is used as a resource object for management, and the corresponding responsibilities, number of people and other characteristic attributes of the department can also be added. In order to improve query efficiency, index fields can also be added to the tree table entity class for rapid database location or retrieval of records to improve query efficiency.
[0077] For example, the device group entity class can be mapped to a target database table in the database through annotations. The device group entity class can inherit the general group entity class AbstractGroupEntity to represent the device group. The annotations provided by the tree component code generation tool library (such as the Lombok library) can generate readers, modifiers and other methods to simplify the amount of code. Composite indexes are defined through annotations, which are indexes composed of two or more attributes, to improve the query performance of the attribute.
[0078] In some embodiments, executing management logic on resources based on a tree function class in a tree component includes:
[0079] Based on the calling class information, the target tree table entity class corresponding to the tree function class is determined; based on the component method of the tree function class, the management logic is executed on the resources in the target tree table where the target tree table entity class is located.
[0080] Exemplarily, the calling class information may be information about the class of the method that triggers the tree function class, which is used to dynamically determine which target tree table entity class should be operated. For example, the calling class information may include the name of the target entity class, or an annotation may be used in the calling class information to specify an attribute of a resource to indicate the target entity class. Among them, by explicitly calling the component method of the tree function class, a call such as super.{method name} is displayed; the method name may be to create a node, update a node, delete a node, get a node, etc. For example, for the business of updating the node name, it is necessary to explicitly call the interface of the component method by the subclass.
[0081] Accordingly, when the component method is executed, the calling class information is read from the stack frame, and the target tree table entity class is obtained through the GroupEntity annotation, so as to execute the management logic for the resources of the target tree table.
[0082] In some embodiments, before executing the management logic on the resource based on the tree function class in the tree component, the method further comprises:
[0083] Based on business needs, pre-checks are performed on resources. The pre-checks include at least one of parameter checks, name checks, and distributed lock checks.
[0084] For example, before calling a component method, the business class will check whether the parameters passed to the component method are valid. For example, if the component method requires a non-empty string as a parameter, the business class will ensure that the string is not an empty string. This helps prevent the component method from throwing an exception or performing an incorrect operation due to receiving an invalid parameter.
[0085] Exemplarily, when the business involves creating or updating an entity with a unique name (such as a tree node), the business class checks whether the name has been used before calling the component method by querying a database or storage unit to confirm that no duplicate names exist.
[0086] Exemplarily, in a distributed system, a distributed lock is used to prevent conflicts caused by multiple threads concurrently modifying a resource (such as a resource in a tree structure). Before the business class calls a component method, the distributed lock is acquired, and after the lock is acquired, the component method continues to be executed. If the lock is not acquired, the lock continues to wait until the distributed lock is acquired and then the component method is executed.
[0087] Accordingly, after executing the management logic, the method further includes:
[0088] Perform post-operation on the resource, where the post-operation includes at least one of updating characteristic attributes and releasing distributed locks.
[0089] Exemplarily, after the component method is executed, the business class updates the characteristic attributes related to the business. For example, if the business involves updating the state of a node in a tree structure, the business class updates the state attribute of the node after the component method is successfully executed. Accordingly, if a distributed lock is acquired before calling the component method, the distributed lock is released after the component method is successfully executed, thereby allowing other threads to access and modify this resource.
[0090] For example, for the business of adding nodes, after executing the component method of adding nodes, the type information in the feature attributes is updated; for the business of deleting nodes, since the component method is not aware of the node type, the field of whether the parent node has child nodes is updated after executing the component method of deleting nodes.
[0091] The embodiments of the present application provide tree components and unified access interfaces by encapsulating general tree structures and operation methods. The components have good versatility and are applicable to a variety of business scenarios, such as the group management of audio materials by network broadcasting systems, the organization and management of company employees by access control and attendance systems, and the management of classrooms and classes by smart campus systems. With the help of tree components, businesses can more quickly implement rich and flexible resource management functions that are user-friendly and easy to use, such as group sorting and whole group migration, thereby improving user operating experience. The abstraction of the tree structure better supports business concept topology and has good scalability. For example, adding a "region" group above a "city" only requires adapting the front end without adjusting the back-end database and interface implementation. The tree structure design is optimized to support rich and efficient tree operations, solving the complexity problem of recursive operations when the tree size is large, thereby improving system performance.
[0092] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0093] Corresponding to the method for managing resources based on a tree structure provided in the above embodiment, Figure 3 A structural schematic diagram of a device for managing resources based on a tree structure provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0094] Reference Figure 3 , the device for managing resources based on a tree structure comprises:
[0095] A tree table creation unit 31 is used to create a database table in a database based on a tree structure template, and the database table is used to store resources of the tree structure;
[0096] A dependency adding unit 32 is used to add a tree component dependency to a resource of a tree structure, wherein the tree component dependency is configured with management logic for the resource;
[0097] The resource management unit 33 is used to execute management logic on resources based on the tree function class in the component dependency after the tree table entity class in the database table inherits the entity class of the tree node.
[0098] In a possible implementation, the tree table creation unit 31 is further used to create attribute fields and / or index fields of each tree node in the tree structure in the database based on the template of the tree structure to obtain the database table.
[0099] In one possible implementation, the dependency adding unit 32 is also used to add dependencies of a tree structure management component, a database operation component, a distributed identification component, and a code generation tool library for the resources of the tree structure; wherein the tree components include the tree structure management component, the database operation component, the distributed identification component, and the code generation tool library.
[0100] In a possible implementation, the resource management unit 33 is further used to define characteristic attributes of the tree table entity class and add index fields; the tree table entity class supports defining the characteristic attributes and adding index fields.
[0101] In a possible implementation, the resource management unit 33 is further used to determine the target tree table entity class corresponding to the tree function class based on the calling class information; and execute management logic on the resources in the target tree table where the target tree table entity class is located based on the component method of the tree function class.
[0102] In one possible implementation, the tree table entity class includes encapsulation of tree structure resources; the management logic includes at least one of query tree node logic, add tree node logic, update tree node logic and delete tree node logic; the tree function class is an encapsulation of the management logic.
[0103] In one possible implementation, the resource management unit 33 is also used to perform a pre-check on the resources based on business needs, and the pre-check includes: at least one of a parameter check, a name check, and a distributed lock check; the resource management unit 33 is also used to perform a post-operation on the resources, and the post-operation includes at least one of updating feature attributes and releasing distributed locks.
[0104] Through the embodiments of the present application, a database table is created based on a tree structure template to store tree structure resources. For the tree structure resources, tree component dependencies are added, and efficient management of resources is achieved based on the tree function class encapsulated by the tree component dependencies. For complex tree structure resources, the query and maintenance performance of data can be improved by adding tree component dependencies and inheriting the entity class of the tree node by the tree table entity class, thereby improving the system management performance.
[0105] Figure 4 A schematic diagram of the hardware structure of the electronic device 4 is shown.
[0106] like Figure 4 As shown, the electronic device 4 of this embodiment includes: at least one processor 40 ( Figure 4 Only one is shown), a memory 41, wherein the memory 41 stores a computer program 42 that can be run on the processor 40. When the processor 40 executes the computer program 42, the steps in the above method embodiment are implemented, such as Figure 2 Alternatively, when the processor 40 executes the computer program 42, the functions of the modules / units in the above-mentioned device embodiments are realized.
[0107] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 4. In other embodiments of the present application, the electronic device 4 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0108] The electronic device 4 may include, but is not limited to, a processor 40 and a memory 41. Those skilled in the art will appreciate that Figure 4 It is only an example of the electronic device 4 and does not constitute a limitation of the electronic device 4. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the server may also include an input sending device, a network access device, a bus, etc.
[0109] The processor 40 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0110] The processor 40 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 40 is a cache memory. The memory may store instructions or data that the processor 40 has just used or cyclically used. If the processor 40 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 40, and thus improves the efficiency of the system.
[0111] In some embodiments, the memory 41 may be an internal storage unit of the electronic device 4, such as a hard disk or memory of the electronic device 4. The memory 41 may also be an external storage device of the electronic device 4, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 4. Further, the memory 41 may also include both an internal storage unit of the electronic device 4 and an external storage device. The memory 41 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as program codes of computer programs, etc. The memory 41 may also be used to temporarily store data that has been sent or is to be sent.
[0112] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0113] It should be noted that the structure of the above-mentioned electronic device is only illustrative, and based on different application scenarios, it may also include other physical structures, and the physical structure of the electronic device is not limited here.
[0114] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0115] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0116] An embodiment of the present application provides a computer program product. When the computer program product runs on a server, the server can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0117] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0118] The electronic device, computer storage medium, and computer program product provided in the above-mentioned embodiments of the present application are all used to execute the method provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the method provided above, and will not be repeated here.
[0119] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0120] It should be understood that the above is only to help those skilled in the art to better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application. According to the above examples given, those skilled in the art can obviously make various equivalent modifications or changes. For example, some steps in each embodiment of the above detection method may be unnecessary, or some steps may be newly added. Or a combination of any two or any multiple embodiments of the above. Such modifications, changes or combined schemes also fall within the scope of the embodiments of the present application.
[0121] It should also be understood that the division of the methods, situations, categories and embodiments in the embodiments of the present application is only for the convenience of description and should not constitute a special limitation. The features of various methods, categories, situations and embodiments can be combined without contradiction.
[0122] It should also be understood that in the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.
[0123] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0124] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0125] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0126] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
[0127] Finally, it should be noted that the above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for managing resources based on a tree structure, characterized in that: The method comprises: Based on the tree structure template, a database table is created in the database, and the database table is used to store resources of the tree structure; For the resources of the tree structure, a tree component dependency is added, wherein the tree component is configured with management logic for the resources; After the tree table entity class in the database table inherits the entity class of the tree node, the management logic is executed on the resource based on the tree function class in the tree component.
2. The method according to claim 1, characterized in that The step of creating a database table in a database based on a tree structure template includes: Based on the template of the tree structure, the attribute fields and / or index fields of each tree node in the tree structure are created in the database to obtain the database table.
3. The method according to claim 1, characterized in that The resource for the tree structure, adding the dependency of the tree component, includes: For the resources of the tree structure, add the dependency of the tree structure management component, the dependency of the database operation component, the dependency of the distributed identification component and the dependency of the code generation tool library; The tree component includes the tree structure management component, the database operation component, the distributed identification component and the code generation tool library.
4. The method according to claim 2, characterized in that: After the tree table entity class in the database table inherits the entity class of the tree node, the method further includes: Define the characteristic attributes of the tree table entity class and add index fields; the tree table entity class supports defining the characteristic attributes and adding index fields.
5. The method according to claim 1, characterized in that The executing the management logic on the resource based on the tree function class in the tree component comprises: Based on the calling class information, determining the target tree table entity class corresponding to the tree function class; Based on the component method of the tree function class, the management logic is executed on the resources in the target tree table where the target tree table entity class is located.
6. The method according to any one of claims 1 to 5, characterized in that: The tree table entity class includes encapsulation of resources of the tree structure; The management logic includes at least one of query tree node logic, add tree node logic, update tree node logic, and delete tree node logic; The tree function class is an encapsulation of the management logic.
7. The method according to any one of claims 1 to 5, characterized in that: Before executing the management logic on the resource based on the tree function class in the tree component, the method further includes: Based on business requirements, a pre-check is performed on the resource, wherein the pre-check includes at least one of a parameter check, a name check, and a distributed lock check; After executing the management logic, the method further includes: A post-operation is performed on the resource, where the post-operation includes at least one of updating a characteristic attribute and releasing a distributed lock.
8. A device for managing resources based on a tree structure, characterized in that: The device comprises: A tree table creation unit is used to create a database table in a database based on a tree structure template, wherein the database table is used to store resources of the tree structure; An adding dependency unit, used for adding a tree component dependency for a resource of the tree structure, wherein the tree component dependency is configured with management logic for the resource; The resource management unit is used to execute the management logic on the resource based on the tree function class in the component dependency after the tree table entity class in the database table inherits the entity class of the tree node.
9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer program product, characterized in that When the computer program product is executed on a device, the device is caused to execute the method according to any one of claims 1 to 7.