GroupProcessNode.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  2. using OASystem.Domain.Entities.Groups;
  3. using OASystem.Infrastructure.Repositories.Groups;
  4. using static OASystem.Infrastructure.Repositories.Groups.ProcessOverviewRepository;
  5. namespace OASystem.API.OAMethodLib.Quartz.Business
  6. {
  7. /// <summary>
  8. /// 团组流程节点提示通知
  9. /// </summary>
  10. public static class GroupProcessNode
  11. {
  12. private readonly static DelegationInfoRepository _grpDeleRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  13. private readonly static ProcessOverviewRepository _procOverviewRep = AutofacIocManager.Instance.GetService<ProcessOverviewRepository>();
  14. //private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  15. /// <summary>
  16. /// 默认通知人用户ID集合 团组流程
  17. /// </summary>
  18. private readonly static HashSet<string> defaultNotifyUserIds_groupProc = new HashSet<string>
  19. {
  20. "johnny.yang@pan-american-intl.com", // 杨俊霄 5
  21. "Roy.lei", // 雷怡 208
  22. "js" // 江姗 327
  23. };
  24. /// <summary>
  25. /// 默认通知人用户ID集合 费用结算流程
  26. /// </summary>
  27. private readonly static HashSet<string> defaultNotifyUserIds_feeProc = new HashSet<string>
  28. {
  29. "johnny.yang@pan-american-intl.com", // 杨俊霄 5
  30. "amy.zhu@pan-american-intl.com", // 朱成梅 22
  31. "Roy.lei", // 雷怡 208
  32. };
  33. /// <summary>
  34. /// 企微通知
  35. /// </summary>
  36. public static async void QiYeWeChatNotifyAsync()
  37. {
  38. var currDt = DateTime.Now;
  39. var groupAllNodeInfos = await _procOverviewRep.GetGroupAllProcessNodeInfoAsync();
  40. if (groupAllNodeInfos == null) return;
  41. var notifyList = groupAllNodeInfos.FindAll(x =>
  42. x.IsPrompt &&
  43. x.PromptTime?.Date == currDt.Date &&
  44. (x.GroupType != 248 || // 条件1:非248团组
  45. x.GroupType == 248 && // 条件2:248团组
  46. (x.ProcType == GroupProcessType.Visa ||
  47. x.ProcType == GroupProcessType.Invitation)) // 条件3:只允许签证和商邀
  48. );
  49. if (notifyList == null) return;
  50. // 按照团组ID和流程枚举分组
  51. var groupedByGroupIdAndProcType = notifyList.GroupBy(x => new { x.GroupId, x.ProcType })
  52. .ToDictionary(
  53. group => group.Key,
  54. group => group.ToList()
  55. );
  56. // 提取获取提示人员企业微信用户ID的逻辑
  57. Func<List<UserAndQiWeiUserIdView>, List<string>> getPromptPersonQiyeChatUserIds = promptPersons =>
  58. promptPersons?.Select(x => x.QiyeChatUserId).ToList() ?? new List<string>();
  59. // 按照团分组发送通知
  60. foreach (var group in groupedByGroupIdAndProcType)
  61. {
  62. var info = group.Value.FirstOrDefault();
  63. if (info == null) continue;
  64. var msgs = info.ProcType == GroupProcessType.Invitation
  65. ? group.Value.Select(x => $"任务:{x.NodeName},开始了。").ToList()
  66. : new List<string> { $"任务:{info.NodeName},开始了。" };
  67. var qiWeiChatUserIds = new List<string>();
  68. //根据流程 通知不同的人 费用结算 通知财务主管;其他类型 通知国交经理
  69. if (info.ProcType == GroupProcessType.FeeSettle) qiWeiChatUserIds.AddRange(defaultNotifyUserIds_feeProc);
  70. else qiWeiChatUserIds.AddRange(defaultNotifyUserIds_groupProc);
  71. qiWeiChatUserIds.AddRange(getPromptPersonQiyeChatUserIds(info.PromptPerson));
  72. // 企微通知
  73. await AppNoticeLibrary.SendUserMsg_GroupProcNode_Notif("团组任务通知", info.GroupName, msgs, qiWeiChatUserIds);
  74. }
  75. }
  76. /// <summary>
  77. /// 企微预警通知
  78. /// </summary>
  79. public static async void QiYeWeChatWarnNotifyAsync()
  80. {
  81. var currDt = DateTime.Now;
  82. var groupAllNodeInfos = await _procOverviewRep.GetGroupAllProcessNodeInfoAsync();
  83. if (groupAllNodeInfos == null) return;
  84. var notifyList = groupAllNodeInfos.FindAll(x =>
  85. x.IsAlert &&
  86. x.AlertTime?.Date == currDt.Date &&
  87. (x.GroupType != 248 || // 条件1:非248团组
  88. x.GroupType == 248 && // 条件2:248团组
  89. (x.ProcType == GroupProcessType.Visa ||
  90. x.ProcType == GroupProcessType.Invitation)) // 条件3:只允许签证和商邀
  91. );
  92. if (notifyList == null) return;
  93. // 按照团组ID和流程枚举分组
  94. var groupedByGroupIdAndProcType = notifyList.GroupBy(x => new { x.GroupId, x.ProcType })
  95. .ToDictionary(
  96. group => group.Key,
  97. group => group.ToList()
  98. );
  99. // 提取获取提示人员企业微信用户ID的逻辑
  100. Func<List<UserAndQiWeiUserIdView>, List<string>> getPromptPersonQiyeChatUserIds = promptPersons =>
  101. promptPersons?.Select(x => x.QiyeChatUserId).ToList() ?? new List<string>();
  102. // 按照团分组发送通知
  103. foreach (var group in groupedByGroupIdAndProcType)
  104. {
  105. var info = group.Value.FirstOrDefault();
  106. if (info == null) continue;
  107. var msgs = info.ProcType == GroupProcessType.Invitation
  108. ? group.Value.Select(x => $"你操作的 {x.NodeName} 任务进度用时已过半,请抓紧时间完成任务!如需帮助,请立即联系上级领导!").ToList()
  109. : new List<string> { $"你操作的 {info.NodeName} 任务进度用时已过半,请抓紧时间完成任务!如需帮助,请立即联系上级领导!" };
  110. var qiWeiChatUserIds = new List<string>();
  111. //根据流程 通知不同的人 费用结算 通知财务主管;其他类型 通知国交经理
  112. if (info.ProcType == GroupProcessType.FeeSettle) qiWeiChatUserIds.AddRange(defaultNotifyUserIds_feeProc);
  113. else qiWeiChatUserIds.AddRange(defaultNotifyUserIds_groupProc);
  114. qiWeiChatUserIds.AddRange(getPromptPersonQiyeChatUserIds(info.PromptPerson));
  115. // 企微通知
  116. await AppNoticeLibrary.SendUserMsg_GroupProcNode_Notif("团组任务预警",info.GroupName, msgs, qiWeiChatUserIds);
  117. }
  118. }
  119. }
  120. }