service_list_base.py
4.0 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# coding=utf-8
#author: 4N
#createtime: 2021/9/14
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.ModelVisitor import ModelVisitor
from .models import Service,ServiceFunction,ServiceEngine
from app.util.component.GeometryAdapter import GeometryAdapter
import requests
from .util.ServiceType import ServiceType
class Api(ApiTemplate):
api_name = "底图服务列表"
def process(self):
# 返回结果
res = {}
try:
page_index = int(self.para.get("page_index", "0"))
page_size = int(self.para.get("page_size", "10"))
bbox = self.para.get("bbox")
state = self.para.get("state")
services = Service.query.order_by(Service.update_time.desc())
if state:
services = services.filter_by(state=int(state))
services = services.join(ServiceFunction).filter(ServiceFunction.type=="WMTS")
services = services.all()
fit_services = []
if bbox:
g1 = GeometryAdapter.bbox_2_polygon([float(x) for x in bbox.split(",")])
for ser in services:
if ser.type == ServiceType.tile_service.value:
layer_exetent = ser.relate_tile_service.one_or_none().layer_extent
g2 = GeometryAdapter.envelop_2_polygon([float(x) for x in layer_exetent.split(",")])
if g1.Intersect(g2):
fit_services.append(ser)
else:
fit_services = services
# 本地服务
fit_services_json = ModelVisitor.objects_to_jsonarray(fit_services)
for service_json in fit_services_json:
service_json["functions"] = sorted(ModelVisitor.objects_to_jsonarray(ServiceFunction.query.filter_by(service_guid=service_json["guid"]).all()),
key=lambda x:x["type"])
# 影像地图
image_engines = ServiceEngine.query.filter_by(type="ImageServer").all()
for ie in image_engines:
url = "{}/API/Service/BaseMapList".format(ie.url)
response:requests.Response = requests.post(url,{"page_size":"9999","page_index":"0",
"bbox":bbox,"state":state})
if not response.json().get("result"):
raise Exception("获取影像地图失败!")
else:
raw_json = response.json()["data"]["list"]
fit_services_json.extend(raw_json)
res["data"] = {}
res["data"]["count"] = len(fit_services_json)
fit_services_json = sorted(fit_services_json, key=lambda x: x["update_time"], reverse=True)
res["data"]["list"] = fit_services_json[page_index*page_size:(page_index+1)*page_size]
res["result"] = True
except Exception as e:
raise e
return res
def judge(self,name):
return name.__contains__("演示")
api_doc = {
"tags": ["服务接口"],
"parameters": [
{"name": "page_index",
"in": "formData",
"type": "int",
"description": "页"},
{"name": "page_size",
"in": "formData",
"type": "int",
"description": "页大小"},
{"name": "state",
"in": "formData",
"type": "string",
"description": "状态",
"enum":[0,1]},
{"name": "bbox",
"in": "formData",
"type": "String",
"description": "x1,y1,x2,y2"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}