fix 非闰年29号生日问题

This commit is contained in:
2026-03-02 10:11:17 +08:00
parent c367d2b253
commit 5d2d6f7b29
2 changed files with 9 additions and 5 deletions

View File

@@ -52,7 +52,6 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
.Where(x => departmentNos.Contains(x.No)) .Where(x => departmentNos.Contains(x.No))
.ToListAsync(); .ToListAsync();
foreach (var gainfo in gainfos.Where(x => x.Birthday.HasValue)) foreach (var gainfo in gainfos.Where(x => x.Birthday.HasValue))
{ {
await DbContext.Client.Ado.BeginTranAsync(); await DbContext.Client.Ado.BeginTranAsync();
@@ -65,8 +64,6 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
years = years.Where(y => years = years.Where(y =>
{ {
var r = gainfo.EntryDate.Value.Date < SafeDateForYear(y, gainfo.Birthday.Value); var r = gainfo.EntryDate.Value.Date < SafeDateForYear(y, gainfo.Birthday.Value);
if (!r) if (!r)
{ {
events.Add(new UserBusinessEventEntity events.Add(new UserBusinessEventEntity
@@ -221,6 +218,7 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
var factries = await _factorySettingApi.GetEnableBirthdayVoucherFactoriesAsync(); var factries = await _factorySettingApi.GetEnableBirthdayVoucherFactoriesAsync();
var isToday = begin.Date == end.Date; var isToday = begin.Date == end.Date;
var includeLeapDayBirthday = isToday && begin.Month == 2 && begin.Day == 28 && !DateTime.IsLeapYear(begin.Year);
var beginMonth = begin.Month; var beginMonth = begin.Month;
var endMonth = end.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.Type == GainfoUserTypeEnumType.Normal || x.Type == GainfoUserTypeEnumType.SecurityWhite)
.Where(x => x.Birthday.HasValue) .Where(x => x.Birthday.HasValue)
//.Where(x => !string.IsNullOrEmpty(x.CostId)) //.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)
.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)) .Where(x => factries.Contains(x.Factory))

View File

@@ -15,7 +15,7 @@ public class GenerateBirthdayVoucherJob : BaseJob
protected override async Task RunAsync(IServiceProvider serviceProvider) 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<IVoucherApi>(); var voucherApi = serviceProvider.GetService<IVoucherApi>();
await voucherApi.CreateAsync(new VoucherByBirthdayRequest await voucherApi.CreateAsync(new VoucherByBirthdayRequest