123 lines
4.3 KiB
Python
123 lines
4.3 KiB
Python
"""
|
|
检查数据库中的模板配置
|
|
"""
|
|
import pymysql
|
|
import json
|
|
import os
|
|
|
|
# 数据库连接配置
|
|
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
|
|
|
|
def check_template_code():
|
|
"""检查模板编码"""
|
|
print("="*80)
|
|
print("检查数据库中的模板配置")
|
|
print("="*80)
|
|
|
|
try:
|
|
conn = pymysql.connect(**DB_CONFIG)
|
|
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
|
|
|
# 查询所有文件配置
|
|
sql = """
|
|
SELECT id, name, file_path, input_data, template_code, state
|
|
FROM f_polic_file_config
|
|
WHERE tenant_id = %s
|
|
ORDER BY name
|
|
"""
|
|
cursor.execute(sql, (TENANT_ID,))
|
|
configs = cursor.fetchall()
|
|
|
|
print(f"\n共找到 {len(configs)} 个文件配置\n")
|
|
|
|
# 查找 REPORT_CARD
|
|
print("查找 REPORT_CARD 模板编码:")
|
|
print("-" * 80)
|
|
found = False
|
|
|
|
for config in configs:
|
|
name = config['name']
|
|
template_code_col = config.get('template_code') # 从 template_code 列
|
|
input_data_str = config.get('input_data')
|
|
state = config.get('state', 0)
|
|
|
|
# 从 input_data JSON 中解析
|
|
template_code_json = None
|
|
if input_data_str:
|
|
try:
|
|
input_data = json.loads(input_data_str) if isinstance(input_data_str, str) else input_data_str
|
|
if isinstance(input_data, dict):
|
|
template_code_json = input_data.get('template_code')
|
|
except:
|
|
pass
|
|
|
|
# 检查是否匹配 REPORT_CARD
|
|
if template_code_col == 'REPORT_CARD' or template_code_json == 'REPORT_CARD':
|
|
found = True
|
|
print(f"\n✓ 找到匹配的配置:")
|
|
print(f" - ID: {config['id']}")
|
|
print(f" - 名称: {name}")
|
|
print(f" - template_code 列: {template_code_col}")
|
|
print(f" - input_data 中的 template_code: {template_code_json}")
|
|
print(f" - 文件路径: {config['file_path']}")
|
|
print(f" - 状态: {'启用' if state == 1 else '未启用'}")
|
|
print(f" - input_data 完整内容: {input_data_str}")
|
|
print()
|
|
|
|
if not found:
|
|
print("✗ 未找到 REPORT_CARD 模板编码")
|
|
print("\n所有模板配置列表:")
|
|
print("-" * 80)
|
|
for config in configs:
|
|
name = config['name']
|
|
template_code_col = config.get('template_code')
|
|
input_data_str = config.get('input_data')
|
|
state = config.get('state', 0)
|
|
|
|
# 从 input_data JSON 中解析
|
|
template_code_json = None
|
|
if input_data_str:
|
|
try:
|
|
input_data = json.loads(input_data_str) if isinstance(input_data_str, str) else input_data_str
|
|
if isinstance(input_data, dict):
|
|
template_code_json = input_data.get('template_code')
|
|
except:
|
|
pass
|
|
|
|
status_str = "启用" if state == 1 else "未启用"
|
|
code_info = f"列:{template_code_col or '(空)'}, JSON:{template_code_json or '(空)'}"
|
|
print(f" - {name} [{status_str}] [{code_info}]")
|
|
|
|
# 检查表结构
|
|
print("\n" + "="*80)
|
|
print("检查表结构")
|
|
print("="*80)
|
|
cursor.execute("DESCRIBE f_polic_file_config")
|
|
columns = cursor.fetchall()
|
|
print("\n表字段:")
|
|
for col in columns:
|
|
print(f" - {col['Field']}: {col['Type']}")
|
|
|
|
except Exception as e:
|
|
print(f"✗ 查询失败: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
finally:
|
|
if 'cursor' in locals():
|
|
cursor.close()
|
|
if 'conn' in locals():
|
|
conn.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
check_template_code()
|