fix: 剩余服务文件时间统一为北京时间
- agent_dispatcher、alert_service、report_generator、 oss_storage、work_order_service 全部使用 beijing_now() - 全局无遗留 UTC 时间调用 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,13 +11,14 @@
|
||||
"""
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import timedelta
|
||||
from typing import Dict, Optional
|
||||
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
from app.config import settings
|
||||
from app.utils.logger import logger
|
||||
from app.utils.timezone import beijing_now
|
||||
|
||||
INTENT_SYSTEM_PROMPT = """你是物业安防AI助手。根据用户消息识别意图,仅输出JSON。
|
||||
|
||||
@@ -144,7 +145,7 @@ class AgentDispatcher:
|
||||
|
||||
# 解析时间范围
|
||||
time_range = params.get("time_range", "today")
|
||||
now = datetime.now(timezone.utc)
|
||||
now = beijing_now()
|
||||
if time_range == "week":
|
||||
start = now - timedelta(days=now.weekday())
|
||||
start = start.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
处理告警 CRUD(旧版告警系统,已迁移至 alarm_event_service)
|
||||
"""
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
from app.models import Alert, AlertStatus, AlertLevel, get_session
|
||||
from app.schemas import AlertCreate, AlertHandleRequest
|
||||
from app.services.oss_storage import get_oss_storage
|
||||
from app.utils.logger import logger
|
||||
from app.utils.timezone import beijing_now
|
||||
|
||||
|
||||
class AlertService:
|
||||
@@ -20,7 +21,7 @@ class AlertService:
|
||||
|
||||
def generate_alert_no(self) -> str:
|
||||
"""生成告警编号"""
|
||||
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S")
|
||||
timestamp = beijing_now().strftime("%Y%m%d%H%M%S")
|
||||
unique_id = uuid.uuid4().hex[:8].upper()
|
||||
return f"ALT{timestamp}{unique_id}"
|
||||
|
||||
@@ -161,8 +162,8 @@ class AlertService:
|
||||
alert.status = AlertStatus(handle_data.status)
|
||||
alert.handle_remark = handle_data.remark
|
||||
alert.handled_by = handled_by
|
||||
alert.handled_at = datetime.now(timezone.utc)
|
||||
alert.updated_at = datetime.now(timezone.utc)
|
||||
alert.handled_at = beijing_now()
|
||||
alert.updated_at = beijing_now()
|
||||
|
||||
db.commit()
|
||||
db.refresh(alert)
|
||||
@@ -183,7 +184,7 @@ class AlertService:
|
||||
|
||||
alert.status = AlertStatus.DISPATCHED
|
||||
alert.work_order_id = work_order_id
|
||||
alert.updated_at = datetime.now(timezone.utc)
|
||||
alert.updated_at = beijing_now()
|
||||
|
||||
db.commit()
|
||||
db.refresh(alert)
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pathlib import Path
|
||||
|
||||
from app.config import settings
|
||||
from app.utils.logger import logger
|
||||
from app.utils.timezone import beijing_now
|
||||
|
||||
|
||||
# 按需导入 COS SDK
|
||||
@@ -148,7 +149,7 @@ def _generate_object_key(prefix: str = "", ext: str = ".jpg") -> str:
|
||||
生成对象存储 Key
|
||||
格式: {prefix}/{YYYY}/{MM}/{DD}/{YYYYMMDDHHmmss}_{uuid8}{ext}
|
||||
"""
|
||||
now = datetime.now(timezone.utc)
|
||||
now = beijing_now()
|
||||
date_path = now.strftime("%Y/%m/%d")
|
||||
timestamp = now.strftime("%Y%m%d%H%M%S")
|
||||
unique_id = uuid.uuid4().hex[:8].upper()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"""
|
||||
|
||||
import io
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import timedelta
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from openpyxl import Workbook
|
||||
@@ -13,6 +13,7 @@ from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
|
||||
|
||||
from app.models import AlarmEvent, get_session
|
||||
from app.utils.logger import logger
|
||||
from app.utils.timezone import beijing_now
|
||||
|
||||
|
||||
TYPE_NAMES = {"leave_post": "人员离岗", "intrusion": "周界入侵"}
|
||||
@@ -35,7 +36,7 @@ def generate_alarm_report(
|
||||
Returns:
|
||||
(filename, bytes_io) 或 None(无数据时)
|
||||
"""
|
||||
now = datetime.now(timezone.utc)
|
||||
now = beijing_now()
|
||||
if time_range == "today":
|
||||
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
label = now.strftime("%Y%m%d")
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional, Dict, List, Tuple
|
||||
|
||||
from app.models import WorkOrder, WorkOrderStatus, WorkOrderPriority, get_session
|
||||
from app.utils.logger import logger
|
||||
from app.utils.timezone import beijing_now
|
||||
|
||||
|
||||
def generate_order_no() -> str:
|
||||
"""生成工单编号: WO + YYYYMMDDHHmmss + 6位uuid"""
|
||||
ts = datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S")
|
||||
ts = beijing_now().strftime("%Y%m%d%H%M%S")
|
||||
return f"WO{ts}{uuid.uuid4().hex[:6].upper()}"
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class WorkOrderService:
|
||||
if result:
|
||||
order.result = result
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
now = beijing_now()
|
||||
if status == "processing" and not order.started_at:
|
||||
order.started_at = now
|
||||
elif status == "completed":
|
||||
|
||||
Reference in New Issue
Block a user