Add configurable approval timeliness guidance
This commit is contained in:
1 parent
31a75d3bca
commit
8f4ea907e4
4 files changed
+54
-4
No files matched your search
@@ -905,6 +905,8 @@ public sealed partial class ApprovalsController(
|
||||
if (overdueHours is < 1 or > 8760)
|
||||
return ValidationProblem("等待时长必须在 1 到 8760 小时之间。");
|
||||
|
||||
var timelinessEnabled = await db.SystemFeatureSettings.AsNoTracking().AnyAsync(x => x.Key == "ApprovalTimeliness" && x.IsEnabled, ct);
|
||||
if (timelinessEnabled) oldestFirst = true;
|
||||
var cutoff = overdueHours.HasValue ? DateTime.UtcNow.AddHours(-overdueHours.Value) : (DateTime?)null;
|
||||
var take = checked(page * pageSize);
|
||||
var total = 0;
|
||||
@@ -1201,7 +1203,7 @@ public sealed partial class ApprovalsController(
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
return Ok(new ApprovalPendingResult(pageItems, total, page, pageSize, counts));
|
||||
return Ok(new ApprovalPendingResult(pageItems, total, page, pageSize, counts, timelinessEnabled));
|
||||
}
|
||||
|
||||
[HttpGet("pending/{type}/{id:guid}")]
|
||||
@@ -2015,7 +2017,7 @@ public sealed class ApprovalReviewedItem
|
||||
public bool? Approved { get; init; }
|
||||
}
|
||||
public sealed record ApprovalReviewedResult(IReadOnlyList<ApprovalReviewedItem> Items, int Total);
|
||||
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts);
|
||||
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts, bool TimelinessEnabled = false);
|
||||
public sealed record ApprovalRouteSettingRequest([Required] string ReviewerRole);
|
||||
public sealed record ApprovalProgressStep(string Kind, DateTime Time, string? Comment);
|
||||
public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyList<ApprovalProgressStep> Steps, bool HistoryIncomplete = false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Domain.System;
|
||||
using Jiaowu.Api.Infrastructure.Configuration;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -12,6 +13,23 @@ namespace Jiaowu.Api.Controllers;
|
||||
[Route("api/business-settings")]
|
||||
public sealed class BusinessSettingsController(AppDbContext db, BusinessSettingsReader reader) : ControllerBase
|
||||
{
|
||||
[HttpGet("approval-timeliness")]
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin)]
|
||||
public async Task<IActionResult> GetApprovalTimeliness(CancellationToken ct) =>
|
||||
Ok(new { enabled = await db.SystemFeatureSettings.AsNoTracking().AnyAsync(x => x.Key == "ApprovalTimeliness" && x.IsEnabled, ct) });
|
||||
|
||||
[HttpPut("approval-timeliness")]
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin)]
|
||||
public async Task<IActionResult> PutApprovalTimeliness(ApprovalTimelinessRequest request, CancellationToken ct)
|
||||
{
|
||||
var setting = await db.SystemFeatureSettings.SingleOrDefaultAsync(x => x.Key == "ApprovalTimeliness", ct);
|
||||
if (setting is null) { setting = new SystemFeatureSetting { Key = "ApprovalTimeliness" }; db.SystemFeatureSettings.Add(setting); }
|
||||
setting.IsEnabled = request.Enabled;
|
||||
setting.UpdatedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync(ct);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("branding")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Branding() => Ok(reader.Brand());
|
||||
@@ -59,3 +77,5 @@ public sealed record BusinessSettingsRequest(
|
||||
[Required, StringLength(100)] string IssuingOffice,
|
||||
[Required, StringLength(32)] string DocumentNumberPrefix,
|
||||
[Range(1, 180)] int GradeAppealWindowDays);
|
||||
|
||||
public sealed record ApprovalTimelinessRequest(bool Enabled);
|
||||
@@ -93,6 +93,15 @@ const isStudent = computed(
|
||||
);
|
||||
|
||||
const pending = ref<any[]>([]);
|
||||
const timelinessEnabled = ref(false);
|
||||
function approvalDeadline(value: string) {
|
||||
const utc = new Date(/(?:Z|[+-]\d\d:\d\d)$/i.test(value) ? value : value + 'Z');
|
||||
const china = new Date(utc.getTime() + 8 * 3600000);
|
||||
const late = china.getUTCHours() >= 16;
|
||||
const deadline = Date.UTC(china.getUTCFullYear(), china.getUTCMonth(), china.getUTCDate() + 1, late ? 12 : 0) - 8 * 3600000;
|
||||
const label = new Intl.DateTimeFormat('zh-CN', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(deadline);
|
||||
return `${Date.now() >= deadline ? '已超时' : late ? '优先处理' : '当日处理'} · 目标 ${label}(北京时间)`;
|
||||
}
|
||||
const leavePanel = ref<InstanceType<typeof StudentLeavePanel> | null>(null);
|
||||
async function showLeave(id: string) {
|
||||
await leavePanel.value?.focusLeave(id);
|
||||
@@ -402,6 +411,7 @@ async function load() {
|
||||
if (sequence !== loadSequence) return;
|
||||
targetMissing.value = false;
|
||||
pending.value = [data];
|
||||
timelinessEnabled.value = false;
|
||||
pendingTotal.value = 1;
|
||||
pendingCounts.value = {};
|
||||
} else {
|
||||
@@ -417,6 +427,8 @@ async function load() {
|
||||
});
|
||||
if (sequence !== loadSequence) return;
|
||||
pending.value = data.items;
|
||||
timelinessEnabled.value = data.timelinessEnabled;
|
||||
if (timelinessEnabled.value) oldestFirst.value = true;
|
||||
pendingTotal.value = data.total;
|
||||
pendingCounts.value = data.counts ?? {};
|
||||
}
|
||||
@@ -1347,7 +1359,7 @@ onMounted(async () => {
|
||||
}}</span>
|
||||
<el-switch
|
||||
v-model="oldestFirst"
|
||||
:disabled="!!targetApprovalId"
|
||||
:disabled="timelinessEnabled || !!targetApprovalId"
|
||||
:active-text="t('approvalCenterExtra.oldestFirst')"
|
||||
@change="
|
||||
pendingPage = 1;
|
||||
@@ -1409,6 +1421,7 @@ onMounted(async () => {
|
||||
>
|
||||
<div class="appr-body">
|
||||
<b>{{ item.title }}</b>
|
||||
<p v-if="timelinessEnabled">{{ approvalDeadline(item.time) }}</p>
|
||||
<p>{{ item.desc }}</p>
|
||||
<small
|
||||
>{{ item.college }} ·
|
||||
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user