|
@ -2,13 +2,16 @@ using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Linq.Expressions; |
|
|
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 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.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; |
|
@ -45,8 +48,10 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
/// 客户零件关系领域
|
|
|
/// 客户零件关系领域
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private readonly MaterialRelationshipManager _materialRelationshipManager; |
|
|
private readonly MaterialRelationshipManager _materialRelationshipManager; |
|
|
|
|
|
/// <summary>
|
|
|
//private readonly IVmiService _vmiService;
|
|
|
/// 发运同步扩展
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly SeSyncExtendManager _syncExtendManager; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 构造
|
|
|
/// 构造
|
|
@ -57,14 +62,14 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
|
|
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
|
|
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository, |
|
|
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> jisSeDetailRepository, |
|
|
MaterialRelationshipManager materialRelationshipManager, |
|
|
MaterialRelationshipManager materialRelationshipManager, |
|
|
VmiAppService vmiService) |
|
|
SeSyncExtendManager syncExtendManager) |
|
|
{ |
|
|
{ |
|
|
_wmsBJBMPTContext = wmsBJBMPTContext; |
|
|
_wmsBJBMPTContext = wmsBJBMPTContext; |
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
_syncPositionFlagRepository = syncPositionFlagRepository; |
|
|
_syncPositionFlagRepository = syncPositionFlagRepository; |
|
|
_jisSeDetailRepository = jisSeDetailRepository; |
|
|
_jisSeDetailRepository = jisSeDetailRepository; |
|
|
_materialRelationshipManager = materialRelationshipManager; |
|
|
_materialRelationshipManager = materialRelationshipManager; |
|
|
//_vmiService = vmiService;
|
|
|
_syncExtendManager = syncExtendManager; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -80,8 +85,7 @@ public class JisHBPOSeSyncBaseAppService : 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); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -98,15 +102,12 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
//业务类别
|
|
|
//业务类别
|
|
|
var businessType = SeSyncConfigInfo.BusinessType; |
|
|
var businessType = SeSyncConfigInfo.BusinessType; |
|
|
|
|
|
|
|
|
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
var syncPositionFlag = await _settleAccountDbContext.Set<SyncPositionFlag>().FirstOrDefaultAsync(t => t.TableName == syncTableName).ConfigureAwait(false); |
|
|
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName).ConfigureAwait(false); |
|
|
var syncPosition = syncPositionFlag?.Position ?? "0"; |
|
|
if (syncPositionFlag != null) |
|
|
|
|
|
{ |
|
|
|
|
|
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == deliverBillType && deliverSubBillTypes.Contains(t.DeliverSubBillType); |
|
|
//WMS发运记录
|
|
|
//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); |
|
|
var jisSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(wmsSeRecords); |
|
|
if (jisSeDetails.Any()) |
|
|
if (jisSeDetails.Any()) |
|
|
{ |
|
|
{ |
|
@ -115,7 +116,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
if (luRePartCodes.Any()) |
|
|
if (luRePartCodes.Any()) |
|
|
{ |
|
|
{ |
|
|
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType)); |
|
|
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 => |
|
|
jisSeDetails.ForEach(t => |
|
@ -129,21 +130,35 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable |
|
|
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM")); |
|
|
t.Version = int.Parse(t.BillTime?.ToString("yyyyMM")); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
await _settleAccountDbContext.BulkInsertAsync(jisSeDetails).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
if (syncPositionFlag != null) |
|
|
var syncPositionNew = jisSeDetails.Last().UID.ToString(); |
|
|
|
|
|
|
|
|
|
|
|
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false); |
|
|
|
|
|
try |
|
|
{ |
|
|
{ |
|
|
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString(); |
|
|
if (syncPositionFlag != null) |
|
|
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); |
|
|
{ |
|
|
|
|
|
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); |
|
|
} |
|
|
} |
|
|
else |
|
|
catch (Exception) |
|
|
{ |
|
|
{ |
|
|
syncPositionFlag = new SyncPositionFlag() |
|
|
await transaction.RollbackAsync().ConfigureAwait(false); |
|
|
{ |
|
|
throw; |
|
|
TableName = syncTableName, |
|
|
|
|
|
Position = wmsSeRecords.Last().UID.ToString() |
|
|
|
|
|
}; |
|
|
|
|
|
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|