From b6648c6f3559e42653822415ba73c433da1b4876 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 25 Aug 2023 17:32:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E6=9F=A5=E8=AF=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WmsStockReportService.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs index e9809af7..a44d8e4b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Dynamic; using System.Linq; using System.Text; @@ -50,16 +51,18 @@ namespace Tnb.WarehouseMgr }, true) .ToListAsync(); var carryCodes = await _db.Queryable().ToListAsync(); + var storeMap = items.DistinctBy(x=> new {x.warehouse_id,x.material_id }).ToDictionary(x => $"{x.warehouse_id}{x.material_id}", x => x); + var result = items.GroupBy(g => new { g.warehouse_id, g.material_id }).Select(itGroup => { + storeMap.TryGetValue($"{itGroup.Key.warehouse_id}{itGroup.Key.material_id}", out var report); WmsStockReportH stockReport = new(); - stockReport.material_code = items.Find(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id)?.material_code; - stockReport.mater_name = items.Find(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id)?.mater_name ?? string.Empty; + stockReport.material_code = report?.material_code ?? ""; + stockReport.mater_name = report?.mater_name ?? ""; stockReport.existing_stock_qty = itGroup.Sum(d => d.codeqty); - stockReport.max_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.max_stock; - stockReport.safe_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.safe_stock; - stockReport.min_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.min_stock; - stockReport.min_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.min_stock; + stockReport.max_stock = report?.max_stock ?? 0; + stockReport.safe_stock = report?.safe_stock ?? 0; + stockReport.min_stock = report?.min_stock ?? 0; stockReport.storage_valid_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.storage_valid_day; stockReport.early_warn_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.early_warn_day; stockReport.create_id = _userManager.UserId; @@ -86,6 +89,7 @@ namespace Tnb.WarehouseMgr return stockReport; }); + var pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(); SqlSugarPagedList pagedList = new() { From 778a7c7819c86265af32de1ecf2bd5700b4c3d1b Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 25 Aug 2023 17:35:22 +0800 Subject: [PATCH 2/2] 1 --- WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs index a44d8e4b..ab1a2f9c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs @@ -51,11 +51,11 @@ namespace Tnb.WarehouseMgr }, true) .ToListAsync(); var carryCodes = await _db.Queryable().ToListAsync(); - var storeMap = items.DistinctBy(x=> new {x.warehouse_id,x.material_id }).ToDictionary(x => $"{x.warehouse_id}{x.material_id}", x => x); + var storeMap = items.DistinctBy(x=> new {x.warehouse_id,x.material_id }).ToDictionary(x => new {x.warehouse_id,x.material_id }, x => x); var result = items.GroupBy(g => new { g.warehouse_id, g.material_id }).Select(itGroup => { - storeMap.TryGetValue($"{itGroup.Key.warehouse_id}{itGroup.Key.material_id}", out var report); + storeMap.TryGetValue(itGroup.Key, out var report); WmsStockReportH stockReport = new(); stockReport.material_code = report?.material_code ?? ""; stockReport.mater_name = report?.mater_name ?? "";