fix 非闰年29号生日问题
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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<IVoucherApi>();
|
||||
await voucherApi.CreateAsync(new VoucherByBirthdayRequest
|
||||
|
||||
Reference in New Issue
Block a user