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.
 
 
 
 
 
 

232 lines
7.3 KiB

  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2019-12-25 10:39
  15. /// 描 述:校长信箱
  16. /// </summary>
  17. public class StuMailService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表分页数据
  22. /// <summary>
  23. /// <param name="pagination">分页参数</param>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<StuMailEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.* ");
  32. strSql.Append(" FROM StuMail t ");
  33. strSql.Append(" WHERE 1=1 ");
  34. var queryParam = queryJson.ToJObject();
  35. // 虚拟参数
  36. var dp = new DynamicParameters(new { });
  37. if (!queryParam["Title"].IsEmpty())
  38. {
  39. dp.Add("Title", "%" + queryParam["Title"].ToString() + "%", DbType.String);
  40. strSql.Append(" AND t.Title Like @Title ");
  41. }
  42. return this.BaseRepository("CollegeMIS").FindList<StuMailEntity>(strSql.ToString(), dp, pagination);
  43. }
  44. catch (Exception ex)
  45. {
  46. if (ex is ExceptionEx)
  47. {
  48. throw;
  49. }
  50. else
  51. {
  52. throw ExceptionEx.ThrowServiceException(ex);
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 获取页面显示列表分页数据
  58. /// <summary>
  59. /// <param name="pagination">分页参数</param>
  60. /// <param name="queryJson">查询参数</param>
  61. /// <returns></returns>
  62. public IEnumerable<StuMailEntity> GetPageListByUserId(Pagination pagination, string queryJson, string userId)
  63. {
  64. try
  65. {
  66. var strSql = new StringBuilder();
  67. strSql.Append("SELECT t.* ");
  68. strSql.Append(" FROM StuMail t ");
  69. strSql.Append(" WHERE 1=1 ");
  70. var queryParam = queryJson.ToJObject();
  71. // 虚拟参数
  72. var dp = new DynamicParameters(new { });
  73. if (!queryParam["Title"].IsEmpty())
  74. {
  75. dp.Add("Title", "%" + queryParam["Title"].ToString() + "%", DbType.String);
  76. strSql.Append(" AND t.Title Like @Title ");
  77. }
  78. if (!userId.IsEmpty())
  79. {
  80. dp.Add("CreateUserId", userId, DbType.String);
  81. strSql.Append(" AND t.CreateUserId = @CreateUserId ");
  82. }
  83. return this.BaseRepository("CollegeMIS").FindList<StuMailEntity>(strSql.ToString(), dp, pagination);
  84. }
  85. catch (Exception ex)
  86. {
  87. if (ex is ExceptionEx)
  88. {
  89. throw;
  90. }
  91. else
  92. {
  93. throw ExceptionEx.ThrowServiceException(ex);
  94. }
  95. }
  96. }
  97. /// <summary>
  98. /// 获取页面显示列表数据
  99. /// <summary>
  100. /// <param name="queryJson">查询参数</param>
  101. /// <returns></returns>
  102. public IEnumerable<StuMailEntity> GetList(string queryJson)
  103. {
  104. try
  105. {
  106. var strSql = new StringBuilder();
  107. strSql.Append("SELECT ");
  108. strSql.Append(@"
  109. t.Id,
  110. t.Title,
  111. t.Content
  112. ");
  113. strSql.Append(" FROM StuMail t ");
  114. strSql.Append(" WHERE 1=1 ");
  115. var queryParam = queryJson.ToJObject();
  116. // 虚拟参数
  117. var dp = new DynamicParameters(new { });
  118. if (!queryParam["Title"].IsEmpty())
  119. {
  120. dp.Add("Title", "%" + queryParam["Title"].ToString() + "%", DbType.String);
  121. strSql.Append(" AND t.Title Like @Title ");
  122. }
  123. return this.BaseRepository("CollegeMIS").FindList<StuMailEntity>(strSql.ToString(), dp);
  124. }
  125. catch (Exception ex)
  126. {
  127. if (ex is ExceptionEx)
  128. {
  129. throw;
  130. }
  131. else
  132. {
  133. throw ExceptionEx.ThrowServiceException(ex);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 获取StuMail表实体数据
  139. /// <param name="keyValue">主键</param>
  140. /// <summary>
  141. /// <returns></returns>
  142. public StuMailEntity GetStuMailEntity(string keyValue)
  143. {
  144. try
  145. {
  146. return this.BaseRepository("CollegeMIS").FindEntity<StuMailEntity>(keyValue);
  147. }
  148. catch (Exception ex)
  149. {
  150. if (ex is ExceptionEx)
  151. {
  152. throw;
  153. }
  154. else
  155. {
  156. throw ExceptionEx.ThrowServiceException(ex);
  157. }
  158. }
  159. }
  160. #endregion
  161. #region 提交数据
  162. /// <summary>
  163. /// 删除实体数据
  164. /// <param name="keyValue">主键</param>
  165. /// <summary>
  166. /// <returns></returns>
  167. public void DeleteEntity(string keyValue)
  168. {
  169. try
  170. {
  171. this.BaseRepository("CollegeMIS").Delete<StuMailEntity>(t => t.Id == keyValue);
  172. }
  173. catch (Exception ex)
  174. {
  175. if (ex is ExceptionEx)
  176. {
  177. throw;
  178. }
  179. else
  180. {
  181. throw ExceptionEx.ThrowServiceException(ex);
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// 保存实体数据(新增、修改)
  187. /// <param name="keyValue">主键</param>
  188. /// <summary>
  189. /// <returns></returns>
  190. public void SaveEntity(UserInfo userInfo, string keyValue, StuMailEntity entity)
  191. {
  192. try
  193. {
  194. if (!string.IsNullOrEmpty(keyValue))
  195. {
  196. entity.Modify(keyValue, userInfo);
  197. this.BaseRepository("CollegeMIS").Update(entity);
  198. }
  199. else
  200. {
  201. entity.Create(userInfo);
  202. this.BaseRepository("CollegeMIS").Insert(entity);
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. if (ex is ExceptionEx)
  208. {
  209. throw;
  210. }
  211. else
  212. {
  213. throw ExceptionEx.ThrowServiceException(ex);
  214. }
  215. }
  216. }
  217. #endregion
  218. }
  219. }