2026-07-12 01:07:26 +08:00
|
|
|
"""
|
|
|
|
|
参数数据自动化管理系统
|
|
|
|
|
"""
|
2026-07-12 01:23:15 +08:00
|
|
|
from flask import Flask, jsonify, render_template, send_from_directory
|
2026-07-12 01:07:26 +08:00
|
|
|
from flask_cors import CORS
|
|
|
|
|
from config import Config
|
|
|
|
|
from models.database import db
|
|
|
|
|
from utils.scheduler import task_scheduler, setup_auto_process_job
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
# 配置日志
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
|
|
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
|
|
handlers=[
|
|
|
|
|
logging.FileHandler(os.path.join(Config.LOG_DIR, 'app.log')),
|
|
|
|
|
logging.StreamHandler()
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
logger = logging.getLogger('param_auto_manager')
|
|
|
|
|
|
|
|
|
|
# 创建Flask应用
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
CORS(app)
|
|
|
|
|
|
|
|
|
|
# 注册路由
|
|
|
|
|
from routes.articles import bp as articles_bp
|
|
|
|
|
from routes.products import bp as products_bp
|
|
|
|
|
from routes.system import bp as system_bp
|
2026-07-14 10:59:18 +08:00
|
|
|
from routes.tasks import bp as tasks_bp
|
2026-07-14 12:23:49 +08:00
|
|
|
from routes.process_monitor import bp as process_monitor_bp
|
2026-07-12 01:07:26 +08:00
|
|
|
|
|
|
|
|
app.register_blueprint(articles_bp)
|
|
|
|
|
app.register_blueprint(products_bp)
|
|
|
|
|
app.register_blueprint(system_bp)
|
2026-07-14 10:59:18 +08:00
|
|
|
app.register_blueprint(tasks_bp)
|
2026-07-14 12:23:49 +08:00
|
|
|
app.register_blueprint(process_monitor_bp)
|
2026-07-12 01:07:26 +08:00
|
|
|
|
|
|
|
|
# 首页
|
|
|
|
|
@app.route('/')
|
|
|
|
|
def index():
|
2026-07-12 01:23:15 +08:00
|
|
|
return render_template('index.html')
|
|
|
|
|
|
2026-07-13 16:38:14 +08:00
|
|
|
# 搜索页面
|
|
|
|
|
@app.route('/search')
|
|
|
|
|
def search_page():
|
|
|
|
|
return render_template('search.html')
|
|
|
|
|
|
2026-07-13 17:35:34 +08:00
|
|
|
# 内容库页面
|
|
|
|
|
@app.route('/library')
|
|
|
|
|
def library_page():
|
|
|
|
|
return render_template('library.html')
|
|
|
|
|
|
2026-07-14 12:23:49 +08:00
|
|
|
# 处理监控页面
|
|
|
|
|
@app.route('/process')
|
|
|
|
|
def process_page():
|
|
|
|
|
return render_template('process.html')
|
|
|
|
|
|
2026-07-12 01:23:15 +08:00
|
|
|
# API首页
|
|
|
|
|
@app.route('/api')
|
|
|
|
|
def api_index():
|
2026-07-12 01:07:26 +08:00
|
|
|
return jsonify({
|
|
|
|
|
'name': 'Param Auto Manager',
|
|
|
|
|
'version': '1.0.0',
|
|
|
|
|
'description': '参数数据自动化管理系统',
|
|
|
|
|
'endpoints': {
|
|
|
|
|
'articles': '/api/articles',
|
|
|
|
|
'products': '/api/products',
|
|
|
|
|
'system': '/api/system'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-12 01:23:15 +08:00
|
|
|
# 静态文件
|
|
|
|
|
@app.route('/static/<path:filename>')
|
|
|
|
|
def static_files(filename):
|
|
|
|
|
return send_from_directory('static', filename)
|
|
|
|
|
|
2026-07-12 01:07:26 +08:00
|
|
|
# 错误处理
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
|
def not_found(error):
|
|
|
|
|
return jsonify({'error': '资源不存在'}), 404
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
|
|
|
|
def internal_error(error):
|
|
|
|
|
return jsonify({'error': '服务器内部错误'}), 500
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
# 确保日志目录存在
|
|
|
|
|
os.makedirs(Config.LOG_DIR, exist_ok=True)
|
|
|
|
|
os.makedirs(os.path.dirname(Config.DATABASE), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# 初始化数据库
|
|
|
|
|
logger.info("初始化数据库...")
|
|
|
|
|
|
|
|
|
|
# 设置自动处理任务
|
|
|
|
|
setup_auto_process_job()
|
|
|
|
|
|
|
|
|
|
# 启动定时任务调度器
|
|
|
|
|
task_scheduler.start()
|
|
|
|
|
logger.info("定时任务调度器已启动")
|
|
|
|
|
|
|
|
|
|
# 启动Flask应用
|
|
|
|
|
logger.info(f"启动服务,端口: {Config.PORT}")
|
|
|
|
|
app.run(
|
|
|
|
|
host=Config.HOST,
|
|
|
|
|
port=Config.PORT,
|
|
|
|
|
debug=Config.DEBUG
|
|
|
|
|
)
|