$ErrorActionPreference = "SilentlyContinue"
# Check if his controllers are in nested fs-admin-saas jar inside fs-company.jar
Add-Type -AssemblyName System.IO.Compression.FileSystem

$jarPath = "d:\ylrz\ylrz_saas_his_scrm\fs-company\target\fs-company.jar"
$zip = [System.IO.Compression.ZipFile]::OpenRead($jarPath)

# Find fs-admin-saas jar entry
$saasEntry = $zip.Entries | Where-Object { $_.FullName -match "fs-admin-saas.*\.jar$" }
Write-Output "=== fs-admin-saas JAR in fs-company.jar ==="
foreach ($e in $saasEntry) {
    Write-Output "$($e.FullName) ($($e.Length) bytes)"
}

# Extract fs-admin-saas jar
$tempDir = "$env:TEMP\saas_check"
if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null

foreach ($e in $saasEntry) {
    $destPath = Join-Path $tempDir "fs-admin-saas.jar"
    [System.IO.Compression.ZipFileExtensions]::ExtractToFile($e, $destPath, $true)
    Write-Output "Extracted to $destPath"
    
    # Now check what controllers are inside this nested jar
    $nestedZip = [System.IO.Compression.ZipFile]::OpenRead($destPath)
    
    Write-Output ""
    Write-Output "=== HIS Controller classes in fs-admin-saas.jar ==="
    $hisEntries = $nestedZip.Entries | Where-Object { $_.FullName -match "his/controller/.*Controller\.class" }
    Write-Output "Total: $($hisEntries.Count)"
    foreach ($h in $hisEntries) {
        Write-Output $h.FullName
    }
    
    Write-Output ""
    Write-Output "=== COURSE Controller classes in fs-admin-saas.jar ==="
    $courseEntries = $nestedZip.Entries | Where-Object { $_.FullName -match "course/controller/.*Controller\.class" }
    Write-Output "Total: $($courseEntries.Count)"
    foreach ($h in $courseEntries) {
        Write-Output $h.FullName
    }
    
    Write-Output ""
    Write-Output "=== QW Controller classes in fs-admin-saas.jar ==="
    $qwEntries = $nestedZip.Entries | Where-Object { $_.FullName -match "qw/controller/.*Controller\.class" }
    Write-Output "Total: $($qwEntries.Count)"
    foreach ($h in $qwEntries) {
        Write-Output $h.FullName
    }
    
    Write-Output ""
    Write-Output "=== CRM Controller classes in fs-admin-saas.jar ==="
    $crmEntries = $nestedZip.Entries | Where-Object { $_.FullName -match "crm/controller/.*Controller\.class" }
    Write-Output "Total: $($crmEntries.Count)"
    foreach ($h in $crmEntries) {
        Write-Output $h.FullName
    }
    
    Write-Output ""
    Write-Output "=== LIVE Controller classes in fs-admin-saas.jar ==="
    $liveEntries = $nestedZip.Entries | Where-Object { $_.FullName -match "live/controller/.*Controller\.class" }
    Write-Output "Total: $($liveEntries.Count)"
    foreach ($h in $liveEntries) {
        Write-Output $h.FullName
    }
    
    $nestedZip.Dispose()
}

$zip.Dispose()
Write-Output "Done"
