Browse Source

Jis发运同步

master
mahao 1 year ago
parent
commit
5a5ca9f39e
  1. 18
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs
  2. 13
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs
  3. 72
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs
  4. 97
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs
  5. 3
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs
  6. 10
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs
  7. 11
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs

18
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/BBACSeSyncAppService.cs

@ -39,14 +39,14 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService
private readonly INormalEfCoreRepository<BBAC_SE_DETAIL, Guid> _bbacSeDetailRepository;
/// <summary>
/// 客户零件关系仓储
/// 客户零件关系领域
/// </summary>
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _materialRelationshipRepository;
private readonly MaterialRelationshipManager _materialRelationshipManager;
/// <summary>
/// 客户零件关系领域
/// 客户零件关系集合
/// </summary>
private readonly MaterialRelationshipManager _materialRelationshipManager;
private List<MaterialRelationship> _addMaterialRelationships;
/// <summary>
/// 构造
@ -61,6 +61,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService
_syncPositionFlagRepository = syncPositionFlagRepository;
_bbacSeDetailRepository = bbacSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
_addMaterialRelationships = new List<MaterialRelationship>();
}
[ApiExplorerSettings(IgnoreApi = true)]
@ -74,6 +75,11 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService
{
await SyncJitRecordAsync();
await SyncJisRecordAsync();
if (_addMaterialRelationships.Any())
{
_addMaterialRelationships = _addMaterialRelationships.GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList();
await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false);
}
}
/// <summary>
@ -101,7 +107,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService
{
//客户零件号和厂内零件号
var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, ""));
await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
_addMaterialRelationships.AddRange(materialRelationships);
bbacSeDetails.ForEach(bbacSeDetail =>
{
@ -151,7 +157,7 @@ public class BBACSeSyncAppService : ApplicationService, IInvocable, IJobService
{
//客户零件号和厂内零件号
var materialRelationships = bbacSeDetails.GroupBy(t => new { t.LU, t.PartCode }).Select(t => new MaterialRelationship(GuidGenerator.Create(), t.Key.LU, "", t.Key.PartCode, ""));
await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
_addMaterialRelationships.AddRange(materialRelationships);
bbacSeDetails.ForEach(bbacSeDetail => bbacSeDetail.KeyCode = bbacSeDetail.PN + bbacSeDetail.LU);
await _bbacSeDetailRepository.InsertManyAsync(bbacSeDetails);

13
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/HBPOSeSyncAppService.cs

@ -49,6 +49,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService
/// </summary>
private readonly MaterialRelationshipManager _materialRelationshipManager;
/// <summary>
/// 客户零件关系集合
/// </summary>
private List<MaterialRelationship> _addMaterialRelationships;
/// <summary>
/// 构造
/// </summary>
@ -64,6 +69,7 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService
_hbpoSeDetailRepository = hbpoSeDetailRepository;
_pubSeDetailRepository = pubSeDetailRepository;
_materialRelationshipManager = materialRelationshipManager;
_addMaterialRelationships = new List<MaterialRelationship>();
}
[ApiExplorerSettings(IgnoreApi = true)]
@ -80,6 +86,11 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService
{
await SyncJitRecordAsync().ConfigureAwait(false);
await SyncJisRecordAsync().ConfigureAwait(false);
if (_addMaterialRelationships.Any())
{
_addMaterialRelationships = _addMaterialRelationships.GroupBy(t => new { t.ErpMaterialCode }).Select(t => t.First()).ToList();
await _materialRelationshipManager.AddNewMaterialRelationships(_addMaterialRelationships).ConfigureAwait(false);
}
}
/// <summary>
@ -200,7 +211,7 @@ public class HBPOSeSyncAppService : ApplicationService, IInvocable, IJobService
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, ""));
await _materialRelationshipManager.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false);
_addMaterialRelationships.AddRange(materialRelationships);
hbpoSeDetails.ForEach(hbpoSeDetail => hbpoSeDetail.KeyCode = hbpoSeDetail.PN + hbpoSeDetail.LU);
maiDanHBPOSeDetails.ForEach(maiDanHBPOSeDetail =>

72
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs

@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coravel.Invocable;
using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services;
@ -16,6 +18,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
[ApiExplorerSettings(IgnoreApi = true)]
public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
{
private readonly object _lockObj = new object();
private readonly IServiceProvider _serviceProvider;
public JisBBACSeEdiCompareAppService(IServiceProvider serviceProvider)
@ -28,21 +31,39 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
/// </summary>
public async Task Invoke()
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
var seDetailGroup = db.Set<BBAC_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var ediDetailGroup = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU });
var seDetails = db.Set<BBAC_SE_DETAIL>().Where(t => keyCodes.Contains(new { t.PN, t.LU }));
var ediDetails = db.Set<BBAC_SE_EDI>().Where(t => keyCodes.Contains(new { t.PN, t.LU }));
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
db.Set<BBAC_SE_DETAIL>().UpdateRange(seDetails);
db.Set<BBAC_SE_EDI>().UpdateRange(ediDetails);
await db.SaveChangesAsync().ConfigureAwait(false);
await HandDelEdiDataAsync().ConfigureAwait(false);
lock (_lockObj)
{
var seDetailGroup = db.Set<BBAC_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var ediDetailGroup = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU });
if (keyCodes.Any())
{
var seDetails = db.Set<BBAC_SE_DETAIL>().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
var ediDetails = db.Set<BBAC_SE_EDI>().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = true);
db.Set<BBAC_SE_DETAIL>().UpdateRange(seDetails);
}
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = true);
db.Set<BBAC_SE_EDI>().UpdateRange(ediDetails);
}
db.SaveChanges();
}
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
@ -61,12 +82,21 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
//Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct();
var seDetails = db.Set<BBAC_SE_DETAIL>().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU }));
var ediDetails = db.Set<BBAC_SE_EDI>().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU }));
seDetails.ForEach(t => t.IsHaveEdiData = false);
ediDetails.ForEach(t => t.IsHaveSeData = false);
db.Set<BBAC_SE_DETAIL>().UpdateRange(seDetails);
db.Set<BBAC_SE_EDI>().UpdateRange(ediDetails);
await db.SaveChangesAsync().ConfigureAwait(false);
if (ediDelKeyCodes.Any())
{
var seDetails = db.Set<BBAC_SE_DETAIL>().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
var ediDetails = db.Set<BBAC_SE_EDI>().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = false);
db.Set<BBAC_SE_DETAIL>().UpdateRange(seDetails);
}
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = false);
db.Set<BBAC_SE_EDI>().UpdateRange(ediDetails);
}
await db.SaveChangesAsync().ConfigureAwait(false);
}
}
}

97
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

@ -20,6 +20,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
[ApiExplorerSettings(IgnoreApi = true)]
public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
{
private readonly object _lockObj = new object();
private readonly IServiceProvider _serviceProvider;
/// <summary>
@ -46,48 +47,39 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
/// </summary>
public async Task Invoke()
{
Debug.WriteLine($"执行了:{this.GetType()}");
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = from se in db.Set<HBPO_SE_DETAIL>()
where se.IsHaveEdiData == false
group se by new { se.PN, se.LU }
into a
select new { a.Key.PN, a.Key.LU };
var ediDetailGroup = from edi in db.Set<HBPO_SE_EDI>()
where edi.IsDeleted == false && edi.IsHaveSeData == false
group edi by new { edi.PN, edi.LU }
into a
select new { a.Key.PN, a.Key.LU };
var keyCodes = from se in seDetailGroup
join edi in ediDetailGroup on new
{
se.PN,
se.LU
} equals new
{
edi.PN,
edi.LU
}
select new { se.PN, se.LU };
//var seDetailGroup2 = db.Set<HBPO_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
//var ediDetailGroup2 = db.Set<HBPO_SE_EDI>().Where(t => t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
//var keyCodes2 = seDetailGroup2.Join(ediDetailGroup2, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU });
var seDetails = db.Set<HBPO_SE_DETAIL>().Where(t => keyCodes.Contains(new { t.PN, t.LU }));
var ediDetails = db.Set<HBPO_SE_EDI>().Where(t => keyCodes.Contains(new { t.PN, t.LU }));
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
db.Set<HBPO_SE_DETAIL>().UpdateRange(seDetails);
db.Set<HBPO_SE_EDI>().UpdateRange(ediDetails);
await db.SaveChangesAsync().ConfigureAwait(false);
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
Debug.WriteLine($"处理数量:{keyCodes.Count()}");
await HandDelEdiDataAsync().ConfigureAwait(false);
lock (_lockObj)
{
var seDetailGroup = db.Set<HBPO_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var ediDetailGroup = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.LU }).Select(t => new { t.Key.PN, t.Key.LU });
var keyCodes = seDetailGroup.Join(ediDetailGroup, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (se, edi) => new { se.PN, se.LU });
if (keyCodes.Any())
{
var seDetails = db.Set<HBPO_SE_DETAIL>().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
var ediDetails = db.Set<HBPO_SE_EDI>().Join(keyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = true);
db.Set<HBPO_SE_DETAIL>().UpdateRange(seDetails);
}
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = true);
db.Set<HBPO_SE_EDI>().UpdateRange(ediDetails);
}
db.SaveChanges();
}
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
@ -100,12 +92,21 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
//Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct();
var seDetails = db.Set<HBPO_SE_DETAIL>().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU }));
var ediDetails = db.Set<HBPO_SE_EDI>().Where(t => ediDelKeyCodes.Contains(new { t.PN, t.LU }));
seDetails.ForEach(t => t.IsHaveEdiData = false);
ediDetails.ForEach(t => t.IsHaveSeData = false);
db.Set<HBPO_SE_DETAIL>().UpdateRange(seDetails);
db.Set<HBPO_SE_EDI>().UpdateRange(ediDetails);
await db.SaveChangesAsync().ConfigureAwait(false);
if (ediDelKeyCodes.Any())
{
var seDetails = db.Set<HBPO_SE_DETAIL>().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
var ediDetails = db.Set<HBPO_SE_EDI>().Join(ediDelKeyCodes, a => new { a.PN, a.LU }, b => new { b.PN, b.LU }, (a, b) => a);
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = false);
db.Set<HBPO_SE_DETAIL>().UpdateRange(seDetails);
}
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = false);
db.Set<HBPO_SE_EDI>().UpdateRange(ediDetails);
}
await db.SaveChangesAsync().ConfigureAwait(false);
}
}
}

3
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/MaterialRelationshipManager.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Services;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase;
@ -29,7 +30,7 @@ public class MaterialRelationshipManager : DomainService
{
//客户零件号和厂内零件号
var luRePartCodes = materialRelationships.Select(t => new { t.ErpMaterialCode, t.SettleMaterialCode }).Distinct().ToList();
var haveLuRePartCodes = materialRelationships.Join(_materialRelationshipRepository,
var haveLuRePartCodes = materialRelationships.Join(_materialRelationshipRepository.AsNoTracking(),
a => new { a.ErpMaterialCode, a.SettleMaterialCode },
b => new { b.ErpMaterialCode, b.SettleMaterialCode },
(a, b) => a).ToList();

10
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIS_RECORD.cs

@ -35,8 +35,8 @@ public class TM_BJBMPT_JIS_RECORD
[DisplayName("JIS生产码类型")]
public string CodeType { get; set; }
[DisplayName("状态")]
public EnumBillState State { get; set; }
//[DisplayName("状态")]
//public EnumBillState State { get; set; }
[DisplayName("订单零件号")]
public string RealPartCode { get; set; }
@ -51,7 +51,7 @@ public class TM_BJBMPT_JIS_RECORD
public string CustPartCode { get; set; }
[DisplayName("数量")]
public decimal Qty { get; set; }
public decimal? Qty { get; set; }
[DisplayName("发货单号")]
public string BillNum { get; set; }
@ -60,7 +60,7 @@ public class TM_BJBMPT_JIS_RECORD
public string MESConfigCode { get; set; }
[DisplayName("订单时间")]
public DateTime AssembleData { get; set; }
public DateTime? AssembleData { get; set; }
[DisplayName("来源库位")]
public string FromLoc { get; set; }
@ -120,5 +120,5 @@ public class TM_BJBMPT_JIS_RECORD
public string Position { get; set; }
[DisplayName("创建时间")]
public DateTime CreateTime { get; set; }
public DateTime? CreateTime { get; set; }
}

11
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Syncs/TM_BJBMPT_JIT_RECORD.cs

@ -39,7 +39,7 @@ public class TM_BJBMPT_JIT_RECORD
public string Seq { get; set; }
[DisplayName("订单时间")]
public DateTime AssembleData { get; set; }
public DateTime? AssembleData { get; set; }
[DisplayName("发货条码")]
public string DeliverCode { get; set; }
@ -89,9 +89,6 @@ public class TM_BJBMPT_JIT_RECORD
[DisplayName("原生产码")]
public string OrigiCode { get; set; }
[DisplayName("描述")]
public string PartDesc { get; set; }
[DisplayName("备注")]
public string Remark { get; set; }
@ -125,11 +122,11 @@ public class TM_BJBMPT_JIT_RECORD
[DisplayName("虚拟小总成")]
public string MatchNumber { get; set; }
[DisplayName("状态")]
public EnumBillState State { get; set; }
//[DisplayName("状态")]
//public EnumBillState State { get; set; }
[DisplayName("创建时间")]
public DateTime CreateTime { get; set; }
public DateTime? CreateTime { get; set; }
}
public enum EnumProTpe

Loading…
Cancel
Save