fix 查询处理

This commit is contained in:
2024-08-27 18:17:56 +08:00
parent 482a07ac08
commit 82c1110449

View File

@@ -59,34 +59,46 @@ public class GainfoService : IGainfoService
/// <returns></returns>
public async Task<Pagination<GainfoPageResponse>> GetPageAsync(GainfoPageRequest request)
{
//根据组织架构搜索档案
var where = LinqExpressionExtensions.False<GainfoEntity>();
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<GainfoEntity>();
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<GainfoEntity>()
.And(where)
.Or(gainfo => SqlFunc.Subqueryable<BusinessTripEntity>()
.Where(p => p.Code == gainfo.Code && factories.Contains(p.Destination) && SqlFunc.DateIsSame(p.BeginDate, today))
.Any())
.ToExpression();
}
ISugarQueryable<GainfoPageResponse> queryable = request.IsSearchAll
? _gainfoStore.Queryable(request.Status)
? _dbContext.Queryable<GainfoEntity>().AS("GainfoEntity", "gainfo")
.Where(where)
.LeftJoin<DepartmentEntity>((gainfo, department) => gainfo.DepartmentNo == department.No)
.LeftJoin<BasicTypeEntity>((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<BusinessTripEntity>().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);
//外包人员部门号处理