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.
 
 
 
 
 
 

178 lines
5.3 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.EducationalAdministration
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2019-06-12 10:06
  15. /// 描 述:书籍信息
  16. /// </summary>
  17. public class BookInfoService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表数据
  22. /// <summary>
  23. /// <param name="queryJson">查询参数</param>
  24. /// <returns></returns>
  25. public IEnumerable<Book_infoEntity> GetPageList(Pagination pagination, string queryJson)
  26. {
  27. try
  28. {
  29. var strSql = new StringBuilder();
  30. strSql.Append("SELECT ");
  31. strSql.Append(@"
  32. t.ID,
  33. t.BookName,
  34. t.Collation,
  35. t.ISBN,
  36. t.BookType,
  37. t.Author,
  38. t.Publisher,
  39. t.BookCode,
  40. t.PublishTime,
  41. t.AddTime,
  42. t.Price,
  43. t.BookLocation,
  44. t.CheckMark,
  45. t.Remark
  46. ");
  47. strSql.Append(" FROM Book_info t ");
  48. strSql.Append(" WHERE 1=1 ");
  49. var queryParam = queryJson.ToJObject();
  50. // 虚拟参数
  51. var dp = new DynamicParameters(new { });
  52. if (!queryParam["BookName"].IsEmpty())
  53. {
  54. dp.Add("BookName", "%" + queryParam["BookName"].ToString() + "%", DbType.String);
  55. strSql.Append(" AND t.BookName Like @BookName ");
  56. }
  57. if (!queryParam["ISBN"].IsEmpty())
  58. {
  59. dp.Add("ISBN", "%" + queryParam["ISBN"].ToString() + "%", DbType.String);
  60. strSql.Append(" AND t.ISBN Like @ISBN ");
  61. }
  62. if (!queryParam["BookType"].IsEmpty())
  63. {
  64. dp.Add("BookType", "%" + queryParam["BookType"].ToString() + "%", DbType.String);
  65. strSql.Append(" AND t.BookType Like @BookType ");
  66. }
  67. if (!queryParam["Author"].IsEmpty())
  68. {
  69. dp.Add("Author", "%" + queryParam["Author"].ToString() + "%", DbType.String);
  70. strSql.Append(" AND t.Author Like @Author ");
  71. }
  72. return this.BaseRepository().FindList<Book_infoEntity>(strSql.ToString(),dp, pagination);
  73. }
  74. catch (Exception ex)
  75. {
  76. if (ex is ExceptionEx)
  77. {
  78. throw;
  79. }
  80. else
  81. {
  82. throw ExceptionEx.ThrowServiceException(ex);
  83. }
  84. }
  85. }
  86. /// <summary>
  87. /// 获取Book_info表实体数据
  88. /// <param name="keyValue">主键</param>
  89. /// <summary>
  90. /// <returns></returns>
  91. public Book_infoEntity GetBook_infoEntity(string keyValue)
  92. {
  93. try
  94. {
  95. return this.BaseRepository().FindEntity<Book_infoEntity>(keyValue);
  96. }
  97. catch (Exception ex)
  98. {
  99. if (ex is ExceptionEx)
  100. {
  101. throw;
  102. }
  103. else
  104. {
  105. throw ExceptionEx.ThrowServiceException(ex);
  106. }
  107. }
  108. }
  109. #endregion
  110. #region 提交数据
  111. /// <summary>
  112. /// 删除实体数据
  113. /// <param name="keyValue">主键</param>
  114. /// <summary>
  115. /// <returns></returns>
  116. public void DeleteEntity(string keyValue)
  117. {
  118. try
  119. {
  120. this.BaseRepository().Delete<Book_infoEntity>(t=>t.ID == keyValue);
  121. }
  122. catch (Exception ex)
  123. {
  124. if (ex is ExceptionEx)
  125. {
  126. throw;
  127. }
  128. else
  129. {
  130. throw ExceptionEx.ThrowServiceException(ex);
  131. }
  132. }
  133. }
  134. /// <summary>
  135. /// 保存实体数据(新增、修改)
  136. /// <param name="keyValue">主键</param>
  137. /// <summary>
  138. /// <returns></returns>
  139. public void SaveEntity(string keyValue, Book_infoEntity entity)
  140. {
  141. try
  142. {
  143. if (!string.IsNullOrEmpty(keyValue))
  144. {
  145. entity.Modify(keyValue);
  146. this.BaseRepository().Update(entity);
  147. }
  148. else
  149. {
  150. entity.Create();
  151. this.BaseRepository().Insert(entity);
  152. }
  153. }
  154. catch (Exception ex)
  155. {
  156. if (ex is ExceptionEx)
  157. {
  158. throw;
  159. }
  160. else
  161. {
  162. throw ExceptionEx.ThrowServiceException(ex);
  163. }
  164. }
  165. }
  166. #endregion
  167. }
  168. }