原始数据分表处理

This commit is contained in:
lhx
2025-10-23 10:32:48 +08:00
parent 2fdec05e86
commit 21c61cdec7
6 changed files with 385 additions and 58 deletions

View File

@@ -2,15 +2,31 @@ from sqlalchemy.orm import Session
from ..models.account import Account
from ..schemas.account import AccountCreate, AccountUpdate, AccountResponse
from typing import List, Optional
import logging
logger = logging.getLogger(__name__)
class AccountService:
@staticmethod
def create_account(db: Session, account_data: AccountCreate) -> AccountResponse:
"""创建账号"""
"""创建账号并自动创建对应的原始数据表"""
from .original_data import OriginalDataService
db_account = Account(**account_data.dict())
db.add(db_account)
db.commit()
db.refresh(db_account)
# 创建对应的原始数据表
try:
original_service = OriginalDataService()
original_service.create_table_for_account(db, db_account.id)
logger.info(f"Created original data table for account {db_account.id}")
except Exception as e:
logger.error(f"Failed to create original data table for account {db_account.id}: {str(e)}")
# 注意:这里不回滚账号创建,因为表创建失败不应该影响账号创建
# 可以稍后手动重试创建表
return AccountResponse.from_orm_account(db_account)
@staticmethod