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();
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.VinCode == data.VinCode &&
o.ErpToLoc == data.ErpToLoc &&
o.OrderNum == data.OrderNum);
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<VmiBalance>().AddAsync(balance).ConfigureAwait(false);
//新建库存,库存事务种库存备份的初始库存为0
log.InjectFrom(balance);
log.Qty = 0;
}
else
{
//已有库存,直接备份
log.InjectFrom(balance);
var qty = balance.Qty + data.Qty;
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<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
{
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<VmiBalance>().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<VmiBalance>().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<VmiBalance>())
.ToListAsync().ConfigureAwait(false);
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);
return fileName;
}
@ -393,10 +436,13 @@ public class VmiAppService : ApplicationService, IVmiService, IJobService, ITran
/// <param name="input"></param>
/// <returns></returns>
[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 totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
var query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiLog>())
.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 QueryLogFromTSDb(input);
}
@ -596,3 +642,8 @@ public class BackupListRequest : RequestDto
[Required]
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.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<Guid>, IHasConcurrencyStamp
[Display(Name = "LU零件号")]
public string PartCode { get; set; }
/// <summary>
/// 生产码
/// </summary>
[Display(Name = "生产码")]
public string VinCode { get; set; }
@ -38,9 +38,15 @@ public class VmiBalance : BasicAggregateRoot<Guid>, IHasConcurrencyStamp
[Display(Name = "客户零件号")]
public string CustomerPartCode { get; set; }
/// <summary>
/// 生产码类型
/// </summary>
[Display(Name = "生产码类型")]
public string CodeType { get; set; }
/// <summary>
/// 发货类型
/// </summary>
[Display(Name = "发货类型")]
public EnumDeliverBjBmpBillType BillType { get; set; }
@ -91,13 +97,4 @@ public class VmiBalance : BasicAggregateRoot<Guid>, 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;
}
}

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

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

Loading…
Cancel
Save