prod_final_analysis.py
5.38 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import pyodbc
conn = pyodbc.connect(
'DRIVER={ODBC Driver 17 for SQL Server};'
'SERVER=192.168.1.168,1433;'
'DATABASE=wms4_global;'
'UID=sa;PWD=HHrobot123.'
)
cursor = conn.cursor()
print("=" * 90)
print("【生产环境】ERP推送问题单据完整分析")
print("=" * 90)
# ========== 一、入库单分析 ==========
print("\n\n【一、入库单问题分析】")
print("-" * 70)
# 状态300的入库单
cursor.execute("""
SELECT COUNT(*) FROM receipt_header
WHERE first_status = 300
AND type NOT IN ('DBR', 'dbr')
""")
receipt_300 = cursor.fetchone()[0]
print(f"入库单状态300的数量: {receipt_300}")
print("\n入库单状态300详情:")
print(f"{'入库单号':<35} {'类型':<12} {'头状态':<8} {'尾状态':<8} {'组盘码':<25}")
print("-" * 88)
cursor.execute("""
SELECT
rh.code,
rh.type,
rh.first_status,
rh.last_status,
rch.container_code,
rch.status as container_status,
th.status as task_status
FROM receipt_header rh
LEFT JOIN receipt_container_header rch ON rh.id = rch.id
LEFT JOIN task_header th ON rch.id = th.receipt_container_header_id
WHERE rh.first_status = 300
AND rh.type NOT IN ('DBR', 'dbr')
ORDER BY rh.create_time DESC
""")
receipt_problems = cursor.fetchall()
for row in receipt_problems:
code = row[0] or ''
bill_type = row[1] or ''
first = row[2] if row[2] is not None else '-'
last = row[3] if row[3] is not None else '-'
container = row[4] or '无组盘'
print(f"{code:<35} {bill_type:<12} {str(first):<8} {str(last):<8} {str(container):<25}")
# ========== 二、出库单分析 ==========
print("\n\n【二、出库单问题分析】")
print("-" * 70)
cursor.execute("""
SELECT COUNT(*) FROM shipment_header
WHERE first_status = 300
AND type NOT IN ('DBR', 'dbr')
""")
shipment_300 = cursor.fetchone()[0]
print(f"出库单状态300的数量: {shipment_300}")
# 按类型统计
print("\n按类型统计:")
cursor.execute("""
SELECT
type,
COUNT(*) as cnt
FROM shipment_header
WHERE first_status = 300
AND type NOT IN ('DBR', 'dbr')
GROUP BY type
ORDER BY cnt DESC
""")
for row in cursor.fetchall():
print(f" {row[0]}: {row[1]} 条")
print("\n出库单状态300详情(通过container_code关联):")
print(f"{'出库单号':<35} {'类型':<12} {'组盘码':<25} {'组盘状态':<10} {'任务状态':<10}")
print("-" * 92)
cursor.execute("""
SELECT
sh.code,
sh.type,
sch.container_code,
sch.status as container_status,
th.status as task_status
FROM shipment_header sh
LEFT JOIN shipment_container_header sch ON sh.id = sch.id
LEFT JOIN task_header th ON sch.id = th.shipment_container_header_id
WHERE sh.first_status = 300
AND sh.type NOT IN ('DBR', 'dbr')
ORDER BY sh.create_time DESC
""")
shipment_problems = cursor.fetchall()
for row in shipment_problems:
code = row[0] or ''
bill_type = row[1] or ''
container = row[2] or '无组盘'
container_status = row[3] if row[3] is not None else '-'
task_status = row[4] if row[4] is not None else '-'
print(f"{code:<35} {bill_type:<12} {str(container):<25} {str(container_status):<10} {str(task_status):<10}")
# ========== 三、任务状态分析 ==========
print("\n\n【三、任务状态分析(重点关注状态不是50的)】")
print("-" * 70)
# 统计任务状态分布
print("任务状态分布:")
cursor.execute("""
SELECT
status,
COUNT(*) as cnt
FROM task_header
GROUP BY status
ORDER BY status
""")
for row in cursor.fetchall():
print(f" 任务状态 {row[0]}: {row[1]} 条")
# ========== 四、组盘头表状态分析 ==========
print("\n\n【四、组盘头表状态分析】")
print("-" * 70)
print("receipt_container_header.status 分布:")
cursor.execute("""
SELECT
status,
COUNT(*) as cnt
FROM receipt_container_header
GROUP BY status
ORDER BY status
""")
for row in cursor.fetchall():
print(f" 状态 {row[0]}: {row[1]} 条")
print("\nshipment_container_header.status 分布:")
cursor.execute("""
SELECT
status,
COUNT(*) as cnt
FROM shipment_container_header
GROUP BY status
ORDER BY status
""")
for row in cursor.fetchall():
print(f" 状态 {row[0]}: {row[1]} 条")
# ========== 五、问题总结 ==========
print("\n\n【五、问题总结】")
print("=" * 70)
# 入库单
cursor.execute("""
SELECT COUNT(*) FROM receipt_header
WHERE first_status = 300
AND type NOT IN ('DBR', 'dbr')
""")
total_receipt = cursor.fetchone()[0]
# 出库单
cursor.execute("""
SELECT COUNT(*) FROM shipment_header
WHERE first_status = 300
AND type NOT IN ('DBR', 'dbr')
""")
total_shipment = cursor.fetchone()[0]
print(f"需要处理的入库单(状态300,排除调拨入库): {total_receipt} 条")
print(f"需要处理的出库单(状态300,排除调拨出库): {total_shipment} 条")
print(f"总计: {total_receipt + total_shipment} 条")
print("\n状态含义说明:")
print(" 入库单 first_status:")
print(" 0 = 新建")
print(" 100 = 已提交")
print(" 200 = 已确认")
print(" 300 = 组盘中/拣货中")
print(" 800 = 已回传ERP")
print(" 900 = 已完成")
print()
print(" 任务 status:")
print(" 1 = 未开始")
print(" 50 = 进行中")
print(" 100 = 已完成")
conn.close()
print("\n\n分析完成!")