diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 29e8aa38..466de104 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -3293,14 +3293,6 @@ 即时库存-服务 - - - 改箱-箱库存的变更 - - - - - 改箱-箱库存的变更 @@ -3309,14 +3301,6 @@ - - - 移箱-箱库存的变更 - - - - - 移箱-箱库存的变更 @@ -3325,14 +3309,6 @@ - - - 入库回退上下架-箱库存的变更 - - - - - 入库回退上下架-箱库存的变更 @@ -3349,14 +3325,6 @@ - - - 盘点单-箱库存的变更 - - - - - 入库单-箱库存的变更 @@ -3365,14 +3333,6 @@ - - - 入库单-箱库存变更 - - - - - 出库单-箱库存变更 @@ -3381,7 +3341,47 @@ - + + + 改箱-箱库存的变更 + + + + + + + + 移箱-箱库存的变更 + + + + + + + + 入库回退上下架-箱库存的变更 + + + + + + + + 盘点单-箱库存的变更 + + + + + + + + 入库单-箱库存变更 + + + + + + 出库单-箱库存变更 diff --git a/src/WMS.Web.Domain/Services/BoxInventoryService.cs b/src/WMS.Web.Domain/Services/BoxInventoryService.cs index 3d6f8209..66e1bdce 100644 --- a/src/WMS.Web.Domain/Services/BoxInventoryService.cs +++ b/src/WMS.Web.Domain/Services/BoxInventoryService.cs @@ -35,13 +35,403 @@ namespace WMS.Web.Domain.Services _boxInventoryRepositories = boxInventoryRepositories; } + + /// /// 改箱-箱库存的变更 /// /// /// /// - private async Task GenerateChangeBox(List dtoDatas, bool isTransaction) + public async Task GenerateChangeBox(List dtoDatas, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoDatas == null || dtoDatas.Count == 0) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + //2.原来箱库存集合 + var boxIds = dtoDatas.Where(x => x.SrcBoxId != 0).GroupBy(x => x.SrcBoxId).Select(x => x.Key).ToList(); + var sourceBoxInventorys = await _boxInventoryRepositories.GetList(boxIds); + + //2.1目标箱库存集合 + var targetBoxIds = dtoDatas.GroupBy(x => x.DestBoxId).Select(x => x.Key).ToList(); + var targetBoxInventorys = await _boxInventoryRepositories.GetList(targetBoxIds); + + //2.2组合要生成的dto + var generateDtos = dtoDatas.GroupBy(x => new { x.SrcBoxId, x.DestBoxId, x.DestStockCode, x.DestSubStockId, x.DestBoxOrgCode }).Select(x => new BoxInventoryChangeGenerateDto() + { + BoxId = x.Key.SrcBoxId, + TargetBoxId = x.Key.DestBoxId, + StockCode = x.Key.DestStockCode, + SubStockId = x.Key.DestSubStockId, + TargetBoxOrgCode = x.Key.DestBoxOrgCode + + }).ToList(); + + //3.遍历:组装明细 + generateDtos.ForEach(x => + { + foreach (var item in dtoDatas) + { + //3.1原箱和目标箱是当前的 + if (item.SrcBoxId == x.BoxId && item.DestBoxId == x.TargetBoxId) + { + //3.2组装明细 + var det = new BoxInventoryDetailsChangeGenerateDto(); + det.MaterialId = item.MaterialId; + det.Qty = item.Qty; + det.SerialNumbers = item.SerialNumbers; + x.Details.Add(det); + } + } + }); + //4.开始处理 + return await this.ExeChangeBox(generateDtos, isTransaction); + } + + /// + /// 移箱-箱库存的变更 + /// + /// + /// + /// + public async Task GenerateMoveBox(List dtoDatas, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoDatas == null || dtoDatas.Count == 0) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + //2.箱库存集合 + var boxIds = dtoDatas.Where(x => x.BoxId != 0 && x.Type == MoveBoxType.Down).GroupBy(x => x.BoxId).Select(x => x.Key).ToList(); + var boxInventorys = await _boxInventoryRepositories.GetList(boxIds); + + //2.1箱基本信息 + var boxs = await _boxRepositories.GetEntityList(boxIds); + + //2.2组合要生成的dto + var generateDtoList = new List(); + foreach (var item in dtoDatas) + { + var generateDto = new BoxInventoryMoveGenerateDto(); + generateDto.BoxId = item.BoxId; + generateDto.OrgCode = item.OrgCode; + generateDto.StockCode = item.StockCode; + generateDto.SubStockId = item.Type == MoveBoxType.Up ? item.DestSubStockId : item.SrcSubStockId; + generateDto.InventoryInOutType = item.Type == MoveBoxType.Down ? (int)InventoryInOutType.Out : (int)InventoryInOutType.In; + generateDtoList.Add(generateDto); + + } + //4.开始处理 + return await this.ExeMoveBox(generateDtoList, isTransaction); + } + + /// + /// 入库回退上下架-箱库存的变更 + /// + /// + /// + /// + public async Task GenerateBackBox(List dtoDatas, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoDatas == null || dtoDatas.Count == 0) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + var generateDtoList = new List(); + + #region 入库组装 + //入库的明细 + var dtoDetails_in = dtoDatas.Where(x => x.Type == BackRecordType.OutstockOn).SelectMany(x => x.Details).ToList(); + + //2.1组织:头部 + var generateDtoList_in = dtoDetails_in.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }) + .Select(x => new BoxInventoryBackGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = x.Key.OrgCode, + StockCode = x.Key.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutType = (int)InventoryInOutType.In + }).ToList(); + + + //3.遍历:组装明细 + generateDtoList_in.ForEach(x => + { + foreach (var detItem in dtoDetails_in) + { + //3.1箱是当前的 + if (detItem.BoxId == x.BoxId) + { + //3.2组装明细 + var det = new BoxInventoryBackDetailsGenerateDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.Qty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + #endregion + + #region 出库组装 + //出库的明细 + var dtoDetails_out = dtoDatas.Where(x => x.Type == BackRecordType.InstockOff).SelectMany(x => x.Details).ToList(); + + //2.1组织:头部 + var generateDtoList_out = dtoDetails_out.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }) + .Select(x => new BoxInventoryBackGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = x.Key.OrgCode, + StockCode = x.Key.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutType = (int)InventoryInOutType.Out + }).ToList(); + + + //3.遍历:组装明细 + generateDtoList_out.ForEach(x => + { + foreach (var detItem in dtoDetails_out) + { + //3.1箱是当前的 + if (detItem.BoxId == x.BoxId) + { + //3.2组装明细 + var det = new BoxInventoryBackDetailsGenerateDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.Qty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + #endregion + generateDtoList.AddRange(generateDtoList_in); + generateDtoList.AddRange(generateDtoList_out); + //4.提交处理 + return await this.ExeBackBox(generateDtoList, isTransaction); + } + + /// + /// 盘点单-箱库存的变更 + /// + /// + /// + /// + public async Task GenerateTakeBox(List dtoDatas, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoDatas == null || dtoDatas.Count == 0) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + //2.组装:入库数据 + var generateDtoList_in = dtoDatas.Where(x => x.ResultType == TakeStockType.Profit).GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }).Select(x => new BoxInventoryTakeGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = x.Key.OrgCode, + StockCode = x.Key.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutType = (int)InventoryInOutType.In + }).ToList(); + + //2.1.遍历:组装明细 + generateDtoList_in.ForEach(x => + { + foreach (var detItem in dtoDatas) + { + //3.1箱是当前的 + if (detItem.BoxId == x.BoxId) + { + //3.2组装明细 + var det = new BoxInventoryTakeDetailsGenerateDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.FinalQty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + + //3.组装:出库数据 + var generateDtoList_out = dtoDatas.Where(x => x.ResultType == TakeStockType.Loss).GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }).Select(x => new BoxInventoryTakeGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = x.Key.OrgCode, + StockCode = x.Key.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutType = (int)InventoryInOutType.Out + }).ToList(); + + //3.1遍历:组装明细 + generateDtoList_in.ForEach(x => + { + foreach (var detItem in dtoDatas) + { + //3.1箱是当前的 + if (detItem.BoxId == x.BoxId) + { + //3.2组装明细 + var det = new BoxInventoryTakeDetailsGenerateDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.FinalQty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + + //整合一起 + var generateDtoList = new List(); + generateDtoList.AddRange(generateDtoList_in); + generateDtoList.AddRange(generateDtoList_out); + //提交处理 + return await this.ExeTakeBox(generateDtoList, isTransaction); + } + + /// + /// 入库单-箱库存的变更 + /// + /// + /// + /// + public async Task GenerateInStockBox(List dtoDatas, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoDatas == null || dtoDatas.Count == 0) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + #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 }) + .Select(x => new BoxInventoryGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = x.Key.OrgCode, + StockCode = x.Key.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutMethod = (int)InventoryInOutMethod.Box, + InventoryInOutType = (int)InventoryInOutType.In + }).ToList(); + + //2.1.遍历:组装明细 + generateDtoList_Metod_Box.ForEach(x => + { + foreach (var detItem in dtoDatas_details_Method_box) + { + //2.1箱是当前的 + if (detItem.BoxId == x.BoxId) + { + //2.2组装明细 + var det = new BoxInventoryGenerateDetailsDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.Qty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + #endregion + + #region 按产品 + //3.组装-按产品入库 + var dtoDatas_details_Method_Product = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Box).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(); + generateDtoList.AddRange(generateDtoList_Metod_Box); + generateDtoList.AddRange(generateDtoList_Metod_Product); + //提交处理 + return await this.ExeInStockBox(generateDtoList, isTransaction); + } + + /// + /// 出库单-箱库存变更 + /// + /// + /// + /// + public async Task GenerateOutStockBox(OutStock dtoData, bool isTransaction) + { + //1.判断来源数据是否存在 + if (dtoData == null) + return Result.ReFailure(ResultCodes.InventoryNoSourceError); + + //2.组装 + var generateDtoList = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => new { x.BoxId, x.SubStockId }) + .Select(x => new BoxInventoryGenerateDto() + { + BoxId = x.Key.BoxId, + OrgCode = dtoData.OrgCode, + StockCode = dtoData.StockCode, + SubStockId = x.Key.SubStockId, + InventoryInOutMethod = (int)dtoData.Method, + InventoryInOutType = (int)InventoryInOutType.Out + + }).ToList(); + //3.组装明细 + generateDtoList.ForEach(x => + { + //3.1先通过中间层的明细的箱明细找到中间层明细的IDS + var current_materialDetails_ids = dtoData.Details.SelectMany(t => t.BoxsDetails).Where(t => t.BoxId == x.BoxId).GroupBy(t => t.DetailId).Select(t => t.Key).ToList(); + //3.2再通过找到的IDS获取中间层的明细 + var current_materialDetails = dtoData.Details.Where(t => current_materialDetails_ids.Contains(t.Id)).ToList(); + //3.3遍历-组装箱库存要的dto明细 + if (current_materialDetails != null && current_materialDetails.Count != 0) + { + foreach (var detItem in current_materialDetails) + { + //2.2组装明细 + var det = new BoxInventoryGenerateDetailsDto(); + det.MaterialId = detItem.MaterialId; + det.Qty = detItem.Qty; + det.SerialNumbers = detItem.SerialNumbers; + x.Details.Add(det); + } + } + }); + + //提交处理 + return await this.ExeOutStockBox(generateDtoList, isTransaction); + } + /// + /// 改箱-箱库存的变更 + /// + /// + /// + /// + private async Task ExeChangeBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0) @@ -179,65 +569,13 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } - /// - /// 改箱-箱库存的变更 - /// - /// - /// - /// - public async Task GenerateChangeBox(List dtoDatas, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoDatas == null || dtoDatas.Count == 0) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - //2.原来箱库存集合 - var boxIds = dtoDatas.Where(x => x.SrcBoxId != 0).GroupBy(x => x.SrcBoxId).Select(x => x.Key).ToList(); - var sourceBoxInventorys = await _boxInventoryRepositories.GetList(boxIds); - - //2.1目标箱库存集合 - var targetBoxIds = dtoDatas.GroupBy(x => x.DestBoxId).Select(x => x.Key).ToList(); - var targetBoxInventorys = await _boxInventoryRepositories.GetList(targetBoxIds); - - //2.2组合要生成的dto - var generateDtos = dtoDatas.GroupBy(x => new { x.SrcBoxId, x.DestBoxId, x.DestStockCode, x.DestSubStockId, x.DestBoxOrgCode }).Select(x => new BoxInventoryChangeGenerateDto() - { - BoxId = x.Key.SrcBoxId, - TargetBoxId = x.Key.DestBoxId, - StockCode = x.Key.DestStockCode, - SubStockId = x.Key.DestSubStockId, - TargetBoxOrgCode = x.Key.DestBoxOrgCode - - }).ToList(); - - //3.遍历:组装明细 - generateDtos.ForEach(x => - { - foreach (var item in dtoDatas) - { - //3.1原箱和目标箱是当前的 - if (item.SrcBoxId == x.BoxId && item.DestBoxId == x.TargetBoxId) - { - //3.2组装明细 - var det = new BoxInventoryDetailsChangeGenerateDto(); - det.MaterialId = item.MaterialId; - det.Qty = item.Qty; - det.SerialNumbers = item.SerialNumbers; - x.Details.Add(det); - } - } - }); - //4.开始处理 - return await this.GenerateChangeBox(generateDtos, isTransaction); - } - /// /// 移箱-箱库存的变更 /// /// /// /// - private async Task GenerateMoveBox(List dtoDatas, bool isTransaction) + private async Task ExeMoveBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0) @@ -352,49 +690,13 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } - /// - /// 移箱-箱库存的变更 - /// - /// - /// - /// - public async Task GenerateMoveBox(List dtoDatas, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoDatas == null || dtoDatas.Count == 0) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - //2.箱库存集合 - var boxIds = dtoDatas.Where(x => x.BoxId != 0 && x.Type == MoveBoxType.Down).GroupBy(x => x.BoxId).Select(x => x.Key).ToList(); - var boxInventorys = await _boxInventoryRepositories.GetList(boxIds); - - //2.1箱基本信息 - var boxs = await _boxRepositories.GetEntityList(boxIds); - - //2.2组合要生成的dto - var generateDtoList = new List(); - foreach (var item in dtoDatas) - { - var generateDto = new BoxInventoryMoveGenerateDto(); - generateDto.BoxId = item.BoxId; - generateDto.OrgCode = item.OrgCode; - generateDto.StockCode = item.StockCode; - generateDto.SubStockId = item.Type == MoveBoxType.Up ? item.DestSubStockId : item.SrcSubStockId; - generateDto.InventoryInOutType = item.Type == MoveBoxType.Down ? (int)InventoryInOutType.Out : (int)InventoryInOutType.In; - generateDtoList.Add(generateDto); - - } - //4.开始处理 - return await this.GenerateMoveBox(generateDtoList, isTransaction); - } - /// /// 入库回退上下架-箱库存的变更 /// /// /// /// - private async Task GenerateBackBox(List dtoDatas, bool isTransaction) + private async Task ExeBackBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0) @@ -507,178 +809,13 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } - /// - /// 入库回退上下架-箱库存的变更 - /// - /// - /// - /// - public async Task GenerateBackBox(List dtoDatas, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoDatas == null || dtoDatas.Count == 0) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - var generateDtoList = new List(); - - #region 入库组装 - //入库的明细 - var dtoDetails_in = dtoDatas.Where(x => x.Type == BackRecordType.OutstockOn).SelectMany(x => x.Details).ToList(); - - //2.1组织:头部 - var generateDtoList_in = dtoDetails_in.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }) - .Select(x => new BoxInventoryBackGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = x.Key.OrgCode, - StockCode = x.Key.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutType = (int)InventoryInOutType.In - }).ToList(); - - - //3.遍历:组装明细 - generateDtoList_in.ForEach(x => - { - foreach (var detItem in dtoDetails_in) - { - //3.1箱是当前的 - if (detItem.BoxId == x.BoxId) - { - //3.2组装明细 - var det = new BoxInventoryBackDetailsGenerateDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.Qty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - #endregion - - #region 出库组装 - //出库的明细 - var dtoDetails_out = dtoDatas.Where(x => x.Type == BackRecordType.InstockOff).SelectMany(x => x.Details).ToList(); - - //2.1组织:头部 - var generateDtoList_out = dtoDetails_out.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }) - .Select(x => new BoxInventoryBackGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = x.Key.OrgCode, - StockCode = x.Key.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutType = (int)InventoryInOutType.Out - }).ToList(); - - - //3.遍历:组装明细 - generateDtoList_out.ForEach(x => - { - foreach (var detItem in dtoDetails_out) - { - //3.1箱是当前的 - if (detItem.BoxId == x.BoxId) - { - //3.2组装明细 - var det = new BoxInventoryBackDetailsGenerateDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.Qty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - #endregion - generateDtoList.AddRange(generateDtoList_in); - generateDtoList.AddRange(generateDtoList_out); - //4.提交处理 - return await this.GenerateBackBox(generateDtoList, isTransaction); - } - - /// - /// 盘点单-箱库存的变更 - /// - /// - /// - /// - public async Task GenerateTakeBox(List dtoDatas, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoDatas == null || dtoDatas.Count == 0) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - //2.组装:入库数据 - var generateDtoList_in = dtoDatas.Where(x => x.ResultType == TakeStockType.Profit).GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }).Select(x => new BoxInventoryTakeGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = x.Key.OrgCode, - StockCode = x.Key.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutType = (int)InventoryInOutType.In - }).ToList(); - - //2.1.遍历:组装明细 - generateDtoList_in.ForEach(x => - { - foreach (var detItem in dtoDatas) - { - //3.1箱是当前的 - if (detItem.BoxId == x.BoxId) - { - //3.2组装明细 - var det = new BoxInventoryTakeDetailsGenerateDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.FinalQty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - - //3.组装:出库数据 - var generateDtoList_out = dtoDatas.Where(x => x.ResultType == TakeStockType.Loss).GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId }).Select(x => new BoxInventoryTakeGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = x.Key.OrgCode, - StockCode = x.Key.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutType = (int)InventoryInOutType.Out - }).ToList(); - - //3.1遍历:组装明细 - generateDtoList_in.ForEach(x => - { - foreach (var detItem in dtoDatas) - { - //3.1箱是当前的 - if (detItem.BoxId == x.BoxId) - { - //3.2组装明细 - var det = new BoxInventoryTakeDetailsGenerateDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.FinalQty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - - //整合一起 - var generateDtoList = new List(); - generateDtoList.AddRange(generateDtoList_in); - generateDtoList.AddRange(generateDtoList_out); - //提交处理 - return await this.GenerateTakeBox(generateDtoList, isTransaction); - } - /// /// 盘点单-箱库存的变更 /// /// /// /// - private async Task GenerateTakeBox(List dtoDatas, bool isTransaction) + private async Task ExeTakeBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0) @@ -799,99 +936,13 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } - /// - /// 入库单-箱库存的变更 - /// - /// - /// - /// - public async Task GenerateInStockBox(List dtoDatas, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoDatas == null || dtoDatas.Count == 0) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - #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 }) - .Select(x => new BoxInventoryGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = x.Key.OrgCode, - StockCode = x.Key.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutMethod = (int)InventoryInOutMethod.Box, - InventoryInOutType = (int)InventoryInOutType.In - }).ToList(); - - //2.1.遍历:组装明细 - generateDtoList_Metod_Box.ForEach(x => - { - foreach (var detItem in dtoDatas_details_Method_box) - { - //2.1箱是当前的 - if (detItem.BoxId == x.BoxId) - { - //2.2组装明细 - var det = new BoxInventoryGenerateDetailsDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.Qty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - #endregion - - #region 按产品 - //3.组装-按产品入库 - var dtoDatas_details_Method_Product = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Box).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(); - generateDtoList.AddRange(generateDtoList_Metod_Box); - generateDtoList.AddRange(generateDtoList_Metod_Product); - //提交处理 - return await this.GenerateInStockBox(generateDtoList, isTransaction); - } - /// /// 入库单-箱库存变更 /// /// /// /// - private async Task GenerateInStockBox(List dtoDatas, bool isTransaction) + private async Task ExeInStockBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0) @@ -1010,63 +1061,13 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } - /// - /// 出库单-箱库存变更 - /// - /// - /// - /// - public async Task GenerateOutStockBox(OutStock dtoData, bool isTransaction) - { - //1.判断来源数据是否存在 - if (dtoData == null) - return Result.ReFailure(ResultCodes.InventoryNoSourceError); - - //2.组装 - var generateDtoList = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => new { x.BoxId, x.SubStockId }) - .Select(x => new BoxInventoryGenerateDto() - { - BoxId = x.Key.BoxId, - OrgCode = dtoData.OrgCode, - StockCode = dtoData.StockCode, - SubStockId = x.Key.SubStockId, - InventoryInOutMethod = (int)dtoData.Method, - InventoryInOutType = (int)InventoryInOutType.Out - - }).ToList(); - //3.组装明细 - generateDtoList.ForEach(x => - { - //3.1先通过中间层的明细的箱明细找到中间层明细的IDS - var current_materialDetails_ids = dtoData.Details.SelectMany(t => t.BoxsDetails).Where(t => t.BoxId == x.BoxId).GroupBy(t => t.DetailId).Select(t => t.Key).ToList(); - //3.2再通过找到的IDS获取中间层的明细 - var current_materialDetails = dtoData.Details.Where(t => current_materialDetails_ids.Contains(t.Id)).ToList(); - //3.3遍历-组装箱库存要的dto明细 - if (current_materialDetails != null && current_materialDetails.Count != 0) - { - foreach (var detItem in current_materialDetails) - { - //2.2组装明细 - var det = new BoxInventoryGenerateDetailsDto(); - det.MaterialId = detItem.MaterialId; - det.Qty = detItem.Qty; - det.SerialNumbers = detItem.SerialNumbers; - x.Details.Add(det); - } - } - }); - - //提交处理 - return await this.GenerateOutStockBox(generateDtoList, isTransaction); - } - /// /// 出库单-箱库存变更 /// /// /// /// - private async Task GenerateOutStockBox(List dtoDatas, bool isTransaction) + private async Task ExeOutStockBox(List dtoDatas, bool isTransaction) { //1.判断来源数据是否存在 if (dtoDatas == null || dtoDatas.Count == 0)