fix_profile_admin_to_both.ps1 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Change @Profile("admin") to @Profile({"admin", "company"}) for non-conflicting controllers
  2. $saasPath = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
  3. # Get conflicting paths (these should NOT be changed)
  4. $conflictPaths = @(
  5. "/bill/billLog", "/chat/chatDataset", "/chat/chatDatasetFile", "/chat/chatKeyword",
  6. "/chat/chatMsg", "/chat/chatMsgLogs", "/chat/chatRole", "/chat/chatSession",
  7. "/chat/chatUser", "/chat/upload", "/course/courseAnswerLog", "/course/courseFinishTemp",
  8. "/course/courseFinishTempParent", "/course/courseLink", "/course/courseRedPacketLog",
  9. "/course/courseTrafficLog", "/course/period", "/course/playSourceConfig",
  10. "/course/sop", "/course/sopLogs", "/course/trainingCamp", "/course/userCourse",
  11. "/course/userCourseCategory", "/course/userCourseVideo", "/crm/customer",
  12. "/crm/customerAssign", "/crm/customerContacts", "/crm/customerExt",
  13. "/crm/customerHisOrder", "/crm/customerLevel", "/crm/customerLogs",
  14. "/crm/customerUser", "/crm/customerVisit", "/crm/event", "/crm/msg",
  15. "/fastGpt/fastgptChatArtificialWords", "/fastGpt/fastgptEventLogTotal",
  16. "/fastGpt/fastGptKeywordSend", "/fastGpt/fastGptRole", "/fastGpt/fastGptRoleTag",
  17. "/his/doctor", "/his/follow", "/his/FsFollowReport", "/his/integralGoods",
  18. "/his/integralOrder", "/his/userOperationLog", "/index/statistics",
  19. "/live/coupon", "/live/gift", "/live/live", "/live/liveAfterSales",
  20. "/live/liveAnchor", "/live/liveCart", "/live/liveGoods", "/live/liveLotteryConf",
  21. "/live/liveLotteryRecord", "/live/liveLotteryRegistration", "/live/liveMsg",
  22. "/live/liveOrder", "/live/liveOrderItem", "/live/liveOrderLogs",
  23. "/live/liveRedConf", "/live/liveUserFavorite", "/live/liveUserFollow",
  24. "/live/liveUserLike", "/live/liveUserLotteryRecord", "/live/liveVideo",
  25. "/live/record", "/live/task", "/live/words", "/liveData/liveData",
  26. "/monitor/logininfor", "/monitor/operlog", "/order",
  27. "/qw/appContactWay", "/qw/externalContact", "/qw/externalContactTransferCompanyAudit",
  28. "/qw/friendWelcome", "/qw/group_chat_user", "/qw/groupChat", "/qw/qwDept",
  29. "/qw/QwWorkTaskNew", "/qw/sop", "/qw/sopLogs", "/qw/sopTemp", "/qw/tag",
  30. "/qw/tagGroup", "/qw/user", "/qwSop/sopUserLogs", "/qwSop/sopUserLogsInfo",
  31. "/store/material", "/store/materialGroup", "/store/store/statistics",
  32. "/store/store/storeAfterSales", "/store/store/storeOrder", "/store/store/storeOrderAudit",
  33. "/store/store/storeOrderOffline", "/store/store/storePayment", "/store/store/storeProduct",
  34. "/store/store/storeProductCategory", "/store/store/storeProductPackage",
  35. "/store/userOnlineState", "/system/approval", "/system/config",
  36. "/system/dict/data", "/system/dict/type"
  37. )
  38. # Scan all controllers with @Profile("admin")
  39. $controllers = Get-ChildItem -Path $saasPath -Recurse -Filter "*Controller.java"
  40. $changedCount = 0
  41. $skippedCount = 0
  42. $errorCount = 0
  43. foreach ($file in $controllers) {
  44. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  45. # Check if this has @Profile("admin")
  46. if ($content -notmatch '@Profile\s*\(\s*"admin"\s*\)') { continue }
  47. # Get the RequestMapping path
  48. $path = ""
  49. if ($content -match '@RequestMapping\s*\(\s*(?:value\s*=\s*)?"/([^"]+)"') {
  50. $path = "/" + $Matches[1]
  51. }
  52. if ($path -eq "") { continue }
  53. # Check if this path conflicts
  54. if ($conflictPaths -contains $path) {
  55. $skippedCount++
  56. continue
  57. }
  58. # Change @Profile("admin") to @Profile({"admin", "company"})
  59. # Need to handle import as well
  60. $newContent = $content
  61. # Replace @Profile("admin") with @Profile({"admin", "company"})
  62. $newContent = $newContent -replace '@Profile\s*\(\s*"admin"\s*\)', '@Profile({"admin", "company"})'
  63. # Add import for org.springframework.context.annotation.Profile if not already present
  64. # Actually, Profile is already imported since @Profile("admin") exists
  65. if ($newContent -ne $content) {
  66. # Write back without BOM
  67. $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  68. [System.IO.File]::WriteAllText($file.FullName, $newContent, $utf8NoBom)
  69. $changedCount++
  70. }
  71. }
  72. Write-Host "Changed: $changedCount controllers"
  73. Write-Host "Skipped (conflicting): $skippedCount controllers"
  74. Write-Host "Errors: $errorCount"
  75. # Verify a few changes
  76. Write-Host "`n=== Verification ==="
  77. $verifyFiles = Get-ChildItem -Path $saasPath -Recurse -Filter "*Controller.java" | Select-Object -First 5
  78. foreach ($file in $verifyFiles) {
  79. $content = Get-Content $file.FullName -Raw -Encoding UTF8
  80. if ($content -match '@Profile\s*\(\s*\{"admin",\s*"company"\}\s*\)') {
  81. Write-Host " OK: $($file.Name) has @Profile({admin, company})"
  82. }
  83. }