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.
 
 
 
 
 
 

175 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.EmailReceive
  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 EmailReceiveService : RepositoryFactory
  16. {
  17. #region 获取数据
  18. /// <summary>
  19. /// 获取收取邮件数据
  20. /// </summary>
  21. /// <param name="pagination">分页参数</param>
  22. /// <param name="keyword">关键词</param>
  23. /// <returns></returns>
  24. public IEnumerable<EmailReceiveEntity> GetReceiveList(Pagination pagination,string queryJson)
  25. {
  26. try
  27. {
  28. UserInfo userInfo = LoginUserInfo.Get();
  29. var strSql = new StringBuilder();
  30. strSql.Append("SELECT * FROM LR_EmailReceive t WHERE t.F_DeleteMark = 0 AND t.F_EnabledMark = 0 AND F_CreatorUserId=@userId");
  31. var queryParam = queryJson.ToJObject();
  32. DateTime startTime = new DateTime(), endTime = new DateTime();
  33. // 日期
  34. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  35. {
  36. startTime = queryParam["StartTime"].ToDate();
  37. endTime = queryParam["EndTime"].ToDate().AddDays(1);
  38. strSql.Append(" AND ( t.F_Date >= @startTime AND t.F_Date <= @endTime ) ");
  39. }
  40. // 关键字
  41. string keyword = "";
  42. if (!queryParam["keyword"].IsEmpty())
  43. {
  44. keyword = queryParam["keyword"].ToString();
  45. strSql.Append(" AND (t.F_Subject like @keyword OR t.F_Sender like @keyword )");
  46. }
  47. return this.BaseRepository().FindList<EmailReceiveEntity>(strSql.ToString(), new { userId=userInfo.userId, startTime = startTime, endTime = endTime, keyword = "%" + keyword + "%" }, pagination);
  48. }
  49. catch (Exception ex)
  50. {
  51. if (ex is ExceptionEx)
  52. {
  53. throw;
  54. }
  55. else
  56. {
  57. throw ExceptionEx.ThrowServiceException(ex);
  58. }
  59. }
  60. }
  61. /// <summary>
  62. /// 获取邮件接收实体
  63. /// </summary>
  64. /// <param name="keyValue">主键</param>
  65. /// <returns></returns>
  66. public EmailReceiveEntity GetReceiveEntity(string keyValue)
  67. {
  68. try
  69. {
  70. return this.BaseRepository().FindEntity<EmailReceiveEntity>(keyValue);
  71. }
  72. catch (Exception ex)
  73. {
  74. if (ex is ExceptionEx)
  75. {
  76. throw;
  77. }
  78. else
  79. {
  80. throw ExceptionEx.ThrowServiceException(ex);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 获取邮件接收个数
  86. /// </summary>
  87. /// <returns></returns>
  88. public int GetCount()
  89. {
  90. try
  91. {
  92. string sql = "SELECT F_Id FROM LR_EmailReceive";
  93. var list = this.BaseRepository().FindTable(sql);
  94. return list.Rows.Count;
  95. }
  96. catch (Exception ex)
  97. {
  98. if (ex is ExceptionEx)
  99. {
  100. throw;
  101. }
  102. else
  103. {
  104. throw ExceptionEx.ThrowServiceException(ex);
  105. }
  106. }
  107. }
  108. #endregion
  109. #region 提交数据
  110. /// <summary>
  111. /// 删除
  112. /// </summary>
  113. /// <param name="keyValue">主键</param>
  114. public void DeleteEntity(string keyValue)
  115. {
  116. try
  117. {
  118. this.BaseRepository().Delete<EmailReceiveEntity>(t => t.F_Id == keyValue);
  119. }
  120. catch (Exception ex)
  121. {
  122. if (ex is ExceptionEx)
  123. {
  124. throw;
  125. }
  126. else
  127. {
  128. throw ExceptionEx.ThrowServiceException(ex);
  129. }
  130. }
  131. }
  132. /// <summary>
  133. /// 保存(新增、修改)
  134. /// </summary>
  135. /// <param name="keyValue">主键值</param>
  136. /// <param name="receiveEntity">邮件接收实体</param>
  137. /// <returns></returns>
  138. public void SaveReceiveEntity(string keyValue, EmailReceiveEntity receiveEntity)
  139. {
  140. try
  141. {
  142. if (!string.IsNullOrEmpty(keyValue))
  143. {
  144. receiveEntity.Modify(keyValue);
  145. this.BaseRepository().Update(receiveEntity);
  146. }
  147. else
  148. {
  149. receiveEntity.Create();
  150. this.BaseRepository().Insert(receiveEntity);
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. if (ex is ExceptionEx)
  156. {
  157. throw;
  158. }
  159. else
  160. {
  161. throw ExceptionEx.ThrowServiceException(ex);
  162. }
  163. }
  164. }
  165. #endregion
  166. }
  167. }