fix 查询优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.Core.CustomClass;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
@@ -6,6 +7,17 @@ namespace Dlhis.Canteen.MealSupplementRecord.Request;
|
||||
|
||||
public class MealSupplementRecordRequest : PageDto, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 餐补状态 MealSupplementStatusEnumtype
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(MealSupplementStatusEnumtype))]
|
||||
public MealSupplementStatusEnumtype? Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 同步状态
|
||||
/// </summary>
|
||||
public bool? Sync { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐补日期范围
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Dlhis.Canteen.MealSupplementRecord.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Sys.Api;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
@@ -17,36 +18,60 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
||||
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
|
||||
public MealSupplementRecordService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public MealSupplementRecordService(IDbContext dbContext, ICurrentUser currentUser, ITenantApi tenantApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_tenantApi = tenantApi;
|
||||
}
|
||||
|
||||
public async Task<Pagination<MealSupplementRecordResponse>> GetPageAsync(MealSupplementRecordRequest request)
|
||||
{
|
||||
var page = await _dbContext.Queryable<MealSupplementRecordEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.Code == ga.Code)
|
||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name.Contains(request.Search))
|
||||
.WhereIF(request.DateTimePeriod?.Start.HasValue == true && request.DateTimePeriod?.End.HasValue == true,
|
||||
.WhereIF(request.Status.HasValue, x => x.Status == request.Status)
|
||||
.WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync)
|
||||
.WhereIF(request.DateTimePeriod?.Start.HasValue == true
|
||||
&& request.DateTimePeriod?.End.HasValue == true,
|
||||
x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End)
|
||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search)
|
||||
.Select((x, ga) => new MealSupplementRecordResponse
|
||||
{
|
||||
Amount = x.Amount,
|
||||
Code = x.Code,
|
||||
Date = x.Date,
|
||||
Factory = x.Factory,
|
||||
Remark = x.Remark,
|
||||
Result = x.Result,
|
||||
Status = x.Status,
|
||||
Sync = x.Sync,
|
||||
UniqueId = x.UniqueId,
|
||||
UserName = ga.Name,
|
||||
|
||||
Workplace = x.Workplace,
|
||||
Factory = x.Factory,
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var tenantsResult = await _tenantApi.GetTenantsInternalAsync();
|
||||
var tenants = tenantsResult.Data;
|
||||
|
||||
page.Data.ForEach(item =>
|
||||
{
|
||||
item.Workplace = tenants.FirstOrDefault(x => x.Code == item.Workplace)?.Name;
|
||||
item.Factory = tenants.FirstOrDefault(x => x.Code == item.Factory)?.Name;
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user