#!/usr/bin/env python3
import pandas as pd
from datetime import datetime

# 读取招聘跟进表
file_path = '/Volumes/home/Hermes/呆/All Client List/招聘跟進表2026.xlsx'
xls = pd.ExcelFile(file_path)
print(f"所有Sheet: {xls.sheet_names}")
print("\n")

all_pending = []

for sheet in xls.sheet_names:
    df = pd.read_excel(xls, sheet_name=sheet)
    print(f"Sheet: {sheet}, 形状: {df.shape}")
    if df.empty:
        continue
    
    # 找姓名列
    name_col = None
    for col in df.columns:
        if '姓名' in str(col):
            name_col = col
            break
    
    # 找状态列/应聘阶段
    stage_col = None
    for col in df.columns:
        if '階段' in str(col) or '阶段' in str(col) or '狀態' in str(col) or '状态' in str(col):
            stage_col = col
            break
    
    if stage_col is None:
        # 所有都算待跟进？
        print(f"  未找到阶段列，当前sheet有 {len(df)} 条记录")
        if name_col is not None:
            for idx, row in df.iterrows():
                if pd.notna(row[name_col]):
                    all_pending.append(row[name_col])
        continue
    
    # 筛选待跟进/未成交/未入职
    for idx, row in df.iterrows():
        stage = str(row[stage_col]).lower()
        if pd.isna(row[stage_col]):
            continue
        # 如果包含待、跟进、面试、未、入职前，就算待跟进
        if '待' in stage or '跟进' in stage or '面试' in stage or '未' in stage or '接觸' in stage or '接触' in stage:
            if name_col is not None and pd.notna(row[name_col]):
                all_pending.append(row[name_col])

print(f"\n===== 總共待跟進候選人: {len(all_pending)} =====")
print("\n名单:")
for name in all_pending:
    print(f"- {name}")

# 保存
with open('/Volumes/home/Hermes/呆/All Client List/待跟進招聘候選人.txt', 'w', encoding='utf-8') as f:
    f.write('\n'.join(all_pending))
print(f"\n已保存名单到: /Volumes/home/Hermes/呆/All Client List/待跟進招聘候選人.txt")
