service_delete.py
2.9 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
# coding=utf-8
#author: 4N
#createtime: 2021/9/14
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from app.models import db
from app.modules.service.models import Service
from app.modules.service.models import TileService
from app.modules.service.models import MapService
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")
s_type = self.para.get("type")
#删除本地服务
if s_type in ["切片服务","地图服务"]:
service:Service = Service.query.filter_by(guid=guid).one_or_none()
if service:
# 验证权限
UserCheck.verify(service.creator)
try:
if service.type.__eq__("切片服务"):
#调用接口
tile_service = TileService.query.filter_by(service_guid=guid).one_or_none()
db.session.delete(tile_service)
if service.type.__eq__("地图服务"):
map_service = MapService.query.filter_by(service_guid=guid).one_or_none()
db.session.delete(map_service)
service_functions = service.relate_service_functions.all()
for function in service_functions:
db.session.delete(function)
except:
pass
db.session.delete(service)
else:
raise Exception("服务不存在!")
# 删除影像服务
else:
from app.modules.service.image_service.image_service_delete import Api as RealApi
api = RealApi()
api.para = self.para
res = api.process()
db.session.commit()
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["服务接口"],
"parameters": [
{"name": "guid",
"in": "formData",
"type": "string",
"description": "guid"},
{"name": "type",
"in": "formData",
"type": "string",
"description": "type"},
{"name": "url",
"in": "formData",
"type": "string",
"description": "url"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}