From 3a5175624e7870d813105ff3cd906a77d1479ece Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Thu, 31 Aug 2023 08:57:16 +0800 Subject: [PATCH] up --- .../wwwroot/router/base-data.js | 8 +- .../Entities/BQ/VmiAsyncBalanceService.cs | 2 +- .../Entities/BQ/VmiAsyncMessageService.cs | 122 ------------------ 3 files changed, 5 insertions(+), 127 deletions(-) diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js index 634b4d0f..4d273df5 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/router/base-data.js +++ b/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: [ 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 4f5f1991..17a1bd32 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 @@ -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().GetConnectionString("SettleAccountService"); using var connection = new SqlConnection(connectionString); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs index be57c1c2..789c2501 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs +++ b/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; -/// -/// 异步更新库存 -/// -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().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().UseSqlServer(connection).Options; - using var context = new SettleAccountDbContext(options); - context.Database.UseTransaction(transaction); - var messages = context.Set().Where(o => !o.isConsumed).OrderBy(o => o.Number).Take(1000 * 100).ToList(); - var repo = context.Set(); - foreach (var message in messages) - { - var log = JsonSerializer.Deserialize(message.Message); - log.SetId(Guid.Parse(JsonSerializer.Deserialize(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().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().AddAsync(log2).ConfigureAwait(false); - } - } - message.isConsumed = true; - } - context.SaveChanges(); - transaction.Commit(); - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - transaction.Rollback(); - throw; - } - } -} - /// /// 消息表定时清理 ///