docker,字段更改
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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="更新时间")
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user