diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js index a2f2b332..439c1feb 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js @@ -30,7 +30,6 @@ export default function () { title: "通用代码", type: "object", properties: { - // logTypes: { type: "array", hidden: true, default: ["Type200", "Type400"] }, filters: { title: "项目", type: "array", @@ -135,6 +134,7 @@ export default function () { sorting: { hidden: true, }, + useHistory: { type: "boolean", title: "查询历史数据" }, }, }, }, 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 4321d181..39dde05b 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 @@ -293,6 +293,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> Log(LogRequestDto input) { + if (input.UseHistory) + { + return await Log2(input).ConfigureAwait(false); + } //按季度计算查询需要 union 的表名 var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value); var end = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.SmallThan).Value); @@ -348,7 +352,34 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } /// - /// 3.1库存事务导出 + /// 3.1 库存事务查询(不分表) + /// + /// + /// + [HttpPost] + public async Task> Log2(LogRequestDto input) + { + 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 WITH(NOLOCK)"); + var filters = input.Filters.ToLambda(); + if (input.Filters.Count > 0) + { + query = query.Where(input.Filters.ToLambda()); + } + if (input.LogTypes.Count > 0) + { + query = query.Where(o => input.LogTypes.Contains(o.LogType)); + } + var totalCount = query.Count(); + query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); + var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); + return new PagedResultDto(totalCount, entities); + } + + /// + /// 3.2库存事务导出 /// [HttpPost] public async Task LogExport(RequestDto input) @@ -565,7 +596,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var batchSize = 10000; var fetchSize = 0; var connectionString = serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - while(true) + while (true) { var balanceList = new List>(); var sw = new Stopwatch(); @@ -678,7 +709,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } } - private List>> ImportInternal(byte[] data) { var list = new List>>(); @@ -839,6 +869,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public class LogRequestDto : RequestDto { public List LogTypes { get; set; } = new List(); + public bool UseHistory { get; set; } } public class VmiBalanceSumDto diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs index d566c4d4..96a61bc2 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs @@ -4,6 +4,7 @@ using System.Data.SqlClient; using System.Diagnostics; using System.Linq; using System.Linq.Dynamic.Core; +using System.Linq.Expressions; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -55,6 +56,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return (DateTime.Now - now).TotalMinutes; } + [NonAction] public async Task Invoke(IServiceProvider serviceProvider) { @@ -71,7 +73,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private async Task InvokeInternal(IServiceProvider serviceProvider) { - var batchSize = 10000; + var batchSize = 2500; var fetchSize = 0; var connectionString = serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); for (var i = 0; i < 1000; i++) @@ -149,15 +151,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //数据库查找 if (balance == null) { - balance = vmiBalanceRepo.FirstOrDefault( - o => o.DeliverBillType == log.DeliverBillType && - o.CodeType == log.CodeType && - o.RealPartCode == log.RealPartCode && - o.VinCode == log.VinCode && - o.ErpToLoc == log.ErpToLoc && - o.OrderNum == log.OrderNum && - o.factory == log.factory && - o.Configcode == log.Configcode); + balance = vmiBalanceRepo.AsNoTracking().FirstOrDefault( + o => o.DeliverBillType == log.DeliverBillType && + o.CodeType == log.CodeType && + o.RealPartCode == log.RealPartCode && + o.VinCode == log.VinCode && + o.ErpToLoc == log.ErpToLoc && + o.OrderNum == log.OrderNum && + o.factory == log.factory && + o.Configcode == log.Configcode); } if (balance == null) {//不存在库存记录