import paramiko
import os

host = '8.140.221.49'
username = 'root'
private_key_path = r'C:\Users\FZX\.ssh\FzxBdsh-ECS.pem'

print('='*80)
print('全面对比分析：阿里云 vs 本地开发环境')
print('='*80)

# 1. 检查本地前端文件
print('\n【本地开发环境】')
print('-'*60)

local_html = r'd:\FzxBDSH\infrastructure\nginx\html\user'
print(f'\n1. 前端文件目录: {local_html}')
if os.path.exists(local_html):
    local_files = os.listdir(local_html)
    print(f'   文件数量: {len(local_files)}')
    print(f'   文件列表: {", ".join(local_files[:10])}...')
else:
    print('   ❌ 目录不存在')

# 检查本地配置文件
local_config = os.path.join(local_html, 'assets', 'config', 'environments', 'app_config.aliyun-dev.json')
print(f'\n2. 阿里云配置文件: {local_config}')
if os.path.exists(local_config):
    with open(local_config, 'r', encoding='utf-8') as f:
        print(f.read())
else:
    print('   ❌ 配置文件不存在')

# 检查本地index.html
local_index = os.path.join(local_html, 'index.html')
print(f'\n3. index.html内容:')
if os.path.exists(local_index):
    with open(local_index, 'r', encoding='utf-8') as f:
        content = f.read()
        print(content[:1000])
else:
    print('   ❌ 文件不存在')

# 2. 检查阿里云环境
print('\n\n【阿里云开发环境】')
print('-'*60)

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
    ssh.connect(host, username=username, key_filename=private_key_path, timeout=30)
    print('✅ 连接成功')
    
    # 检查前端文件
    print('\n1. 前端文件目录')
    cmd = 'ls -la /opt/Fzxpodman/infrastructure/nginx/html/user/'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    print(stdout.read().decode())
    
    # 检查配置文件
    print('\n2. 阿里云配置文件')
    cmd = 'cat /opt/Fzxpodman/infrastructure/nginx/html/user/assets/config/environments/app_config.aliyun-dev.json'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    result = stdout.read().decode()
    if result:
        print(result)
    else:
        print('❌ 配置文件不存在')
    
    # 检查index.html
    print('\n3. index.html内容')
    cmd = 'cat /opt/Fzxpodman/infrastructure/nginx/html/user/index.html'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    result = stdout.read().decode()[:1000]
    print(result)
    
    # 检查Nginx配置
    print('\n4. Nginx配置')
    cmd = 'cat /opt/Fzxpodman/nginx/conf/default.conf'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    print(stdout.read().decode())
    
    # 测试前端页面内容
    print('\n5. 前端页面内容')
    cmd = 'curl -s http://8.140.221.49/user/ | head -30'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    print(stdout.read().decode())
    
    # 测试API
    print('\n6. API测试')
    cmd = 'curl -s http://8.140.221.49/api/user/health'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    print(stdout.read().decode())
    
    # 检查容器状态
    print('\n7. 容器状态')
    cmd = 'podman ps --format "table {{.Names}}\t{{.Status}}"'
    stdin, stdout, stderr = ssh.exec_command(cmd)
    print(stdout.read().decode())
    
finally:
    ssh.close()

print('\n' + '='*80)
print('对比分析完成！')
print('='*80)
