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.
 
 
 
 
 
 

449 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,a.Id as ElectiveMajorOnlineId,a.MajorId,a.Grade from LessonInfoOfElectiveOnline b
  178. left join StuSelectLessonListOfElectiveOnline c on b.Id=c.LIOEOId and c.StuNo=@StuNo
  179. left join ElectiveMajorOnline a on a.LIOEOId=b.Id
  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. strSql.Append(" AND b.CheckMark='1' ");
  185. strSql.Append(" AND b.AcademicYearNo='" + EADateArrangeEntityAboutElective?.AcademicYearNo + "' and b.Semester='" + EADateArrangeEntityAboutElective?.Semester + "' ");
  186. //学生选课显示‘是否可选’为‘是’的课程信息
  187. strSql.Append(" and b.IsAllowSelect=1 ");
  188. //管理选课专业可以为空
  189. if (!queryParam["StuMajorNo"].IsEmpty())
  190. {
  191. dp.Add("StuMajorNo", queryParam["StuMajorNo"].ToString(), DbType.String);
  192. strSql.Append(" and (a.MajorId is null or a.MajorId = @StuMajorNo ) ");
  193. }
  194. else
  195. {
  196. strSql.Append(" and a.MajorId is null ");
  197. }
  198. if (!queryParam["StuGrade"].IsEmpty())
  199. {
  200. dp.Add("StuGrade", queryParam["StuGrade"].ToString(), DbType.String);
  201. strSql.Append(" and (a.Grade is null or a.Grade = @StuGrade) ");
  202. }
  203. else
  204. {
  205. strSql.Append(" and a.Grade is null ");
  206. }
  207. if (!queryParam["LessonNo"].IsEmpty())
  208. {
  209. dp.Add("LessonNo", "%" + queryParam["LessonNo"].ToString() + "%", DbType.String);
  210. strSql.Append(" AND b.LessonNo like @LessonNo ");
  211. }
  212. if (!queryParam["LessonName"].IsEmpty())
  213. {
  214. dp.Add("LessonName", "%" + queryParam["LessonName"].ToString() + "%", DbType.String);
  215. strSql.Append(" AND b.LessonName Like @LessonName ");
  216. }
  217. var list = this.BaseRepository("CollegeMIS").FindList<LessonInfoOfElectiveOnlineEntity>(strSql.ToString(), dp, pagination);
  218. foreach (var item in list)
  219. {
  220. //模式二:正式选课
  221. var aa = this.BaseRepository("CollegeMIS").FindList<StuSelectLessonListOfElectiveOnlineEntity>(x => x.LIOEOId == item.Id);
  222. //已报名人数
  223. item.StuNumOfApply = aa.Where(x => (x.Status == 1 || x.Status == 2)).Count();
  224. }
  225. return list;
  226. }
  227. catch (Exception ex)
  228. {
  229. if (ex is ExceptionEx)
  230. {
  231. throw;
  232. }
  233. else
  234. {
  235. throw ExceptionEx.ThrowServiceException(ex);
  236. }
  237. }
  238. }
  239. #endregion
  240. #region 提交数据
  241. /// <summary>
  242. /// 删除实体数据
  243. /// </summary>
  244. /// <param name="keyValue">主键</param>
  245. public void DeleteEntity(string keyValue)
  246. {
  247. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  248. try
  249. {
  250. //单个删除
  251. //this.BaseRepository("CollegeMIS").Delete<LessonInfoOfElectiveOnlineEntity>(t => t.Id == keyValue);
  252. //批量删除
  253. foreach (var item in keyValue.Split(','))
  254. {
  255. //删除选课专业
  256. db.ExecuteBySql($"delete from ElectiveMajorOnline where LIOEOId='{item}'");
  257. //删除选修课课程表
  258. db.ExecuteBySql($"delete from LessonInfoOfElectiveOnline where Id='{item}'");
  259. }
  260. db.Commit();
  261. }
  262. catch (Exception ex)
  263. {
  264. db.Rollback();
  265. if (ex is ExceptionEx)
  266. {
  267. throw;
  268. }
  269. else
  270. {
  271. throw ExceptionEx.ThrowServiceException(ex);
  272. }
  273. }
  274. }
  275. /// <summary>
  276. /// 保存实体数据(新增、修改)
  277. /// </summary>
  278. /// <param name="keyValue">主键</param>
  279. /// <param name="entity">实体</param>
  280. public void SaveEntity(string keyValue, LessonInfoOfElectiveOnlineEntity entity)
  281. {
  282. try
  283. {
  284. if (!string.IsNullOrEmpty(keyValue))
  285. {
  286. entity.Modify(keyValue);
  287. this.BaseRepository("CollegeMIS").Update(entity);
  288. }
  289. else
  290. {
  291. entity.Create();
  292. this.BaseRepository("CollegeMIS").Insert(entity);
  293. }
  294. }
  295. catch (Exception ex)
  296. {
  297. if (ex is ExceptionEx)
  298. {
  299. throw;
  300. }
  301. else
  302. {
  303. throw ExceptionEx.ThrowServiceException(ex);
  304. }
  305. }
  306. }
  307. #endregion
  308. #region 扩展数据
  309. /// <summary>
  310. /// 启用/停用实体数据
  311. /// </summary>
  312. /// <param name="keyValue">主键</param>
  313. public void DoLock(string keyValue, string status)
  314. {
  315. try
  316. {
  317. //单个启用
  318. //this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id='{keyValue}' ");
  319. if (keyValue.Contains(","))
  320. {
  321. keyValue = string.Join("','", keyValue.Split(','));
  322. }
  323. string sql = $"update LessonInfoOfElectiveOnline set CheckMark='{status}' where Id in ('{keyValue}')";
  324. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  325. }
  326. catch (Exception ex)
  327. {
  328. if (ex is ExceptionEx)
  329. {
  330. throw;
  331. }
  332. else
  333. {
  334. throw ExceptionEx.ThrowServiceException(ex);
  335. }
  336. }
  337. }
  338. /// <summary>
  339. /// 设置可选/取消可选
  340. /// </summary>
  341. /// <param name="keyValue"></param>
  342. /// <param name="IsAllowSelect"></param>
  343. public void SetUpIsAllowSelect(string keyValue, int IsAllowSelect)
  344. {
  345. try
  346. {
  347. if (keyValue.Contains(","))
  348. {
  349. keyValue = string.Join("','", keyValue.Split(','));
  350. }
  351. string sql = $"update LessonInfoOfElectiveOnline set IsAllowSelect='{IsAllowSelect}' where Id in ('{keyValue}')";
  352. this.BaseRepository("CollegeMIS").ExecuteBySql(sql);
  353. }
  354. catch (Exception ex)
  355. {
  356. if (ex is ExceptionEx)
  357. {
  358. throw;
  359. }
  360. else
  361. {
  362. throw ExceptionEx.ThrowServiceException(ex);
  363. }
  364. }
  365. }
  366. /// <summary>
  367. /// 批量设置人数
  368. /// </summary>
  369. /// <param name="keyValue"></param>
  370. /// <param name="StuNumMax"></param>
  371. public void SaveStuNumMax(string keyValue, int StuNumMax)
  372. {
  373. try
  374. {
  375. if (keyValue.Contains(","))
  376. {
  377. keyValue = string.Join("','", keyValue.Split(','));
  378. }
  379. this.BaseRepository("CollegeMIS").ExecuteBySql($"update LessonInfoOfElectiveOnline set StuNumMax='{StuNumMax}' where Id in ('{keyValue}')");
  380. }
  381. catch (Exception ex)
  382. {
  383. if (ex is ExceptionEx)
  384. {
  385. throw;
  386. }
  387. else
  388. {
  389. throw ExceptionEx.ThrowServiceException(ex);
  390. }
  391. }
  392. }
  393. /// <summary>
  394. /// 获取选课时间管理
  395. /// </summary>
  396. /// <returns></returns>
  397. public EADateArrangeEntity GetEADateArrangeEntityAboutElective()
  398. {
  399. try
  400. {
  401. var semesterAndYear = Common.GetSemesterAndYear();
  402. var strAcademicYear = semesterAndYear.AcademicYearShort;
  403. var strSemester = semesterAndYear.Semester;
  404. var now = DateTime.Now;
  405. //不判断学年学期
  406. return this.BaseRepository("CollegeMIS").FindEntity<EADateArrangeEntity>(x => x.WorkName == "线上选课" && x.MakeDate <= now && x.EndDate >= now && x.CheckMark == "1");
  407. }
  408. catch (Exception ex)
  409. {
  410. if (ex is ExceptionEx)
  411. {
  412. throw;
  413. }
  414. else
  415. {
  416. throw ExceptionEx.ThrowServiceException(ex);
  417. }
  418. }
  419. }
  420. #endregion
  421. }
  422. }