安全:隔离主数据并封闭单条删除

This commit is contained in:
焦龙言
2026-09-22 18:16:30 +08:00
parent af5428d0e3
commit b6f606d9f2
13 changed files with 1382 additions and 1131 deletions
@@ -12,6 +12,8 @@ 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.master_vo import CustomerModel, CustomerPageQueryModel, DeleteCustomerModel
from module_business.service.master_service import MasterService
from utils.response_util import ResponseUtil
@@ -32,8 +34,9 @@ async def get_master_customer_list(
request: Request,
customer_page_query: Annotated[CustomerPageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
customer_page_query_result = await MasterService.list_customer(query_db, customer_page_query, is_page=True)
customer_page_query_result = await MasterService.list_customer(query_db, customer_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=customer_page_query_result)
@@ -49,8 +52,9 @@ async def query_detail_master_customer(
request: Request,
customer_id: Annotated[int, Path(gt=0, description='客户ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
customer_detail_result = await MasterService.detail_customer(query_db, customer_id)
customer_detail_result = await MasterService.detail_customer(query_db, customer_id, scope)
return ResponseUtil.success(data=customer_detail_result)
@@ -68,13 +72,14 @@ async def add_master_customer(
add_customer: CustomerModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_customer.create_by = current_user.user.user_name
add_customer.create_time = current_time
add_customer.update_by = current_user.user.user_name
add_customer.update_time = current_time
add_customer_result = await MasterService.add_customer(query_db, add_customer)
add_customer_result = await MasterService.add_customer(query_db, add_customer, current_user, scope)
return ResponseUtil.success(msg=add_customer_result.message)
@@ -92,10 +97,11 @@ async def edit_master_customer(
edit_customer: CustomerModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_customer.update_by = current_user.user.user_name
edit_customer.update_time = datetime.now()
edit_customer_result = await MasterService.edit_customer(query_db, edit_customer)
edit_customer_result = await MasterService.edit_customer(query_db, edit_customer, current_user, scope)
return ResponseUtil.success(msg=edit_customer_result.message)
@@ -12,6 +12,8 @@ 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.master_vo import DeleteLineModel, LineModel, LinePageQueryModel
from module_business.service.master_service import MasterService
from utils.response_util import ResponseUtil
@@ -30,8 +32,9 @@ async def get_master_line_list(
request: Request,
line_page_query: Annotated[LinePageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
line_page_query_result = await MasterService.list_line(query_db, line_page_query, is_page=True)
line_page_query_result = await MasterService.list_line(query_db, line_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=line_page_query_result)
@@ -47,8 +50,9 @@ async def query_detail_master_line(
request: Request,
line_id: Annotated[int, Path(gt=0, description='生产线ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
line_detail_result = await MasterService.detail_line(query_db, line_id)
line_detail_result = await MasterService.detail_line(query_db, line_id, scope)
return ResponseUtil.success(data=line_detail_result)
@@ -66,13 +70,14 @@ async def add_master_line(
add_line: LineModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_line.create_by = current_user.user.user_name
add_line.create_time = current_time
add_line.update_by = current_user.user.user_name
add_line.update_time = current_time
add_line_result = await MasterService.add_line(query_db, add_line)
add_line_result = await MasterService.add_line(query_db, add_line, current_user, scope)
return ResponseUtil.success(msg=add_line_result.message)
@@ -90,10 +95,11 @@ async def edit_master_line(
edit_line: LineModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_line.update_by = current_user.user.user_name
edit_line.update_time = datetime.now()
edit_line_result = await MasterService.edit_line(query_db, edit_line)
edit_line_result = await MasterService.edit_line(query_db, edit_line, current_user, scope)
return ResponseUtil.success(msg=edit_line_result.message)
@@ -11,6 +11,8 @@ 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.master_vo import (
DeletePalletModel,
PalletCreateModel,
@@ -37,8 +39,9 @@ async def get_master_pallet_list(
request: Request,
pallet_page_query: Annotated[PalletPageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await PalletService.list_pallet(query_db, pallet_page_query, is_page=True)
result = await PalletService.list_pallet(query_db, pallet_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=result)
@@ -54,8 +57,9 @@ async def query_master_pallet_qrcode(
request: Request,
pallet_id: Annotated[int, Path(gt=0, description='托盘ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
png = await PalletService.get_pallet_qrcode(query_db, pallet_id)
png = await PalletService.get_pallet_qrcode(query_db, pallet_id, scope)
return Response(content=png, media_type='image/png')
@@ -70,8 +74,9 @@ async def query_detail_master_pallet(
request: Request,
pallet_id: Annotated[int, Path(gt=0, description='托盘ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await PalletService.detail_pallet(query_db, pallet_id)
result = await PalletService.detail_pallet(query_db, pallet_id, scope)
return ResponseUtil.success(data=result)
@@ -88,8 +93,9 @@ async def add_master_pallet(
add_pallet: PalletCreateModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await PalletService.add_pallet(query_db, add_pallet, current_user.user.user_name)
result = await PalletService.add_pallet(query_db, add_pallet, current_user, scope)
return ResponseUtil.success(msg=result.message)
@@ -106,8 +112,9 @@ async def edit_master_pallet(
edit_pallet: PalletEditModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await PalletService.edit_pallet(query_db, edit_pallet, current_user.user.user_name)
result = await PalletService.edit_pallet(query_db, edit_pallet, current_user, scope)
return ResponseUtil.success(msg=result.message)
@@ -12,6 +12,8 @@ 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.master_vo import (
BusinessUserOptionModel,
DeleteSiteModel,
@@ -45,8 +47,9 @@ async def get_master_site_users(
request: Request,
site_id: Annotated[int, Path(gt=0, description='客户现场ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
users = await PalletService.list_site_users(query_db, site_id)
users = await PalletService.list_site_users(query_db, site_id, scope)
return ResponseUtil.success(data=users)
@@ -64,8 +67,9 @@ async def assign_master_site_users(
assignment: UserAssignModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, ASSIGN_CURRENT_USER()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await PalletService.assign_site_users(query_db, site_id, assignment)
result = await PalletService.assign_site_users(query_db, site_id, assignment, current_user, scope)
return ResponseUtil.success(msg=result.message)
@@ -80,8 +84,9 @@ async def get_master_site_list(
request: Request,
site_page_query: Annotated[SitePageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
site_page_query_result = await MasterService.list_site(query_db, site_page_query, is_page=True)
site_page_query_result = await MasterService.list_site(query_db, site_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=site_page_query_result)
@@ -97,8 +102,9 @@ async def query_detail_master_site(
request: Request,
site_id: Annotated[int, Path(gt=0, description='客户现场ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
site_detail_result = await MasterService.detail_site(query_db, site_id)
site_detail_result = await MasterService.detail_site(query_db, site_id, scope)
return ResponseUtil.success(data=site_detail_result)
@@ -116,13 +122,14 @@ async def add_master_site(
add_site: SiteModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_site.create_by = current_user.user.user_name
add_site.create_time = current_time
add_site.update_by = current_user.user.user_name
add_site.update_time = current_time
add_site_result = await MasterService.add_site(query_db, add_site)
add_site_result = await MasterService.add_site(query_db, add_site, current_user, scope)
return ResponseUtil.success(msg=add_site_result.message)
@@ -140,10 +147,11 @@ async def edit_master_site(
edit_site: SiteModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_site.update_by = current_user.user.user_name
edit_site.update_time = datetime.now()
edit_site_result = await MasterService.edit_site(query_db, edit_site)
edit_site_result = await MasterService.edit_site(query_db, edit_site, current_user, scope)
return ResponseUtil.success(msg=edit_site_result.message)
@@ -12,6 +12,8 @@ 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.master_vo import DeleteStrainModel, StrainModel, StrainPageQueryModel
from module_business.service.master_service import MasterService
from utils.response_util import ResponseUtil
@@ -32,8 +34,9 @@ async def get_master_strain_list(
request: Request,
strain_page_query: Annotated[StrainPageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
strain_page_query_result = await MasterService.list_strain(query_db, strain_page_query, is_page=True)
strain_page_query_result = await MasterService.list_strain(query_db, strain_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=strain_page_query_result)
@@ -49,8 +52,9 @@ async def query_detail_master_strain(
request: Request,
strain_id: Annotated[int, Path(gt=0, description='菌种ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
strain_detail_result = await MasterService.detail_strain(query_db, strain_id)
strain_detail_result = await MasterService.detail_strain(query_db, strain_id, scope)
return ResponseUtil.success(data=strain_detail_result)
@@ -68,13 +72,14 @@ async def add_master_strain(
add_strain: StrainModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_strain.create_by = current_user.user.user_name
add_strain.create_time = current_time
add_strain.update_by = current_user.user.user_name
add_strain.update_time = current_time
add_strain_result = await MasterService.add_strain(query_db, add_strain)
add_strain_result = await MasterService.add_strain(query_db, add_strain, current_user, scope)
return ResponseUtil.success(msg=add_strain_result.message)
@@ -92,10 +97,11 @@ async def edit_master_strain(
edit_strain: StrainModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_strain.update_by = current_user.user.user_name
edit_strain.update_time = datetime.now()
edit_strain_result = await MasterService.edit_strain(query_db, edit_strain)
edit_strain_result = await MasterService.edit_strain(query_db, edit_strain, current_user, scope)
return ResponseUtil.success(msg=edit_strain_result.message)
@@ -12,6 +12,8 @@ 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.master_vo import (
BusinessUserOptionModel,
DeleteWarehouseModel,
@@ -45,8 +47,9 @@ async def get_master_warehouse_users(
request: Request,
warehouse_id: Annotated[int, Path(gt=0, description='仓库ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
users = await PalletService.list_warehouse_users(query_db, warehouse_id)
users = await PalletService.list_warehouse_users(query_db, warehouse_id, scope)
return ResponseUtil.success(data=users)
@@ -64,8 +67,9 @@ async def assign_master_warehouse_users(
assignment: UserAssignModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, ASSIGN_CURRENT_USER()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await PalletService.assign_warehouse_users(query_db, warehouse_id, assignment)
result = await PalletService.assign_warehouse_users(query_db, warehouse_id, assignment, current_user, scope)
return ResponseUtil.success(msg=result.message)
@@ -80,8 +84,14 @@ async def get_master_warehouse_list(
request: Request,
warehouse_page_query: Annotated[WarehousePageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
warehouse_page_query_result = await MasterService.list_warehouse(query_db, warehouse_page_query, is_page=True)
warehouse_page_query_result = await MasterService.list_warehouse(
query_db,
warehouse_page_query,
scope,
is_page=True,
)
return ResponseUtil.success(model_content=warehouse_page_query_result)
@@ -97,8 +107,9 @@ async def query_detail_master_warehouse(
request: Request,
warehouse_id: Annotated[int, Path(gt=0, description='仓库ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
warehouse_detail_result = await MasterService.detail_warehouse(query_db, warehouse_id)
warehouse_detail_result = await MasterService.detail_warehouse(query_db, warehouse_id, scope)
return ResponseUtil.success(data=warehouse_detail_result)
@@ -116,13 +127,14 @@ async def add_master_warehouse(
add_warehouse: WarehouseModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_warehouse.create_by = current_user.user.user_name
add_warehouse.create_time = current_time
add_warehouse.update_by = current_user.user.user_name
add_warehouse.update_time = current_time
add_warehouse_result = await MasterService.add_warehouse(query_db, add_warehouse)
add_warehouse_result = await MasterService.add_warehouse(query_db, add_warehouse, current_user, scope)
return ResponseUtil.success(msg=add_warehouse_result.message)
@@ -140,10 +152,11 @@ async def edit_master_warehouse(
edit_warehouse: WarehouseModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_warehouse.update_by = current_user.user.user_name
edit_warehouse.update_time = datetime.now()
edit_warehouse_result = await MasterService.edit_warehouse(query_db, edit_warehouse)
edit_warehouse_result = await MasterService.edit_warehouse(query_db, edit_warehouse, current_user, scope)
return ResponseUtil.success(msg=edit_warehouse_result.message)