Files
ShiErFeng/shierfeng-fastapi-backend/module_business/controller/shipment_receipt_controller.py
T

109 lines
4.5 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, ResponseBaseModel
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 ShipmentModel
from module_business.entity.vo.shipment_receipt_vo import (
ShipmentReceiptCommandModel,
ShipmentReceiptItemModel,
ShipmentReceiptModel,
ShipmentReceiptQueryModel,
)
from module_business.service.shipment_receipt_service import ShipmentReceiptService
from utils.response_util import ResponseUtil
shipment_receipt_controller = APIRouterPro(
prefix='/business/shipment-receipt',
tags=['业务管理-发货收货核对'],
dependencies=[PreAuthDependency()],
)
@shipment_receipt_controller.get(
'/list',
response_model=PageResponseModel[ShipmentModel],
summary='查询目标现场收货单',
dependencies=[UserInterfaceAuthDependency('business:shipment:receive')],
)
async def list_shipment_receipts(
request: Request,
query: Annotated[ShipmentReceiptQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await ShipmentReceiptService.list_services(query_db, query, current_user, test_scope)
return ResponseUtil.success(model_content=result)
@shipment_receipt_controller.get(
'/{shipment_id}',
response_model=DataResponseModel[ShipmentReceiptModel],
summary='查询原发货核对明细',
dependencies=[UserInterfaceAuthDependency('business:shipment:receive')],
)
async def get_shipment_receipt(
request: Request,
shipment_id: Annotated[int, Path(gt=0)],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await ShipmentReceiptService.detail_services(query_db, shipment_id, current_user, test_scope)
return ResponseUtil.success(data=result)
@shipment_receipt_controller.get(
'/{shipment_id}/scan/{identifier:path}',
response_model=DataResponseModel[ShipmentReceiptItemModel],
summary='扫码或录入原托盘号核对',
dependencies=[UserInterfaceAuthDependency('business:shipment:receive')],
)
@Log(
title='收货扫码',
business_type=BusinessType.OTHER,
request_log_mode='none',
response_log_mode='summary',
oper_url_mode='route',
)
async def scan_shipment_receipt(
request: Request,
shipment_id: Annotated[int, Path(gt=0)],
identifier: Annotated[str, Path(min_length=1, max_length=128, pattern=r'\S')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await ShipmentReceiptService.scan_services(query_db, shipment_id, identifier, current_user, test_scope)
return ResponseUtil.success(data=result)
@shipment_receipt_controller.put(
'/{shipment_id}/confirm',
response_model=ResponseBaseModel,
summary='接收方确认核对收货',
dependencies=[UserInterfaceAuthDependency('business:shipment:receive')],
)
@Log(title='发货收货核对', business_type=BusinessType.UPDATE)
async def confirm_shipment_receipt(
request: Request,
shipment_id: Annotated[int, Path(gt=0)],
command: ShipmentReceiptCommandModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await ShipmentReceiptService.confirm_services(query_db, shipment_id, command, current_user, test_scope)
return ResponseUtil.success(msg=result.message)