调整事物
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Domain.Infrastructure
|
||||
{
|
||||
public interface ITransactionRepositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取事务 用来处理即时库存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IDbContextTransaction GetTransaction();
|
||||
|
||||
/// <summary>
|
||||
/// 获取事务 用来处理即时库存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool CommitTransaction(bool isRollback, IDbContextTransaction transaction);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -20,11 +21,14 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ILoginService _loginService;
|
||||
private readonly IChangeBoxRecordRepositories _changeBoxRecordRepositories;
|
||||
public ChangeMoveBoxService(IMapper mapper, ILoginService loginService, IChangeBoxRecordRepositories changeBoxRecordRepositories)
|
||||
public readonly ITransactionRepositories _transactionRepositories;
|
||||
public ChangeMoveBoxService(IMapper mapper, ILoginService loginService,
|
||||
IChangeBoxRecordRepositories changeBoxRecordRepositories, ITransactionRepositories transactionRepositories)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_loginService = loginService;
|
||||
_changeBoxRecordRepositories = changeBoxRecordRepositories;
|
||||
_transactionRepositories = transactionRepositories;
|
||||
}
|
||||
|
||||
public async Task<Result> Save(SaveChangeBoxRecordRequest dto, LoginInDto loginInfo)
|
||||
@@ -35,9 +39,17 @@ namespace WMS.Web.Domain.Services
|
||||
//需要填写序列号
|
||||
//需要修改库存
|
||||
|
||||
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isSuccess = true;
|
||||
entity = await _changeBoxRecordRepositories.Add(entity, true);
|
||||
if (entity == null)
|
||||
if (entity == null) isRollback = true;
|
||||
|
||||
//提交事务
|
||||
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user