From e6fe0fab4833a6902d786df92263b5d6a1a749cf Mon Sep 17 00:00:00 2001 From: lhx Date: Sat, 27 Sep 2025 10:23:00 +0800 Subject: [PATCH] =?UTF-8?q?docker=EF=BC=8C=E5=AD=97=E6=AE=B5=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/account.py | 8 ++++---- app/models/account.py | 4 ++-- app/schemas/account.py | 12 ++++++------ app/services/account.py | 16 ++++++++-------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/api/account.py b/app/api/account.py index 2a7f021..0ef0c10 100644 --- a/app/api/account.py +++ b/app/api/account.py @@ -14,11 +14,11 @@ router = APIRouter(prefix="/accounts", tags=["账号管理"]) def create_account(account: AccountCreate, db: Session = Depends(get_db)): """创建账号""" # 检查账号是否已存在 - existing_account = AccountService.get_account_by_account(db, account.account) + existing_account = AccountService.get_account_by_username(db, account.username) if existing_account: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail="账号已存在" + detail="用户名已存在" ) return AccountService.create_account(db, account) @@ -34,8 +34,8 @@ def get_account(request: AccountGetRequest, db: Session = Depends(get_db)): accounts = AccountService.search_accounts( db, account_id=request.account_id, - account=request.account, - section=request.section, + username=request.username, + project_name=request.project_name, status=request.status, today_updated=request.today_updated ) diff --git a/app/models/account.py b/app/models/account.py index f82082d..6302a74 100644 --- a/app/models/account.py +++ b/app/models/account.py @@ -6,10 +6,10 @@ class Account(Base): __tablename__ = "accounts" id = Column(Integer, primary_key=True, index=True, autoincrement=True) - account = Column(String(50), unique=True, index=True, nullable=False, comment="账号") + username = Column(String(50), unique=True, index=True, nullable=False, comment="用户名") password = Column(String(100), nullable=False, comment="密码") status = Column(Integer, default=1, comment="状态: 1-正常, 0-禁用") today_updated = Column(Integer, default=0, comment="是否更新") - section = Column(String(100), comment="标段") + project_name = Column(String(100), comment="项目名称") created_at = Column(DateTime, server_default=func.now(), comment="创建时间") updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间") \ No newline at end of file diff --git a/app/schemas/account.py b/app/schemas/account.py index 94fc943..29bdb43 100644 --- a/app/schemas/account.py +++ b/app/schemas/account.py @@ -3,21 +3,21 @@ from typing import Optional from datetime import datetime class AccountBase(BaseModel): - account: str + username: str password: str status: Optional[int] = 1 today_updated: Optional[int] = 0 - section: Optional[str] = None + project_name: Optional[str] = None class AccountCreate(AccountBase): pass class AccountUpdate(BaseModel): - account: Optional[str] = None + username: Optional[str] = None password: Optional[str] = None status: Optional[int] = None today_updated: Optional[int] = None - section: Optional[str] = None + project_name: Optional[str] = None class AccountResponse(AccountBase): id: int @@ -33,8 +33,8 @@ class AccountListRequest(BaseModel): class AccountGetRequest(BaseModel): account_id: Optional[int] = None - account: Optional[str] = None - section: Optional[str] = None + username: Optional[str] = None + project_name: Optional[str] = None status: Optional[int] = None today_updated: Optional[int] = None diff --git a/app/services/account.py b/app/services/account.py index fa6bd0b..aacb64b 100644 --- a/app/services/account.py +++ b/app/services/account.py @@ -15,17 +15,17 @@ class AccountService: @staticmethod def search_accounts(db: Session, account_id: Optional[int] = None, - account: Optional[str] = None, section: Optional[str] = None, + username: Optional[str] = None, project_name: Optional[str] = None, status: Optional[int] = None, today_updated: Optional[int] = None) -> List[Account]: """根据多种条件搜索账号""" query = db.query(Account) if account_id is not None: query = query.filter(Account.id == account_id) - if account is not None: - query = query.filter(Account.account.like(f"%{account}%")) - if section is not None: - query = query.filter(Account.section.like(f"%{section}%")) + if username is not None: + query = query.filter(Account.username.like(f"%{username}%")) + if project_name is not None: + query = query.filter(Account.project_name.like(f"%{project_name}%")) if status is not None: query = query.filter(Account.status == status) if today_updated is not None: @@ -39,9 +39,9 @@ class AccountService: return db.query(Account).filter(Account.id == account_id).first() @staticmethod - def get_account_by_account(db: Session, account: str) -> Optional[Account]: - """根据账号名获取账号""" - return db.query(Account).filter(Account.account == account).first() + def get_account_by_username(db: Session, username: str) -> Optional[Account]: + """根据用户名获取账号""" + return db.query(Account).filter(Account.username == username).first() @staticmethod def get_accounts(db: Session, skip: int = 0, limit: int = 100) -> List[Account]: