image_list.py
4.3 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
# coding=utf-8
#author: 4N
#createtime: 2021/7/19
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.ModelVisitor import ModelVisitor
from app.util.component.FileProcess import FileProcess
from app.modules.service.models import Image,ImageTag
from sqlalchemy import or_
import datetime
class Api(ApiTemplate):
api_name = "影像数据List"
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")
band = self.para.get("band")
region = self.para.get("region")
tag_guids = self.para.get("tag_guids")
collect_time = self.para.get("collect_time")
type = self.para.get("type")
images = Image.query.order_by(Image.update_time.desc())
# 并集
if alias and name:
images = images.filter(or_(Image.alias.like("%" + alias + "%") , Image.name.like("%" + name + "%")))
else:
if alias:
images = images.filter(Image.alias.like("%" + alias + "%"))
if name:
images = images.filter(Image.name.like("%" + name + "%"))
if band:
images = images.filter(Image.band_view.like("%" + str(band) + "%"))
if type:
images = images.filter_by(type=type)
if region:
images = images.filter(Image.region.in_(region.split(",")))
if collect_time:
begin,end = collect_time.split(",")
begin:datetime.datetime= datetime.datetime.strptime(begin,"%Y-%m-%d")
end = datetime.datetime.strptime(end, "%Y-%m-%d")
images = images.filter(Image.collect_time.__ge__(begin)).filter(Image.collect_time.__le__(end))
if tag_guids:
tag_guids = tag_guids.split(",")
tags = ImageTag.query.filter(ImageTag.guid.in_(tag_guids)).all()
images_guid = []
for tag in tags:
images_guid.extend([img.guid for img in tag.images.all()])
images = images.filter(Image.guid.in_(images_guid))
res["data"] = {}
res["data"]["count"] = images.count()
imgs = images.limit(page_size).offset(page_index * page_size).all()
res["data"]["list"] = ModelVisitor.objects_to_jsonarray(imgs)
#格式化数据
for info in res["data"]["list"]:
info["size"] = FileProcess.get_text_size(info["size"])
info["cell_x_size"] = round(info["cell_x_size"],3)
info["cell_y_size"] = round(info["cell_y_size"], 3)
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"},
{"name": "name",
"in": "formData",
"type": "string"},
{"name": "collect_time",
"in": "formData",
"type": "string"},
{"name": "region",
"in": "formData",
"type": "string"},
{"name": "type",
"in": "formData",
"type": "string"},
{"name": "band",
"in": "formData",
"type": "string"},
{"name": "tag_guids",
"in": "formData",
"type": "string"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}