| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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
- {
- /// <summary>
- /// 团组流程节点提示通知
- /// </summary>
- public static class GroupProcessNode
- {
- private readonly static DelegationInfoRepository _grpDeleRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
- private static readonly ProcessOverviewRepository _procOverviewRep = AutofacIocManager.Instance.GetService<ProcessOverviewRepository>();
- //private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
- /// <summary>
- /// 企微通知
- /// </summary>
- public static async void QiYeWeChatNotifyAsync()
- {
- var currDt = DateTime.Now;
- // 默认通知人
- var defaultNotifyUserIds = new HashSet<int>
- {
- 5, // 雷怡
- 208, // 杨俊霄
- 327 // 江姗
- };
- var defaultNotifyQiyeChatUserIds = await _grpDeleRep._sqlSugar.Queryable<Sys_Users>()
- .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<UserAndQiWeiUserIdView>, List<string>> getPromptPersonQiyeChatUserIds = promptPersons =>
- promptPersons?.Select(x => x.QiyeChatUserId).ToList() ?? new List<string>();
- // 按照团分组发送通知
- 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<string> { $"- {info.NodeName}开始了。" };
- var qiWeiChatUserIds = new List<string>();
- qiWeiChatUserIds.AddRange(defaultNotifyQiyeChatUserIds);
- qiWeiChatUserIds.AddRange(getPromptPersonQiyeChatUserIds(info.PromptPerson));
- // 企微通知
- await AppNoticeLibrary.SendUserMsg_GroupProcNode_Notif(info.GroupName, msgs, qiWeiChatUserIds);
- }
- }
- /// <summary>
- /// 企微预警通知
- /// </summary>
- public static async void QiYeWeChatWarnNotifyAsync()
- {
- var currDt = DateTime.Now;
- var groupInfos = await _grpDeleRep._sqlSugar.Queryable<Grp_DelegationInfo>()
- .Where(x => x.IsDel == 0)
- .ToListAsync();
- }
- }
- }
|