You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
3.1 KiB
63 lines
3.1 KiB
# -*- coding: utf-8 -*-
|
|
"""一次性清理:第三轮冒烟中断留下的脏数据
|
|
- 两个演示分组 e2d_group_a_173237 / e2d_group_b_173237
|
|
- 被误建进预置组的「e2d-项1」(name=e2d-项1, value=e2d-val-1, code=dict_xxx)
|
|
- 以及更早探针残留: e2d-探针编辑 组(e2d_probe_edit_*)、e2d_probe_grp 组、e2d_group_a_172001
|
|
"""
|
|
import json, sys, io, urllib.request, urllib.parse
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
|
|
API = "http://localhost:8080"
|
|
ADMIN = "739564171091247104"
|
|
|
|
def post(url, data=None, token=None):
|
|
body = urllib.parse.urlencode(data or {}).encode()
|
|
req = urllib.request.Request(url, data=body, method="POST")
|
|
req.add_header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
|
|
if token: req.add_header("Authorization", "Bearer " + token)
|
|
with urllib.request.urlopen(req, timeout=20) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
tok = json.loads(urllib.request.urlopen(f"{API}/api/auth/debug/token?userId={ADMIN}", timeout=10).read().decode())["data"]
|
|
report = {"items": [], "groups": []}
|
|
|
|
# 1) 全量翻页找出所有 name 以 e2d- 开头的孤儿项(含误建的 e2d-项1 / e2d-项2)
|
|
seen_groups = {}
|
|
for cur in (1, 2, 3, 4, 5):
|
|
pg = post(f"{API}/api/dict/item/page", {"current": cur, "size": 100}, tok)
|
|
rows = (pg.get("data") or {}).get("content", [])
|
|
for it in rows:
|
|
nm = str(it.get("name", ""))
|
|
cd = str(it.get("code", ""))
|
|
if nm.startswith("e2d-") or cd.startswith("e2d_"):
|
|
report["items"].append({"id": str(it["id"]), "name": nm, "code": cd,
|
|
"groupId": str(it.get("groupId", "")), "group": it.get("groupName")})
|
|
if cur >= int((pg.get("data") or {}).get("pages", 1) or 1):
|
|
break
|
|
|
|
# 2) 删这些项
|
|
for it in report["items"]:
|
|
try:
|
|
r = post(f"{API}/api/dict/item/delete", {"id": it["id"]}, tok)
|
|
it["deleted"] = r.get("code") == 200 or r.get("success")
|
|
except Exception as ex:
|
|
it["deleted"] = False; it["err"] = str(ex)[:120]
|
|
|
|
# 3) 找出并删除 e2d 演示分组(先清组内项再删组)
|
|
for kw in ("e2d_group_", "e2d_probe_"):
|
|
gp = post(f"{API}/api/dict/group/page", {"current": 1, "size": 50, "keyword": kw}, tok)
|
|
for g in (gp.get("data") or {}).get("content", []):
|
|
if not str(g.get("code", "")).startswith(("e2d_group_", "e2d_probe_")):
|
|
continue
|
|
gid = str(g["id"])
|
|
ip = post(f"{API}/api/dict/item/page", {"current": 1, "size": 200, "groupId": gid}, tok)
|
|
for it in (ip.get("data") or {}).get("content", []):
|
|
try: post(f"{API}/api/dict/item/delete", {"id": str(it["id"])}, tok)
|
|
except Exception as ex: print("inner item fail", it.get("code"), ex)
|
|
try:
|
|
r = post(f"{API}/api/dict/group/delete", {"id": gid}, tok)
|
|
report["groups"].append({"code": g.get("code"), "deleted": r.get("code") == 200 or r.get("success")})
|
|
except Exception as ex:
|
|
report["groups"].append({"code": g.get("code"), "deleted": False, "err": str(ex)[:120]})
|
|
|
|
print(json.dumps(report, ensure_ascii=False, indent=1))
|
|
|