DeleReminderMessage.cs 4.2 KB

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