Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

379 linhas
12 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-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. var strSql = "";
  286. if (entity.WeekPracticeHour.ToString() == "")
  287. {
  288. strSql += " update LessonInfo set WeekPracticeHour = null where LessonId ='" + keyValue + "' ;";
  289. }
  290. if (entity.TotalStudyHour.ToString() == "")
  291. {
  292. strSql += " update LessonInfo set TotalStudyHour = null where LessonId ='" + keyValue + "' ;";
  293. }
  294. if (entity.StudyScore.ToString() == "")
  295. {
  296. strSql += " update LessonInfo set StudyScore = null where LessonId ='" + keyValue + "' ;";
  297. }
  298. if (entity.WeekStudyHour.ToString() == "")
  299. {
  300. strSql += " update LessonInfo set WeekStudyHour = null where LessonId ='" + keyValue + "' ;";
  301. }
  302. this.BaseRepository("CollegeMIS").Update(entity);
  303. if (!string.IsNullOrEmpty(strSql))
  304. {
  305. BaseRepository("CollegeMIS").ExecuteBySql(strSql);
  306. }
  307. }
  308. else
  309. {
  310. entity.Create();
  311. this.BaseRepository("CollegeMIS").Insert(entity);
  312. }
  313. }
  314. catch (Exception ex)
  315. {
  316. if (ex is ExceptionEx)
  317. {
  318. throw;
  319. }
  320. else
  321. {
  322. throw ExceptionEx.ThrowServiceException(ex);
  323. }
  324. }
  325. }
  326. public IEnumerable<LessonInfoEntity> GetAllLesson()
  327. {
  328. try
  329. {
  330. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(m => m.CheckMark == true);
  331. }
  332. catch (Exception ex)
  333. {
  334. if (ex is ExceptionEx)
  335. {
  336. throw;
  337. }
  338. else
  339. {
  340. throw ExceptionEx.ThrowServiceException(ex);
  341. }
  342. }
  343. }
  344. public IEnumerable<LessonInfoEntity> GetAllList()
  345. {
  346. try
  347. {
  348. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>();
  349. }
  350. catch (Exception ex)
  351. {
  352. if (ex is ExceptionEx)
  353. {
  354. throw;
  355. }
  356. else
  357. {
  358. throw ExceptionEx.ThrowServiceException(ex);
  359. }
  360. }
  361. }
  362. #endregion
  363. }
  364. }