catalog_real_tree.py 2.1 KB
# coding=utf-8
#author:        4N
#createtime:    2021/3/9
#email:         nheweijun@sina.com


from ..models import *

from app.util.component.ApiTemplate import ApiTemplate
class Api(ApiTemplate):
    api_name = "目录树"
    def process(self):

        # 返回结果
        res = {}
        try:
            # 业务逻辑
            database_guid = self.para.get("database_guid")
            catalogs = Catalog.query.filter_by(database_guid=database_guid).all()

            tree_origin = []
            for cata in catalogs:
                catalog_guids = [c.guid for c in Catalog.query.filter(Catalog.path.like("%" + cata.guid + "%")).all()]
                table_count = Table.query.filter(Table.catalog_guid.in_(catalog_guids)).count()

                cata_json ={}
                cata_json["database_guid"]=cata.database_guid
                cata_json["description"] = cata.description
                cata_json["guid"] = cata.guid
                cata_json["name"] = cata.name
                cata_json["path"] = cata.path
                cata_json["pguid"] = cata.pguid
                cata_json["sort"] = cata.sort
                cata_json["table_count"]=table_count
                cata_json["children"] = []
                tree_origin.append(cata_json)

            for cata in tree_origin:
                cata_pguid = cata["pguid"]
                if not cata_pguid=="0":
                    for c in tree_origin:
                        if c["guid"].__eq__(cata_pguid):
                            c["children"].append(cata)

            res["data"] = [cata for cata in tree_origin if cata["pguid"].__eq__("0")]
            res["result"] = True
        except Exception as e:
            raise e
        return res

    api_doc={
    
    "tags":["矢量数据目录接口"],
    "parameters":[
        {"name": "database_guid",
         "in": "formData",
         "type": "string",
         "description": "数据库guid", "required": "true"},
    
    ],
    "responses":{
        200:{
            "schema":{
                "properties":{
                }
            }
            }
        }
    }