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:
@@ -1,7 +1,7 @@
|
||||
import hashlib
|
||||
import json
|
||||
import secrets
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, NoReturn
|
||||
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
@@ -11,6 +11,7 @@ from common.vo import CrudResponseModel, PageModel
|
||||
from exceptions.exception import PermissionException, ServiceException
|
||||
from module_admin.entity.vo.user_vo import CurrentUserModel
|
||||
from module_business.dao.access_dao import AccessDao
|
||||
from module_business.dao.filling_summary_dao import FillingSummaryDao
|
||||
from module_business.dao.inventory_dao import InventoryDao
|
||||
from module_business.dao.master_dao import MasterDao
|
||||
from module_business.dao.operation_dao import OperationDao
|
||||
@@ -22,8 +23,14 @@ from module_business.entity.do.operation_do import BizFillingRecord, BizPalletEv
|
||||
from module_business.entity.vo.master_vo import StrainPageQueryModel
|
||||
from module_business.entity.vo.operation_vo import (
|
||||
BusinessOptionModel,
|
||||
FillingBatchDetailModel,
|
||||
FillingBatchDetailQueryModel,
|
||||
FillingBatchModel,
|
||||
FillingBatchPageQueryModel,
|
||||
FillingCreateModel,
|
||||
FillingListItemModel,
|
||||
FillingModel,
|
||||
FillingOverviewModel,
|
||||
FillingPageQueryModel,
|
||||
PalletScanResponseModel,
|
||||
)
|
||||
@@ -34,6 +41,9 @@ from module_business.service.test_batch_access_service import TestBatchAccessSer
|
||||
class FillingService:
|
||||
"""仓库内单托盘即时装填服务层。"""
|
||||
|
||||
# 有效期剩余不超过该天数的在仓批次视为临期
|
||||
NEAR_EXPIRY_DAYS = 14
|
||||
|
||||
@staticmethod
|
||||
def _current_identity(current_user: CurrentUserModel) -> tuple[int, str]:
|
||||
user = current_user.user
|
||||
@@ -187,7 +197,7 @@ class FillingService:
|
||||
current_user: CurrentUserModel,
|
||||
test_scope: TestBatchScope,
|
||||
is_page: bool = True,
|
||||
) -> PageModel | list[FillingModel]:
|
||||
) -> PageModel | list[FillingListItemModel]:
|
||||
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
|
||||
if (
|
||||
warehouse_ids is not None
|
||||
@@ -203,11 +213,81 @@ class FillingService:
|
||||
is_page=is_page,
|
||||
)
|
||||
rows = result.rows if isinstance(result, PageModel) else result
|
||||
models = [FillingModel.model_validate(record) for record in rows]
|
||||
records = [FillingModel.model_validate(record) for record in rows]
|
||||
# 仅对本页已按数据范围筛出的记录补充托盘编号、仓库与操作人名称
|
||||
summaries = await FillingSummaryDao.get_list_summaries(
|
||||
query_db,
|
||||
[record.filling_id for record in records],
|
||||
test_scope,
|
||||
)
|
||||
models = [
|
||||
FillingListItemModel.model_validate({**record.model_dump(), **summaries.get(record.filling_id, {})})
|
||||
for record in records
|
||||
]
|
||||
if isinstance(result, PageModel):
|
||||
return result.model_copy(update={'rows': models})
|
||||
return models
|
||||
|
||||
@classmethod
|
||||
async def get_filling_batches_services(
|
||||
cls,
|
||||
query_db: AsyncSession,
|
||||
query_object: FillingBatchPageQueryModel,
|
||||
current_user: CurrentUserModel,
|
||||
test_scope: TestBatchScope,
|
||||
) -> PageModel:
|
||||
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
|
||||
batches, total = await FillingSummaryDao.get_batch_page(query_db, query_object, warehouse_ids, test_scope)
|
||||
return PageModel(
|
||||
rows=[FillingBatchModel.model_validate(batch) for batch in batches],
|
||||
pageNum=query_object.page_num,
|
||||
pageSize=query_object.page_size,
|
||||
total=total,
|
||||
hasNext=query_object.page_num * query_object.page_size < total,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def get_filling_batch_detail_services(
|
||||
cls,
|
||||
query_db: AsyncSession,
|
||||
query_object: FillingBatchDetailQueryModel,
|
||||
current_user: CurrentUserModel,
|
||||
test_scope: TestBatchScope,
|
||||
) -> FillingBatchDetailModel:
|
||||
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
|
||||
batch = await FillingSummaryDao.get_batch_detail(
|
||||
query_db,
|
||||
query_object.strain_id,
|
||||
query_object.batch_no,
|
||||
warehouse_ids,
|
||||
test_scope,
|
||||
)
|
||||
if batch is None:
|
||||
if cls._is_admin(current_user):
|
||||
raise ServiceException(message='生产批次不存在')
|
||||
raise PermissionException(data='', message='无权访问该生产批次')
|
||||
return FillingBatchDetailModel.model_validate(batch)
|
||||
|
||||
@classmethod
|
||||
async def get_filling_overview_services(
|
||||
cls,
|
||||
query_db: AsyncSession,
|
||||
current_user: CurrentUserModel,
|
||||
test_scope: TestBatchScope,
|
||||
) -> FillingOverviewModel:
|
||||
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
|
||||
today_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
overview = await FillingSummaryDao.get_overview(
|
||||
query_db,
|
||||
warehouse_ids,
|
||||
test_scope,
|
||||
today_start,
|
||||
today_start.replace(day=1),
|
||||
(today_start + timedelta(days=cls.NEAR_EXPIRY_DAYS)).date(),
|
||||
cls.NEAR_EXPIRY_DAYS,
|
||||
)
|
||||
return FillingOverviewModel.model_validate(overview)
|
||||
|
||||
@classmethod
|
||||
async def filling_detail_services(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user