using OASystem.API.OAMethodLib.QiYeWeChatAPI;
using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
using OASystem.Domain.Entities.Groups;
using OASystem.Infrastructure.Repositories.Groups;
using static OASystem.Infrastructure.Repositories.Groups.ProcessOverviewRepository;
namespace OASystem.API.OAMethodLib.Quartz.Business
{
///
/// 团组流程节点提示通知
///
public static class GroupProcessNode
{
private readonly static DelegationInfoRepository _grpDeleRep = AutofacIocManager.Instance.GetService();
private static readonly ProcessOverviewRepository _procOverviewRep = AutofacIocManager.Instance.GetService();
//private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService();
///
/// 企微通知
///
public static async void QiYeWeChatNotifyAsync()
{
var currDt = DateTime.Now;
// 默认通知人
var defaultNotifyUserIds = new HashSet
{
5, // 雷怡
208, // 杨俊霄
327 // 江姗
};
var defaultNotifyQiyeChatUserIds = await _grpDeleRep._sqlSugar.Queryable()
.Where(x => defaultNotifyUserIds.Contains(x.Id) && x.IsDel == 0)
.Select(x => x.QiyeChatUserId)
.ToListAsync();
var groupAllNodeInfos = await _procOverviewRep.GetGroupAllProcessNodeInfoAsync();
if (groupAllNodeInfos == null) return;
var notifyList = groupAllNodeInfos.FindAll(x => x.PromptTime?.Date == currDt.Date);
if (notifyList == null) return;
// 按照团组ID和流程枚举分组
var groupedByGroupIdAndProcType = notifyList.GroupBy(x => new { x.GroupId, x.ProcType })
.ToDictionary(
group => group.Key,
group => group.ToList()
);
// 提取获取提示人员企业微信用户ID的逻辑
Func, List> getPromptPersonQiyeChatUserIds = promptPersons =>
promptPersons?.Select(x => x.QiyeChatUserId).ToList() ?? new List();
// 按照团分组发送通知
foreach (var group in groupedByGroupIdAndProcType)
{
var info = group.Value.FirstOrDefault();
if (info == null) continue;
var msgs = info.ProcType == GroupProcessType.Invitation
? group.Value.Select(x => $"- {x.NodeName}开始了。").ToList()
: new List { $"- {info.NodeName}开始了。" };
var qiWeiChatUserIds = new List();
qiWeiChatUserIds.AddRange(defaultNotifyQiyeChatUserIds);
qiWeiChatUserIds.AddRange(getPromptPersonQiyeChatUserIds(info.PromptPerson));
// 企微通知
await AppNoticeLibrary.SendUserMsg_GroupProcNode_Notif(info.GroupName, msgs, qiWeiChatUserIds);
}
}
///
/// 企微预警通知
///
public static async void QiYeWeChatWarnNotifyAsync()
{
var currDt = DateTime.Now;
var groupInfos = await _grpDeleRep._sqlSugar.Queryable()
.Where(x => x.IsDel == 0)
.ToListAsync();
}
}
}