DeleReminderMessage.cs 4.3 KB

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