diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs index 0de93ca2..73cf8aaa 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs @@ -596,410 +596,333 @@ public class ClientCommonService : IClientCommonService var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = new List(); + var parList = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable) + .Select() + .ToList(); - var carrier = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsCarrier == true) - .Select((a, b) => new ClientSelectRes + var clientList = tenantDb.Queryable() + .Where(a => a.Status == StatusEnum.Enable.ToEnumInt()); + var carrier = await clientList.Where(a=> SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsCarrier == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent + BLContent = a.BLContent, }) .Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); }) .ToListAsync(); data.Add(new ClientSelectMultiRes("carrier", carrier)); - var yard = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsYard == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ) - .Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var yard = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsYard == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("yard", yard)); - var booking = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsBooking == true) - .Select((a, b) => new ClientSelectRes + var booking = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsBooking == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("booking", booking)); - var truck = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsTruck == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var truck = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsTruck == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("truck", truck)); - var controller = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsController == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var controller = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsController == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("controller", controller)); - var custom = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsCustom == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var custom = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsCustom == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("custom", custom)); - var agent = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsAgent == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var agent = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsAgent == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("agent", agent)); - var agentcn = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsAgentCn == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var agentcn = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsAgentCn == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("agentcn", agentcn)); - var express = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsExpress == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var express = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsExpress == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("express", express)); - var airlines = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsAirLines == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => + var airlines = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsAirLines == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("airlines", airlines)); - var shipper = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsShipper == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var shipper = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsShipper == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("shipper", shipper)); - var shippercn = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsShipperCn == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + var shippercn = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsShipperCn == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("shippercn", shippercn)); - var notifyparty = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsNotifyParty == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => + var notifyparty = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsNotifyParty == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("notifyparty", notifyparty)); - var warehouse = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsWareHouse == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => + var warehouse = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsWareHouse == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("warehouse", warehouse)); - var wharf = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsWharf == true) - .Select((a, b) => new ClientSelectRes - { - Id = a.Id, - CodeName = a.CodeName, - ShortName = a.ShortName, - EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => + var wharf = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsWharf == true).Any()) + .Select(a => new ClientSelectRes + { + Id = a.Id, + CodeName = a.CodeName, + ShortName = a.ShortName, + EnShortName = a.EnShortName, + BLContent = a.BLContent, + }) + .Mapper(it => { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("wharf", wharf)); - var insurer = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsInsurer == true) - .Select((a, b) => new ClientSelectRes + var insurer = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsInsurer == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("insurer", insurer)); - var leasing = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsLeasing == true) - .Select((a, b) => new ClientSelectRes + var leasing = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsLeasing == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("leasing", leasing)); - var tradingagency = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsTradingAgency == true) - .Select((a, b) => new ClientSelectRes + var tradingagency = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsTradingAgency == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("tradingagency", tradingagency)); - var shipagency = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsShipAgency == true) - .Select((a, b) => new ClientSelectRes + var shipagency = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsShipAgency == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); data.Add(new ClientSelectMultiRes("shipagency", shipagency)); - var enterprise = await tenantDb.Queryable() - .InnerJoin((a, b) => a.Id == b.ClientId) - .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsEnterprise == true) - .Select((a, b) => new ClientSelectRes + var enterprise = await clientList.Where(a => SqlFunc.Subqueryable().Where(s => s.ClientId == a.Id && s.IsEnterprise == true).Any()) + .Select(a => new ClientSelectRes { Id = a.Id, CodeName = a.CodeName, ShortName = a.ShortName, EnShortName = a.EnShortName, - BLContent = a.BLContent - } - ).Mapper(it => - { - it.ClientParams = tenantDb.Queryable() - .Where(x => x.CustomerId == it.Id && x.Status == StatusEnum.Enable) - .Select() - .ToList(); - }).ToListAsync(); - data.Add(new ClientSelectMultiRes("enterprise", enterprise)); + BLContent = a.BLContent, + }) + .Mapper(it => + { + it.ClientParams = parList.Where(x => x.CustomerId == it.Id).ToList(); + }) + .ToListAsync(); return await Task.FromResult(DataResult>.Success(data)); }