analyze_404.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Analyze 404 APIs - check which ones are due to excludeFilters vs truly missing controllers
  2. $notFound = Get-Content "d:\ylrz\saasadminui\api_404.txt"
  3. # Check which of these paths exist in fs-admin-saas controllers but are excluded by @Profile("admin") or excludeFilters
  4. $saasSrc = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
  5. $companySrc = "d:\ylrz\ylrz_saas_his_scrm\fs-company\src\main\java\com\fs"
  6. $serviceSrc = "d:\ylrz\ylrz_saas_his_scrm\fs-service\src\main\java\com\fs"
  7. # Excluded packages by excludeFilters
  8. $excludedPackages = @(
  9. "admin\controller",
  10. "web\controller",
  11. "api\controller",
  12. "crm\controller",
  13. "qw\controller",
  14. "live\controller",
  15. "course\controller",
  16. "fastGpt",
  17. "fastgptApi",
  18. "user\controller"
  19. )
  20. # Find all @RequestMapping paths in fs-admin-saas
  21. Write-Host "=== Scanning fs-admin-saas controller paths ==="
  22. $saasMappings = @{}
  23. Get-ChildItem -Path $saasSrc -Filter "*.java" -Recurse | ForEach-Object {
  24. $content = Get-Content $_.FullName -Raw -Encoding UTF8
  25. $relPath = $_.FullName.Substring($saasSrc.Length + 1)
  26. # Get class-level @RequestMapping
  27. $classMapping = ""
  28. if ($content -match '@RequestMapping\("([^"]+)"\)') {
  29. $classMapping = $matches[1]
  30. }
  31. # Check if excluded by excludeFilters
  32. $isExcluded = $false
  33. foreach ($pkg in $excludedPackages) {
  34. if ($relPath -like "$pkg*") {
  35. $isExcluded = $true
  36. break
  37. }
  38. }
  39. # Check @Profile
  40. $profile = ""
  41. if ($content -match '@Profile\("([^"]+)"\)') {
  42. $profile = $matches[1]
  43. } elseif ($content -match '@Profile\(\{([^}]+)\}\)') {
  44. $profile = $matches[1]
  45. }
  46. if ($classMapping -ne "") {
  47. $saasMappings[$classMapping] = @{
  48. File = $relPath
  49. Excluded = $isExcluded
  50. Profile = $profile
  51. }
  52. }
  53. }
  54. # Check which 404 paths match saas controllers
  55. $excluded404 = @{}
  56. $missing404 = @{}
  57. foreach ($path in $notFound) {
  58. if ($path -match "^(/[^/]+/[^\?]+)") {
  59. $basePath = $matches[1]
  60. } else {
  61. $basePath = $path
  62. }
  63. $found = $false
  64. foreach ($mapping in $saasMappings.Keys) {
  65. if ($path -like "$mapping*" -or $basePath -like "$mapping*") {
  66. $found = $true
  67. if ($saasMappings[$mapping].Excluded -or $saasMappings[$mapping].Profile -eq "admin") {
  68. if (-not $excluded404.ContainsKey($mapping)) {
  69. $excluded404[$mapping] = @{ Count = 0; File = $saasMappings[$mapping].File; Profile = $saasMappings[$mapping].Profile }
  70. }
  71. $excluded404[$mapping].Count++
  72. }
  73. break
  74. }
  75. }
  76. if (-not $found) {
  77. $prefix = if ($path -match "^(/[^/]+/[^\?/]+)") { $matches[1] } else { $path }
  78. if (-not $missing404.ContainsKey($prefix)) {
  79. $missing404[$prefix] = 0
  80. }
  81. $missing404[$prefix]++
  82. }
  83. }
  84. Write-Host "`n=== 404s caused by excluded @Profile('admin') controllers ==="
  85. $excluded404.GetEnumerator() | Sort-Object { $_.Value.Count } -Descending | ForEach-Object {
  86. Write-Host " $($_.Key) ($($_.Value.Count) APIs) - File: $($_.Value.File) - Profile: $($_.Value.Profile)"
  87. }
  88. Write-Host "`n=== 404s with NO matching controller (truly missing) ==="
  89. $missing404.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 30 | ForEach-Object {
  90. Write-Host " $($_.Key): $($_.Value)"
  91. }
  92. Write-Host "`nTotal excluded-profile 404s: $(($excluded404.GetEnumerator() | Measure-Object -Property { $_.Value.Count } -Sum).Sum)"
  93. Write-Host "Total truly-missing 404s: $(($missing404.GetEnumerator() | Measure-Object -Property Value -Sum).Sum)"