From 266aaaf404c8d7a688378abe469902ac19315b6d Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 9 Aug 2023 15:51:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AF=84=E5=94=AE=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/VmiAppService.cs | 101 +++++++++++++----- .../Entities/BQ/Vmi/VmiBalance.cs | 21 ++-- .../Entities/BQ/Vmi/VmiLog.cs | 2 +- ...AccountDbContextModelCreatingExtensions.cs | 12 ++- 4 files changed, 97 insertions(+), 39 deletions(-) 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 2ca466be..0709d865 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 @@ -219,11 +219,16 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran { using var scope = _serviceProvider.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); - var balance = db.Set().FirstOrDefault(o => o.BillType == data.BillType && - o.PartCode == data.PartCode && - o.VinCode == data.VinCode && - o.ErpToLoc == data.ErpToLoc && - o.OrderNum == data.OrderNum); + + var balance = db.Set().FirstOrDefault( + o => o.BillType == data.BillType && + o.CodeType == data.CodeType && + o.PartCode == data.PartCode && + o.VinCode == data.VinCode && + o.ErpToLoc == data.ErpToLoc && + o.OrderNum == data.OrderNum && + o.factory == data.factory && + o.Configcode == data.Configcode); var log = new VmiLog { @@ -234,20 +239,34 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran ChangedBy = _currentUser.UserName, ChangedQty = data.Qty, }; - log.InjectFrom(data); + if (balance == null) { balance = new VmiBalance(GuidGenerator.Create()); balance.InjectFrom(data); - // 初始化库存 - balance.Qty = data.Qty; - balance.SetId(GuidGenerator.Create()); await db.Set().AddAsync(balance).ConfigureAwait(false); + //新建库存,库存事务种库存备份的初始库存为0 + log.InjectFrom(balance); + log.Qty = 0; } else { + //已有库存,直接备份 + log.InjectFrom(balance); var qty = balance.Qty + data.Qty; - balance.InjectFrom(data); + if (logType == VmiLogType.Type100) + { + //发运入库,只更新库存 + } + else if (logType == VmiLogType.Type300) + { + //反结入库,只更新库存 + } + else if (logType == VmiLogType.Type500) + { + //调整入库,更新库存和其他字段 + balance.InjectFrom(data); + } // 加库存 balance.Qty = qty; if (balance.Qty == decimal.Zero) @@ -281,33 +300,57 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran { using var scope = _serviceProvider.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); - var balance = db.Set().FirstOrDefault(o => o.BillType == data.BillType && o.PartCode == data.PartCode && o.VinCode == data.VinCode && o.ErpToLoc == data.ErpToLoc && o.OrderNum == data.OrderNum); + var balance = db.Set().FirstOrDefault( + o => o.BillType == data.BillType && + o.CodeType == data.CodeType && + o.PartCode == data.PartCode && + o.VinCode == data.VinCode && + o.ErpToLoc == data.ErpToLoc && + o.OrderNum == data.OrderNum && + o.factory == data.factory && + o.Configcode == data.Configcode); var log = new VmiLog { LogType = logType, - ChangedType = VmiType.Out, + ChangedType = VmiType.In, ChangedNumber = changedNumber, + ChangedTime = DateTime.Now, + ChangedBy = _currentUser.UserName, + ChangedQty = data.Qty, }; - log.InjectFrom(data); - log.LogType = logType; - log.ChangedType = VmiType.Out; - log.ChangedTime = DateTime.Now; - log.ChangedBy = _currentUser.UserName; - log.ChangedQty = data.Qty; if (balance == null) { - balance = new VmiBalance(); + //负库存出库 + balance = new VmiBalance(GuidGenerator.Create()); balance.InjectFrom(data); + //新建库存,库存事务种库存备份的初始库存为0 + log.InjectFrom(data); + log.Qty = 0; // 负库存 balance.Qty = -data.Qty; - balance.SetId(GuidGenerator.Create()); await db.Set().AddAsync(balance).ConfigureAwait(false); } else { + //已有库存,直接备份 + log.InjectFrom(data);//更新附加字段 + log.InjectFrom(balance);//备份库存 // 减库存 balance.Qty -= data.Qty; ; + if (logType == VmiLogType.Type200) + { + //结算出库,只更新库存 + } + else if (logType == VmiLogType.Type400) + { + //退货出库,只更新库存 + } + else if (logType == VmiLogType.Type600) + { + //调整出库,更新库存和其他字段 + balance.InjectFrom(data); + } if (balance.Qty == decimal.Zero) { db.Set().Remove(balance); @@ -335,7 +378,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran o.OrderNum == item.OrderNum); if (balance == null) { - balance = new VmiBalance(); + balance = new VmiBalance(GuidGenerator.Create()); balance.InjectFrom(item); await _balanceRepository.InsertAsync(balance).ConfigureAwait(false); } @@ -376,7 +419,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran var entities = await _balanceRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda()) .ToListAsync().ConfigureAwait(false); var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")}.xlsx"; - var content = this.GetContent(entities, "库存备份"); + var content = this.GetContent(entities, "库存备份"); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; } @@ -393,10 +436,13 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran /// /// [HttpPost] - public async Task> Log(RequestDto input) + public async Task> Log(LogRequestDto input) { - var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); - var totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); + var query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda()) + .WhereIf(input.LogTypes?.Count != 0, o => input.LogTypes.Contains(o.LogType)); + var totalCount = await query.CountAsync().ConfigureAwait(false); + query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); + var entities = query.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); return new PagedResultDto(totalCount, entities); //return QueryLogFromTSDb(input); } @@ -596,3 +642,8 @@ public class BackupListRequest : RequestDto [Required] public string Name { get; set; } } + +public class LogRequestDto : RequestDto +{ + public List LogTypes { get; set; } = new List(); +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs index 491c7c46..0e10a422 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs @@ -1,8 +1,5 @@ using System; using System.ComponentModel.DataAnnotations; -using System.Security.Cryptography; -using System.Text; -using System.Text.Json; using Volo.Abp.Domain.Entities; using Win.Sfs.SettleAccount.Entities.BQ.Syncs; @@ -29,6 +26,9 @@ public class VmiBalance : BasicAggregateRoot, IHasConcurrencyStamp [Display(Name = "LU零件号")] public string PartCode { get; set; } + /// + /// 生产码 + /// [Display(Name = "生产码")] public string VinCode { get; set; } @@ -38,9 +38,15 @@ public class VmiBalance : BasicAggregateRoot, IHasConcurrencyStamp [Display(Name = "客户零件号")] public string CustomerPartCode { get; set; } + /// + /// 生产码类型 + /// [Display(Name = "生产码类型")] public string CodeType { get; set; } + /// + /// 发货类型 + /// [Display(Name = "发货类型")] public EnumDeliverBjBmpBillType BillType { get; set; } @@ -91,13 +97,4 @@ public class VmiBalance : BasicAggregateRoot, IHasConcurrencyStamp public string ConcurrencyStamp { get; set; } public DateTime? BackupTime { get; set; } - - public VmiBalance SetId(Guid guid) - { - var data = new { BillType, PartCode, VinCode, ErpToLoc, OrderNum }; - var json = JsonSerializer.Serialize(data); - var bytes = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(json)); - this.Id = new Guid(bytes); - return this; - } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs index 9382f572..f33d32c9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs @@ -47,10 +47,10 @@ public class VmiLog : BasicAggregateRoot [Display(Name = "变动时间")] public DateTime ChangedTime { get; set; } = DateTime.Now; + /// /// 变动类型 /// - [Display(Name = "变动类型")] public VmiType ChangedType { get; set; } /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs index 4a7f17ba..de0c7eeb 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs @@ -1314,7 +1314,17 @@ namespace Win.Sfs.SettleAccount { b.ToTable($"{options.TablePrefix}_VmiBalance", options.Schema); b.ConfigureByConvention(); - b.HasIndex(o => (new { o.BillType, o.PartCode, o.VinCode, o.ErpToLoc, o.OrderNum })).IsUnique(); + b.HasIndex(o => (new + { + o.BillType, + o.CodeType, + o.PartCode, + o.VinCode, + o.ErpToLoc, + o.OrderNum, + o.factory, + o.Configcode + })).IsUnique(); })); builder.Entity().HasData(new VmiBalance(Guid.NewGuid()) { BillType = EnumDeliverBjBmpBillType.JIS件, PartCode = "PartCode", VinCode = "VinCode", ErpToLoc = "ErpToLoc", OrderNum = "OrderNum" });