83 lines
3.4 KiB
Python
83 lines
3.4 KiB
Python
"""
|
||
直接测试 API,查看返回的关联关系数据
|
||
"""
|
||
import requests
|
||
import json
|
||
|
||
TENANT_ID = 615873064429507639
|
||
TEMPLATE_ID = 1765432134276990 # 1.请示报告卡(初核谈话)
|
||
API_BASE_URL = 'http://localhost:7500'
|
||
|
||
def test_api():
|
||
"""测试 API"""
|
||
print(f"测试租户ID: {TENANT_ID}")
|
||
print(f"测试模板ID: {TEMPLATE_ID}")
|
||
print("=" * 80)
|
||
|
||
try:
|
||
response = requests.get(
|
||
f'{API_BASE_URL}/api/template-field-relations',
|
||
params={'tenant_id': TENANT_ID},
|
||
timeout=10
|
||
)
|
||
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
if result.get('isSuccess'):
|
||
data = result.get('data', {})
|
||
relations = data.get('relations', {})
|
||
|
||
# 查找该模板的关联关系
|
||
template_id_str = str(TEMPLATE_ID)
|
||
related_fields = relations.get(template_id_str, [])
|
||
|
||
print(f"\n模板ID: {TEMPLATE_ID}")
|
||
print(f"关联字段数: {len(related_fields)}")
|
||
print(f"关联字段ID: {related_fields}")
|
||
|
||
# 获取字段列表
|
||
input_fields = data.get('input_fields', [])
|
||
output_fields = data.get('output_fields', [])
|
||
|
||
input_field_ids = {f['id'] for f in input_fields}
|
||
output_field_ids = {f['id'] for f in output_fields}
|
||
|
||
related_input = [fid for fid in related_fields if fid in input_field_ids]
|
||
related_output = [fid for fid in related_fields if fid in output_field_ids]
|
||
|
||
print(f"\n关联的输入字段ID: {related_input}")
|
||
print(f"关联的输出字段ID: {related_output}")
|
||
|
||
if related_input:
|
||
print(f"\n关联的输入字段详情:")
|
||
for fid in related_input:
|
||
field = next((f for f in input_fields if f['id'] == fid), None)
|
||
if field:
|
||
print(f" - {field['name']} (ID: {fid})")
|
||
|
||
if related_output:
|
||
print(f"\n关联的输出字段详情:")
|
||
for fid in related_output[:10]:
|
||
field = next((f for f in output_fields if f['id'] == fid), None)
|
||
if field:
|
||
print(f" - {field['name']} (ID: {fid})")
|
||
else:
|
||
print(f"\n[警告] 没有找到关联的输出字段")
|
||
|
||
# 检查其他模板是否有输出字段关联
|
||
print(f"\n检查其他模板的输出字段关联:")
|
||
for key, fields in list(relations.items())[:5]:
|
||
template_id = int(key)
|
||
output_count = len([fid for fid in fields if fid in output_field_ids])
|
||
if output_count > 0:
|
||
print(f" 模板ID {template_id}: {output_count} 个输出字段")
|
||
else:
|
||
print(f"API 返回错误: {result.get('errorMsg')}")
|
||
else:
|
||
print(f"API 请求失败: {response.status_code}")
|
||
except Exception as e:
|
||
print(f"API 请求异常: {e}")
|
||
|
||
if __name__ == '__main__':
|
||
test_api()
|