Unify all timestamps to Beijing time (UTC+8)

- Add BEIJING_TZ constant in config.py
- Replace all timezone.utc references across 11 files
- Device-reported times, DB defaults, protocol sync all use Beijing time

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
This commit is contained in:
2026-03-24 05:25:31 +00:00
parent 11281e5be2
commit ced836179c
11 changed files with 70 additions and 47 deletions

View File

@@ -3,7 +3,9 @@ Device Service - 设备管理服务
Provides CRUD operations and statistics for badge devices.
"""
from datetime import datetime, timezone
from datetime import datetime
from app.config import BEIJING_TZ
from sqlalchemy import func, select, or_
from sqlalchemy.ext.asyncio import AsyncSession
@@ -158,7 +160,7 @@ async def update_device(
for field, value in update_fields.items():
setattr(device, field, value)
device.updated_at = datetime.now(timezone.utc)
device.updated_at = datetime.now(BEIJING_TZ)
await db.flush()
await db.refresh(device)
return device
@@ -245,7 +247,7 @@ async def batch_update_devices(
devices = await get_devices_by_ids(db, device_ids)
found_map = {d.id: d for d in devices}
update_fields = update_data.model_dump(exclude_unset=True)
now = datetime.now(timezone.utc)
now = datetime.now(BEIJING_TZ)
results = []
for device_id in device_ids: