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.

AddressBookService.cs 5.4 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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-03-06 17:19
  15. /// 描 述:通讯录
  16. /// </summary>
  17. public class AddressBookService : RepositoryFactory
  18. {
  19. #region 构造函数和属性
  20. private string fieldSql;
  21. public AddressBookService()
  22. {
  23. fieldSql=@"
  24. t.AId,
  25. t.ASaverId,
  26. t.AName,
  27. t.AGender,
  28. t.ACompany,
  29. t.ACTell,
  30. t.AMobile,
  31. t.AEmail,
  32. t.AIsShare
  33. ";
  34. }
  35. #endregion
  36. #region 获取数据
  37. /// <summary>
  38. /// 获取列表数据
  39. /// <summary>
  40. /// <returns></returns>
  41. public IEnumerable<AddressBookEntity> GetList( string queryJson )
  42. {
  43. try
  44. {
  45. //参考写法
  46. //var queryParam = queryJson.ToJObject();
  47. // 虚拟参数
  48. //var dp = new DynamicParameters(new { });
  49. //dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  50. var strSql = new StringBuilder();
  51. strSql.Append("SELECT ");
  52. strSql.Append(fieldSql);
  53. strSql.Append(" FROM AddressBook t ");
  54. return this.BaseRepository().FindList<AddressBookEntity>(strSql.ToString());
  55. }
  56. catch (Exception ex)
  57. {
  58. if (ex is ExceptionEx)
  59. {
  60. throw;
  61. }
  62. else
  63. {
  64. throw ExceptionEx.ThrowServiceException(ex);
  65. }
  66. }
  67. }
  68. /// <summary>
  69. /// 获取列表分页数据
  70. /// <param name="pagination">分页参数</param>
  71. /// <summary>
  72. /// <returns></returns>
  73. public IEnumerable<AddressBookEntity> GetPageList(Pagination pagination, string queryJson)
  74. {
  75. try
  76. {
  77. var strSql = new StringBuilder();
  78. strSql.Append("SELECT ");
  79. strSql.Append(fieldSql);
  80. strSql.Append(" FROM AddressBook t ");
  81. var data = LoginUserInfo.Get();
  82. if (!data.isSystem)
  83. {
  84. strSql.Append($" where ASaverId='{data.userId}' or AIsShare=1");
  85. }
  86. return this.BaseRepository().FindList<AddressBookEntity>(strSql.ToString(), pagination);
  87. }
  88. catch (Exception ex)
  89. {
  90. if (ex is ExceptionEx)
  91. {
  92. throw;
  93. }
  94. else
  95. {
  96. throw ExceptionEx.ThrowServiceException(ex);
  97. }
  98. }
  99. }
  100. /// <summary>
  101. /// 获取实体数据
  102. /// <param name="keyValue">主键</param>
  103. /// <summary>
  104. /// <returns></returns>
  105. public AddressBookEntity GetEntity(string keyValue)
  106. {
  107. try
  108. {
  109. return this.BaseRepository().FindEntity<AddressBookEntity>(keyValue);
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowServiceException(ex);
  120. }
  121. }
  122. }
  123. #endregion
  124. #region 提交数据
  125. /// <summary>
  126. /// 删除实体数据
  127. /// <param name="keyValue">主键</param>
  128. /// <summary>
  129. /// <returns></returns>
  130. public void DeleteEntity(string keyValue)
  131. {
  132. try
  133. {
  134. this.BaseRepository().Delete<AddressBookEntity>(t=>t.AId == keyValue);
  135. }
  136. catch (Exception ex)
  137. {
  138. if (ex is ExceptionEx)
  139. {
  140. throw;
  141. }
  142. else
  143. {
  144. throw ExceptionEx.ThrowServiceException(ex);
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 保存实体数据(新增、修改)
  150. /// <param name="keyValue">主键</param>
  151. /// <summary>
  152. /// <returns></returns>
  153. public void SaveEntity(string keyValue, AddressBookEntity entity)
  154. {
  155. try
  156. {
  157. if (!string.IsNullOrEmpty(keyValue))
  158. {
  159. entity.Modify(keyValue);
  160. this.BaseRepository().Update(entity);
  161. }
  162. else
  163. {
  164. entity.Create();
  165. this.BaseRepository().Insert(entity);
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. if (ex is ExceptionEx)
  171. {
  172. throw;
  173. }
  174. else
  175. {
  176. throw ExceptionEx.ThrowServiceException(ex);
  177. }
  178. }
  179. }
  180. #endregion
  181. }
  182. }