修复AI建议逻辑和字段映射问题

- 修复AI建议基于问题描述而不是处理过程生成
- 修复工单详情页面显示逻辑
- 修复飞书时间字段处理(毫秒时间戳转换)
- 优化字段映射和转换逻辑
- 添加飞书集成功能
- 改进对话历史合并功能
- 优化系统优化反馈机制
This commit is contained in:
赵杰 Jie Zhao (雄狮汽车科技)
2025-09-19 17:29:33 +01:00
parent 66f44143d9
commit 79cf316c63
20 changed files with 2648 additions and 86 deletions

View File

@@ -306,6 +306,108 @@ def optimize_disk():
except Exception as e:
return jsonify({"error": str(e)}), 500
@system_bp.route('/system-optimizer/clear-cache', methods=['POST'])
def clear_cache():
"""清理应用缓存(内存/Redis均尝试"""
try:
cleared = False
try:
from src.core.cache_manager import cache_manager
cache_manager.clear()
cleared = True
except Exception:
pass
return jsonify({
'success': True,
'message': '缓存已清理' if cleared else '缓存清理已尝试(可能未启用缓存模块)',
'progress': 100
})
except Exception as e:
return jsonify({"error": str(e)}), 500
@system_bp.route('/system-optimizer/optimize-all', methods=['POST'])
def optimize_all():
"""一键优化CPU/内存/磁盘 + 缓存清理 + 轻量数据库维护"""
try:
import gc
import time
actions = []
start_time = time.time()
# 垃圾回收 & 缓存
try:
collected = gc.collect()
actions.append(f"垃圾回收:{collected}")
except Exception:
actions.append("垃圾回收:跳过")
try:
from src.core.cache_manager import cache_manager
cache_manager.clear()
actions.append("缓存清理:完成")
except Exception:
actions.append("缓存清理:跳过")
# 临时文件与日志清理(沿用磁盘优化逻辑的子集)
temp_files_cleaned = 0
log_files_cleaned = 0
try:
import os, tempfile
temp_dir = tempfile.gettempdir()
for filename in os.listdir(temp_dir):
if filename.startswith('tsp_') or filename.startswith('tmp_'):
file_path = os.path.join(temp_dir, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path)
temp_files_cleaned += 1
except Exception:
pass
except Exception:
pass
actions.append(f"临时文件:{temp_files_cleaned}")
try:
import os, glob
from datetime import datetime, timedelta
log_dir = 'logs'
if os.path.exists(log_dir):
cutoff_date = datetime.now() - timedelta(days=7)
for log_file in glob.glob(os.path.join(log_dir, '*.log')):
try:
file_time = datetime.fromtimestamp(os.path.getmtime(log_file))
if file_time < cutoff_date:
os.remove(log_file)
log_files_cleaned += 1
except Exception:
pass
except Exception:
pass
actions.append(f"日志清理:{log_files_cleaned}")
# 轻量数据库维护尽力而为SQLite时执行VACUUM其他数据库跳过
try:
engine = db_manager.engine
if str(engine.url).startswith('sqlite'):
with engine.begin() as conn:
conn.exec_driver_sql('VACUUM')
actions.append("SQLite VACUUM:完成")
else:
actions.append("DB维护:跳过(非SQLite)")
except Exception:
actions.append("DB维护:失败")
optimization_time = round((time.time() - start_time) * 1000, 1)
return jsonify({
'success': True,
'message': '一键优化完成: ' + ''.join(actions) + f',耗时{optimization_time}ms',
'progress': 100,
'actions': actions,
'optimization_time': optimization_time
})
except Exception as e:
return jsonify({"error": str(e)}), 500
@system_bp.route('/system-optimizer/security-settings', methods=['GET', 'POST'])
def security_settings():
"""安全设置"""