Files
his/zentao_api_example.py
zhangfei 9c3e603b94 Fix Bug #443: 手术计费:点击签发耗材时异常报错
当手术计费弹窗中点击"签发"耗材时,因耗材的locationId(发放库房)为空导致后端异常。
在DoctorStationAdviceAppServiceImpl.handDevice方法中,当locationId为null时,使用登录用户的科室ID作为默认值,
与NurseBillingAppService中的处理方式保持一致。
2026-05-08 09:14:18 +08:00

101 lines
2.8 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
禅道 API 示例脚本 - 创建 Bug
"""
import requests
import json
# 禅道配置(需要根据实际情况修改)
ZENTAO_URL = "http://your-zentao-domain.com" # 禅道地址
ZENTAO_ACCOUNT = "your_username" # 禅道账号
ZENTAO_PASSWORD = "your_password" # 禅道密码
def get_token():
"""获取禅道 API Token"""
url = f"{ZENTAO_URL}/api.php/v1/tokens"
headers = {
"Content-Type": "application/json"
}
data = {
"account": ZENTAO_ACCOUNT,
"password": ZENTAO_PASSWORD
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if response.status_code == 200 and result.get("status") == "success":
return result.get("token")
else:
raise Exception(f"获取 Token 失败: {result}")
def create_bug(token, product_id, title, steps, severity=2, priority=2, module='', assigned_to=''):
"""
创建Bug
参数:
token: API Token
product_id: 产品ID
title: Bug标题
steps: 重现步骤
severity: 严重程度 (1-4, 默认2: 一般)
priority: 优先级 (1-4, 默认2: 中等)
module: 模块ID (可选)
assigned_to: 指派给谁 (可选)
"""
url = f"{ZENTAO_URL}/api.php/v1/products/{product_id}/bugs"
headers = {
"Content-Type": "application/json",
"Authorization": token
}
data = {
"product": product_id,
"module": module,
"title": title,
"steps": steps,
"severity": severity,
"priority": priority,
"assignedTo": assigned_to
}
# 移除值为空的字段
data = {k: v for k, v in data.items() if v}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if response.status_code == 200 and result.get("status") == "success":
print(f"✅ Bug 创建成功Bug ID: {result.get('data', {}).get('id')}")
return result
else:
print(f"❌ Bug 创建失败: {result}")
return None
def main():
try:
# 1. 获取 Token
print("正在获取 Token...")
token = get_token()
print(f"✓ Token 获取成功: {token[:10]}...")
# 2. 创建 Bug 示例
# TODO: 请根据实际情况修改以下参数
product_id = 100 # 产品ID需要在禅道中查询
title = "【测试】API 创建 Bug 示例"
steps = """1. 登录系统
2. 进入某个模块
3. 执行某个操作
4. 观察结果"""
print("\n正在创建 Bug...")
create_bug(token, product_id, title, steps)
except Exception as e:
print(f"❌ 发生错误: {e}")
if __name__ == "__main__":
main()