map_service_edit.py
5.1 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
# coding=utf-8
#author: 4N
#createtime: 2021/9/17
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
import uuid
from ..models import Service,MapService,db,ServiceFunction
import requests
import configure
import json
import datetime
from app.util.component.UserCheck import UserCheck
class Api(ApiTemplate):
api_name = "修改MapService服务"
def process(self):
# 返回结果
res = {}
try:
guid = self.para.get("guid")
functions = self.para.get("functions")
service :Service = Service.query.filter_by(guid=guid).one_or_none()
this_time = datetime.datetime.now()
if not service:
raise Exception("服务不存在!")
#验证权限
UserCheck.verify(service.creator)
service_update = {"update_time":this_time}
map_service_update = {}
for key in self.para.keys():
if key in ["name","title","description","overview","catalog_guid"]:
service_update[key] = self.para.get(key)
if key in ["name","tile","project","capabilities"]:
map_service_update[key] = self.para.get(key)
para = {"name":self.para.get("name"),
"title":self.para.get("title"),
"type":"mapserver",
"capabilities":2,
"project":self.para.get("project"),
"state":service.state
}
map_service_register_url = "{}/dmap/api/manager/regservice".format(configure.dmap_engine)
resp: requests.Response = requests.post(map_service_register_url,data=json.dumps(para),
headers={'Content-Type':'application/json'},timeout=3
)
if resp.status_code == 200:
resp.encoding="utf-8"
resp_json = resp.json()
if not resp_json["status"]=="1":
raise Exception("调用矢量服务的修改服务接口失败!")
else:
raise Exception("调用矢量服务的修改服务接口失败!")
service_update["overview"] = resp_json["url"]
# 修改功能
if functions:
new_types = functions.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__(),type=new_type,
service_guid=guid)
db.session.add(service_function)
map_service = MapService.query.filter_by(service_guid=guid)
if service_update:
Service.query.filter_by(guid=guid).update(service_update)
if map_service_update:
map_service.update(map_service_update)
db.session.commit()
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["矢量地图接口"],
"parameters": [
{"name": "name",
"in": "formData",
"type": "string",
"required": "true",
"description": "[矢量地图,电子地图,影像地图]"},
{"name": "title",
"in": "formData",
"type": "string",
"description": "[矢量地图,电子地图,影像地图]"},
{"name": "description",
"in": "formData",
"type": "string",
"description": "[矢量地图,电子地图,影像地图]"},
{"name": "catalog_guid",
"in": "formData",
"type": "string",
"description": "[矢量地图,电子地图,影像地图]"},
{"name": "layer_style",
"in": "formData",
"type": "string",
"description": "[矢量地图,电子地图]图层样式"},
{"name": "functions",
"in": "formData",
"type": "string",
"description": "[矢量地图]服务能力,用逗号相隔"},
#矢量地图参数
{"name": "capabilities",
"in": "formData",
"type": "int",
"description": "[矢量地图]"},
{"name": "project",
"in": "formData",
"type": "string",
"description": "[矢量地图]project"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}