fix 修复查询

This commit is contained in:
2025-12-10 14:30:17 +08:00
parent 17c5d6a54c
commit 7a50b21592
3 changed files with 15 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ using Dlhis.Canteen.Voucher.Requests;
using Dlhis.Canteen.Voucher.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities.Voucher;
using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
@@ -13,19 +14,24 @@ namespace Dlhis.Canteen.Tickets.Services.Implements;
public abstract class BaseVoucherService : IVoucherService
{
private readonly ICurrentUser _currentUser;
protected IDbContext DbContext { get; set; }
protected BaseVoucherService(IDbContext dbContext)
protected BaseVoucherService(IServiceProvider serviceProvider)
{
DbContext = dbContext;
DbContext = serviceProvider.GetService<IDbContext>();
_currentUser = serviceProvider.GetService<ICurrentUser>();
}
public async Task<Pagination<VoucherPageResponse>> GetPageAsync(VoucherPageRequest request)
{
var tenantId = _currentUser.GetStringTenantId();
var pagination = await DbContext.Queryable<VoucherEntity>()
.LeftJoin<VoucherUserInfoEntity>((x, u) => x.No == u.VoucherNo)
.LeftJoin<GainfoEntity>((x, u, ga) => u.UserCode == ga.Code)
.Where(x => x.Type == request.Type)
.Where((x, u) => x.Type == request.Type && u.Factory == tenantId)
.WhereIF(request.UserCode.IsPresent(), (x, u, ga) => u.UserCode == request.UserCode)
.WhereIF(request.SearchDateTimePeriod.HasValue(),
(x, u, ga) => x.CreateTime >= request.SearchDateTimePeriod.Start &&

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text;
using Dlhis.Basic.Api;
using Dlhis.Canteen.Tickets.Services;
@@ -15,7 +14,6 @@ using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using SqlSugar;
@@ -27,9 +25,9 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
private readonly IFactorySettingApi _factorySettingApi;
/// <inheritdoc />
public BirthdayVoucherService(IDbContext dbContext, IFactorySettingApi factorySettingApi) : base(dbContext)
public BirthdayVoucherService(IServiceProvider serviceProvider) : base(serviceProvider)
{
_factorySettingApi = factorySettingApi;
_factorySettingApi = serviceProvider.GetService<IFactorySettingApi>();
}
/// <inheritdoc />
@@ -164,6 +162,7 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
//var limit = end.Date.AddHours(9);//9点入职
return await DbContext.Queryable<GainfoEntity>()
.WhereIF(userCodes.IsPresent(), x => userCodes.Contains(x.Code))
.Where(x => !SqlFunc.IsNullOrEmpty(x.DepartmentNo))
.Where(x => x.Type == GainfoUserTypeEnumType.Normal || x.Type == GainfoUserTypeEnumType.SecurityWhite)
.Where(x => x.Birthday.HasValue && !string.IsNullOrEmpty(x.CostId))
.WhereIF(isToday, x => SqlFunc.DateValue(x.Birthday.Value, DateType.Month) == begin.Month && SqlFunc.DateValue(x.Birthday.Value, DateType.Day) == begin.Day)
@@ -222,7 +221,7 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
return await DbContext.Queryable<BalanceRecordEntity>()
.LeftJoin<BusinessPlaceEntity>((x, bPlace) => x.BusinessPlaceCode == bPlace.Code)
.LeftJoin<DepartmentEntity>((x, bPlace, department) => x.DepartmentNo == department.No)
.Where(x => x.UserCode == request.UserCode)
.WhereIF(request.UserCode.IsPresent(), x => x.UserCode == request.UserCode)
.WhereIF(request.SearchDateTimePeriod.HasValue(), x => x.CostDate >= request.SearchDateTimePeriod.Start && x.CostDate <= request.SearchDateTimePeriod.End) //成本日期
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid && x.Type == BalanceRecordTypeEnumType.Out) //有效,消费数据
.Where(x => x.Source == BalanceRecordSourceEnumType.Birthday)