8920a337e0
- 前端
- topics.html: 恢复结构并修复Vue初始化问题
- 调整创作按钮逻辑:仅已发布选题禁用
- 修正API端点与payload格式(generate/optimizer/publishing使用topic_ids数组)
- 移除ElementPlus图标模块依赖,使用全局构建
- admin.html: 回退至Options API版本,解决this上下文错误
- 后端
- 注册/api/generate/run路由
- 简化generate逻辑:允许非已发布选题重创作,更新状态为“待审查”
- 统一logs查询接口支持query参数
- 修复admin用户管理字段引用
- 系统概览返回{ stats }结构
- 静态资源整理
- 删除冗余element-plus-icons、重复CSS/JS、图标文件
- 正确放置Vue和ElementPlus全局文件
- 数据库与数据
- 补充30个案例
- 更新选题状态与初始数据
验证:所有页面可访问,API认证与端点正常工作。
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
# 宇之然内容创作平台 - 系统管理API
|
|
|
|
from sqlalchemy import func
|
|
from datetime import datetime, date
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.models import Topic
|
|
import os
|
|
|
|
from app.database import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/status")
|
|
async def get_system_status(db: Session = Depends(get_db)):
|
|
"""获取系统概览状态(格式匹配前端)"""
|
|
today = date.today()
|
|
|
|
# 统计总数
|
|
total = db.query(func.count(Topic.id)).scalar()
|
|
|
|
# 今日新选题数
|
|
today_count = db.query(func.count(Topic.id)).filter(
|
|
func.date(Topic.created_at) == today
|
|
).scalar()
|
|
|
|
# 各状态选题数量(映射到前端字段)
|
|
pending = db.query(func.count(Topic.id)).filter(Topic.status == "待处理").scalar() or 0
|
|
review = db.query(func.count(Topic.id)).filter(Topic.status == "待审查").scalar() or 0
|
|
ready = db.query(func.count(Topic.id)).filter(Topic.status == "待发布").scalar() or 0
|
|
published = db.query(func.count(Topic.id)).filter(Topic.status == "已发布").scalar() or 0
|
|
|
|
return {
|
|
"stats": {
|
|
"total": total,
|
|
"pending": pending,
|
|
"review": review,
|
|
"ready": ready,
|
|
"published": published,
|
|
"today": today_count
|
|
}
|
|
}
|
|
|
|
@router.get("/pipeline/status")
|
|
async def get_pipeline_status():
|
|
"""获取流水线状态"""
|
|
import subprocess
|
|
import json
|
|
|
|
# 检查各个模块的运行状态
|
|
pipeline_modules = {
|
|
"creator": {
|
|
"exists": os.path.exists("modules/creator"),
|
|
"has_error": False, # 简化实现,实际应检查日志或进程状态
|
|
"last_run": get_last_run_time("creator"),
|
|
"error": None
|
|
},
|
|
"collector": {
|
|
"exists": os.path.exists("modules/collector"),
|
|
"has_error": False,
|
|
"last_run": get_last_run_time("collector"),
|
|
"error": None
|
|
}
|
|
}
|
|
|
|
# 统计分布(这里应该从数据库查询,简化为静态数据)
|
|
status_distribution = {
|
|
"待处理": 0,
|
|
"待审查": 0,
|
|
"待发布": 0
|
|
}
|
|
|
|
# 实际实现中应该从数据库查询真实数据
|
|
# for status in ["待处理", "待审查", "待发布"]:
|
|
# count = db.query(func.count(Topic.id)).filter(
|
|
# Topic.status == status
|
|
# ).scalar()
|
|
# status_distribution[status] = count
|
|
|
|
return {
|
|
"status_distribution": status_distribution,
|
|
"pipeline_modules": pipeline_modules,
|
|
"topics_count": 0 # 简化实现
|
|
}
|
|
|
|
def get_last_run_time(module_name: str) -> str:
|
|
"""获取模块最后运行时间(简化实现)"""
|
|
# 实际实现应检查日志文件或数据库记录
|
|
return "2026-04-26 15:30:00" |