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.
 
 
 
 
 
 

221 lines
6.7 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 DataSourceService : RepositoryFactory
  16. {
  17. #region 属性 构造函数
  18. private string fieldSql;
  19. public DataSourceService()
  20. {
  21. fieldSql = @"
  22. t.F_Id,
  23. t.F_Code,
  24. t.F_Name,
  25. t.F_DbId,
  26. t.F_Description,
  27. t.F_CreateUserId,
  28. t.F_CreateUserName,
  29. t.F_CreateDate,
  30. t.F_ModifyUserId,
  31. t.F_ModifyUserName,
  32. t.F_ModifyDate
  33. ";
  34. }
  35. #endregion
  36. #region 获取数据
  37. /// <summary>
  38. /// 获取分页数据
  39. /// </summary>
  40. /// <param name="pagination">分页参数</param>
  41. /// <param name="keyword">关键字</param>
  42. /// <returns></returns>
  43. public IEnumerable<DataSourceEntity> GetPageList(Pagination pagination, string keyword)
  44. {
  45. try
  46. {
  47. var strSql = new StringBuilder();
  48. strSql.Append("SELECT ");
  49. strSql.Append(fieldSql);
  50. strSql.Append(" FROM LR_Base_DataSource t ");
  51. strSql.Append(" WHERE 1=1 ");
  52. if (!string.IsNullOrEmpty(keyword))
  53. {
  54. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  55. keyword = "%" + keyword + "%";
  56. }
  57. return this.BaseRepository().FindList<DataSourceEntity>(strSql.ToString(), new { keyword = keyword }, pagination);
  58. }
  59. catch (Exception ex)
  60. {
  61. if (ex is ExceptionEx)
  62. {
  63. throw;
  64. }
  65. else
  66. {
  67. throw ExceptionEx.ThrowServiceException(ex);
  68. }
  69. }
  70. }
  71. /// <summary>
  72. /// 获取列表数据
  73. /// </summary>
  74. /// <returns></returns>
  75. public IEnumerable<DataSourceEntity> GetList()
  76. {
  77. try
  78. {
  79. var strSql = new StringBuilder();
  80. strSql.Append("SELECT ");
  81. strSql.Append(fieldSql);
  82. strSql.Append(" FROM LR_Base_DataSource t ");
  83. return this.BaseRepository().FindList<DataSourceEntity>(strSql.ToString());
  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="code">编码</param>
  101. /// <returns></returns>
  102. public DataSourceEntity GetEntityByCode(string code)
  103. {
  104. try
  105. {
  106. return this.BaseRepository().FindEntity<DataSourceEntity>(t => t.F_Code.Equals(code));
  107. }
  108. catch (Exception ex)
  109. {
  110. if (ex is ExceptionEx)
  111. {
  112. throw;
  113. }
  114. else
  115. {
  116. throw ExceptionEx.ThrowServiceException(ex);
  117. }
  118. }
  119. }
  120. /// <summary>
  121. /// 获取实体
  122. /// </summary>
  123. /// <param name="keyValue">主键</param>
  124. /// <returns></returns>
  125. public DataSourceEntity GetEntity(string keyValue) {
  126. try
  127. {
  128. return this.BaseRepository().FindEntity<DataSourceEntity>(keyValue);
  129. }
  130. catch (Exception ex)
  131. {
  132. if (ex is ExceptionEx)
  133. {
  134. throw;
  135. }
  136. else
  137. {
  138. throw ExceptionEx.ThrowServiceException(ex);
  139. }
  140. }
  141. }
  142. #endregion
  143. #region 提交数据
  144. /// <summary>
  145. /// 删除数据源
  146. /// </summary>
  147. /// <param name="keyValue">主键</param>
  148. public void DeleteEntity(string keyValue)
  149. {
  150. try
  151. {
  152. DataSourceEntity entity = new DataSourceEntity()
  153. {
  154. F_Id = keyValue,
  155. };
  156. this.BaseRepository().Delete(entity);
  157. }
  158. catch (Exception ex)
  159. {
  160. if (ex is ExceptionEx)
  161. {
  162. throw;
  163. }
  164. else
  165. {
  166. throw ExceptionEx.ThrowServiceException(ex);
  167. }
  168. }
  169. }
  170. /// <summary>
  171. /// 保存(新增、修改)
  172. /// </summary>
  173. /// <param name="keyValue">主键值</param>
  174. /// <param name="dataSourceEntity">数据源实体</param>
  175. /// <returns></returns>
  176. public bool SaveEntity(string keyValue, DataSourceEntity dataSourceEntity)
  177. {
  178. try
  179. {
  180. if (!string.IsNullOrEmpty(keyValue))
  181. {
  182. DataSourceEntity entity = this.BaseRepository().FindEntity<DataSourceEntity>(t => t.F_Code.Equals(dataSourceEntity.F_Code) && t.F_Id != keyValue);
  183. if (entity != null)
  184. {
  185. return false;
  186. }
  187. dataSourceEntity.Modify(keyValue);
  188. this.BaseRepository().Update(dataSourceEntity);
  189. }
  190. else
  191. {
  192. DataSourceEntity entity = GetEntityByCode(dataSourceEntity.F_Code);
  193. if (entity != null) {
  194. return false;
  195. }
  196. dataSourceEntity.Create();
  197. this.BaseRepository().Insert(dataSourceEntity);
  198. }
  199. return true;
  200. }
  201. catch (Exception ex)
  202. {
  203. if (ex is ExceptionEx)
  204. {
  205. throw;
  206. }
  207. else
  208. {
  209. throw ExceptionEx.ThrowServiceException(ex);
  210. }
  211. }
  212. }
  213. #endregion
  214. }
  215. }