service_info.py
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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
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 ["地图服务","切片服务"]:
service = Service.query.filter_by(guid=guid).one_or_none()
if not service:
raise Exception("服务不存在!")
res["data"] = {}
if service.type.__eq__("影像服务"):
speci_service = service.relate_image_service.one_or_none()
relate_images = speci_service.images.all()
res["data"]["speci_service"] = ModelVisitor.object_to_json(speci_service)
res["data"]["speci_service"]["images"] = [{"name":im["name"],"guid":im["guid"]} for im in ModelVisitor.objects_to_jsonarray(relate_images)]
res["data"]["speci_service"]["images"] = sorted(res["data"]["speci_service"]["images"], key=lambda x: x["name"])
elif service.type.__eq__("切片服务"):
speci_service = service.relate_tile_service.one_or_none()
res["data"]["speci_service"] = ModelVisitor.object_to_json(speci_service)
elif service.type.__eq__("地图服务"):
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 ["影像服务"]:
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":["地图服务","切片服务","影像服务"]},
{"name": "url",
"in": "formData",
"type": "string",
"description": "url"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}