test_store_dashboard_statistics.sh
5.29 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
#!/bin/bash
# 测试门店驾驶舱统计数据接口
echo "=== 测试门店驾驶舱统计数据接口 ==="
echo ""
# 1. 获取token
echo "=== 1. 获取Token ==="
TOKEN_RESPONSE=$(curl -s -X POST "http://localhost:2011/api/oauth/Login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "account=admin&password=e10adc3949ba59abbe56e057f20f883e")
TOKEN=$(echo "$TOKEN_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['data']['token'])" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ Token获取失败"
echo "$TOKEN_RESPONSE"
exit 1
fi
echo "✅ Token获取成功"
echo ""
# 2. 测试接口
echo "=== 2. 测试接口 - 门店驾驶舱统计数据 ==="
echo ""
# 测试参数
STORE_ID="1649328471923847169"
STATISTICS_MONTH="202601"
echo "请求参数:"
echo " - storeId: $STORE_ID"
echo " - statisticsMonth: $STATISTICS_MONTH"
echo ""
RESPONSE=$(curl -s -X POST "http://localhost:2011/api/Extend/LqStoreDashboard/GetStatistics" \
-H "Authorization: $TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"storeId\": \"$STORE_ID\",
\"statisticsMonth\": \"$STATISTICS_MONTH\"
}")
echo "$RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
code = data.get('code')
msg = data.get('msg')
result = data.get('data', {})
print('=' * 80)
print('门店驾驶舱统计数据 - 接口测试结果')
print('=' * 80)
print(f'HTTP状态码: {code}')
print(f'消息: {msg}')
print('')
if code == 200:
print('✅ 接口测试成功!')
print('')
print('=' * 80)
print('返回数据:')
print('=' * 80)
print('【核心指标】')
print(f' 开单业绩: ¥{result.get(\"BillingPerformance\", 0):,.2f}')
print(f' 消耗业绩: ¥{result.get(\"ConsumePerformance\", 0):,.2f}')
print(f' 完成率: {result.get(\"CompletionRate\", 0):.2f}%')
print(f' 净业绩: ¥{result.get(\"NetPerformance\", 0):,.2f}')
print('')
print('【业绩概览数据】')
print(f' 开单次数: {result.get(\"BillingCount\", 0):,}')
print(f' 消耗次数: {result.get(\"ConsumeCount\", 0):,}')
print(f' 退卡次数: {result.get(\"RefundCount\", 0):,}')
print(f' 平均开单金额: ¥{result.get(\"AvgBillingAmount\", 0):,.2f}')
print(f' 平均消耗金额: ¥{result.get(\"AvgConsumeAmount\", 0):,.2f}')
print(f' 剩余权益: ¥{result.get(\"RemainingRightsAmount\", 0):,.2f}')
print(f' 目标业绩: ¥{result.get(\"TargetPerformance\", 0):,.2f}')
print(f' 退卡金额: ¥{result.get(\"RefundAmount\", 0):,.2f}')
print('')
# 验证数据完整性
print('=' * 80)
print('数据完整性检查:')
print('-' * 80)
required_fields = [
'BillingPerformance', 'ConsumePerformance', 'CompletionRate', 'NetPerformance',
'BillingCount', 'ConsumeCount', 'RefundCount',
'AvgBillingAmount', 'AvgConsumeAmount',
'RemainingRightsAmount', 'TargetPerformance', 'RefundAmount'
]
all_ok = True
for field in required_fields:
if field in result:
value = result[field]
if isinstance(value, (int, float)):
print(f'✅ {field}: {value} (类型正确)')
else:
print(f'❌ {field}: {value} (类型错误,应为数字)')
all_ok = False
else:
print(f'❌ {field}: 缺失')
all_ok = False
if all_ok:
print('')
print('✅ 所有字段都存在且类型正确!')
# 验证数据逻辑
print('')
print('=' * 80)
print('数据逻辑验证:')
print('-' * 80)
billing = result.get('BillingPerformance', 0)
consume = result.get('ConsumePerformance', 0)
completion = result.get('CompletionRate', 0)
net = result.get('NetPerformance', 0)
# 验证完成率是否合理(0-200%之间)
if 0 <= completion <= 200:
print(f'✅ 完成率在合理范围内: {completion:.2f}%')
else:
print(f'⚠️ 完成率超出合理范围: {completion:.2f}%')
# 验证净业绩计算(开单业绩应该大于等于净业绩)
if billing >= net:
print(f'✅ 净业绩计算正确: 开单业绩({billing:,.2f}) >= 净业绩({net:,.2f})')
else:
print(f'❌ 净业绩计算异常: 开单业绩({billing:,.2f}) < 净业绩({net:,.2f})')
# 验证数据是否非负
if billing >= 0 and consume >= 0 and completion >= 0 and net >= 0:
print('✅ 所有数据均为非负数')
else:
print('⚠️ 存在负数数据')
else:
print(f'❌ 接口返回错误: {msg}')
print('完整响应:')
print(json.dumps(data, indent=2, ensure_ascii=False))
except json.JSONDecodeError as e:
print('❌ JSON解析失败')
print('响应内容:')
print(sys.stdin.read())
except Exception as e:
print(f'❌ 处理失败: {e}')
import traceback
traceback.print_exc()
"
echo ""
echo "=== 测试完成 ==="