test #25

Merged
zzh merged 2 commits from test into master 2026-11-18 12:06:59 +08:00
2 changed files with 93 additions and 3 deletions
Showing only changes of commit cbe22652c0 - Show all commits

View File

@ -224,6 +224,16 @@ public class ApprovalEngineCore(
// 通知失败不影响审批
}
try
{
// 终审后清掉候选人侧「待审批」未读,避免还要再点一次已读
await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id);
}
catch
{
// 已读标记失败不影响审批
}
await ExecuteHandlerAsync(instance, mapId, guid);
}
@ -281,6 +291,15 @@ public class ApprovalEngineCore(
// 通知失败不影响审批
}
try
{
await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id);
}
catch
{
// 已读标记失败不影响审批
}
await InvokeRejectOrWithdrawHandlerAsync(instance, mapId, guid, name, isReject: true, comment.Trim());
}
@ -325,6 +344,15 @@ public class ApprovalEngineCore(
name,
comment?.Trim() ?? "撤回");
try
{
await approvalNotifier.MarkPendingApprovalNoticesReadAsync(instance.Id);
}
catch
{
// 已读标记失败不影响撤回
}
await InvokeRejectOrWithdrawHandlerAsync(
instance,
mapId,

View File

@ -14,11 +14,13 @@ namespace Oms.Application.Services.Approval;
/// </summary>
public class ApprovalNotifier(
INoticeRepository noticeRepository,
INoticeReadRepository noticeReadRepository,
FakeRbacDbContext rbacDbContext,
ILogger<ApprovalNotifier> logger) : IScopedDependency
{
private const string NoticeTypeMessage = "message";
private const string ReceiverTypeUser = "user";
private const string PendingTitlePrefix = "待审批:";
/// <summary>
/// 通知审批候选人:有待办需处理。
@ -37,13 +39,13 @@ public class ApprovalNotifier(
return;
}
var title = $"待审批:{instance.Title}";
var title = $"{PendingTitlePrefix}{instance.Title}";
var content =
$"审批单 {instance.InstanceNo} 待你处理。\n" +
$"操作:{instance.OperationCode}\n" +
$"申请人:{instance.ApplicantUserName ?? instance.ApplicantUserGuid}\n" +
$"请到「系统管理 / 审批待办」处理。\n" +
$"[OMS_APPROVAL:id={instance.Id}&tab=todo]";
BuildApprovalToken(instance.Id, "todo");
await noticeRepository.InsertAsync(new Notice
{
@ -86,7 +88,7 @@ public class ApprovalNotifier(
$"操作:{instance.OperationCode}\n" +
(string.IsNullOrWhiteSpace(comment) ? string.Empty : $"意见:{comment.Trim()}\n") +
$"可在「系统管理 / 审批待办 → 我发起的」查看详情。\n" +
$"[OMS_APPROVAL:id={instance.Id}&tab=submitted]";
BuildApprovalToken(instance.Id, "submitted");
await noticeRepository.InsertAsync(new Notice
{
@ -99,6 +101,66 @@ public class ApprovalNotifier(
}, cancellationToken);
}
/// <summary>
/// 将指定审批实例的「待审批」站内信标为已读(所有定向接收人)。
/// 通过 / 驳回 / 撤回后调用,避免候选人侧仍残留未读待办。
/// </summary>
public async Task MarkPendingApprovalNoticesReadAsync(
int instanceId,
CancellationToken cancellationToken = default)
{
if (instanceId <= 0)
{
return;
}
var token = $"[OMS_APPROVAL:id={instanceId}";
var notices = await noticeRepository.GetListAsync(x =>
x.NoticeType == NoticeTypeMessage
&& x.Title != null
&& x.Title.StartsWith(PendingTitlePrefix)
&& x.Content != null
&& x.Content.Contains(token));
if (notices.Count == 0)
{
return;
}
var now = DateTime.Now;
foreach (var notice in notices)
{
var receiverIds = OmsDocHelper.DeserializeJson<List<int>>(notice.ReceiverIds) ?? [];
foreach (var receiverId in receiverIds.Distinct())
{
if (receiverId <= 0)
{
continue;
}
var existed = await noticeReadRepository.GetByNoticeReceiverAsync(
notice.Id,
ReceiverTypeUser,
receiverId,
cancellationToken);
if (existed != null)
{
continue;
}
await noticeReadRepository.InsertAsync(new NoticeRead
{
NoticeId = notice.Id,
ReceiverType = ReceiverTypeUser,
ReceiverId = receiverId,
ReadTime = now
});
}
}
}
private static string BuildApprovalToken(int instanceId, string tab) =>
$"[OMS_APPROVAL:id={instanceId}&tab={tab}]";
private async Task<List<int>> ResolveMapUserIdsAsync(
IReadOnlyCollection<string> userGuids,
CancellationToken cancellationToken)