fix: 6 bug fixes - timezone CST, knowledge_ids mismatch, skill uninstall, dashboard stats, chat knowledge retrieval, skill selection
This commit is contained in:
1 parent
f7ab61bd9d
commit
8ec808b515
6 files changed
+119
-49
No files matched your search
@@ -10,10 +10,13 @@ from ...models import (
|
||||
)
|
||||
from ...auth import get_current_admin
|
||||
from ...middleware.log_service import LogService
|
||||
from datetime import datetime, date
|
||||
from datetime import datetime, date, timezone, timedelta
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# CST timezone (UTC+8)
|
||||
CST_TZ = timezone(timedelta(hours=8))
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
async def get_dashboard_stats(
|
||||
@@ -21,7 +24,11 @@ async def get_dashboard_stats(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""获取管理员仪表盘统计数据"""
|
||||
today = date.today()
|
||||
# Use CST timezone for "today" since container uses UTC but users are in CST
|
||||
now_cst = datetime.now(CST_TZ)
|
||||
today_cst = now_cst.date()
|
||||
# Convert CST today start to UTC for DB comparison
|
||||
today_start_utc = datetime(now_cst.year, now_cst.month, now_cst.day, 0, 0, 0, tzinfo=CST_TZ).astimezone(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
active_users = db.query(func.count(User.id)).filter(
|
||||
User.status == "active"
|
||||
@@ -31,12 +38,13 @@ async def get_dashboard_stats(
|
||||
AIModel.is_enabled == True
|
||||
).scalar() or 0
|
||||
|
||||
# Use range comparison instead of func.date() for timezone-correct results
|
||||
today_orders = db.query(func.count(Order.id)).filter(
|
||||
func.date(Order.created_at) == today
|
||||
Order.created_at >= today_start_utc
|
||||
).scalar() or 0
|
||||
|
||||
today_tokens = db.query(func.sum(TokenUsageLog.total_tokens)).filter(
|
||||
func.date(TokenUsageLog.created_at) == today
|
||||
TokenUsageLog.created_at >= today_start_utc
|
||||
).scalar() or 0
|
||||
|
||||
total_tokens = db.query(func.sum(TokenUsageLog.total_tokens)).scalar() or 0
|
||||
@@ -47,6 +55,7 @@ async def get_dashboard_stats(
|
||||
"today_orders": today_orders,
|
||||
"today_tokens": int(today_tokens),
|
||||
"total_tokens": int(total_tokens),
|
||||
"server_time": now_cst.isoformat(),
|
||||
}
|
||||
|
||||
|
||||
@@ -69,12 +78,20 @@ async def get_recent_logs(
|
||||
"target_id": log.target_id,
|
||||
"detail": log.detail,
|
||||
"ip": log.ip,
|
||||
"created_at": log.created_at.isoformat() if log.created_at else None,
|
||||
"created_at": _format_cst(log.created_at),
|
||||
}
|
||||
for log in logs
|
||||
]
|
||||
|
||||
|
||||
def _format_cst(dt_value):
|
||||
"""Format UTC naive datetime to CST ISO string"""
|
||||
if dt_value is None:
|
||||
return None
|
||||
utc_dt = dt_value.replace(tzinfo=timezone.utc)
|
||||
cst_dt = utc_dt.astimezone(CST_TZ)
|
||||
return cst_dt.isoformat()
|
||||
|
||||
@router.get("/recent-audit")
|
||||
async def get_recent_audit(
|
||||
admin_user=Depends(get_current_admin),
|
||||
@@ -93,7 +110,16 @@ async def get_recent_audit(
|
||||
"target_type": log.target_type,
|
||||
"target_id": log.target_id,
|
||||
"detail": log.detail,
|
||||
"created_at": log.created_at.isoformat() if log.created_at else None,
|
||||
"created_at": _format_cst(log.created_at),
|
||||
}
|
||||
for log in logs
|
||||
]
|
||||
|
||||
|
||||
def _format_cst(dt_value):
|
||||
"""Format UTC naive datetime to CST ISO string"""
|
||||
if dt_value is None:
|
||||
return None
|
||||
utc_dt = dt_value.replace(tzinfo=timezone.utc)
|
||||
cst_dt = utc_dt.astimezone(CST_TZ)
|
||||
return cst_dt.isoformat()
|
||||
Reference in new issue
Block a user