Account for holidays in approval deadlines
This commit is contained in:
1 parent
8f4ea907e4
commit
27cad42d45
7 files changed
+67
-10
No files matched your search
@@ -1203,6 +1203,13 @@ public sealed partial class ApprovalsController(
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
if (timelinessEnabled && pageItems.Length > 0)
|
||||
{
|
||||
var holidays = await db.AcademicCalendarEvents.AsNoTracking()
|
||||
.Where(x => x.IsEnabled && x.Source == AcademicCalendarEventSource.HolidayCn && x.IsOffDay != null)
|
||||
.ToListAsync(ct);
|
||||
pageItems = pageItems.Select(x => x with { DeadlineUtc = ApprovalTimeliness.DeadlineUtc(x.Time, holidays) }).ToArray();
|
||||
}
|
||||
return Ok(new ApprovalPendingResult(pageItems, total, page, pageSize, counts, timelinessEnabled));
|
||||
}
|
||||
|
||||
@@ -2006,7 +2013,7 @@ public sealed partial class ApprovalsController(
|
||||
ApprovalsErrorKeys.TryGetValue(detail, out var key) ? SharedResourceText.Get(localizer, key) : detail;
|
||||
}
|
||||
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null);
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null, DateTime? DeadlineUtc = null);
|
||||
public sealed class ApprovalReviewedItem
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
|
||||
@@ -3,7 +3,7 @@ using Jiaowu.Api.Domain.Common;
|
||||
namespace Jiaowu.Api.Domain.Academic;
|
||||
|
||||
/// <summary>
|
||||
/// 校历中的独立日程。它仅用于展示和提醒,不参与任何业务流程的状态判断或截止限制。
|
||||
/// 校历中的独立日程。同步的节假日用于审批时限提示,其余日程用于展示和提醒。
|
||||
/// </summary>
|
||||
public sealed class AcademicCalendarEvent : EntityBase
|
||||
{
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Approvals;
|
||||
|
||||
public static class ApprovalTimeliness
|
||||
{
|
||||
public static DateTime DeadlineUtc(DateTime submittedUtc, IReadOnlyCollection<AcademicCalendarEvent> holidays)
|
||||
{
|
||||
var china = DateTime.SpecifyKind(submittedUtc, DateTimeKind.Utc).AddHours(8);
|
||||
var date = DateOnly.FromDateTime(china);
|
||||
bool IsWorkday(DateOnly day)
|
||||
{
|
||||
var matching = holidays.Where(x => x.IsEnabled && x.Source == AcademicCalendarEventSource.HolidayCn
|
||||
&& x.IsOffDay.HasValue && x.StartsOn <= day && (x.EndsOn ?? x.StartsOn) >= day).ToArray();
|
||||
if (matching.Any(x => x.IsOffDay == true)) return false;
|
||||
if (matching.Any(x => x.IsOffDay == false)) return true;
|
||||
return day.DayOfWeek is not (DayOfWeek.Saturday or DayOfWeek.Sunday);
|
||||
}
|
||||
var morning = !IsWorkday(date) || china.TimeOfDay >= TimeSpan.FromHours(16);
|
||||
if (IsWorkday(date) && morning) date = date.AddDays(1);
|
||||
while (!IsWorkday(date)) date = date.AddDays(1);
|
||||
var localDeadline = date.ToDateTime(TimeOnly.MinValue).AddDays(morning ? 0 : 1).AddHours(morning ? 12 : 0);
|
||||
return DateTime.SpecifyKind(localDeadline.AddHours(-8), DateTimeKind.Utc);
|
||||
}
|
||||
}
|
||||
Loaded 3 of 7 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user