修复数据字段,调整测试页面代码
This commit is contained in:
parent
7a304eab31
commit
c9d1d3dfd0
122
check_template_in_db.py
Normal file
122
check_template_in_db.py
Normal file
@ -0,0 +1,122 @@
|
||||
"""
|
||||
检查数据库中的模板配置
|
||||
"""
|
||||
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()
|
||||
233
fix_template_input_data.py
Normal file
233
fix_template_input_data.py
Normal file
@ -0,0 +1,233 @@
|
||||
"""
|
||||
修复数据库中模板配置的 input_data 字段
|
||||
确保所有记录的 input_data JSON 中包含正确的 template_code
|
||||
"""
|
||||
import pymysql
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# 数据库连接配置
|
||||
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
|
||||
UPDATED_BY = 655162080928945152
|
||||
CURRENT_TIME = datetime.now()
|
||||
|
||||
# 模板编码映射(从 init_all_templates.py 复制)
|
||||
DOCUMENT_TYPE_MAPPING = {
|
||||
"1.请示报告卡(XXX)": {
|
||||
"template_code": "REPORT_CARD",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"2.初步核实审批表(XXX)": {
|
||||
"template_code": "PRELIMINARY_VERIFICATION_APPROVAL",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"3.附件初核方案(XXX)": {
|
||||
"template_code": "INVESTIGATION_PLAN",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"谈话通知书第一联": {
|
||||
"template_code": "NOTIFICATION_LETTER_1",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"谈话通知书第二联": {
|
||||
"template_code": "NOTIFICATION_LETTER_2",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"谈话通知书第三联": {
|
||||
"template_code": "NOTIFICATION_LETTER_3",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"1.请示报告卡(初核谈话)": {
|
||||
"template_code": "REPORT_CARD_INTERVIEW",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"2谈话审批表": {
|
||||
"template_code": "INTERVIEW_APPROVAL_FORM",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"3.谈话前安全风险评估表": {
|
||||
"template_code": "PRE_INTERVIEW_RISK_ASSESSMENT",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"4.谈话方案": {
|
||||
"template_code": "INTERVIEW_PLAN",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"5.谈话后安全风险评估表": {
|
||||
"template_code": "POST_INTERVIEW_RISK_ASSESSMENT",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"1.谈话笔录": {
|
||||
"template_code": "INTERVIEW_RECORD",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"2.谈话询问对象情况摸底调查30问": {
|
||||
"template_code": "INVESTIGATION_30_QUESTIONS",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"3.被谈话人权利义务告知书": {
|
||||
"template_code": "RIGHTS_OBLIGATIONS_NOTICE",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"4.点对点交接单": {
|
||||
"template_code": "HANDOVER_FORM",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"4.点对点交接单2": {
|
||||
"template_code": "HANDOVER_FORM_2",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"5.陪送交接单(新)": {
|
||||
"template_code": "ESCORT_HANDOVER_FORM",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"6.1保密承诺书(谈话对象使用-非中共党员用)": {
|
||||
"template_code": "CONFIDENTIALITY_COMMITMENT_NON_PARTY",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"6.2保密承诺书(谈话对象使用-中共党员用)": {
|
||||
"template_code": "CONFIDENTIALITY_COMMITMENT_PARTY",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"7.办案人员-办案安全保密承诺书": {
|
||||
"template_code": "INVESTIGATOR_CONFIDENTIALITY_COMMITMENT",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"8-1请示报告卡(初核报告结论) ": {
|
||||
"template_code": "REPORT_CARD_CONCLUSION",
|
||||
"business_type": "INVESTIGATION"
|
||||
},
|
||||
"8.XXX初核情况报告": {
|
||||
"template_code": "INVESTIGATION_REPORT",
|
||||
"business_type": "INVESTIGATION"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def fix_input_data():
|
||||
"""修复所有记录的 input_data 字段"""
|
||||
print("="*80)
|
||||
print("修复模板配置的 input_data 字段")
|
||||
print("="*80)
|
||||
|
||||
try:
|
||||
conn = pymysql.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||
|
||||
# 查询所有文件配置
|
||||
sql = """
|
||||
SELECT id, name, template_code, input_data, 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")
|
||||
|
||||
updated_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
for config in configs:
|
||||
config_id = config['id']
|
||||
name = config['name']
|
||||
template_code_col = config.get('template_code')
|
||||
input_data_str = config.get('input_data')
|
||||
state = config.get('state', 0)
|
||||
|
||||
# 确定应该使用的 template_code
|
||||
target_template_code = None
|
||||
target_business_type = "INVESTIGATION" # 默认值
|
||||
|
||||
# 方法1: 从映射表中查找
|
||||
if name in DOCUMENT_TYPE_MAPPING:
|
||||
target_template_code = DOCUMENT_TYPE_MAPPING[name]['template_code']
|
||||
target_business_type = DOCUMENT_TYPE_MAPPING[name]['business_type']
|
||||
# 方法2: 使用 template_code 列的值
|
||||
elif template_code_col:
|
||||
target_template_code = template_code_col
|
||||
|
||||
if not target_template_code:
|
||||
print(f"⚠ 跳过: {name} (无法确定 template_code)")
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
# 检查 input_data 是否需要更新
|
||||
need_update = False
|
||||
current_input_data = {}
|
||||
|
||||
if input_data_str:
|
||||
try:
|
||||
current_input_data = json.loads(input_data_str) if isinstance(input_data_str, str) else input_data_str
|
||||
if not isinstance(current_input_data, dict):
|
||||
current_input_data = {}
|
||||
except:
|
||||
current_input_data = {}
|
||||
|
||||
# 检查 template_code 是否匹配
|
||||
if current_input_data.get('template_code') != target_template_code:
|
||||
need_update = True
|
||||
|
||||
# 检查 business_type 是否存在
|
||||
if not current_input_data.get('business_type'):
|
||||
need_update = True
|
||||
|
||||
if need_update:
|
||||
# 更新 input_data
|
||||
new_input_data = {
|
||||
'template_code': target_template_code,
|
||||
'business_type': target_business_type
|
||||
}
|
||||
# 保留原有的其他字段(如果有)
|
||||
for key, value in current_input_data.items():
|
||||
if key not in ['template_code', 'business_type']:
|
||||
new_input_data[key] = value
|
||||
|
||||
new_input_data_str = json.dumps(new_input_data, ensure_ascii=False)
|
||||
|
||||
update_sql = """
|
||||
UPDATE f_polic_file_config
|
||||
SET input_data = %s, updated_time = %s, updated_by = %s
|
||||
WHERE id = %s
|
||||
"""
|
||||
cursor.execute(update_sql, (new_input_data_str, CURRENT_TIME, UPDATED_BY, config_id))
|
||||
conn.commit()
|
||||
|
||||
print(f"✓ 更新: {name}")
|
||||
print(f" template_code: {target_template_code}")
|
||||
print(f" business_type: {target_business_type}")
|
||||
updated_count += 1
|
||||
else:
|
||||
print(f"✓ 已正确: {name} (template_code: {target_template_code})")
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("修复完成")
|
||||
print("="*80)
|
||||
print(f"更新: {updated_count} 个记录")
|
||||
print(f"跳过: {skipped_count} 个记录")
|
||||
print(f"总计: {len(configs)} 个记录")
|
||||
|
||||
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__':
|
||||
fix_input_data()
|
||||
@ -256,13 +256,17 @@ def get_or_create_file_config(conn, doc_config: Dict, file_path: str) -> int:
|
||||
|
||||
if existing:
|
||||
file_config_id = existing[0]
|
||||
# 更新文件路径
|
||||
# 更新文件路径和 input_data(确保 input_data 中包含正确的 template_code)
|
||||
input_data = json.dumps({
|
||||
'template_code': doc_config['template_code'],
|
||||
'business_type': doc_config['business_type']
|
||||
}, ensure_ascii=False)
|
||||
update_sql = """
|
||||
UPDATE f_polic_file_config
|
||||
SET file_path = %s, updated_time = %s, updated_by = %s
|
||||
SET file_path = %s, input_data = %s, updated_time = %s, updated_by = %s, state = 1
|
||||
WHERE id = %s
|
||||
"""
|
||||
cursor.execute(update_sql, (file_path, CURRENT_TIME, UPDATED_BY, file_config_id))
|
||||
cursor.execute(update_sql, (file_path, input_data, CURRENT_TIME, UPDATED_BY, file_config_id))
|
||||
conn.commit()
|
||||
return file_config_id
|
||||
else:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -567,7 +567,7 @@
|
||||
|
||||
// 初始化默认文件(包含多个模板用于测试)
|
||||
addFileItem(1, '初步核实审批表.doc', 'PRELIMINARY_VERIFICATION_APPROVAL');
|
||||
addFileItem(2, '请示报告卡.doc', 'REQUEST_REPORT_CARD');
|
||||
addFileItem(2, '请示报告卡.doc', 'REPORT_CARD');
|
||||
}
|
||||
|
||||
function addGenerateField(fieldCode = '', fieldValue = '') {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
27
test_template_query.py
Normal file
27
test_template_query.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""
|
||||
测试模板编码查询
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from services.document_service import DocumentService
|
||||
|
||||
# 测试查询 REPORT_CARD
|
||||
print("="*60)
|
||||
print("测试查询模板编码: REPORT_CARD")
|
||||
print("="*60)
|
||||
|
||||
service = DocumentService()
|
||||
result = service.get_file_config_by_template_code('REPORT_CARD')
|
||||
|
||||
if result:
|
||||
print("\n✓ 找到模板配置:")
|
||||
print(f" - ID: {result['id']}")
|
||||
print(f" - 名称: {result['name']}")
|
||||
print(f" - 文件路径: {result['file_path']}")
|
||||
print(f" - 模板编码: {result['template_code']}")
|
||||
else:
|
||||
print("\n✗ 未找到模板配置")
|
||||
print("\n请运行以下脚本修复:")
|
||||
print(" python fix_template_input_data.py")
|
||||
92
verify_template_code.py
Normal file
92
verify_template_code.py
Normal file
@ -0,0 +1,92 @@
|
||||
"""
|
||||
验证模板编码是否存在
|
||||
"""
|
||||
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 verify_template_code(template_code: str):
|
||||
"""验证指定的模板编码是否存在"""
|
||||
print("="*60)
|
||||
print(f"验证模板编码: {template_code}")
|
||||
print("="*60)
|
||||
|
||||
try:
|
||||
conn = pymysql.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||
|
||||
# 查询所有文件配置
|
||||
sql = """
|
||||
SELECT id, name, file_path, input_data, state
|
||||
FROM f_polic_file_config
|
||||
WHERE tenant_id = %s
|
||||
AND state = 1
|
||||
"""
|
||||
cursor.execute(sql, (TENANT_ID,))
|
||||
configs = cursor.fetchall()
|
||||
|
||||
found = False
|
||||
print(f"\n查询到 {len(configs)} 个启用的文件配置\n")
|
||||
|
||||
for config in configs:
|
||||
try:
|
||||
input_data = json.loads(config['input_data']) if config['input_data'] else {}
|
||||
config_template_code = input_data.get('template_code')
|
||||
|
||||
if config_template_code == template_code:
|
||||
found = True
|
||||
print(f"✓ 找到匹配的模板:")
|
||||
print(f" - 名称: {config['name']}")
|
||||
print(f" - ID: {config['id']}")
|
||||
print(f" - 模板编码: {config_template_code}")
|
||||
print(f" - 文件路径: {config['file_path']}")
|
||||
print(f" - 状态: {'启用' if config['state'] == 1 else '未启用'}")
|
||||
print()
|
||||
except (json.JSONDecodeError, TypeError) as e:
|
||||
continue
|
||||
|
||||
if not found:
|
||||
print(f"✗ 未找到模板编码: {template_code}")
|
||||
print("\n可用的模板编码列表:")
|
||||
print("-" * 60)
|
||||
for config in configs:
|
||||
try:
|
||||
input_data = json.loads(config['input_data']) if config['input_data'] else {}
|
||||
config_template_code = input_data.get('template_code')
|
||||
if config_template_code:
|
||||
print(f" - {config_template_code} ({config['name']})")
|
||||
except:
|
||||
continue
|
||||
print()
|
||||
|
||||
return found
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ 查询失败: {str(e)}")
|
||||
return False
|
||||
finally:
|
||||
if 'cursor' in locals():
|
||||
cursor.close()
|
||||
if 'conn' in locals():
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 验证 REPORT_CARD 模板编码
|
||||
verify_template_code('REPORT_CARD')
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("验证完成")
|
||||
print("="*60)
|
||||
Loading…
x
Reference in New Issue
Block a user