check_erp_push_v2.py
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- 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}")