入库接口调整
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Dto.InStock;
|
||||
using WMS.Web.Core.Dto.InStockTask;
|
||||
using WMS.Web.Core.Dto.Login;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
@@ -19,7 +21,7 @@ namespace WMS.Web.Domain.Services
|
||||
/// <summary>
|
||||
/// 入库单服务
|
||||
/// </summary>
|
||||
public class InStockService: IInStockService
|
||||
public class InStockService : IInStockService
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ILoginService _loginService;
|
||||
@@ -37,35 +39,7 @@ namespace WMS.Web.Domain.Services
|
||||
_inStockTaskRepositories = inStockTaskRepositories;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出库单
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Save(List<SaveInStockRequest> dto, LoginInDto loginInfo)
|
||||
{
|
||||
var entity = new InStock();
|
||||
entity.Details = _mapper.Map<List<InStockDetails>>(dto);
|
||||
entity.Create(loginInfo.UserInfo.StaffId);
|
||||
|
||||
//需要填写序列号
|
||||
//需要修改库存
|
||||
//需要同步金蝶
|
||||
|
||||
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isSuccess = true;
|
||||
entity = await _inStockRepositories.Add(entity, true);
|
||||
if (entity == null) isRollback = true;
|
||||
|
||||
//提交事务
|
||||
isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步金蝶
|
||||
@@ -78,5 +52,139 @@ namespace WMS.Web.Domain.Services
|
||||
|
||||
return Task.FromResult(Result.ReSuccess());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 收货
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Receive(UpdateInStockTaskRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isTransaction = false;
|
||||
var result = await this.Update(dto, loginInfo.UserInfo.StaffId,true, isTransaction);
|
||||
if (!result.IsSuccess) isRollback = true;
|
||||
|
||||
//提交事务
|
||||
var isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上架
|
||||
/// </summary>
|
||||
/// <param name="instock"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Shelf(SaveInStockRequest instock, LoginInDto loginInfo)
|
||||
{
|
||||
IDbContextTransaction _transaction = _transactionRepositories.GetTransaction();
|
||||
bool isRollback = false;
|
||||
bool isTransaction = false;
|
||||
|
||||
//1.添加入库单:(同步金蝶在save方法里面进行)
|
||||
var save_result = await this.Save(instock, loginInfo.UserInfo.StaffId, isTransaction);
|
||||
if (!save_result.IsSuccess) isRollback = true;
|
||||
{
|
||||
//2.修改入库任务单
|
||||
var ids = new List<int>();
|
||||
ids.Add(instock.TaskId);
|
||||
var result = await this.UpdateRange(ids, loginInfo.UserInfo.StaffId, false, isTransaction);
|
||||
if (!result.IsSuccess) isRollback = true;
|
||||
}
|
||||
|
||||
//提交事务
|
||||
var isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存-出库单
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="staffId"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Save(SaveInStockRequest dto, int staffId, bool isTransaction = true)
|
||||
{
|
||||
var entity = new InStock();
|
||||
entity.Type = (InstockType)dto.Type;
|
||||
entity.TaskId = dto.TaskId;
|
||||
entity.Details = _mapper.Map<List<InStockDetails>>(dto.Details);
|
||||
entity.Create(staffId);
|
||||
|
||||
//需要填写序列号
|
||||
//需要修改库存
|
||||
//需要同步金蝶
|
||||
|
||||
entity = await _inStockRepositories.Add(entity, isTransaction);
|
||||
|
||||
if (entity != null)
|
||||
return Result.ReSuccess();
|
||||
else
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改-入库任务信息
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="staffId"></param>
|
||||
/// <param name="isReceive"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> Update(UpdateInStockTaskRequest dto, int staffId,bool isReceive, bool isTransaction = true)
|
||||
{
|
||||
var entity = await _inStockTaskRepositories.Get(dto.Id);
|
||||
if (entity == null)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
entity = _mapper.Map(dto, entity);
|
||||
if (isReceive)
|
||||
entity.Receive(staffId);
|
||||
else
|
||||
entity.Shelf(staffId);
|
||||
var result = _inStockTaskRepositories.Update(entity, isTransaction);
|
||||
if (result != null)
|
||||
return Result.ReSuccess();
|
||||
else
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改-入库任务信息
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="staffId"></param>
|
||||
/// <param name="isReceive"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> UpdateRange(List<int> ids, int staffId, bool isReceive, bool isTransaction = true)
|
||||
{
|
||||
var entitys = await _inStockTaskRepositories.GetList(ids);
|
||||
if (entitys == null || entitys.Count==0)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
if (isReceive)
|
||||
item.Receive(staffId);
|
||||
else
|
||||
item.Shelf(staffId);
|
||||
}
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(entitys, isTransaction);
|
||||
if (isSuccess)
|
||||
return Result.ReSuccess();
|
||||
else
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user