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.
 
 
 
 
 
 

256 lines
8.9 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 V7.0.6 力软敏捷开发框架
  12. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2022-01-24 12:19
  15. /// 描 述:教材信息管理
  16. /// </summary>
  17. public class TextBookInfoService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表数据
  22. /// </summary>
  23. /// <param name="pagination">查询参数</param>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<TextBookInfoEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@" * ");
  33. strSql.Append(" FROM TextBookInfo t ");
  34. strSql.Append(" WHERE 1=1 ");
  35. var queryParam = queryJson.ToJObject();
  36. // 虚拟参数
  37. var dp = new DynamicParameters(new { });
  38. if (!queryParam["TextBookName"].IsEmpty())
  39. {
  40. dp.Add("TextBookName", "%" + queryParam["TextBookName"].ToString() + "%", DbType.String);
  41. strSql.Append(" AND t.TextBookName Like @TextBookName ");
  42. }
  43. if (!queryParam["DeptNo"].IsEmpty())
  44. {
  45. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  46. strSql.Append(" AND t.DeptNo = @DeptNo ");
  47. }
  48. if (!queryParam["TextBookType"].IsEmpty())
  49. {
  50. dp.Add("TextBookType", queryParam["TextBookType"].ToString(), DbType.String);
  51. strSql.Append(" AND t.TextBookType = @TextBookType ");
  52. }
  53. if (!queryParam["TextBookNature"].IsEmpty())
  54. {
  55. dp.Add("TextBookNature", queryParam["TextBookNature"].ToString(), DbType.String);
  56. strSql.Append(" AND t.TextBookNature = @TextBookNature ");
  57. }
  58. if (!queryParam["SqlParameter"].IsEmpty())
  59. {
  60. strSql.Append(queryParam["SqlParameter"].ToString());
  61. }
  62. return this.BaseRepository("CollegeMIS").FindList<TextBookInfoEntity>(strSql.ToString(), dp, pagination);
  63. }
  64. catch (Exception ex)
  65. {
  66. if (ex is ExceptionEx)
  67. {
  68. throw;
  69. }
  70. else
  71. {
  72. throw ExceptionEx.ThrowServiceException(ex);
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 获取TextBookInfo表实体数据
  78. /// </summary>
  79. /// <param name="keyValue">主键</param>
  80. /// <returns></returns>
  81. public TextBookInfoEntity GetTextBookInfoEntity(string keyValue)
  82. {
  83. try
  84. {
  85. return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(keyValue);
  86. }
  87. catch (Exception ex)
  88. {
  89. if (ex is ExceptionEx)
  90. {
  91. throw;
  92. }
  93. else
  94. {
  95. throw ExceptionEx.ThrowServiceException(ex);
  96. }
  97. }
  98. }
  99. #endregion
  100. #region 提交数据
  101. /// <summary>
  102. /// 删除实体数据
  103. /// </summary>
  104. /// <param name="keyValue">主键</param>
  105. public void DeleteEntity(string keyValue)
  106. {
  107. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  108. try
  109. {
  110. var keyValueArr = keyValue.Split(',');
  111. foreach (var item in keyValueArr)
  112. {
  113. var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(x => x.ID == item);
  114. entity.IsDel = 1;
  115. db.Update(entity);
  116. }
  117. db.Commit();
  118. }
  119. catch (Exception ex)
  120. {
  121. db.Rollback();
  122. if (ex is ExceptionEx)
  123. {
  124. throw;
  125. }
  126. else
  127. {
  128. throw ExceptionEx.ThrowServiceException(ex);
  129. }
  130. }
  131. }
  132. /// <summary>
  133. /// 保存实体数据(新增、修改)
  134. /// </summary>
  135. /// <param name="keyValue">主键</param>
  136. /// <param name="entity">实体</param>
  137. public void SaveEntity(string keyValue, TextBookInfoEntity entity)
  138. {
  139. try
  140. {
  141. if (!string.IsNullOrEmpty(keyValue))
  142. {
  143. entity.Modify(keyValue);
  144. this.BaseRepository("CollegeMIS").Update(entity);
  145. }
  146. else
  147. {
  148. entity.Create();
  149. this.BaseRepository("CollegeMIS").Insert(entity);
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. if (ex is ExceptionEx)
  155. {
  156. throw;
  157. }
  158. else
  159. {
  160. throw ExceptionEx.ThrowServiceException(ex);
  161. }
  162. }
  163. }
  164. #endregion
  165. #region 扩展数据
  166. /// <summary>
  167. /// 启用或禁用
  168. /// </summary>
  169. /// <param name="keyValue"></param>
  170. public void EnabOrDisabEntity(string keyValue, string IsValid)
  171. {
  172. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  173. try
  174. {
  175. var keyValueArr = keyValue.Split(',');
  176. foreach (var item in keyValueArr)
  177. {
  178. var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(x => x.ID == item);
  179. entity.IsValid = IsValid.ToString() == "1" ? true : false;
  180. db.Update(entity);
  181. }
  182. db.Commit();
  183. }
  184. catch (Exception ex)
  185. {
  186. db.Rollback();
  187. if (ex is ExceptionEx)
  188. {
  189. throw;
  190. }
  191. else
  192. {
  193. throw ExceptionEx.ThrowServiceException(ex);
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 去重
  199. /// </summary>
  200. /// <param name="keyValue"></param>
  201. /// <param name="TextBookNo"></param>
  202. /// <param name="TextBookName"></param>
  203. /// <param name="PublishNo"></param>
  204. /// <param name="DeptNo"></param>
  205. /// <param name="Publisher"></param>
  206. /// <param name="TextBookNature"></param>
  207. /// <param name="TextBookType"></param>
  208. /// <param name="Edition"></param>
  209. /// <param name="Impression"></param>
  210. /// <returns></returns>
  211. public TextBookInfoEntity GetRepetitions(string keyValue, string TextBookNo, string TextBookName, string PublishNo, string DeptNo, string Publisher, string TextBookNature, string TextBookType, string Edition, string Impression)
  212. {
  213. try
  214. {
  215. if (!string.IsNullOrEmpty(keyValue))
  216. {
  217. return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(
  218. x => x.ID != keyValue && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
  219. x.DeptNo == DeptNo && x.PublishNo == Publisher && x.TextBookNature == TextBookNature && x.TextBookType == TextBookType
  220. && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0);
  221. }
  222. else
  223. {
  224. return this.BaseRepository("CollegeMIS").FindEntity<TextBookInfoEntity>(
  225. x => x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
  226. x.DeptNo == DeptNo && x.PublishNo == Publisher && x.TextBookNature == TextBookNature && x.TextBookType == TextBookType
  227. && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0);
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. if (ex is ExceptionEx)
  233. {
  234. throw;
  235. }
  236. else
  237. {
  238. throw ExceptionEx.ThrowServiceException(ex);
  239. }
  240. }
  241. }
  242. #endregion
  243. }
  244. }