- 调整单金额恒正:schema 正则拦格式(非负两位小数、≤12 位整数防 NUMERIC(14,2) 溢出)+ 服务层 Decimal>0 语义校验——负数会反转补发/ 扣减语义,'abc' 原样入库会以 500 暴露 - 分界天数参数解析:int(parse_fraction(...)) 替代 int(参数原文)—— '360.0' 是 INT 参数的合法入库值(Fraction 分母为 1),直接 int(str) 抛 ValueError 会让整月核算 500 - logo 旧文件清理容错:OSError 只记 warning——裸抛会把成功的 logo 更新 记成失败审计并 500(库中 logo_path 却已是新值,审计与事实相反) - health_check.sh:Redis 探活改容器内环境变量展开(密码不进宿主进程 命令行,模式同 backup_full.sh);compose redis 补 REDIS_PASSWORD - restore_drill.sh:行数核对扩到全部 32 张业务表(原 16 张漏 V7 四表、 二次分配等核心表,备份漏表演练全绿);查询失败回显 '?' 一律判 ✗ (原 '?'=='?' 判一致,表缺失时误报「备份可恢复」) - 并入 88 会话的 #12 实现:manager.personal.included 开关消费 (_build_manager_aggregates 参数化,测试见 828b573) - 测试:调整单金额恒正 5 稿、INT 参数小数原文核算 200 回归;单测 469 Co-Authored-By: Claude Code <noreply@anthropic.com>
96 lines
2.7 KiB
Python
96 lines
2.7 KiB
Python
"""月度结算的请求/响应模型(M3 ④)。"""
|
||
|
||
import re
|
||
from datetime import datetime
|
||
from decimal import Decimal
|
||
|
||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||
|
||
from app.core.response import PageQuery
|
||
|
||
_MONTH_RE = re.compile(r"^\d{4}-\d{2}$")
|
||
|
||
|
||
def _check_month(value: str) -> str:
|
||
"""月份格式 YYYY-MM(settlement_month 全表唯一的维度)。"""
|
||
if not _MONTH_RE.match(value):
|
||
raise ValueError("月份格式须为 YYYY-MM")
|
||
return value
|
||
|
||
|
||
class SettlementGenerateIn(BaseModel):
|
||
"""月结生成入参。"""
|
||
|
||
month: str = Field(description="结算月份 YYYY-MM")
|
||
|
||
@field_validator("month")
|
||
@classmethod
|
||
def _v_month(cls, value: str) -> str:
|
||
return _check_month(value)
|
||
|
||
|
||
class SettlementQuery(PageQuery):
|
||
"""月结列表查询。"""
|
||
|
||
status: int | None = Field(default=None, ge=1, le=4, description="状态筛选")
|
||
|
||
|
||
class SettlementItemOut(BaseModel):
|
||
"""月结明细行。"""
|
||
|
||
model_config = ConfigDict(from_attributes=True)
|
||
|
||
id: int
|
||
personnel_id: int
|
||
personnel_name: str
|
||
role_code: str
|
||
calc_type: int
|
||
performance_sum: Decimal
|
||
payable_sum: Decimal
|
||
basic_amount: Decimal | None = None
|
||
salary_mode: str | None = None
|
||
net_amount: Decimal | None = None
|
||
is_probation: int
|
||
probation_note: str | None = None
|
||
|
||
|
||
class SettlementOut(BaseModel):
|
||
"""月结头表响应。"""
|
||
|
||
model_config = ConfigDict(from_attributes=True)
|
||
|
||
id: int
|
||
settlement_month: str
|
||
status: int
|
||
total_performance: Decimal | None = None
|
||
total_payable: Decimal | None = None
|
||
person_count: int
|
||
approval_order_no: str | None = None
|
||
submitter_name: str
|
||
locked_at: datetime | datetime | None = None
|
||
locked_by: str | None = None
|
||
create_time: datetime
|
||
|
||
|
||
class SettlementDetailOut(SettlementOut):
|
||
"""月结详情:附明细。"""
|
||
|
||
items: list[SettlementItemOut] = Field(default_factory=list)
|
||
|
||
|
||
class AdjustmentCreateIn(BaseModel):
|
||
"""调整单创建入参(金额恒正,方向表达补发/扣减)。"""
|
||
|
||
model_config = ConfigDict(str_strip_whitespace=True)
|
||
|
||
settlement_month: str = Field(description="调整月份 YYYY-MM")
|
||
personnel_id: int = Field(ge=1, description="调整人员ID")
|
||
direction: int = Field(ge=1, le=2, description="1补发 2扣减")
|
||
# 正则先拦格式(非负两位小数、≤12 位整数防 NUMERIC(14,2) 溢出);
|
||
# 「> 0」由服务层判定(schema 只管形状,语义校验留在 service)
|
||
amount: str = Field(
|
||
pattern=r"^\d{1,12}(\.\d{1,2})?$",
|
||
description="金额(元,两位小数,恒正)",
|
||
)
|
||
reason: str = Field(min_length=1, max_length=255, description="扣补说明")
|