Browse Source

更新版本

master
学 赵 12 months ago
parent
commit
36dadc09b5
  1. 72
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

72
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

@ -12,6 +12,7 @@ using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper; using AutoMapper;
using ClosedXML.Excel; using ClosedXML.Excel;
using Dapper;
using DocumentFormat.OpenXml; using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml.Wordprocessing;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
@ -196,24 +197,64 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[HttpPost] [HttpPost]
public async Task<PagedResultDto<VmiBalanceNewDto>> Balance(RequestDto input) public async Task<PagedResultDto<VmiBalanceNewDto>> 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<IConfiguration>().GetConnectionString("SettleAccountService"); var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options; var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
using var db = new SettleAccountDbContext(options); using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiLog>().FromSqlRaw("select * from Set_VmiLog");
var filters = input.Filters.ToLambda<VmiLog>(); var query = db.Database.GetDbConnection().Query<VmiBalanceNewDto>(sql).AsQueryable();
var query1 = db.Database.GetDbConnection().Query<int>(sql2).AsQueryable();
var filters = input.Filters.ToLambda<VmiBalanceNewDto>();
if (input.Filters.Count > 0) if (input.Filters.Count > 0)
{ {
query = query.Where(input.Filters.ToLambda<VmiLog>()); query = query.Where(input.Filters.ToLambda<VmiBalanceNewDto>());
query1 = query1.Where(input.Filters.ToLambda<VmiBalanceNewDto>());
} }
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); //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 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(); var totalCount = query1.Count();
//query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); //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 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 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 entities = await _balanceRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false);
//var totalCount = await _balanceRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); //var totalCount = await _balanceRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
return new PagedResultDto<VmiBalanceNewDto>(totalCount, entities); return new PagedResultDto<VmiBalanceNewDto>(totalCount, entities);
@ -238,7 +279,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
query = query.Where(input.Filters.ToLambda<VmiLog>()); query = query.Where(input.Filters.ToLambda<VmiLog>());
} }
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); 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 = query2.ToList();
// var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false); // var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false);
@ -1338,7 +1379,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[Display(Name = "数量", Order = 4)] [Display(Name = "数量", Order = 4)]
public decimal Qty { get; set; } public decimal Qty { get; set; }
[Display(Name = "最后发运时间", Order = 5)] [Display(Name = "发运时间", Order = 5)]
public DateTime? BillTime { get; set; } public DateTime? BillTime { get; set; }
[Display(Name = "发运入库数量", Order = 4)] [Display(Name = "发运入库数量", Order = 4)]
@ -1347,15 +1388,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[Display(Name = "发运退货数量", Order = 4)] [Display(Name = "发运退货数量", Order = 4)]
public decimal ReturnGoods { get; set; } 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; }
}

Loading…
Cancel
Save