修复:补齐测试批次恢复锁定

This commit is contained in:
焦龙言
2026-09-23 09:01:50 +08:00
parent f5df2150d8
commit 97b4dc8508
15 changed files with 212 additions and 16 deletions
@@ -160,8 +160,8 @@ async def edit_business_inbound(
@inbound_controller.delete(
'/{inbound_ids}',
summary='删除首次入库草稿接口',
description='原子删除一个或多个尚未确认的首次入库草稿',
summary='不支持单条物理删除,请通过测试数据批次清理',
description='不支持单条物理删除,请通过测试数据批次清理',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('business:inbound:remove')],
)
@@ -177,8 +177,8 @@ async def edit_business_shipment(
@shipment_controller.delete(
'/{shipment_ids}',
summary='删除整托发货草稿接口',
description='原子删除一个或多个尚未确认的整托发货草稿',
summary='不支持单条物理删除,请通过测试数据批次清理',
description='不支持单条物理删除,请通过测试数据批次清理',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('business:shipment:remove')],
)
@@ -112,6 +112,7 @@ class InventoryDao:
db: AsyncSession,
inventory: BizPalletInventory,
event: BizPalletEvent,
scope: TestBatchScope,
) -> BizPalletEvent:
"""在调用方持有库存行锁时,为托盘追加下一序号事件。"""
last_sequence = 0
@@ -121,6 +122,7 @@ class InventoryDao:
.where(
BizPalletEvent.event_id == inventory.last_event_id,
BizPalletEvent.pallet_id == inventory.pallet_id,
batch_scope_condition(BizPalletEvent.test_batch_id, scope),
)
.with_for_update()
)
@@ -304,6 +304,7 @@ class FillingService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
if warehouse_ids is not None and page_object.warehouse_id not in warehouse_ids:
raise PermissionException(data='', message='无权访问该仓库')
@@ -509,7 +510,7 @@ class FillingService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return cls._success(filling_id)
except IntegrityError:
@@ -502,6 +502,7 @@ class InboundService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
current = await OperationDao.get_inbound_by_id(
query_db,
@@ -694,7 +695,7 @@ class InboundService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return cls._success('确认成功')
@@ -585,7 +585,6 @@ class ReturnService:
) -> None:
site = await MasterDao.get_site(query_db, return_order.source_site_id, test_scope, for_update=True)
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
await AccessService.assert_site_access(
query_db,
current_user,
@@ -607,6 +606,7 @@ class ReturnService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
site_ids = await cls._site_scope(query_db, current_user)
request_warehouse_ids = None if site_ids is None else []
recovered = None
@@ -678,6 +678,7 @@ class ReturnService:
preflight_existing_id = int(existing.return_id) if existing is not None else None
await query_db.rollback()
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
if preflight_existing_id is not None:
locked_existing = await OperationDao.get_return_for_update(
query_db,
@@ -802,7 +803,7 @@ class ReturnService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return cls._success('申请成功', return_id)
@@ -813,6 +814,7 @@ class ReturnService:
page_object,
cls._build_request_hash(page_object),
current_user,
test_scope,
)
except Exception:
await query_db.rollback()
@@ -941,6 +943,7 @@ class ReturnService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
warehouse_ids = await cls._warehouse_scope(query_db, current_user)
confirm_site_ids = None if warehouse_ids is None else []
route = await OperationDao.get_return_by_id(
@@ -1040,6 +1043,7 @@ class ReturnService:
raise ServiceException(message='确认退回失败,幂等键已被其他请求使用')
await query_db.rollback()
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
locked = await OperationDao.get_return_for_update(
query_db,
return_id,
@@ -1146,7 +1150,7 @@ class ReturnService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return cls._success('确认成功', return_id)
@@ -738,6 +738,7 @@ class ShipmentService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
warehouse_ids, site_ids = await cls._scopes(query_db, current_user)
current = await OperationDao.get_shipment_by_id(
query_db,
@@ -932,7 +933,7 @@ class ShipmentService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return cls._success('确认成功')
@@ -177,6 +177,7 @@ class UsageService:
test_scope: TestBatchScope,
) -> CrudResponseModel:
try:
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
site_ids = await cls._site_scope(query_db, current_user)
if site_ids is not None and expected_site_id not in site_ids:
cls._raise_pallet_not_accessible(current_user)
@@ -403,6 +404,7 @@ class UsageService:
cls._raise_pallet_not_accessible(current_user)
scanned_pallet_id = int(scanned_pallet.pallet_id)
await query_db.rollback()
await TestBatchAccessService.lock_active_batch(query_db, test_scope)
inventory = await InventoryDao.get_inventory_for_update(
query_db,
@@ -579,7 +581,7 @@ class UsageService:
request_hash=request_hash,
test_batch_id=test_scope.batch_id,
)
await InventoryDao.add_event(query_db, inventory, event)
await InventoryDao.add_event(query_db, inventory, event, test_scope)
await query_db.commit()
return result
except IntegrityError: