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)):
|
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:
|
if existing_account:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail="账号已存在"
|
detail="用户名已存在"
|
||||||
)
|
)
|
||||||
|
|
||||||
return AccountService.create_account(db, account)
|
return AccountService.create_account(db, account)
|
||||||
@@ -34,8 +34,8 @@ def get_account(request: AccountGetRequest, db: Session = Depends(get_db)):
|
|||||||
accounts = AccountService.search_accounts(
|
accounts = AccountService.search_accounts(
|
||||||
db,
|
db,
|
||||||
account_id=request.account_id,
|
account_id=request.account_id,
|
||||||
account=request.account,
|
username=request.username,
|
||||||
section=request.section,
|
project_name=request.project_name,
|
||||||
status=request.status,
|
status=request.status,
|
||||||
today_updated=request.today_updated
|
today_updated=request.today_updated
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ class Account(Base):
|
|||||||
__tablename__ = "accounts"
|
__tablename__ = "accounts"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
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="密码")
|
password = Column(String(100), nullable=False, comment="密码")
|
||||||
status = Column(Integer, default=1, comment="状态: 1-正常, 0-禁用")
|
status = Column(Integer, default=1, comment="状态: 1-正常, 0-禁用")
|
||||||
today_updated = Column(Integer, default=0, comment="是否更新")
|
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="创建时间")
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=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
|
from datetime import datetime
|
||||||
|
|
||||||
class AccountBase(BaseModel):
|
class AccountBase(BaseModel):
|
||||||
account: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
status: Optional[int] = 1
|
status: Optional[int] = 1
|
||||||
today_updated: Optional[int] = 0
|
today_updated: Optional[int] = 0
|
||||||
section: Optional[str] = None
|
project_name: Optional[str] = None
|
||||||
|
|
||||||
class AccountCreate(AccountBase):
|
class AccountCreate(AccountBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class AccountUpdate(BaseModel):
|
class AccountUpdate(BaseModel):
|
||||||
account: Optional[str] = None
|
username: Optional[str] = None
|
||||||
password: Optional[str] = None
|
password: Optional[str] = None
|
||||||
status: Optional[int] = None
|
status: Optional[int] = None
|
||||||
today_updated: Optional[int] = None
|
today_updated: Optional[int] = None
|
||||||
section: Optional[str] = None
|
project_name: Optional[str] = None
|
||||||
|
|
||||||
class AccountResponse(AccountBase):
|
class AccountResponse(AccountBase):
|
||||||
id: int
|
id: int
|
||||||
@@ -33,8 +33,8 @@ class AccountListRequest(BaseModel):
|
|||||||
|
|
||||||
class AccountGetRequest(BaseModel):
|
class AccountGetRequest(BaseModel):
|
||||||
account_id: Optional[int] = None
|
account_id: Optional[int] = None
|
||||||
account: Optional[str] = None
|
username: Optional[str] = None
|
||||||
section: Optional[str] = None
|
project_name: Optional[str] = None
|
||||||
status: Optional[int] = None
|
status: Optional[int] = None
|
||||||
today_updated: Optional[int] = None
|
today_updated: Optional[int] = None
|
||||||
|
|
||||||
|
|||||||
@@ -15,17 +15,17 @@ class AccountService:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def search_accounts(db: Session, account_id: Optional[int] = None,
|
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]:
|
status: Optional[int] = None, today_updated: Optional[int] = None) -> List[Account]:
|
||||||
"""根据多种条件搜索账号"""
|
"""根据多种条件搜索账号"""
|
||||||
query = db.query(Account)
|
query = db.query(Account)
|
||||||
|
|
||||||
if account_id is not None:
|
if account_id is not None:
|
||||||
query = query.filter(Account.id == account_id)
|
query = query.filter(Account.id == account_id)
|
||||||
if account is not None:
|
if username is not None:
|
||||||
query = query.filter(Account.account.like(f"%{account}%"))
|
query = query.filter(Account.username.like(f"%{username}%"))
|
||||||
if section is not None:
|
if project_name is not None:
|
||||||
query = query.filter(Account.section.like(f"%{section}%"))
|
query = query.filter(Account.project_name.like(f"%{project_name}%"))
|
||||||
if status is not None:
|
if status is not None:
|
||||||
query = query.filter(Account.status == status)
|
query = query.filter(Account.status == status)
|
||||||
if today_updated is not None:
|
if today_updated is not None:
|
||||||
@@ -39,9 +39,9 @@ class AccountService:
|
|||||||
return db.query(Account).filter(Account.id == account_id).first()
|
return db.query(Account).filter(Account.id == account_id).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_account_by_account(db: Session, account: str) -> Optional[Account]:
|
def get_account_by_username(db: Session, username: str) -> Optional[Account]:
|
||||||
"""根据账号名获取账号"""
|
"""根据用户名获取账号"""
|
||||||
return db.query(Account).filter(Account.account == account).first()
|
return db.query(Account).filter(Account.username == username).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_accounts(db: Session, skip: int = 0, limit: int = 100) -> List[Account]:
|
def get_accounts(db: Session, skip: int = 0, limit: int = 100) -> List[Account]:
|
||||||
|
|||||||
Reference in New Issue
Block a user