fix: 6 bug fixes - timezone CST, knowledge_ids mismatch, skill uninstall, dashboard stats, chat knowledge retrieval, skill selection

This commit is contained in:
qyyfw committed 2026-07-03 09:18:04 +08:00
1 parent f7ab61bd9d
commit 8ec808b515
6 files changed
+119 -49

No files matched your search

+22 -8
View File
@@ -4,7 +4,7 @@ from sqlalchemy import and_, desc, asc, func, extract
from pydantic import BaseModel, Field
from typing import Optional
import uuid
from datetime import datetime, date, timedelta
from datetime import datetime, date, timedelta, timezone
from ..database import get_db
from ..models import (
@@ -16,6 +16,9 @@ from ..middleware.log_service import LogService
router = APIRouter()
# CST timezone (UTC+8)
CST_TZ = timezone(timedelta(hours=8))
class RechargeRequest(BaseModel):
amount: int = Field(ge=1)
@@ -32,12 +35,15 @@ def get_overview(
TokenUsageLog.user_id == current_user.id
).scalar()
# 今日使用中应用数
today_start = datetime.combine(date.today(), datetime.min.time())
# 今日使用中应用数 - 使用CST时区的"今天"
now_cst = datetime.now(CST_TZ)
today_start = now_cst.replace(hour=0, minute=0, second=0, microsecond=0)
# Convert to UTC for DB comparison since container uses UTC timestamps
today_start_utc = today_start.astimezone(timezone.utc).replace(tzinfo=None)
today_apps = db.query(func.count(func.distinct(TokenUsageLog.model_id))).filter(
and_(
TokenUsageLog.user_id == current_user.id,
TokenUsageLog.created_at >= today_start,
TokenUsageLog.created_at >= today_start_utc,
)
).scalar() or 0
@@ -46,9 +52,7 @@ def get_overview(
TokenBalance.user_id == current_user.id
).first()
from datetime import timezone, timedelta
shanghai_tz = timezone(timedelta(hours=8))
server_time = datetime.now(shanghai_tz).isoformat()
server_time = datetime.now(CST_TZ).isoformat()
return {
"code": 0,
@@ -169,7 +173,7 @@ def get_token_logs(
"completion_tokens": log_item.completion_tokens or 0,
"total_tokens": log_item.total_tokens or 0,
"conversation_id": log_item.conversation_id,
"created_at": log_item.created_at.isoformat() if log_item.created_at else None,
"created_at": _format_cst_time(log_item.created_at),
})
return {
@@ -245,3 +249,13 @@ def recharge(
},
"message": "充值成功",
}
def _format_cst_time(dt_value):
"""Format datetime to CST ISO string. Input is UTC naive datetime from DB."""
if dt_value is None:
return None
# DB stores UTC naive datetime, convert to CST
utc_dt = dt_value.replace(tzinfo=timezone.utc)
cst_dt = utc_dt.astimezone(CST_TZ)
return cst_dt.isoformat()