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


from app.models import ServiceCatalog,db,Service

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

        # 返回结果
        res = {}
        try:
            # 业务逻辑

            res["data"] = []
            catalogs = ServiceCatalog.query.filter_by(pguid=self.para.get("catalog_guid")).all()
            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 = ModelVisitor.object_to_json(cata)
                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":[
        {"name": "catalog_guid",
         "in": "formData",
         "type": "string",
         "description":"目录guid","required": "true"},
        {"name": "database_guid",
         "in": "formData",
         "type": "string",
         "description": "数据库guid", "required": "true"},

    ],
    "responses":{
        200:{
            "schema":{
                "properties":{
                }
            }
            }
        }
    }