安全:补齐业务批次归属校验

This commit is contained in:
焦龙言
2026-09-23 11:49:35 +08:00
parent 97b4dc8508
commit 5a76fe7521
10 changed files with 509 additions and 58 deletions
@@ -16,7 +16,7 @@ from module_business.dao.master_dao import MasterDao
from module_business.dao.operation_dao import OperationDao
from module_business.domain.enums import PalletEventType, PalletFlowState
from module_business.domain.pallet_state_machine import PalletStateMachine
from module_business.domain.test_batch_scope import TestBatchScope
from module_business.domain.test_batch_scope import TestBatchScope, assert_record_in_scope
from module_business.entity.do.master_do import BizPallet, BizStrain
from module_business.entity.do.operation_do import BizFillingRecord, BizPalletEvent, BizPalletInventory
from module_business.entity.vo.master_vo import StrainPageQueryModel
@@ -260,9 +260,11 @@ class FillingService:
pallet = await InventoryDao.get_pallet_by_qr_token(query_db, qr_token, test_scope)
if pallet is None:
cls._raise_pallet_not_accessible(current_user)
assert_record_in_scope(pallet, test_scope, '托盘')
inventory = await MasterDao.get_pallet_inventory(query_db, pallet.pallet_id, test_scope)
if inventory is None:
cls._raise_pallet_not_accessible(current_user, '托盘库存不存在')
assert_record_in_scope(inventory, test_scope, '库存')
if inventory.warehouse_id is None:
cls._raise_pallet_not_accessible(current_user, '托盘不在仓库')
await cls._assert_pallet_warehouse_access(
@@ -351,6 +353,7 @@ class FillingService:
warehouse_ids=[page_object.warehouse_id],
)
if existing is not None:
assert_record_in_scope(existing, test_scope, '装填记录')
await AccessService.assert_warehouse_access(
query_db,
current_user,
@@ -375,6 +378,7 @@ class FillingService:
)
if scanned_pallet is None:
cls._raise_pallet_not_accessible(current_user)
assert_record_in_scope(scanned_pallet, test_scope, '托盘')
inventory = await InventoryDao.get_inventory_for_update(
query_db,
@@ -383,6 +387,7 @@ class FillingService:
)
if inventory is None:
cls._raise_pallet_not_accessible(current_user, '托盘库存不存在')
assert_record_in_scope(inventory, test_scope, '库存')
if inventory.warehouse_id is None:
cls._raise_pallet_not_accessible(current_user, '托盘不在仓库')
await cls._assert_pallet_warehouse_access(
@@ -398,6 +403,7 @@ class FillingService:
if len(locked_pallets) != 1 or locked_pallets[0].pallet_id != scanned_pallet.pallet_id:
cls._raise_pallet_not_accessible(current_user)
pallet = locked_pallets[0]
assert_record_in_scope(pallet, test_scope, '托盘')
if inventory.active_filling_id is not None:
concurrent = await OperationDao.get_active_filling_for_update(
@@ -406,6 +412,7 @@ class FillingService:
test_scope,
)
if concurrent is not None and concurrent.idempotency_key == page_object.idempotency_key:
assert_record_in_scope(concurrent, test_scope, '活动装填')
# 结束首次非锁定读取建立的 RR 快照,再按最新数据范围恢复并发成功结果。
await query_db.rollback()
recovery_transaction_ended = True
@@ -425,6 +432,7 @@ class FillingService:
)
if warehouse is None:
raise ServiceException(message='仓库不存在')
assert_record_in_scope(warehouse, test_scope, '仓库')
if warehouse.status != '0':
raise ServiceException(message='仓库已停用')
await cls._assert_pallet_warehouse_access(
@@ -441,6 +449,7 @@ class FillingService:
for_update=True,
)
)
assert_record_in_scope(strain, test_scope, '菌种')
cls._validate_empty_warehouse_pallet(
pallet,