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


from app.models import Service,ServiceCatalog,db

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

        # 返回结果
        res = {}
        try:
            # 业务逻辑
            catalogs = ServiceCatalog.query.all()
            res["data"]=[]
            for cata in catalogs:
                catalog_guids = [c.guid for c in ServiceCatalog.query.filter(ServiceCatalog.path.like("%" + cata.guid + "%")).all()]
                service_count = Service.query.filter(Service.catalog_guid.in_(catalog_guids)).count()
                cata_json ={}
                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["service_count"]=service_count
                res["data"].append(cata_json)
    
            res["result"] = True
    
        except Exception as e:
            raise e
        return res
    
    api_doc={
    
    "tags":["服务目录接口"],
    "parameters":[
    ],
    "responses":{
        200:{
            "schema":{
                "properties":{
                }
            }
            }
        }
    }