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
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. internal bool GetAny()
  101. {
  102. try
  103. {
  104. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>().ToList().Count() > 0 ? true : false;
  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. /// <summary>
  119. /// 获取LessonInfo表实体数据
  120. /// <param name="keyValue">主键</param>
  121. /// <summary>
  122. /// <returns></returns>
  123. public LessonInfoEntity GetLessonInfoEntity(string keyValue)
  124. {
  125. try
  126. {
  127. return this.BaseRepository("CollegeMIS").FindEntity<LessonInfoEntity>(keyValue);
  128. }
  129. catch (Exception ex)
  130. {
  131. if (ex is ExceptionEx)
  132. {
  133. throw;
  134. }
  135. else
  136. {
  137. throw ExceptionEx.ThrowServiceException(ex);
  138. }
  139. }
  140. }
  141. /// <summary>
  142. /// 获取LessonInfo表实体数据
  143. /// <param name="keyValue">主键</param>
  144. /// <summary>
  145. /// <returns></returns>
  146. public LessonInfoEntity GetLessonInfoEntityByLessonNo(string lessonNo)
  147. {
  148. try
  149. {
  150. return this.BaseRepository("CollegeMIS").FindEntity<LessonInfoEntity>(x => x.LessonNo == lessonNo);
  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. public void Lock(string keyValue)
  167. {
  168. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  169. try
  170. {
  171. //单个启用
  172. //this.BaseRepository("CollegeMIS").ExecuteBySql("update LessonInfo set CheckMark=1 where LessonId='" + keyValue + "'");
  173. //多个启用
  174. var keyValueArr = keyValue.Split(',');
  175. foreach (var item in keyValueArr)
  176. {
  177. db.ExecuteBySql("update LessonInfo set CheckMark=1 where LessonId='" + item + "'");
  178. }
  179. db.Commit();
  180. }
  181. catch (Exception ex)
  182. {
  183. db.Rollback();
  184. if (ex is ExceptionEx)
  185. {
  186. throw;
  187. }
  188. else
  189. {
  190. throw ExceptionEx.ThrowServiceException(ex);
  191. }
  192. }
  193. }
  194. public void UnLock(string keyValue)
  195. {
  196. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  197. try
  198. {
  199. //单个停用
  200. //this.BaseRepository("CollegeMIS").ExecuteBySql("update LessonInfo set CheckMark=0 where LessonId='" + keyValue + "'");
  201. //多个停用
  202. var keyValueArr = keyValue.Split(',');
  203. foreach (var item in keyValueArr)
  204. {
  205. db.ExecuteBySql("update LessonInfo set CheckMark=0 where LessonId='" + item + "'");
  206. }
  207. db.Commit();
  208. }
  209. catch (Exception ex)
  210. {
  211. db.Rollback();
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowServiceException(ex);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 删除实体数据
  224. /// <param name="keyValue">主键</param>
  225. /// <summary>
  226. /// <returns></returns>
  227. public void DeleteEntity(string keyValue)
  228. {
  229. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  230. try
  231. {
  232. //单个删除
  233. //this.BaseRepository("CollegeMIS").Delete<LessonInfoEntity>(t => t.LessonId == keyValue);
  234. //多个删除
  235. var keyValueArr = keyValue.Split(',');
  236. foreach (var item in keyValueArr)
  237. {
  238. db.Delete<LessonInfoEntity>(t => t.LessonId == item);
  239. }
  240. db.Commit();
  241. }
  242. catch (Exception ex)
  243. {
  244. db.Rollback();
  245. if (ex is ExceptionEx)
  246. {
  247. throw;
  248. }
  249. else
  250. {
  251. throw ExceptionEx.ThrowServiceException(ex);
  252. }
  253. }
  254. }
  255. /// <summary>
  256. /// 保存实体数据(新增、修改)
  257. /// <param name="keyValue">主键</param>
  258. /// <summary>
  259. /// <returns></returns>
  260. public void SaveEntity(string keyValue, LessonInfoEntity entity)
  261. {
  262. try
  263. {
  264. if (!string.IsNullOrEmpty(keyValue))
  265. {
  266. entity.Modify(keyValue);
  267. this.BaseRepository("CollegeMIS").Update(entity);
  268. }
  269. else
  270. {
  271. entity.Create();
  272. this.BaseRepository("CollegeMIS").Insert(entity);
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. if (ex is ExceptionEx)
  278. {
  279. throw;
  280. }
  281. else
  282. {
  283. throw ExceptionEx.ThrowServiceException(ex);
  284. }
  285. }
  286. }
  287. public IEnumerable<LessonInfoEntity> GetAllLesson()
  288. {
  289. try
  290. {
  291. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(m => m.CheckMark == true);
  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> GetAllList()
  306. {
  307. try
  308. {
  309. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>();
  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. #endregion
  324. }
  325. }