check_progress.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. """盘点接口实现进度:对照 API清单.csv 与 Java 控制器的 @RequestMapping。"""
  3. import csv
  4. import re
  5. from pathlib import Path
  6. ROOT = Path(r"C:\Users\Administrator\WorkBuddy\2026-10-17-12-27-10\java-rewrite")
  7. CTRL = ROOT / "yoshop-java/src/main/java/cn/yoshop/store/controller"
  8. # 收集 Java 已实现路由
  9. implemented = set()
  10. for f in CTRL.glob("*.java"):
  11. src = f.read_text(encoding="utf-8")
  12. base = re.search(r'@RequestMapping\("([^"]+)"\)', src)
  13. if not base:
  14. continue
  15. base = base.group(1)
  16. # 支持 @RequestMapping("/x") 与 @RequestMapping(value = {"/x", "/y"}) 两种写法
  17. for m in re.finditer(r'@(?:Get|Post|Request)Mapping\(([^)]*)\)', src):
  18. for sub in re.findall(r'"([^"]*)"', m.group(1)):
  19. if sub.startswith("/store/"):
  20. implemented.add(sub)
  21. elif sub.startswith("/"):
  22. implemented.add(base + sub)
  23. implemented = {p.rstrip("/") for p in implemented}
  24. def norm(p):
  25. """统一大小写/下划线:清单里是 list_by_ids,Java 路由是 listByIds"""
  26. return re.sub(r"[^a-z0-9]", "", p.lower())
  27. implemented_norm = {norm(p) for p in implemented}
  28. # 收集 PHP 接口清单(仅 store 模块)
  29. php = []
  30. with open(ROOT / "API清单.csv", encoding="utf-8-sig") as fp:
  31. for row in csv.reader(fp):
  32. if len(row) < 7 or row[0] != "store":
  33. continue
  34. action = row[4].strip()
  35. if not action:
  36. continue
  37. path = row[5].rstrip("/")
  38. if path not in php:
  39. php.append(path)
  40. done, todo = [], []
  41. for p in php:
  42. if norm(p) in implemented_norm:
  43. done.append(p)
  44. else:
  45. todo.append(p)
  46. print("PHP 接口数:", len(php), " Java 已实现:", len(done), " 待实现:", len(todo))
  47. print("\n待实现清单:")
  48. for p in todo:
  49. print(" " + p)