优化
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Dto.ChangeBoxRecord;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Dto.Erp.Org;
|
||||
using WMS.Web.Core.Dto.InStock;
|
||||
using WMS.Web.Core.Dto.InStockTask;
|
||||
using WMS.Web.Core.Dto.Inventory;
|
||||
@@ -217,8 +218,19 @@ namespace WMS.Web.Domain.Services
|
||||
/// <returns></returns>
|
||||
private async Task<Result> ShelfSave(PurchaseShelfRequest dto, InstockType type, LoginInDto loginInfo, bool isTransaction = true)
|
||||
{
|
||||
// 组织集合
|
||||
var orgs = new List<ErpOrgDto>();
|
||||
var orgs_result = await _erpService.BillQueryForOrg();
|
||||
if (orgs_result.IsSuccess)
|
||||
orgs = orgs_result.Data.ToList();
|
||||
var currentOrg= orgs.Where(x => x.Number == dto.OrgCode).FirstOrDefault();
|
||||
|
||||
var entity = new InStock();
|
||||
entity.Type = type;
|
||||
entity.OrgId = currentOrg == null ? 0 : currentOrg.Id;
|
||||
entity.StockCode = dto.StockCode;
|
||||
entity.OrgCode = dto.OrgCode;
|
||||
entity.SubStockId = dto.SubStockId;
|
||||
entity.Method = InventoryInOutMethod.Box;
|
||||
entity.Details = _mapper.Map<List<InStockDetails>>(dto.Details);
|
||||
entity.Create(loginInfo.UserInfo.StaffId);
|
||||
@@ -242,6 +254,22 @@ namespace WMS.Web.Domain.Services
|
||||
if (entity == null)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//处理添加入库汇总明细
|
||||
var totalDetails = dto.Details.GroupBy(x => new { x.TaskId, x.SourceBillNo, x.SupplierId, x.MaterialId })
|
||||
.Select(x => new InStockTotalDetails
|
||||
{
|
||||
InStockId= entity.Id,
|
||||
TaskId=x.Key.TaskId,
|
||||
SourceBillNo=x.Key.SourceBillNo,
|
||||
SupplierId=x.Key.SupplierId,
|
||||
MaterialId=x.Key.MaterialId,
|
||||
Qty=x.Sum(t=>t.Qty),
|
||||
SerialNumbers= x.SelectMany(t=>t.SerialNumbers).ToList()
|
||||
}).ToList();
|
||||
|
||||
var isSuccess= await _inStockRepositories.AddRangeTotalDetails(totalDetails, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
//同步金蝶后,反写任务单的已交数量
|
||||
var taskIds = dto.Details.GroupBy(x => x.TaskId).Select(x => x.Key).ToList();
|
||||
var tasks = await _inStockTaskRepositories.GetList(taskIds);
|
||||
@@ -262,7 +290,7 @@ namespace WMS.Web.Domain.Services
|
||||
task.Shelf(loginInfo.UserInfo.StaffId);
|
||||
}
|
||||
|
||||
var isSuccess = await _inStockTaskRepositories.UpdateRange(tasks, isTransaction);
|
||||
isSuccess = await _inStockTaskRepositories.UpdateRange(tasks, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
}
|
||||
@@ -273,9 +301,7 @@ namespace WMS.Web.Domain.Services
|
||||
return serialNumber_result;
|
||||
|
||||
//箱库存变动
|
||||
var dtoDatas = new List<InStock>();
|
||||
dtoDatas.Add(entity);
|
||||
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(dtoDatas, isTransaction);
|
||||
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(entity, isTransaction);
|
||||
if (!boxInventoryResult.IsSuccess)
|
||||
return boxInventoryResult;
|
||||
|
||||
@@ -306,6 +332,10 @@ namespace WMS.Web.Domain.Services
|
||||
//2.生成:入库单
|
||||
var entity = new InStock();
|
||||
entity.Type = task.Type;
|
||||
entity.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
|
||||
entity.StockCode = dto.StockCode;
|
||||
entity.OrgCode = dto.OrgCode;
|
||||
entity.SubStockId = dto.SubStockId;
|
||||
entity.Method = dto.ShelfMethod == (int)ShelfMethod.Box ? InventoryInOutMethod.Box : InventoryInOutMethod.Product;
|
||||
entity.Details = new List<InStockDetails>();
|
||||
|
||||
@@ -321,10 +351,10 @@ namespace WMS.Web.Domain.Services
|
||||
item.TaskId = dto.TaskId;
|
||||
item.SourceBillNo = task.SourceBillNo;
|
||||
item.BoxId = box.BoxId;
|
||||
item.SubStockId = dto.SubStockId;
|
||||
item.StockCode = dto.StockCode;
|
||||
item.OrgCode = dto.OrgCode;
|
||||
item.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
|
||||
//item.SubStockId = dto.SubStockId;
|
||||
//item.StockCode = dto.StockCode;
|
||||
//item.OrgCode = dto.OrgCode;
|
||||
//item.OrgId = task.Details.Select(x => x.OrgId).FirstOrDefault();
|
||||
});
|
||||
//3.3添加到临时集合中
|
||||
temps.AddRange(dets);
|
||||
@@ -356,6 +386,22 @@ namespace WMS.Web.Domain.Services
|
||||
if (entity == null)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//处理添加入库汇总明细
|
||||
var totalDetails = dto.Boxs.SelectMany(x=>x.Details).GroupBy(x => new { x.MaterialId })
|
||||
.Select(x => new InStockTotalDetails
|
||||
{
|
||||
InStockId = entity.Id,
|
||||
TaskId =dto.TaskId,
|
||||
SourceBillNo = task.SourceBillNo,
|
||||
MaterialId = x.Key.MaterialId,
|
||||
Qty = x.Sum(t => t.Qty),
|
||||
SerialNumbers = x.SelectMany(t => t.SerialNumbers).ToList()
|
||||
}).ToList();
|
||||
|
||||
var isSuccess = await _inStockRepositories.AddRangeTotalDetails(totalDetails, isTransaction);
|
||||
if (!isSuccess)
|
||||
return Result.ReFailure(ResultCodes.DateWriteError);
|
||||
|
||||
//同步金蝶后,反写任务单的已交数量
|
||||
if (task != null)
|
||||
{
|
||||
@@ -422,9 +468,7 @@ namespace WMS.Web.Domain.Services
|
||||
return serialNumber_result;
|
||||
|
||||
//箱库存变动
|
||||
var dtoDatas = new List<InStock>();
|
||||
dtoDatas.Add(entity);
|
||||
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(dtoDatas, isTransaction);
|
||||
var boxInventoryResult = await _boxInventoryService.GenerateInStockBox(entity, isTransaction);
|
||||
if (!boxInventoryResult.IsSuccess)
|
||||
return boxInventoryResult;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user