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.
 
 
 
 
 
 

211 lines
6.6 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. using System.Linq;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-01-28 17:11
  16. /// 描 述:教学楼信息管理
  17. /// </summary>
  18. public class ClassroomBuildingService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<ClassroomBuildingEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. t.ClassroomBuildingId,
  34. t.ClassroomBuildingName,
  35. t.ClassroomBuildingNo
  36. ");
  37. strSql.Append(" FROM ClassroomBuilding t ");
  38. strSql.Append(" WHERE 1=1 ");
  39. var queryParam = queryJson.ToJObject();
  40. // 虚拟参数
  41. var dp = new DynamicParameters(new { });
  42. if (!queryParam["ClassroomBuildingName"].IsEmpty())
  43. {
  44. dp.Add("ClassroomBuildingName", "%" + queryParam["ClassroomBuildingName"].ToString() + "%", DbType.String);
  45. strSql.Append(" AND t.ClassroomBuildingName Like @ClassroomBuildingName ");
  46. }
  47. if (!queryParam["ClassroomBuildingNo"].IsEmpty())
  48. {
  49. dp.Add("ClassroomBuildingNo", "%" + queryParam["ClassroomBuildingNo"].ToString() + "%", DbType.String);
  50. strSql.Append(" AND t.ClassroomBuildingNo Like @ClassroomBuildingNo ");
  51. }
  52. return this.BaseRepository("CollegeMIS").FindList<ClassroomBuildingEntity>(strSql.ToString(), dp, pagination);
  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. /// 获取ClassroomBuilding表实体数据
  68. /// <param name="keyValue">主键</param>
  69. /// <summary>
  70. /// <returns></returns>
  71. public ClassroomBuildingEntity GetClassroomBuildingEntity(string keyValue)
  72. {
  73. try
  74. {
  75. return this.BaseRepository("CollegeMIS").FindEntity<ClassroomBuildingEntity>(keyValue);
  76. }
  77. catch (Exception ex)
  78. {
  79. if (ex is ExceptionEx)
  80. {
  81. throw;
  82. }
  83. else
  84. {
  85. throw ExceptionEx.ThrowServiceException(ex);
  86. }
  87. }
  88. }
  89. /// <summary>
  90. /// 获取ClassroomBuilding表实体数据
  91. /// <param name="classroomBuildingNo">教学楼编号</param>
  92. /// <summary>
  93. /// <returns></returns>
  94. public ClassroomBuildingEntity GetClassroomBuildingEntityByNo(string classroomBuildingNo)
  95. {
  96. try
  97. {
  98. return this.BaseRepository("CollegeMIS").FindEntity<ClassroomBuildingEntity>(x => x.ClassroomBuildingNo == classroomBuildingNo);
  99. }
  100. catch (Exception ex)
  101. {
  102. if (ex is ExceptionEx)
  103. {
  104. throw;
  105. }
  106. else
  107. {
  108. throw ExceptionEx.ThrowServiceException(ex);
  109. }
  110. }
  111. }
  112. #endregion
  113. #region 提交数据
  114. /// <summary>
  115. /// 删除实体数据
  116. /// <param name="keyValue">主键</param>
  117. /// <summary>
  118. /// <returns></returns>
  119. public void DeleteEntity(string keyValue)
  120. {
  121. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  122. try
  123. {
  124. //单个删除
  125. //this.BaseRepository("CollegeMIS").Delete<ClassroomBuildingEntity>(t => t.ClassroomBuildingId == keyValue);
  126. //多个删除
  127. var keyValueArr = keyValue.Split(',');
  128. foreach (var item in keyValueArr)
  129. {
  130. db.Delete<ClassroomBuildingEntity>(t => t.ClassroomBuildingId == item);
  131. }
  132. db.Commit();
  133. }
  134. catch (Exception ex)
  135. {
  136. db.Rollback();
  137. if (ex is ExceptionEx)
  138. {
  139. throw;
  140. }
  141. else
  142. {
  143. throw ExceptionEx.ThrowServiceException(ex);
  144. }
  145. }
  146. }
  147. internal bool GetAny()
  148. {
  149. try
  150. {
  151. return this.BaseRepository("CollegeMIS").FindList<ClassroomBuildingEntity>().ToList().Count() > 0 ? true : false;
  152. }
  153. catch (Exception ex)
  154. {
  155. if (ex is ExceptionEx)
  156. {
  157. throw;
  158. }
  159. else
  160. {
  161. throw ExceptionEx.ThrowServiceException(ex);
  162. }
  163. }
  164. }
  165. /// <summary>
  166. /// 保存实体数据(新增、修改)
  167. /// <param name="keyValue">主键</param>
  168. /// <summary>
  169. /// <returns></returns>
  170. public void SaveEntity(string keyValue, ClassroomBuildingEntity entity)
  171. {
  172. try
  173. {
  174. if (!string.IsNullOrEmpty(keyValue))
  175. {
  176. entity.Modify(keyValue);
  177. this.BaseRepository("CollegeMIS").Update(entity);
  178. }
  179. else
  180. {
  181. entity.Create();
  182. this.BaseRepository("CollegeMIS").Insert(entity);
  183. }
  184. }
  185. catch (Exception ex)
  186. {
  187. if (ex is ExceptionEx)
  188. {
  189. throw;
  190. }
  191. else
  192. {
  193. throw ExceptionEx.ThrowServiceException(ex);
  194. }
  195. }
  196. }
  197. #endregion
  198. }
  199. }