service_info.py 2.8 KB
# coding=utf-8
#author:        4N
#createtime:    2021/9/22
#email:         nheweijun@sina.com


from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.ModelVisitor import ModelVisitor
from .models import Service
import requests
from .util.ServiceType import ServiceType

class Api(ApiTemplate):
    api_name = "服务Info"
    def process(self):
        res = {}
        try:

            guid = self.para.get("guid")
            s_type =  self.para.get("type")

            if s_type in [ServiceType.map_service.value,ServiceType.tile_service.value]:

                service = Service.query.filter_by(guid=guid).one_or_none()
                if not service:
                    raise Exception("服务不存在!")
                res["data"] = {}

                if service.type == ServiceType.tile_service.value:
                    speci_service = service.relate_tile_service.one_or_none()
                    res["data"]["speci_service"] = ModelVisitor.object_to_json(speci_service)
                elif service.type == ServiceType.map_service.value:
                    speci_service = service.relate_map_service.one_or_none()
                    res["data"]["speci_service"] = ModelVisitor.object_to_json(speci_service)
                else:
                    res["data"] = {}

                functions = ModelVisitor.objects_to_jsonarray(service.relate_service_functions.all())
                res["data"]["service"] = ModelVisitor.object_to_json(service)
                res["data"]["service"]["functions"] = functions

            elif s_type in [ServiceType.image_service.value]:

                edit_url = "{}/API/Service/Info".format(self.para.get("url"))
                response:requests.Response = requests.post(edit_url,self.para)
                if not response.json().get("result"):
                    raise Exception("查询影像地图失败!")
                res = response.json()
            else:
                pass

        except Exception as e:
            raise e
        return res


    api_doc = {
        "tags": ["服务接口"],
        "parameters": [
            {"name": "guid",
             "in": "formData",
             "type": "string",
             "description": "guid"},
            {"name": "type",
             "in": "formData",
             "type": "string",
             "description": "type",
             "enum":[st.value for st in ServiceType]},
            {"name": "url",
             "in": "formData",
             "type": "string",
             "description": "url"},
        ],
        "responses": {
            200: {
                "schema": {
                    "properties": {
                    }
                }
            }
        }
    }