image_service_edit.py
5.2 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
142
143
144
145
146
# coding=utf-8
#author: 4N
#createtime: 2021/7/19
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from ..models import Service,ImageService,Image,db,ServiceFunction
import datetime
import json
from .image_service_register import Api as RegisterApi
import configure
import uuid
class Api(ApiTemplate):
api_name = "修改影像服务"
def process(self):
# 返回结果
res = {}
try:
guid = self.para.get("guid")
service = Service.query.filter_by(guid=guid)
this_time = datetime.datetime.now()
image_guids = self.para.get("image_guids")
function_types = self.para.get("function_types")
service_update = {}
image_update = {}
for key in self.para.keys():
if key in ["name","title","state","description","catalog_guid"]:
service_update[key] = self.para.get(key)
if key in ["name","scheme_guid"]:
image_update[key] = self.para.get(key)
image_service = ImageService.query.filter_by(service_guid=guid)
# 修改功能
if function_types:
new_types = function_types.split(",")
old_functions = ServiceFunction.query.filter_by(service_guid=guid).all()
for function in old_functions:
if function.type not in new_types:
db.session.delete(function)
for new_type in new_types:
if new_type not in [fun.type for fun in old_functions]:
service_function = ServiceFunction(guid=uuid.uuid1().__str__())
db.session.add(service_function)
#修改影像
if image_guids:
image_service_exetent = []
imgservice:ImageService = image_service.one_or_none()
imgservice.images = []
for g in image_guids.split(","):
image = Image.query.filter_by(guid=g).one_or_none()
if image:
image_extent = json.loads(image.extent)
if not image_service_exetent:
image_service_exetent = image_extent
else:
image_service_exetent[0] = min(image_extent[0], image_service_exetent[0])
image_service_exetent[1] = min(image_extent[1], image_service_exetent[1])
image_service_exetent[2] = max(image_extent[2], image_service_exetent[2])
image_service_exetent[3] = max(image_extent[3], image_service_exetent[3])
imgservice.images.append(image)
image_update["extent"] = json.dumps(image_service_exetent)
if service_update or image_update or function_types:
service_update["update_time"] = this_time
if image_guids:
register_api = RegisterApi()
overview_file = register_api.get_overview(service, image_service)
service_update["overview"] = "http://{}/API/Service/Overview/{}".format(configure.deploy_ip_host, overview_file)
service.update(service_update)
if image_update:
image_service.update(image_update)
db.session.commit()
res["result"] = True
except Exception as e:
db.session.rollback()
raise e
return res
api_doc = {
"tags": ["影像接口"],
"parameters": [
{"name": "guid",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]guid"},
{"name": "name",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]"},
{"name": "title",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]"},
{"name": "description",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]"},
{"name": "catalog_guid",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]"},
{"name": "function_types",
"in": "formData",
"type": "string",
"description": "[地图服务,切片服务,影像服务]以逗号相隔,可选WMTS,WMS"},
{"name": "image_guids",
"in": "formData",
"type": "string","description":"修改该服务的影像,用逗号相隔"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}