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.
 
 
 
 
 
 

197 lines
6.2 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.Base.SystemModule
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.08
  13. /// 描 述:自定义查询
  14. /// </summary>
  15. public class CustmerQueryService : RepositoryFactory
  16. {
  17. #region 构造函数和属性
  18. private string fieldSql;
  19. public CustmerQueryService()
  20. {
  21. fieldSql = @"
  22. t.F_CustmerQueryId,
  23. t.F_Name,
  24. t.F_UserId,
  25. t.F_ModuleId,
  26. t.F_ModuleUrl,
  27. t.F_Formula,
  28. t.F_QueryJson
  29. ";
  30. }
  31. #endregion
  32. #region 获取数据
  33. /// <summary>
  34. /// 获取自定义查询(公共)分页数据
  35. /// </summary>
  36. /// <param name="pagination">分页参数</param>
  37. /// <param name="keyword">关键字</param>
  38. /// <returns></returns>
  39. public IEnumerable<CustmerQueryEntity> GetPageList(Pagination pagination, string keyword)
  40. {
  41. try
  42. {
  43. var strSql = new StringBuilder();
  44. strSql.Append("SELECT ");
  45. strSql.Append(fieldSql);
  46. strSql.Append(" , m.F_FullName as ModuleName ");
  47. strSql.Append(" FROM LR_Base_CustmerQuery t ");
  48. strSql.Append(" LEFT JOIN LR_Base_Module m ON m.F_ModuleId = t.F_ModuleId ");
  49. strSql.Append(" WHERE F_UserId is NULL ");
  50. if (!string.IsNullOrEmpty(keyword))
  51. {
  52. strSql.Append(" AND ( m.F_FullName like @keyword OR t.F_Name like @keyword ) ");
  53. keyword = "%" + keyword + "%";
  54. }
  55. return this.BaseRepository().FindList<CustmerQueryEntity>(strSql.ToString(), new { keyword = keyword }, pagination);
  56. }
  57. catch (Exception ex)
  58. {
  59. if (ex is ExceptionEx)
  60. {
  61. throw;
  62. }
  63. else
  64. {
  65. throw ExceptionEx.ThrowServiceException(ex);
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// 获取自定义查询条件(公共)
  71. /// </summary>
  72. /// <param name="moduleUrl">访问的功能链接地址</param>
  73. /// <param name="userId">用户ID(用户ID为null表示公共)</param>
  74. /// <returns></returns>
  75. public IEnumerable<CustmerQueryEntity> GetList(string moduleUrl, string userId)
  76. {
  77. try
  78. {
  79. var strSql = new StringBuilder();
  80. strSql.Append("SELECT ");
  81. strSql.Append(fieldSql);
  82. strSql.Append(" FROM LR_Base_CustmerQuery t WHERE F_ModuleUrl = @moduleUrl");
  83. if (string.IsNullOrEmpty(userId))
  84. {
  85. strSql.Append(" AND F_UserId is NULL");
  86. }
  87. else
  88. {
  89. strSql.Append(" AND F_UserId = @userId ");
  90. }
  91. return this.BaseRepository().FindList<CustmerQueryEntity>(strSql.ToString(), new { moduleUrl = moduleUrl, userId = userId });
  92. }
  93. catch (Exception ex)
  94. {
  95. if (ex is ExceptionEx)
  96. {
  97. throw;
  98. }
  99. else
  100. {
  101. throw ExceptionEx.ThrowServiceException(ex);
  102. }
  103. }
  104. }
  105. /// <summary>
  106. /// 获取实体
  107. /// </summary>
  108. /// <param name="keyValue">主键</param>
  109. /// <returns></returns>
  110. public CustmerQueryEntity GetEntity(string keyValue)
  111. {
  112. try
  113. {
  114. return this.BaseRepository().FindEntity<CustmerQueryEntity>(keyValue);
  115. }
  116. catch (Exception ex)
  117. {
  118. if (ex is ExceptionEx)
  119. {
  120. throw;
  121. }
  122. else
  123. {
  124. throw ExceptionEx.ThrowServiceException(ex);
  125. }
  126. }
  127. }
  128. #endregion
  129. #region 提交数据
  130. /// <summary>
  131. /// 删除自定义查询条件
  132. /// </summary>
  133. /// <param name="keyValue">主键</param>
  134. public void DeleteEntity(string keyValue)
  135. {
  136. try
  137. {
  138. CustmerQueryEntity entity = new CustmerQueryEntity()
  139. {
  140. F_CustmerQueryId = keyValue,
  141. };
  142. this.BaseRepository().Delete(entity);
  143. }
  144. catch (Exception ex)
  145. {
  146. if (ex is ExceptionEx)
  147. {
  148. throw;
  149. }
  150. else
  151. {
  152. throw ExceptionEx.ThrowServiceException(ex);
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 保存自定义查询(新增、修改)
  158. /// </summary>
  159. /// <param name="keyValue">主键值</param>
  160. /// <param name="departmentEntity">部门实体</param>
  161. /// <returns></returns>
  162. public void SaveEntity(string keyValue, CustmerQueryEntity custmerQueryEntity)
  163. {
  164. try
  165. {
  166. if (!string.IsNullOrEmpty(keyValue))
  167. {
  168. custmerQueryEntity.Modify(keyValue);
  169. this.BaseRepository().Update(custmerQueryEntity);
  170. }
  171. else
  172. {
  173. custmerQueryEntity.Create();
  174. this.BaseRepository().Insert(custmerQueryEntity);
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. if (ex is ExceptionEx)
  180. {
  181. throw;
  182. }
  183. else
  184. {
  185. throw ExceptionEx.ThrowServiceException(ex);
  186. }
  187. }
  188. }
  189. #endregion
  190. }
  191. }