64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace NPP.SmartSchedue.Api.Contracts.Services.Notification.Output;
|
|
|
|
/// <summary>
|
|
/// 批量发送系统消息输出模型
|
|
/// </summary>
|
|
public class BatchSendSystemMessageOutput
|
|
{
|
|
/// <summary>
|
|
/// 总发送数量
|
|
/// </summary>
|
|
public int TotalCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// 成功发送数量
|
|
/// </summary>
|
|
public int SuccessCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// 失败发送数量
|
|
/// </summary>
|
|
public int FailureCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// 详细发送结果
|
|
/// Key: 人员ID, Value: 发送结果
|
|
/// </summary>
|
|
public Dictionary<long, SendSystemMessageOutput> Results { get; set; } = new Dictionary<long, SendSystemMessageOutput>();
|
|
|
|
/// <summary>
|
|
/// 批量发送时间
|
|
/// </summary>
|
|
public DateTime SentTime { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否全部发送成功
|
|
/// </summary>
|
|
public bool AllSuccess => FailureCount == 0;
|
|
|
|
/// <summary>
|
|
/// 成功率(百分比)
|
|
/// </summary>
|
|
public double SuccessRate => TotalCount > 0 ? (double)SuccessCount / TotalCount * 100 : 0;
|
|
|
|
/// <summary>
|
|
/// 创建批量发送结果
|
|
/// </summary>
|
|
public static BatchSendSystemMessageOutput Create(Dictionary<long, SendSystemMessageOutput> results)
|
|
{
|
|
var output = new BatchSendSystemMessageOutput
|
|
{
|
|
Results = results,
|
|
TotalCount = results.Count,
|
|
SuccessCount = results.Values.Count(r => r.Success),
|
|
SentTime = DateTime.Now
|
|
};
|
|
|
|
output.FailureCount = output.TotalCount - output.SuccessCount;
|
|
return output;
|
|
}
|
|
} |