|
|
@ -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()}"); |
|
|
|
try |
|
|
|
{ |
|
|
|
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 |
|
|
|
lock (_lockObj) |
|
|
|
{ |
|
|
|
se.PN, |
|
|
|
se.LU |
|
|
|
} equals new |
|
|
|
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()) |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
if (ediDetails.Any()) |
|
|
|
{ |
|
|
|
ediDetails.ForEach(t => t.IsHaveSeData = true); |
|
|
|
db.Set<HBPO_SE_EDI>().UpdateRange(ediDetails); |
|
|
|
await db.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
Debug.WriteLine($"处理数量:{keyCodes.Count()}"); |
|
|
|
} |
|
|
|
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 })); |
|
|
|
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); |
|
|
|
ediDetails.ForEach(t => t.IsHaveSeData = 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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|