From 36dadc09b52b531d99b5d3c26f6d7d6e0a472ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Wed, 13 Dec 2023 17:12:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/VmiAppService.cs | 72 ++++++++++++++----- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index c6852878..9080e7c3 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -12,6 +12,7 @@ using System.Text.Json; using System.Threading.Tasks; using AutoMapper; using ClosedXML.Excel; +using Dapper; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Wordprocessing; using EFCore.BulkExtensions; @@ -196,24 +197,64 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> Balance(RequestDto input) { + var sql2 = + "select count(number) number from(\n" + + "SELECT 1 number\n" + + "FROM Set_VmiLog\n" + + "GROUP BY VinCode, RealPartCode, ErpToLoc having SUM(ChangedQty)<>0) a\n"; + + + var sql = "select * from (\n" + + "SELECT t.vincode,t.realpartcode,t.erptoloc, shippingtime, receivetime,(isnull(t.[100],0) + isnull(t.[200],0) + isnull(t.[400],0) + isnull(t.[500],0)+isnull(t.[600],0)) sumqty,\n" + + "isnull(t.[100],0) ShippingQty,isnull(t.[200],0) SettleQty , isnull(t.[400],0) ReturnQty,isnull(t.[500],0) InputQty,isnull(t.[600],0) OutputQty\n" + + "FROM (\n" + + "SELECT VinCode, RealPartCode, ErpToLoc, [100], [200], [400], [500],[600]\n" + + "FROM (\n" + + "SELECT VinCode, RealPartCode, ErpToLoc, ChangedQty, LogType\n" + + "FROM Set_VmiLog\n" + + ") AS src\n" + + "PIVOT (\n" + + "SUM(ChangedQty)\n" + + "FOR LogType IN ([100],[200],[400],[500],[600])\n" + + ") AS piv\n" + + ") AS t\n" + + "left JOIN (\n" + + "SELECT VinCode, RealPartCode, ErpToLoc, MAX(BillTime) shippingtime\n" + + "FROM Set_VmiLog\n" + + "WHERE LogType = 100\n" + + "GROUP BY VinCode, RealPartCode, ErpToLoc\n" + + ") AS t1 ON t1.ErpToLoc = t.ErpToLoc AND t1.RealPartCode = t.RealPartCode AND t1.VinCode = t.VinCode\n" + + "left JOIN (\n" + + "SELECT VinCode, RealPartCode, ErpToLoc, MAX(BillTime) receivetime\n" + + "FROM Set_VmiLog\n" + + "WHERE LogType = 200\n" + + "GROUP BY VinCode, RealPartCode, ErpToLoc\n" + + ") AS t2 ON t2.ErpToLoc = t.ErpToLoc AND t2.RealPartCode = t.RealPartCode AND t2.VinCode = t1.VinCode) temp55\n" + + "WHERE sumqty <> 0\n"; + + var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; using var db = new SettleAccountDbContext(options); - var query = db.Set().FromSqlRaw("select * from Set_VmiLog"); - var filters = input.Filters.ToLambda(); + + var query = db.Database.GetDbConnection().Query(sql).AsQueryable(); + var query1 = db.Database.GetDbConnection().Query(sql2).AsQueryable(); + + var filters = input.Filters.ToLambda(); if (input.Filters.Count > 0) { - query = query.Where(input.Filters.ToLambda()); + query = query.Where(input.Filters.ToLambda()); + query1 = query1.Where(input.Filters.ToLambda()); } - query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode,o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se=o.Sum(o=>o.LogType== VmiLogType.Type100 ? 1:0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0); - var totalCount = query2.Count(); + //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); + //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode,o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se=o.Sum(o=>o.LogType== VmiLogType.Type100 ? 1:0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0); + var totalCount = query1.Count(); //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode,o.VinCode }).Select(o => new VmiBalanceDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.Qty),LastTime=o.Max(o=>o.ChangedTime) }); //var totalCount = query2.Count(); - var entities = await query2.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); + var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); //var entities = await _balanceRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); //var totalCount = await _balanceRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); return new PagedResultDto(totalCount, entities); @@ -238,7 +279,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ query = query.Where(input.Filters.ToLambda()); } query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode, o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se = o.Sum(o => o.LogType == VmiLogType.Type100 ? 1 : 0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0),Settlement= o.Sum(o => o.LogType == VmiLogType.Type200 ? 1 : 0),AdjustIn= o.Sum(o => o.LogType == VmiLogType.Type500 ? 1 : 0),AdjustOut= o.Sum(o => o.LogType == VmiLogType.Type600 ? 1 : 0) }).Where(p => p.Qty != 0); + var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode, o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se = o.Sum(o => o.LogType == VmiLogType.Type100 ? 1 : 0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0); var entities = query2.ToList(); // var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false); @@ -1338,7 +1379,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [Display(Name = "数量", Order = 4)] public decimal Qty { get; set; } - [Display(Name = "最后发运时间", Order = 5)] + [Display(Name = "发运时间", Order = 5)] public DateTime? BillTime { get; set; } [Display(Name = "发运入库数量", Order = 4)] @@ -1347,15 +1388,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [Display(Name = "发运退货数量", Order = 4)] public decimal ReturnGoods { get; set; } - [Display(Name = "结算出库数量", Order = 4)] - public decimal Settlement { get; set; } + } + + + + + - [Display(Name = "调整入库数量", Order = 4)] - public decimal AdjustIn { get; set; } - [Display(Name = "调整出库数量", Order = 4)] - public decimal AdjustOut { get; set; } - }