DeleReminderMessage.cs 3.7 KB

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