#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
读取并显示三位一体对比表的统计信息
"""

import pandas as pd
from collections import Counter

def main():
    # 读取Excel文件
    df = pd.read_excel("许可事项三位一体对比表_v2.xlsx")
    
    print("="*80)
    print("许可事项三位一体对比表 - 统计信息")
    print("="*80)
    
    print(f"\n总事项数量: {len(df)}")
    
    # 统计各列的勾选情况
    print(f"\n客户提供的事项: {(df['客户提供'] == '✓').sum()}")
    print(f"已接收的事项: {(df['已接收'] == '✓').sum()}")
    print(f"已入库的事项: {(df['已入库'] == '✓').sum()}")
    
    # 统计状态分布
    print("\n状态分布:")
    status_counts = df['状态说明'].value_counts()
    for status, count in status_counts.items():
        print(f"  {status}: {count}")
    
    # 显示需要关注的事项
    print("\n" + "="*80)
    print("需要关注的事项")
    print("="*80)
    
    # 待入库的事项
    to_import = df[df['状态说明'] == '待入库']
    if len(to_import) > 0:
        print(f"\n【待入库】({len(to_import)} 项):")
        for idx, row in to_import.head(15).iterrows():
            print(f"  - {row['事项名称']}")
        if len(to_import) > 15:
            print(f"  ... 还有 {len(to_import) - 15} 项")
    
    # 缺少文件和数据的事项
    missing_all = df[df['状态说明'] == '缺少文件和数据']
    if len(missing_all) > 0:
        print(f"\n【缺少文件和数据】({len(missing_all)} 项):")
        for idx, row in missing_all.head(15).iterrows():
            print(f"  - {row['事项名称']}")
        if len(missing_all) > 15:
            print(f"  ... 还有 {len(missing_all) - 15} 项")
    
    # 缺少源文件的事项
    missing_source = df[df['状态说明'] == '缺少源文件']
    if len(missing_source) > 0:
        print(f"\n【缺少源文件】({len(missing_source)} 项):")
        for idx, row in missing_source.head(15).iterrows():
            print(f"  - {row['事项名称']}")
        if len(missing_source) > 15:
            print(f"  ... 还有 {len(missing_source) - 15} 项")
    
    # 完整的事项
    complete = df[df['状态说明'] == '完整（三方都有）']
    print(f"\n【完整（三方都有）】({len(complete)} 项)")
    
    print("\n" + "="*80)
    print("对比表已保存到: 许可事项三位一体对比表_v2.xlsx")
    print("="*80)

if __name__ == "__main__":
    main()
