| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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 readonly static ProcessOverviewRepository _procOverviewRep = AutofacIocManager.Instance.GetService<ProcessOverviewRepository>();
- //private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
- /// <summary>
- /// 默认通知人用户ID集合 团组流程
- /// </summary>
- private readonly static HashSet<string> defaultNotifyUserIds_groupProc = new HashSet<string>
- {
- "johnny.yang@pan-american-intl.com", // 杨俊霄 5
- "Roy.lei", // 雷怡 208
- "js" // 江姗 327
- };
- /// <summary>
- /// 默认通知人用户ID集合 费用结算流程
- /// </summary>
- private readonly static HashSet<string> defaultNotifyUserIds_feeProc = new HashSet<string>
- {
- "johnny.yang@pan-american-intl.com", // 杨俊霄 5
- "amy.zhu@pan-american-intl.com", // 朱成梅 22
- "Roy.lei", // 雷怡 208
- };
- /// <summary>
- /// 企微通知
- /// </summary>
- public static async void QiYeWeChatNotifyAsync()
- {
- var currDt = DateTime.Now;
- var groupAllNodeInfos = await _procOverviewRep.GetGroupAllProcessNodeInfoAsync();
- if (groupAllNodeInfos == null) return;
- var notifyList = groupAllNodeInfos.FindAll(x =>
- x.IsPrompt &&
- x.PromptTime?.Date == currDt.Date &&
- (x.GroupType != 248 || // 条件1:非248团组
- x.GroupType == 248 && // 条件2:248团组
- (x.ProcType == GroupProcessType.Visa ||
- x.ProcType == GroupProcessType.Invitation)) // 条件3:只允许签证和商邀
- );
- 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>();
- //根据流程 通知不同的人 费用结算 通知财务主管;其他类型 通知国交经理
- if (info.ProcType == GroupProcessType.FeeSettle) qiWeiChatUserIds.AddRange(defaultNotifyUserIds_feeProc);
- else qiWeiChatUserIds.AddRange(defaultNotifyUserIds_groupProc);
- 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 groupAllNodeInfos = await _procOverviewRep.GetGroupAllProcessNodeInfoAsync();
- if (groupAllNodeInfos == null) return;
- var notifyList = groupAllNodeInfos.FindAll(x =>
- x.IsAlert &&
- x.AlertTime?.Date == currDt.Date &&
- (x.GroupType != 248 || // 条件1:非248团组
- x.GroupType == 248 && // 条件2:248团组
- (x.ProcType == GroupProcessType.Visa ||
- x.ProcType == GroupProcessType.Invitation)) // 条件3:只允许签证和商邀
- );
- 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>();
- //根据流程 通知不同的人 费用结算 通知财务主管;其他类型 通知国交经理
- if (info.ProcType == GroupProcessType.FeeSettle) qiWeiChatUserIds.AddRange(defaultNotifyUserIds_feeProc);
- else qiWeiChatUserIds.AddRange(defaultNotifyUserIds_groupProc);
- qiWeiChatUserIds.AddRange(getPromptPersonQiyeChatUserIds(info.PromptPerson));
- // 企微通知
- await AppNoticeLibrary.SendUserMsg_GroupProcNode_Notif("团组任务预警",info.GroupName, msgs, qiWeiChatUserIds);
- }
- }
- }
- }
|