catalog_delete.py
1.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
# coding=utf-8
#author: 4N
#createtime: 2021/3/9
#email: nheweijun@sina.com
from ..models import *
from app.util.component.ApiTemplate import ApiTemplate
class Api(ApiTemplate):
api_name = "删除目录"
def process(self):
# 返回结果
res = {}
try:
# 业务逻辑
catalog_guid = self.para.get("guid")
catalog = Catalog.query.filter_by(guid=catalog_guid).one_or_none()
if not catalog:
res["msg"]="目录不存在!"
return res
else:
# 转移目录下的数据
pguid = catalog.pguid
# 所有目录
catalogs = Catalog.query.filter(Catalog.path.like("%" + catalog_guid + "%")).all()
for cata in catalogs:
if pguid.__eq__("0"):
Table.query.filter_by(catalog_guid=cata.guid).update({"catalog_guid": None})
db.session.delete(cata)
else:
Table.query.filter_by(catalog_guid=cata.guid).update({"catalog_guid": pguid})
db.session.delete(cata)
db.session.commit()
res["msg"] = "目录删除成功!"
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", "required": "true"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}