项目基础模块代码
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from app.db.db_base import DbCommon
|
||||
from sqlalchemy import String, Integer
|
||||
from sqlalchemy import String, Integer, JSON
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
@ -8,35 +8,36 @@ class ProjectType(DbCommon):
|
||||
项目类别表 - 标识项目的类型目前存在的(目标识别,OCR识别,瑕疵检测,图像分类)
|
||||
"""
|
||||
__tablename__ = "project_type"
|
||||
type_code = Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
||||
type_name = Mapped[str] = mapped_column(String(20))
|
||||
icon_path = Mapped[str] = mapped_column(String(255))
|
||||
description = Mapped[str] = mapped_column(String(255))
|
||||
type_status = Mapped[str] = mapped_column(String(10))
|
||||
type_code: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
||||
type_name: Mapped[str] = mapped_column(String(20))
|
||||
icon_path: Mapped[str] = mapped_column(String(255))
|
||||
description: Mapped[str] = mapped_column(String(255))
|
||||
type_status: Mapped[str] = mapped_column(String(10))
|
||||
|
||||
|
||||
class ProjectInfo(DbCommon):
|
||||
"""项目信息表"""
|
||||
__tablename__ = "project_info"
|
||||
project_no = Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
project_name = Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
type_code = Mapped[str] = mapped_column(String(10))
|
||||
description = Mapped[str] = mapped_column(String(255))
|
||||
project_status = Mapped[str] = mapped_column(String(10))
|
||||
user_id = Mapped[int] = mapped_column(Integer)
|
||||
train_version = Mapped[int] = mapped_column(Integer)
|
||||
project_no: Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
project_name: Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
type_code: Mapped[str] = mapped_column(String(10))
|
||||
description: Mapped[str] = mapped_column(String(255))
|
||||
project_status: Mapped[str] = mapped_column(String(10))
|
||||
user_id: Mapped[int] = mapped_column(Integer)
|
||||
train_version: Mapped[int] = mapped_column(Integer)
|
||||
|
||||
|
||||
class ProjectLabel(DbCommon):
|
||||
"""项目标签表"""
|
||||
__tablename__ = "project_label"
|
||||
label_name = Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
project_id = Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
label_name: Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
project_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
meta: Mapped[dict] = mapped_column(JSON)
|
||||
|
||||
|
||||
class ProjectImage(DbCommon):
|
||||
"""项目图片表"""
|
||||
__tablename__ = "project_image"
|
||||
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)
|
||||
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)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import asc
|
||||
from typing import List
|
||||
|
||||
from app.model.bussiness_model import ProjectImage as piModel
|
||||
from app.model.schemas.project_image_schemas import ProjectImage, ProjectImagePager
|
||||
@ -13,9 +14,9 @@ def get_image_pager(image: ProjectImagePager, session: Session):
|
||||
return pager
|
||||
|
||||
|
||||
def get_image_list(image: ProjectImage, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == image.project_id).order_by(asc(piModel.id))
|
||||
image_list = [ProjectImage.from_orm(image) for image in query.all()]
|
||||
def get_image_list(project_id: int, session: Session):
|
||||
query = session.query(piModel).filter(piModel.project_id == project_id).order_by(asc(piModel.id))
|
||||
image_list = [ProjectImage.from_orm(image).dict() for image in query.all()]
|
||||
return image_list
|
||||
|
||||
|
||||
@ -25,8 +26,14 @@ def add_image(image: ProjectImage, session: Session):
|
||||
return image
|
||||
|
||||
|
||||
def del_image(id: str, session: Session):
|
||||
row_del = session.query(piModel).filter_by(id=id).delete()
|
||||
def add_image_batch(images: List[ProjectImage], session: Session):
|
||||
for image in images:
|
||||
session.add(image)
|
||||
session.commit()
|
||||
|
||||
|
||||
def del_image(image_id: str, session: Session):
|
||||
row_del = session.query(piModel).filter_by(id=image_id).delete()
|
||||
session.commit()
|
||||
return row_del
|
||||
|
||||
|
@ -20,11 +20,12 @@ def get_project_pager(info: ProjectInfoPager, session: Session):
|
||||
return pager
|
||||
|
||||
|
||||
def get_project_by_id(id: str, session: Session):
|
||||
info = session.query(ProjectInfo).filter_by(id=id).first()
|
||||
def get_project_by_id(project_id: str, session: Session):
|
||||
info = session.query(ProjectInfo).filter_by(id=project_id).first()
|
||||
info_out = ProjectInfoOut.from_orm(info)
|
||||
return info_out
|
||||
|
||||
|
||||
def add_project(info: ProjectInfo, session: Session):
|
||||
"""新建项目,并在对应文件夹下面创建文件夹"""
|
||||
session.add(info)
|
||||
|
@ -1,4 +1,5 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import and_
|
||||
|
||||
from app.model.bussiness_model import ProjectLabel as plModel
|
||||
from app.model.schemas.project_label_schemas import ProjectLabel
|
||||
@ -12,7 +13,7 @@ def get_label_list(project_id: int, session: Session):
|
||||
:return:
|
||||
"""
|
||||
label_list = session.query(plModel).filter(plModel.project_id == project_id).all()
|
||||
label_list = [ProjectLabel.from_orm(label) for label in label_list]
|
||||
label_list = [ProjectLabel.from_orm(label).dict() for label in label_list]
|
||||
return label_list
|
||||
|
||||
|
||||
@ -41,11 +42,12 @@ def check_label_name(project_id: int, label_name: str, session: Session, label_i
|
||||
filters = [plModel.project_id == project_id, plModel.label_name == label_name]
|
||||
if label_id is not None:
|
||||
filters.append(plModel.id != label_id)
|
||||
query.filter(*filters)
|
||||
if query.count() > 0:
|
||||
return False
|
||||
else:
|
||||
query = query.filter(and_(*filters))
|
||||
count = query.count()
|
||||
if count > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def update_label(label: plModel, session: Session):
|
||||
@ -56,17 +58,19 @@ def update_label(label: plModel, session: Session):
|
||||
:return:
|
||||
"""
|
||||
session.query(plModel).filter_by(id=label.id).update({
|
||||
"label_name": label.label_name
|
||||
"label_name": label.label_name,
|
||||
"meta": label.meta
|
||||
})
|
||||
session.commit()
|
||||
|
||||
|
||||
def del_label(id: str, session: Session):
|
||||
def del_label(label_id: str, session: Session):
|
||||
"""
|
||||
根据标签id删除标签
|
||||
:param id: 标签id
|
||||
:param label_id: 标签id
|
||||
:param session:
|
||||
:return:
|
||||
"""
|
||||
row_del = session.query(plModel).filter_by(id=id).delete()
|
||||
row_del = session.query(plModel).filter_by(id=label_id).delete()
|
||||
session.commit()
|
||||
return row_del
|
||||
|
@ -13,7 +13,7 @@ def user_pager(user: SysUserPager, session: Session):
|
||||
if user.username is not None:
|
||||
filters.append(SysUser.username.ilike(f"%{user.username}%"))
|
||||
if len(filters) > 0:
|
||||
query.filter(and_(*filters))
|
||||
query = query.filter(and_(*filters))
|
||||
pager = get_pager(query, user.pagerNum, user.pagerSize)
|
||||
pager.data = [SysUserOut.from_orm(user).dict() for user in pager.data]
|
||||
return pager
|
||||
@ -26,8 +26,8 @@ def add_user(user: SysUser, session: Session):
|
||||
return user
|
||||
|
||||
|
||||
def get_user_by_id(id: int, session: Session):
|
||||
user = session.query(SysUser).filter(SysUser.id == id).first()
|
||||
def get_user_by_id(user_id: int, session: Session):
|
||||
user = session.query(SysUser).filter(SysUser.id == user_id).first()
|
||||
return user
|
||||
|
||||
|
||||
|
@ -8,6 +8,9 @@ class ProjectImage(BaseModel):
|
||||
image_url: Optional[str] = Field(..., description="原图路径")
|
||||
thumb_image_url: Optional[str] = Field(..., description="缩略图路径")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ProjectImagePager(BaseModel):
|
||||
project_id: Optional[int] = Field(..., description="项目id")
|
||||
|
@ -5,8 +5,9 @@ from typing import Optional
|
||||
class ProjectLabel(BaseModel):
|
||||
"""项目标签输入输出"""
|
||||
id: Optional[int] = Field(None, description="id")
|
||||
project_id: Optional[int] = Field(..., description="项目id")
|
||||
project_id: Optional[int] = Field(None, description="项目id")
|
||||
label_name: Optional[str] = Field(..., description="标签名称")
|
||||
meta: Optional[dict] = Field(None, description="label属性")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
Reference in New Issue
Block a user