diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc index 9d2c16f..1521c3a 100644 Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ diff --git a/app.py b/app.py index 81c60e7..e2525cb 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from flask import Flask, request, jsonify, send_from_directory from flask_cors import CORS from flasgger import Swagger import os +import pymysql from datetime import datetime from dotenv import load_dotenv @@ -284,6 +285,85 @@ def extract(): return error_response(2001, f"AI解析超时或发生错误: {str(e)}") +@app.route('/api/file-configs', methods=['GET']) +def get_file_configs(): + """ + 获取可用的文件配置列表 + 用于查询可用的fileId,供文档生成接口使用 + + --- + tags: + - 字段配置 + summary: 获取文件配置列表 + description: 返回所有启用的文件配置,包含fileId和文件名称 + responses: + 200: + description: 成功 + schema: + type: object + properties: + code: + type: integer + example: 0 + data: + type: object + properties: + fileConfigs: + type: array + items: + type: object + properties: + fileId: + type: integer + description: 文件配置ID + example: 1765273961563507 + fileName: + type: string + description: 文件名称 + example: 1.请示报告卡(XXX) + filePath: + type: string + description: MinIO文件路径 + example: /615873064429507639/TEMPLATE/2025/12/1.请示报告卡(XXX).docx + isSuccess: + type: boolean + example: true + """ + try: + conn = document_service.get_connection() + cursor = conn.cursor(pymysql.cursors.DictCursor) + + try: + sql = """ + SELECT id, name, file_path + FROM f_polic_file_config + WHERE tenant_id = %s + AND state = 1 + ORDER BY name + """ + cursor.execute(sql, (document_service.tenant_id,)) + configs = cursor.fetchall() + + file_configs = [] + for config in configs: + file_configs.append({ + 'fileId': config['id'], + 'fileName': config['name'], + 'filePath': config['file_path'] or '' + }) + + return success_response({ + 'fileConfigs': file_configs + }) + + finally: + cursor.close() + conn.close() + + except Exception as e: + return error_response(500, f"查询文件配置失败: {str(e)}") + + @app.route('/api/fields', methods=['GET']) def get_fields(): """ diff --git a/get_available_file_ids.py b/get_available_file_ids.py new file mode 100644 index 0000000..177074f --- /dev/null +++ b/get_available_file_ids.py @@ -0,0 +1,64 @@ +""" +获取所有可用的文件ID列表(用于测试) +""" +import pymysql +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 get_available_file_configs(): + """获取所有可用的文件配置""" + conn = pymysql.connect(**DB_CONFIG) + cursor = conn.cursor(pymysql.cursors.DictCursor) + + try: + sql = """ + SELECT id, name, file_path, state + FROM f_polic_file_config + WHERE tenant_id = %s + AND state = 1 + ORDER BY name + """ + cursor.execute(sql, (TENANT_ID,)) + configs = cursor.fetchall() + + print("="*80) + print("可用的文件配置列表(state=1)") + print("="*80) + print(f"\n共找到 {len(configs)} 个启用的文件配置:\n") + + for i, config in enumerate(configs, 1): + print(f"{i}. ID: {config['id']}") + print(f" 名称: {config['name']}") + print(f" 文件路径: {config['file_path'] or '(空)'}") + print() + + # 输出JSON格式,方便复制 + print("\n" + "="*80) + print("JSON格式(可用于测试):") + print("="*80) + print("[") + for i, config in enumerate(configs): + comma = "," if i < len(configs) - 1 else "" + print(f' {{"fileId": {config["id"]}, "fileName": "{config["name"]}.doc"}}{comma}') + print("]") + + return configs + + finally: + cursor.close() + conn.close() + +if __name__ == '__main__': + get_available_file_configs() + diff --git a/services/__pycache__/ai_service.cpython-312.pyc b/services/__pycache__/ai_service.cpython-312.pyc index 5df4db3..a721ebf 100644 Binary files a/services/__pycache__/ai_service.cpython-312.pyc and b/services/__pycache__/ai_service.cpython-312.pyc differ diff --git a/services/__pycache__/document_service.cpython-312.pyc b/services/__pycache__/document_service.cpython-312.pyc index 15bc3b9..42cff65 100644 Binary files a/services/__pycache__/document_service.cpython-312.pyc and b/services/__pycache__/document_service.cpython-312.pyc differ diff --git a/services/document_service.py b/services/document_service.py index 98dc499..cacc49a 100644 --- a/services/document_service.py +++ b/services/document_service.py @@ -215,7 +215,12 @@ class DocumentService: # 获取文件配置 file_config = self.get_file_config_by_id(file_id) if not file_config: - raise Exception(f"文件ID {file_id} 对应的模板不存在或未启用") + # 提供更详细的错误信息 + raise Exception( + f"文件ID {file_id} 对应的模板不存在或未启用。" + f"请通过查询 f_polic_file_config 表获取有效的文件ID," + f"或访问 /api/file-configs 接口查看可用的文件配置列表。" + ) # 检查file_path是否存在 file_path = file_config.get('file_path') diff --git a/static/index.html b/static/index.html index aca06fc..3a4e600 100644 --- a/static/index.html +++ b/static/index.html @@ -327,10 +327,13 @@
+
+ + +
-
@@ -548,27 +551,81 @@ // ==================== 文档生成接口相关 ==================== - function initGenerateTab() { + async function loadAvailableFiles() { + try { + const response = await fetch('/api/file-configs'); + const result = await response.json(); + + if (result.isSuccess && result.data && result.data.fileConfigs) { + const container = document.getElementById('fileListContainer'); + container.innerHTML = ''; // 清空现有列表 + + // 只添加有filePath的文件(有模板文件的) + const filesWithPath = result.data.fileConfigs.filter(f => f.filePath); + + if (filesWithPath.length === 0) { + alert('没有找到可用的文件配置(需要有filePath)'); + return; + } + + // 添加前5个文件作为示例 + filesWithPath.slice(0, 5).forEach(file => { + addFileItem(file.fileId, file.fileName); + }); + + if (filesWithPath.length > 5) { + alert(`已加载前5个文件,共找到 ${filesWithPath.length} 个可用文件`); + } else { + alert(`已加载 ${filesWithPath.length} 个可用文件`); + } + } else { + alert('获取文件列表失败: ' + (result.errorMsg || '未知错误')); + } + } catch (error) { + alert('加载文件列表失败: ' + error.message); + } + } + + async function initGenerateTab() { // 初始化默认字段(完整的虚拟测试数据) addGenerateField('target_name', '张三'); addGenerateField('target_gender', '男'); - addGenerateField('target_age', '44'); - addGenerateField('target_date_of_birth', '198005'); - addGenerateField('target_organization_and_position', '某公司总经理'); - addGenerateField('target_organization', '某公司'); - addGenerateField('target_position', '总经理'); - addGenerateField('target_education_level', '本科'); + addGenerateField('target_age', '34'); + addGenerateField('target_date_of_birth', '199009'); + addGenerateField('target_organization_and_position', '云南省农业机械公司党支部书记、经理'); + addGenerateField('target_organization', '云南省农业机械公司'); + addGenerateField('target_position', '党支部书记、经理'); + addGenerateField('target_education_level', '研究生'); addGenerateField('target_political_status', '中共党员'); - addGenerateField('target_professional_rank', '正处级'); - addGenerateField('clue_source', '群众举报'); - addGenerateField('target_issue_description', '违反国家计划生育有关政策规定,于2010年10月生育二胎。'); - addGenerateField('department_opinion', '建议进行初步核实'); - addGenerateField('filler_name', '李四'); + addGenerateField('target_professional_rank', ''); + addGenerateField('clue_source', ''); + addGenerateField('target_issue_description', '张三多次在私下聚会、网络群组中发表抹黑党中央决策部署的言论,传播歪曲党的理论和路线方针政策的错误观点,频繁接受管理服务对象安排的高档宴请、私人会所聚餐,以及高尔夫球、高端足浴等娱乐活动,相关费用均由对方全额承担,在干部选拔任用、岗位调整工作中,利用职务便利收受他人财物,利用职权为其亲属经营的公司谋取不正当利益,帮助该公司违规承接本单位及关联单位工程项目3个,合同总额超200万元,从中收受亲属给予的"感谢费"15万元;其本人沉迷赌博活动,每周至少参与1次大额赌资赌博,单次赌资超1万元,累计赌资达数十万元。'); + addGenerateField('department_opinion', ''); + addGenerateField('filler_name', ''); - // 初始化默认文件(使用fileId,不再需要templateCode) - // fileId可以从f_polic_file_config表查询获取 - addFileItem(1765273961883544, '初步核实审批表.doc'); // 2.初步核实审批表(XXX) - addFileItem(1765273961563507, '请示报告卡.doc'); // 1.请示报告卡(XXX) + // 自动加载可用的文件列表(只加载前2个作为示例) + try { + const response = await fetch('/api/file-configs'); + const result = await response.json(); + + if (result.isSuccess && result.data && result.data.fileConfigs) { + // 只添加有filePath的文件(有模板文件的) + const filesWithPath = result.data.fileConfigs.filter(f => f.filePath); + + // 添加前2个文件作为示例 + filesWithPath.slice(0, 2).forEach(file => { + addFileItem(file.fileId, file.fileName); + }); + } else { + // 如果加载失败,使用默认的fileId + addFileItem(1765273961883544, '初步核实审批表.doc'); // 2.初步核实审批表(XXX) + addFileItem(1765273961563507, '请示报告卡.doc'); // 1.请示报告卡(XXX) + } + } catch (error) { + // 如果加载失败,使用默认的fileId + addFileItem(1765273961883544, '初步核实审批表.doc'); + addFileItem(1765273961563507, '请示报告卡.doc'); + } } function addGenerateField(fieldCode = '', fieldValue = '') {