# Fix @Profile annotations for packages that are excluded by excludeFilters in FsCompanyApplication
# These controllers should NOT have @Profile({"admin","company"}) because they conflict with
# controllers in fs-company's own source code.
# Change them back to @Profile("admin") so they only load in fs-admin context.

$baseDir = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"

# Packages that are excluded by excludeFilters and have conflicting controllers
$conflictPackages = @(
    "admin\controller",
    "web\controller",
    "api\controller",
    "crm\controller",
    "qw\controller",
    "live\controller",
    "course\controller",
    "user\controller",
    "fastGpt",
    "fastgptApi",
    "company\controller"
)

$totalFixed = 0

foreach ($pkg in $conflictPackages) {
    $pkgDir = Join-Path $baseDir $pkg
    if (-not (Test-Path $pkgDir)) {
        Write-Host "SKIP: $pkgDir not found"
        continue
    }
    
    $files = Get-ChildItem -Path $pkgDir -Filter "*.java" -Recurse
    foreach ($file in $files) {
        $content = [System.IO.File]::ReadAllText($file.FullName)
        if ($content -match '@Profile\(\{"admin",\s*"company"\}\)') {
            $newContent = $content -replace '@Profile\(\{"admin",\s*"company"\}\)', '@Profile("admin")'
            $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
            [System.IO.File]::WriteAllText($file.FullName, $newContent, $utf8NoBom)
            $totalFixed++
            Write-Host "FIXED: $($file.FullName)"
        }
    }
}

Write-Host "`nTotal files fixed: $totalFixed"
