优化目前版本中的问题
This commit is contained in:
@ -45,6 +45,7 @@ class ProjectImage(DbCommon):
|
||||
项目图片表
|
||||
"""
|
||||
__tablename__ = "project_image"
|
||||
img_type: Mapped[str] = mapped_column(String(10))
|
||||
file_name: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
image_url: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
thumb_image_url: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
|
@ -33,7 +33,8 @@ def get_image_pager2(image: ProjectImage, session: Session):
|
||||
)
|
||||
.outerjoin(subquery, piModel.id == subquery.c.image_id)
|
||||
)
|
||||
query = query.filter(piModel.project_id == image.project_id).order_by(asc(piModel.id))
|
||||
query = query.filter(piModel.project_id == image.project_id)\
|
||||
.filter(piModel.img_type == image.img_type).order_by(asc(piModel.id))
|
||||
pager = get_pager(query, image.pagerNum, image.pagerSize)
|
||||
datas = []
|
||||
for result in pager.data:
|
||||
@ -44,16 +45,20 @@ def get_image_pager2(image: ProjectImage, session: Session):
|
||||
return pager
|
||||
|
||||
|
||||
def check_img_name(project_id: int, file_name: str, session: Session):
|
||||
def check_img_name(project_id: int, img_type: str, file_name: str, session: Session):
|
||||
"""
|
||||
根据项目id和文件名称进行查重
|
||||
:param project_id:
|
||||
:param img_type:
|
||||
:param file_name:
|
||||
:param session:
|
||||
:return:
|
||||
"""
|
||||
image = session.query(piModel)\
|
||||
.filter(piModel.project_id == project_id).filter(piModel.file_name == file_name).first()
|
||||
.filter(piModel.project_id == project_id)\
|
||||
.filter(piModel.file_name == file_name)\
|
||||
.filter(piModel.img_type == img_type)\
|
||||
.first()
|
||||
if image is not None:
|
||||
return False
|
||||
return True
|
||||
@ -72,17 +77,26 @@ def get_img_url(image_id: int, session: Session):
|
||||
return sour_url, thumb_url
|
||||
|
||||
|
||||
def get_image_list(project_id: int, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id).order_by(asc(piModel.id))
|
||||
def get_image_list(project_id: int, img_type: str, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id)\
|
||||
.filter(piModel.img_type == img_type)\
|
||||
.order_by(asc(piModel.id))
|
||||
image_list = [ProjectImage.from_orm(image) for image in query.all()]
|
||||
return image_list
|
||||
|
||||
|
||||
def get_images(project_id: int, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id).order_by(asc(piModel.id))
|
||||
def get_images(project_id: int, img_type: str, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id)\
|
||||
.filter(piModel.img_type == img_type).order_by(asc(piModel.id))
|
||||
return query.all()
|
||||
|
||||
|
||||
def get_image_count(project_id: int, img_type: str, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id)\
|
||||
.filter(piModel.img_type == img_type).order_by(asc(piModel.id))
|
||||
return query.count()
|
||||
|
||||
|
||||
def add_image(image: ProjectImage, session: Session):
|
||||
session.add(image)
|
||||
session.commit()
|
||||
|
@ -6,6 +6,7 @@ from typing import Optional, List
|
||||
class ProjectImage(BaseModel):
|
||||
id: Optional[int] = Field(None, description="id")
|
||||
project_id: Optional[int] = Field(..., description="项目id")
|
||||
img_type: Optional[str] = Field(None, description="图片类别")
|
||||
file_name: Optional[str] = Field(None, description="文件名称")
|
||||
create_time: Optional[datetime] = Field(None, description="上传时间")
|
||||
|
||||
@ -32,6 +33,7 @@ class ProjectImageOut(BaseModel):
|
||||
|
||||
class ProjectImagePager(BaseModel):
|
||||
project_id: Optional[int] = Field(..., description="项目id")
|
||||
img_type: Optional[str] = Field(None, description="图片类别")
|
||||
pagerNum: Optional[int] = Field(None, description="当前页码")
|
||||
pagerSize: Optional[int] = Field(None, description="每页数量")
|
||||
|
||||
|
Reference in New Issue
Block a user