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.
 
 
 
 
 
 

450 lines
17 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.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. /// 日 期:2023-05-29 14:28
  16. /// 描 述:线上课程
  17. /// </summary>
  18. public class LessonInfoOfElectiveOnlineService : 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<LessonInfoOfElectiveOnlineEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT t.* ");
  33. strSql.Append(" FROM LessonInfoOfElectiveOnline 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["AcademicYearNo"].IsEmpty())
  49. {
  50. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  51. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  52. }
  53. if (!queryParam["Semester"].IsEmpty())
  54. {
  55. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  56. strSql.Append(" AND t.Semester = @Semester ");
  57. }
  58. if (!queryParam["EmpNo"].IsEmpty())
  59. {
  60. dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
  61. strSql.Append(" AND t.EmpNo = @EmpNo ");
  62. }
  63. if (!queryParam["CheckMark"].IsEmpty())
  64. {
  65. dp.Add("CheckMark", queryParam["CheckMark"].ToString(), DbType.String);
  66. strSql.Append(" AND t.CheckMark = @CheckMark ");
  67. }
  68. var list = new List<LessonInfoOfElectiveOnlineEntity>();
  69. list = this.BaseRepository("CollegeMIS").FindList<LessonInfoOfElectiveOnlineEntity>(strSql.ToString(), dp, pagination).ToList();
  70. //选课专业
  71. var majorSql = @"SELECT t.MajorName,t.MajorNo,a.* FROM ElectiveMajorOnline a left join CdMajor t on a.majorid=t.id";
  72. var electiveMajorOnlineList = this.BaseRepository("CollegeMIS").FindList<ElectiveMajorOnlineEntity>(majorSql);
  73. foreach (var item in list)
  74. {
  75. //模式二:正式选课
  76. var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == item.Id);
  77. //已报名人数
  78. item.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
  79. //审核通过人数
  80. item.StuNum = aa.Where(x => x.Status == 2).Count();
  81. //选课专业
  82. item.ElectiveMajorOnlineList = electiveMajorOnlineList.Where(x => x.LIOEOId == item.Id).ToList();
  83. }
  84. return list;
  85. }
  86. catch (Exception ex)
  87. {
  88. if (ex is ExceptionEx)
  89. {
  90. throw;
  91. }
  92. else
  93. {
  94. throw ExceptionEx.ThrowServiceException(ex);
  95. }
  96. }
  97. }
  98. /// <summary>
  99. /// 获取LessonInfoOfElectiveOnline表实体数据
  100. /// </summary>
  101. /// <param name="keyValue">主键</param>
  102. /// <returns></returns>
  103. public LessonInfoOfElectiveOnlineEntity GetLessonInfoOfElectiveOnlineEntity(string keyValue)
  104. {
  105. try
  106. {
  107. var opeentity = BaseRepository("CollegeMIS").FindEntity<LessonInfoOfElectiveOnlineEntity>(keyValue);
  108. if (opeentity != null)
  109. {
  110. //模式二:正式选课
  111. var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == opeentity.Id);
  112. //已报名人数
  113. opeentity.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
  114. }
  115. return opeentity;
  116. }
  117. catch (Exception ex)
  118. {
  119. if (ex is ExceptionEx)
  120. {
  121. throw;
  122. }
  123. else
  124. {
  125. throw ExceptionEx.ThrowServiceException(ex);
  126. }
  127. }
  128. }
  129. /// <summary>
  130. /// 获取LessonInfoOfElectiveOnline表实体数据
  131. /// </summary>
  132. /// <param name="keyValue">主键</param>
  133. /// <returns></returns>
  134. public LessonInfoOfElectiveOnlineEntity GetLessonInfoOfElectiveOnlineEntityByLessonNo(string lessonNo)
  135. {
  136. try
  137. {
  138. return BaseRepository("CollegeMIS").FindEntity<LessonInfoOfElectiveOnlineEntity>(x => x.LessonNo == lessonNo);
  139. }
  140. catch (Exception ex)
  141. {
  142. if (ex is ExceptionEx)
  143. {
  144. throw;
  145. }
  146. else
  147. {
  148. throw ExceptionEx.ThrowServiceException(ex);
  149. }
  150. }
  151. }
  152. /// <summary>
  153. /// 获取页面显示列表数据【学子在线-线上课程选课】
  154. /// <summary>
  155. /// <param name="queryJson">查询参数</param>
  156. /// <returns></returns>
  157. public IEnumerable<LessonInfoOfElectiveOnlineEntity> GetPageListOfStudent(Pagination pagination, string queryJson)
  158. {
  159. try
  160. {
  161. var queryParam = queryJson.ToJObject();
  162. // 虚拟参数
  163. var dp = new DynamicParameters(new { });
  164. //学号
  165. if (!queryParam["StuNo"].IsEmpty())
  166. {
  167. dp.Add("StuNo", queryParam["StuNo"].ToString(), DbType.String);
  168. }
  169. //教学工作安排中“线上选课”工作设置的学年学期
  170. var now = DateTime.Now;
  171. var EADateArrangeEntityAboutElective = this.BaseRepository("CollegeMIS").FindEntity<EADateArrangeEntity>(x => x.WorkName == "线上选课" && x.MakeDate <= now && x.EndDate >= now && x.CheckMark == "1");
  172. if (EADateArrangeEntityAboutElective == null)
  173. {
  174. return new List<LessonInfoOfElectiveOnlineEntity>();
  175. }
  176. var strSql = new StringBuilder();
  177. strSql.Append(@"select b.*,c.StuNo,c.StuName,c.Status from ElectiveMajorOnline a
  178. left join LessonInfoOfElectiveOnline b on a.LIOEOId=b.Id
  179. left join StuSelectLessonListOfElectiveOnline c on b.Id=c.LIOEOId and c.StuNo=@StuNo
  180. where not exists ( ");
  181. //不显示与已选课程 相同课程名称相同教师的课程
  182. strSql.Append(" select * from StuSelectLessonListOfElectiveOnline s where s.AcademicYearNo='" + EADateArrangeEntityAboutElective?.AcademicYearNo + "' and s.Semester='" + EADateArrangeEntityAboutElective.Semester + "' and s.StuNo=@StuNo and s.Status <>3 and s.LessonName=b.LessonName and s.EmpNo=b.EmpNo and s.LIOEOId!=b.Id ");
  183. strSql.Append(" ) ");
  184. //管理选课专业不为空
  185. strSql.Append(" and a.MajorId is not null and a.Grade is not null ");
  186. strSql.Append(" AND b.CheckMark='1' ");
  187. strSql.Append(" AND b.AcademicYearNo='" + EADateArrangeEntityAboutElective?.AcademicYearNo + "' and b.Semester='" + EADateArrangeEntityAboutElective?.Semester + "' ");
  188. //学生选课显示‘是否可选’为‘是’的课程信息
  189. strSql.Append(" and b.IsAllowSelect=1 ");
  190. if (!queryParam["StuMajorNo"].IsEmpty())
  191. {
  192. dp.Add("StuMajorNo", queryParam["StuMajorNo"].ToString(), DbType.String);
  193. strSql.Append(" and a.MajorId=@StuMajorNo ");
  194. }
  195. else
  196. {
  197. strSql.Append(" and a.MajorId='' ");
  198. }
  199. if (!queryParam["StuGrade"].IsEmpty())
  200. {
  201. dp.Add("StuGrade", queryParam["StuGrade"].ToString(), DbType.String);
  202. strSql.Append(" and a.Grade=@StuGrade ");
  203. }
  204. else
  205. {
  206. strSql.Append(" and a.Grade='' ");
  207. }
  208. if (!queryParam["LessonNo"].IsEmpty())
  209. {
  210. dp.Add("LessonNo", "%" + queryParam["LessonNo"].ToString() + "%", DbType.String);
  211. strSql.Append(" AND b.LessonNo like @LessonNo ");
  212. }
  213. if (!queryParam["LessonName"].IsEmpty())
  214. {
  215. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  216. strSql.Append(" AND b.LessonName Like @LessonName ");
  217. }
  218. var list = this.BaseRepository("CollegeMIS").FindList<LessonInfoOfElectiveOnlineEntity>(strSql.ToString(), dp, pagination);
  219. foreach (var item in list)
  220. {
  221. //模式二:正式选课
  222. var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == item.Id);
  223. //已报名人数
  224. item.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
  225. }
  226. return list;
  227. }
  228. catch (Exception ex)
  229. {
  230. if (ex is ExceptionEx)
  231. {
  232. throw;
  233. }
  234. else
  235. {
  236. throw ExceptionEx.ThrowServiceException(ex);
  237. }
  238. }
  239. }
  240. #endregion
  241. #region 提交数据
  242. /// <summary>
  243. /// 删除实体数据
  244. /// </summary>
  245. /// <param name="keyValue">主键</param>
  246. public void DeleteEntity(string keyValue)
  247. {
  248. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  249. try
  250. {
  251. //单个删除
  252. //this.BaseRepository("CollegeMIS").Delete<LessonInfoOfElectiveOnlineEntity>(t => t.Id == keyValue);
  253. //批量删除
  254. foreach (var item in keyValue.Split(','))
  255. {
  256. //删除选课专业
  257. db.ExecuteBySql($"delete from ElectiveMajorOnline where LIOEOId='{item}'");
  258. //删除选修课课程表
  259. db.ExecuteBySql($"delete from LessonInfoOfElectiveOnline where Id='{item}'");
  260. }
  261. db.Commit();
  262. }
  263. catch (Exception ex)
  264. {
  265. db.Rollback();
  266. if (ex is ExceptionEx)
  267. {
  268. throw;
  269. }
  270. else
  271. {
  272. throw ExceptionEx.ThrowServiceException(ex);
  273. }
  274. }
  275. }
  276. /// <summary>
  277. /// 保存实体数据(新增、修改)
  278. /// </summary>
  279. /// <param name="keyValue">主键</param>
  280. /// <param name="entity">实体</param>
  281. public void SaveEntity(string keyValue, LessonInfoOfElectiveOnlineEntity entity)
  282. {
  283. try
  284. {
  285. if (!string.IsNullOrEmpty(keyValue))
  286. {
  287. entity.Modify(keyValue);
  288. this.BaseRepository("CollegeMIS").Update(entity);
  289. }
  290. else
  291. {
  292. entity.Create();
  293. this.BaseRepository("CollegeMIS").Insert(entity);
  294. }
  295. }
  296. catch (Exception ex)
  297. {
  298. if (ex is ExceptionEx)
  299. {
  300. throw;
  301. }
  302. else
  303. {
  304. throw ExceptionEx.ThrowServiceException(ex);
  305. }
  306. }
  307. }
  308. #endregion
  309. #region 扩展数据
  310. /// <summary>
  311. /// 启用/停用实体数据
  312. /// </summary>
  313. /// <param name="keyValue">主键</param>
  314. public void DoLock(string keyValue, string status)
  315. {
  316. try
  317. {
  318. //单个启用
  319. //this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id='{keyValue}' ");
  320. if (keyValue.Contains(","))
  321. {
  322. keyValue = string.Join("','", keyValue.Split(','));
  323. }
  324. string sql = $"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id in ('{keyValue}')";
  325. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  326. }
  327. catch (Exception ex)
  328. {
  329. if (ex is ExceptionEx)
  330. {
  331. throw;
  332. }
  333. else
  334. {
  335. throw ExceptionEx.ThrowServiceException(ex);
  336. }
  337. }
  338. }
  339. /// <summary>
  340. /// 设置可选/取消可选
  341. /// </summary>
  342. /// <param name="keyValue"></param>
  343. /// <param name="IsAllowSelect"></param>
  344. public void SetUpIsAllowSelect(string keyValue, int IsAllowSelect)
  345. {
  346. try
  347. {
  348. if (keyValue.Contains(","))
  349. {
  350. keyValue = string.Join("','", keyValue.Split(','));
  351. }
  352. string sql = $"update LessonInfoOfElectiveOnline set IsAllowSelect='{IsAllowSelect}' where Id in ('{keyValue}')";
  353. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  354. }
  355. catch (Exception ex)
  356. {
  357. if (ex is ExceptionEx)
  358. {
  359. throw;
  360. }
  361. else
  362. {
  363. throw ExceptionEx.ThrowServiceException(ex);
  364. }
  365. }
  366. }
  367. /// <summary>
  368. /// 批量设置人数
  369. /// </summary>
  370. /// <param name="keyValue"></param>
  371. /// <param name="StuNumMax"></param>
  372. public void SaveStuNumMax(string keyValue, int StuNumMax)
  373. {
  374. try
  375. {
  376. if (keyValue.Contains(","))
  377. {
  378. keyValue = string.Join("','", keyValue.Split(','));
  379. }
  380. this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set StuNumMax='{StuNumMax}' where Id in ('{keyValue}')");
  381. }
  382. catch (Exception ex)
  383. {
  384. if (ex is ExceptionEx)
  385. {
  386. throw;
  387. }
  388. else
  389. {
  390. throw ExceptionEx.ThrowServiceException(ex);
  391. }
  392. }
  393. }
  394. /// <summary>
  395. /// 获取选课时间管理
  396. /// </summary>
  397. /// <returns></returns>
  398. public EADateArrangeEntity GetEADateArrangeEntityAboutElective()
  399. {
  400. try
  401. {
  402. var semesterAndYear = Common.GetSemesterAndYear();
  403. var strAcademicYear = semesterAndYear.AcademicYearShort;
  404. var strSemester = semesterAndYear.Semester;
  405. var now = DateTime.Now;
  406. //不判断学年学期
  407. return this.BaseRepository("CollegeMIS").FindEntity<EADateArrangeEntity>(x => x.WorkName == "线上选课" && x.MakeDate <= now && x.EndDate >= now && x.CheckMark == "1");
  408. }
  409. catch (Exception ex)
  410. {
  411. if (ex is ExceptionEx)
  412. {
  413. throw;
  414. }
  415. else
  416. {
  417. throw ExceptionEx.ThrowServiceException(ex);
  418. }
  419. }
  420. }
  421. #endregion
  422. }
  423. }