wanggang 1 year ago
parent
commit
3a5175624e
  1. 8
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js
  2. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs
  3. 122
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs

8
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js

@ -18,10 +18,10 @@ export default [
...createPage("role", "title=角色管理"),
children: [createButton("query", "title=查询&isTop=true"), createButton("create", "title=新建&isTop=true"), createButton("delete", "title=删除&disabled=o => o.isStatic")],
},
{
...createPage("material", "title=物料主数据"),
children: [createButton("query", "title=查询&isTop=true"), createButton("export", "title=导出&isTop=true&pattern=paged")],
},
// {
// ...createPage("material", "title=物料主数据"),
// children: [createButton("query", "title=查询&isTop=true"), createButton("export", "title=导出&isTop=true&pattern=paged")],
// },
{
...createPage("version", "title=期间设置"),
children: [

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

@ -30,7 +30,7 @@ public class VmiAsyncBalanceService : ApplicationService, IJobService, ITransien
public async Task Invoke(IServiceProvider serviceProvider)
{
for (var i = 0; i < 30; i++)
for (var i = 0; i < 50; i++)
{
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
using var connection = new SqlConnection(connectionString);

122
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs

@ -1,140 +1,18 @@
using System;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text.Json;
using System.Threading.Tasks;
using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Extension;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Omu.ValueInjecter;
using SettleAccount.Job.SignalR;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ;
/// <summary>
/// 异步更新库存
/// </summary>
public class VmiAsyncBalanceService : ApplicationService, IJobService, ITransientDependency
{
private readonly IServiceProvider _serviceProvider;
public VmiAsyncBalanceService(IServiceProvider serviceProvider)
{
this._serviceProvider = serviceProvider;
}
public async Task Invoke(IServiceProvider serviceProvider)
{
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
using var connection = new SqlConnection(connectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
try
{
var command = connection.CreateCommand();
command.Transaction = transaction;
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options;
using var context = new SettleAccountDbContext(options);
context.Database.UseTransaction(transaction);
var messages = context.Set<VmiMessage>().Where(o => !o.isConsumed).OrderBy(o => o.Number).Take(1000 * 100).ToList();
var repo = context.Set<VmiBalance>();
foreach (var message in messages)
{
var log = JsonSerializer.Deserialize<VmiLog>(message.Message);
log.SetId(Guid.Parse(JsonSerializer.Deserialize<JsonElement>(message.Message).GetProperty("Id").GetString()));
//插入分表
var table = $"Set_VmiLog_{log.ChangedTime.Year}_{(log.ChangedTime.Month - 1) / 3 + 1}";
command.CommandText = $"select OBJECT_ID('{table}', 'U')";
var result = command.ExecuteScalar().ToString();
if (result == string.Empty)
{
command.CommandText = $"select * into {table} from Set_VmiLog where 1=0;";
command.ExecuteNonQuery();
command.CommandText = $"create clustered index IX_{table}_ChangedTime on {table} (ChangedTime);";
command.ExecuteNonQuery();
command.CommandText = $"alter table {table} add constraint PK_{table} primary key (Id);";
command.ExecuteNonQuery();
}
//插入到分表
command.CommandText = $"insert into {table} select * from Set_VmiLog where id ='{log.Id}'";
command.ExecuteNonQuery();
//插入库存
var balance = context.Set<VmiBalance>().FirstOrDefault(
o => 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 (balance == null)
{
balance = new VmiBalance(GuidGenerator.Create());
balance.InjectFrom(log);
await repo.AddAsync(balance).ConfigureAwait(false);
log.InjectFrom(balance);
}
else
{
var logType = log.LogType;
var qty = balance.Qty;// + log.ty
if (logType == VmiLogType.Type100)
{
//发运入库,负库存字段需要更新
if (balance.Qty < decimal.Zero)
{
balance.InjectFrom(log);
}
}
else if (logType == VmiLogType.Type300)
{
//反结入库,只更新库存
}
else if (logType == VmiLogType.Type500)
{
//调整入库,更新库存和其他字段
balance.InjectFrom(log);
}
// 更新库存
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();
log2.InjectFrom(log);
await context.Set<VmiReplenished>().AddAsync(log2).ConfigureAwait(false);
}
}
message.isConsumed = true;
}
context.SaveChanges();
transaction.Commit();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
transaction.Rollback();
throw;
}
}
}
/// <summary>
/// 消息表定时清理
/// </summary>

Loading…
Cancel
Save