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.
 
 
 
 
 
 

308 lines
9.7 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:30
  16. /// 描 述:教室信息管理
  17. /// </summary>
  18. public class ClassroomInfoService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<ClassroomInfoEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. t.ClassroomId,
  34. t.ClassroomName,
  35. t.ClassroomNo,
  36. t.ClassroomTypeNo,
  37. t.ClassroomBuildingNo,
  38. t.ClassroomFloor,
  39. t.ContainStuNum,
  40. t.TestContainStuNum,
  41. t.CheckMark,t.F_SchoolId
  42. ");
  43. strSql.Append(" FROM ClassroomInfo t ");
  44. strSql.Append(" WHERE 1=1 ");
  45. var queryParam = queryJson.ToJObject();
  46. // 虚拟参数
  47. var dp = new DynamicParameters(new { });
  48. if (!queryParam["ClassroomName"].IsEmpty())
  49. {
  50. dp.Add("ClassroomName", "%" + queryParam["ClassroomName"].ToString() + "%", DbType.String);
  51. strSql.Append(" AND t.ClassroomName Like @ClassroomName ");
  52. }
  53. if (!queryParam["ClassroomNo"].IsEmpty())
  54. {
  55. dp.Add("ClassroomNo", "%" + queryParam["ClassroomNo"].ToString() + "%", DbType.String);
  56. strSql.Append(" AND t.ClassroomNo Like @ClassroomNo ");
  57. }
  58. if (!queryParam["ClassroomBuildingNo"].IsEmpty())
  59. {
  60. dp.Add("ClassroomBuildingNo", queryParam["ClassroomBuildingNo"].ToString(), DbType.String);
  61. strSql.Append(" AND t.ClassroomBuildingNo = @ClassroomBuildingNo ");
  62. }
  63. if (!queryParam["ClassroomTypeNo"].IsEmpty())
  64. {
  65. dp.Add("ClassroomTypeNo", queryParam["ClassroomTypeNo"].ToString(), DbType.String);
  66. strSql.Append(" AND t.ClassroomTypeNo = @ClassroomTypeNo ");
  67. }
  68. return this.BaseRepository("CollegeMIS").FindList<ClassroomInfoEntity>(strSql.ToString(), dp, pagination);
  69. }
  70. catch (Exception ex)
  71. {
  72. if (ex is ExceptionEx)
  73. {
  74. throw;
  75. }
  76. else
  77. {
  78. throw ExceptionEx.ThrowServiceException(ex);
  79. }
  80. }
  81. }
  82. /// <summary>
  83. /// 获取页面显示列表数据
  84. /// <summary>
  85. /// <param name="queryJson">查询参数</param>
  86. /// <returns></returns>
  87. public IEnumerable<ClassroomInfoEntity> GetAllList()
  88. {
  89. try
  90. {
  91. return this.BaseRepository("CollegeMIS").FindList<ClassroomInfoEntity>();
  92. }
  93. catch (Exception ex)
  94. {
  95. if (ex is ExceptionEx)
  96. {
  97. throw;
  98. }
  99. else
  100. {
  101. throw ExceptionEx.ThrowServiceException(ex);
  102. }
  103. }
  104. }
  105. internal bool GetAny()
  106. {
  107. try
  108. {
  109. return this.BaseRepository("CollegeMIS").FindList<ClassroomInfoEntity>().ToList().Count() > 0 ? true : false;
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowServiceException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 获取ClassroomInfo表实体数据
  125. /// <param name="keyValue">主键</param>
  126. /// <summary>
  127. /// <returns></returns>
  128. public ClassroomInfoEntity GetClassroomInfoEntity(string keyValue)
  129. {
  130. try
  131. {
  132. return this.BaseRepository("CollegeMIS").FindEntity<ClassroomInfoEntity>(keyValue);
  133. }
  134. catch (Exception ex)
  135. {
  136. if (ex is ExceptionEx)
  137. {
  138. throw;
  139. }
  140. else
  141. {
  142. throw ExceptionEx.ThrowServiceException(ex);
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 获取ClassroomInfo表实体数据
  148. /// <param name="classroomNo">教室编号</param>
  149. /// <summary>
  150. /// <returns></returns>
  151. public ClassroomInfoEntity GetClassroomInfoEntityByNo(string classroomNo)
  152. {
  153. try
  154. {
  155. return this.BaseRepository("CollegeMIS").FindEntity<ClassroomInfoEntity>(x => x.ClassroomNo == classroomNo);
  156. }
  157. catch (Exception ex)
  158. {
  159. if (ex is ExceptionEx)
  160. {
  161. throw;
  162. }
  163. else
  164. {
  165. throw ExceptionEx.ThrowServiceException(ex);
  166. }
  167. }
  168. }
  169. #endregion
  170. #region 提交数据
  171. public void Lock(string keyValue)
  172. {
  173. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  174. try
  175. {
  176. //单个启用
  177. // this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassroomInfo set CheckMark=1 where ClassroomId='" + keyValue + "'");
  178. //多个启用
  179. var keyValueArr = keyValue.Split(',');
  180. foreach (var item in keyValueArr)
  181. {
  182. db.ExecuteBySql("update ClassroomInfo set CheckMark=1 where ClassroomId='" + item + "'");
  183. }
  184. db.Commit();
  185. }
  186. catch (Exception ex)
  187. {
  188. db.Rollback();
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowServiceException(ex);
  196. }
  197. }
  198. }
  199. public void UnLock(string keyValue)
  200. {
  201. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  202. try
  203. {
  204. //单个停用
  205. // this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassroomInfo set CheckMark=0 where ClassroomId='" + keyValue + "'");
  206. //多个停用
  207. var keyValueArr = keyValue.Split(',');
  208. foreach (var item in keyValueArr)
  209. {
  210. db.ExecuteBySql("update ClassroomInfo set CheckMark=0 where ClassroomId='" + item + "'");
  211. }
  212. db.Commit();
  213. }
  214. catch (Exception ex)
  215. {
  216. db.Rollback();
  217. if (ex is ExceptionEx)
  218. {
  219. throw;
  220. }
  221. else
  222. {
  223. throw ExceptionEx.ThrowServiceException(ex);
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 删除实体数据
  229. /// <param name="keyValue">主键</param>
  230. /// <summary>
  231. /// <returns></returns>
  232. public void DeleteEntity(string keyValue)
  233. {
  234. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  235. try
  236. {
  237. //单个删除
  238. //this.BaseRepository("CollegeMIS").Delete<ClassroomInfoEntity>(t => t.ClassroomId == keyValue);
  239. //多个删除
  240. var keyValueArr = keyValue.Split(',');
  241. foreach (var item in keyValueArr)
  242. {
  243. db.Delete<ClassroomInfoEntity>(t => t.ClassroomId == item);
  244. }
  245. db.Commit();
  246. }
  247. catch (Exception ex)
  248. {
  249. db.Rollback();
  250. if (ex is ExceptionEx)
  251. {
  252. throw;
  253. }
  254. else
  255. {
  256. throw ExceptionEx.ThrowServiceException(ex);
  257. }
  258. }
  259. }
  260. /// <summary>
  261. /// 保存实体数据(新增、修改)
  262. /// <param name="keyValue">主键</param>
  263. /// <summary>
  264. /// <returns></returns>
  265. public void SaveEntity(string keyValue, ClassroomInfoEntity entity)
  266. {
  267. try
  268. {
  269. if (!string.IsNullOrEmpty(keyValue))
  270. {
  271. entity.Modify(keyValue);
  272. this.BaseRepository("CollegeMIS").Update(entity);
  273. }
  274. else
  275. {
  276. entity.Create();
  277. this.BaseRepository("CollegeMIS").Insert(entity);
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. if (ex is ExceptionEx)
  283. {
  284. throw;
  285. }
  286. else
  287. {
  288. throw ExceptionEx.ThrowServiceException(ex);
  289. }
  290. }
  291. }
  292. #endregion
  293. }
  294. }