fix 增加入职日期判断

This commit is contained in:
2026-01-07 10:59:52 +08:00
parent d7a34c6e10
commit c24bdddb16

View File

@@ -59,6 +59,29 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
try try
{ {
var years = GetBirthdayYears(gainfo.Birthday.Value, p.begin, p.end); var years = GetBirthdayYears(gainfo.Birthday.Value, p.begin, p.end);
if (gainfo.EntryDate.HasValue)
{
// 仅保留在候选发放年份中,入职日期严格早于该年生日的年份
years = years.Where(y =>
{
var r = gainfo.EntryDate.Value.Date < SafeDateForYear(y, gainfo.Birthday.Value);
if (!r)
{
events.Add(new UserBusinessEventEntity
{
UserCode = gainfo.Code,
EventType = "GenerateBirthdayVoucher",
Content = $"入职时间为{gainfo.EntryDate.Value.ToString("yyyy-MM-dd")},不发放日期{SafeDateForYear(y, gainfo.Birthday.Value).ToString("yyyy-MM-dd")}的生日券"
});
}
return r;
}).ToList();
}
foreach (var year in years) foreach (var year in years)
{ {
await GenerateVoucherAsync(gainfo, departmentInfos, year, remark); await GenerateVoucherAsync(gainfo, departmentInfos, year, remark);
@@ -98,7 +121,6 @@ public class BirthdayVoucherService : BaseVoucherService, IVoucherService
// 使用安全日期来处理 2/29 情况:非闰年会退到当年该月最大天数(即 2/28) // 使用安全日期来处理 2/29 情况:非闰年会退到当年该月最大天数(即 2/28)
var claimDate = SafeDateForYear(year, gainfo.Birthday.Value); var claimDate = SafeDateForYear(year, gainfo.Birthday.Value);
await DbContext.InsertAsync(new VoucherEntity await DbContext.InsertAsync(new VoucherEntity
{ {
No = no, No = no,