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.

ClassPlanService.cs 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2021-11-29 11:43
  16. /// 描 述:开课计划
  17. /// </summary>
  18. public class ClassPlanService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// </summary>
  24. /// <param name="pagination">查询参数</param>
  25. /// <param name="queryJson">查询参数</param>
  26. /// <returns></returns>
  27. public IEnumerable<OpenLessonPlanEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT ");
  33. strSql.Append(@" * ");
  34. strSql.Append(" FROM OpenLessonPlan t ");
  35. strSql.Append(" WHERE 1=1 ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. if (!queryParam["F_SchoolId"].IsEmpty())
  40. {
  41. dp.Add("F_SchoolId", queryParam["F_SchoolId"].ToString(), DbType.String);
  42. strSql.Append(" AND t.F_SchoolId = @F_SchoolId ");
  43. }
  44. if (!queryParam["AcademicYearNo"].IsEmpty())
  45. {
  46. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  47. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  48. }
  49. if (!queryParam["Semester"].IsEmpty())
  50. {
  51. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  52. strSql.Append(" AND t.Semester = @Semester ");
  53. }
  54. if (!queryParam["DeptNo"].IsEmpty())
  55. {
  56. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  57. strSql.Append(" AND t.DeptNo = @DeptNo ");
  58. }
  59. if (!queryParam["MajorNo"].IsEmpty())
  60. {
  61. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  62. strSql.Append(" AND t.MajorNo = @MajorNo ");
  63. }
  64. if (!queryParam["Grade"].IsEmpty())
  65. {
  66. dp.Add("Grade", "%" + queryParam["Grade"].ToString() + "%", DbType.String);
  67. strSql.Append(" AND t.Grade Like @Grade ");
  68. }
  69. if (!queryParam["LessonNo"].IsEmpty())
  70. {
  71. dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
  72. strSql.Append(" AND t.LessonNo = @LessonNo ");
  73. }
  74. return this.BaseRepository("CollegeMIS").FindList<OpenLessonPlanEntity>(strSql.ToString(), dp, pagination);
  75. }
  76. catch (Exception ex)
  77. {
  78. if (ex is ExceptionEx)
  79. {
  80. throw;
  81. }
  82. else
  83. {
  84. throw ExceptionEx.ThrowServiceException(ex);
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 获取OpenLessonPlan表实体数据
  90. /// </summary>
  91. /// <param name="keyValue">主键</param>
  92. /// <returns></returns>
  93. public OpenLessonPlanEntity GetClassPlanEntity(string keyValue)
  94. {
  95. try
  96. {
  97. return this.BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanEntity>(keyValue.ToInt());
  98. }
  99. catch (Exception ex)
  100. {
  101. if (ex is ExceptionEx)
  102. {
  103. throw;
  104. }
  105. else
  106. {
  107. throw ExceptionEx.ThrowServiceException(ex);
  108. }
  109. }
  110. }
  111. #endregion
  112. #region 提交数据
  113. /// <summary>
  114. /// 删除实体数据
  115. /// </summary>
  116. /// <param name="keyValue">主键</param>
  117. public void DeleteEntity(string keyValue)
  118. {
  119. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  120. try
  121. {
  122. var keyvalue = keyValue.Split(',');
  123. foreach (var items in keyvalue)
  124. {
  125. var OpList = this.BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanEntity>(t => t.ID.ToString() == items);
  126. if (OpList != null)
  127. {
  128. var TeachList = this.BaseRepository("CollegeMIS").FindList<TeachClassEntity>(
  129. x => x.DeptNo == OpList.DeptNo &&
  130. x.MajorNo == OpList.MajorNo &&
  131. x.Grade == OpList.Grade &&
  132. x.Semester == OpList.Semester &&
  133. x.LessonNo == OpList.LessonNo &&
  134. x.AcademicYearNo == OpList.AcademicYearNo
  135. ).ToList();
  136. List<string> StrTeach = null;
  137. if (TeachList.Count > 0)
  138. {
  139. StrTeach = TeachList.Select(x => x.TeachClassNo).ToList();
  140. if (StrTeach.Count() > 0)
  141. {
  142. var LessonList = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListEntity>(
  143. y => y.DeptNo == OpList.DeptNo &&
  144. y.MajorNo == OpList.MajorNo &&
  145. y.Grade == OpList.Grade &&
  146. y.Semester == OpList.Semester &&
  147. y.LessonNo == OpList.LessonNo &&
  148. y.AcademicYearNo == OpList.AcademicYearNo &&
  149. StrTeach.Contains(y.ClassNo)
  150. );
  151. foreach (var item in LessonList)
  152. {
  153. db.Delete<StuSelectLessonListEntity>(m => m.SelectId == Convert.ToInt32(item.SelectId));
  154. }
  155. foreach (var item in TeachList)
  156. {
  157. db.Delete<TeachClassEntity>(m => m.ID == item.ID);
  158. }
  159. }
  160. }
  161. }
  162. db.Delete<OpenLessonPlanEntity>(m => m.ID.ToString() == items);
  163. }
  164. db.Commit();
  165. }
  166. catch (Exception ex)
  167. {
  168. db.Rollback();
  169. if (ex is ExceptionEx)
  170. {
  171. throw;
  172. }
  173. else
  174. {
  175. throw ExceptionEx.ThrowServiceException(ex);
  176. }
  177. }
  178. }
  179. /// <summary>
  180. /// 保存实体数据(新增、修改)
  181. /// </summary>
  182. /// <param name="keyValue">主键</param>
  183. /// <param name="entity">实体</param>
  184. public void SaveEntity(string keyValue, OpenLessonPlanEntity entity)
  185. {
  186. try
  187. {
  188. if (!string.IsNullOrEmpty(keyValue))
  189. {
  190. entity.Modify(keyValue);
  191. this.BaseRepository("CollegeMIS").Update(entity);
  192. }
  193. else
  194. {
  195. entity.Create();
  196. this.BaseRepository("CollegeMIS").Insert(entity);
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. if (ex is ExceptionEx)
  202. {
  203. throw;
  204. }
  205. else
  206. {
  207. throw ExceptionEx.ThrowServiceException(ex);
  208. }
  209. }
  210. }
  211. #endregion
  212. #region 扩展数据
  213. /// <summary>
  214. /// 去重
  215. /// </summary>
  216. /// <param name="ID">主键</param>
  217. /// <param name="School">校区</param>
  218. /// <param name="Year">学年</param>
  219. /// <param name="Semester">学期</param>
  220. /// <param name="Dept">系部</param>
  221. /// <param name="Major">专业</param>
  222. /// <param name="Grade">年级</param>
  223. /// <param name="Lesson">课程</param>
  224. /// <returns></returns>
  225. public OpenLessonPlanEntity GetRepetitions(string School, string Year, string Semester, string Dept,
  226. string Major, string Grade, string Lesson)
  227. {
  228. try
  229. {
  230. return this.BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanEntity>(
  231. x => x.F_SchoolId == School
  232. && x.AcademicYearNo == Year
  233. && x.Semester == Semester
  234. && x.DeptNo == Dept
  235. && x.MajorNo == Major
  236. && x.Grade == Grade
  237. && x.LessonNo == Lesson
  238. );
  239. }
  240. catch (Exception e)
  241. {
  242. Console.WriteLine(e);
  243. throw;
  244. }
  245. }
  246. public void DelRelation(string keyValue)
  247. {
  248. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  249. try
  250. {
  251. var keyvalue = Convert.ToInt32(keyValue);
  252. var OpList = this.BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanEntity>(t => t.ID == keyvalue);
  253. if (OpList != null)
  254. {
  255. var TeachList = this.BaseRepository("CollegeMIS").FindList<TeachClassEntity>(
  256. x => x.DeptNo == OpList.DeptNo &&
  257. x.MajorNo == OpList.MajorNo &&
  258. x.Grade == OpList.Grade &&
  259. x.Semester == OpList.Semester &&
  260. x.LessonNo == OpList.LessonNo &&
  261. x.AcademicYearNo == OpList.AcademicYearNo
  262. ).ToList();
  263. List<string> StrTeach = null;
  264. if (TeachList.Count > 0)
  265. {
  266. StrTeach = TeachList.Select(x => x.TeachClassNo).ToList();
  267. if (StrTeach.Count > 0)
  268. {
  269. var LessonList = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListEntity>(
  270. y => y.DeptNo == OpList.DeptNo &&
  271. y.MajorNo == OpList.MajorNo &&
  272. y.Grade == OpList.Grade &&
  273. y.Semester == OpList.Semester &&
  274. y.LessonNo == OpList.LessonNo &&
  275. y.AcademicYearNo == OpList.AcademicYearNo &&
  276. StrTeach.Contains(y.ClassNo)
  277. );
  278. foreach (var item in LessonList)
  279. {
  280. db.Delete<StuSelectLessonListEntity>(m => m.SelectId == Convert.ToInt32(item.SelectId));
  281. }
  282. foreach (var item in TeachList)
  283. {
  284. db.Delete<TeachClassEntity>(m => m.ID == item.ID);
  285. }
  286. }
  287. }
  288. }
  289. db.Commit();
  290. }
  291. catch (Exception ex)
  292. {
  293. db.Rollback();
  294. if (ex is ExceptionEx)
  295. {
  296. throw;
  297. }
  298. else
  299. {
  300. throw ExceptionEx.ThrowServiceException(ex);
  301. }
  302. }
  303. }
  304. /// <summary>
  305. /// 获取OpenLessonPlan表实体数据
  306. /// <param name="keyValue">主键</param>
  307. /// <summary>
  308. /// <returns></returns>
  309. public List<OpenLessonPlanEntity> GetListById(string keyValue)
  310. {
  311. try
  312. {
  313. var id = keyValue.Split(',');
  314. return this.BaseRepository("CollegeMIS")
  315. .FindList<OpenLessonPlanEntity>(x => id.Contains(x.ID.ToString())).ToList();
  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 void SaveEntityList(string keyValue, List<OpenLessonPlanEntity> entity)
  330. {
  331. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  332. try
  333. {
  334. var keyvalue = keyValue.Split(',');
  335. foreach (var item in keyvalue)
  336. {
  337. var entityList = this.BaseRepository("CollegeMIS").FindEntity<OpenLessonPlanEntity>(x => x.ID.ToString() == item);
  338. entityList.State = 1;
  339. db.Update(entityList);
  340. }
  341. db.Commit();
  342. }
  343. catch (Exception ex)
  344. {
  345. db.Rollback();
  346. if (ex is ExceptionEx)
  347. {
  348. throw;
  349. }
  350. else
  351. {
  352. throw ExceptionEx.ThrowServiceException(ex);
  353. }
  354. }
  355. }
  356. #endregion
  357. }
  358. }