test_tech_dashboard_statistics.sh
6.09 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
#!/bin/bash
# 测试科技部驾驶舱 GetStatistics 接口 - 验证新增字段
# 使用方法: ./scripts/sh/test_tech_dashboard_statistics.sh
BASE_URL="http://localhost:2011"
TOKEN=""
echo "=========================================="
echo "测试科技部驾驶舱 GetStatistics 接口"
echo "验证新增字段:开单、储扣、退款、消耗、手工费"
echo "=========================================="
echo ""
# 1. 登录获取token
echo "1. 登录获取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; print(json.load(sys.stdin)['data']['token'])" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ 登录失败,无法获取token"
exit 1
fi
echo "✅ Token获取成功"
echo ""
# 2. 测试使用科技部ID查询
echo "2. 测试使用科技部ID查询..."
TECH_DEPT_ID="734725579919590661" # 科技一部ID
STATISTICS_MONTH="202601"
RESPONSE=$(curl -s -X POST "${BASE_URL}/api/Extend/LqTechDepartmentDashboard/GetStatistics" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"techDepartmentId\": \"${TECH_DEPT_ID}\",
\"statisticsMonth\": \"${STATISTICS_MONTH}\"
}")
echo "响应状态码: $(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('code', 'N/A'))" 2>/dev/null)"
echo ""
# 3. 验证新增字段是否存在
echo "3. 验证新增字段是否存在..."
VALIDATION_RESULT=$(echo "$RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
if data.get('code') == 200 and data.get('data'):
result = data['data']
missing_fields = []
required_fields = {
'BillingAmount': '开单金额',
'DeductAmount': '储扣金额',
'RefundAmount': '退款金额',
'ConsumeAmount': '消耗金额',
'HandworkFee': '手工费'
}
for field, name in required_fields.items():
if field not in result:
missing_fields.append(f'{name}({field})')
if missing_fields:
print('❌ 以下字段缺失:')
for field in missing_fields:
print(f' - {field}')
exit(1)
else:
print('✅ 所有新增字段都存在')
print('')
print('字段值:')
for field, name in required_fields.items():
value = result.get(field, 0)
print(f' {name}({field}): {value}')
exit(0)
else:
print('❌ 响应数据格式不正确')
print('响应内容:', json.dumps(data, indent=2, ensure_ascii=False))
exit(1)
except Exception as e:
print(f'❌ 解析响应失败: {e}')
exit(1)
" 2>/dev/null)
if [ $? -ne 0 ]; then
echo "$VALIDATION_RESULT"
echo ""
echo "完整响应:"
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
exit 1
fi
echo "$VALIDATION_RESULT"
echo ""
# 4. 显示完整响应数据
echo "4. 完整响应数据:"
echo "$RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
if data.get('code') == 200 and data.get('data'):
result = data['data']
print('=' * 60)
print('基础指标:')
print(f' 溯源金额: {result.get(\"TraceabilityAmount\", 0)}')
print(f' Cell金额: {result.get(\"CellAmount\", 0)}')
print(f' 科美总收入: {result.get(\"TotalKemeiIncome\", 0)}')
print(f' 管理的门店数: {result.get(\"ManagedStoreCount\", 0)}')
print(f' 活跃门店数: {result.get(\"ActiveStoreCount\", 0)}')
print('')
print('开单/退卡明细:')
print(f' 开单溯源金额: {result.get(\"BillingTraceabilityAmount\", 0)}')
print(f' 退卡溯源金额: {result.get(\"RefundTraceabilityAmount\", 0)}')
print(f' 开单Cell金额: {result.get(\"BillingCellAmount\", 0)}')
print(f' 退卡Cell金额: {result.get(\"RefundCellAmount\", 0)}')
print('')
print('新增字段:')
print(f' 开单金额(BillingAmount): {result.get(\"BillingAmount\", 0)}')
print(f' 储扣金额(DeductAmount): {result.get(\"DeductAmount\", 0)}')
print(f' 退款金额(RefundAmount): {result.get(\"RefundAmount\", 0)}')
print(f' 消耗金额(ConsumeAmount): {result.get(\"ConsumeAmount\", 0)}')
print(f' 手工费(HandworkFee): {result.get(\"HandworkFee\", 0)}')
print('=' * 60)
else:
print('响应数据格式不正确')
print(json.dumps(data, indent=2, ensure_ascii=False))
except Exception as e:
print(f'解析失败: {e}')
" 2>/dev/null
echo ""
# 5. 测试使用门店ID列表查询
echo "5. 测试使用门店ID列表查询..."
STORE_ID="1649328471923847198" # 绿纤川音店
STORE_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/Extend/LqTechDepartmentDashboard/GetStatistics" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"storeIds\": [\"${STORE_ID}\"],
\"statisticsMonth\": \"${STATISTICS_MONTH}\"
}")
echo "响应状态码: $(echo "$STORE_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('code', 'N/A'))" 2>/dev/null)"
echo ""
# 验证门店ID查询的字段
echo "门店ID查询的新增字段值:"
echo "$STORE_RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
if data.get('code') == 200 and data.get('data'):
result = data['data']
print(f' 开单金额: {result.get(\"BillingAmount\", 0)}')
print(f' 储扣金额: {result.get(\"DeductAmount\", 0)}')
print(f' 退款金额: {result.get(\"RefundAmount\", 0)}')
print(f' 消耗金额: {result.get(\"ConsumeAmount\", 0)}')
print(f' 手工费: {result.get(\"HandworkFee\", 0)}')
else:
print('响应数据格式不正确')
except Exception as e:
print(f'解析失败: {e}')
" 2>/dev/null
echo ""
echo "=========================================="
echo "✅ 测试完成"
echo "=========================================="