This commit is contained in:
tongfei
2023-11-17 15:55:15 +08:00
2 changed files with 46 additions and 28 deletions

View File

@@ -93,25 +93,33 @@ namespace WMS.Web.Domain.Services
IDbContextTransaction _transaction = null; IDbContextTransaction _transaction = null;
if (isTransaction) if (isTransaction)
_transaction = _transactionRepositories.GetTransaction(); _transaction = _transactionRepositories.GetTransaction();
bool isRollback = false; Result res_Rollback = Result.ReSuccess();
bool isSuccess = true; bool isSuccess = true;
var res_Inventory = await _boxInventoryService.GenerateChangeBox(inventoryList, false); var res_Inventory = await _boxInventoryService.GenerateChangeBox(inventoryList, false);
if (!res_Inventory.IsSuccess) isRollback = true; if (!res_Inventory.IsSuccess) res_Rollback = res_Inventory;
isSuccess = await _changeBoxRecordRepositories.AddRange(list, false); if (res_Rollback.IsSuccess)
if (!isSuccess) isRollback = true; {
var res_change = await _serialNumberService.ChangeBox(list, loginInfo, false); isSuccess = await _changeBoxRecordRepositories.AddRange(list, false);
if (!res_change.IsSuccess) isRollback = true; if (!isSuccess) res_Rollback=Result.ReFailure(ResultCodes.DateWriteError);
isSuccess = await _boxRepositories.EditEntityList(boxList, false); }
if (!isSuccess) isRollback = true; if (res_Rollback.IsSuccess)
{
var res_change = await _serialNumberService.ChangeBox(list, loginInfo, false);
if (!res_change.IsSuccess) res_Rollback = res_change;
}
if (res_Rollback.IsSuccess)
{
isSuccess = await _boxRepositories.EditEntityList(boxList, false);
if (!isSuccess) res_Rollback= Result.ReFailure(ResultCodes.DateWriteError);
}
//提交事务 //提交事务
if (isTransaction) if (isTransaction)
{ {
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction); isSuccess = _transactionRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
if (!res_Rollback.IsSuccess) return res_Rollback;
if (!isSuccess) if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError); return Result.ReFailure(ResultCodes.DateWriteError);
} }
return Result.ReSuccess(); return Result.ReSuccess();
} }
/// <summary> /// <summary>
@@ -120,7 +128,7 @@ namespace WMS.Web.Domain.Services
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="loginInfo"></param> /// <param name="loginInfo"></param>
/// <returns></returns> /// <returns></returns>
public async Task<Result> MoveBoxSave(List<SaveMoveBoxRecordRequest> dto,bool IsUp, LoginInDto loginInfo) public async Task<Result> MoveBoxSave(List<SaveMoveBoxRecordRequest> dto, bool IsUp, LoginInDto loginInfo)
{ {
//1.下架时 需要验证箱是否在库存里 //1.下架时 需要验证箱是否在库存里
@@ -135,19 +143,28 @@ namespace WMS.Web.Domain.Services
inventoryList.ForEach(f => f.InventoryInOutType = IsUp == true ? 1 : 2); inventoryList.ForEach(f => f.InventoryInOutType = IsUp == true ? 1 : 2);
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction(); IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
bool isRollback = false;
bool isSuccess = true; bool isSuccess = true;
Result res_Rollback = Result.ReSuccess();
var res_Inventory = await _boxInventoryService.GenerateMoveBox(inventoryList, false); var res_Inventory = await _boxInventoryService.GenerateMoveBox(inventoryList, false);
if (!res_Inventory.IsSuccess) isRollback = true; if (!res_Inventory.IsSuccess) res_Rollback = res_Inventory;
isSuccess = await _moveBoxRecordRepositories.AddRange(entityList, false);
if (!isSuccess) isRollback = true; if (res_Rollback.IsSuccess)
var res_change = await _serialNumberService.MoveBox(entityList, loginInfo, false); {
if (!res_change.IsSuccess) isRollback = true; isSuccess = await _moveBoxRecordRepositories.AddRange(entityList, false);
if (!isSuccess) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
}
if (res_Rollback.IsSuccess)
{
var res_change = await _serialNumberService.MoveBox(entityList, loginInfo, false);
if (!res_change.IsSuccess) res_Rollback = res_change;
}
//提交事务 //提交事务
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction); isSuccess = _transactionRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
if (!res_Rollback.IsSuccess) return res_Rollback;
if (!isSuccess) if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError); return Result.ReFailure(ResultCodes.DateWriteError);
return Result.ReSuccess(); return Result.ReSuccess();
} }
} }

View File

@@ -123,28 +123,29 @@ namespace WMS.Web.Domain.Services
#endregion #endregion
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction(); IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
bool isRollback = false; Result res_Rollback = Result.ReSuccess();
bool isSuccess = true; bool isSuccess = true;
//修改库存 //修改库存
var res_Inventory = await _boxInventoryService.HandlBoxInventory(inventoryList, false); var res_Inventory = await _boxInventoryService.HandlBoxInventory(inventoryList, false);
if (!res_Inventory.IsSuccess) isRollback = true; if (!res_Inventory.IsSuccess) res_Rollback = res_Inventory;
if (!isRollback) if (res_Rollback.IsSuccess)
{ {
entity = await _outStockRepositories.Add(entity, false); entity = await _outStockRepositories.Add(entity, false);
if (entity == null) isRollback = true; if (entity == null) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
} }
if (!isRollback) if (res_Rollback.IsSuccess)
{ {
outStockTask = await _outStockTaskRepositories.Edit(outStockTask, false); outStockTask = await _outStockTaskRepositories.Edit(outStockTask, false);
if (outStockTask == null) isRollback = true; if (outStockTask == null) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError);
} }
if (!isRollback) if (res_Rollback.IsSuccess)
{ {
var res_change = await _serialNumberService.OutStock(entity, loginInfo, false); var res_change = await _serialNumberService.OutStock(entity, loginInfo, false);
if (!res_change.IsSuccess) isRollback = true; if (!res_change.IsSuccess) res_Rollback = res_change;
} }
//提交事务 //提交事务
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction); isSuccess = _transactionRepositories.CommitTransaction(res_Rollback.IsSuccess ? false : true, _transaction);
if (!res_Rollback.IsSuccess) return res_Rollback;
if (!isSuccess) if (!isSuccess)
return Result.ReFailure(ResultCodes.DateWriteError); return Result.ReFailure(ResultCodes.DateWriteError);