extract_mappings.ps1 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Extract all @RequestMapping paths from fs-admin-saas source code
  2. # and compare with frontend API paths
  3. $basePath = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
  4. $controllers = Get-ChildItem -Path $basePath -Recurse -Filter "*Controller.java"
  5. $backendMappings = @{}
  6. foreach ($file in $controllers) {
  7. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  8. # Extract class-level @RequestMapping
  9. $classMapping = ""
  10. if ($content -match '@RequestMapping\(["\s]*\(\s*["\x27]([^"\x27]+)["\x27]') {
  11. $classMapping = $Matches[1]
  12. } elseif ($content -match '@RequestMapping\s*\(\s*value\s*=\s*["\x27]([^"\x27]+)["\x27]') {
  13. $classMapping = $Matches[1]
  14. }
  15. # Check if controller has @Profile that excludes it from company
  16. $hasAdminProfile = $content -match '@Profile\s*\(\s*["\x27]admin["\x27]\s*\)'
  17. # Extract method-level mappings
  18. $methodMatches = [regex]::Matches($content, '@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=\s*)?["\x27]([^"\x27]+)["\x27]')
  19. foreach ($m in $methodMatches) {
  20. $methodPath = $m.Groups[2].Value
  21. $fullPath = "$classMapping$methodPath"
  22. # Normalize: remove trailing slash, ensure starts with /
  23. $fullPath = $fullPath -replace '/+', '/'
  24. if (-not $fullPath.StartsWith('/')) { $fullPath = "/$fullPath" }
  25. $profile = if ($hasAdminProfile) { "admin" } else { "company" }
  26. $relPath = $file.FullName.Substring($basePath.Length + 1)
  27. if (-not $backendMappings.ContainsKey($fullPath)) {
  28. $backendMappings[$fullPath] = "$profile | $relPath"
  29. }
  30. }
  31. # Also handle class-level only (no method paths)
  32. if ($classMapping -and $methodMatches.Count -eq 0) {
  33. $fullPath = $classMapping -replace '/+', '/'
  34. if (-not $fullPath.StartsWith('/')) { $fullPath = "/$fullPath" }
  35. $profile = if ($hasAdminProfile) { "admin" } else { "company" }
  36. $relPath = $file.FullName.Substring($basePath.Length + 1)
  37. if (-not $backendMappings.ContainsKey($fullPath)) {
  38. $backendMappings[$fullPath] = "$profile | $relPath"
  39. }
  40. }
  41. }
  42. Write-Host "Total backend mappings found: $($backendMappings.Count)"
  43. # Also scan fs-company's own controllers
  44. $companyPath = "d:\ylrz\ylrz_saas_his_scrm\fs-company\src\main\java\com\fs"
  45. $companyControllers = Get-ChildItem -Path $companyPath -Recurse -Filter "*Controller.java"
  46. foreach ($file in $companyControllers) {
  47. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  48. $classMapping = ""
  49. if ($content -match '@RequestMapping\(["\s]*\(\s*["\x27]([^"\x27]+)["\x27]') {
  50. $classMapping = $Matches[1]
  51. } elseif ($content -match '@RequestMapping\s*\(\s*value\s*=\s*["\x27]([^"\x27]+)["\x27]') {
  52. $classMapping = $Matches[1]
  53. }
  54. $methodMatches = [regex]::Matches($content, '@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=\s*)?["\x27]([^"\x27]+)["\x27]')
  55. foreach ($m in $methodMatches) {
  56. $methodPath = $m.Groups[2].Value
  57. $fullPath = "$classMapping$methodPath"
  58. $fullPath = $fullPath -replace '/+', '/'
  59. if (-not $fullPath.StartsWith('/')) { $fullPath = "/$fullPath" }
  60. $relPath = "company:" + $file.FullName.Substring($companyPath.Length + 1)
  61. if (-not $backendMappings.ContainsKey($fullPath)) {
  62. $backendMappings[$fullPath] = "company | $relPath"
  63. }
  64. }
  65. }
  66. Write-Host "Total backend mappings (with fs-company): $($backendMappings.Count)"
  67. # Count by profile
  68. $adminMappings = ($backendMappings.Values | Where-Object { $_ -match "^admin" }).Count
  69. $companyMappings = ($backendMappings.Values | Where-Object { $_ -match "^company" }).Count
  70. Write-Host "Admin-only mappings: $adminMappings"
  71. Write-Host "Company mappings: $companyMappings"
  72. # List all mappings sorted
  73. $backendMappings.Keys | Sort-Object | Select-Object -First 50 | ForEach-Object { Write-Host " $_ => $($backendMappings[$_])" }
  74. # Save all mappings
  75. $out = [System.Collections.ArrayList]::new()
  76. [void]$out.Add("Total backend mappings: $($backendMappings.Count)")
  77. [void]$out.Add("Admin-only: $adminMappings")
  78. [void]$out.Add("Company: $companyMappings")
  79. [void]$out.Add("")
  80. foreach ($key in ($backendMappings.Keys | Sort-Object)) {
  81. [void]$out.Add("$key => $($backendMappings[$key])")
  82. }
  83. [System.IO.File]::WriteAllLines("d:\ylrz\saasadminui\backend_mappings.txt", $out, (New-Object System.Text.UTF8Encoding($false)))
  84. Write-Host "`nMappings saved to d:\ylrz\saasadminui\backend_mappings.txt"