From 72cb3e9fc2527a29b293d34da2592efcbcbebea7 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Mon, 4 Dec 2023 17:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20/DataSync/SyncVesselDateLi?= =?UTF-8?q?st=20=E6=8E=A5=E5=8F=A3=E5=90=8C=E6=AD=A5=E8=88=B9=E6=9C=9F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=B6=EF=BC=8C=E8=AF=AF=E6=8A=8AATD?= =?UTF-8?q?=E3=80=81=E4=BA=91=E6=B8=AF=E9=80=9AETD=E7=AD=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9B=B4=E6=96=B0=E4=B8=BAnull=E7=9A=84bug=EF=BC=9B?= =?UTF-8?q?=E9=A1=BA=E4=BE=BF=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/DataSync/DataSyncService.cs | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index a03b64d9..4d679e69 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -468,20 +468,25 @@ namespace Myshipping.Application [SqlSugarUnitOfWork] public async Task SyncVesselDateList(List model) { + Lazy> mapcarrier = new(() => _mapcarrier.Where(x => x.Module == "HeChuan").ToList()); - var mapcarrier = _mapcarrier.Where(x => x.Module == "HeChuan").ToList(); - var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList(); - var mlist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList(); - var orderlist = _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList(); foreach (var item in model) { - var CreatedUserId = userlist.Where(x => x.Name == item.CreatedUserName).Select(x => x.Id).FirstOrDefault(); + var CreatedUserId = await _repUser.AsQueryable() + .Filter(null, true) + .Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.CreatedUserName) + .Select(x => x.Id) + .FirstAsync(); + if (string.IsNullOrWhiteSpace(item.BSNO)) { throw Oops.Bah("BSNO未录入"); } //根据东胜bsno获取当前数据查询不到则为新增 - var m = mlist.Where(x => x.BSNO == item.BSNO).FirstOrDefault(); + var m = await _vesselinfo.AsQueryable() + .Filter(null, true) + .Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.BSNO == item.BSNO) + .FirstAsync(); var entity = item.Adapt(); entity.Vessel = item.Vessel.ToUpper().Trim(); if (!string.IsNullOrEmpty(item.CARRIER)) @@ -490,7 +495,7 @@ namespace Myshipping.Application if (string.IsNullOrEmpty(entity.CARRIERID)) { - entity.CARRIERID = mapcarrier.Where(x => x.MapName == item.CARRIER).Select(x => x.Code).FirstOrDefault(); + entity.CARRIERID = mapcarrier.Value.Where(x => x.MapName == item.CARRIER).Select(x => x.Code).FirstOrDefault(); } if (string.IsNullOrEmpty(entity.CARRIERID)) { @@ -509,7 +514,11 @@ namespace Myshipping.Application if (m == null) { //查询是否存在相同船名航次数据 - var e = mlist.Where(x => x.CARRIERID == entity.CARRIERID && x.Vessel == entity.Vessel && x.Voyno == entity.Voyno && x.VoynoInside == entity.VoynoInside).FirstOrDefault(); + var e = await _vesselinfo.AsQueryable() + .Filter(null, true) + .Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.CARRIERID == entity.CARRIERID && x.Vessel == entity.Vessel && x.Voyno == entity.Voyno && x.VoynoInside == entity.VoynoInside) + .FirstAsync(); + //2023年7月27日,王书岚:航次为V.开头的不查询船期 if (!string.IsNullOrEmpty(entity.VoynoInside) && entity.VoynoInside.StartsWith("V.")) { @@ -526,7 +535,7 @@ namespace Myshipping.Application { entity.ETA = e.ETA; } - await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).ExecuteCommandAsync(); + await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } } else @@ -541,15 +550,18 @@ namespace Myshipping.Application { entity.ETA = m.ETA; } - await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).ExecuteCommandAsync(); + await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } ////根据船公司船名航次更新船期信息 if (!string.IsNullOrEmpty(item.CARRIER) && !string.IsNullOrEmpty(item.Vessel) && (!string.IsNullOrEmpty(item.Voyno) || !string.IsNullOrWhiteSpace(item.VoynoInside))) { - - var order = orderlist.Where(x => x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel) - .WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno) - .WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside).Distinct().ToList(); + var order = await _rep.AsQueryable() + .Filter(null, true) + .Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel) + .WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno) + .WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside) + .Distinct() + .ToListAsync(); _logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据"); foreach (var it in order)