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.

41 lines
1.3 KiB

6 days ago
# -*- coding: utf-8 -*-
"""Ticket 02 存量盘点:资源树 catalog/menu 节点 perms=null 的欠账统计(只读,不写库)。
list 接口返回树形结构需递归展开后统计"""
import io
import sys
import requests
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
BASE = "http://localhost:8080"
tr = requests.get(BASE + "/api/auth/debug/token", params={"userId": "739564171091247104"}, timeout=15).json()
H = {"Authorization": "Bearer " + tr["data"]}
def flatten(nodes):
out = []
for n in nodes or []:
out.append(n)
out.extend(flatten(n.get("children")))
return out
tree = requests.get(BASE + "/api/resources/list", headers=H, timeout=15).json()["data"]
nodes = flatten(tree)
by_type = {}
null_perms = {}
for n in nodes:
t = n["type"]
by_type[t] = by_type.get(t, 0) + 1
if not n.get("perms"):
null_perms[t] = null_perms.get(t, 0) + 1
print("total=%d by_type=%s" % (len(nodes), by_type))
for t in ("CATALOG", "MENU", "BUTTON"):
total = by_type.get(t, 0)
print("%s: total=%d perms_null=%d" % (t, total, null_perms.get(t, 0)))
if t != "BUTTON" and null_perms.get(t):
for n in nodes:
if n["type"] == t and not n.get("perms"):
print(" - id=%s name=%s" % (n["id"], n["name"]))