Browse Source

优化同步库存时系统资源占用

master
wanggang 1 year ago
parent
commit
14e76388fb
  1. 2
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js
  2. 37
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  3. 22
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs

2
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/vmi/log.js

@ -30,7 +30,6 @@ export default function () {
title: "通用代码", title: "通用代码",
type: "object", type: "object",
properties: { properties: {
// logTypes: { type: "array", hidden: true, default: ["Type200", "Type400"] },
filters: { filters: {
title: "项目", title: "项目",
type: "array", type: "array",
@ -135,6 +134,7 @@ export default function () {
sorting: { sorting: {
hidden: true, hidden: true,
}, },
useHistory: { type: "boolean", title: "查询历史数据" },
}, },
}, },
}, },

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

@ -293,6 +293,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[HttpPost] [HttpPost]
public async Task<PagedResultDto<VmiLog>> Log(LogRequestDto input) public async Task<PagedResultDto<VmiLog>> Log(LogRequestDto input)
{ {
if (input.UseHistory)
{
return await Log2(input).ConfigureAwait(false);
}
//按季度计算查询需要 union 的表名 //按季度计算查询需要 union 的表名
var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value); 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); 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
} }
/// <summary> /// <summary>
/// 3.1库存事务导出 /// 3.1 库存事务查询(不分表)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<PagedResultDto<VmiLog>> Log2(LogRequestDto input)
{
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiLog>().FromSqlRaw("select * from Set_VmiLog WITH(NOLOCK)");
var filters = input.Filters.ToLambda<VmiLog>();
if (input.Filters.Count > 0)
{
query = query.Where(input.Filters.ToLambda<VmiLog>());
}
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<VmiLog>(totalCount, entities);
}
/// <summary>
/// 3.2库存事务导出
/// </summary> /// </summary>
[HttpPost] [HttpPost]
public async Task<string> LogExport(RequestDto input) public async Task<string> LogExport(RequestDto input)
@ -565,7 +596,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var batchSize = 10000; var batchSize = 10000;
var fetchSize = 0; var fetchSize = 0;
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
while(true) while (true)
{ {
var balanceList = new List<Tuple<VmiBalance, int>>(); var balanceList = new List<Tuple<VmiBalance, int>>();
var sw = new Stopwatch(); var sw = new Stopwatch();
@ -678,7 +709,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
} }
private List<Tuple<T, List<ValidationResult>>> ImportInternal<T>(byte[] data) private List<Tuple<T, List<ValidationResult>>> ImportInternal<T>(byte[] data)
{ {
var list = new List<Tuple<T, List<ValidationResult>>>(); var list = new List<Tuple<T, List<ValidationResult>>>();
@ -839,6 +869,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public class LogRequestDto : RequestDto public class LogRequestDto : RequestDto
{ {
public List<VmiLogType> LogTypes { get; set; } = new List<VmiLogType>(); public List<VmiLogType> LogTypes { get; set; } = new List<VmiLogType>();
public bool UseHistory { get; set; }
} }
public class VmiBalanceSumDto public class VmiBalanceSumDto

22
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs

@ -4,6 +4,7 @@ using System.Data.SqlClient;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -55,6 +56,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
return (DateTime.Now - now).TotalMinutes; return (DateTime.Now - now).TotalMinutes;
} }
[NonAction] [NonAction]
public async Task Invoke(IServiceProvider serviceProvider) public async Task Invoke(IServiceProvider serviceProvider)
{ {
@ -71,7 +73,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
private async Task InvokeInternal(IServiceProvider serviceProvider) private async Task InvokeInternal(IServiceProvider serviceProvider)
{ {
var batchSize = 10000; var batchSize = 2500;
var fetchSize = 0; var fetchSize = 0;
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
for (var i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
@ -149,15 +151,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
//数据库查找 //数据库查找
if (balance == null) if (balance == null)
{ {
balance = vmiBalanceRepo.FirstOrDefault( balance = vmiBalanceRepo.AsNoTracking().FirstOrDefault(
o => o.DeliverBillType == log.DeliverBillType && o => o.DeliverBillType == log.DeliverBillType &&
o.CodeType == log.CodeType && o.CodeType == log.CodeType &&
o.RealPartCode == log.RealPartCode && o.RealPartCode == log.RealPartCode &&
o.VinCode == log.VinCode && o.VinCode == log.VinCode &&
o.ErpToLoc == log.ErpToLoc && o.ErpToLoc == log.ErpToLoc &&
o.OrderNum == log.OrderNum && o.OrderNum == log.OrderNum &&
o.factory == log.factory && o.factory == log.factory &&
o.Configcode == log.Configcode); o.Configcode == log.Configcode);
} }
if (balance == null) if (balance == null)
{//不存在库存记录 {//不存在库存记录

Loading…
Cancel
Save