| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- """
- 历史记录工具函数(客户端后端仅保留会话/配置/nonce 相关)
- """
- from datetime import datetime
- from app.utils.timezone import beijing_now_naive
- from sqlalchemy.orm import Session as DBSession
- from app.models import (
- Session as SessionModel,
- SessionHis,
- SteamAccount,
- SteamAccountHis,
- SystemConfig,
- SystemConfigHis,
- APINonce,
- APINonceHis,
- )
- def create_session_history(
- db: DBSession,
- session: SessionModel,
- operation: str,
- expires_at_before: datetime = None,
- ):
- """创建会话历史记录
- Args:
- db: 数据库会话
- session: 会话对象
- operation: 操作类型 (INSERT/UPDATE/DELETE/RENEW)
- expires_at_before: RENEW操作时,记录续期前的过期时间
- """
- his_record = SessionHis(
- id=session.id,
- session_id=session.session_id,
- user_id=session.user_id,
- machine_code=session.machine_code,
- is_active=session.is_active,
- expires_at=session.expires_at,
- created_at=session.created_at,
- updated_at=session.updated_at,
- his_created_at=beijing_now_naive(),
- his_operation=operation,
- )
- db.add(his_record)
- def create_steam_account_history(db: DBSession, steam_account: SteamAccount, operation: str):
- """创建Steam账号历史记录(先写 his 再改/删时调用)"""
- his_record = SteamAccountHis(
- id=steam_account.id,
- user_id=steam_account.user_id,
- steam_username=steam_account.steam_username,
- steam_id=steam_account.steam_id,
- is_active=steam_account.is_active,
- is_deleted=steam_account.is_deleted,
- created_at=steam_account.created_at,
- updated_at=steam_account.updated_at,
- his_created_at=beijing_now_naive(),
- his_operation=operation,
- )
- db.add(his_record)
- def create_system_config_history(db: DBSession, system_config: SystemConfig, operation: str):
- """创建系统配置历史记录"""
- his_record = SystemConfigHis(
- id=system_config.id,
- config_key=system_config.config_key,
- config_value=system_config.config_value,
- config_type=system_config.config_type,
- app_name=system_config.app_name,
- description=system_config.description,
- is_system=system_config.is_system,
- is_editable=system_config.is_editable,
- is_deleted=system_config.is_deleted,
- created_at=system_config.created_at,
- updated_at=system_config.updated_at,
- his_created_at=beijing_now_naive(),
- his_operation=operation,
- )
- db.add(his_record)
- def create_api_nonce_history(db: DBSession, api_nonce: APINonce, operation: str):
- """创建API Nonce历史记录"""
- his_record = APINonceHis(
- id=api_nonce.id,
- nonce=api_nonce.nonce,
- endpoint=api_nonce.endpoint,
- session_id=api_nonce.session_id,
- created_at=api_nonce.created_at,
- expires_at=api_nonce.expires_at,
- his_created_at=beijing_now_naive(),
- his_operation=operation,
- )
- db.add(his_record)
|