|
|
@ -36,6 +36,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ; |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// DbContext
|
|
|
|
/// </summary>
|
|
|
|
public SettleAccountDbContext _settleAccountDbContext; |
|
|
|
/// <summary>
|
|
|
|
/// PUB结算仓储
|
|
|
|
/// </summary>
|
|
|
@ -76,7 +80,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// </summary>
|
|
|
|
public PUB_SA_SERVICE(INormalEfCoreRepository<PUB_SA, Guid> repository, |
|
|
|
public PUB_SA_SERVICE(SettleAccountDbContext settleAccountDbContext, |
|
|
|
INormalEfCoreRepository<PUB_SA, Guid> repository, |
|
|
|
INormalEfCoreRepository<PUB_SA_DETAIL, Guid> pubSaDetailRepository, |
|
|
|
INormalEfCoreRepository<PUB_CAN_SA, Guid> pubCanSaRepository, |
|
|
|
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> pubCanSaDetailRepository, |
|
|
@ -91,6 +96,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
ICommonManager commonManager |
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
|
_repository = repository; |
|
|
|
_pubSaDetailRepository = pubSaDetailRepository; |
|
|
|
_pubCanSaRepository = pubCanSaRepository; |
|
|
@ -105,7 +111,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
/// <summary>
|
|
|
|
/// 期间
|
|
|
|
/// </summary>
|
|
|
|
private int _version; |
|
|
|
private int version; |
|
|
|
/// <summary>
|
|
|
|
/// 业务类别
|
|
|
|
/// </summary>
|
|
|
@ -123,7 +129,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) |
|
|
|
{ |
|
|
|
IActionResult result = new JsonResult(new { Code = 400 }); |
|
|
|
_version = pubSaImportRequestDto.Version; |
|
|
|
version = pubSaImportRequestDto.Version; |
|
|
|
businessType = pubSaImportRequestDto.BusinessType; |
|
|
|
site = pubSaImportRequestDto.Site; |
|
|
|
switch (pubSaImportRequestDto.BusinessType) |
|
|
@ -376,7 +382,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
//验证客户对应厂内零件号是否存在
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = pubSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == businessType && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
//不存在的客户零件号(差集)
|
|
|
@ -429,9 +435,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
/// </summary>
|
|
|
|
private async Task<IActionResult> InsertSaDataAsync(List<PUB_SA_DETAIL> pubSaDetails, EnumBusinessType businessType) |
|
|
|
{ |
|
|
|
//客户零件关系
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
for (var i = 0; i < pubSaDetails.Count; i++) |
|
|
|
{ |
|
|
@ -439,7 +442,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
pubSaDetail.SetId(GuidGenerator.Create()); |
|
|
|
pubSaDetail.CustomerPartCodeNoSpace = pubSaDetail.LU.Replace(" ", ""); |
|
|
|
pubSaDetail.KeyCode = pubSaDetail.PN + pubSaDetail.LU; |
|
|
|
pubSaDetail.Version = _version; |
|
|
|
pubSaDetail.Version = version; |
|
|
|
pubSaDetail.BusinessType = businessType; |
|
|
|
pubSaDetail.IndexNum = i; |
|
|
|
} |
|
|
@ -494,9 +497,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
|
var importPubSaLUs = pubSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => t.BusinessType == businessType && importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false); |
|
|
|
|
|
|
|
var seAllMaterialRelationships = materialRelationshipEntitys.Union(materialRelationships); |
|
|
|
pubSaDetails.ForEach(pubSaDetail => |
|
|
|
{ |
|
|
|
pubSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == pubSaDetail.LU)?.ErpMaterialCode; |
|
|
@ -505,10 +507,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
|
|
|
|
#region 添加入库
|
|
|
|
await SeDataEntryAsync(pubSaDetails).ConfigureAwait(false); |
|
|
|
if (materialRelationships.Count > 0) |
|
|
|
{ |
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships).ConfigureAwait(false); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|