SendEmailJob.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Utils;
  8. namespace PMS.NetCore.Service
  9. {
  10. /// <summary>
  11. /// 进度报告发邮件任务
  12. /// </summary>
  13. public class SendEmailJob : IJob
  14. {
  15. NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
  16. public Task Execute(IJobExecutionContext context)
  17. {
  18. return Task.Run(() =>
  19. {
  20. try
  21. {
  22. ////NlogHelper.quartzLogger.Info("开始");
  23. //var sql = $"select b.ProgressName,a.NodeName,a.ProgressId,a.id progressnodeid,a.PlannedStartDate from pmProgressNode a inner join pmprogress b on a.ProgressId=b.id where (b.IsMaster =1 or b.ismaster=2) and b.State=2 and a.PlannedStartDate is not null";
  24. ////logger.Info($"主项计划sql:{sql}");
  25. //var manager = new actionsManager();
  26. //var dt = manager.Db.Ado.GetDataTable(sql);
  27. //for (int i = 0; i < dt.Rows.Count; i++)
  28. //{
  29. // var PlannedStartDate = Convert.ToDateTime(dt.Rows[i]["PlannedStartDate"]);
  30. // var name = dt.Rows[i]["ProgressName"].ToString() + "->" + dt.Rows[i]["NodeName"].ToString();
  31. // var progressid = Convert.ToInt32(dt.Rows[i]["progressid"]);
  32. // var progressnodeid = Convert.ToInt32(dt.Rows[i]["progressnodeid"]);
  33. // #region 给责任人发邮件
  34. // if (DateHelper.DateDiff(DateInterval.Day, DateTime.Now.AddDays(1), PlannedStartDate) == 0) //如果计划开始时间是当前时间的前一天
  35. // {
  36. // sql = $"select u.UserName,u.MailBox from SystemUser u inner join pmProgressNodePerson p on u.UserCode=p.UserCode where p.ProgressNodeId={progressnodeid} and p.type=1";
  37. // //logger.Info($"获取责任人sql:{sql}");
  38. // var dt2 = manager.Db.Ado.GetDataTable(sql);
  39. // for (int j = 0; j < dt2.Rows.Count; j++) //给责任人发邮件
  40. // {
  41. // var username = dt2.Rows[j]["UserName"].ToString();
  42. // var mailBox = dt2.Rows[j]["MailBox"].SConvertString();
  43. // if (mailBox.IsEmail())
  44. // {
  45. // NlogHelper.quartzLogger.Info($"给责任人{username}发邮件开始");
  46. // EmailHelper helper = new EmailHelper();
  47. // helper.Title = $"地产ERP进度计划即将开始提醒";
  48. // helper.Cont = $"此\"{name}\"于{PlannedStartDate.ToString("yyyy-MM-dd")}即将开始";
  49. // helper.ReceiveEmail = mailBox;
  50. // helper.SendMail(helper);
  51. // NlogHelper.quartzLogger.Info($"给责任人{username}发邮件结束");
  52. // }
  53. // }
  54. // }
  55. // #endregion
  56. // #region 给关注人和责任人发邮件
  57. // if (DateHelper.DateDiff(DateInterval.Day, DateTime.Now, PlannedStartDate.AddDays(1)) == 0) //如果计划开始时间是当前时间的前一天
  58. // {
  59. // sql = $"select id from pmProgressReport where ProgressId={progressid} and ProgressNodeId={progressnodeid}";
  60. // var exist = manager.Db.Ado.GetString(sql); //若没有任何进度报告
  61. // if (exist.IsNullOrEmpty())
  62. // {
  63. // sql = $"select u.UserName,u.MailBox from SystemUser u inner join pmProgressNodePerson p on u.UserCode=p.UserCode where p.ProgressNodeId={progressnodeid} and (p.type=9 or p.type=1)";
  64. // NlogHelper.quartzLogger.Info($"获取关注人sql:{sql}");
  65. // var dt2 = manager.Db.Ado.GetDataTable(sql);
  66. // for (int j = 0; j < dt2.Rows.Count; j++) //给责任人发邮件
  67. // {
  68. // var username = dt2.Rows[j]["UserName"].ToString();
  69. // var mailBox = dt2.Rows[j]["MailBox"].SConvertString();
  70. // if (mailBox.IsEmail())
  71. // {
  72. // NlogHelper.quartzLogger.Info($"给关注人和责任人{username}发邮件开始");
  73. // EmailHelper helper = new EmailHelper();
  74. // helper.Title = $"地产ERP进度计划填报提醒";
  75. // helper.Cont = $"此\"{name}\"于{PlannedStartDate.ToString("yyyy-MM-dd")}已开始,未填报";
  76. // helper.ReceiveEmail = mailBox;
  77. // helper.SendMail(helper);
  78. // NlogHelper.quartzLogger.Info($"给关注人和责任人{username}发邮件结束");
  79. // }
  80. // }
  81. // }
  82. // }
  83. // #endregion
  84. //}
  85. }
  86. catch (Exception ero)
  87. {
  88. NlogHelper.quartzLogger.Error(" 发邮件执行出错:" + ero, true);
  89. }
  90. });
  91. }
  92. }
  93. }