extract_mappings_v2.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Better extraction: properly combine class + method request mappings
  2. $basePath = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
  3. $companyBasePath = "d:\ylrz\ylrz_saas_his_scrm\fs-company\src\main\java\com\fs"
  4. $backendMappings = @{}
  5. function Process-Controllers {
  6. param($searchPath, $label)
  7. $controllers = Get-ChildItem -Path $searchPath -Recurse -Filter "*Controller.java"
  8. foreach ($file in $controllers) {
  9. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  10. # Skip admin-profiled controllers when we care about company
  11. $hasAdminProfile = $content -match '@Profile\s*\(\s*["\x27]admin["\x27]\s*\)'
  12. $hasCompanyProfile = $content -match '@Profile\s*\(\s*["\x27]company["\x27]\s*\)'
  13. # Extract class-level @RequestMapping
  14. $classMapping = ""
  15. if ($content -match '(?s)@RequestMapping\s*\(\s*(?:value\s*=\s*)?["\x27](/[^"\x27]+)["\x27]') {
  16. $classMapping = $Matches[1]
  17. }
  18. if ($classMapping -eq "") { continue }
  19. $profile = if ($hasAdminProfile) { "admin" } elseif ($hasCompanyProfile) { "company" } else { "none" }
  20. # Get all method mappings with their HTTP methods
  21. # Split content by method annotations to get individual methods
  22. $methods = $content -split '@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)'
  23. $i = 0
  24. while ($i -lt $methods.Count) {
  25. $annotation = $methods[$i]
  26. $i++
  27. if ($i -ge $methods.Count) { break }
  28. $methodBody = $methods[$i]
  29. $i++
  30. # Extract path from annotation value
  31. $methodPath = ""
  32. if ($methodBody -match '^\s*\(\s*(?:value\s*=\s*)?["\x27]([^"\x27]+)["\x27]') {
  33. $methodPath = $Matches[1]
  34. } elseif ($methodBody -match '^\s*\(\s*(?:path|value)\s*=\s*["\x27]([^"\x27]+)["\x27]') {
  35. $methodPath = $Matches[1]
  36. }
  37. if ($methodPath -eq "") { continue }
  38. $fullPath = "$classMapping$methodPath"
  39. $fullPath = $fullPath -replace '/+', '/'
  40. $httpMethod = switch ($annotation) {
  41. "GetMapping" { "GET" }
  42. "PostMapping" { "POST" }
  43. "PutMapping" { "PUT" }
  44. "DeleteMapping" { "DELETE" }
  45. "RequestMapping" { "ANY" }
  46. default { "?" }
  47. }
  48. $key = "$httpMethod $fullPath"
  49. $relPath = "${label}:" + $file.FullName.Substring($searchPath.Length + 1)
  50. if (-not $backendMappings.ContainsKey($key)) {
  51. $backendMappings[$key] = "$profile | $relPath"
  52. }
  53. }
  54. # If class has @RequestMapping but no method paths, add the class path itself
  55. # This handles cases where methods use inherited paths
  56. }
  57. }
  58. Process-Controllers -searchPath $basePath -label "saas"
  59. Process-Controllers -searchPath $companyBasePath -label "company"
  60. Write-Host "Total unique mappings: $($backendMappings.Count)"
  61. # Group by module (first segment of path)
  62. $byModule = @{}
  63. foreach ($key in $backendMappings.Keys) {
  64. if ($key -match '^\w+\s+(/[^/]+)') {
  65. $mod = $Matches[1]
  66. if (-not $byModule.ContainsKey($mod)) { $byModule[$mod] = 0 }
  67. $byModule[$mod]++
  68. }
  69. }
  70. Write-Host "`n=== Mappings by Module ==="
  71. $byModule.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { Write-Host " $($_.Key): $($_.Value)" }
  72. # Count active (non-admin) mappings
  73. $activeMappings = $backendMappings.Keys | Where-Object { $backendMappings[$_] -notmatch "^admin" }
  74. Write-Host "`nActive (company) mappings: $($activeMappings.Count)"
  75. # List company mappings
  76. Write-Host "`n=== Company/Active Mappings (first 50) ==="
  77. $activeMappings | Sort-Object | Select-Object -First 50 | ForEach-Object { Write-Host " $_ => $($backendMappings[$_])" }
  78. # Save
  79. $out = [System.Collections.ArrayList]::new()
  80. [void]$out.Add("Total: $($backendMappings.Count)")
  81. foreach ($key in ($backendMappings.Keys | Sort-Object)) {
  82. [void]$out.Add("$key => $($backendMappings[$key])")
  83. }
  84. [System.IO.File]::WriteAllLines("d:\ylrz\saasadminui\backend_mappings_v2.txt", $out, (New-Object System.Text.UTF8Encoding($false)))
  85. Write-Host "`nSaved to backend_mappings_v2.txt"