优化
This commit is contained in:
@@ -440,33 +440,31 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="dtoDatas"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> GenerateInStockBox(List<InStock> dtoDatas, bool isTransaction)
|
||||
public async Task<Result> GenerateInStockBox(InStock dtoData, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
if (dtoData == null)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//物料收发明细dtos
|
||||
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
|
||||
|
||||
#region 按箱
|
||||
//2.组装-按箱入库
|
||||
var dtoDatas_details_Method_box = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Box).SelectMany(x => x.Details).ToList();
|
||||
var generateDtoList_Metod_Box = dtoDatas_details_Method_box.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
|
||||
//2.组装-按箱和按产品入库
|
||||
var generateDtoList = dtoData.Details.GroupBy(x => new { x.BoxId })
|
||||
.Select(x => new BoxInventoryGenerateDto()
|
||||
{
|
||||
BoxId = x.Key.BoxId,
|
||||
OrgCode = x.Key.OrgCode,
|
||||
StockCode = x.Key.StockCode,
|
||||
SubStockId = x.Key.SubStockId,
|
||||
InventoryInOutMethod = (int)InventoryInOutMethod.Box,
|
||||
OrgCode = dtoData.OrgCode,
|
||||
StockCode = dtoData.StockCode,
|
||||
SubStockId = dtoData.SubStockId,
|
||||
InventoryInOutMethod = (int)dtoData.Method,
|
||||
InventoryInOutType = (int)InventoryInOutType.In
|
||||
}).ToList();
|
||||
|
||||
//2.1.遍历:组装明细
|
||||
generateDtoList_Metod_Box.ForEach(x =>
|
||||
generateDtoList.ForEach(x =>
|
||||
{
|
||||
foreach (var detItem in dtoDatas_details_Method_box)
|
||||
foreach (var detItem in dtoData.Details)
|
||||
{
|
||||
//2.1箱是当前的
|
||||
if (detItem.BoxId == x.BoxId)
|
||||
@@ -480,63 +478,21 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
}
|
||||
});
|
||||
#endregion
|
||||
|
||||
#region 按产品
|
||||
//3.组装-按产品入库
|
||||
var dtoDatas_details_Method_Product = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Product).SelectMany(x => x.Details).ToList();
|
||||
var generateDtoList_Metod_Product = dtoDatas_details_Method_Product.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
|
||||
.Select(x => new BoxInventoryGenerateDto()
|
||||
{
|
||||
BoxId = x.Key.BoxId,
|
||||
OrgCode = x.Key.OrgCode,
|
||||
StockCode = x.Key.StockCode,
|
||||
SubStockId = x.Key.SubStockId,
|
||||
InventoryInOutMethod = (int)InventoryInOutMethod.Product,
|
||||
InventoryInOutType = (int)InventoryInOutType.In
|
||||
}).ToList();
|
||||
|
||||
//3.1.遍历:组装明细
|
||||
generateDtoList_Metod_Product.ForEach(x =>
|
||||
{
|
||||
foreach (var detItem in dtoDatas_details_Method_Product)
|
||||
{
|
||||
//3.1箱是当前的
|
||||
if (detItem.BoxId == x.BoxId)
|
||||
{
|
||||
//3.2组装明细
|
||||
var det = new BoxInventoryGenerateDetailsDto();
|
||||
det.MaterialId = detItem.MaterialId;
|
||||
det.Qty = detItem.Qty;
|
||||
det.SerialNumbers = detItem.SerialNumbers;
|
||||
x.Details.Add(det);
|
||||
}
|
||||
}
|
||||
});
|
||||
#endregion
|
||||
|
||||
//整合一起
|
||||
var generateDtoList = new List<BoxInventoryGenerateDto>();
|
||||
generateDtoList.AddRange(generateDtoList_Metod_Box);
|
||||
generateDtoList.AddRange(generateDtoList_Metod_Product);
|
||||
//提交处理
|
||||
var result = await this.ExeInStockBox(generateDtoList, isTransaction);
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
|
||||
//5.组装物料收发明细dto
|
||||
foreach (var item in dtoDatas.SelectMany(x => x.Details).ToList())
|
||||
foreach (var item in dtoData.Details)
|
||||
{
|
||||
var entity = dtoDatas.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
if (entity != null)
|
||||
{
|
||||
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
|
||||
item.BoxId, item.MaterialId,
|
||||
item.OrgCode, item.StockCode,
|
||||
item.SubStockId, InStockTypeConvert(entity.Type),
|
||||
item.SourceBillNo, item.Qty, InventoryInOutType.In);
|
||||
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
|
||||
}
|
||||
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
|
||||
item.BoxId, item.MaterialId,
|
||||
dtoData.OrgCode, dtoData.StockCode,
|
||||
dtoData.SubStockId, InStockTypeConvert(dtoData.Type),
|
||||
item.SourceBillNo, item.Qty, InventoryInOutType.In);
|
||||
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
|
||||
|
||||
}
|
||||
//5.提交物料收发明细:新增
|
||||
if (InventoryInOutDetailsGenerateDtoList.Count != 0)
|
||||
@@ -565,16 +521,16 @@ namespace WMS.Web.Domain.Services
|
||||
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
|
||||
|
||||
//找出所有的箱库存
|
||||
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x=>x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
|
||||
//判断箱库存是否存在
|
||||
foreach (var bid in boxIds)
|
||||
{
|
||||
var isHaveBoxInvetory= boxInventorys.Where(x => x.BoxId == bid).Any();
|
||||
var isHaveBoxInvetory = boxInventorys.Where(x => x.BoxId == bid).Any();
|
||||
if (!isHaveBoxInvetory)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//2.组装
|
||||
var generateDtoList = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => new { x.BoxId })
|
||||
@@ -590,7 +546,7 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
//从箱库存找到:组织、仓库、仓位、进行赋值;
|
||||
var current_box_invetory = boxInventorys.Where(t => t.BoxId == x.BoxId).FirstOrDefault();
|
||||
if (current_box_invetory != null && current_box_invetory.BoxId==x.BoxId)
|
||||
if (current_box_invetory != null && current_box_invetory.BoxId == x.BoxId)
|
||||
{
|
||||
x.OrgCode = current_box_invetory.OrgCode;
|
||||
x.StockCode = current_box_invetory.StockCode;
|
||||
@@ -1439,7 +1395,7 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="boxInventorys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas,List<BoxInventory> boxInventorys, bool isTransaction)
|
||||
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas, List<BoxInventory> boxInventorys, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -168,6 +168,18 @@ namespace WMS.Web.Domain.Services.Public
|
||||
return org == null ? "" : org.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取组织id
|
||||
/// </summary>
|
||||
/// <param name="erpOrgs"></param>
|
||||
/// <param name="orgCode"></param>
|
||||
/// <returns></returns>
|
||||
public int GetOrgId(List<ErpOrgDto> erpOrgs, string orgCode)
|
||||
{
|
||||
var org = erpOrgs.Where(x => x.Number == orgCode).FirstOrDefault();
|
||||
return org == null ? 0 : org.Id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取供应商名称
|
||||
/// </summary>
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
var box = boxList.FirstOrDefault(f => f.Id == entity.BoxId);
|
||||
var instockDetail = inStock.Details.FirstOrDefault(f => f.MaterialId == entity.MaterialId);
|
||||
var subStock = _singleDataService.GetSingleData(SingleAction.SubStocks, loginInfo.UserInfo.CompanyId, instockDetail.SubStockId);
|
||||
var subStock = _singleDataService.GetSingleData(SingleAction.SubStocks, loginInfo.UserInfo.CompanyId, inStock.SubStockId);
|
||||
//修改序列号和箱绑定关系
|
||||
entity.InStock(instockDetail.SourceBillNo, inStock.Type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user