# 找出不同包名的冲突
$saasRoot = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
$companyRoot = "d:\ylrz\ylrz_saas_his_scrm\fs-company\src\main\java\com\fs"

$excludedPatterns = @(
    "com\.fs\.framework\.web\.service\.UserDetailsServiceImpl",
    "com\.fs\.api\.controller\..*",
    "com\.fs\.web\.controller\..*",
    "com\.fs\.his\.controller\.FsFollowController",
    "com\.fs\.his\.controller\.FsFollowReportController",
    "com\.fs\.his\.controller\.FsUserOnlineStateController",
    "com\.fs\.his\.controller\.FsMaterialGroupController",
    "com\.fs\.his\.controller\.FsMaterialController",
    "com\.fs\.his\.controller\.FsUserOperationLogController",
    "com\.fs\.his\.controller\.FsDoctorController",
    "com\.fs\.his\.controller\.FsStoreOrderBillLogController",
    "com\.fs\.admin\.controller\..*",
    "com\.fs\.admin\.helper\..*",
    "com\.fs\.company\.controller\.chat\..*",
    "com\.fs\.chat\.controller\.FastGptRoleController",
    "com\.fs\.crm\.controller\..*",
    "com\.fs\.course\.controller\..*",
    "com\.fs\.qw\.controller\..*",
    "com\.fs\.live\.controller\..*",
    "com\.fs\.newAdv\.controller\..*",
    "com\.fs\.company\.controller\.hisStore\..*",
    "com\.fs\.user\.controller\..*",
    "com\.fs\.proxy\.controller\..*",
    "com\.fs\.fastGpt\.[^.]+",
    "com\.fs\.fastgptApi\.[^.]+",
    "com\.fs\.company\.controller\.transfer\..*",
    "com\.fs\.task\.[^.]+",
    "com\.fs\.ad\.controller\..*",
    "com\.fs\.third\.controller\..*",
    "com\.fs\.quartz\.saas\.QuartzSaaSConfig"
)

$companyMaps = @{}
Get-ChildItem $companyRoot -Recurse -Filter "*Controller.java" | ForEach-Object {
    $content = Get-Content $_.FullName -Raw
    if ($content -match '@RequestMapping\("([^"]+)"\)') {
        $path = $Matches[1]
        $className = $_.BaseName
        $content -match '(?s)^package\s+([^;]+)' | Out-Null; $pkg = $Matches[1]
        $fqn = "$pkg.$className"
        $companyMaps[$path] = $fqn
    }
}

$crossPackageConflicts = @()
Get-ChildItem $saasRoot -Recurse -Filter "*Controller.java" | ForEach-Object {
    $content = Get-Content $_.FullName -Raw
    if ($content -match '@Profile\("admin"\)') { return }
    if ($content -match '@RequestMapping\("([^"]+)"\)') {
        $path = $Matches[1]
        $className = $_.BaseName
        $content -match '(?s)^package\s+([^;]+)' | Out-Null; $pkg = $Matches[1]
        $fqn = "$pkg.$className"
        
        $excluded = $false
        foreach ($pattern in $excludedPatterns) {
            if ($fqn -match $pattern) { $excluded = $true; break }
        }
        
        if (-not $excluded -and $companyMaps.ContainsKey($path)) {
            $otherFqn = $companyMaps[$path]
            # 检查是否不同包
            if ($fqn -ne $otherFqn) {
                $crossPackageConflicts += "DIFF_PKG: $fqn vs $otherFqn = $path"
            }
        }
    }
}

"Found $($crossPackageConflicts.Count) cross-package conflicts:"
$crossPackageConflicts | ForEach-Object { $_ }
