Browse Source

JISHBPO同步发运调用寄售库

master
mahao 1 year ago
parent
commit
b129d9bd29
  1. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HandSeSyncAppService.cs
  2. 12
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeSyncAppService.cs
  3. 202
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeSyncBaseAppService.cs
  4. 11
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncAppService.cs
  5. 198
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs
  6. 10
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JitSeSyncAppService.cs
  7. 12
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MaiDanBBACSeSyncAppService.cs
  8. 10
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MaiDanHBPOSeSyncAppService.cs
  9. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/SeSyncExtendManager.cs

4
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HandSeSyncAppService.cs

@ -32,7 +32,7 @@ public class HandSeSyncAppService : ApplicationService
public virtual async Task SyncAsync([FromBody] EnumBusinessType businessType)
{
using var scope = this._applicationServices.CreateScope();
IInvocable jitSeSyncAppService = businessType switch
IInvocable seSyncAppService = businessType switch
{
EnumBusinessType.JisBBAC => scope.ServiceProvider.GetRequiredService<JisBBACSeSyncAppService>(),
EnumBusinessType.JisHBPO => scope.ServiceProvider.GetRequiredService<JisHBPOSeSyncAppService>(),
@ -44,6 +44,6 @@ public class HandSeSyncAppService : ApplicationService
EnumBusinessType.YinDuJian => scope.ServiceProvider.GetRequiredService<YinDuSeSyncAppService>(),
_ => throw new ArgumentOutOfRangeException(nameof(businessType), $"Not expected direction value: {businessType}"),
};
await jitSeSyncAppService.Invoke().ConfigureAwait(false);
await seSyncAppService.Invoke().ConfigureAwait(false);
}
}

12
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeSyncAppService.cs

@ -3,11 +3,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +22,8 @@ public class JisBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobService
public JisBBACSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, vmiService)
SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{
base.SeSyncConfigInfo = new SeSyncConfig()
{
@ -43,6 +38,7 @@ public class JisBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobService
};
}
[UnitOfWork(IsDisabled = true)]
public async Task Invoke(IServiceProvider serviceProvider)
{
await this.Invoke().ConfigureAwait(false);

202
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeSyncBaseAppService.cs

@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Coravel.Invocable;
using EFCore.BulkExtensions;
using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase;
@ -25,28 +24,14 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
/// WMS数据上下文
/// </summary>
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext;
/// <summary>
/// 数据上下文
/// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext;
/// <summary>
/// 同步位置标记
/// 发运同步扩展
/// </summary>
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository;
/// <summary>
/// Jis发运数据仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> _jisSeDetailRepository;
/// <summary>
/// 客户零件关系领域
/// </summary>
private readonly MaterialRelationshipManager _materialRelationshipManager;
//private readonly IVmiService _vmiService;
private readonly SeSyncExtendManager _syncExtendManager;
/// <summary>
/// 构造
@ -54,17 +39,11 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
public JisBBACSeSyncBaseAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService)
SeSyncExtendManager syncExtendManager)
{
_wmsBJBMPTContext = wmsBJBMPTContext;
_settleAccountDbContext = settleAccountDbContext;
_syncPositionFlagRepository = syncPositionFlagRepository;
_jisSeDetailRepository = jisSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
//_vmiService = vmiService;
_syncExtendManager = syncExtendManager;
}
/// <summary>
@ -80,7 +59,6 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
return;
}
await SyncJitRecordAsync().ConfigureAwait(false);
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false);
await SyncJisRecordAsync().ConfigureAwait(false);
}
@ -97,53 +75,27 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (syncPositionFlag != null)
{
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
}
//WMS发运记录
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<BBAC_SE_DETAIL>>(wmsSeRecords);
if (jisSeDetails.Any())
var seed = 0;
while (seed < 10)
{
//客户零件号和厂内零件号
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";
//WMS发运记录
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD
.Where(t => t.UID > int.Parse(syncPosition))
.Where(t => t.DeliverBillType == deliverBillType)
.Where(t => deliverSubBillTypes.Contains(t.DeliverSubBillType))
.OrderBy(b => b.UID).Take(100_000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<BBAC_SE_DETAIL>>(wmsSeRecords);
if (jisSeDetails.Any())
{
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
}
jisSeDetails.ForEach(t =>
{
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false);
if (syncPositionFlag != null)
{
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString();
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false);
await SeDataPutInStorageAsync(jisSeDetails, false).ConfigureAwait(false);
}
else
{
syncPositionFlag = new SyncPositionFlag()
{
TableName = syncTableName,
Position = wmsSeRecords.Last().UID.ToString()
};
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false);
break;
}
}
}
@ -161,74 +113,90 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
var seed = 0;
while (seed < 10)
{
seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";
//WMS发运记录
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD
.Where(t => t.UID > int.Parse(syncPosition))
.Where(t => t.DeliverBillType == deliverBillType)
.Where(t => deliverSubBillTypes.Contains(t.DeliverSubBillType))
.OrderBy(b => b.UID).Take(100_000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<BBAC_SE_DETAIL>>(wmsSeRecords);
if (jisSeDetails.Any())
{
await SeDataPutInStorageAsync(jisSeDetails, true).ConfigureAwait(false);
}
else
{
break;
}
}
}
/// <summary>
/// 发运数据入库
/// </summary>
private async Task SeDataPutInStorageAsync(List<BBAC_SE_DETAIL> seDetails, bool isJisTable)
{
//同步表名称
var syncTableName = isJisTable ? SeSyncConfigInfo.SyncTableName +
"_Jis" : SeSyncConfigInfo.SyncTableName + "_Jit";
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (syncPositionFlag != null)
//客户零件号和厂内零件号
var luRePartCodes = seDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
{
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
}
//WMS发运数据
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<BBAC_SE_DETAIL>>(wmsRecords);
if (jisSeDetails.Any())
seDetails.ForEach(t =>
{
//客户零件号和厂内零件号
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
var syncPosition = seDetails.Last().UID.ToString();
jisSeDetails.ForEach(t =>
{
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false);
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (syncPositionFlag != null)
{
syncPositionFlag.Position = wmsRecords.Last().UID.ToString();
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false);
syncPositionFlag.Position = syncPosition;
_settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag);
}
else
{
syncPositionFlag = new SyncPositionFlag()
{
TableName = syncTableName,
Position = wmsRecords.Last().UID.ToString()
Position = syncPosition
};
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false); ;
_settleAccountDbContext.Add<SyncPositionFlag>(syncPositionFlag);
}
await _settleAccountDbContext.BulkInsertAsync(seDetails).ConfigureAwait(false);
await _syncExtendManager.JisSeDetailsSaveConsignAsync<BBAC_SE_DETAIL>(seDetails, isJisTable).ConfigureAwait(false);
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
}
/// <summary>
/// 添加零件关系
/// </summary>
public async Task AddNewMaterialRelationships(IEnumerable<MaterialRelationship> materialRelationships)
{
//新客户零件号和厂内零件号
var noHaveLuRePartCodes = from item1 in materialRelationships
join item2 in _settleAccountDbContext.Set<MaterialRelationship>()
on new { item1.ErpMaterialCode, item1.SettleMaterialCode } equals new { item2.ErpMaterialCode, item2.SettleMaterialCode }
into temp
from item3 in temp.DefaultIfEmpty()
where item3 == null
select item1;
if (noHaveLuRePartCodes.Any())
catch (Exception)
{
await _settleAccountDbContext.BulkInsertAsync(noHaveLuRePartCodes.ToList()).ConfigureAwait(false);
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
}

11
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncAppService.cs

@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +20,8 @@ public class JisHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobService
public JisHBPOSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, syncExtendManager)
) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{
base.SeSyncConfigInfo = new SeSyncConfig()
{
@ -43,7 +36,7 @@ public class JisHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobService
};
}
[UnitOfWork(IsDisabled = false)]
[UnitOfWork(IsDisabled = true)]
public virtual async Task Invoke(IServiceProvider serviceProvider)
{
await this.Invoke().ConfigureAwait(false);

198
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs

@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.LinqAsync;
using System.Threading.Tasks;
using Coravel.Invocable;
using EFCore.BulkExtensions;
using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.Cmp;
using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.MaterialRelationships;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase;
@ -28,26 +24,10 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
/// WMS数据上下文
/// </summary>
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext;
/// <summary>
/// 数据上下文
/// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext;
/// <summary>
/// 同步位置标记
/// </summary>
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository;
/// <summary>
/// Jis发运数据仓储
/// </summary>
private readonly INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> _jisSeDetailRepository;
/// <summary>
/// 客户零件关系领域
/// </summary>
private readonly MaterialRelationshipManager _materialRelationshipManager;
/// <summary>
/// 发运同步扩展
/// </summary>
@ -59,17 +39,12 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
public JisHBPOSeSyncBaseAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager)
{
_wmsBJBMPTContext = wmsBJBMPTContext;
_settleAccountDbContext = settleAccountDbContext;
_syncPositionFlagRepository = syncPositionFlagRepository;
_jisSeDetailRepository = jisSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
_syncExtendManager = syncExtendManager;
_syncExtendManager._settleAccountDbContext = settleAccountDbContext;
}
/// <summary>
@ -78,7 +53,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
public SeSyncConfig SeSyncConfigInfo { get; set; }
[HttpPost]
public async Task Invoke()
public virtual async Task Invoke()
{
if (SeSyncConfigInfo == null)
{
@ -101,64 +76,27 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
//WMS发运记录
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100_000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(wmsSeRecords);
if (jisSeDetails.Any())
var seed = 0;
while (seed < 10)
{
//客户零件号和厂内零件号
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";
//WMS发运记录
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD
.Where(t => t.UID > int.Parse(syncPosition))
.Where(t => t.DeliverBillType == deliverBillType)
.Where(t => deliverSubBillTypes.Contains(t.DeliverSubBillType))
.OrderBy(b => b.UID).Take(100_000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(wmsSeRecords);
if (jisSeDetails.Any())
{
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
await SeDataPutInStorageAsync(jisSeDetails, false).ConfigureAwait(false);
}
jisSeDetails.ForEach(t =>
{
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
var syncPositionNew = jisSeDetails.Last().UID.ToString();
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
if (syncPositionFlag != null)
{
syncPositionFlag.Position = syncPositionNew;
_settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag);
}
else
{
syncPositionFlag = new SyncPositionFlag()
{
TableName = syncTableName,
Position = syncPositionNew
};
_settleAccountDbContext.Add<SyncPositionFlag>(syncPositionFlag);
}
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false);
await _syncExtendManager.JisSeDetailsSaveConsignAsync(jisSeDetails, false).ConfigureAwait(false);
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
else
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
break;
}
}
}
@ -176,54 +114,90 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
var seed = 0;
while (seed < 10)
{
seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";
//WMS发运记录
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD
.Where(t => t.UID > int.Parse(syncPosition))
.Where(t => t.DeliverBillType == deliverBillType)
.Where(t => deliverSubBillTypes.Contains(t.DeliverSubBillType))
.OrderBy(b => b.UID).Take(100_000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<HBPO_SE_DETAIL>>(wmsRecords);
if (jisSeDetails.Any())
{
await SeDataPutInStorageAsync(jisSeDetails, true).ConfigureAwait(false);
}
else
{
break;
}
}
}
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (syncPositionFlag != null)
/// <summary>
/// 发运数据入库
/// </summary>
private async Task SeDataPutInStorageAsync(List<HBPO_SE_DETAIL> seDetails, bool isJisTable)
{
//同步表名称
var syncTableName = isJisTable ? SeSyncConfigInfo.SyncTableName +
"_Jis" : SeSyncConfigInfo.SyncTableName + "_Jit";
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
//客户零件号和厂内零件号
var luRePartCodes = seDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
{
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType);
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
}
//WMS发运数据
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100000).ToList();
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<HBPO_SE_DETAIL>>(wmsRecords);
if (jisSeDetails.Any())
seDetails.ForEach(t =>
{
//客户零件号和厂内零件号
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (luRePartCodes.Any())
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
var syncPosition = seDetails.Last().UID.ToString();
jisSeDetails.ForEach(t =>
{
t.SetId(GuidGenerator.Create());
t.BusinessType = businessType;
t.CustomerPartCodeNoSpace = t.LU.Replace(" ", "");
t.KeyCode = t.PN + t.LU;
if (t.BillTime != null)
{
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
}
});
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false);
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (syncPositionFlag != null)
{
syncPositionFlag.Position = wmsRecords.Last().UID.ToString();
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false);
syncPositionFlag.Position = syncPosition;
_settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag);
}
else
{
syncPositionFlag = new SyncPositionFlag()
{
TableName = syncTableName,
Position = wmsRecords.Last().UID.ToString()
Position = syncPosition
};
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false);
_settleAccountDbContext.Add<SyncPositionFlag>(syncPositionFlag);
}
await _settleAccountDbContext.BulkInsertAsync(seDetails).ConfigureAwait(false);
await _syncExtendManager.JisSeDetailsSaveConsignAsync<HBPO_SE_DETAIL>(seDetails, isJisTable).ConfigureAwait(false);
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
}

10
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JitSeSyncAppService.cs

@ -49,10 +49,6 @@ public class JitSeSyncAppService : ApplicationService, IInvocable
/// 发运同步配置
/// </summary>
public SeSyncConfig SeSyncConfigInfo { get; set; }
/// <summary>
/// Seed
/// </summary>
public int Seed { get; set; }
[HttpPost]
public async Task Invoke()
@ -69,10 +65,10 @@ public class JitSeSyncAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别
var businessType = SeSyncConfigInfo.BusinessType;
while (Seed < 10)
var seed = 0;
while (seed < 10)
{
Seed++;
seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0";

12
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MaiDanBBACSeSyncAppService.cs

@ -3,11 +3,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +22,8 @@ public class MaiDanBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobServi
public MaiDanBBACSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, vmiService)
SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{
base.SeSyncConfigInfo = new SeSyncConfig()
{
@ -43,6 +38,7 @@ public class MaiDanBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobServi
};
}
[UnitOfWork(IsDisabled = true)]
public async Task Invoke(IServiceProvider serviceProvider)
{
await this.Invoke().ConfigureAwait(false);

10
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MaiDanHBPOSeSyncAppService.cs

@ -2,12 +2,9 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -23,11 +20,8 @@ public class MaiDanHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobServi
public MaiDanHBPOSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, syncExtendManager)
) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{
base.SeSyncConfigInfo = new SeSyncConfig()
{
@ -42,7 +36,7 @@ public class MaiDanHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobServi
};
}
[UnitOfWork(IsDisabled = false)]
[UnitOfWork(IsDisabled = true)]
public async Task Invoke(IServiceProvider serviceProvider)
{
await this.Invoke().ConfigureAwait(false);

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/SeSyncExtendManager.cs

@ -37,7 +37,7 @@ public class SeSyncExtendManager : DomainService
//新客户零件号和厂内零件号
var noHaveLuRePartCodes = from item1 in materialRelationships
join item2 in _settleAccountDbContext.Set<MaterialRelationship>()
on new { item1.ErpMaterialCode, item1.SettleMaterialCode } equals new { item2.ErpMaterialCode, item2.SettleMaterialCode }
on new { item1.ErpMaterialCode, item1.SettleMaterialCode, item1.BusinessType } equals new { item2.ErpMaterialCode, item2.SettleMaterialCode, item2.BusinessType }
into temp
from item3 in temp.DefaultIfEmpty()
where item3 == null

Loading…
Cancel
Save