test_payment_reminder.sh
5.1 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
#!/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 POST "http://localhost:2011/api/Extend/LqContract/GetPaymentReminderList" \
-H "Authorization: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"onlyOverdue": false}')
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 and items:
print('✅ 接口测试成功!')
print('')
print('=' * 100)
print('前3条记录详情:')
print('=' * 100)
for idx, item in enumerate(items[:3], 1):
print(f'\n【记录 {idx}】')
print(f' 合同ID: {item.get(\"ContractId\", \"缺失\")}')
print(f' 明细ID: {item.get(\"DetailId\", \"缺失\")}')
print(f' 店名: {item.get(\"StoreName\", \"缺失\")}')
print(f' 合同标题: {item.get(\"Title\", \"缺失\")}')
print(f' 收款方: {item.get(\"TenantName\", \"无\")}')
# 付款时间
if 'PaymentDate' in item and item['PaymentDate']:
payment_date = datetime.fromtimestamp(item['PaymentDate'] / 1000).strftime('%Y-%m-%d')
print(f' ✅ 付款时间: {payment_date}')
else:
print(f' ❌ 付款时间: 缺失')
# 付款金额
if 'PaymentAmount' in item:
print(f' ✅ 付款金额: {item[\"PaymentAmount\"]:,.2f} 元')
else:
print(f' ❌ 付款金额: 缺失')
# 应缴月份
if 'PaymentMonth' in item:
print(f' ✅ 应缴月份: {item[\"PaymentMonth\"]}')
else:
print(f' ❌ 应缴月份: 缺失')
# 提醒时间
if 'ReminderDate' in item and item['ReminderDate']:
reminder_date = datetime.fromtimestamp(item['ReminderDate'] / 1000).strftime('%Y-%m-%d')
print(f' ✅ 提醒时间: {reminder_date}')
else:
print(f' ⚠️ 提醒时间: 无')
# 状态
days = item.get('DaysUntilPayment', 0)
is_overdue = item.get('IsOverdue', False)
status = '已过期' if is_overdue else f'{days}天后'
print(f' ✅ 状态: {status} (距离付款 {days} 天)')
print('')
print('=' * 100)
print('字段完整性检查:')
print('-' * 100)
required_fields = ['ContractId', 'DetailId', 'StoreName', 'Title', 'TenantName', 'PaymentDate', 'PaymentAmount', 'PaymentMonth', 'ReminderDate', 'DaysUntilPayment', 'IsOverdue']
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 ['ReminderDate', 'TenantName', 'Remarks']))
if missing_count > 0:
print(f'❌ {field}: {missing_count}条记录缺失')
all_ok = False
else:
print(f'✅ {field}: 所有记录都有此字段')
if all_ok:
print('')
print('✅ 所有必需字段都存在!')
# 统计信息
total_amount = sum(item.get('PaymentAmount', 0) for item in items)
overdue_count = sum(1 for item in items if item.get('IsOverdue', False))
print('')
print('=' * 100)
print('统计信息:')
print('-' * 100)
print(f'总记录数: {len(items)}')
print(f'总付款金额: {total_amount:,.2f} 元')
print(f'已过期: {overdue_count} 条')
print(f'未过期: {len(items) - overdue_count} 条')
elif code == 200 and not items:
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}')
print('响应内容:')
print(sys.stdin.read())
"
echo ""
echo "=== 测试完成 ==="