test_my_today_appointments.sh
5.44 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
#!/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. 测试接口 - 我的今日预约 ==="
RESPONSE=$(curl -s -X GET "http://localhost:2011/api/Extend/LqYyjl/GetMyTodayAppointments" \
-H "Authorization: $TOKEN")
echo "$RESPONSE" | python3 -c "
import sys, json
from datetime import datetime
try:
data = json.load(sys.stdin)
code = data.get('code')
msg = data.get('msg')
items = data.get('data', [])
print(f'HTTP状态码: {code}')
print(f'消息: {msg}')
print(f'预约记录数: {len(items)}')
print('')
if code == 200:
if items:
print('✅ 接口测试成功!')
print('')
print('=' * 100)
print('今日预约客户列表:')
print('=' * 100)
print(f'{'序号':<5} {'顾客姓名':<12} {'预约时间':<15} {'体验项目':<20} {'健康师':<12} {'门店':<15} {'状态':<10}')
print('-' * 100)
for idx, item in enumerate(items, 1):
customer_name = item.get('CustomerName', '未知')
time_display = item.get('AppointmentTimeDisplay', '')
project = item.get('ProjectName', '')
health_coach = item.get('HealthCoachName', '无')
store = item.get('StoreName', '无')
status = item.get('Status', '')
print(f'{idx:<5} {customer_name:<12} {time_display:<15} {project:<20} {health_coach:<12} {store:<15} {status:<10}')
print('')
print('=' * 100)
print('字段完整性检查:')
print('-' * 100)
required_fields = ['AppointmentId', 'CustomerId', 'CustomerName', 'ProjectName', 'AppointmentStartTime', 'AppointmentTimeDisplay', 'HealthCoachName', 'Status', 'StoreName']
all_ok = True
for field in required_fields:
missing_count = sum(1 for item in items if field not in item or (item[field] is None and field not in ['HealthCoachName', 'StoreName']))
if missing_count > 0:
print(f'❌ {field}: {missing_count}条记录缺失')
all_ok = False
else:
print(f'✅ {field}: 所有记录都有此字段')
if all_ok:
print('')
print('✅ 所有必需字段都存在!')
# 显示详细信息
print('')
print('=' * 100)
print('前3条记录详细信息:')
print('=' * 100)
for idx, item in enumerate(items[:3], 1):
print(f'\n【预约 {idx}】')
print(f' 预约编号: {item.get(\"AppointmentId\", \"缺失\")}')
print(f' 顾客ID: {item.get(\"CustomerId\", \"缺失\")}')
print(f' 顾客姓名: {item.get(\"CustomerName\", \"缺失\")}')
print(f' 顾客类型: {item.get(\"CustomerType\", \"无\")}')
print(f' 体验项目: {item.get(\"ProjectName\", \"缺失\")}')
if 'AppointmentStartTime' in item and item['AppointmentStartTime']:
start_time = datetime.fromtimestamp(item['AppointmentStartTime'] / 1000).strftime('%Y-%m-%d %H:%M')
print(f' ✅ 预约开始时间: {start_time}')
else:
print(f' ❌ 预约开始时间: 缺失')
if 'AppointmentEndTime' in item and item['AppointmentEndTime']:
end_time = datetime.fromtimestamp(item['AppointmentEndTime'] / 1000).strftime('%Y-%m-%d %H:%M')
print(f' ✅ 预约结束时间: {end_time}')
else:
print(f' ⚠️ 预约结束时间: 无')
print(f' 预约时间显示: {item.get(\"AppointmentTimeDisplay\", \"缺失\")}')
print(f' 健康师: {item.get(\"HealthCoachName\", \"无\")}')
print(f' 门店: {item.get(\"StoreName\", \"无\")}')
print(f' 状态: {item.get(\"Status\", \"缺失\")}')
else:
print('⚠️ 接口返回成功,但今天没有预约记录')
print('')
print('提示:如果今天确实有预约,请检查:')
print(' 1. 预约记录的 yyr 字段是否匹配当前用户ID')
print(' 2. 预约记录的 yysj 字段是否在今天')
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 "=== 测试完成 ==="