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);
//外包人员部门号处理