93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Core.Dto.ChangeBoxRecord;
|
|
using WMS.Web.Core.Dto.Login;
|
|
using WMS.Web.Core.Dto.MoveBoxRecord;
|
|
using WMS.Web.Core.Internal.Results;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Domain.IService;
|
|
using WMS.Web.Domain.IService.Public;
|
|
using WMS.Web.Domain.Values;
|
|
|
|
namespace WMS.Web.Domain.Services
|
|
{
|
|
///改箱 移箱服务
|
|
public class ChangeMoveBoxService : IChangeMoveBoxService
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly ILoginService _loginService;
|
|
private readonly IChangeBoxRecordRepositories _changeBoxRecordRepositories;
|
|
public readonly ITransactionRepositories _transactionRepositories;
|
|
private readonly IMoveBoxRecordRepositories _moveBoxRecordRepositories;
|
|
public ChangeMoveBoxService(IMapper mapper, ILoginService loginService,
|
|
IChangeBoxRecordRepositories changeBoxRecordRepositories, ITransactionRepositories transactionRepositories,
|
|
IMoveBoxRecordRepositories moveBoxRecordRepositories)
|
|
{
|
|
_mapper = mapper;
|
|
_loginService = loginService;
|
|
_changeBoxRecordRepositories = changeBoxRecordRepositories;
|
|
_transactionRepositories = transactionRepositories;
|
|
_moveBoxRecordRepositories = moveBoxRecordRepositories;
|
|
}
|
|
/// <summary>
|
|
/// 改箱保存
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <param name="loginInfo"></param>
|
|
/// <returns></returns>
|
|
public async Task<Result> ChangeBoxSave(SaveChangeBoxRecordRequest dto, LoginInDto loginInfo)
|
|
{
|
|
var entity = _mapper.Map<ChangeBoxRecord>(dto);
|
|
entity.Create(loginInfo.UserInfo.StaffId);
|
|
|
|
//需要填写序列号
|
|
//需要修改库存
|
|
|
|
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
|
bool isRollback = false;
|
|
bool isSuccess = true;
|
|
entity = await _changeBoxRecordRepositories.Add(entity, true);
|
|
if (entity == null) isRollback = true;
|
|
|
|
//提交事务
|
|
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
|
if (!isSuccess)
|
|
return Result.ReFailure(ResultCodes.DateWriteError);
|
|
|
|
return Result.ReSuccess();
|
|
}
|
|
/// <summary>
|
|
/// 移箱保存
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <param name="loginInfo"></param>
|
|
/// <returns></returns>
|
|
public async Task<Result> MoveBoxSave(SaveMoveBoxRecordRequest dto, LoginInDto loginInfo)
|
|
{
|
|
var entity = _mapper.Map<MoveBoxRecord>(dto);
|
|
entity.Create(loginInfo.UserInfo.StaffId);
|
|
|
|
//需要填写规格型号
|
|
//需要修改库存
|
|
|
|
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
|
bool isRollback = false;
|
|
bool isSuccess = true;
|
|
entity = await _moveBoxRecordRepositories.Add(entity, true);
|
|
if (entity == null) isRollback = true;
|
|
|
|
//提交事务
|
|
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
|
if (!isSuccess)
|
|
return Result.ReFailure(ResultCodes.DateWriteError);
|
|
|
|
return Result.ReSuccess();
|
|
}
|
|
}
|
|
}
|