DeleReminderMessage.cs 5.6 KB

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