前后端交互完成
This commit is contained in:
@ -41,3 +41,21 @@ class ProjectImage(DbCommon):
|
||||
image_url: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
thumb_image_url: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
project_id: Mapped[int] = mapped_column(Integer)
|
||||
|
||||
|
||||
class ProjectImgLeafer(DbCommon):
|
||||
"""项目图片leafer表"""
|
||||
__tablename__ = "project_img_leafer"
|
||||
image_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
leafer: Mapped[dict] = mapped_column(JSON)
|
||||
|
||||
|
||||
class ProjectImgLabel(DbCommon):
|
||||
"""项目图片标签对应表,一张图片对应多个label"""
|
||||
__tablename__ = "project_img_label"
|
||||
image_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
label_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
mark_center_x: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
mark_center_y: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
mark_width: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
mark_height: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
|
@ -27,8 +27,7 @@ def add_image(image: ProjectImage, session: Session):
|
||||
|
||||
|
||||
def add_image_batch(images: List[ProjectImage], session: Session):
|
||||
for image in images:
|
||||
session.add(image)
|
||||
session.add_all(images)
|
||||
session.commit()
|
||||
|
||||
|
||||
|
32
app/model/crud/project_img_leafer_label_crud.py
Normal file
32
app/model/crud/project_img_leafer_label_crud.py
Normal file
@ -0,0 +1,32 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from app.model.bussiness_model import ProjectImgLeafer
|
||||
from app.model.bussiness_model import ProjectImgLabel
|
||||
|
||||
|
||||
def get_img_leafer(image_id: int, session: Session):
|
||||
"""
|
||||
根据图片id查询图片的leafer信息
|
||||
:param image_id:
|
||||
:param session:
|
||||
:return:
|
||||
"""
|
||||
img_leafer = session.query(ProjectImgLeafer).filter_by(image_id=image_id).first()
|
||||
return img_leafer
|
||||
|
||||
|
||||
def save_img_leafer(leafer: ProjectImgLeafer, session: Session):
|
||||
leafer_saved = session.query(ProjectImgLeafer).filter_by(image_id=leafer.image_id).first()
|
||||
if leafer_saved is not None:
|
||||
session.delete(leafer_saved)
|
||||
session.add(leafer)
|
||||
session.commit()
|
||||
return leafer
|
||||
|
||||
|
||||
def save_img_label_batch(image_id: int, img_labels: List[ProjectImgLabel], session: Session):
|
||||
session.query(ProjectImgLabel).filter_by(image_id=image_id).delete()
|
||||
session.add_all(img_labels)
|
||||
session.commit()
|
||||
return len(img_labels)
|
@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class ProjectImage(BaseModel):
|
||||
@ -16,3 +16,25 @@ class ProjectImagePager(BaseModel):
|
||||
project_id: Optional[int] = Field(..., description="项目id")
|
||||
pagerNum: Optional[int] = Field(1, description="当前页码")
|
||||
pagerSize: Optional[int] = Field(10, description="每页数量")
|
||||
|
||||
|
||||
class ProjectImgLabelIn(BaseModel):
|
||||
label_id: int
|
||||
mark_center_x: str
|
||||
mark_center_y: str
|
||||
mark_width: str
|
||||
mark_height: str
|
||||
|
||||
|
||||
class ProjectImgLeaferLabel(BaseModel):
|
||||
image_id: Optional[int] = Field(..., description="图片id")
|
||||
leafer: Optional[dict] = Field(..., description="保存的leafer")
|
||||
label_infos: List[ProjectImgLabelIn] = Field(..., description="标签框选信息")
|
||||
|
||||
|
||||
class ProjectImgLeaferOut(BaseModel):
|
||||
image_id: Optional[int] = Field(..., description="图片id")
|
||||
leafer: Optional[dict] = Field(..., description="保存的leafer")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
Reference in New Issue
Block a user