From 5d2d6f7b2923ed9814e176df7709b6d83c0a606f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 2 Mar 2026 10:11:17 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E9=9D=9E=E9=97=B0=E5=B9=B429=E5=8F=B7?= =?UTF-8?q?=E7=94=9F=E6=97=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/BirthdayVoucherService.cs | 12 ++++++++---- .../Jobs/GenerateBirthdayVoucherJob.cs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.Canteen/Voucher/Services/Implements/BirthdayVoucherService.cs b/Src/Dlhis.Canteen/Voucher/Services/Implements/BirthdayVoucherService.cs index 032fe680..fd818319 100644 --- a/Src/Dlhis.Canteen/Voucher/Services/Implements/BirthdayVoucherService.cs +++ b/Src/Dlhis.Canteen/Voucher/Services/Implements/BirthdayVoucherService.cs @@ -52,7 +52,6 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService .Where(x => departmentNos.Contains(x.No)) .ToListAsync(); - foreach (var gainfo in gainfos.Where(x => x.Birthday.HasValue)) { await DbContext.Client.Ado.BeginTranAsync(); @@ -65,8 +64,6 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService years = years.Where(y => { var r = gainfo.EntryDate.Value.Date < SafeDateForYear(y, gainfo.Birthday.Value); - - if (!r) { events.Add(new UserBusinessEventEntity @@ -221,6 +218,7 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService var factries = await _factorySettingApi.GetEnableBirthdayVoucherFactoriesAsync(); var isToday = begin.Date == end.Date; + var includeLeapDayBirthday = isToday && begin.Month == 2 && begin.Day == 28 && !DateTime.IsLeapYear(begin.Year); var beginMonth = begin.Month; var endMonth = end.Month; @@ -246,7 +244,13 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService .Where(x => x.Type == GainfoUserTypeEnumType.Normal || x.Type == GainfoUserTypeEnumType.SecurityWhite) .Where(x => x.Birthday.HasValue) //.Where(x => !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) + // 正常情况:匹配当天生日 + .WhereIF(isToday && !includeLeapDayBirthday, x => SqlFunc.DateValue(x.Birthday.Value, DateType.Month) == begin.Month && SqlFunc.DateValue(x.Birthday.Value, DateType.Day) == begin.Day) + // 特殊情况:非闰年的2月28日,同时匹配当天生日和2月29日生日 + .WhereIF(isToday && includeLeapDayBirthday, x => + (SqlFunc.DateValue(x.Birthday.Value, DateType.Month) == begin.Month && SqlFunc.DateValue(x.Birthday.Value, DateType.Day) == begin.Day) + || + (SqlFunc.DateValue(x.Birthday.Value, DateType.Month) == 2 && SqlFunc.DateValue(x.Birthday.Value, DateType.Day) == 29)) .WhereIF(!isToday && !overYear, x => SqlFunc.DateValue(x.Birthday.Value, DateType.Month) >= beginMonth && SqlFunc.DateValue(x.Birthday.Value, DateType.Month) <= endMonth) .WhereIF(!isToday && overYear, x => SqlFunc.DateValue(x.Birthday.Value, DateType.Month) >= beginMonth || SqlFunc.DateValue(x.Birthday.Value, DateType.Month) <= endMonth) .Where(x => factries.Contains(x.Factory)) diff --git a/Src/Dlhis.ScheduledTask/Jobs/GenerateBirthdayVoucherJob.cs b/Src/Dlhis.ScheduledTask/Jobs/GenerateBirthdayVoucherJob.cs index 3c7969e2..eab86399 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/GenerateBirthdayVoucherJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/GenerateBirthdayVoucherJob.cs @@ -15,7 +15,7 @@ public class GenerateBirthdayVoucherJob : BaseJob protected override async Task RunAsync(IServiceProvider serviceProvider) { - var now = DateTime.Today.Date; + var now = new DateTime(2026, 2, 28); //DateTime.Today.Date; var voucherApi = serviceProvider.GetService(); await voucherApi.CreateAsync(new VoucherByBirthdayRequest