table_list.py
4.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#author: 4N
#createtime: 2021/1/27
#email: nheweijun@sina.com
from app.models import Table,Catalog,Database,DES,Columns,db
from sqlalchemy import or_,and_
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.ModelVisitor import ModelVisitor
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")
database_guid = self.para.get("database_guid")
catalog_guid = self.para.get("catalog_guid")
table_type = self.para.get("table_type")
start_time = self.para.get("start_time")
end_time = self.para.get("end_time")
recursion = int(self.para.get("recursion","0"))
sort = int(self.para.get("sort","1"))
if sort.__eq__(1):
tables = Table.query.order_by(Table.update_time.desc(),Table.name)
else:
tables = Table.query.order_by(Table.name)
if database_guid:
tables = tables.filter_by(database_guid=database_guid)
if catalog_guid:
if recursion.__eq__(0):
tables = tables.filter_by(catalog_guid=catalog_guid)
else:
#所有子目录id
catalog_guids = [c.guid for c in Catalog.query.filter(Catalog.path.like("%" + catalog_guid + "%")).all()]
tables = tables.filter(Table.catalog_guid.in_(catalog_guids))
if table_type:
tables = tables.filter_by(table_type=table_type)
if start_time and end_time:
tables = tables.filter(Table.create_time.between(start_time, end_time))
# 并集
if alias and name:
tables = tables.filter(or_(Table.alias.like("%" + alias + "%") , Table.name.like("%" + name + "%")))
else:
if alias:
tables = tables.filter(Table.alias.like("%" + alias + "%"))
if name:
tables = tables.filter(Table.name.like("%" + name + "%"))
res["data"]={}
res["data"]["count"] = tables.count()
tables = tables.limit(page_size).offset(page_index * page_size).all()
res["data"]["list"]=[]
for t in tables:
res["data"]["list"].append(ModelVisitor.table_to_json(t))
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": "table_type",
"in": "formData",
"type": "int",
"description": "点线面123","enum":[1,2,3]},
{"name": "database_guid",
"in": "formData",
"type": "string",
"description": "数据库guid"},
{"name": "catalog_guid",
"in": "formData",
"type": "string",
"description": "目录guid"},
{"name": "recursion",
"in": "formData",
"type": "int",
"description": "是否递归目录,0不递归,1递归","enum":[0,1]},
{"name": "start_time",
"in": "formData",
"type": "string",
"description": "开始时间 2020-12-12 00:00:00"},
{"name": "end_time",
"in": "formData",
"type": "string",
"description": "结束时间"},
{"name": "sort",
"in": "formData",
"type": "int",
"description": "排序","enum":[1,2]},
],
"responses":{
200:{
"schema":{
"properties":{
}
}
}
}
}