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" });