Feat: 后端新增基础资料与业务管理只读汇总接口

为 Web 端改版提供名称、统计和看板数据。只新增只读查询、扩展列表与详情
返回字段;写接口、托盘状态机和幂等键规则均未改动,未新增权限标识。

- 基础资料:列表补充名称与汇总,客户详情返回现场树,托盘详情返回最近流转,
  托盘列表支持按流转阶段筛选和二维码精确匹配;新增现场、产线、隧道的上级
  资料选项接口;Excel 导入支持 preview 只校验不写入
- 发货出库:列表支持 keyword、receiptState 筛选并补充名称、托盘数、包数和
  菌种构成;详情明细补充托盘号、菌种、批次
- 首次入库:列表与详情补充名称、托盘数、托盘当前状态;新增 /summary
- 托盘退回:列表支持 keyword 并补充名称与托盘汇总,详情补充托盘号和隧道;
  新增 /summary、/site-options
- 工厂装填:列表支持 keyword 并补充托盘号、仓库、操作人;新增 /summary、
  /batches、/batches/detail
- 客户现场使用:列表支持 keyword、fifoSkipped 并补充名称和被跳过的先到托盘号;
  新增 /site-options、/site-board 以及 usage-fifo 的 /queue
- 先到先用 DAO 抽出公共候选条件与排序,建议查询生成的 SQL 与改动前一致
- 新增各汇总 DAO 的单元测试,同步更新路由权限与模型字段契约测试

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-18 05:03:10 -07:00
co-authored by Claude Opus 5.5
parent 80a71b48ce
commit 3050ccdc4e
51 changed files with 6545 additions and 103 deletions
@@ -14,6 +14,8 @@ from module_business.dao.access_dao import AccessDao
from module_business.dao.inventory_dao import InventoryDao
from module_business.dao.master_dao import MasterDao
from module_business.dao.operation_dao import OperationDao
from module_business.dao.shipment_label_dao import ShipmentLabelDao
from module_business.dao.shipment_summary_dao import ShipmentSummaryDao
from module_business.domain.enums import DocumentStatus, PalletEventType, PalletFlowState
from module_business.domain.pallet_state_machine import PalletStateMachine
from module_business.domain.test_batch_scope import TestBatchScope, assert_record_in_scope
@@ -31,6 +33,7 @@ from module_business.entity.vo.operation_vo import (
ConfirmCommandModel,
PalletScanResponseModel,
ShipmentCreateModel,
ShipmentListItemModel,
ShipmentModel,
ShipmentPageQueryModel,
ShipmentScanQueryModel,
@@ -254,7 +257,7 @@ class ShipmentService:
current_user: CurrentUserModel,
test_scope: TestBatchScope,
is_page: bool = True,
) -> PageModel | list[ShipmentModel]:
) -> PageModel | list[ShipmentListItemModel]:
warehouse_ids, site_ids = await cls._scopes(query_db, current_user)
if (
warehouse_ids is not None
@@ -288,7 +291,17 @@ class ShipmentService:
is_page=is_page,
)
rows = result.rows if isinstance(result, PageModel) else result
models = [ShipmentModel.model_validate(record) for record in rows]
records = [ShipmentModel.model_validate(record) for record in rows]
# 仅对本页已按数据范围筛出的单据补充名称与汇总
summaries = await ShipmentSummaryDao.get_list_summaries(
query_db,
[record.shipment_id for record in records],
test_scope,
)
models = [
ShipmentListItemModel.model_validate({**record.model_dump(), **summaries.get(record.shipment_id, {})})
for record in records
]
if isinstance(result, PageModel):
return result.model_copy(update={'rows': models})
return models
@@ -311,7 +324,35 @@ class ShipmentService:
)
if shipment is None:
cls._raise_shipment_not_accessible(current_user)
return ShipmentModel.model_validate(shipment)
model = ShipmentModel.model_validate(shipment)
identities = await cls._item_identities(query_db, shipment, test_scope)
if not identities:
return model
return model.model_copy(
update={
'items': [
item.model_copy(update=identities.get(item.shipment_item_id, {}))
for item in model.items
]
}
)
@staticmethod
async def _item_identities(
query_db: AsyncSession,
shipment: BizShipmentOrder,
test_scope: TestBatchScope,
) -> dict[int, dict[str, str | None]]:
"""为详情明细补充托盘编号与菌种批次,只读展示,不参与任何写入或数量计算。"""
identities: dict[int, dict[str, str | None]] = {}
for item, pallet, filling, _quantity in await ShipmentLabelDao.get_label_sources(query_db, shipment, test_scope):
identities[item.shipment_item_id] = {
'pallet_code': getattr(pallet, 'pallet_code', None),
'strain_code': getattr(filling, 'strain_code_snapshot', None),
'strain_name': getattr(filling, 'strain_name_snapshot', None),
'batch_no': getattr(filling, 'batch_no', None),
}
return identities
@classmethod
async def get_warehouse_options_services(