mahao 1 year ago
parent
commit
ec0789e6f6
  1. 93
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  2. 21
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs
  3. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs
  4. 12
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs

93
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(); using var scope = _serviceProvider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
var balance = db.Set<VmiBalance>().FirstOrDefault(o => o.BillType == data.BillType &&
var balance = db.Set<VmiBalance>().FirstOrDefault(
o => o.BillType == data.BillType &&
o.CodeType == data.CodeType &&
o.PartCode == data.PartCode && o.PartCode == data.PartCode &&
o.VinCode == data.VinCode && o.VinCode == data.VinCode &&
o.ErpToLoc == data.ErpToLoc && o.ErpToLoc == data.ErpToLoc &&
o.OrderNum == data.OrderNum); o.OrderNum == data.OrderNum &&
o.factory == data.factory &&
o.Configcode == data.Configcode);
var log = new VmiLog var log = new VmiLog
{ {
@ -234,20 +239,34 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
ChangedBy = _currentUser.UserName, ChangedBy = _currentUser.UserName,
ChangedQty = data.Qty, ChangedQty = data.Qty,
}; };
log.InjectFrom(data);
if (balance == null) if (balance == null)
{ {
balance = new VmiBalance(GuidGenerator.Create()); balance = new VmiBalance(GuidGenerator.Create());
balance.InjectFrom(data); balance.InjectFrom(data);
// 初始化库存
balance.Qty = data.Qty;
balance.SetId(GuidGenerator.Create());
await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false); await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false);
//新建库存,库存事务种库存备份的初始库存为0
log.InjectFrom(balance);
log.Qty = 0;
} }
else else
{ {
//已有库存,直接备份
log.InjectFrom(balance);
var qty = balance.Qty + data.Qty; var qty = balance.Qty + data.Qty;
if (logType == VmiLogType.Type100)
{
//发运入库,只更新库存
}
else if (logType == VmiLogType.Type300)
{
//反结入库,只更新库存
}
else if (logType == VmiLogType.Type500)
{
//调整入库,更新库存和其他字段
balance.InjectFrom(data); balance.InjectFrom(data);
}
// 加库存 // 加库存
balance.Qty = qty; balance.Qty = qty;
if (balance.Qty == decimal.Zero) if (balance.Qty == decimal.Zero)
@ -281,33 +300,57 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
{ {
using var scope = _serviceProvider.CreateScope(); using var scope = _serviceProvider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
var balance = db.Set<VmiBalance>().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<VmiBalance>().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 var log = new VmiLog
{ {
LogType = logType, LogType = logType,
ChangedType = VmiType.Out, ChangedType = VmiType.In,
ChangedNumber = changedNumber, 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) if (balance == null)
{ {
balance = new VmiBalance(); //负库存出库
balance = new VmiBalance(GuidGenerator.Create());
balance.InjectFrom(data); balance.InjectFrom(data);
//新建库存,库存事务种库存备份的初始库存为0
log.InjectFrom(data);
log.Qty = 0;
// 负库存 // 负库存
balance.Qty = -data.Qty; balance.Qty = -data.Qty;
balance.SetId(GuidGenerator.Create());
await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false); await db.Set<VmiBalance>().AddAsync(balance).ConfigureAwait(false);
} }
else else
{ {
//已有库存,直接备份
log.InjectFrom(data);//更新附加字段
log.InjectFrom(balance);//备份库存
// 减库存 // 减库存
balance.Qty -= data.Qty; ; 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) if (balance.Qty == decimal.Zero)
{ {
db.Set<VmiBalance>().Remove(balance); db.Set<VmiBalance>().Remove(balance);
@ -335,7 +378,7 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
o.OrderNum == item.OrderNum); o.OrderNum == item.OrderNum);
if (balance == null) if (balance == null)
{ {
balance = new VmiBalance(); balance = new VmiBalance(GuidGenerator.Create());
balance.InjectFrom(item); balance.InjectFrom(item);
await _balanceRepository.InsertAsync(balance).ConfigureAwait(false); 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<VmiBalance>()) var entities = await _balanceRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiBalance>())
.ToListAsync().ConfigureAwait(false); .ToListAsync().ConfigureAwait(false);
var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")}.xlsx"; var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss")}.xlsx";
var content = this.GetContent<VmiBalance>(entities, "库存备份"); var content = this.GetContent(entities, "库存备份");
await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false);
return fileName; return fileName;
} }
@ -393,10 +436,13 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<PagedResultDto<VmiLog>> Log(RequestDto input) public async Task<PagedResultDto<VmiLog>> Log(LogRequestDto input)
{ {
var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); var query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiLog>())
var totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); .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<VmiLog>(totalCount, entities); return new PagedResultDto<VmiLog>(totalCount, entities);
//return QueryLogFromTSDb(input); //return QueryLogFromTSDb(input);
} }
@ -596,3 +642,8 @@ public class BackupListRequest : RequestDto
[Required] [Required]
public string Name { get; set; } public string Name { get; set; }
} }
public class LogRequestDto : RequestDto
{
public List<VmiLogType> LogTypes { get; set; } = new List<VmiLogType>();
}

21
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiBalance.cs

@ -1,8 +1,5 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs; using Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -29,6 +26,9 @@ public class VmiBalance : BasicAggregateRoot<Guid>, IHasConcurrencyStamp
[Display(Name = "LU零件号")] [Display(Name = "LU零件号")]
public string PartCode { get; set; } public string PartCode { get; set; }
/// <summary>
/// 生产码
/// </summary>
[Display(Name = "生产码")] [Display(Name = "生产码")]
public string VinCode { get; set; } public string VinCode { get; set; }
@ -38,9 +38,15 @@ public class VmiBalance : BasicAggregateRoot<Guid>, IHasConcurrencyStamp
[Display(Name = "客户零件号")] [Display(Name = "客户零件号")]
public string CustomerPartCode { get; set; } public string CustomerPartCode { get; set; }
/// <summary>
/// 生产码类型
/// </summary>
[Display(Name = "生产码类型")] [Display(Name = "生产码类型")]
public string CodeType { get; set; } public string CodeType { get; set; }
/// <summary>
/// 发货类型
/// </summary>
[Display(Name = "发货类型")] [Display(Name = "发货类型")]
public EnumDeliverBjBmpBillType BillType { get; set; } public EnumDeliverBjBmpBillType BillType { get; set; }
@ -91,13 +97,4 @@ public class VmiBalance : BasicAggregateRoot<Guid>, IHasConcurrencyStamp
public string ConcurrencyStamp { get; set; } public string ConcurrencyStamp { get; set; }
public DateTime? BackupTime { 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;
}
} }

2
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs

@ -47,10 +47,10 @@ public class VmiLog : BasicAggregateRoot<Guid>
[Display(Name = "变动时间")] [Display(Name = "变动时间")]
public DateTime ChangedTime { get; set; } = DateTime.Now; public DateTime ChangedTime { get; set; } = DateTime.Now;
/// <summary> /// <summary>
/// 变动类型 /// 变动类型
/// </summary> /// </summary>
[Display(Name = "变动类型")] [Display(Name = "变动类型")]
public VmiType ChangedType { get; set; } public VmiType ChangedType { get; set; }
/// <summary> /// <summary>

12
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.ToTable($"{options.TablePrefix}_VmiBalance", options.Schema);
b.ConfigureByConvention(); 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<VmiBalance>().HasData(new VmiBalance(Guid.NewGuid()) { BillType = EnumDeliverBjBmpBillType.JIS件, PartCode = "PartCode", VinCode = "VinCode", ErpToLoc = "ErpToLoc", OrderNum = "OrderNum" }); builder.Entity<VmiBalance>().HasData(new VmiBalance(Guid.NewGuid()) { BillType = EnumDeliverBjBmpBillType.JIS件, PartCode = "PartCode", VinCode = "VinCode", ErpToLoc = "ErpToLoc", OrderNum = "OrderNum" });

Loading…
Cancel
Save