feat:添加报告模板及审核页面类型字段

master
HuangHuiKang 1 day ago
parent 9b071f2e74
commit 98ebb12741

@ -21,6 +21,7 @@ class EnergyReportReviewModel(ModelMixin, TenantMixin, UserMixin):
]
task_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="任务名称", index=True)
report_type: Mapped[int] = mapped_column(Integer, default=1, nullable=False, comment="报告类型 1:能源报告 2:光伏报告", index=True)
template_id: Mapped[int] = mapped_column(
Integer,
ForeignKey("energy_report_template.id", ondelete="RESTRICT", onupdate="CASCADE"),

@ -15,6 +15,7 @@ class EnergyReportReviewCreateSchema(BaseModel):
"""能源报告审核任务创建模型。"""
task_name: str = Field(..., min_length=1, max_length=128, description="任务名称")
report_type: int = Field(default=1, ge=1, le=2, description="报告类型 1:能源报告 2:光伏报告")
template_id: int = Field(..., ge=1, description="能源报告模板ID")
file_id: int = Field(..., ge=1, description="上传文档文件ID")
attachment_file_id: int | None = Field(default=None, ge=1, description="附件文件ID")
@ -37,6 +38,13 @@ class EnergyReportReviewCreateSchema(BaseModel):
raise ValueError("状态仅支持 0(待审查)、1(审核通过)、2(审核不通过)")
return value
@field_validator("report_type")
@classmethod
def validate_report_type(cls, value: int) -> int:
if value not in {1, 2}:
raise ValueError("报告类型仅支持 1(能源报告) 或 2(光伏报告)")
return value
class EnergyReportReviewUpdateSchema(EnergyReportReviewCreateSchema):
"""能源报告审核任务更新模型。"""
@ -84,6 +92,7 @@ class EnergyReportReviewQueryParam(BaseQueryParam, UserByQueryParam, TenantByQue
"""能源报告审核任务查询参数。"""
task_name: str | None = Query(None, description="任务名称")
report_type: int | None = Query(None, ge=1, le=2, description="报告类型 1:能源报告 2:光伏报告")
status: int | None = Query(None, ge=0, le=2, description="状态 0:待审查 1:审核通过 2:审核不通过")
template_id: int | None = Query(None, ge=1, description="模板ID")
reviewer_id: int | None = Query(None, ge=1, description="审查人ID")
@ -91,6 +100,8 @@ class EnergyReportReviewQueryParam(BaseQueryParam, UserByQueryParam, TenantByQue
def __post_init__(self) -> None:
if self.task_name:
self.task_name = (QueueEnum.like.value, self.task_name)
if isinstance(self.report_type, int):
self.report_type = (QueueEnum.eq.value, self.report_type)
if isinstance(self.status, int):
self.status = (QueueEnum.eq.value, self.status)
if isinstance(self.template_id, int):

@ -65,7 +65,7 @@ class EnergyReportReviewService:
}
async def create(self, data: EnergyReportReviewCreateSchema) -> EnergyReportReviewOutSchema:
await self._validate_template(template_id=data.template_id)
await self._validate_template(template_id=data.template_id, report_type=data.report_type)
await self._validate_file(file_id=data.file_id)
attachment_file = await self._validate_attachment_file(
attachment_file_id=data.attachment_file_id,
@ -88,7 +88,7 @@ class EnergyReportReviewService:
async def update(self, id: int, data: EnergyReportReviewUpdateSchema) -> EnergyReportReviewOutSchema:
old_review = await EnergyReportReviewCRUD(self.auth).get_or_404(id=id, msg="更新失败,能源报告审核任务不存在")
await self._validate_template(template_id=data.template_id)
await self._validate_template(template_id=data.template_id, report_type=data.report_type)
await self._validate_file(file_id=data.file_id, current_review_id=id)
if old_review.attachment_file_id and old_review.attachment_file_id == data.file_id:
raise CustomException(msg="更新失败,上传文档不能使用原附件文件")
@ -166,10 +166,12 @@ class EnergyReportReviewService:
item["reviewer_name"] = reviewer_info.get("name")
return item
async def _validate_template(self, template_id: int) -> None:
async def _validate_template(self, template_id: int, report_type: int) -> None:
template = await EnergyReportTemplateCRUD(self.auth).get(id=template_id)
if not template:
raise CustomException(msg="能源报告模板不存在")
if template.report_type != report_type:
raise CustomException(msg="报告类型与模板类型不一致")
async def _validate_file(self, file_id: int, current_review_id: int | None = None) -> None:
file_record = await FileCRUD(self.auth).get(id=file_id)

@ -18,6 +18,7 @@ class EnergyReportTemplateModel(ModelMixin, TenantMixin, UserMixin):
]
template_name: Mapped[str] = mapped_column(String(128), nullable=False, comment="模板名称", index=True)
report_type: Mapped[int] = mapped_column(Integer, default=1, nullable=False, comment="报告类型 1:能源报告 2:光伏报告", index=True)
template_type: Mapped[str] = mapped_column(String(64), nullable=False, comment="模板类型", index=True)
version: Mapped[str | None] = mapped_column(String(32), default=None, nullable=True, comment="模板版本")
file_id: Mapped[int] = mapped_column(

@ -13,6 +13,7 @@ class EnergyReportTemplateCreateSchema(BaseModel):
"""能源报告模板创建模型。"""
template_name: str = Field(..., min_length=1, max_length=128, description="模板名称")
report_type: int = Field(default=1, ge=1, le=2, description="报告类型 1:能源报告 2:光伏报告")
template_type: str = Field(default="", max_length=64, description="模板类型")
version: str | None = Field(default=None, max_length=32, description="模板版本")
file_id: int = Field(..., ge=1, description="文件记录ID")
@ -35,6 +36,13 @@ class EnergyReportTemplateCreateSchema(BaseModel):
raise ValueError("状态仅支持 0(启用) 或 1(停用)")
return value
@field_validator("report_type")
@classmethod
def validate_report_type(cls, value: int) -> int:
if value not in {1, 2}:
raise ValueError("报告类型仅支持 1(能源报告) 或 2(光伏报告)")
return value
class EnergyReportTemplateUpdateSchema(EnergyReportTemplateCreateSchema):
"""能源报告模板更新模型。"""
@ -57,6 +65,7 @@ class EnergyReportTemplateQueryParam(BaseQueryParam, UserByQueryParam, TenantByQ
"""能源报告模板查询参数。"""
template_name: str | None = Query(None, description="模板名称")
report_type: int | None = Query(None, ge=1, le=2, description="报告类型 1:能源报告 2:光伏报告")
template_type: str | None = Query(None, description="模板类型")
version: str | None = Query(None, description="模板版本")
status: int | None = Query(None, ge=0, le=1, description="状态 0:启用 1:停用")
@ -64,6 +73,8 @@ class EnergyReportTemplateQueryParam(BaseQueryParam, UserByQueryParam, TenantByQ
def __post_init__(self) -> None:
if self.template_name:
self.template_name = (QueueEnum.like.value, self.template_name)
if isinstance(self.report_type, int):
self.report_type = (QueueEnum.eq.value, self.report_type)
if self.template_type:
self.template_type = (QueueEnum.eq.value, self.template_type)
if self.version:

Loading…
Cancel
Save