为 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>
218 lines
9.0 KiB
Python
218 lines
9.0 KiB
Python
"""客户现场使用接口。"""
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import Path, Query, Request, Response
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from common.annotation.log_annotation import Log
|
|
from common.aspect.db_seesion import DBSessionDependency
|
|
from common.aspect.interface_auth import UserInterfaceAuthDependency
|
|
from common.aspect.pre_auth import CurrentUserDependency, PreAuthDependency
|
|
from common.enums import BusinessType
|
|
from common.router import APIRouterPro
|
|
from common.vo import DataResponseModel, PageResponseModel
|
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
|
from module_business.dependency.test_batch_dependency import TestBatchScopeDependency
|
|
from module_business.domain.test_batch_scope import TestBatchScope
|
|
from module_business.entity.vo.operation_vo import (
|
|
BusinessOptionModel,
|
|
PalletScanResponseModel,
|
|
TunnelEntryCreateModel,
|
|
TunnelEntrySuccessResponseModel,
|
|
UsageCreateModel,
|
|
UsageListItemModel,
|
|
UsageModel,
|
|
UsagePageQueryModel,
|
|
UsageSiteBoardModel,
|
|
UsageSiteOptionModel,
|
|
UsageSuccessResponseModel,
|
|
)
|
|
from module_business.service.usage_service import UsageService
|
|
from utils.response_util import ResponseUtil
|
|
|
|
usage_controller = APIRouterPro(
|
|
prefix='/business/usage',
|
|
tags=['业务管理-客户现场使用'],
|
|
dependencies=[PreAuthDependency()],
|
|
)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/list',
|
|
summary='获取客户现场使用记录分页列表接口',
|
|
description='按当前用户客户现场数据范围获取使用记录',
|
|
response_model=PageResponseModel[UsageListItemModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:list')],
|
|
)
|
|
async def get_business_usage_list(
|
|
request: Request,
|
|
usage_page_query: Annotated[UsagePageQueryModel, Query()],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.get_usage_list_services(
|
|
query_db,
|
|
usage_page_query,
|
|
current_user,
|
|
test_scope,
|
|
is_page=True,
|
|
)
|
|
return ResponseUtil.success(model_content=result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/line-options',
|
|
summary='获取客户现场启用产线选项接口',
|
|
description='仅返回当前用户有权访问的指定客户现场启用产线',
|
|
response_model=DataResponseModel[list[BusinessOptionModel]],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:query')],
|
|
)
|
|
async def get_business_usage_line_options(
|
|
request: Request,
|
|
site_id: Annotated[int, Query(alias='siteId', gt=0, description='客户现场ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.get_line_options_services(query_db, site_id, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/tunnel-options',
|
|
summary='获取客户现场启用隧道选项接口',
|
|
description='仅返回当前用户有权访问的指定客户现场启用隧道',
|
|
response_model=DataResponseModel[list[BusinessOptionModel]],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:query')],
|
|
)
|
|
async def get_business_usage_tunnel_options(
|
|
request: Request,
|
|
site_id: Annotated[int, Query(alias='siteId', gt=0, description='客户现场ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.get_tunnel_options_services(query_db, site_id, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/site-options',
|
|
summary='获取客户现场使用的现场选项接口',
|
|
description='返回当前用户有权访问且已启用的客户现场,附带启用隧道与产线数',
|
|
response_model=DataResponseModel[list[UsageSiteOptionModel]],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:list')],
|
|
)
|
|
async def get_business_usage_site_options(
|
|
request: Request,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.get_site_options_services(query_db, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/site-board',
|
|
summary='获取客户现场看板接口',
|
|
description='统计指定现场的托盘库存、今日用量、隧道使用与跳过先到托盘次数;不返回内部溯源号',
|
|
response_model=DataResponseModel[UsageSiteBoardModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:query')],
|
|
)
|
|
async def get_business_usage_site_board(
|
|
request: Request,
|
|
site_id: Annotated[int, Query(alias='siteId', gt=0, description='客户现场ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.get_site_board_services(query_db, site_id, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.post(
|
|
'/enter-tunnel',
|
|
summary='扫码入隧接口',
|
|
description='将单个已到客户现场的托盘绑定到指定隧道,并生成或复用隧道内部溯源号',
|
|
response_model=DataResponseModel[TunnelEntrySuccessResponseModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:add')],
|
|
)
|
|
@Log(title='扫码入隧', business_type=BusinessType.INSERT)
|
|
async def enter_business_usage_tunnel(
|
|
request: Request,
|
|
entry_command: TunnelEntryCreateModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
result = await UsageService.enter_tunnel_services(query_db, entry_command, current_user, test_scope)
|
|
return ResponseUtil.success(msg=result.message, data=result.result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/scan/{qr_token:path}',
|
|
summary='扫描客户现场待使用托盘接口',
|
|
description='按托盘当前客户现场数据范围判断是否允许记录使用',
|
|
response_model=DataResponseModel[PalletScanResponseModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:query')],
|
|
)
|
|
@Log(
|
|
title='扫码操作',
|
|
business_type=BusinessType.OTHER,
|
|
request_log_mode='none',
|
|
response_log_mode='summary',
|
|
oper_url_mode='route',
|
|
)
|
|
async def scan_business_usage_pallet(
|
|
request: Request,
|
|
qr_token: Annotated[
|
|
str,
|
|
Path(min_length=1, max_length=128, pattern=r'\S', description='二维码固定标识'),
|
|
],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.scan_usage_pallet_services(query_db, qr_token, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.get(
|
|
'/{usage_id}',
|
|
summary='获取客户现场使用记录详情接口',
|
|
description='按客户现场数据范围获取指定使用记录',
|
|
response_model=DataResponseModel[UsageModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:query')],
|
|
)
|
|
async def query_detail_business_usage(
|
|
request: Request,
|
|
usage_id: Annotated[int, Path(gt=0, description='使用记录ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await UsageService.usage_detail_services(query_db, usage_id, current_user, test_scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@usage_controller.post(
|
|
'',
|
|
summary='记录客户现场使用接口',
|
|
description='扫描托盘并原子记录客户现场使用包数',
|
|
response_model=DataResponseModel[UsageSuccessResponseModel],
|
|
dependencies=[UserInterfaceAuthDependency('business:usage:add')],
|
|
)
|
|
@Log(title='客户现场使用', business_type=BusinessType.INSERT)
|
|
async def add_business_usage(
|
|
request: Request,
|
|
add_usage: UsageCreateModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
result = await UsageService.record_usage_services(query_db, add_usage, current_user, test_scope)
|
|
return ResponseUtil.success(msg=result.message, data=result.result)
|