DeleReminderMessage.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using OASystem.API.OAMethodLib.ALiYun;
  2. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  3. using OASystem.Domain.Dtos.Business;
  4. using OASystem.Domain.Entities.Business;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.PersonnelModule;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Infrastructure.Repositories.Groups;
  9. using OASystem.Infrastructure.Repositories.PersonnelModule;
  10. namespace OASystem.API.OAMethodLib.Quartz.Business
  11. {
  12. public static class DeleReminderMessage
  13. {
  14. private readonly static DelegationInfoRepository _grpDeleRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  15. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  16. /// <summary>
  17. /// 检查团组结束日期,将当天和2天后的团组整理并发送短信提醒
  18. /// </summary>
  19. public static async void PostMessage()
  20. {
  21. DeleReminderConfig _deleReminderConfig = AutofacIocManager.Instance.GetService<DeleReminderConfig>();
  22. List<string> list_PhoneNumbers = _deleReminderConfig.PhoneNumber.Split(',').ToList();
  23. //sqladd2day查询0A2014数据库,正式使用新OA后将两次查询合并
  24. DateTime dtNow = DateTime.Now;
  25. string add2day = dtNow.AddDays(2).ToString("yyyy-MM-dd");
  26. string add7day = dtNow.AddDays(7).ToString("yyyy-MM-dd");
  27. _grpDeleRep.ChangeDataBase(DBEnum.OA2014DB);
  28. string sql = string.Format(@" Select * From DelegationInfo With(Nolock) Where IsDel=0 And VisitEndDate ='{0}' Or VisitStartDate='{1}' ", add2day, add7day);
  29. List<OA2021_DelegationInfo> list_source = _grpDeleRep._sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sql).ToList();
  30. _grpDeleRep.ChangeDataBase(DBEnum.OA2023DB);
  31. if (list_source.Count > 0)
  32. {
  33. List<OA2021_DelegationInfo> listAdd7day = list_source.Where(s => s.VisitStartDate.Equals(add7day)).ToList();
  34. List<OA2021_DelegationInfo> listAdd2day = list_source.Where(s => s.VisitEndDate.Equals(add2day)).ToList();
  35. if (listAdd7day.Count > 0)
  36. {
  37. string teamNames = "";
  38. listAdd7day.ForEach(s => teamNames += s.TeamName + "、");
  39. teamNames = teamNames.TrimEnd('、');
  40. //发送短信
  41. string add7dayZH = dtNow.AddDays(7).ToString("yyyy年MM月dd日");
  42. string templateParam = JsonConvert.SerializeObject(new { teams = teamNames, date = add7dayZH });
  43. foreach (string postPhoneNumber in list_PhoneNumbers)
  44. {
  45. string postResult = AliMessagePost.PostMessage(postPhoneNumber, "泛美国际团组", "SMS_461505530", templateParam);
  46. Bus_MsgPostInfo _entity = new Bus_MsgPostInfo();
  47. _entity.Source = "ALiYun";
  48. _entity.TeamNames = teamNames;
  49. _entity.PostType = "Dele2";
  50. _entity.PhoneNumber = postPhoneNumber;
  51. _entity.PostResult = postResult;
  52. _grpDeleRep._sqlSugar.Insertable<Bus_MsgPostInfo>(_entity);
  53. }
  54. }
  55. if (listAdd2day.Count > 0)
  56. {
  57. string teamNames = "";
  58. listAdd2day.ForEach(s => teamNames += s.TeamName + "、");
  59. teamNames = teamNames.TrimEnd('、');
  60. //发送短信
  61. string add2dayZH = dtNow.AddDays(2).ToString("yyyy年MM月dd日");
  62. string templateParam = JsonConvert.SerializeObject(new { teams = teamNames, date = add2dayZH });
  63. foreach (string postPhoneNumber in list_PhoneNumbers)
  64. {
  65. string postResult = AliMessagePost.PostMessage(postPhoneNumber, "泛美国际团组", "SMS_461575447", templateParam);
  66. Bus_MsgPostInfo _entity = new Bus_MsgPostInfo();
  67. _entity.Source = "ALiYun";
  68. _entity.TeamNames = teamNames;
  69. _entity.PostType = "Dele1";
  70. _entity.PhoneNumber = postPhoneNumber;
  71. _entity.PostResult = postResult;
  72. _grpDeleRep._sqlSugar.Insertable<Bus_MsgPostInfo>(_entity);
  73. }
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 企业微信发送消息
  79. /// </summary>
  80. public static async void PostMessageByWebhook()
  81. {
  82. DateTime dtNow = DateTime.Now;
  83. string add2day = dtNow.AddDays(3).ToString("yyyy-MM-dd"); //结束出访前3天
  84. string add7day = dtNow.AddDays(7).ToString("yyyy-MM-dd"); //开始出访前1周
  85. string sql = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) Where IsDel=0 And VisitEndDate ='{0}' Or VisitStartDate='{1}' ", add2day, add7day);
  86. List<Grp_DelegationInfo> list_source = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  87. if (list_source.Count > 0)
  88. {
  89. List<Grp_DelegationInfo> listAdd7day = list_source.Where(s => s.VisitStartDate.Equals(add7day)).ToList();
  90. List<Grp_DelegationInfo> listAdd2day = list_source.Where(s => s.VisitEndDate.Equals(add2day)).ToList();
  91. string dayStr = dtNow.ToString("yyyy年MM月dd日");
  92. string content = string.Format(@" 今天是{0},\n ", dayStr);
  93. if (listAdd7day.Count > 0)
  94. {
  95. string tempStr1 = string.Format(@" \n\n检查到7天后开始的团组数量: <font color='warning'>** {1} **</font>\n ", dayStr, listAdd7day.Count);
  96. listAdd7day.ForEach(s => tempStr1 += string.Format(@">{0} \n", s.TeamName));
  97. content += tempStr1;
  98. }
  99. if (listAdd2day.Count > 0)
  100. {
  101. string tempStr2 = string.Format(@" \n\n检查到3天后结束的团组数量: <font color='info'>** {1} **</font>\n ", dayStr, listAdd2day.Count);
  102. listAdd7day.ForEach(s => tempStr2 += string.Format(@">{0} \n", s.TeamName));
  103. content += tempStr2;
  104. }
  105. content += string.Format(@"\n\n请注检查合同、款项等信息");
  106. OASystem.Domain.ViewModels.QiYeWeChat.ResponseBase result = await _qiYeWeChatApiService.RobotSendMsg_GroupInfo(content);
  107. }
  108. }
  109. }
  110. }