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) public virtual async Task SyncAsync([FromBody] EnumBusinessType businessType)
{ {
using var scope = this._applicationServices.CreateScope(); using var scope = this._applicationServices.CreateScope();
IInvocable jitSeSyncAppService = businessType switch IInvocable seSyncAppService = businessType switch
{ {
EnumBusinessType.JisBBAC => scope.ServiceProvider.GetRequiredService<JisBBACSeSyncAppService>(), EnumBusinessType.JisBBAC => scope.ServiceProvider.GetRequiredService<JisBBACSeSyncAppService>(),
EnumBusinessType.JisHBPO => scope.ServiceProvider.GetRequiredService<JisHBPOSeSyncAppService>(), EnumBusinessType.JisHBPO => scope.ServiceProvider.GetRequiredService<JisHBPOSeSyncAppService>(),
@ -44,6 +44,6 @@ public class HandSeSyncAppService : ApplicationService
EnumBusinessType.YinDuJian => scope.ServiceProvider.GetRequiredService<YinDuSeSyncAppService>(), EnumBusinessType.YinDuJian => scope.ServiceProvider.GetRequiredService<YinDuSeSyncAppService>(),
_ => throw new ArgumentOutOfRangeException(nameof(businessType), $"Not expected direction value: {businessType}"), _ => 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 System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; 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.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +22,8 @@ public class JisBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobService
public JisBBACSeSyncAppService( public JisBBACSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, SeSyncExtendManager syncExtendManager
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository, ) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, vmiService)
{ {
base.SeSyncConfigInfo = new SeSyncConfig() base.SeSyncConfigInfo = new SeSyncConfig()
{ {
@ -43,6 +38,7 @@ public class JisBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobService
}; };
} }
[UnitOfWork(IsDisabled = true)]
public async Task Invoke(IServiceProvider serviceProvider) public async Task Invoke(IServiceProvider serviceProvider)
{ {
await this.Invoke().ConfigureAwait(false); 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Coravel.Invocable; using Coravel.Invocable;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
using LinqToDB;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.SettleAccount.MaterialRelationships; using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.Shared.RepositoryBase;
@ -25,28 +24,14 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
/// WMS数据上下文 /// WMS数据上下文
/// </summary> /// </summary>
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; private readonly WMSBJBMPTDbContext _wmsBJBMPTContext;
/// <summary> /// <summary>
/// 数据上下文 /// 数据上下文
/// </summary> /// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext; private readonly SettleAccountDbContext _settleAccountDbContext;
/// <summary> /// <summary>
/// 同步位置标记 /// 发运同步扩展
/// </summary> /// </summary>
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository; private readonly SeSyncExtendManager _syncExtendManager;
/// <summary>
/// Jis发运数据仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> _jisSeDetailRepository;
/// <summary>
/// 客户零件关系领域
/// </summary>
private readonly MaterialRelationshipManager _materialRelationshipManager;
//private readonly IVmiService _vmiService;
/// <summary> /// <summary>
/// 构造 /// 构造
@ -54,17 +39,11 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
public JisBBACSeSyncBaseAppService( public JisBBACSeSyncBaseAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, SeSyncExtendManager syncExtendManager)
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService)
{ {
_wmsBJBMPTContext = wmsBJBMPTContext; _wmsBJBMPTContext = wmsBJBMPTContext;
_settleAccountDbContext = settleAccountDbContext; _settleAccountDbContext = settleAccountDbContext;
_syncPositionFlagRepository = syncPositionFlagRepository; _syncExtendManager = syncExtendManager;
_jisSeDetailRepository = jisSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
//_vmiService = vmiService;
} }
/// <summary> /// <summary>
@ -80,7 +59,6 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
return; return;
} }
await SyncJitRecordAsync().ConfigureAwait(false); await SyncJitRecordAsync().ConfigureAwait(false);
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false);
await SyncJisRecordAsync().ConfigureAwait(false); await SyncJisRecordAsync().ConfigureAwait(false);
} }
@ -97,53 +75,27 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别 //业务类别
var businessType = SeSyncConfigInfo.BusinessType; var businessType = SeSyncConfigInfo.BusinessType;
var seed = 0;
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType); while (seed < 10)
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())
{ {
//客户零件号和厂内零件号 seed++;
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList(); var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (luRePartCodes.Any()) 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 SeDataPutInStorageAsync(jisSeDetails, false).ConfigureAwait(false);
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);
} }
else else
{ {
syncPositionFlag = new SyncPositionFlag() break;
{
TableName = syncTableName,
Position = wmsSeRecords.Last().UID.ToString()
};
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false);
} }
} }
} }
@ -161,74 +113,90 @@ public class JisBBACSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别 //业务类别
var businessType = SeSyncConfigInfo.BusinessType; 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); var luRePartCodes = seDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList();
if (syncPositionFlag != null) 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发运数据 seDetails.ForEach(t =>
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())
{ {
//客户零件号和厂内零件号 t.SetId(GuidGenerator.Create());
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList(); t.BusinessType = businessType;
if (luRePartCodes.Any()) 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)); t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
} }
});
var syncPosition = seDetails.Last().UID.ToString();
jisSeDetails.ForEach(t => using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
{ try
t.SetId(GuidGenerator.Create()); {
t.BusinessType = businessType; var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
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) if (syncPositionFlag != null)
{ {
syncPositionFlag.Position = wmsRecords.Last().UID.ToString(); syncPositionFlag.Position = syncPosition;
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); _settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag);
} }
else else
{ {
syncPositionFlag = new SyncPositionFlag() syncPositionFlag = new SyncPositionFlag()
{ {
TableName = syncTableName, 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);
} }
} catch (Exception)
/// <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())
{ {
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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +20,8 @@ public class JisHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobService
public JisHBPOSeSyncAppService( public JisHBPOSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, syncExtendManager) ) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{ {
base.SeSyncConfigInfo = new SeSyncConfig() 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) public virtual async Task Invoke(IServiceProvider serviceProvider)
{ {
await this.Invoke().ConfigureAwait(false); 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.LinqAsync;
using System.Threading.Tasks; using System.Threading.Tasks;
using Coravel.Invocable; using Coravel.Invocable;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
using LinqToDB;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.Cmp;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services; 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.EntityFrameworkCore;
using Win.Sfs.SettleAccount.MaterialRelationships; using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.Shared.RepositoryBase;
@ -28,26 +24,10 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
/// WMS数据上下文 /// WMS数据上下文
/// </summary> /// </summary>
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; private readonly WMSBJBMPTDbContext _wmsBJBMPTContext;
/// <summary> /// <summary>
/// 数据上下文 /// 数据上下文
/// </summary> /// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext; 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>
/// 发运同步扩展 /// 发运同步扩展
/// </summary> /// </summary>
@ -59,17 +39,12 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
public JisHBPOSeSyncBaseAppService( public JisHBPOSeSyncBaseAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager) SeSyncExtendManager syncExtendManager)
{ {
_wmsBJBMPTContext = wmsBJBMPTContext; _wmsBJBMPTContext = wmsBJBMPTContext;
_settleAccountDbContext = settleAccountDbContext; _settleAccountDbContext = settleAccountDbContext;
_syncPositionFlagRepository = syncPositionFlagRepository;
_jisSeDetailRepository = jisSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
_syncExtendManager = syncExtendManager; _syncExtendManager = syncExtendManager;
_syncExtendManager._settleAccountDbContext = settleAccountDbContext;
} }
/// <summary> /// <summary>
@ -78,7 +53,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
public SeSyncConfig SeSyncConfigInfo { get; set; } public SeSyncConfig SeSyncConfigInfo { get; set; }
[HttpPost] [HttpPost]
public async Task Invoke() public virtual async Task Invoke()
{ {
if (SeSyncConfigInfo == null) if (SeSyncConfigInfo == null)
{ {
@ -101,64 +76,27 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别 //业务类别
var businessType = SeSyncConfigInfo.BusinessType; var businessType = SeSyncConfigInfo.BusinessType;
var seed = 0;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false); while (seed < 10)
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())
{ {
//客户零件号和厂内零件号 seed++;
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList(); var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
if (luRePartCodes.Any()) 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 SeDataPutInStorageAsync(jisSeDetails, false).ConfigureAwait(false);
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
} }
else
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)
{ {
await transaction.RollbackAsync().ConfigureAwait(false); break;
throw;
} }
} }
} }
@ -176,54 +114,90 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别 //业务类别
var businessType = SeSyncConfigInfo.BusinessType; 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); /// <summary>
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName).ConfigureAwait(false); /// 发运数据入库
if (syncPositionFlag != null) /// </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发运数据 seDetails.ForEach(t =>
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())
{ {
//客户零件号和厂内零件号 t.SetId(GuidGenerator.Create());
var luRePartCodes = jisSeDetails.Where(t => !string.IsNullOrEmpty(t.LU) && !string.IsNullOrEmpty(t.FactoryPartCode)).Select(t => new { t.LU, t.FactoryPartCode }).Distinct().ToList(); t.BusinessType = businessType;
if (luRePartCodes.Any()) 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)); t.Version = int.Parse(t.BillTime?.ToString("yyyyMM"));
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
} }
});
var syncPosition = seDetails.Last().UID.ToString();
jisSeDetails.ForEach(t => using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
{ try
t.SetId(GuidGenerator.Create()); {
t.BusinessType = businessType; var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
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) if (syncPositionFlag != null)
{ {
syncPositionFlag.Position = wmsRecords.Last().UID.ToString(); syncPositionFlag.Position = syncPosition;
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); _settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag);
} }
else else
{ {
syncPositionFlag = new SyncPositionFlag() syncPositionFlag = new SyncPositionFlag()
{ {
TableName = syncTableName, 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> /// </summary>
public SeSyncConfig SeSyncConfigInfo { get; set; } public SeSyncConfig SeSyncConfigInfo { get; set; }
/// <summary>
/// Seed
/// </summary>
public int Seed { get; set; }
[HttpPost] [HttpPost]
public async Task Invoke() public async Task Invoke()
@ -69,10 +65,10 @@ public class JitSeSyncAppService : ApplicationService, IInvocable
var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes; var deliverSubBillTypes = SeSyncConfigInfo.SyncDeliverSubBillTypes;
//业务类别 //业务类别
var businessType = SeSyncConfigInfo.BusinessType; var businessType = SeSyncConfigInfo.BusinessType;
var seed = 0;
while (Seed < 10) while (seed < 10)
{ {
Seed++; seed++;
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false); var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false);
var syncPosition = syncPositionFlag?.Position ?? "0"; 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 System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; 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.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -24,11 +22,8 @@ public class MaiDanBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobServi
public MaiDanBBACSeSyncAppService( public MaiDanBBACSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, SeSyncExtendManager syncExtendManager
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> jisSeDetailRepository, ) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
MaterialRelationshipManager materialRelationshipManager,
VmiAppService vmiService
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, vmiService)
{ {
base.SeSyncConfigInfo = new SeSyncConfig() base.SeSyncConfigInfo = new SeSyncConfig()
{ {
@ -43,6 +38,7 @@ public class MaiDanBBACSeSyncAppService : JisBBACSeSyncBaseAppService, IJobServi
}; };
} }
[UnitOfWork(IsDisabled = true)]
public async Task Invoke(IServiceProvider serviceProvider) public async Task Invoke(IServiceProvider serviceProvider)
{ {
await this.Invoke().ConfigureAwait(false); 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.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; using Win.Sfs.SettleAccount.Entities.BQ.Vmi;
using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.EntityFrameworkCore;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -23,11 +20,8 @@ public class MaiDanHBPOSeSyncAppService : JisHBPOSeSyncBaseAppService, IJobServi
public MaiDanHBPOSeSyncAppService( public MaiDanHBPOSeSyncAppService(
WMSBJBMPTDbContext wmsBJBMPTContext, WMSBJBMPTDbContext wmsBJBMPTContext,
SettleAccountDbContext settleAccountDbContext, SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository,
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository,
MaterialRelationshipManager materialRelationshipManager,
SeSyncExtendManager syncExtendManager SeSyncExtendManager syncExtendManager
) : base(wmsBJBMPTContext, settleAccountDbContext, syncPositionFlagRepository, jisSeDetailRepository, materialRelationshipManager, syncExtendManager) ) : base(wmsBJBMPTContext, settleAccountDbContext, syncExtendManager)
{ {
base.SeSyncConfigInfo = new SeSyncConfig() 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) public async Task Invoke(IServiceProvider serviceProvider)
{ {
await this.Invoke().ConfigureAwait(false); 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 var noHaveLuRePartCodes = from item1 in materialRelationships
join item2 in _settleAccountDbContext.Set<MaterialRelationship>() 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 into temp
from item3 in temp.DefaultIfEmpty() from item3 in temp.DefaultIfEmpty()
where item3 == null where item3 == null

Loading…
Cancel
Save