test_health_coach_salary_calculate.py 3.21 KB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试健康师薪酬计算接口
验证已锁定和已确认的记录不会被覆盖
"""

import requests
import urllib.parse

# API配置
BASE_URL = "http://localhost:2011"
LOGIN_URL = f"{BASE_URL}/api/oauth/Login"
CALCULATE_URL = f"{BASE_URL}/api/Extend/LqSalary/calculate/health-coach"

def get_token():
    """获取登录token"""
    data = {
        "account": "admin",
        "password": "e10adc3949ba59abbe56e057f20f883e"  # 123456的MD5
    }
    
    headers = {
        "Content-Type": "application/x-www-form-urlencoded"
    }
    
    response = requests.post(LOGIN_URL, data=data, headers=headers)
    if response.status_code == 200:
        result = response.json()
        if result.get("code") == 200 and result.get("data"):
            token = result["data"].get("token")
            return token
    return None

def test_calculate_salary(year, month):
    """测试计算工资接口"""
    token = get_token()
    if not token:
        print("❌ 获取token失败")
        return
    
    headers = {
        "Authorization": token,
        "Content-Type": "application/json"
    }
    
    # 计算工资
    params = {
        "year": year,
        "month": month
    }
    
    print(f"\n{'='*60}")
    print(f"测试健康师薪酬计算接口")
    print(f"{'='*60}")
    print(f"年份: {year}")
    print(f"月份: {month}")
    print(f"\n请求URL: {CALCULATE_URL}")
    print(f"请求参数: {params}")
    print(f"\n正在发送请求...")
    
    try:
        response = requests.post(CALCULATE_URL, json=params, headers=headers)
        
        print(f"\n响应状态码: {response.status_code}")
        
        if response.status_code == 200:
            print("✅ 接口调用成功")
            
            # 检查响应内容
            try:
                result = response.json()
                print(f"\n响应内容:")
                print(f"  {result}")
                
                # 如果是字符串响应(成功消息)
                if isinstance(result, str):
                    print(f"\n✅ 计算完成: {result}")
                elif isinstance(result, dict):
                    print(f"\n响应详情:")
                    for key, value in result.items():
                        print(f"  {key}: {value}")
            except:
                print(f"\n响应文本: {response.text[:500]}")
        else:
            print(f"❌ 接口调用失败")
            print(f"响应内容: {response.text}")
            
    except Exception as e:
        print(f"❌ 请求异常: {str(e)}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    # 测试2025年12月的工资计算
    test_calculate_salary(2025, 12)
    
    print(f"\n{'='*60}")
    print("测试说明:")
    print("1. 接口调用成功后,需要检查日志确认:")
    print("   - 跳过了多少条已锁定或已确认的记录")
    print("   - 更新了多少条未锁定且未确认的记录")
    print("2. 检查数据库中已锁定或已确认的记录,确认:")
    print("   - 扣款项目是否被保留")
    print("   - 补贴项目是否被保留")
    print("   - 其他导入的数据是否被保留")
    print(f"{'='*60}")