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.
 
 
 
 
 
 

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