121 lines
4.3 KiB
Python
121 lines
4.3 KiB
Python
"""
|
|
验证更新后的关联关系
|
|
"""
|
|
import pymysql
|
|
import os
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
DB_CONFIG = {
|
|
'host': os.getenv('DB_HOST', '152.136.177.240'),
|
|
'port': int(os.getenv('DB_PORT', 5012)),
|
|
'user': os.getenv('DB_USER', 'finyx'),
|
|
'password': os.getenv('DB_PASSWORD', '6QsGK6MpePZDE57Z'),
|
|
'database': os.getenv('DB_NAME', 'finyx'),
|
|
'charset': 'utf8mb4'
|
|
}
|
|
|
|
TENANT_ID = 615873064429507639
|
|
TEMPLATE_ID = 1765432134276990 # 1.请示报告卡(初核谈话)
|
|
API_BASE_URL = 'http://localhost:7500'
|
|
|
|
def verify_relations():
|
|
"""验证关联关系"""
|
|
print("验证更新后的关联关系")
|
|
print("=" * 80)
|
|
|
|
# 从数据库查询
|
|
conn = pymysql.connect(**DB_CONFIG)
|
|
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
|
|
|
try:
|
|
# 查询模板信息
|
|
cursor.execute("""
|
|
SELECT id, name
|
|
FROM f_polic_file_config
|
|
WHERE tenant_id = %s AND id = %s
|
|
""", (TENANT_ID, TEMPLATE_ID))
|
|
template = cursor.fetchone()
|
|
print(f"模板: {template['name']} (ID: {template['id']})")
|
|
|
|
# 查询关联关系
|
|
cursor.execute("""
|
|
SELECT
|
|
fff.filed_id,
|
|
f.name as field_name,
|
|
f.filed_code,
|
|
f.field_type
|
|
FROM f_polic_file_field fff
|
|
INNER JOIN f_polic_field f ON fff.filed_id = f.id AND fff.tenant_id = f.tenant_id
|
|
WHERE fff.tenant_id = %s
|
|
AND fff.file_id = %s
|
|
AND fff.state = 1
|
|
ORDER BY f.field_type, f.name
|
|
""", (TENANT_ID, TEMPLATE_ID))
|
|
relations = cursor.fetchall()
|
|
|
|
input_fields = [r for r in relations if r['field_type'] == 1]
|
|
output_fields = [r for r in relations if r['field_type'] == 2]
|
|
|
|
print(f"\n数据库中的关联关系:")
|
|
print(f" 输入字段: {len(input_fields)}")
|
|
for f in input_fields:
|
|
print(f" - {f['field_name']} ({f['filed_code']})")
|
|
print(f" 输出字段: {len(output_fields)}")
|
|
for f in output_fields[:10]:
|
|
print(f" - {f['field_name']} ({f['filed_code']})")
|
|
if len(output_fields) > 10:
|
|
print(f" ... 还有 {len(output_fields) - 10} 个输出字段")
|
|
|
|
finally:
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
# 从 API 查询
|
|
print("\n" + "=" * 80)
|
|
print("从 API 查询关联关系")
|
|
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_field_ids = relations.get(template_id_str, [])
|
|
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_field_ids if fid in input_field_ids]
|
|
related_output = [fid for fid in related_field_ids if fid in output_field_ids]
|
|
|
|
print(f"\nAPI 返回的关联关系:")
|
|
print(f" 输入字段: {len(related_input)}")
|
|
for fid in related_input:
|
|
field = next((f for f in input_fields if f['id'] == fid), None)
|
|
if field:
|
|
print(f" - {field['name']} ({field['filed_code']})")
|
|
print(f" 输出字段: {len(related_output)}")
|
|
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']} ({field['filed_code']})")
|
|
if len(related_output) > 10:
|
|
print(f" ... 还有 {len(related_output) - 10} 个输出字段")
|
|
except Exception as e:
|
|
print(f"API 查询失败: {e}")
|
|
|
|
if __name__ == '__main__':
|
|
verify_relations()
|