test_store_dashboard_statistics.sh 5.29 KB
#!/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 "=== 测试完成 ==="