# Change @Profile("admin") to @Profile({"admin", "company"}) for non-conflicting web.controller classes
# These controllers do NOT conflict with fs-company's own controllers and are needed by saasadminui

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

# Non-conflicting controllers that saasadminui needs
$nonConflicting = @(
    "system\SysUserController.java",
    "system\SysRoleController.java",
    "system\SysDeptController.java",
    "system\SysNoticeController.java",
    "system\SysPostController.java",
    "system\SysKeywordController.java",
    "system\SysProfileController.java",
    "system\SysUserSetController.java",
    "system\SysMenuController.java",
    "system\AdminMenuController.java",
    "monitor\ServerController.java",
    "monitor\CacheController.java",
    "monitor\SysUserOnlineController.java",
    "system\SysIndexController.java",
    "tool\SwaggerController.java",
    "tool\TestController.java"
)

$totalFixed = 0

foreach ($file in $nonConflicting) {
    $fullPath = Join-Path $baseDir $file
    if (-not (Test-Path $fullPath)) {
        Write-Host "SKIP: $fullPath not found"
        continue
    }
    
    $content = [System.IO.File]::ReadAllText($fullPath)
    if ($content -match '@Profile\("admin"\)') {
        $newContent = $content -replace '@Profile\("admin"\)', '@Profile({"admin", "company"})'
        $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
        [System.IO.File]::WriteAllText($fullPath, $newContent, $utf8NoBom)
        $totalFixed++
        Write-Host "FIXED: $file"
    } else {
        Write-Host "SKIP (no @Profile admin): $file"
    }
}

# Also fix the api/controller/StatisticManageController - it was excluded by excludeFilters
# but now we excluded the whole api.controller package. Let's check if it's needed.
$apiController = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs\api\controller\StatisticManageController.java"
if (Test-Path $apiController) {
    $content = [System.IO.File]::ReadAllText($apiController)
    if ($content -match '@Profile\("admin"\)') {
        Write-Host "SKIP: StatisticManageController is excluded by package-level excludeFilters, cannot be enabled via @Profile"
    }
}

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