6 changed files with 83 additions and 0 deletions
@ -0,0 +1,64 @@ |
|||||
|
import csv |
||||
|
import io |
||||
|
|
||||
|
# Read file |
||||
|
with open(r'D:\EnforcementCodeProject\CodeV2\EnforcementCode-2.0\doc\数据权限控制\原始数据.csv', 'r', encoding='utf-8') as f: |
||||
|
content = f.read() |
||||
|
|
||||
|
# Parse paths from CSV, store vir_id and vir_zone for each path endpoint |
||||
|
path_info = {} # path -> (vir_id, vir_zone) |
||||
|
reader = csv.reader(io.StringIO(content)) |
||||
|
for row in reader: |
||||
|
if len(row) >= 8: |
||||
|
path = row[6].strip() |
||||
|
vir_id = row[0].strip() |
||||
|
vir_zone = row[4].strip() |
||||
|
if path and path.startswith('深圳市'): |
||||
|
path_info[path] = (vir_id, vir_zone) |
||||
|
|
||||
|
# Build tree - store children as ordered dict |
||||
|
tree = {} |
||||
|
for path in sorted(path_info.keys()): |
||||
|
parts = path.split('/') |
||||
|
node = tree |
||||
|
for part in parts: |
||||
|
if part not in node: |
||||
|
node[part] = {} |
||||
|
node = node[part] |
||||
|
|
||||
|
# Build a lookup: full_path -> (vir_id, vir_zone) for each node |
||||
|
# We need to map each node in the tree to its path to find info |
||||
|
node_info = {} # tuple of path parts -> (vir_id, vir_zone) |
||||
|
for path, info in path_info.items(): |
||||
|
parts = tuple(path.split('/')) |
||||
|
node_info[parts] = info |
||||
|
|
||||
|
# Generate ASCII tree |
||||
|
lines = [] |
||||
|
|
||||
|
def render_tree(node, prefix='', is_root=True, path_parts=()): |
||||
|
keys = sorted(node.keys()) |
||||
|
for i, key in enumerate(keys): |
||||
|
is_last_item = (i == len(keys) - 1) |
||||
|
current_path = path_parts + (key,) |
||||
|
# Get info suffix |
||||
|
info = node_info.get(current_path) |
||||
|
suffix = f'({info[0]})({info[1]})' if info else '' |
||||
|
|
||||
|
if is_root: |
||||
|
lines.append(key + suffix) |
||||
|
render_tree(node[key], '', False, current_path) |
||||
|
else: |
||||
|
connector = '└── ' if is_last_item else '├── ' |
||||
|
lines.append(prefix + connector + key + suffix) |
||||
|
extension = ' ' if is_last_item else '│ ' |
||||
|
render_tree(node[key], prefix + extension, False, current_path) |
||||
|
|
||||
|
render_tree(tree) |
||||
|
|
||||
|
# Write output |
||||
|
output = '# 树型执法单位\n\n```\n' + '\n'.join(lines) + '\n```\n' |
||||
|
with open(r'D:\EnforcementCodeProject\CodeV2\EnforcementCode-2.0\doc\数据权限控制\树型执法单位.md', 'w', encoding='utf-8') as f: |
||||
|
f.write(output) |
||||
|
|
||||
|
print(f'Done! Total paths: {len(path_info)}, Total lines: {len(lines)}') |
||||
@ -0,0 +1,2 @@ |
|||||
|
@echo off |
||||
|
python "D:\EnforcementCodeProject\CodeV2\EnforcementCode-2.0\doc\数据权限控制\gen_tree.py" |
||||
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 794 B |
|
After Width: | Height: | Size: 794 B |
@ -0,0 +1,17 @@ |
|||||
|
package org.dromara; |
||||
|
|
||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
|
public class Main { |
||||
|
public static void main(String[] args) { |
||||
|
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
|
// to see how IntelliJ IDEA suggests fixing it.
|
||||
|
System.out.printf("Hello and welcome!"); |
||||
|
|
||||
|
for (int i = 1; i <= 5; i++) { |
||||
|
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
|
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
|
System.out.println("i = " + i); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue