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.
 
 
 
 
 
 

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