查询条件优化

master
zhangxiaofeng 5 months ago
parent 68fa2c2d87
commit fe17d0008e

@ -85,12 +85,16 @@ namespace EntrustSettle.Api.Controllers
} }
} }
// 运踪筛选条件 // 可以查看所有数据的用户Gid列表
List<string> queryBilltraceGidList = null; var seeAllDataUserGids = AppSettings.app<string>("Startup", "SeeAllDataUserGids");
PageModel<OrderDto> result;
if (input.BillTraceState != null || input.AtaStart != null || input.AtaEnd != null) if (input.BillTraceState != null || input.AtaStart != null || input.AtaEnd != null)
{ {
var billtraceGidPageList = await billtraceService.AsQueryable() var billtraceGidPageList = await billtraceService.AsQueryable()
.Where(x => x.IsOuter == true && x.CompID == App.User.CompanyId) .Where(x => x.IsOuter == true)
.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompID == App.User.CompanyId)
.WhereIF(input.BillTraceState == 1, x => x.StaCangDan == "Y") .WhereIF(input.BillTraceState == 1, x => x.StaCangDan == "Y")
.WhereIF(input.BillTraceState == 2, x => x.StaHaiGuan == "Y") .WhereIF(input.BillTraceState == 2, x => x.StaHaiGuan == "Y")
.WhereIF(input.BillTraceState == 3, x => x.StaTiHuo == "Y") .WhereIF(input.BillTraceState == 3, x => x.StaTiHuo == "Y")
@ -101,25 +105,38 @@ namespace EntrustSettle.Api.Controllers
.Select(x => x.GID) .Select(x => x.GID)
.ToPageListAsyncExtension(input.pageIndex, input.pageSize); .ToPageListAsyncExtension(input.pageIndex, input.pageSize);
queryBilltraceGidList = billtraceGidPageList.data; List<string> queryBilltraceGidList = billtraceGidPageList.data;
var tempResult = await orderService.AsQueryable()
.Where(x => queryBilltraceGidList.Contains(x.BilltraceGid))
.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompanyId == App.User.CompanyId) // 衣国豪的账号在客户端也可以看全部数据
.WhereIF(!string.IsNullOrWhiteSpace(input.Mblno), x => x.Mblno.Contains(input.Mblno))
.WhereIF(!string.IsNullOrWhiteSpace(input.CompanyName), x => x.CompanyName.Contains(input.CompanyName))
.WhereIF(!string.IsNullOrWhiteSpace(input.Remark), x => x.Remark.Contains(input.Remark))
.WhereIF(input.ServiceType != null, x => x.ServiceType == input.ServiceType)
.WhereIF(input.Status != null, x => x.Status == (int)input.Status)
.WhereIF(input.CreateTimeStart != null, x => x.CreateTime >= input.CreateTimeStart)
.WhereIF(input.CreateTimeEnd != null, x => x.CreateTime <= input.CreateTimeEnd)
.Select<OrderDto>()
.OrderBy("id desc")
.ToListAsync();
result = new PageModel<OrderDto>(input.pageIndex, billtraceGidPageList.dataCount, input.pageSize, tempResult);
}
else
{
result = await orderService.AsQueryable()
.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompanyId == App.User.CompanyId) // 衣国豪的账号在客户端也可以看全部数据
.WhereIF(!string.IsNullOrWhiteSpace(input.Mblno), x => x.Mblno.Contains(input.Mblno))
.WhereIF(!string.IsNullOrWhiteSpace(input.CompanyName), x => x.CompanyName.Contains(input.CompanyName))
.WhereIF(!string.IsNullOrWhiteSpace(input.Remark), x => x.Remark.Contains(input.Remark))
.WhereIF(input.ServiceType != null, x => x.ServiceType == input.ServiceType)
.WhereIF(input.Status != null, x => x.Status == (int)input.Status)
.WhereIF(input.CreateTimeStart != null, x => x.CreateTime >= input.CreateTimeStart)
.WhereIF(input.CreateTimeEnd != null, x => x.CreateTime <= input.CreateTimeEnd)
.Select<OrderDto>()
.OrderBy("id desc")
.ToPageListAsyncExtension(input.pageIndex, input.pageSize);
} }
// 可以查看所有数据的用户Gid列表
var seeAllDataUserGids = AppSettings.app<string>("Startup", "SeeAllDataUserGids");
PageModel<OrderDto> result = await orderService.AsQueryable()
.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompanyId == App.User.CompanyId) // 衣国豪的账号在客户端也可以看全部数据
.WhereIF(!string.IsNullOrWhiteSpace(input.Mblno), x => x.Mblno.Contains(input.Mblno))
.WhereIF(!string.IsNullOrWhiteSpace(input.CompanyName), x => x.CompanyName.Contains(input.CompanyName))
.WhereIF(!string.IsNullOrWhiteSpace(input.Remark), x => x.Remark.Contains(input.Remark))
.WhereIF(input.ServiceType != null, x => x.ServiceType == input.ServiceType)
.WhereIF(input.Status != null, x => x.Status == (int)input.Status)
.WhereIF(input.CreateTimeStart != null, x => x.CreateTime >= input.CreateTimeStart)
.WhereIF(input.CreateTimeEnd != null, x => x.CreateTime <= input.CreateTimeEnd)
.WhereIF(queryBilltraceGidList != null, x => queryBilltraceGidList.Contains(x.BilltraceGid))
.Select<OrderDto>()
.OrderBy("id desc")
.ToPageListAsyncExtension(input.pageIndex, input.pageSize);
//var sql = orderService.AsQueryable() //var sql = orderService.AsQueryable()
//.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompanyId == App.User.CompanyId).ToSqlString(); //.WhereIF(!seeAllDataUserGids.Contains(App.User.ID) && input.QueryType != 2, x => x.CompanyId == App.User.CompanyId).ToSqlString();

@ -12,7 +12,7 @@ public static class PagedQueryableExtensions
public static async Task<PageModel<TEntity>> ToPageListAsyncExtension<TEntity>(this ISugarQueryable<TEntity> query, int pageIndex, int pageSize) public static async Task<PageModel<TEntity>> ToPageListAsyncExtension<TEntity>(this ISugarQueryable<TEntity> query, int pageIndex, int pageSize)
{ {
RefAsync<int> totalCount = 0; RefAsync<int> totalCount = 0;
var data = await query.ToPageListAsync(pageIndex, pageSize, totalCount); System.Collections.Generic.List<TEntity> data = await query.ToPageListAsync(pageIndex, pageSize, totalCount);
return new PageModel<TEntity>(pageIndex, totalCount, pageSize, data); return new PageModel<TEntity>(pageIndex, totalCount, pageSize, data);
} }
} }
Loading…
Cancel
Save