tile_service_edit.py
7.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# coding=utf-8
#author: 4N
#createtime: 2021/7/19
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.StructuredPrint import StructurePrint
from app.util.component.ModelVisitor import ModelVisitor
import uuid
from ..models import TileService,Service,db,ServiceFunction,TileScheme
import datetime
import requests
from .util.ProjectFile import ProjectFile
import json
from requests import Response
import configure
from authlib.integrations.flask_oauth2 import current_token
from app.util.component.UserCheck import UserCheck
class Api(ApiTemplate):
api_name = "修改切片服务"
def process(self):
res = {}
try:
guid = self.para.get("guid")
service = Service.query.filter_by(guid=guid)
if not service:
raise Exception("服务不存在!")
#验证权限
UserCheck.verify(service.creator)
this_time = datetime.datetime.now()
service_update = {"update_time":this_time}
tile_update = {}
for key in self.para.keys():
if key in ["name","title","state","description","overview","catalog_guid"]:
service_update[key] = self.para.get(key)
if key in ["name","tile_type","vendor","crs","datasource","description",
"layer_name","layer_alias","layer_title","layer_style","layer_format",
"layer_extent","layer_description","scheme_guid"]:
tile_update[key] = self.para.get(key)
if self.para.get("scheme_guid"):
tilesche = TileScheme.query.filter_by(guid=self.para.get("scheme_guid")).one_or_none()
tile_update["scheme"] = json.dumps(ModelVisitor.object_to_json(tilesche))
#通知tileserver,更新缓存
ts:TileService = TileService.query.filter_by(service_guid=guid).one_or_none()
se = service.one_or_none()
tile_type = self.para.get("tile_type") if self.para.get("tile_type") else ts.tile_type
ts_json = ModelVisitor.object_to_json(ts)
ts_json.update(tile_update)
project_file = ProjectFile.create(ts_json)
para = {"name":self.para.get("name") if self.para.get("name") else se.name,
"title":self.para.get("title") if self.para.get("title") else se.title,
"type":"tileserver","capabilities":1 if tile_type == "WMTS" else 16,"project":project_file}
tile_service_edit_url = "{}/dmap/api/manager/RegService".format(configure.tile_engine)
resp: Response = requests.post(tile_service_edit_url,data=json.dumps(para),headers={'Content-Type':'application/json'},timeout=3)
resp.encoding="utf-8"
resp_json = resp.json()
if not resp_json["status"].__eq__("1"):
raise Exception("调用切片服务的注册服务接口失败!")
service_update["overview"] = resp_json["url"]
#修改数据库
tile_service = TileService.query.filter_by(service_guid=guid)
tile_type = self.para.get("tile_type")
# 修改功能
if tile_type:
old_functions = ServiceFunction.query.filter_by(service_guid=guid).all()
for function in old_functions:
if not function.type.__eq__(tile_type):
db.session.delete(function)
if tile_type not in [fun.type for fun in old_functions]:
service_function = ServiceFunction(guid=uuid.uuid1().__str__(),type=tile_type,service_guid=guid)
db.session.add(service_function)
if service_update:
service.update(service_update)
if tile_update:
tile_service.update(tile_update)
db.session.commit()
res["result"] = True
except Exception as e:
raise Exception("数据库错误!")
return res
api_doc = {
"tags": ["切片服务接口"],
"parameters": [
{"name": "guid",
"in": "formData",
"type": "string",
"description": "service 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": "scheme_guid",
"in": "formData",
"type": "string",
"description": "[切片服务,影像服务]切片方案"},
# 切片服务参数
{"name": "overview",
"in": "formData",
"type": "string",
"description": "[切片服务]缩略图"},
{"name": "tile_type",
"in": "formData",
"type": "string",
"description": "[切片服务]tile_type",
"enum":["WMTS","TMS"]},
{"name": "vendor",
"in": "formData",
"type": "string",
"description": "[切片服务]厂商"},
{"name": "crs",
"in": "formData",
"type": "string",
"description": "[切片服务]坐标系"},
{"name": "datasource",
"in": "formData",
"type": "string",
"description": "[切片服务]数据路径"},
{"name": "layer_name",
"in": "formData",
"type": "string",
"description": "[切片服务]图层名"},
{"name": "layer_alias",
"in": "formData",
"type": "string",
"description": "[切片服务]图层别名"},
{"name": "layer_title",
"in": "formData",
"type": "string",
"description": "[切片服务]图层标题"},
{"name": "layer_style",
"in": "formData",
"type": "string",
"description": "[切片服务,地图服务]图层样式"},
{"name": "layer_format",
"in": "formData",
"type": "string",
"description": "[切片服务]图层format"},
{"name": "layer_extent",
"in": "formData",
"type": "string",
"description": "[切片服务]图层范围"},
{"name": "layer_description",
"in": "formData",
"type": "string",
"description": "[切片服务]图层描述"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}