check_erp_push_v2.py 2.98 KB
# -*- coding: utf-8 -*-
import pyodbc

# 先尝试列出可用的驱动
print("可用的ODBC驱动:")
for d in pyodbc.drivers():
    print(f"  {d}")

# 尝试连接
conn_str = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.168.1.91,1433;DATABASE=wms4_global;UID=sa;PWD=HHrobot123.'

try:
    conn = pyodbc.connect(conn_str)
    print("\n连接成功!")
    
    cursor = conn.cursor()
    
    # 查询入库单问题单据
    print("\n" + "=" * 80)
    print("一、入库单(receipt_header)分析")
    print("=" * 80)
    
    print("\n【1. 入库单类型分布】")
    cursor.execute("""
        SELECT ISNULL(type, 'NULL') as type, COUNT(*) as cnt
        FROM receipt_header
        GROUP BY type
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  {row[0]}: {row[1]}条")
    
    print("\n【2. 入库单头状态分布】")
    cursor.execute("""
        SELECT ISNULL(first_status, 'NULL') as first_status, COUNT(*) as cnt
        FROM receipt_header
        GROUP BY first_status
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  头状态{row[0]}: {row[1]}条")
    
    print("\n【3. 入库单尾状态分布】")
    cursor.execute("""
        SELECT ISNULL(last_status, 'NULL') as last_status, COUNT(*) as cnt
        FROM receipt_header
        GROUP BY last_status
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  尾状态{row[0]}: {row[1]}条")
    
    print("\n【4. 入库单组盘状态分布】")
    cursor.execute("""
        SELECT ISNULL(rch.status, 'NULL') as container_status, COUNT(*) as cnt
        FROM receipt_header rh
        LEFT JOIN receipt_container_header rch ON rh.id = rch.receipt_id
        GROUP BY rch.status
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  组盘状态{row[0]}: {row[1]}条")
    
    print("\n" + "=" * 80)
    print("二、出库单(shipment_header)分析")
    print("=" * 80)
    
    print("\n【1. 出库单类型分布】")
    cursor.execute("""
        SELECT ISNULL(type, 'NULL') as type, COUNT(*) as cnt
        FROM shipment_header
        GROUP BY type
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  {row[0]}: {row[1]}条")
    
    print("\n【2. 出库单头状态分布】")
    cursor.execute("""
        SELECT ISNULL(first_status, 'NULL') as first_status, COUNT(*) as cnt
        FROM shipment_header
        GROUP BY first_status
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  头状态{row[0]}: {row[1]}条")
    
    print("\n【3. 出库单尾状态分布】")
    cursor.execute("""
        SELECT ISNULL(last_status, 'NULL') as last_status, COUNT(*) as cnt
        FROM shipment_header
        GROUP BY last_status
        ORDER BY cnt DESC
    """)
    for row in cursor.fetchall():
        print(f"  尾状态{row[0]}: {row[1]}条")
    
    conn.close()
    
except Exception as e:
    print(f"\n连接失败: {e}")