25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

287 lines
11 KiB

  1. using System;
  2. using Nancy;
  3. using Learun.Util;
  4. using System.Collections.Generic;
  5. using Learun.Application.TwoDevelopment.EducationalAdministration;
  6. using System.Linq;
  7. namespace Learun.Application.WebApi
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创 建:超级管理员
  13. /// 日 期:2023-06-05 17:06
  14. /// 描 述:线上选修选课
  15. /// </summary>
  16. public class LessonInfoOfElectiveOnlineApi : BaseNoAuthentication
  17. {
  18. private LessonInfoOfElectiveOnlineIBLL lessonInfoOfElectiveOnlineIbll = new LessonInfoOfElectiveOnlineBLL();
  19. private StuSelectLessonListOfElectiveOnlineIBLL stuSelectLessonListOfElectiveOnlineIBLL = new StuSelectLessonListOfElectiveOnlineBLL();
  20. private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
  21. LessonInfoIBLL lessonInfoIbll = new LessonInfoBLL();
  22. EmpInfoIBLL empInfoIbll = new EmpInfoBLL();
  23. private LessonInfoIBLL lessonInfoIBLL = new LessonInfoBLL();
  24. /// <summary>
  25. /// 注册接口
  26. /// <summary>
  27. public LessonInfoOfElectiveOnlineApi()
  28. : base("/Learun/LessonInfoOfElectiveOnline")
  29. {
  30. Get["/pagelist"] = GetPageList;
  31. Get["/studentpagelist"] = StudentGetPageList;
  32. Get["/form"] = GetForm;
  33. Post["/Cancel"] = Cancel;
  34. Post["/SignIn"] = SignIn;
  35. Post["/SignInByMobile"] = SignInByMobile;
  36. Post["/GetApplyResult"] = GetApplyResult;
  37. }
  38. /// <summary>
  39. /// 判断队列结果
  40. /// </summary>
  41. /// <param name="_"></param>
  42. /// <returns></returns>
  43. private Response GetApplyResult(dynamic _)
  44. {
  45. dynamic parameter = this.GetReqData<dynamic>();
  46. string keyValue = parameter.keyValue;
  47. string account = parameter.StuNo;
  48. //学员信息
  49. var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
  50. if (stuInfoBasicEntity == null)
  51. {
  52. return Success(new { msg = "当前学员不存在!" });
  53. }
  54. //课程信息
  55. var olpeEntity = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
  56. if (olpeEntity == null)
  57. {
  58. return Success(new { msg = "当前课程不存在!" });
  59. }
  60. //当前学员本学期是否有报名课程:每学期一门
  61. //var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(account, "");
  62. //if (sslleEntity != null)
  63. //{
  64. // if (sslleEntity.OLPEId != keyValue && sslleEntity.Status != 3)
  65. // {
  66. // return Success("已存在报名课程,每学期只能选择一门选修课!如需报名其他课程请先取消。");
  67. // }
  68. // if (sslleEntity.Status == 1)
  69. // {
  70. // return Success("报名审核中,请耐心等待!");
  71. // }
  72. // else if (sslleEntity.Status == 2)
  73. // {
  74. // return Success("已存在报名成功的课程,只能选择一门选修课!");
  75. // }
  76. //}
  77. //else
  78. //{
  79. // //所选课程的报名人数是否已满
  80. // var aa = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(keyValue);
  81. // var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
  82. // if (aaa >= olpeEntity.StuNumMax)
  83. // {
  84. // return Success("当前课程报名人数已满,请选择其他课程!");
  85. // }
  86. //}
  87. //每学期两门(几门根据系统配置文件值确定)
  88. var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(account, keyValue);
  89. if (sslleEntity != null)
  90. {
  91. if (sslleEntity.Status == 1)
  92. {
  93. return Success(new { msg = "当前课程报名审核中,请耐心等待!" });
  94. }
  95. else if (sslleEntity.Status == 2)
  96. {
  97. return Success(new { msg = "当前课程已报名成功!" });
  98. }
  99. }
  100. else
  101. {
  102. //所选课程的报名人数是否已满
  103. var aa = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(keyValue);
  104. var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
  105. if (aaa >= olpeEntity.StuNumMax)
  106. {
  107. return Success(new { msg = "当前课程报名人数已满,请选择其他课程!" });
  108. }
  109. //每学期最多两门
  110. var sslleList = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByStuNo(account);
  111. var sslleListOfNow = sslleList.Where(x => x.AcademicYearNo == olpeEntity.AcademicYearNo && x.Semester == olpeEntity.Semester);
  112. var sslleListOfNow1 = sslleListOfNow.Where(x => x.Status == 1 || x.Status == 2);
  113. if (sslleListOfNow1.Count() >= Config.GetValue("OnlineElectiveLessonApplyMax").ToInt())
  114. {
  115. return Success(new { msg = "每学期最多选择" + Config.GetValue("OnlineElectiveLessonApplyMax").ToInt() + "门线上选修课!" });
  116. }
  117. //相同时间不能报名
  118. if (!string.IsNullOrEmpty(olpeEntity.LessonSection) && sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
  119. {
  120. //相同时间不能报名
  121. return Success(new { msg = "本学期此时间段已有报名的选修课!" });
  122. }
  123. }
  124. return Fail("正在提交,请等待!");
  125. }
  126. #region 获取数据
  127. /// <summary>
  128. /// 获取页面显示列表分页数据
  129. /// <summary>
  130. /// <param name="_"></param>
  131. /// <returns></returns>
  132. public Response GetPageList(dynamic _)
  133. {
  134. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  135. var data = lessonInfoOfElectiveOnlineIbll.GetPageListOfStudent(parameter.pagination, parameter.queryJson).OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x => x.LessonNo).ThenBy(x => x.EmpNo);
  136. var jsonData = new
  137. {
  138. rows = data,
  139. total = parameter.pagination.total,
  140. page = parameter.pagination.page,
  141. records = parameter.pagination.records
  142. };
  143. return Success(jsonData);
  144. }
  145. public Response StudentGetPageList(dynamic _)
  146. {
  147. ReqPageParam parameter = this.GetReqData<ReqPageParam>();
  148. var data = stuSelectLessonListOfElectiveOnlineIBLL.GetPageList(parameter.pagination, parameter.queryJson).OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x => x.LessonNo).ThenBy(x => x.EmpNo);
  149. var jsonData = new
  150. {
  151. rows = data,
  152. total = parameter.pagination.total,
  153. page = parameter.pagination.page,
  154. records = parameter.pagination.records
  155. };
  156. return Success(jsonData);
  157. }
  158. /// <summary>
  159. /// 获取表单数据
  160. /// <summary>
  161. /// <param name="_"></param>
  162. /// <returns></returns>
  163. public Response GetForm(dynamic _)
  164. {
  165. string keyValue = this.GetReqData();
  166. var Data = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
  167. var jsonData = new
  168. {
  169. data = Data,
  170. };
  171. return Success(jsonData);
  172. }
  173. #endregion
  174. #region 提交数据
  175. /// <summary>
  176. /// 删除实体数据
  177. /// <param name="_"></param>
  178. /// <summary>
  179. /// <returns></returns>
  180. public Response Cancel(dynamic _)
  181. {
  182. dynamic parameter = this.GetReqData<dynamic>();
  183. string keyValue = parameter.keyValue;
  184. string account = parameter.StuNo;
  185. //学员信息
  186. var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
  187. if (stuInfoBasicEntity == null)
  188. {
  189. return Fail("当前学员不存在!");
  190. }
  191. //课程信息
  192. var olpeEntity = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
  193. if (olpeEntity == null)
  194. {
  195. return Fail("当前课程不存在!");
  196. }
  197. //当前学员是否已经报名该课程
  198. var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(account, keyValue);
  199. if (sslleEntity != null)
  200. {
  201. if (sslleEntity.Status != 2)
  202. {
  203. stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(sslleEntity.Id);
  204. return Success("取消成功");
  205. }
  206. else
  207. {
  208. return Fail("取消失败,当前课程已报名成功!");
  209. }
  210. }
  211. else
  212. {
  213. return Fail("当前课程未报名,无需取消!");
  214. }
  215. }
  216. /// <summary>
  217. /// 报名
  218. /// </summary>
  219. /// <param name="_"></param>
  220. /// <returns></returns>
  221. public Response SignIn(dynamic _)
  222. {
  223. //dynamic parameter = this.GetReqData<dynamic>();
  224. //string keyValue = parameter.keyValue;
  225. //string account = parameter.StuNo;
  226. var parameter = this.GetReq<SignModel>();
  227. string keyValue = parameter.keyValue;
  228. string account = parameter.StuNo;
  229. SignUpOnlineHelper.Instance.Start();
  230. //进队列
  231. SignUpOnlineHelper.AddQueue(account, keyValue);
  232. return Success("操作成功");
  233. }
  234. public Response SignInByMobile(dynamic _)
  235. {
  236. dynamic parameter = this.GetReqData<dynamic>();
  237. string keyValue = parameter.keyValue;
  238. string account = parameter.StuNo;
  239. SignUpOnlineHelper.Instance.Start();
  240. //进队列
  241. SignUpOnlineHelper.AddQueue(account, keyValue);
  242. return Success("操作成功");
  243. }
  244. #endregion
  245. #region 私有类
  246. /// <summary>
  247. /// 表单实体类
  248. /// <summary>
  249. private class ReqFormEntity
  250. {
  251. public string keyValue { get; set; }
  252. public string strEntity { get; set; }
  253. }
  254. /// <summary>
  255. /// 报名模型
  256. /// </summary>
  257. private class SignModel
  258. {
  259. public string keyValue { get; set; }
  260. public string StuNo { get; set; }
  261. }
  262. #endregion
  263. }
  264. }