From 82c111044944a10f6bb0be35b74f558f68c335a0 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Aug 2024 18:17:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=9F=A5=E8=AF=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoService.cs | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 556095ab..52cd2cb9 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -59,34 +59,46 @@ public class GainfoService : IGainfoService /// public async Task> GetPageAsync(GainfoPageRequest request) { - //根据组织架构搜索档案 - var where = LinqExpressionExtensions.False(); - foreach (var item in request.DepartmentSelections) - { - var searchDepartments = await GetRecursionDepartmentNosAsync(item.DepartmentNos); - where = searchDepartments.Any() - ? where.Or(gainfo => gainfo.Factory == item.Tenant && searchDepartments.Contains(gainfo.DepartmentNo)) - : where.Or(gainfo => gainfo.Factory == item.Tenant); - } - - //获取所有厂区 - var factories = request.DepartmentSelections.Select(x => x.Tenant).ToList(); - if (factories.Count == 0) - { - factories = _currentUser.GetUserClaim("tenants").Split(",").ToList(); - } - var today = DateTime.Today; + //根据组织架构搜索档案 + var where = LinqExpressionExtensions.False(); + var factories = _currentUser.GetUserClaim("tenants").Split(",").ToList(); + if (request.DepartmentSelections.Any()) + { + foreach (var item in request.DepartmentSelections) + { + var searchDepartments = await GetRecursionDepartmentNosAsync(item.DepartmentNos); + where = searchDepartments.Any() + ? where.Or(gainfo => gainfo.Factory == item.Tenant && searchDepartments.Contains(gainfo.DepartmentNo)) + : where.Or(gainfo => gainfo.Factory == item.Tenant); + } + + factories = request.DepartmentSelections.Select(x => x.Tenant).Distinct().ToList(); + } + else + { + where = where.Or(gainfo => factories.Contains(gainfo.Factory)); + } + + + if (request.IsSearchAll) + { + where = Expressionable.Create() + .And(where) + .Or(gainfo => SqlFunc.Subqueryable() + .Where(p => p.Code == gainfo.Code && factories.Contains(p.Destination) && SqlFunc.DateIsSame(p.BeginDate, today)) + .Any()) + .ToExpression(); + } + ISugarQueryable queryable = request.IsSearchAll - ? _gainfoStore.Queryable(request.Status) + ? _dbContext.Queryable().AS("GainfoEntity", "gainfo") + .Where(where) .LeftJoin((gainfo, department) => gainfo.DepartmentNo == department.No) .LeftJoin((gainfo, department, type) => type.Code == SqlFunc.ToString(gainfo.CardType) && type.Type == "timeperiod") - .WhereIF(request.DepartmentSelections?.Any() == true, where) - .WhereIF(request.DepartmentSelections?.Any() == false, gainfo => factories.Contains(gainfo.Factory) || - SqlFunc.Subqueryable().Where(p => p.Code == gainfo.Code && factories.Contains(p.Destination) && SqlFunc.DateIsSame(p.BeginDate, today)).Any()) .WhereIF(request.Search.IsPresent(), gainfo => - gainfo.Name.Contains(request.Search) + gainfo.Name == request.Search || gainfo.Code == request.Search || gainfo.IdNo == request.Search) .Select((gainfo, department, type) => new GainfoPageResponse @@ -116,6 +128,7 @@ public class GainfoService : IGainfoService CardTypeName = type.Display }, true); + _logger.LogInformation(queryable.ToSqlString()); var page = await queryable.ToPageListAsync(request); //外包人员部门号处理