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.

LessonInfoService.cs 11 KiB

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