You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

168 lines
5.4 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.OA.Email.EmailSend
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2017
  11. /// 创建人:陈彬彬
  12. /// 日 期:2018.06.04
  13. /// 描 述:邮件发送管理
  14. /// </summary>
  15. public class EmailSendService : RepositoryFactory
  16. {
  17. #region 获取数据
  18. /// <summary>
  19. /// 获取发送邮件数据
  20. /// </summary>
  21. /// <param name="pagination">分页参数</param>
  22. /// <param name="queryJson">关键词</param>
  23. /// <returns></returns>
  24. public IEnumerable<EmailSendEntity> GetSendList(Pagination pagination, string queryJson)
  25. {
  26. try
  27. {
  28. var strSql = new StringBuilder();
  29. strSql.Append("SELECT * FROM LR_EmailSend t WHERE t.F_DeleteMark = 0 AND t.F_EnabledMark = 0 ");
  30. var queryParam = queryJson.ToJObject();
  31. DateTime startTime = new DateTime(), endTime = new DateTime();
  32. // 日期
  33. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  34. {
  35. startTime = queryParam["StartTime"].ToDate();
  36. endTime = queryParam["EndTime"].ToDate().AddDays(1);
  37. strSql.Append(" AND ( t.F_CreatorTime >= @startTime AND t.F_CreatorTime <= @endTime ) ");
  38. }
  39. // 关键字
  40. string keyword = "";
  41. if (!queryParam["keyword"].IsEmpty())
  42. {
  43. keyword = queryParam["keyword"].ToString();
  44. strSql.Append(" AND F_Subject like @keyword");
  45. }
  46. return this.BaseRepository().FindList<EmailSendEntity>(strSql.ToString(), new { startTime = startTime, endTime = endTime, keyword = "%" + keyword + "%" }, pagination);
  47. }
  48. catch (Exception ex)
  49. {
  50. if (ex is ExceptionEx)
  51. {
  52. throw;
  53. }
  54. else
  55. {
  56. throw ExceptionEx.ThrowServiceException(ex);
  57. }
  58. }
  59. }
  60. /// <summary>
  61. /// 获取邮件发送实体
  62. /// </summary>
  63. /// <param name="keyValue">主键</param>
  64. /// <returns></returns>
  65. public EmailSendEntity GetSendEntity(string keyValue)
  66. {
  67. try
  68. {
  69. return this.BaseRepository().FindEntity<EmailSendEntity>(keyValue);
  70. }
  71. catch (Exception ex)
  72. {
  73. if (ex is ExceptionEx)
  74. {
  75. throw;
  76. }
  77. else
  78. {
  79. throw ExceptionEx.ThrowServiceException(ex);
  80. }
  81. }
  82. }
  83. /// <summary>
  84. /// 获取今天的邮件数据
  85. /// </summary>
  86. /// <returns></returns>
  87. public IEnumerable<EmailSendEntity> GetTodayList(string emailAddr)
  88. {
  89. try
  90. {
  91. string sql = $@"SELECT * FROM LR_EmailSend t WHERE t.F_DeleteMark = 0 AND t.F_EnabledMark = 0 and DATEDIFF(DD,F_CreatorTime,Getdate())=0 and cast(F_To as nvarchar)='{emailAddr}' and F_Description='授权到期提醒'";
  92. return this.BaseRepository().FindList<EmailSendEntity>(sql);
  93. }
  94. catch (Exception ex)
  95. {
  96. if (ex is ExceptionEx)
  97. {
  98. throw;
  99. }
  100. else
  101. {
  102. throw ExceptionEx.ThrowServiceException(ex);
  103. }
  104. }
  105. }
  106. #endregion
  107. #region 提交数据
  108. /// <summary>
  109. /// 删除
  110. /// </summary>
  111. /// <param name="keyValue">主键</param>
  112. public void DeleteEntity(string keyValue)
  113. {
  114. try
  115. {
  116. this.BaseRepository().Delete<EmailSendEntity>(t => t.F_Id == keyValue);
  117. }
  118. catch (Exception ex)
  119. {
  120. if (ex is ExceptionEx)
  121. {
  122. throw;
  123. }
  124. else
  125. {
  126. throw ExceptionEx.ThrowServiceException(ex);
  127. }
  128. }
  129. }
  130. /// <summary>
  131. /// 保存(新增、修改)
  132. /// </summary>
  133. /// <param name="keyValue">主键值</param>
  134. /// <param name="sendEntity">邮件发送实体</param>
  135. /// <returns></returns>
  136. public void SaveSendEntity(string keyValue, EmailSendEntity sendEntity)
  137. {
  138. try
  139. {
  140. if (!string.IsNullOrEmpty(keyValue))
  141. {
  142. sendEntity.Modify(keyValue);
  143. this.BaseRepository().Update(sendEntity);
  144. }
  145. else
  146. {
  147. sendEntity.Create();
  148. this.BaseRepository().Insert(sendEntity);
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. if (ex is ExceptionEx)
  154. {
  155. throw;
  156. }
  157. else
  158. {
  159. throw ExceptionEx.ThrowServiceException(ex);
  160. }
  161. }
  162. }
  163. #endregion
  164. }
  165. }