# inventory-backend/run.py from app import create_app app = create_app() # ========================================================= # 启动时注册库存预警定时任务(每天 9:30 北京时) # ========================================================= from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger import pytz beijing_tz = pytz.timezone('Asia/Shanghai') def _run_warning_job(): with app.app_context(): try: from app.services.inventory_task import InventoryWarningService result = InventoryWarningService.check_and_send_warning_emails() print(f"[Scheduler] 库存预警扫描完成: red={result['red_count']}, yellow={result['yellow_count']}") except Exception as e: print(f"[Scheduler] 库存预警任务失败: {e}") scheduler = BackgroundScheduler(timezone=beijing_tz) scheduler.add_job( func=_run_warning_job, trigger=CronTrigger(hour=9, minute=30, timezone=beijing_tz), id='inventory_warning_daily', name='库存预警每日邮件发送', replace_existing=True ) scheduler.start() print("✅ 库存预警定时任务已启动(每天 9:30 北京时间执行)") if __name__ == '__main__': # ================================================= # 路由打印调试 (启动时会在控制台列出所有 URL) # 这一步能帮你确认 /api/inbound/base/list 是否存在 # ================================================= print("\n====== 当前生效的路由映射 ======") try: # 按 URL 排序打印,方便查找 sorted_rules = sorted(app.url_map.iter_rules(), key=lambda x: str(x)) for rule in sorted_rules: # 过滤掉一些系统自带的 static 路由,只显示 API if 'api' in str(rule): methods = ','.join(rule.methods - {'OPTIONS', 'HEAD'}) print(f"{str(rule):<50} | {methods:<10} | {rule.endpoint}") except Exception: pass print("==============================\n") # 启动开发服务器 # 端口设置为 5000 (Flask 默认) 或 8000,请确保与前端 Vite 代理一致 app.run(host='0.0.0.0', port=8000, debug=True)