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.
 
 
 
 
 
 

364 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.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. strSql.Append(" FROM LessonInfo t ");
  34. strSql.Append(" WHERE 1=1 ");
  35. var queryParam = queryJson.ToJObject();
  36. // 虚拟参数
  37. var dp = new DynamicParameters(new { });
  38. if (!queryParam["LessonNo"].IsEmpty())
  39. {
  40. dp.Add("LessonNo", "%" + queryParam["LessonNo"].ToString() + "%", DbType.String);
  41. strSql.Append(" AND t.LessonNo Like @LessonNo ");
  42. }
  43. if (!queryParam["LessonName"].IsEmpty())
  44. {
  45. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  46. strSql.Append(" AND t.LessonName Like @LessonName ");
  47. }
  48. if (!queryParam["TeachDeptNo"].IsEmpty())
  49. {
  50. dp.Add("TeachDeptNo", queryParam["TeachDeptNo"].ToString(), DbType.String);
  51. strSql.Append(" AND t.TeachDeptNo = @TeachDeptNo ");
  52. }
  53. if (!queryParam["TeachMajorNo"].IsEmpty())
  54. {
  55. dp.Add("TeachMajorNo", queryParam["TeachMajorNo"].ToString(), DbType.String);
  56. strSql.Append(" AND t.TeachMajorNo = @TeachMajorNo ");
  57. }
  58. if (!queryParam["F_SchoolId"].IsEmpty())
  59. {
  60. dp.Add("F_SchoolId", queryParam["F_SchoolId"].ToString(), DbType.String);
  61. strSql.Append(" AND t.F_SchoolId = @F_SchoolId ");
  62. }
  63. if (!queryParam["LessonTypeId"].IsEmpty())
  64. {
  65. dp.Add("LessonTypeId", queryParam["LessonTypeId"].ToString(), DbType.String);
  66. strSql.Append(" AND t.LessonTypeId = @LessonTypeId ");
  67. }
  68. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(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. public IEnumerable<LessonInfoEntity> GetLessonByMajorNo(string majorNo)
  83. {
  84. try
  85. {
  86. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(x => x.TeachMajorNo == majorNo);
  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. /// <summary>
  165. /// 获取LessonInfo表实体数据和课程类型
  166. /// <param name="keyValue">主键</param>
  167. /// <summary>
  168. /// <returns></returns>
  169. public LessonInfoEntity GetLessonInfoAndTypeByLessonNo(string lessonNo)
  170. {
  171. try
  172. {
  173. string sql = $"select a.*,b.LessonTypeCode from LessonInfo a join CdLessonType b on a.LessonTypeId=b.LTId where a.LessonNo='{lessonNo}'";
  174. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(sql).FirstOrDefault();
  175. }
  176. catch (Exception ex)
  177. {
  178. if (ex is ExceptionEx)
  179. {
  180. throw;
  181. }
  182. else
  183. {
  184. throw ExceptionEx.ThrowServiceException(ex);
  185. }
  186. }
  187. }
  188. #endregion
  189. #region 提交数据
  190. public void Lock(string keyValue)
  191. {
  192. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  193. try
  194. {
  195. //单个启用
  196. //this.BaseRepository("CollegeMIS").ExecuteBySql("update LessonInfo set CheckMark=1 where LessonId='" + keyValue + "'");
  197. //多个启用
  198. var keyValueArr = keyValue.Split(',');
  199. foreach (var item in keyValueArr)
  200. {
  201. db.ExecuteBySql("update LessonInfo set CheckMark=1 where LessonId='" + item + "'");
  202. }
  203. db.Commit();
  204. }
  205. catch (Exception ex)
  206. {
  207. db.Rollback();
  208. if (ex is ExceptionEx)
  209. {
  210. throw;
  211. }
  212. else
  213. {
  214. throw ExceptionEx.ThrowServiceException(ex);
  215. }
  216. }
  217. }
  218. public void UnLock(string keyValue)
  219. {
  220. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  221. try
  222. {
  223. //单个停用
  224. //this.BaseRepository("CollegeMIS").ExecuteBySql("update LessonInfo set CheckMark=0 where LessonId='" + keyValue + "'");
  225. //多个停用
  226. var keyValueArr = keyValue.Split(',');
  227. foreach (var item in keyValueArr)
  228. {
  229. db.ExecuteBySql("update LessonInfo set CheckMark=0 where LessonId='" + item + "'");
  230. }
  231. db.Commit();
  232. }
  233. catch (Exception ex)
  234. {
  235. db.Rollback();
  236. if (ex is ExceptionEx)
  237. {
  238. throw;
  239. }
  240. else
  241. {
  242. throw ExceptionEx.ThrowServiceException(ex);
  243. }
  244. }
  245. }
  246. /// <summary>
  247. /// 删除实体数据
  248. /// <param name="keyValue">主键</param>
  249. /// <summary>
  250. /// <returns></returns>
  251. public void DeleteEntity(string keyValue)
  252. {
  253. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  254. try
  255. {
  256. //单个删除
  257. //this.BaseRepository("CollegeMIS").Delete<LessonInfoEntity>(t => t.LessonId == keyValue);
  258. //多个删除
  259. var keyValueArr = keyValue.Split(',');
  260. foreach (var item in keyValueArr)
  261. {
  262. db.Delete<LessonInfoEntity>(t => t.LessonId == item);
  263. }
  264. db.Commit();
  265. }
  266. catch (Exception ex)
  267. {
  268. db.Rollback();
  269. if (ex is ExceptionEx)
  270. {
  271. throw;
  272. }
  273. else
  274. {
  275. throw ExceptionEx.ThrowServiceException(ex);
  276. }
  277. }
  278. }
  279. /// <summary>
  280. /// 保存实体数据(新增、修改)
  281. /// <param name="keyValue">主键</param>
  282. /// <summary>
  283. /// <returns></returns>
  284. public void SaveEntity(string keyValue, LessonInfoEntity entity)
  285. {
  286. try
  287. {
  288. if (!string.IsNullOrEmpty(keyValue))
  289. {
  290. entity.Modify(keyValue);
  291. this.BaseRepository("CollegeMIS").Update(entity);
  292. }
  293. else
  294. {
  295. entity.Create();
  296. this.BaseRepository("CollegeMIS").Insert(entity);
  297. }
  298. }
  299. catch (Exception ex)
  300. {
  301. if (ex is ExceptionEx)
  302. {
  303. throw;
  304. }
  305. else
  306. {
  307. throw ExceptionEx.ThrowServiceException(ex);
  308. }
  309. }
  310. }
  311. public IEnumerable<LessonInfoEntity> GetAllLesson()
  312. {
  313. try
  314. {
  315. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>(m => m.CheckMark == true);
  316. }
  317. catch (Exception ex)
  318. {
  319. if (ex is ExceptionEx)
  320. {
  321. throw;
  322. }
  323. else
  324. {
  325. throw ExceptionEx.ThrowServiceException(ex);
  326. }
  327. }
  328. }
  329. public IEnumerable<LessonInfoEntity> GetAllList()
  330. {
  331. try
  332. {
  333. return this.BaseRepository("CollegeMIS").FindList<LessonInfoEntity>();
  334. }
  335. catch (Exception ex)
  336. {
  337. if (ex is ExceptionEx)
  338. {
  339. throw;
  340. }
  341. else
  342. {
  343. throw ExceptionEx.ThrowServiceException(ex);
  344. }
  345. }
  346. }
  347. #endregion
  348. }
  349. }