mahao
1 year ago
5 changed files with 7 additions and 432 deletions
@ -1,195 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Threading.Tasks; |
|||
using Coravel.Invocable; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using SettleAccount.Domain.BQ; |
|||
using Volo.Abp.Application.Services; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Managers; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
|||
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.MaterialRelationships; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
|||
|
|||
/// <summary>
|
|||
/// HBPO发运数据同步
|
|||
/// </summary>
|
|||
[AllowAnonymous] |
|||
[Route("api/settleaccount/[controller]/[action]")]
|
|||
public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService |
|||
{ |
|||
/// <summary>
|
|||
/// WMS数据上下文
|
|||
/// </summary>
|
|||
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; |
|||
|
|||
/// <summary>
|
|||
/// 同步位置标记
|
|||
/// </summary>
|
|||
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository; |
|||
|
|||
/// <summary>
|
|||
/// HBPO发运数据仓储
|
|||
/// </summary>
|
|||
private readonly INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> _bbacSeDetailRepository; |
|||
|
|||
/// <summary>
|
|||
/// 客户零件关系领域
|
|||
/// </summary>
|
|||
private readonly MaterialRelationshipManager _materialRelationshipManager; |
|||
|
|||
/// <summary>
|
|||
/// 客户零件关系集合
|
|||
/// </summary>
|
|||
private List<MaterialRelationship> _addMaterialRelationships; |
|||
|
|||
/// <summary>
|
|||
/// 构造
|
|||
/// </summary>
|
|||
public BBACSeSyncAppService( |
|||
WMSBJBMPTDbContext wmsBJBMPTContext, |
|||
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
|||
INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> bbacSeDetailRepository, |
|||
MaterialRelationshipManager materialRelationshipManager) |
|||
{ |
|||
_wmsBJBMPTContext = wmsBJBMPTContext; |
|||
_syncPositionFlagRepository = syncPositionFlagRepository; |
|||
_bbacSeDetailRepository = bbacSeDetailRepository; |
|||
_materialRelationshipManager = materialRelationshipManager; |
|||
_addMaterialRelationships = new List<MaterialRelationship>(); |
|||
} |
|||
|
|||
[ApiExplorerSettings(IgnoreApi = true)] |
|||
public async Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
await this.Invoke().ConfigureAwait(false); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public async Task Invoke() |
|||
{ |
|||
await SyncJitRecordAsync().ConfigureAwait(false); |
|||
await SyncJisRecordAsync().ConfigureAwait(false); |
|||
if (_addMaterialRelationships.Any()) |
|||
{ |
|||
_addMaterialRelationships = _addMaterialRelationships.Where(t => !string.IsNullOrEmpty(t.ErpMaterialCode)).GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList(); |
|||
await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 同步JitRecord
|
|||
/// </summary>
|
|||
private async Task SyncJitRecordAsync() |
|||
{ |
|||
//同步表名称
|
|||
var syncTableName = "JisBBACSeSync_Jit"; |
|||
//BBAC类型集合
|
|||
var EnumDeliverSubBillTypes = GetDeliverSubBillTypes(); |
|||
|
|||
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.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 == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|||
} |
|||
|
|||
//WMS发运记录
|
|||
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100000).ToList(); |
|||
|
|||
var bbacSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<BBAC_SE_DETAIL>>(wmsSeRecords); |
|||
if (bbacSeDetails.Any()) |
|||
{ |
|||
//客户零件号和厂内零件号
|
|||
var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); |
|||
_addMaterialRelationships.AddRange(materialRelationships); |
|||
|
|||
bbacSeDetails.ForEach(bbacSeDetail => |
|||
{ |
|||
bbacSeDetail.KeyCode = bbacSeDetail.PN + bbacSeDetail.LU; |
|||
bbacSeDetail.BusinessType = EnumBusinessType.JisBBAC; |
|||
}); |
|||
await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails); |
|||
|
|||
if (syncPositionFlag != null) |
|||
{ |
|||
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString(); |
|||
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
|||
} |
|||
else |
|||
{ |
|||
syncPositionFlag = new SyncPositionFlag() |
|||
{ |
|||
TableName = syncTableName, |
|||
Position = wmsSeRecords.Last().UID.ToString() |
|||
}; |
|||
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 同步JisRecord
|
|||
/// </summary>
|
|||
private async Task SyncJisRecordAsync() |
|||
{ |
|||
//同步表名称
|
|||
var syncTableName = "JisBBACSeSync_Jis"; |
|||
//BBAC类型集合
|
|||
var EnumDeliverSubBillTypes = GetDeliverSubBillTypes(); |
|||
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|||
var syncPositionFlag = await _syncPositionFlagRepository.FindAsync(t => t.TableName == syncTableName); |
|||
if (syncPositionFlag != null) |
|||
{ |
|||
predicate = (t) => t.UID > int.Parse(syncPositionFlag.Position) && t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|||
} |
|||
|
|||
//WMS发运数据
|
|||
var wmsRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).Take(100000).ToList(); |
|||
|
|||
var bbacSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<BBAC_SE_DETAIL>>(wmsRecords); |
|||
if (bbacSeDetails.Any()) |
|||
{ |
|||
//客户零件号和厂内零件号
|
|||
var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); |
|||
_addMaterialRelationships.AddRange(materialRelationships); |
|||
|
|||
bbacSeDetails.ForEach(bbacSeDetail => bbacSeDetail.KeyCode = bbacSeDetail.PN + bbacSeDetail.LU); |
|||
await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails); |
|||
|
|||
if (syncPositionFlag != null) |
|||
{ |
|||
syncPositionFlag.Position = wmsRecords.Last().UID.ToString(); |
|||
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag); |
|||
} |
|||
else |
|||
{ |
|||
syncPositionFlag = new SyncPositionFlag() |
|||
{ |
|||
TableName = syncTableName, |
|||
Position = wmsRecords.Last().UID.ToString() |
|||
}; |
|||
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取BBAC类型集合
|
|||
/// </summary>
|
|||
private List<EnumDeliverSubBillType> GetDeliverSubBillTypes() |
|||
{ |
|||
return new List<EnumDeliverSubBillType> |
|||
{ |
|||
EnumDeliverSubBillType.保险杠BBAC, |
|||
EnumDeliverSubBillType.买单件保险杠BBAC, |
|||
EnumDeliverSubBillType.买单件小件BBAC, |
|||
EnumDeliverSubBillType.小件BBAC |
|||
}; |
|||
} |
|||
} |
@ -1,225 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Linq.Expressions; |
|||
using System.Threading.Tasks; |
|||
using Coravel.Invocable; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using SettleAccount.Domain.BQ; |
|||
using Volo.Abp.Application.Services; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Managers; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Vmi; |
|||
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.MaterialRelationships; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; |
|||
|
|||
/// <summary>
|
|||
/// HBPO发运数据同步
|
|||
/// </summary>
|
|||
[AllowAnonymous] |
|||
[Route("api/settleaccount/[controller]/[action]")]
|
|||
public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService |
|||
{ |
|||
/// <summary>
|
|||
/// WMS数据上下文
|
|||
/// </summary>
|
|||
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; |
|||
|
|||
/// <summary>
|
|||
/// 同步位置标记
|
|||
/// </summary>
|
|||
private readonly INormalEfCoreRepository<SyncPositionFlag, Guid> _syncPositionFlagRepository; |
|||
|
|||
/// <summary>
|
|||
/// HBPO发运数据仓储
|
|||
/// </summary>
|
|||
private readonly INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> _hbpoSeDetailRepository; |
|||
|
|||
/// <summary>
|
|||
/// PUB发运数据仓储
|
|||
/// </summary>
|
|||
private readonly INormalEfCoreRepository<PUB_SE_DETAIL, Guid> _pubSeDetailRepository; |
|||
|
|||
/// <summary>
|
|||
/// 客户零件关系领域
|
|||
/// </summary>
|
|||
private readonly MaterialRelationshipManager _materialRelationshipManager; |
|||
|
|||
/// <summary>
|
|||
/// 客户零件关系集合
|
|||
/// </summary>
|
|||
private List<MaterialRelationship> _addMaterialRelationships; |
|||
|
|||
/// <summary>
|
|||
/// 构造
|
|||
/// </summary>
|
|||
public HBPOSeSyncAppService( |
|||
WMSBJBMPTDbContext wmsBJBMPTContext, |
|||
INormalEfCoreRepository<SyncPositionFlag, Guid> syncPositionFlagRepository, |
|||
INormalEfCoreRepository<HBPO_SE_DETAIL, Guid> hbpoSeDetailRepository, |
|||
INormalEfCoreRepository<PUB_SE_DETAIL, Guid> pubSeDetailRepository, |
|||
MaterialRelationshipManager materialRelationshipManager) |
|||
{ |
|||
_wmsBJBMPTContext = wmsBJBMPTContext; |
|||
_syncPositionFlagRepository = syncPositionFlagRepository; |
|||
_hbpoSeDetailRepository = hbpoSeDetailRepository; |
|||
_pubSeDetailRepository = pubSeDetailRepository; |
|||
_materialRelationshipManager = materialRelationshipManager; |
|||
_addMaterialRelationships = new List<MaterialRelationship>(); |
|||
} |
|||
|
|||
[ApiExplorerSettings(IgnoreApi = true)] |
|||
public async Task Invoke(IServiceProvider serviceProvider) |
|||
{ |
|||
await this.Invoke().ConfigureAwait(false); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 执行
|
|||
/// </summary>
|
|||
[HttpPost] |
|||
public async Task Invoke() |
|||
{ |
|||
await SyncJitRecordAsync().ConfigureAwait(false); |
|||
await SyncJisRecordAsync().ConfigureAwait(false); |
|||
if (_addMaterialRelationships.Any()) |
|||
{ |
|||
_addMaterialRelationships = _addMaterialRelationships.Where(t => !string.IsNullOrEmpty(t.ErpMaterialCode)).GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList(); |
|||
await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 同步JitRecord
|
|||
/// </summary>
|
|||
private async Task SyncJitRecordAsync() |
|||
{ |
|||
//同步表名称
|
|||
var syncTableName = "JisHBPOSeSync_Jit"; |
|||
//HBPO类型集合
|
|||
var EnumDeliverSubBillTypes = GetDeliverSubBillTypes(); |
|||
Expression<Func<TM_BJBMPT_JIT_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.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 == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|||
} |
|||
|
|||
//WMS发运数据
|
|||
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIT_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
|||
if (wmsSeRecords.Any()) |
|||
{ |
|||
//JisHBPO发运
|
|||
var hbpoWmsSeRecords = wmsSeRecords.FindAll(t => t.DeliverSubBillType == EnumDeliverSubBillType.保险杠HBPO || t.DeliverSubBillType == EnumDeliverSubBillType.小件HBPO); |
|||
//买单件HBPO发运
|
|||
var maiDanHBPOWmsSeRecords = wmsSeRecords.FindAll(t => t.DeliverSubBillType == EnumDeliverSubBillType.买单件保险杠HBPO || t.DeliverSubBillType == EnumDeliverSubBillType.买单件小件HBPO); |
|||
|
|||
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<HBPO_SE_DETAIL>>(hbpoWmsSeRecords); |
|||
var maiDanHBPOSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIT_RECORD>, List<PUB_SE_DETAIL>>(maiDanHBPOWmsSeRecords); |
|||
|
|||
await SaveSeDataAsync(hbpoSeDetails, maiDanHBPOSeDetails).ConfigureAwait(false); |
|||
|
|||
if (syncPositionFlag != null) |
|||
{ |
|||
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString(); |
|||
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); |
|||
} |
|||
else |
|||
{ |
|||
syncPositionFlag = new SyncPositionFlag() |
|||
{ |
|||
TableName = syncTableName, |
|||
Position = wmsSeRecords.Last().UID.ToString() |
|||
}; |
|||
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false); ; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 同步JisRecord
|
|||
/// </summary>
|
|||
private async Task SyncJisRecordAsync() |
|||
{ |
|||
//同步表名称
|
|||
var syncTableName = "JisHBPOSeSync_Jis"; |
|||
//BBAC类型集合
|
|||
var EnumDeliverSubBillTypes = GetDeliverSubBillTypes(); |
|||
Expression<Func<TM_BJBMPT_JIS_RECORD, bool>> predicate = (t) => t.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.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 == EnumDeliverBjBmpBillType.JIS件 && EnumDeliverSubBillTypes.Contains(t.DeliverSubBillType); |
|||
} |
|||
|
|||
//WMS发运数据
|
|||
var wmsSeRecords = _wmsBJBMPTContext.TM_BJBMPT_JIS_RECORD.Where(predicate).OrderBy(b => b.UID).ToList(); |
|||
if (wmsSeRecords.Any()) |
|||
{ |
|||
//JisHBPO发运
|
|||
var hbpoWmsSeRecords = wmsSeRecords.FindAll(t => t.DeliverSubBillType == EnumDeliverSubBillType.保险杠HBPO || t.DeliverSubBillType == EnumDeliverSubBillType.小件HBPO); |
|||
//买单件HBPO发运
|
|||
var maiDanHBPOWmsSeRecords = wmsSeRecords.FindAll(t => t.DeliverSubBillType == EnumDeliverSubBillType.买单件保险杠HBPO || t.DeliverSubBillType == EnumDeliverSubBillType.买单件小件HBPO); |
|||
|
|||
var hbpoSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<HBPO_SE_DETAIL>>(hbpoWmsSeRecords); |
|||
var maiDanHBPOSeDetails = ObjectMapper.Map<List<TM_BJBMPT_JIS_RECORD>, List<PUB_SE_DETAIL>>(maiDanHBPOWmsSeRecords); |
|||
|
|||
await SaveSeDataAsync(hbpoSeDetails, maiDanHBPOSeDetails).ConfigureAwait(false); |
|||
|
|||
if (syncPositionFlag != null) |
|||
{ |
|||
syncPositionFlag.Position = wmsSeRecords.Last().UID.ToString(); |
|||
await _syncPositionFlagRepository.UpdateAsync(syncPositionFlag).ConfigureAwait(false); |
|||
} |
|||
else |
|||
{ |
|||
syncPositionFlag = new SyncPositionFlag() |
|||
{ |
|||
TableName = syncTableName, |
|||
Position = wmsSeRecords.Last().UID.ToString() |
|||
}; |
|||
await _syncPositionFlagRepository.InsertAsync(syncPositionFlag).ConfigureAwait(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取HBPO类型集合
|
|||
/// </summary>
|
|||
private List<EnumDeliverSubBillType> GetDeliverSubBillTypes() |
|||
{ |
|||
return new List<EnumDeliverSubBillType> |
|||
{ |
|||
EnumDeliverSubBillType.保险杠HBPO, |
|||
EnumDeliverSubBillType.买单件保险杠HBPO, |
|||
EnumDeliverSubBillType.买单件小件HBPO, |
|||
EnumDeliverSubBillType.小件HBPO |
|||
}; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 保存发运树
|
|||
/// </summary>
|
|||
private async Task SaveSeDataAsync(List<HBPO_SE_DETAIL> hbpoSeDetails, List<PUB_SE_DETAIL> maiDanHBPOSeDetails) |
|||
{ |
|||
//客户零件号和厂内零件号
|
|||
var hbpoSeLuRePartCodes = hbpoSeDetails.Select(t => new { t.LU, t.PartCode }); |
|||
var maiDanHBPOSeLuRePartCodes = maiDanHBPOSeDetails.Select(t => new { t.LU, t.PartCode }); |
|||
var luRePartCodes = hbpoSeLuRePartCodes.Union(maiDanHBPOSeLuRePartCodes); |
|||
var materialRelationships = luRePartCodes.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, "")); |
|||
_addMaterialRelationships.AddRange(materialRelationships); |
|||
|
|||
hbpoSeDetails.ForEach(hbpoSeDetail => hbpoSeDetail.KeyCode = hbpoSeDetail.PN + hbpoSeDetail.LU); |
|||
maiDanHBPOSeDetails.ForEach(maiDanHBPOSeDetail => |
|||
{ |
|||
maiDanHBPOSeDetail.KeyCode = maiDanHBPOSeDetail.PN + maiDanHBPOSeDetail.LU; |
|||
maiDanHBPOSeDetail.BusinessType = EnumBusinessType.MaiDanJianHBPO; |
|||
}); |
|||
await _hbpoSeDetailRepository.InsertManyAsync(hbpoSeDetails).ConfigureAwait(false); |
|||
await _pubSeDetailRepository.InsertManyAsync(maiDanHBPOSeDetails).ConfigureAwait(false); |
|||
} |
|||
} |
Loading…
Reference in new issue