Blame view

项目文档相关/scripts/py/test_health_coach_salary_calculate.py 3.21 KB
d9aced6a   “wangming”   优化工资计算逻辑,确保未锁定且未确...
1
2
3
4
5
6
7
8
9
10
11
  #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  测试健康师薪酬计算接口
  验证已锁定和已确认的记录不会被覆盖
  """
  
  import requests
  import urllib.parse
  
  # API配置
8daf47d0   “wangming”   修改访问地址
12
  BASE_URL = "http://localhost:2015"
d9aced6a   “wangming”   优化工资计算逻辑,确保未锁定且未确...
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
  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}")