141 lines
5.5 KiB
Python
141 lines
5.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
|
|
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,
|
|
UsageCreateModel,
|
|
UsageModel,
|
|
UsagePageQueryModel,
|
|
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[UsageModel],
|
|
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(
|
|
'/scan/{qr_token}',
|
|
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)
|