|
|
@ -2,13 +2,16 @@ 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 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; |
|
|
@ -45,8 +48,10 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
/// 客户零件关系领域
|
|
|
|
/// </summary>
|
|
|
|
private readonly MaterialRelationshipManager _materialRelationshipManager; |
|
|
|
|
|
|
|
//private readonly IVmiService _vmiService;
|
|
|
|
/// <summary>
|
|
|
|
/// 发运同步扩展
|
|
|
|
/// </summary>
|
|
|
|
private readonly SeSyncExtendManager _syncExtendManager; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
@ -57,14 +62,14 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
|
|
|
INormalEfCoreRepository<HBPO_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,8 +85,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
return; |
|
|
|
} |
|
|
|
await SyncJitRecordAsync().ConfigureAwait(false); |
|
|
|
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
await SyncJisRecordAsync().ConfigureAwait(false); |
|
|
|
//await SyncJisRecordAsync().ConfigureAwait(false);
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -98,15 +102,12 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
//业务类别
|
|
|
|
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); |
|
|
|
} |
|
|
|
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(100000).ToList(); |
|
|
|
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()) |
|
|
|
{ |
|
|
@ -115,7 +116,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
if (luRePartCodes.Any()) |
|
|
|
{ |
|
|
|
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType)); |
|
|
|
await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); |
|
|
|
await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
jisSeDetails.ForEach(t => |
|
|
@ -129,21 +130,35 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
|
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM")); |
|
|
|
} |
|
|
|
}); |
|
|
|
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false); |
|
|
|
|
|
|
|
var syncPositionNew = jisSeDetails.Last().UID.ToString(); |
|
|
|
|
|
|
|
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false); |
|
|
|
try |
|
|
|
{ |
|
|
|
if (syncPositionFlag != null) |
|
|
|
{ |
|
|
|
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString(); |
|
|
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); |
|
|
|
syncPositionFlag.Position = syncPositionNew; |
|
|
|
_settleAccountDbContext.Update<SyncPositionFlag>(syncPositionFlag); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
syncPositionFlag = new SyncPositionFlag() |
|
|
|
{ |
|
|
|
TableName = syncTableName, |
|
|
|
Position = wmsSeRecords.Last().UID.ToString() |
|
|
|
Position = syncPositionNew |
|
|
|
}; |
|
|
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false); |
|
|
|
_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); |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|