Browse Source

update

master
wanggang 1 year ago
parent
commit
95c00e6af8
  1. 9
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  2. 80
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs

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

@ -27,6 +27,7 @@ using Microsoft.Extensions.Logging;
using RestSharp.Extensions; using RestSharp.Extensions;
using SettleAccount.Job.SignalR; using SettleAccount.Job.SignalR;
using SqlSugar; using SqlSugar;
using Volo.Abp;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring;
@ -118,12 +119,12 @@ public class VmiAppService : Controller, IApplicationService, IJobService, ITran
transaction.Commit(); transaction.Commit();
return Task.CompletedTask; return Task.CompletedTask;
} }
throw new Exception("备份程序正在运行"); throw new UserFriendlyException("备份程序正在运行", "500");
} }
catch catch(Exception ex)
{ {
transaction.Rollback(); transaction.Rollback();
throw; throw new UserFriendlyException(ex.ToString(), "500");
} }
} }
@ -501,7 +502,7 @@ public class VmiAppService : Controller, IApplicationService, IJobService, ITran
catch (Exception ex) catch (Exception ex)
{ {
this._logger.LogError(ex.ToString()); this._logger.LogError(ex.ToString());
throw; throw new UserFriendlyException(ex.ToString(), "500");
} }
} }

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

@ -12,6 +12,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Omu.ValueInjecter; using Omu.ValueInjecter;
using Volo.Abp;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
@ -49,7 +50,8 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi
[NonAction] [NonAction]
public async Task Invoke(IServiceProvider serviceProvider) public async Task Invoke(IServiceProvider serviceProvider)
{ {
for (var i = 0; i < 100; i++) var batchSize = 1000;
for (var i = 0; i < 1000; i++)
{ {
var sw = new Stopwatch(); var sw = new Stopwatch();
sw.Start(); sw.Start();
@ -68,7 +70,9 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi
{ {
break; break;
} }
var messages = context.Set<VmiMessage>().Where(o => !o.isConsumed).OrderBy(o => o.Number).Take(1000).ToList(); var messages = context.Set<VmiMessage>()
//.AsNoTracking()
.Where(o => !o.isConsumed).OrderBy(o => o.Number).Take(batchSize).ToList();
var repo = context.Set<VmiBalance>(); var repo = context.Set<VmiBalance>();
foreach (var message in messages) foreach (var message in messages)
{ {
@ -92,26 +96,50 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi
command.ExecuteNonQuery(); command.ExecuteNonQuery();
//插入库存 //插入库存
var balance = context.Set<VmiBalance>().FirstOrDefault( var balance = context.Set<VmiBalance>().FirstOrDefault(
o => o.DeliverBillType == log.DeliverBillType && o => o.DeliverBillType == log.DeliverBillType &&
o.CodeType == log.CodeType && o.CodeType == log.CodeType &&
o.DeliverBillType == log.DeliverBillType && o.DeliverBillType == log.DeliverBillType &&
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)
{ {//不存在库存记录
//新建库存记录
balance = new VmiBalance(); balance = new VmiBalance();
balance.InjectFrom(log); if (log.LogType == VmiLogType.Type300)
{//反结算入库,重建库存
var logHistory = context.Set<VmiLog>().AsNoTracking().FirstOrDefault(
o => o.LogType == VmiLogType.Type100 &&
o.DeliverBillType == log.DeliverBillType &&
o.CodeType == log.CodeType &&
o.DeliverBillType == log.DeliverBillType &&
o.VinCode == log.VinCode &&
o.ErpToLoc == log.ErpToLoc &&
o.OrderNum == log.OrderNum &&
o.factory == log.factory &&
o.Configcode == log.Configcode);
if (logHistory != null)
{
balance.InjectFrom(logHistory);
}
else
{
balance.InjectFrom(log);
}
}
else
{
balance.InjectFrom(log);
}
balance.Qty = log.ChangedQty;
await repo.AddAsync(balance).ConfigureAwait(false); await repo.AddAsync(balance).ConfigureAwait(false);
log.InjectFrom(balance);
} }
else else
{ {//存在库存记录
var logType = log.LogType; var logType = log.LogType;
var currentQty = balance.Qty;// + log.ty
var qty = balance.Qty;// + log.ty
if (logType == VmiLogType.Type100) if (logType == VmiLogType.Type100)
{ {
//发运入库,负库存字段需要更新 //发运入库,负库存字段需要更新
@ -129,20 +157,20 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi
//调整入库,更新库存和其他字段 //调整入库,更新库存和其他字段
balance.InjectFrom(log); balance.InjectFrom(log);
} }
// 更新库存 if (logType == VmiLogType.Type100 && balance.Qty < decimal.Zero)
balance.Qty = qty;
if (balance.Qty == decimal.Zero)
{
//删除0库存
repo.Remove(balance);
}
if (logType == VmiLogType.Type100 && balance.Qty < decimal.Zero && log.Qty > 0)
{ {
//添加负库存补货记录 //添加负库存补货记录
var log2 = new VmiReplenished(); var log2 = new VmiReplenished();
log2.InjectFrom(log); log2.InjectFrom(log);
await context.Set<VmiReplenished>().AddAsync(log2).ConfigureAwait(false); await context.Set<VmiReplenished>().AddAsync(log2).ConfigureAwait(false);
} }
// 更新库存
balance.Qty = currentQty + log.ChangedQty;
if (balance.Qty == decimal.Zero)
{
//删除0库存
repo.Remove(balance);
}
} }
message.isConsumed = true; message.isConsumed = true;
} }
@ -153,12 +181,12 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi
{ {
this._logger.LogError(ex.ToString()); this._logger.LogError(ex.ToString());
transaction.Rollback(); transaction.Rollback();
throw; throw new UserFriendlyException(ex.ToString(), "500");
} }
finally finally
{ {
sw.Stop(); sw.Stop();
this._logger.LogInformation($"结束,耗时 ${sw.ElapsedMilliseconds / 1000 / 60}分钟"); this._logger.LogInformation($"处理{batchSize}条,耗时 {sw.ElapsedMilliseconds / 1000 / 60}分钟,{sw.ElapsedMilliseconds / 1000}秒");
} }
} }
} }

Loading…
Cancel
Save