From 00f01db9507687a0a0163d65b587458a9d4b0f4a Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Fri, 9 Aug 2024 14:08:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E5=8D=87=E9=99=8D=E6=9C=BA=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96=20=E5=85=AB=E5=B7=A5=E4=BD=8D?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E4=BC=98=E5=8C=96=20=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 57 +++--- .../Entity/WmsStockReportCode.cs | 50 +++++- .../Entity/WmsStockReportH.cs | 127 ++++++++----- .../Entity/WmsStockReportH.part.cs | 14 +- .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 13 +- .../WmsCarryStockReportService.cs | 4 +- .../Tnb.WarehouseMgr/WmsStockReportService.cs | 167 ++++++++++++------ 7 files changed, 286 insertions(+), 146 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 1e3a1939..3aefd58c 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -946,6 +946,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { var strs = dic.Where(p => p.Key == key).First().Value; + JObject reObj = await GetObjectTag(key, strs[0]); if (reObj == null) continue; @@ -981,9 +982,9 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA result = "LX" + result.Replace("\r", ""); } - if (timestamp_judgeCode > timestamp_code) + if (timestamp_judgeCode < timestamp_code) { - LoggerSSX.LogInformation($"【定时任务SSXcode】下升降机入中储仓 判定料箱{result}的条码判断请求信号时间{timestamp_judgeCode.ToString("yyyy-MM-dd HH:mm:ss")} 大于条码更新的时间{timestamp_code.ToString("yyyy-MM-dd HH:mm:ss")},将跳过此次执行"); + LoggerSSX.LogInformation($"【定时任务SSXcode】下升降机入中储仓 判定料箱{result}的条码判断请求信号时间{timestamp_judgeCode.ToString("yyyy-MM-dd HH:mm:ss")} 早于条码更新的时间{timestamp_code.ToString("yyyy-MM-dd HH:mm:ss")},将跳过此次执行"); continue; } @@ -2579,41 +2580,41 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA public Task StartAsync(CancellationToken cancellationToken) { - //CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); - //Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - SSXcodetimer = new Timer(SSXcode, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); - //// 八工位缓存区补充空托盘 - //BGWCarrySupplementtimer = new Timer(BGWCarrySupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); + Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); + SSXcodetimer = new Timer(SSXcode, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); + // 八工位缓存区补充空托盘 + BGWCarrySupplementtimer = new Timer(BGWCarrySupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //// 供料叠盘机空托盘自动入库 - //YCLGLDPJInstocktimer = new Timer(YCLGLDPJInstock, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); + // 供料叠盘机空托盘自动入库 + YCLGLDPJInstocktimer = new Timer(YCLGLDPJInstock, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); - //// 外协叠盘机空托盘自动入库 - //YCLWXDPJInstocktimer = new Timer(YCLWXDPJInstock, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30)); + // 外协叠盘机空托盘自动入库 + YCLWXDPJInstocktimer = new Timer(YCLWXDPJInstock, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30)); - //// 二楼上升降机 - //Floor2UpMachinecodetimer = new Timer(Floor2UpMachinecode, null, TimeSpan.Zero, TimeSpan.FromSeconds(20)); + // 二楼上升降机 + Floor2UpMachinecodetimer = new Timer(Floor2UpMachinecode, null, TimeSpan.Zero, TimeSpan.FromSeconds(20)); - //// 二楼料架配送 - //Floor2timer送空托到上升降区 = new Timer(送空托到上升降区, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //Floor2timer送满托到下升降区 = new Timer(送满托到下升降区, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); - //Floor2timer移走上升降区未生成预任务且满托的料架 = new Timer(移走上升降区未生成预任务且满托的料架, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //Floor2timer移走下升降区未生成预任务且空托的料架 = new Timer(移走下升降区未生成预任务且空托的料架, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); + // 二楼料架配送 + Floor2timer送空托到上升降区 = new Timer(送空托到上升降区, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + Floor2timer送满托到下升降区 = new Timer(送满托到下升降区, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); + Floor2timer移走上升降区未生成预任务且满托的料架 = new Timer(移走上升降区未生成预任务且满托的料架, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + Floor2timer移走下升降区未生成预任务且空托的料架 = new Timer(移走下升降区未生成预任务且空托的料架, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)); - //GenTaskExecutetimer = new Timer(GenTaskExecute, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + GenTaskExecutetimer = new Timer(GenTaskExecute, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //// 停用 - ////PackOutstockServicetimer = new Timer(PackOutstockService, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); + // 停用 + //PackOutstockServicetimer = new Timer(PackOutstockService, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - //ElevatorTaskExceptionHandleThread = new Thread(ElevatorTaskExceptionHandle); - //ElevatorTaskExceptionHandleThread.Start(); + ElevatorTaskExceptionHandleThread = new Thread(ElevatorTaskExceptionHandle); + ElevatorTaskExceptionHandleThread.Start(); - //Floor4DMJ2MJXtimer = new Timer(Floor4DMJ2MJX, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //Floor4MJX2MJCtimer = new Timer(Floor4MJX2MJC, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //Floor4DMC2CPKtimer = new Timer(Floor4DMC2CPK, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + Floor4DMJ2MJXtimer = new Timer(Floor4DMJ2MJX, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + Floor4MJX2MJCtimer = new Timer(Floor4MJX2MJC, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + Floor4DMC2CPKtimer = new Timer(Floor4DMC2CPK, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //F2KTPsupplementtimer = new Timer(F2KTPsupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - //YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(185)); + F2KTPsupplementtimer = new Timer(F2KTPsupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(185)); return Task.CompletedTask; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportCode.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportCode.cs index 28376aa5..69c50463 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportCode.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportCode.cs @@ -19,15 +19,15 @@ public partial class WmsStockReportCode : BaseEntity /// public string? report_id { get; set; } - /// - /// 载具ID - /// - public string? carry_id { get; set; } + ///// + ///// 载具ID + ///// + //public string? carry_id { get; set; } - /// - /// 载具编号 - /// - public string? carry_code { get; set; } + ///// + ///// 载具编号 + ///// + //public string? carry_code { get; set; } /// /// 物料ID @@ -52,7 +52,7 @@ public partial class WmsStockReportCode : BaseEntity /// /// 条码数量 /// - public decimal? codeqty { get; set; } + public decimal codeqty { get; set; } /// /// 单位ID @@ -84,4 +84,36 @@ public partial class WmsStockReportCode : BaseEntity /// public DateTime? time_stamp { get; set; } + /// + /// 规格型号 + /// + public string? material_specification { get; set; } + /// + /// 箱号 + /// + public string? container_no { get; set; } + /// + /// 供应商编码 + /// + public string? supplier_code { get; set; } + /// + /// 供应商名称 + /// + public string? supplier_name { get; set; } + + /// + /// 仓库ID + /// + public string? warehouse_id { get; set; } + + /// + /// 仓库编码 + /// + public string? warehouse_code { get; set; } + + /// + /// 仓库名称 + /// + public string? warehouse_name { get; set; } + } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.cs index 683f1780..3fd95b23 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.cs @@ -29,45 +29,86 @@ public partial class WmsStockReportH : BaseEntity /// public string? material_code { get; set; } + /// + /// 规格型号 + /// + public string? material_specification { get; set; } + /// + /// 箱号 + /// + public string? container_no { get; set; } + /// + /// 供应商编码 + /// + public string? supplier_code { get; set; } + /// + /// 供应商名称 + /// + public string? supplier_name { get; set; } + /// /// 仓库ID /// public string? warehouse_id { get; set; } /// - /// 现有库存 + /// 仓库编码 /// - public decimal? existing_stock_qty { get; set; } + public string? warehouse_code { get; set; } /// - /// 最大库存 + /// 仓库名称 /// - public int? max_stock { get; set; } + public string? warehouse_name { get; set; } /// - /// 安全库存 + /// 单位ID /// - public int? safe_stock { get; set; } + public string unit_id { get; set; } = string.Empty; /// - /// 最小库存 + /// 单位代码 /// - public int? min_stock { get; set; } - + public string unit_code { get; set; } = string.Empty; /// - /// 库存有效期(天) + /// 批次 /// - public int? storage_valid_day { get; set; } + public string code_batch { get; set; } = string.Empty; - /// - /// 预警提前期(天) - /// - public int? early_warn_day { get; set; } + ///// + ///// 现有库存 + ///// + //public decimal? existing_stock_qty { get; set; } - /// - /// 过期预警数量 - /// - public decimal? expired_warning_qty { get; set; } + ///// + ///// 最大库存 + ///// + //public int? max_stock { get; set; } + + ///// + ///// 安全库存 + ///// + //public int? safe_stock { get; set; } + + ///// + ///// 最小库存 + ///// + //public int? min_stock { get; set; } + + ///// + ///// 库存有效期(天) + ///// + //public int? storage_valid_day { get; set; } + + ///// + ///// 预警提前期(天) + ///// + //public int? early_warn_day { get; set; } + + ///// + ///// 过期预警数量 + ///// + //public decimal? expired_warning_qty { get; set; } /// /// 创建用户 @@ -79,35 +120,35 @@ public partial class WmsStockReportH : BaseEntity /// public DateTime? create_time { get; set; } - /// - /// 修改用户 - /// - public string? modify_id { get; set; } + ///// + ///// 修改用户 + ///// + //public string? modify_id { get; set; } - /// - /// 修改时间 - /// - public DateTime? modify_time { get; set; } + ///// + ///// 修改时间 + ///// + //public DateTime? modify_time { get; set; } - /// - /// 扩展 - /// - public string? extras { get; set; } + ///// + ///// 扩展 + ///// + //public string? extras { get; set; } - /// - /// 时间戳 - /// - public DateTime? timestamp { get; set; } + ///// + ///// 时间戳 + ///// + //public DateTime? timestamp { get; set; } - /// - /// 流程任务Id - /// - public string? f_flowtaskid { get; set; } + ///// + ///// 流程任务Id + ///// + //public string? f_flowtaskid { get; set; } - /// - /// 流程引擎Id - /// - public string? f_flowid { get; set; } + ///// + ///// 流程引擎Id + ///// + //public string? f_flowid { get; set; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.part.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.part.cs index 984ecc3c..42af197c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.part.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsStockReportH.part.cs @@ -11,13 +11,13 @@ public partial class WmsStockReportH /// 物料名称 /// [SugarColumn(IsIgnore = true)] - public string mater_name { get; set; } - /// - /// 明细列表 - /// - [SugarColumn(IsIgnore = true)] - public List Details { get; set; } - [SugarColumn(IsIgnore = true)] + public string material_name { get; set; } + ///// + ///// 明细列表 + ///// + //[SugarColumn(IsIgnore = true)] + //public List Details { get; set; } + //[SugarColumn(IsIgnore = true)] public decimal codeqty { get; set; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index fee6a9e7..6703d5e7 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -16,6 +16,7 @@ using Newtonsoft.Json; using Npgsql; using Senparc.Weixin.MP.AdvancedAPIs.Card; using SqlSugar; +using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; @@ -145,7 +146,6 @@ namespace Tnb.WarehouseMgr [HttpPost] public async Task GetInfoByCode(string code) { - var data = await _db.Queryable().Where(p => p.barcode == code).FirstAsync(); if (data == null) throw new AppFriendlyException("没有条码信息", 500); @@ -169,6 +169,11 @@ namespace Tnb.WarehouseMgr { throw new Exception($"托盘{input.carrycode}不存在!"); } + BasLocation carrryLoc = await _db.Queryable().Where(r => r.id == carry.location_id).FirstAsync(); + if (carrryLoc != null && carrryLoc.is_type == "0") + { + throw new Exception($"托盘{carry.carry_code}在存储库位中,不能绑定!"); + } var _WmsCarryCode = _db.Queryable().Where(it => it.carry_id == carry.id).OrderByDescending(it => it.id).First(); if (_WmsCarryCode != null) @@ -230,7 +235,13 @@ namespace Tnb.WarehouseMgr db = dbConn; try { + WmsCarryH? carry = await db.Queryable().SingleAsync(it => it.carry_code == input.carrycode); + if (carry == null) + { + throw new Exception($"托盘{carry.carry_code}不存在!"); + } + List WmsCarryCodes = new List(); foreach (var detail in input.details) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs index 3f7e3105..0dc9458e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs @@ -71,7 +71,7 @@ namespace Tnb.WarehouseMgr carry_type = d.carrystd_name, location_code = a.location_code, location_name = a.location_name, - location_status = b.is_lock == 1 ? "锁定" : "未锁定", + location_status = a.is_lock == 1 ? "锁定" : "未锁定", instock_time = b.instock_time != null ? b.instock_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", barcode = e.barcode, code_batch = e.code_batch, @@ -111,7 +111,7 @@ namespace Tnb.WarehouseMgr carry_type = d.carrystd_name, location_code = a.location_code, location_name = a.location_name, - location_status = b.is_lock == 1 ? "锁定" : "未锁定", + location_status = a.is_lock == 1 ? "锁定" : "未锁定", instock_time = b.instock_time != null ? b.instock_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", barcode = f.barcode, code_batch = f.code_batch, diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs index 99ef65d1..12aae692 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs @@ -5,10 +5,12 @@ using JNPF.Common.Security; using JNPF.VisualDev; using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; using Mapster; +using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Enums; namespace Tnb.WarehouseMgr @@ -26,72 +28,125 @@ namespace Tnb.WarehouseMgr { _db = repository.AsSugarClient(); _userManager = userManager; - OverideFuncs.GetListAsync = GetListAsync; } - private async Task GetListAsync(VisualDevModelListQueryInput input) + + [HttpPost] + public async Task MaterialStock(VisualDevModelListQueryInput input) { - var materialCode = ""; + var supplier_code = ""; + var code_batch = ""; + var material_specification = ""; if (!input.queryJson.IsNullOrWhiteSpace()) { - materialCode = JObject.Parse(input.queryJson).Value(nameof(WmsCarryCode.material_code)); + supplier_code = JObject.Parse(input.queryJson).Value("supplier_code"); + code_batch = JObject.Parse(input.queryJson).Value(nameof(WmsCarryCode.code_batch)); + material_specification = JObject.Parse(input.queryJson).Value(nameof(WmsCarryCode.material_specification)); } - List items = await _db.Queryable().InnerJoin((a, b) => a.material_id == b.id) - .InnerJoin((a, b, c) => b.id == c.material_id) - .InnerJoin((a, b, c, d) => a.carry_id == d.id) - .InnerJoin((a, b, c, d, e) => d.location_id == e.id) - .Where((a, b, c, d, e) => e.is_type == ((int)EnumLocationType.存储库位).ToString()) - .WhereIF(!string.IsNullOrEmpty(materialCode), (a, b, c, d, e) => a.material_code.Contains(materialCode)) - .Select((a, b, c, d, e) => new WmsStockReportH - { - warehouse_id = a.warehouse_id, - mater_name = b.name, - create_time = a.create_time, - create_id = a.create_id, - }, true) - .ToListAsync(); - List carryCodes = await _db.Queryable().ToListAsync(); - var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id }).ToDictionary(x => new { x.warehouse_id, x.material_id }, x => x); - - IEnumerable result = items.GroupBy(g => new { g.warehouse_id, g.material_id }).Select(itGroup => + IEnumerable result; + if (string.IsNullOrEmpty(supplier_code)) { - _ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? report); - WmsStockReportH stockReport = new() + List items = await _db.Queryable().InnerJoin((a, b) => a.carry_id == b.id) + .InnerJoin((a, b, c) => b.location_id == c.id).InnerJoin((a, b, c, d) => c.wh_id == d.id) + .InnerJoin((a, b, c, d, e) => e.barcode == a.barcode) + .InnerJoin((a, b, c, d, e, f) => f.id == e.material_id) + .LeftJoin((a, b, c, d, e, f, g) => e.require_id == g.id) + .LeftJoin((a, b, c, d, e, f, g, h) => h.id == g.bill_id) + .WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification)) + .WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch)) + .Select((a, b, c, d, e, f, g, h) => new WmsStockReportH { - material_code = report?.material_code ?? "", - mater_name = report?.mater_name ?? "", - existing_stock_qty = itGroup.Sum(d => d.codeqty), - max_stock = report?.max_stock ?? 0, - safe_stock = report?.safe_stock ?? 0, - min_stock = report?.min_stock ?? 0, - storage_valid_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.storage_valid_day, - early_warn_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.early_warn_day, - create_id = _userManager.UserId, - create_time = DateTime.Now - }; - if (stockReport.storage_valid_day.HasValue) - { - decimal expired_warning_qty = 0; - foreach (WmsStockReportH? item in itGroup) - { - if (DateTime.Now.Subtract(item.create_time.Value).TotalDays >= (item.storage_valid_day - item.early_warn_day)) - { - expired_warning_qty += item.codeqty; - } - } - stockReport.expired_warning_qty = expired_warning_qty; - } - List curCarryCodes = carryCodes.FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id); - stockReport.Details = curCarryCodes.Adapt>(); - stockReport.Details.ForEach(x => - { - x.id = SnowflakeIdHelper.NextId(); - x.report_id = stockReport.id; - }); - return stockReport; - }); + org_id = e.org_id, + warehouse_id = a.warehouse_id, + warehouse_code = d.whcode, + warehouse_name = d.whname, + material_name = f.name, + material_specification = f.material_specification, + container_no = f.container_no, + create_time = a.create_time, + create_id = a.create_id, + code_batch = a.code_batch, + supplier_code = "", + supplier_name = "", + }, true).ToListAsync(); + List carryCodes = await _db.Queryable().ToListAsync(); + var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch }, x => x); + + result = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch }).Select(itGroup => + { + _ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport); + + List curCarryCodes = carryCodes.FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id + && x.code_batch == itGroup.Key.code_batch); + curCarryCodes.ForEach(x => + { + stockReport.codeqty += x.codeqty; + }); + + //stockReport.Details = curCarryCodes.Adapt>(); + + //stockReport.codeqty = 0; + //stockReport.Details.ForEach(x => + //{ + // x.id = SnowflakeIdHelper.NextId(); + // x.report_id = stockReport.id; + // x.warehouse_id = stockReport.warehouse_id; + // x.warehouse_code = stockReport.warehouse_code; + // x.warehouse_name = stockReport.warehouse_name; + // x.material_specification = stockReport.material_specification; + // x.container_no = stockReport.container_no; + + // stockReport.codeqty += x.codeqty; + //}); + return stockReport; + }); + } + else + { + List items = await _db.Queryable().InnerJoin((a, b) => a.carry_id == b.id) + .InnerJoin((a, b, c) => b.location_id == c.id).InnerJoin((a, b, c, d) => c.wh_id == d.id) + .InnerJoin((a, b, c, d, e) => e.barcode == a.barcode) + .InnerJoin((a, b, c, d, e, f) => f.id == e.material_id) + .LeftJoin((a, b, c, d, e, f, g) => e.require_id == g.id) + .LeftJoin((a, b, c, d, e, f, g, h) => h.id == g.bill_id) + .WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification)) + .WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch)) + .WhereIF(!string.IsNullOrEmpty(supplier_code), (a, b, c, d, e, f, g, h) => h.supplier_code.Contains(supplier_code)) + .Select((a, b, c, d, e, f, g, h) => new WmsStockReportH + { + org_id = e.org_id, + warehouse_id = a.warehouse_id, + warehouse_code = d.whcode, + warehouse_name = d.whname, + material_name = f.name, + material_specification = f.material_specification, + container_no = f.container_no, + create_time = a.create_time, + create_id = a.create_id, + code_batch = a.code_batch, + supplier_code = h.supplier_code, + supplier_name = h.supplier_name, + }, true).ToListAsync(); + + List carryCodes = await _db.Queryable().ToListAsync(); + var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }, x => x); + + result = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch, g.supplier_code }).Select(itGroup => + { + _ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport); + + List curCarryCodes = carryCodes.Adapt>().FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id + && x.code_batch == itGroup.Key.code_batch && x.supplier_code == itGroup.Key.supplier_code); + curCarryCodes.ForEach(x => + { + stockReport.codeqty += x.codeqty; + }); + return stockReport; + }); + } + List pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(); SqlSugarPagedList pagedList = new()