check_erp_push.py 3.22 KB
# -*- coding: utf-8 -*-
import pymssql

# 数据库连接
conn = pymssql.connect(
    server='192.168.1.91,1433',
    database='wms4_global',
    user='sa',
    password='HHrobot123.'
)

cursor = conn.cursor()

print("=" * 80)
print("一、查询入库单(receipt_header)问题单据")
print("=" * 80)

# 入库单问题单据:头尾状态不是"回传",且已完成出入库但未推送ERP
# 需要排除:调拨入库(type='transfer')、倒扣料入库(type='deduction')
# 状态值需要确认:先看数据字典

print("\n【1. 查看入库单类型分布】")
cursor.execute("""
    SELECT 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 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 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 TABLE_NAME
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME LIKE '%group%' OR TABLE_NAME LIKE '%container%'
""")
for row in cursor.fetchall():
    print(f"  {row[0]}")

print("\n【5. 查看入库单关联组盘情况】")
cursor.execute("""
    SELECT COUNT(*)
    FROM receipt_header rh
    INNER JOIN receipt_container_header rch ON rh.id = rch.receipt_id
""")
print(f"  入库单关联组盘数量: {cursor.fetchone()[0]}")

print("\n" + "=" * 80)
print("二、查询出库单(shipment_header)问题单据")
print("=" * 80)

print("\n【1. 查看出库单类型分布】")
cursor.execute("""
    SELECT 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 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 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]}条")

# 重点:查询组盘头表
print("\n【6. 查看组盘头表结构】")
cursor.execute("""
    SELECT COLUMN_NAME, DATA_TYPE
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'receipt_container_header'
""")
print("  receipt_container_header 表字段:")
for row in cursor.fetchall():
    print(f"    {row[0]} ({row[1]})")

print("\n【7. 查看组盘头表状态分布】")
cursor.execute("""
    SELECT status, COUNT(*) as cnt
    FROM receipt_container_header
    GROUP BY status
    ORDER BY cnt DESC
""")
for row in cursor.fetchall():
    print(f"  {row[0]}: {row[1]}条")

conn.close()
print("\n查询完成!")