A hierarchical data retrieval method, device and equipment
By dividing the search types and database hierarchical types in hierarchical data retrieval, and combining the design of relational databases and ES index libraries, the problem of inefficiency of traditional hierarchical data retrieval methods is solved, and efficient data retrieval is achieved with hundreds of millions of users.
Patent Information
- Application Number
- CN202111389373.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2041-11-19
AI Technical Summary
Due to the limitations of its architecture and search path, the traditional hierarchical data retrieval method has low retrieval efficiency in the search process of Internet business with a population of hundreds of millions of users and cannot meet the needs of Internet business development.
Obtain the user ID by responding to the login request from the user, and query the home information and database hierarchy type corresponding to the user ID from the preset database. When a data retrieval request is received, the corresponding database or ES index database is retrieved according to the search type (relational database search or index database search) and home information, and the target hierarchy data is obtained and returned to the user.
By dividing search types and database hierarchical types, simplifying the search architecture and paths, and combining the mutual cooperation between database design and ES search library design, hierarchical tree data can be obtained through one SQL statement or several queries, significantly improving the efficiency of data retrieval with hundreds of millions of users.
Smart Images

Figure CN114116716B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data retrieval, and in particular to a hierarchical data retrieval method, device and equipment. Background Art
[0002] Hierarchical data, also known as a directory tree, is similar to Windows Explorer in UI and refers to data stored layer by layer in a tree structure. Its management, search, and analysis are common requirements in Internet business, such as the management, storage, and query of departments and employees at all levels of an enterprise, as well as the management and query of hierarchical data between employees; the management and query of multi-level commodity categories, commodities, and related enterprise and user data; the management and search of multi-level regions in IoT business and the equipment, equipment manufacturers, and enterprises and user data to which the equipment belongs after it is put into use. The data hierarchy can be more than a dozen or even unlimited, and the corresponding data volume may reach millions or even larger. Users and administrators (including regional administrators) involved in these requirements often require different data permissions.
[0003] Therefore, traditional hierarchical data storage and search methods usually use relational databases such as MySQL, Oracle, or Microsoft SQL Server to save hierarchical data; or use fields to record hierarchical relationships for storage and retrieval queries.
[0004] However, with the continuous expansion of Internet business with hundreds of millions of users, the amount of data associated with the hierarchical tree entity data will further increase. According to the hierarchical data management and search services built according to traditional relational database theory, common table design schemes can only query from the database cyclically or recursively using programming languages such as Java. The more hierarchical trees there are, the deeper the loops or recursive levels. In addition, since application systems and databases often run on different servers, each access to the database will go through network communication, internal processing of the database server, hard disk I / O interaction and other processes. When the amount of data and concurrency are large, the system responds slowly and it is difficult to provide large-scale concurrent access, which reduces the search efficiency of hierarchical data and cannot meet the development needs of Internet business. Summary of the invention
[0005] The present invention provides a hierarchical data retrieval method, device and equipment, which solves the technical problem that the traditional hierarchical data retrieval method has low retrieval efficiency in the process of searching Internet services with hundreds of millions of users due to the limitations of its architecture and retrieval path, and cannot meet the development needs of Internet services.
[0006] A first aspect of the present invention provides a hierarchical data retrieval method, comprising:
[0007] In response to a login request sent by any user terminal, obtaining a user identifier corresponding to the user terminal;
[0008] Querying the attribution information corresponding to the user identifier from a preset database, and determining the database level type corresponding to the user identifier;
[0009] When receiving a data retrieval request sent by the user terminal, obtaining a retrieval type corresponding to the data retrieval request;
[0010] If the search type is a relational database search, searching the relational database corresponding to the database level type according to the attribution information to obtain first target level data;
[0011] If the search type is an index database search, the ES index library corresponding to the database level type is searched according to the data search request and the attribution information to obtain the second target level data;
[0012] Return the first target level data or the second target level data to the user terminal.
[0013] Optionally, the step of querying the attribution information corresponding to the user identifier from a preset database and determining the database level type corresponding to the user identifier includes:
[0014] Searching a preset database according to the user identifier, obtaining the attribution information corresponding to the user identifier and caching it;
[0015] Determine whether the attribution information includes an upper-level node ID;
[0016] If not, determining that the database hierarchy type corresponding to the user identifier is a restricted hierarchy type;
[0017] If so, it is determined that the database hierarchy type corresponding to the user identifier is an unrestricted hierarchy type.
[0018] Optionally, the attribution information includes a first attribution organization ID, and the relational database includes a flat hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, if the search type is a relational database search, the step of searching the relational database corresponding to the database hierarchy type according to the attribution information to obtain the first target hierarchical data includes:
[0019] If the search type is a relational database search, querying the first institution device information table according to the first affiliated institution ID to determine the corresponding device data and the hierarchical tree branch ID;
[0020] Query the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data;
[0021] An association is established between each of the hierarchical tree branch data and the device data to obtain first target hierarchical data.
[0022] Optionally, the attribution information includes a second attribution organization ID and the upper node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization device association information table; when the database hierarchy type is an unrestricted hierarchy type, if the search type is a relational database search, the step of searching the relational database corresponding to the database hierarchy type according to the attribution information to obtain the first target hierarchical data includes:
[0023] If the search type is a relational database search, query the second institution device information table according to the second affiliated institution ID to determine the corresponding device data, the upper node ID and the hierarchical tree node ID;
[0024] Using the upper node ID and the hierarchical tree node ID to search the tree node information table, determine all associated tree node IDs;
[0025] Search the tree node association table according to each of the tree node IDs to obtain the first node associations corresponding to each of the tree node IDs;
[0026] The tree nodes corresponding to the tree node IDs are associated according to the first node association relationship and an association is established between the upper-level node ID and the device data to obtain first target hierarchical data.
[0027] Optionally, the attribution information includes a third institution attribution ID; the ES index library includes a flat hierarchical tree index table and a first institution device association index table; when the database hierarchy type is a limited hierarchy type, if the search type is an index database search, the step of searching the ES index library corresponding to the database hierarchy type according to the data search request and the attribution information to obtain the second target hierarchical data includes:
[0028] If the search type is an index database search, parsing the data search request to obtain search conditions and target data format;
[0029] According to the third institution belonging ID, the institution equipment association index table is searched to determine the corresponding equipment data;
[0030] Search the flat hierarchical tree index table according to the search condition to determine the corresponding hierarchical tree information;
[0031] The hierarchical tree information is associated with the device data and converted into the target data format to obtain second target hierarchical data.
[0032] Optionally, the attribution information includes a fourth institution attribution ID, and the ES index library includes a tree node information index table and a second institution device association index table; when the database hierarchy type is an unrestricted hierarchy type, if the retrieval type is an index database retrieval, the step of retrieving the ES index library corresponding to the database hierarchy type according to the data retrieval request and the attribution information to obtain the second target hierarchical data includes:
[0033] If the search type is an index database search, parsing the data search request to obtain search conditions;
[0034] According to the fourth organization belonging ID, the second organization equipment association index table is searched to determine the corresponding equipment data and the hierarchy tree branch ID;
[0035] Search the tree node information index table according to the search condition to obtain multiple hierarchical tree node IDs that meet the search condition;
[0036] Search the second mechanism equipment association index table according to each of the hierarchical tree node IDs to determine the second node association relationship corresponding to each of the hierarchical tree node IDs;
[0037] The tree nodes corresponding to the hierarchical tree node IDs are associated with each other according to the second node association relationship, and an association is established with the device data to obtain second target hierarchical data.
[0038] Optionally, it also includes:
[0039] When receiving a device reallocation request sent by an additional user terminal, creating an additional user identifier corresponding to the additional user terminal;
[0040] Determining corresponding additional device data according to the device reallocation request;
[0041] An association is established between the additional user identifier and the additional device data, an additional ES index table is obtained and saved in the ES index library.
[0042] Optionally, it also includes:
[0043] Execute a preset configuration file according to a preset update cycle, perform field conversion on the relational data in the relational database, and obtain an ES index field;
[0044] Synchronize the ES index field to the ES index library.
[0045] A second aspect of the present invention provides a hierarchical data retrieval device, comprising:
[0046] A user identification acquisition module, used to respond to a login request sent by any user terminal and acquire a user identification corresponding to the user terminal;
[0047] A database level type determination module, used to query the attribution information corresponding to the user identifier from a preset database, and determine the database level type corresponding to the user identifier;
[0048] A search type acquisition module, configured to, when receiving a data search request sent by the user terminal, acquire a search type corresponding to the data search request;
[0049] A relational data retrieval module, for retrieving the relational database corresponding to the database level type according to the attribution information to obtain first target level data if the retrieval type is a relational database retrieval;
[0050] An index data retrieval module, for, if the retrieval type is an index database retrieval, searching the ES index library corresponding to the database level type according to the data retrieval request and the attribution information to obtain the second target level data;
[0051] The hierarchical data returning module is used to return the first target hierarchical data or the second target hierarchical data to the user terminal.
[0052] The third aspect of the present invention also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the hierarchical data retrieval method as described in any one of the first aspects of the present invention.
[0053] It can be seen from the above technical solutions that the present invention has the following advantages:
[0054] The present invention obtains the user identification corresponding to the user terminal by responding to the login request sent by any user terminal; queries the attribution information corresponding to the user identification from the preset database, and determines the database level type corresponding to the user identification; when receiving the data retrieval request sent by the user terminal, obtains the retrieval type corresponding to the data retrieval request; if the retrieval type is a relational database retrieval, retrieves the relational database corresponding to the database level type according to the attribution information, and obtains the first target level data; if the retrieval type is an index database retrieval, retrieves the ES index library corresponding to the database level type according to the data retrieval request and the attribution information, and obtains the second target level data; returns the first target level data or the second target level data to the user terminal. Thus, by dividing the retrieval type and the database level type, on the basis of simplifying the retrieval architecture and the retrieval path, through the cooperation between the database design and the ES search library design, the hierarchical tree data can be obtained through one SQL statement or several queries, thereby more effectively improving the efficiency of the data retrieval process under the number of hundreds of millions of users. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the embodiments of the present invention 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 invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0056] Figure 1 A flowchart of a hierarchical data retrieval method provided in Embodiment 1 of the present invention;
[0057] Figure 2 A flowchart of a hierarchical data retrieval method provided in Embodiment 2 of the present invention;
[0058] Figure 3 A flowchart of the incremental synchronization process of hierarchical data provided by an embodiment of the present invention;
[0059] Figure 4 A flowchart of the steps of a search query process of an ES index library provided by an embodiment of the present invention;
[0060] Figure 5 This is a structural block diagram of a hierarchical data retrieval device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0061] The embodiments of the present invention provide a hierarchical data retrieval method, device and equipment for solving the technical problem that the traditional hierarchical data retrieval method has low retrieval efficiency in the process of searching Internet services with hundreds of millions of users due to the limitations of its architecture and retrieval path, and cannot meet the development needs of Internet services.
[0062] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0063] See also Figure 1 , Figure 1 A flowchart of the steps of a hierarchical data retrieval method provided in Embodiment 1 of the present invention.
[0064] The present invention provides a hierarchical data retrieval method, comprising:
[0065] Step 101, in response to a login request sent by any user terminal, obtaining a user identification corresponding to the user terminal;
[0066] The user identification refers to the user ID carried in the login request when any user sends a login request.
[0067] In an embodiment of the present invention, the device responds to a login request sent by any user terminal and performs login verification on the login request, for example, judging whether the user terminal has the corresponding login authority by whether the user terminal is registered, etc. If the login verification passes, the user identifier corresponding to the user terminal is obtained from the login request to obtain the data basis for subsequent user terminal queries on hierarchical data.
[0068] Step 102, querying the attribution information corresponding to the user identifier from a preset database, and determining the database level type corresponding to the user identifier;
[0069] The preset database refers to a relational database that stores information such as the user-institution association table and the hierarchical tree branch ID set.
[0070] The attribution information refers to the information indicating the association between the user identity and multiple attribution agencies, user types and attribution tree branches, including but not limited to the first attribution agency ID, the second attribution agency ID, the third attribution agency ID, the fourth attribution agency ID and the upper node ID.
[0071] After obtaining the user ID carried in the login request, the user ID can be used as a search word to query the corresponding attribution information in the preset database. At the same time, according to the user ID combined with the login request, the database level type of the hierarchical database to which the user ID belongs can be determined.
[0072] Step 103, when receiving a data retrieval request sent by a user terminal, obtaining a retrieval type corresponding to the data retrieval request;
[0073] After determining the database hierarchy type corresponding to the user identifier, if a data retrieval request sent by the user is received, the data retrieval request can be further responded to to obtain the corresponding retrieval type therein to determine the retrieval method required by the data retrieval request, such as relational database retrieval or index database retrieval.
[0074] Step 104, if the search type is a relational database search, then search the relational database corresponding to the database level type according to the attribution information to obtain the first target level data;
[0075] A relational database is a database built on the relational database model. It uses concepts and methods such as set algebra to process data in the database. It is also a table organized into a set of formal descriptive tables. The essence of the table is to load a special collection of data items. The data in these tables can be accessed or reassembled in many different ways without reorganizing the database table. The definition of a relational database results in a table of metadata or a formal description of tables, columns, ranges, and constraints. Each table (sometimes called a relation) contains one or more data types represented by columns. Each row contains a unique data entity, which is the type defined by the column. When creating a relational database, you can define the range of possible values for the data column and further constraints that may be applied to that data value. The SQL language is the interface for standard users and applications to relational databases. Its advantage is that it is easy to expand, and after the initial database creation, a new data type can be added without modifying all existing application software. The mainstream relational databases include Oracle, DB2, SQL Server, Sybase, MySQL, etc.
[0076] If the search type is determined to be a relational database search, since the data request in the data search request has been extracted in the form of attribution information, the attribution information can be used as a keyword or key word at this time, and the search can be performed in the relational database corresponding to the database hierarchy type according to the search method of the relational database search to obtain the first target level data.
[0077] Step 105, if the search type is index database search, the ES index library corresponding to the database level type is searched according to the data search request and the attribution information to obtain the second target level data;
[0078] ES index library refers to a distributed, highly scalable, and highly real-time search and data analysis engine. In terms of relational databases, ES indexes are equivalent to tables in relational databases. An index can contain multiple fields of different data types, but ES indexes cannot be associated with tables. It can easily enable large amounts of data to be searched, analyzed, and explored. Making full use of the horizontal scalability of Elasticsearch can make data more valuable in a production environment. The implementation principle of Elasticsearch is mainly divided into the following steps. First, the user submits the data to the Elasticsearch database, and then the corresponding statement is segmented through the segmentation controller, and its weight and segmentation results are stored in the data together. When the user searches for data, the results are ranked and scored according to the weight, and then the returned results are presented to the user.
[0079] If the search type is determined to be an index database search, it indicates that the search method at this time is fuzzy search or full-text search. In order to improve the efficiency of subsequent searches, the search conditions specified in the data retrieval request can be combined with the attribution information to form compound keywords or keywords, and the ES index library corresponding to the database level type can be retrieved to obtain the second target level data.
[0080] Step 106, returning the first target level data or the second target level data to the user end.
[0081] After the first target hierarchical data or the second target hierarchical data is acquired, it is returned to the user terminal for display by the user terminal, so that the user can consult the hierarchical data.
[0082] In an embodiment of the present invention, by responding to a login request sent by any user terminal, a user identifier corresponding to the user terminal is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined; when a data retrieval request sent by the user terminal is received, the retrieval type corresponding to the data retrieval request is obtained; if the retrieval type is a relational database retrieval, the relational database corresponding to the database hierarchy type is retrieved according to the attribution information to obtain the first target hierarchy data; if the retrieval type is an index database retrieval, the ES index library corresponding to the database hierarchy type is retrieved according to the data retrieval request and the attribution information to obtain the second target hierarchy data; the first target hierarchy data or the second target hierarchy data is returned to the user terminal. Thus, by dividing the retrieval type and the database hierarchy type, on the basis of simplifying the retrieval architecture and the retrieval path, through the cooperation between the database design and the ES search library design, the hierarchical tree data can be obtained through one SQL statement or several queries, thereby more effectively improving the efficiency of the data retrieval process under the number of hundreds of millions of users.
[0083] See also Figure 2 , Figure 2 A flowchart of the steps of a hierarchical data retrieval method provided in Embodiment 2 of the present invention.
[0084] The present invention provides a hierarchical data retrieval method, comprising:
[0085] Step 201, in response to a login request sent by any user terminal, obtaining a user identification corresponding to the user terminal;
[0086] In the embodiment of the present invention, the specific implementation process of step 201 is similar to step 101 and will not be repeated here.
[0087] Step 202, querying the attribution information corresponding to the user identifier from a preset database, and determining the database level type corresponding to the user identifier;
[0088] Optionally, step 202 may include the following sub-steps:
[0089] Search the preset database according to the user ID, obtain the attribution information corresponding to the user ID and cache it;
[0090] Determine whether the ownership information contains the parent node ID;
[0091] If not, it is determined that the database level type corresponding to the user identifier is a restricted level type;
[0092] If so, it is determined that the database hierarchy type corresponding to the user identifier is an unqualified hierarchy type.
[0093] In the embodiment of the present invention, the attribution information may include multiple contents. To further improve the subsequent retrieval efficiency, after obtaining the user identification, the preset database may be queried according to the user identification to obtain the attribution information corresponding to the user identification and cache it.
[0094] At the same time, the attribution information is parsed to determine whether it contains the information of the upper node ID. If it does not contain the upper node ID, it means that the attribution agency ID in the attribution information does not have an associated upper node ID, that is, the database hierarchy type corresponding to the user ID is limited. At this time, it can be determined that the database hierarchy type corresponding to the user ID is a limited hierarchy type; if it contains the upper node ID, it means that the attribution agency ID in the attribution information has an associated upper node ID, and the hierarchy data is stored in the form of node information and node association relationship. At this time, it can be determined that the database hierarchy type corresponding to the user ID is an unrestricted hierarchy type.
[0095] It is worth mentioning that the attribution information may also include a user type, which is used to limit the type to which the user terminal belongs, for example, the user terminal belongs to a certain organization, the user terminal is an independent organization, etc. This embodiment of the present invention does not limit this.
[0096] Step 203, when receiving a data retrieval request sent by the user terminal, obtaining a retrieval type corresponding to the data retrieval request;
[0097] In the embodiment of the present invention, the specific implementation process of step 203 is similar to step 103 and will not be repeated here.
[0098] In specific implementation, a relational database can be constructed in the following ways:
[0099] 1) Relational database with limited hierarchical types
[0100] By establishing a flat hierarchical tree information table, an organization information table (saving organization data such as organization id, name, address, contact information, etc.), an organization and equipment association table, a user information table, and a user and organization association table in a relational database, indexes are established for the tables according to SQL query conditions. Among them, the user information table is used to save user id, name, mobile phone number and other personal information. The field name of each node should be the abbreviation of the business entity name as much as possible, and field names with sequential numbering should be used only in special circumstances. The user and organization association table is used to record the relationship between the user and the organization to which he belongs.
[0101] Taking the hierarchical tree from province to street as an example, the plane hierarchical tree information table t_region_tree can be shown in the following Table 1:
[0102] Field meaning Field Name Data Types Remark id id bigint Primary key, also the hierarchical tree branch id Province / Municipality province varchar Province / Municipality ID province_id bigint City / District city varchar City / District ID city_id bigint District / County county varchar District / County ID county_id bigint Street / Town street varchar Street / Town ID street_id bigint Community / Village community varchar Community / Village ID community_id bigint Lower level village / community village varchar The ID of the bottom village / community village_id bigint
[0103] Table 1
[0104] Among them, a table is used to record the complete branches of the hierarchical tree from the top to the bottom and the relationship information of each node therein. The order of the fields in the table from left to right corresponds to the actual order of the nodes from top to bottom in the hierarchical tree. The main fields can include the name of each node, node number and other information. All records with the same root node constitute all branches of this root node tree. If you need to update the node name, take the street name as an example, execute update t_region_treeset street = 'new name' where street = 'old street name'. When deleting a node in the hierarchical tree, directly execute the update operation to clear the node field in the corresponding record, indicating that the hierarchical tree branch ignores this node to assemble the branch; the cleared node can also be written with a new node name through the update operation to add it to the branch of the tree.
[0105] The first institution equipment information table may be as shown in Table 2 below:
[0106]
[0107]
[0108] Table 2
[0109] As shown in Table 2, the main fields of the first organization device information table may include but are not limited to the first affiliated organization ID, device ID, device name, device IP address, etc. If the first affiliated organization has only one hierarchical tree branch, the id can also be the hierarchical tree branch id.
[0110] In the above example, the province, city, county, and district names used as node names change very infrequently. If the node names change frequently and a tree may have many child nodes, to avoid the impact of database update operations, all node names can be extracted to create a node information table. The main fields include node id, node name, and node code. In this way, only one record needs to be updated each time the node name is updated. The flat hierarchical tree information table only stores the node id or code for each hierarchical tree node. The id and code are constructed as continuous self-incrementing data. At this time, one record can store up to hundreds of hierarchical trees.
[0111] The structural advantages of Table 1 and Table 2 above include: 1) meeting the business needs of hierarchical tree management and storage; 2) being able to obtain all directory trees of an organization through a single SQL query; 3) being able to obtain complete information of a hierarchical tree containing a node through a single SQL query; 4) supporting user data permissions and data security to ensure that a user can only see the data allowed by his or her permissions; 5) the impact of management operations such as adding, deleting, and modifying business data on other operations can be controlled within a limited range and will not increase as the amount of data increases.
[0112] 2) Relational databases with unrestricted hierarchical types
[0113] For relational databases of non-restricted hierarchical types, the scale of data that needs to be saved is usually large. If it is saved in the manner of the above-mentioned relational database of restricted hierarchical types, it is easy to cause slow reading. At this time, the above-mentioned flat hierarchical tree information table can be split into a tree node information table t_node_link and a tree node association relationship table t_node_link, and a second institution equipment association information table can be established at the same time.
[0114] Specifically, the tree node information table records each tree node ID, node name, and other fields that can be added according to the business. The tree node association table can be shown in Table 3 below:
[0115]
[0116]
[0117] Table 3
[0118] When t_node_link is used to store the node itself, high_id = node_id, and distance is 0; is_leaf is 1 for leaf nodes, otherwise it is 0. In addition, this table is also used to store the association data between all non-leaf nodes and all their subordinate nodes, that is, the value of distance is at least 0.
[0119] With such a database design, not only can all records of a tree be found at once, but the management and query of hierarchical tree data are not complicated. When adding or deleting a node, it only affects the change position of the branch where the node is located and the records related to the subordinate nodes. Modifying node information will not affect t_node_link. For example: when you need to add (delete) or delete a node, it can be easily implemented through the high_id field, similar to adding or deleting nodes in a linked list. The adjustment of distance can conveniently calculate the relative value of the new level from the UI; to query all nodes of each subordinate of a node, you can use SQL: select * from t_node_link l, t_node n where n.name = 'node name to be queried' and n.id = l.high_id and l.distance! =0, where the node id can also be replaced by the node number; to query all the directly subordinate nodes of any node, you can use SQL: select * from t_node_link l, t_node n where n.name = 'the node name to be queried' and n.id = l.node_id and l.distance = 1; to query all the superior nodes of any node, you can use SQL: select * from t_node_link l, t_node n where n.name = 'the node name to be queried' and n.id = l.node_id and l.distance! = 0, through the node table node_id = node_id of the node association table, distance! = 0; according to is_root = 1, the root nodes of all trees can be easily queried.
[0120] Step 204, if the search type is a relational database search, then search the relational database corresponding to the database level type according to the attribution information to obtain the first target level data;
[0121] In an example of the present invention, the attribution information includes a first attribution organization ID, and the relational database includes a flat hierarchical tree information table and a first organization device association information table; when the database hierarchy type is a limited hierarchy type, step 204 may include the following sub-steps:
[0122] If the search type is a relational database search, the first organization device information table is searched according to the first affiliated organization ID to determine the corresponding device data and the hierarchical tree branch ID;
[0123] Query the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data;
[0124] An association is established between each hierarchical tree branch data and the device data to obtain first target hierarchical data.
[0125] In this embodiment, when it is determined that the database hierarchy type is a limited hierarchy type and the retrieval type is a relational database retrieval, it means that the data to be retrieved at this time is a relational database of a limited hierarchy type. At this time, the first affiliation organization ID can be obtained from the affiliation information, and the first organization equipment information table is queried according to the first affiliation organization ID to determine the equipment data corresponding to the first affiliation organization ID and the corresponding hierarchy tree branch ID. Then, the plane hierarchy tree information table is queried according to the hierarchy tree branch ID to determine the corresponding hierarchy tree branch data, that is, the entire hierarchy tree branch from the province to the bottom village mentioned above. Finally, an association is established between each hierarchy tree branch data and the equipment data to obtain the first target hierarchy data.
[0126] In a specific implementation, the query can also be performed by constructing an SQL statement, where the SQL statement is: select t.*, d.device_id, d.device_name from t_org_device d, t_tree t where d.org_id = user_org_id and d.branch_id = t.id, where user_org_id is the first affiliated organization ID, branch_id is the hierarchical tree branch ID, and t.id is the hierarchical tree branch data.
[0127] After obtaining the hierarchical tree branch data, the hierarchical tree branch data and all device data under the branch and the corresponding hierarchical tree branch ID can be put into one record. The device data can be used as a collection type field to constitute an attribute of the branch data object of the hierarchical tree branch ID.
[0128] In another example of the present invention, the attribution information includes a second attribution organization ID and an upper node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization device association information table; when the database hierarchy type is an unrestricted hierarchy type, step 204 may include the following sub-steps:
[0129] If the search type is a relational database search, query the second organization device information table according to the second affiliated organization ID to determine the corresponding device data, the upper node ID and the hierarchical tree node ID;
[0130] Using the parent node ID and the level tree node ID to search the tree node information table, determine all the associated tree node IDs;
[0131] Search the tree node association table according to each tree node ID to obtain the first node association relationship corresponding to each tree node ID;
[0132] The tree nodes corresponding to the tree node IDs are associated according to the first node association relationship and an association is established between the upper-level node ID and the device data to obtain the first target hierarchical data.
[0133] In this embodiment, when it is determined that the database hierarchy type is an unrestricted hierarchy type and the retrieval type is a relational database retrieval, it means that the relational database to be retrieved at this time is of an unrestricted hierarchy type, and the second institution equipment information table can be queried according to the second affiliation institution ID to determine the equipment data, the upper node ID and the hierarchy tree node ID associated with the second affiliation institution ID; then the upper node ID and the hierarchy tree node ID are used to retrieve the tree node information table to determine all the tree node IDs of the entire hierarchy tree where the tree node corresponding to the hierarchy tree node ID is located, and then the tree node association relationship table is retrieved respectively according to each tree node ID to determine the first node association relationship between the tree nodes corresponding to each tree node ID, and the tree nodes corresponding to each tree node ID are associated according to the first node association relationship, and an association between the upper node ID and the equipment data is established to obtain the first target hierarchy data.
[0134] Optionally, the method may further include the following steps:
[0135] Execute the preset configuration file according to the preset update cycle, convert the fields of the relational data in the relational database, and obtain the ES index fields;
[0136] Synchronize the ES index fields to the ES index library.
[0137] In the specific implementation, in order to ensure the stability and accuracy of the index library, the ES index library is usually built after a relational database of a certain scale has been established and run for a period of time. At the same time, in order to realize the periodic update of the ES index library, the preset configuration file can be executed according to the preset update cycle, and the relational data in the relational database can be converted into fields to obtain the corresponding ES index fields, and then the ES index fields are synchronized to the ES index library.
[0138] Taking the synchronization of the above-mentioned hierarchical tree information table t_plain_tree as an example, the data synchronization of the ES index library can be achieved through the following steps S11-S15 or steps S21-S26:
[0139] S11. Install logstash-integration-jdbc and other related plug-ins. Refer to the official document to configure the database connection and SQL for obtaining data: SELECT distinct p.*from t_plain_tree p,t_org_device dWHERE p.id=d.branch_id and p.id>=:sql_last_value. More requirements can be met by adjusting the SQL here;
[0140] S12. Edit the logstash configuration file to use the configuration items tracking_column=>id, record_last_run=>true, clean_run=>false to track and record the id field in pages, and use the above SQL to query the data from MySQL and save it to ES. Use the plug-ins logstash-filter-mutate and logstash-filter-ruby to add, remove, split fields or change the value of fields. Through logstash-filter-geoip, you can parse the longitude and latitude, province, city and county names corresponding to the device location from the IP address library GeoLite2-City.mmdb according to the device IP and generate the corresponding fields in ES. In this case, the Chinese regional name needs to modify ib / logstash / filters / geoip.rb in the logstash installation directory to continue calling get("zh-CN") for each obtained regional name. Since the IP address information here is saved in a csv file, you can also maintain your own address library. You can also call the IP resolution service through ruby code in geoip.rb to obtain relevant Chinese regional information;
[0141] S13. Use the logstash-filter-mutate plug-in to add the Chinese region information and longitude and latitude information to the ES index fields device_location and device_pos respectively.
[0142] S14. Continue to edit the logstash configuration file and use logstash-output-elasticsearch to write the above processing results to ES;
[0143] S15. Start logstash using the above configuration file and stop it after all data migration is completed. You can also use the schedule in the logstash configuration file to synchronize data from MySQL to ES at a scheduled time.
[0144] In another example, the open source data synchronization tool canal can be well decoupled from the business system because it directly operates MySQL's binlog. At the same time, its operation brings limited pressure to MySQL. However, when a hierarchical tree branch is not fully formed, synchronizing it to ES will only increase useless ES update operations. Due to differences in business rules, business entity data in different states often do not need to be fully synchronized. In addition, data processing and verification may also require querying other databases or ES, so it is necessary to control the incremental synchronization of data through the canal client. For details, please refer to Figure 3 , the steps are as follows:
[0145] Create a canal listening client by implementing the canal interfaces InitializingBean and ParseCanal, parse data changes, and obtain the changed database tables and data; when it is found that the data in the tables t_plain_tree and t_node have changed, check whether there is a device association record corresponding to the id of the changed data in the table t_org_device. If not, the corresponding node data will not be synchronized, otherwise the synchronization will continue; before formally synchronizing the data, first obtain the entity class corresponding to the changed data through reflection; when it is necessary to synchronize the data of t_plain_tree and t_node to ES, if it is a new record, directly Then write a new record in the corresponding ES index. If it is an update operation, directly update the corresponding record in the ES index. If it is a delete operation, first delete the record with the id corresponding to the delete operation in the organization equipment index, and then delete the data in the corresponding indexes of the tables t_plain_tree and t_node. If the organization equipment association table changes, for the new data in the table t_org_device, directly write the new records to the corresponding ES index. For the update and delete data of this table, update or delete the corresponding records in the ES index according to its id. If there is more data to be synchronized, continue to monitor whether data changes occur.
[0146] In the specific implementation, after the ES index library synchronizes the relational data, in order to facilitate subsequent data retrieval, the table can be constructed in the following ways:
[0147] 1) ES index library with limited hierarchical types
[0148] For an ES index library of non-limited hierarchical type, it may include but is not limited to a node information index table, a flat hierarchical tree index table, and a first mechanism device association index table.
[0149] Specifically, the flat hierarchical tree index table may be as shown in Table 4 below:
[0150]
[0151] Table 4
[0152] It is worth mentioning that in the above Table 4, fields that need to be searched in the business can also be added to the index, such as the geographical location of the device, the device name, the device label, the device capability, etc.
[0153] The first mechanism equipment association index table may be as shown in Table 5 below:
[0154]
[0155] Table 5
[0156] It is worth mentioning that based on the above database and ES index design, two supporting measures are provided in R&D implementation. On the one hand, Java-based development is simplified to minimize the amount of code that must be developed, and on the other hand, the performance of search operations is improved. Spring Data Elasticsearch inherits the advantages of Spring Data, including the fact that no implementation code is required, only interfaces and @Repository and @Query annotations are needed to implement fuzzy query and search of data in ES. However, its default findAll() method may cause service instability if it is frequently called to view all data when there is a large amount of data in the production environment. In addition, the content of the @Query annotation is written in the same way as the painless script of ES, which is not easy to understand and remember. It is far less easy to use than the SQL query syntax, and does not support controlling which fields in the index are returned in the query results. The existing implementation actually returns all fields.
[0157] To solve the first problem, since the implementation code of the default findAll() method is in the class SimpleElasticsearchRepository, and in META-INF, by default, spring.factories specifies which class provides the implementation class of the ES query method through ElasticsearchRepositoryFactory. Therefore, you can inherit the SimpleElasticsearchRepository class, rewrite the findAll() method in it, add warning output at the warn or error level, and add the @Deprecated annotation to this method, then inherit the ElasticsearchRepositoryFactory and call the newly developed SimpleElasticsearchRepository subclass, and specify the ElasticsearchRepositoryFactory subclass as RepositoryFactorySupport in spring.factories.
[0158] To solve the second problem, you can encapsulate special query annotations for specific types of queries in ES. For example, for fuzzy queries, you can encapsulate a new annotation FuzzyQuery and its processing flow in accordance with the implementation and processing flow of the Query annotation, specify the fields to be queried, the corresponding parameter value identifiers, and the logical relationship between the fields when assembled. By default, the logic and processing are performed. At runtime, the parameters in the method where the FuzzyQuery annotation of the Repository interface is located are directly replaced in order; when specifying the return field list or the field list to be excluded, the corresponding content is directly generated through string processing in the painless script of the query request, and the other aspects are kept the same as the Query annotation. Then, in the classes ElasticsearchQueryMethod and ElasticsearchRepositoryFactory, the content of the annotation FuzzyQuery is parsed according to the above-mentioned new functions and the corresponding painless script content is generated. This can avoid entering content such as {\"wildcard\":{、\"bool\":or{\"must\":, and can also avoid the trouble caused by many symbols such as {、}、[、]. Finally, repackage and generate jar files to replace the original jar files used by the business system.
[0159] 2) ES index library of non-restricted hierarchical type
[0160] For an ES index library of non-limited hierarchical type, it may include but is not limited to a node information index table, a flat hierarchical tree index table, and a first mechanism device association index table.
[0161] Specifically, the specific construction of the plane hierarchical tree index table is similar to the above Table 4, and the node information index table can be shown in the following Table 6:
[0162]
[0163] Table 6 The second mechanism equipment association index table may be as shown in Table 7 below:
[0164]
[0165] Table 7
[0166] It is worth mentioning that in the actual search, the supplyAsync() method of Java's CompletableFuture simultaneously initiates search requests to the above two indexes, and then all asynchronous requests are aggregated through the allOf() method. In the end, the entire time consumed is slightly longer than the longest of the two requests. When the result data in the form of a hierarchical tree does not need to be returned, the search results here can be directly returned. Otherwise, the Java code can query the branch data of all trees corresponding to the node from the association information table between the nodes of the hierarchical tree according to the node information obtained here, and then assemble it into a complete hierarchical tree data and return it.
[0167] Step 205, if the search type is index database search, the ES index library corresponding to the database level type is searched according to the data search request and the attribution information to obtain the second target level data;
[0168] In one example of the present invention, the attribution information includes a third institution attribution ID; the ES index library includes a flat hierarchical tree index table and a first institution device association index table; when the database hierarchy type is a limited hierarchy type, step 205 may include the following sub-steps:
[0169] If the search type is index database search, the data search request is parsed to obtain the search conditions and target data format;
[0170] According to the third-party institution's ID, the institution's equipment association index table is searched to determine the corresponding equipment data;
[0171] Search the flat hierarchical tree index table according to the search conditions to determine the corresponding hierarchical tree information;
[0172] An association is established between the hierarchical tree information and the device data and converted into a target data format to obtain second target hierarchical data.
[0173] Search conditions refer to data restriction information that may not be exactly the same as the fields in the ES index library but is related. The target data format refers to the hierarchical tree data required by the user or the data format unique to the user.
[0174] In an embodiment of the present invention, when it is determined that the database hierarchy type is a limited hierarchy type, if an index database search is required, the data search request can be parsed to obtain the search conditions and the target data format. According to the search conditions and the third institution belonging ID, the search is performed asynchronously from the institution device management index table and the flat hierarchical tree index table to determine the device data corresponding to the third institution belonging ID and the hierarchical tree information that meets the search conditions; then the association between the hierarchical tree information and the device data is established and converted into the target data format to obtain the second target hierarchical data.
[0175] In the specific implementation, please refer to Figure 4 , the search query of ES index library is realized through the following steps S31-S34:
[0176] S31, the user obtains the third-party institution's attribution ID from the cache. If it cannot be found, the user first queries the relational database MySQL and updates the cache before continuing;
[0177] S32, asynchronously searching for data that meets the conditions from the institution device management index table and the flat hierarchical tree index table according to the third institution belonging ID and the search conditions, and obtaining hierarchical tree information and device data that meet the search conditions as search results;
[0178] Optionally, in the above S32, if the node information of the tree and the relationship between each node of the plane hierarchical tree are stored in different indexes respectively, the search results are obtained by asynchronously searching the institution device management index table and the plane hierarchical tree index table simultaneously according to the cached hierarchical tree branch ID set and the third institution belonging ID. Next, if the search results do not need to be assembled into tree data, the results required by the client can be directly returned. Otherwise, the node relationship data of the tree can be obtained by querying MySQL through the cache again. Finally, the application service assembles the result data into the data required by the user end and returns it.
[0179] S33. If the number of records in the search result exceeds the specified threshold, the first page of results (the number of records per page can be configured) and the total amount of data in the result set are returned to the user end;
[0180] S34, organizing the search results into fields and data formats required by the user end through Java code in the memory, obtaining the second target level data and returning it to the user end;
[0181] In another example of the present invention, the attribution information includes a fourth institution attribution ID, the ES index library includes a tree node information index table and a second institution device association index table; when the database hierarchy type is an unrestricted hierarchy type, step 205 may include the following sub-steps:
[0182] If the search type is index database search, the data search request is parsed to obtain the search conditions;
[0183] According to the fourth organization's belonging ID, the second organization's equipment association index table is searched to determine the corresponding equipment data and the belonging hierarchical tree branch ID;
[0184] Search the tree node information index table according to the search condition to obtain multiple hierarchical tree node IDs that meet the search condition;
[0185] According to each hierarchical tree node ID, the second mechanism equipment association index table is searched respectively to determine the second node association relationship corresponding to each hierarchical tree node ID;
[0186] The tree nodes corresponding to the tree node IDs of each level are associated according to the second node association relationship, and an association is established with the device data to obtain the second target level data.
[0187] In an embodiment of the present invention, if the retrieval type is an index database retrieval and the index database is a non-restricted hierarchical type, the data retrieval request is parsed to obtain the search conditions; the second institution equipment association index table is retrieved according to the fourth institution affiliation ID to determine the corresponding equipment data and the hierarchical tree branch ID to which it belongs; the tree node information index table is searched according to the search conditions to obtain multiple hierarchical tree node IDs that meet the search conditions; the second institution equipment association index table is retrieved respectively according to each hierarchical tree node ID to determine the second node association relationship corresponding to each hierarchical tree node ID; the tree nodes corresponding to each hierarchical tree node ID are associated according to the second node association relationship, and an association with the equipment data is established to obtain the second target hierarchical data.
[0188] Step 206, returning the first target level data or the second target level data to the user end.
[0189] In the embodiment of the present invention, the specific implementation process of step 206 is similar to step 106 and will not be repeated here.
[0190] Step 207, when receiving a device reallocation request sent by an additional user terminal, creating an additional user identifier corresponding to the additional user terminal;
[0191] Step 208, determining corresponding additional device data according to the device reallocation request;
[0192] Step 209: establish association between the additional user identifier and the additional device data, obtain an additional ES index table and save it to the ES index library.
[0193] In a specific implementation, the user end is usually under a certain organization. The same organization can include multiple user ends at the same time. However, due to business needs, it may be necessary to allocate equipment to a single user. To solve this technical problem, when receiving a device reallocation request sent by an additional user end, an additional user ID corresponding to the additional user end is created, and the additional device data required by the additional user end is determined according to the device reallocation request, such as device name, device ID, device location, device label, and device capability, etc., and then the association between the additional user ID and the additional device data is established to obtain an additional ES index table. To facilitate subsequent retrieval, the additional ES index table can be saved to the ES index library.
[0194] In an example of the present invention, Table 8 shows an additional ES index table of an embodiment of the present invention:
[0195] Table 8
[0196] In another example of the present invention, in order to distinguish such users and handle them specially, in the design of the application system, a non-separate role can be created for such users or a special user attribute can be created for them to indicate whether a device has been allocated to them separately. If the role control is used, before allocating the device to the user, it is first checked whether the user is the required role, and the device can be allocated to this type of user only after the check is passed; if the dedicated user attribute indicates that the device has been allocated to the user separately, the operation of allocating the device to the user and setting the attribute value is packaged through a transaction of a relational database, so that after the device allocated to the user is successfully saved in the database, the corresponding attribute value is always successfully set for the corresponding user. Depending on which of the above schemes is selected, when the user logs in, the user's role or the above attribute data of the user is extracted from the database and cached in the Redis cluster. When the user subsequently initiates a search request, it can be determined based on the value of the cached data that the index of this part should be searched for the corresponding user, thereby synchronously realizing the control of user data permissions.
[0197] It is worth mentioning that there may be devices going offline or offline in each tree node in the hierarchical tree. At this time, the device data can be updated in the following ways: There are two main technical ways to perceive device offline and offline events: the establishment and disconnection of TCP / IP communication connections based on sockets, and the reporting of device heartbeat data. The latter will receive the device's heartbeat data regularly and will determine that the device is offline if it is not received after a certain period of time. Both require a dedicated device access service, which can receive device communication requests through the MQTT protocol, a custom protocol based on Netty, or even a device heartbeat request based on the HTTP protocol.
[0198] The details of the real-time calculation scheme for the number of online devices include:
[0199] In order to calculate the number of online devices under the hierarchical tree node in real time, whenever the online status of the device changes, the device access service instance can first save the device id (continuously increasing number) and its status in the memory through ConcurrentHashMap. When confirming that the device connection is established or disconnected, or receiving the device heartbeat request or not receiving the device request after timeout, set the device online status to true or false respectively. When multiple devices change their status at the same time, simply call the put() method of ConcurrentHashMap concurrently through multiple threads to modify the status of the corresponding device id. Then the application service instance in the device access service cluster will periodically (intervals can be configured) synchronize and refresh these data to the multi-master and multi-slave Redis cluster, and Redis will save the online status of the device through its bitset, the master instance of each Redis. When the maximum number of hierarchical tree levels is fixed, the key of the bitset is the id of the hierarchical tree branch; when the maximum number of hierarchical tree levels is unlimited, the key is the id of the device's adjacent upper node. If this id changes, the cached key here needs to be updated synchronously. The serial number of each bit in the bitset is equal to the corresponding device id. The value of this bit is 0 or 1, indicating that the device is offline or online, respectively. Through Redis's SETBIT, GETBIT, and BITCOUNT instructions, you can easily set and get the online status of the device id corresponding to a bit of a sequence number and the total number of online devices under a key. If the device id under a node is generally greater than a number, you can subtract a number from all device ids when operating Redis, such as the smallest device id, to help save memory usage. When you need to get the number of online devices for each node in the hierarchical tree, you can batch send a group of tree branch ids or ids of nodes adjacent to the device through Redis's pipeline mechanism to get the total number of online devices for a key through BITCOUNT, and then the application service assembles the result data and returns it. If the user can only access some devices under a node, you can batch send instructions to get the online status of a device id through GETBIT through Redis's pipeline mechanism, return 1 The device corresponding to the table name is online, and the total number of online devices is returned to the user after accumulating in the application service memory. The total number of devices for each node can be queried in the database and cached in the Redis cluster for subsequent queries on the total number of devices under the node. In Redis, hashing can be used to store tree branch or node IDs as keys and the total number of devices as attributes. When a device is added, deleted, or moved, the hash value of the corresponding key is added or subtracted by the corresponding number of devices. When the total device data of any key in Redis is found to be empty, the data is loaded from the data source and cached in the hash of Redis.If the implementation effect of the user-side hierarchical tree is to open the hierarchical tree level by level, and only the first-level nodes are opened by default at the beginning, the implementation is simpler: when the user double-clicks to open a node, the tree node of the next level is directly opened. When the last-level tree node is to be opened, the number of online devices can be directly obtained from Redis through the BITCOUNT instruction based on the id of this node. If the user can only access some of the devices, the ids of these devices are obtained from Redis in batches through the pipeline to obtain the online status of each device and then accumulated in memory. The result after the accumulation of the devices owned by the user is the total number of online devices of the current node. Since the entire process is mainly carried out in memory, and the Redis multi-resident multi-slave cluster has good scalability and availability, the calculation of the number of online devices can not only be carried out in real time, but also have good performance.
[0200] In an embodiment of the present invention, by responding to a login request sent by any user terminal, a user identifier corresponding to the user terminal is obtained; the attribution information corresponding to the user identifier is queried from a preset database, and the database hierarchy type corresponding to the user identifier is determined; when a data retrieval request sent by the user terminal is received, the retrieval type corresponding to the data retrieval request is obtained; if the retrieval type is a relational database retrieval, the relational database corresponding to the database hierarchy type is retrieved according to the attribution information to obtain the first target hierarchy data; if the retrieval type is an index database retrieval, the ES index library corresponding to the database hierarchy type is retrieved according to the data retrieval request and the attribution information to obtain the second target hierarchy data; the first target hierarchy data or the second target hierarchy data is returned to the user terminal. Thus, by dividing the retrieval type and the database hierarchy type, on the basis of simplifying the retrieval architecture and the retrieval path, through the cooperation between the database design and the ES search library design, the hierarchical tree data can be obtained through one SQL statement or several queries, thereby more effectively improving the efficiency of the data retrieval process under the number of hundreds of millions of users.
[0201] See also Figure 5 , Figure 5 This is a structural block diagram of a hierarchical data retrieval device provided in Embodiment 3 of the present invention.
[0202] The embodiment of the present invention provides a hierarchical data retrieval device, comprising:
[0203] The user identification acquisition module 501 is used to respond to a login request sent by any user terminal and acquire the user identification corresponding to the user terminal;
[0204] A database level type determination module 502 is used to query the attribution information corresponding to the user identifier from a preset database and determine the database level type corresponding to the user identifier;
[0205] The search type acquisition module 503 is used to acquire the search type corresponding to the data search request when receiving the data search request sent by the user terminal;
[0206] The relational data search module 504 is used to search the relational database corresponding to the database level type according to the attribution information to obtain the first target level data if the search type is relational database search;
[0207] The index data search module 505 is used to search the ES index library corresponding to the database level type according to the data search request and the attribution information to obtain the second target level data if the search type is index database search;
[0208] The hierarchical data returning module 506 is used to return the first target hierarchical data or the second target hierarchical data to the user end.
[0209] Optionally, the database level type determination module 502 is specifically configured to:
[0210] Search the preset database according to the user ID, obtain the attribution information corresponding to the user ID and cache it;
[0211] Determine whether the ownership information contains the parent node ID;
[0212] If not, it is determined that the database level type corresponding to the user identifier is a restricted level type;
[0213] If so, it is determined that the database hierarchy type corresponding to the user identifier is an unqualified hierarchy type.
[0214] Optionally, the attribution information includes a first attribution organization ID, and the relational database includes a flat hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, the relational data retrieval module 504 is specifically used to:
[0215] If the search type is a relational database search, the first organization device information table is searched according to the first affiliated organization ID to determine the corresponding device data and the hierarchical tree branch ID;
[0216] Query the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data;
[0217] An association is established between each hierarchical tree branch data and the device data to obtain first target hierarchical data.
[0218] Optionally, the attribution information includes a second attribution organization ID and an upper node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization device association information table; when the database hierarchy type is an unrestricted hierarchy type, the relational data retrieval module 504 is specifically used to:
[0219] If the search type is a relational database search, query the second organization device information table according to the second affiliated organization ID to determine the corresponding device data, the upper node ID and the hierarchical tree node ID;
[0220] Using the parent node ID and the level tree node ID to search the tree node information table, determine all the associated tree node IDs;
[0221] Search the tree node association table according to each tree node ID to obtain the first node association relationship corresponding to each tree node ID;
[0222] The tree nodes corresponding to the tree node IDs are associated according to the first node association relationship and an association is established between the upper-level node ID and the device data to obtain the first target hierarchical data.
[0223] Optionally, the attribution information includes a third institution attribution ID; the ES index library includes a flat hierarchical tree index table and a first institution device association index table; when the database hierarchy type is a limited hierarchy type, the index data retrieval module 505 includes:
[0224] If the search type is index database search, the data search request is parsed to obtain the search conditions and target data format;
[0225] According to the third-party institution's ID, the institution's equipment association index table is searched to determine the corresponding equipment data;
[0226] Search the flat hierarchical tree index table according to the search conditions to determine the corresponding hierarchical tree information;
[0227] An association is established between the hierarchical tree information and the device data and converted into a target data format to obtain second target hierarchical data.
[0228] Optionally, the attribution information includes a fourth institution attribution ID, and the ES index library includes a tree node information index table and a second institution device association index table; when the database hierarchy type is an unrestricted hierarchy type, the index data retrieval module 505 includes:
[0229] If the search type is index database search, the data search request is parsed to obtain the search conditions;
[0230] According to the fourth organization's belonging ID, the second organization's equipment association index table is searched to determine the corresponding equipment data and the belonging hierarchical tree branch ID;
[0231] Search the tree node information index table according to the search condition to obtain multiple hierarchical tree node IDs that meet the search condition;
[0232] According to each hierarchical tree node ID, the second mechanism equipment association index table is searched respectively to determine the second node association relationship corresponding to each hierarchical tree node ID;
[0233] The tree nodes corresponding to the tree node IDs of each level are associated according to the second node association relationship, and an association is established with the device data to obtain the second target level data.
[0234] Optionally, the device further comprises:
[0235] A user identification creation module, configured to create an additional user identification corresponding to the additional user terminal when receiving a device reallocation request sent by the additional user terminal;
[0236] An additional device data determination module, used to determine corresponding additional device data according to the device reallocation request;
[0237] The association establishment module is used to establish an association between the additional user identifier and the additional device data, obtain an additional ES index table and save it to the ES index library.
[0238] Optionally, the device further comprises:
[0239] The field conversion module is used to execute the preset configuration file according to the preset update cycle, perform field conversion on the relational data in the relational database, and obtain the ES index field;
[0240] The field synchronization module is used to synchronize ES index fields to the ES index library.
[0241] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the hierarchical data retrieval method of any embodiment of the present invention.
[0242] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0243] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the 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.
[0244] 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.
[0245] In addition, each functional unit in each embodiment of the present invention 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.
[0246] If the integrated 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 technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0247] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those 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 thereof may be replaced by equivalents. However, these 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 invention.
Claims
1. A hierarchical data retrieval method, It is characterized in that include: In response to a login request sent by any user terminal, obtaining a user identifier corresponding to the user terminal; Querying the attribution information corresponding to the user identifier from a preset database, and determining the database level type corresponding to the user identifier; When receiving a data retrieval request sent by the user terminal, obtaining a retrieval type corresponding to the data retrieval request; If the search type is a relational database search, searching the relational database corresponding to the database level type according to the attribution information to obtain first target level data; If the search type is an index database search, the ES index library corresponding to the database level type is searched according to the data search request and the attribution information to obtain the second target level data; Returning the first target level data or the second target level data to the user terminal; The step of querying the attribution information corresponding to the user identifier from a preset database and determining the database level type corresponding to the user identifier includes: Searching a preset database according to the user identifier, obtaining the attribution information corresponding to the user identifier and caching it; Determine whether the attribution information includes an upper-level node ID; If not, determining that the database level type of the hierarchical database to which the user identifier belongs is a restricted level type; If so, it is determined that the database hierarchy type of the hierarchical database to which the user identifier belongs is an unrestricted hierarchy type.
2. The method according to claim 1, It is characterized in that The attribution information includes a first attribution organization ID, and the relational database includes a flat hierarchical tree information table and a first organization equipment association information table; when the database hierarchy type is a limited hierarchy type, if the search type is a relational database search, the step of searching the relational database corresponding to the database hierarchy type according to the attribution information to obtain the first target hierarchical data includes: If the search type is a relational database search, querying the first institution device information table according to the first affiliated institution ID to determine the corresponding device data and the hierarchical tree branch ID; Query the flat hierarchical tree information table according to the hierarchical tree branch ID to determine the corresponding hierarchical tree branch data; An association is established between each of the hierarchical tree branch data and the device data to obtain first target hierarchical data.
3. The method according to claim 1, It is characterized in that The attribution information includes a second attribution organization ID and the upper node ID, and the relational database includes a tree node information table, a tree node association relationship table, and a second organization device association information table; when the database hierarchy type is an unrestricted hierarchy type, if the search type is a relational database search, the step of searching the relational database corresponding to the database hierarchy type according to the attribution information to obtain the first target hierarchical data includes: If the search type is a relational database search, query the second institution device information table according to the second affiliated institution ID to determine the corresponding device data, the upper node ID and the hierarchical tree node ID; Using the upper node ID and the hierarchical tree node ID to search the tree node information table, determine all associated tree node IDs; Search the tree node association table according to each of the tree node IDs to obtain the first node associations corresponding to each of the tree node IDs; The tree nodes corresponding to the tree node IDs are associated according to the first node association relationship and an association is established between the upper-level node ID and the device data to obtain first target hierarchical data.
4. The method according to claim 1, It is characterized in that The attribution information includes a third institution attribution ID; the ES index library includes a flat hierarchical tree index table and a first institution device association index table; when the database hierarchy type is a limited hierarchy type, if the search type is an index database search, the step of searching the ES index library corresponding to the database hierarchy type according to the data search request and the attribution information to obtain the second target hierarchical data includes: If the search type is an index database search, parsing the data search request to obtain search conditions and target data format; According to the third institution belonging ID, the institution equipment association index table is searched to determine the corresponding equipment data; Search the flat hierarchical tree index table according to the search condition to determine the corresponding hierarchical tree information; The hierarchical tree information is associated with the device data and converted into the target data format to obtain second target hierarchical data.
5. The method according to claim 1, It is characterized in that The attribution information includes a fourth institution attribution ID, and the ES index library includes a tree node information index table and a second institution device association index table; when the database hierarchy type is an unrestricted hierarchy type, if the search type is an index database search, the step of searching the ES index library corresponding to the database hierarchy type according to the data search request and the attribution information to obtain the second target hierarchical data includes: If the search type is an index database search, parsing the data search request to obtain search conditions; According to the fourth organization belonging ID, the second organization equipment association index table is searched to determine the corresponding equipment data and the hierarchy tree branch ID; Search the tree node information index table according to the search condition to obtain multiple hierarchical tree node IDs that meet the search condition; Search the second mechanism equipment association index table according to each of the hierarchical tree node IDs to determine the second node association relationship corresponding to each of the hierarchical tree node IDs; The tree nodes corresponding to the hierarchical tree node IDs are associated with each other according to the second node association relationship, and an association is established with the device data to obtain second target hierarchical data.
6. The method according to claim 1, It is characterized in that Also includes: When receiving a device reallocation request sent by an additional user terminal, creating an additional user identifier corresponding to the additional user terminal; determining corresponding additional device data according to the device reallocation request; An association is established between the additional user identifier and the additional device data, an additional ES index table is obtained and saved in the ES index library.
7. The method according to any one of claims 1 to 6, It is characterized in that Also includes: Execute a preset configuration file according to a preset update cycle, perform field conversion on the relational data in the relational database, and obtain an ES index field; Synchronize the ES index field to the ES index library.
8. A hierarchical data retrieval device, It is characterized in that include: A user identification acquisition module, used to respond to a login request sent by any user terminal and acquire a user identification corresponding to the user terminal; A database level type determination module, used to query the attribution information corresponding to the user identifier from a preset database, and determine the database level type corresponding to the user identifier; A search type acquisition module, configured to, when receiving a data search request sent by the user terminal, acquire a search type corresponding to the data search request; A relational data retrieval module, for retrieving the relational database corresponding to the database level type according to the attribution information to obtain first target level data if the retrieval type is a relational database retrieval; An index data retrieval module, for, if the retrieval type is an index database retrieval, searching the ES index library corresponding to the database level type according to the data retrieval request and the attribution information to obtain the second target level data; A hierarchical data returning module, used for returning the first target hierarchical data or the second target hierarchical data to the user terminal; The database level type determination module is specifically used for: Searching a preset database according to the user identifier, obtaining the attribution information corresponding to the user identifier and caching it; Determine whether the attribution information includes an upper-level node ID; If not, determining that the database level type of the hierarchical database to which the user identifier belongs is a restricted level type; If so, it is determined that the database hierarchy type of the hierarchical database to which the user identifier belongs is an unrestricted hierarchy type.
9. An electronic device, It is characterized in that The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the hierarchical data retrieval method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for supplying service contact information to users
CN102769709A
Database-based data processing method and electronic equipment
CN110837515A
Information management retrieval device
JP1995296004A