service_list_base.py
3.5 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
# 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,ImageService
from sqlalchemy import or_
from app.util.component.GeometryAdapter import GeometryAdapter
import json
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.__eq__("切片服务"):
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)
if ser.type.__eq__("影像服务"):
image_extent = ser.relate_image_service.one_or_none().extent
g2 = GeometryAdapter.bbox_2_polygon(json.loads(image_extent))
if g1.Intersect(g2):
fit_services.append(ser)
else:
fit_services = services
res["data"] = {}
res["data"]["count"] = len(fit_services)
res["data"]["list"] = ModelVisitor.objects_to_jsonarray(fit_services[page_index * page_size:(page_index+1) * page_size])
for service_json in res["data"]["list"]:
service_json["functions"] = sorted(ModelVisitor.objects_to_jsonarray(ServiceFunction.query.filter_by(service_guid=service_json["guid"]).all()),
key=lambda x:x["type"])
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": {
}
}
}
}
}