service_list.py
2.8 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
# 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 app.models import Service
from sqlalchemy import or_
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"))
alias = self.para.get("alias")
name = self.para.get("name")
type = self.para.get("type")
catalog_guid = self.para.get("catalog_guid")
services = Service.query
if type:
services = services.filter_by(type=type)
if catalog_guid:
services = services.filter_by(catalog_guid=catalog_guid)
# 并集
if alias and name:
services = services.filter(
or_(Service.alias.like("%" + alias + "%"), Service.name.like("%" + name + "%")))
else:
if alias:
services = services.filter(Service.alias.like("%" + alias + "%"))
if name:
services = services.filter(Service.name.like("%" + name + "%"))
services = services.limit(page_size).offset(page_index).all()
res["data"] = ModelVisitor.objects_to_jsonarray(services)
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["服务接口"],
"parameters": [
{"name": "page_index",
"in": "formData",
"type": "int",
"description": "页"},
{"name": "page_size",
"in": "formData",
"type": "int",
"description": "页大小"},
{"name": "alias",
"in": "formData",
"type": "string",
"description": "服务别名"},
{"name": "name",
"in": "formData",
"type": "string",
"description": "服务名"},
{"name": "type",
"in": "formData",
"type": "string",
"description": "服务类型",
"enum":["WMTS","TMS","WMS/WFS","ImageWMTS","ImageWMS"]},
{"name": "catalog_guid",
"in": "formData",
"type": "string",
"description": "服务目录"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}