refactor(business): 编辑出参取校验返回值省重查,submit_change 批量预载
- update_receipt 取 _ensure_shipment_of_business 返回值组装出参 (shipment_id 已赋为 payload 新值,与 get_with_refs 重查同源), 省一次三表 join;update_shipment 同理取锁定行的 business_no - 删 business_repository.count_items(无任何调用的死代码,删除保护 实际走 has_docs) - submit_change 校验段定义与岗位各一条 IN 批量预载(逐条查询在批次 扩大时是写侧 N+1);岗位字典键 casefold 归一保持与单条版 ci 校对 等价的命中语义;旧值留痕保持逐条(窗口函数优化留待 M3 一并设计) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
5ef48abf47
commit
409e26614f
6 files changed
+57
-19
No files matched your search
@@ -197,18 +197,6 @@ def replace_items(session: Session, business_id: int, rows: list[BusinessItem])
|
||||
session.flush()
|
||||
|
||||
|
||||
def count_items(session: Session, business_ids: list[int]) -> dict[int, int]:
|
||||
"""业务明细行数(删除保护备用)。"""
|
||||
if not business_ids:
|
||||
return {}
|
||||
rows = session.execute(
|
||||
select(BusinessItem.business_id, func.count())
|
||||
.where(BusinessItem.business_id.in_(business_ids))
|
||||
.group_by(BusinessItem.business_id)
|
||||
).all()
|
||||
return dict(rows)
|
||||
|
||||
|
||||
def add_status_log(session: Session, log: BusinessStatusLog) -> None:
|
||||
"""追加状态留痕(不 commit)。"""
|
||||
session.add(log)
|
||||
|
||||
@@ -25,6 +25,20 @@ def get_by_code(session: Session, role_code: str) -> BusinessRole | None:
|
||||
return session.execute(stmt).scalar_one_or_none()
|
||||
|
||||
|
||||
def list_by_codes(session: Session, role_codes: list[str]) -> dict[str, BusinessRole]:
|
||||
"""按编码批量取岗位(参数批次校验段用,消除逐条 N+1)。
|
||||
|
||||
返回 {编码: 岗位}。MySQL ci 校对下编码大小写变形也能命中,
|
||||
键取库里的规范 role_code,调用方据此把维度值归一为规范值。
|
||||
"""
|
||||
if not role_codes:
|
||||
return {}
|
||||
rows = session.execute(
|
||||
select(BusinessRole).where(BusinessRole.role_code.in_(role_codes))
|
||||
).scalars()
|
||||
return {role.role_code: role for role in rows}
|
||||
|
||||
|
||||
def list_roles(
|
||||
session: Session,
|
||||
*,
|
||||
|
||||
@@ -81,6 +81,21 @@ def get_definition_by_code(session: Session, param_code: str) -> ParamDefinition
|
||||
return session.execute(stmt).scalar_one_or_none()
|
||||
|
||||
|
||||
def list_definitions_by_codes(
|
||||
session: Session, param_codes: list[str]
|
||||
) -> dict[str, ParamDefinition]:
|
||||
"""按编码批量取参数定义(提交批次的校验段用,消除逐条 N+1)。
|
||||
|
||||
返回 {编码: 定义};未定义的编码不在结果中,由调用方判缺失。
|
||||
"""
|
||||
if not param_codes:
|
||||
return {}
|
||||
rows = session.execute(
|
||||
select(ParamDefinition).where(ParamDefinition.param_code.in_(param_codes))
|
||||
).scalars()
|
||||
return {definition.param_code: definition for definition in rows}
|
||||
|
||||
|
||||
def list_history(
|
||||
session: Session,
|
||||
param_id: int,
|
||||
|
||||
Reference in new issue
Block a user