test_business_unit_billing_statistics_final.sh
5 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
#!/bin/bash
# 测试事业部开单统计接口(最终版)
BASE_URL="http://localhost:2011"
TOKEN=""
TEST_DATE="${1:-2026-01-20}"
echo "================================================================================"
echo "事业部开单统计接口测试(修复后验证)"
echo "测试日期: $TEST_DATE"
echo "================================================================================"
echo ""
# 获取Token
LOGIN_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/oauth/Login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "account=admin&password=e10adc3949ba59abbe56e057f20f883e")
TOKEN=$(echo $LOGIN_RESPONSE | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('token', ''))" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ 无法获取Token"
exit 1
fi
echo "✓ Token获取成功"
echo ""
# 调用接口
echo "调用接口: POST /api/Extend/LqDailyReport/get-business-unit-billing-statistics"
echo "参数: {\"date\": \"$TEST_DATE\"}"
echo ""
STATISTICS_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/Extend/LqDailyReport/get-business-unit-billing-statistics" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"date\": \"$TEST_DATE\"}")
# 使用Python解析
python3 <<PYTHON_EOF
import json
import sys
try:
data = json.loads('''$STATISTICS_RESPONSE''')
if data.get('code') == 200:
result = data.get('data', [])
print("✅ 接口调用成功")
print(f"事业部数量: {len(result)}")
print()
if not result:
print("⚠️ 该日期没有开单数据")
else:
total_performance = sum(unit.get('totalPerformance', 0) for unit in result)
total_orders = sum(unit.get('totalOrderCount', 0) for unit in result)
print(f"总业绩: {total_performance}")
print(f"总单量: {total_orders}")
print()
# 查找西站店
has_xizhan = False
all_stores = []
xizhan_orders = []
for unit in result:
unit_name = unit.get('businessUnitName', '未知事业部')
orders = unit.get('orders', [])
print(f"【{unit_name}】")
print(f" 业绩: {unit.get('totalPerformance', 0)}")
print(f" 单量: {unit.get('totalOrderCount', 0)}")
if orders:
print(f" 开单列表:")
for order in orders:
store_name = order.get('storeName', '未知门店')
amount = order.get('amount', 0)
teacher = order.get('healthTeacherNames', '无')
if '西站' in store_name:
marker = '⭐ 西站店'
has_xizhan = True
xizhan_orders.append({
'unit': unit_name,
'store': store_name,
'amount': amount,
'teacher': teacher,
'orderId': order.get('orderId', '')
})
else:
marker = ' '
print(f" {marker} {store_name}: {amount}元 (健康师: {teacher})")
all_stores.append(store_name)
else:
print(f" (无开单记录)")
print()
print("=" * 80)
if has_xizhan:
print("✅ 找到西站店的开单数据!")
print()
print("西站店开单详情:")
for order in xizhan_orders:
print(f" - 事业部: {order['unit']}")
print(f" 门店: {order['store']}")
print(f" 金额: {order['amount']}元")
print(f" 健康师: {order['teacher']}")
print(f" 开单ID: {order['orderId']}")
print()
else:
print("⚠️ 未找到西站店的开单数据")
if all_stores:
unique_stores = sorted(set(all_stores))
print(f"该日期共有 {len(unique_stores)} 个不同门店的开单:")
for store in unique_stores:
print(f" - {store}")
else:
print(f"❌ 接口调用失败")
print(f"错误码: {data.get('code')}")
print(f"错误信息: {data.get('msg', '未知错误')}")
except Exception as e:
print(f"❌ 解析响应失败: {e}")
import traceback
traceback.print_exc()
PYTHON_EOF
echo ""
echo "================================================================================"
echo "测试完成"
echo "================================================================================"