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
5.5 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-12-19 12:03
  13. /// 描 述:数据库建表草稿管理
  14. /// </summary>
  15. public class DbDraftService : RepositoryFactory
  16. {
  17. #region 构造函数和属性
  18. private string fieldSql;
  19. public DbDraftService()
  20. {
  21. fieldSql = @"
  22. t.F_Id,
  23. t.F_Name,
  24. t.F_Content,
  25. t.F_Remark,
  26. t.F_CreateDate,
  27. t.F_CreateUserId,
  28. t.F_CreateUserName
  29. ";
  30. }
  31. #endregion
  32. #region 获取数据
  33. /// <summary>
  34. /// 获取列表数据
  35. /// <summary>
  36. /// <returns></returns>
  37. public IEnumerable<DbDraftEntity> GetList(string queryJson)
  38. {
  39. try
  40. {
  41. var queryParam = queryJson.ToJObject();
  42. var strSql = new StringBuilder();
  43. strSql.Append("SELECT ");
  44. strSql.Append(fieldSql);
  45. strSql.Append(" FROM LR_Base_DbDraft t where 1=1 ");
  46. string keyword = "";
  47. if (!queryParam["keyword"].IsEmpty())
  48. {
  49. keyword = "%" + queryParam["keyword"].ToString() + "%";
  50. strSql.Append(" and ( t.F_Name like @keyword or t.F_Remark like @keyword ) ");
  51. }
  52. return this.BaseRepository().FindList<DbDraftEntity>(strSql.ToString(),new { keyword= keyword });
  53. }
  54. catch (Exception ex)
  55. {
  56. if (ex is ExceptionEx)
  57. {
  58. throw;
  59. }
  60. else
  61. {
  62. throw ExceptionEx.ThrowServiceException(ex);
  63. }
  64. }
  65. }
  66. /// <summary>
  67. /// 获取列表分页数据
  68. /// <param name="pagination">分页参数</param>
  69. /// <summary>
  70. /// <returns></returns>
  71. public IEnumerable<DbDraftEntity> GetPageList(Pagination pagination, string queryJson)
  72. {
  73. try
  74. {
  75. var strSql = new StringBuilder();
  76. strSql.Append("SELECT ");
  77. strSql.Append(fieldSql);
  78. strSql.Append(" FROM LR_Base_DbDraft t where t.F_DeleteMark =0 ");
  79. return this.BaseRepository().FindList<DbDraftEntity>(strSql.ToString(), pagination);
  80. }
  81. catch (Exception ex)
  82. {
  83. if (ex is ExceptionEx)
  84. {
  85. throw;
  86. }
  87. else
  88. {
  89. throw ExceptionEx.ThrowServiceException(ex);
  90. }
  91. }
  92. }
  93. /// <summary>
  94. /// 获取实体数据
  95. /// <param name="keyValue">主键</param>
  96. /// <summary>
  97. /// <returns></returns>
  98. public DbDraftEntity GetEntity(string keyValue)
  99. {
  100. try
  101. {
  102. return this.BaseRepository().FindEntity<DbDraftEntity>(keyValue);
  103. }
  104. catch (Exception ex)
  105. {
  106. if (ex is ExceptionEx)
  107. {
  108. throw;
  109. }
  110. else
  111. {
  112. throw ExceptionEx.ThrowServiceException(ex);
  113. }
  114. }
  115. }
  116. #endregion
  117. #region 提交数据
  118. /// <summary>
  119. /// 删除实体数据
  120. /// <param name="keyValue">主键</param>
  121. /// <summary>
  122. /// <returns></returns>
  123. public void DeleteEntity(string keyValue)
  124. {
  125. var db = this.BaseRepository().BeginTrans();
  126. try
  127. {
  128. string[] keyvalues = keyValue.Split(',');
  129. foreach (var item in keyvalues)
  130. {
  131. db.Delete<DbDraftEntity>(t=>t.F_Id == item);
  132. }
  133. db.Commit();
  134. }
  135. catch (Exception ex)
  136. {
  137. db.Rollback();
  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, DbDraftEntity 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. }