|
- using System;
- using Nancy;
- using Learun.Util;
- using System.Collections.Generic;
- using Learun.Application.TwoDevelopment.EducationalAdministration;
- using System.Linq;
-
- namespace Learun.Application.WebApi
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创 建:超级管理员
- /// 日 期:2019-07-01 17:06
- /// 描 述:邮件查看
- /// </summary>
- public class OpenLessonPlanOfElectiveStudentApi : BaseNoAuthentication
- {
- private OpenLessonPlanOfElectiveIBLL openLessonPlanOfElectiveIbll = new OpenLessonPlanOfElectiveBLL();
- private StuSelectLessonListOfElectiveIBLL stuSelectLessonListOfElectiveIBLL = new StuSelectLessonListOfElectiveBLL();
- private StuSelectLessonListOfElectivePreIBLL stuSelectLessonListOfElectivePreIBLL = new StuSelectLessonListOfElectivePreBLL();
- private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
- LessonInfoIBLL lessonInfoIbll = new LessonInfoBLL();
- EmpInfoIBLL empInfoIbll = new EmpInfoBLL();
-
- /// <summary>
- /// 注册接口
- /// <summary>
- public OpenLessonPlanOfElectiveStudentApi()
- : base("/Learun/EducationalAdministration/OpenLessonPlanOfElectiveStudent")
- {
- Get["/pagelist"] = GetPageList;
- Get["/studentpagelist"] = StudentGetPageList;
- Get["/form"] = GetForm;
- Post["/Cancel"] = Cancel;
- Post["/SignIn"] = SignIn;
- Post["/SignInByMobile"] = SignInByMobile;
- Post["/CancelPre"] = CancelPre;
- Post["/SignInPre"] = SignInPre;
- Post["/GetApplyResult"] = GetApplyResult;
- }
-
- private Response GetApplyResult(dynamic _)
- {
- dynamic parameter = this.GetReqData<dynamic>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
- //学员信息
- var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
- if (stuInfoBasicEntity == null)
- {
- return Success("当前学员不存在!");
- }
- //课程信息
- var olpeEntity = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(keyValue);
- if (olpeEntity == null)
- {
- return Success("当前课程不存在!");
- }
-
- //当前学员本学期是否有报名课程:每学期一门
- //var sslleEntity = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveEntityByStuNo(account, "");
- //if (sslleEntity != null)
- //{
- // if (sslleEntity.OLPEId != keyValue && sslleEntity.Status != 3)
- // {
- // return Success("已存在报名课程,每学期只能选择一门选修课!如需报名其他课程请先取消。");
- // }
- // if (sslleEntity.Status == 1)
- // {
- // return Success("报名审核中,请耐心等待!");
- // }
- // else if (sslleEntity.Status == 2)
- // {
- // return Success("已存在报名成功的课程,只能选择一门选修课!");
- // }
-
- //}
- //else
- //{
- // //所选课程的报名人数是否已满
- // var aa = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByOLPEId(keyValue);
- // var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
- // if (aaa >= olpeEntity.StuNumMax)
- // {
- // return Success("当前课程报名人数已满,请选择其他课程!");
- // }
- //}
-
- //每学期两门
- var sslleEntity = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveEntityByStuNo(account, keyValue);
- if (sslleEntity != null)
- {
- if (sslleEntity.Status == 1)
- {
- return Success("当前课程报名审核中,请耐心等待!");
- }
- else if (sslleEntity.Status == 2)
- {
- return Success("当前课程已报名成功!");
- }
- }
- else
- {
- //所选课程的报名人数是否已满
- var aa = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByOLPEId(keyValue);
- var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
- if (aaa >= olpeEntity.StuNumMax)
- {
- return Success("当前课程报名人数已满,请选择其他课程!");
- }
- //每学期最多两门
- var sslleList = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByStuNo(account);
- var sslleListOfNow = sslleList.Where(x => x.AcademicYearNo == olpeEntity.AcademicYearNo && x.Semester == olpeEntity.Semester);
- var sslleListOfNow1 = sslleListOfNow.Where(x => x.Status == 1 || x.Status == 2);
- if (sslleListOfNow1.Count() >= Config.GetValue("ElectiveLessonApplyMax").ToInt())
- {
- return Success("每学期最多选择" + Config.GetValue("ElectiveLessonApplyMax").ToInt() + "门选修课!");
- }
- //相同时间不能报名
- if (sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
- {
- //相同时间不能报名
- return Success("本学期此时间段已有报名的选修课!");
- }
- }
-
- return Fail("正在提交,请等待!");
- }
-
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表分页数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetPageList(dynamic _)
- {
- ReqPageParam parameter = this.GetReqData<ReqPageParam>();
- var data = openLessonPlanOfElectiveIbll.GetPageListOfStudent(parameter.pagination, parameter.queryJson).OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x => x.LessonNo).ThenBy(x => x.EmpNo);
- var jsonData = new
- {
- rows = data,
- total = parameter.pagination.total,
- page = parameter.pagination.page,
- records = parameter.pagination.records
- };
- return Success(jsonData);
- }
- public Response StudentGetPageList(dynamic _)
- {
- ReqPageParam parameter = this.GetReqData<ReqPageParam>();
- var data = stuSelectLessonListOfElectiveIBLL.GetPageList(parameter.pagination, parameter.queryJson).OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x => x.LessonNo).ThenBy(x => x.EmpNo);
- var jsonData = new
- {
- rows = data,
- total = parameter.pagination.total,
- page = parameter.pagination.page,
- records = parameter.pagination.records
- };
- return Success(jsonData);
- }
- /// <summary>
- /// 获取表单数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetForm(dynamic _)
- {
- string keyValue = this.GetReqData();
- var JournalReceiveData = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(keyValue);
- if (lessonInfoIbll.GetLessonInfoEntityByLessonNo(JournalReceiveData.LessonNo) != null)
- {
- if (!string.IsNullOrEmpty(lessonInfoIbll.GetLessonInfoEntityByLessonNo(JournalReceiveData.LessonNo).Introduction))
- JournalReceiveData.Introduction = WebHelper.NoHtml(WebHelper.HtmlDecode(lessonInfoIbll.GetLessonInfoEntityByLessonNo(JournalReceiveData.LessonNo).Introduction)) ?? "";
- }
- if (empInfoIbll.GetEmpInfoEntityByEmpNo(JournalReceiveData.EmpNo) != null)
- {
- if (!string.IsNullOrEmpty(empInfoIbll.GetEmpInfoEntityByEmpNo(JournalReceiveData.EmpNo).resume))
- JournalReceiveData.resume = WebHelper.NoHtml(WebHelper.HtmlDecode(empInfoIbll.GetEmpInfoEntityByEmpNo(JournalReceiveData.EmpNo).resume)) ?? "";
- }
- var jsonData = new
- {
- JournalReceive = JournalReceiveData,
- };
- return Success(jsonData);
- }
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// <param name="_"></param>
- /// <summary>
- /// <returns></returns>
- public Response Cancel(dynamic _)
- {
- dynamic parameter = this.GetReqData<dynamic>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
- //学员信息
- var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
- if (stuInfoBasicEntity == null)
- {
- return Fail("当前学员不存在!");
- }
- //课程信息
- var olpeEntity = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(keyValue);
- if (olpeEntity == null)
- {
- return Fail("当前课程不存在!");
- }
- //当前学员是否已经报名该课程
- var sslleEntity = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveEntityByStuNo(account, keyValue);
- if (sslleEntity != null)
- {
- if (sslleEntity.Status != 2)
- {
- stuSelectLessonListOfElectiveIBLL.DeleteEntity(sslleEntity.Id);
- return Success("取消成功");
- }
- else
- {
- return Fail("取消失败,当前课程已报名成功!");
- }
- }
- else
- {
- return Fail("当前课程未报名,无需取消!");
- }
- }
- /// <summary>
- /// 报名
- /// </summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response SignIn(dynamic _)
- {
- //dynamic parameter = this.GetReqData<dynamic>();
- //string keyValue = parameter.keyValue;
- //string account = parameter.StuNo;
-
- var parameter = this.GetReq<SignModel>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
-
- SignUpHelper.Instance.Start();
- //进队列
- SignUpHelper.AddQueue(account, keyValue);
-
- return Success("操作成功");
- }
- public Response SignInByMobile(dynamic _)
- {
- dynamic parameter = this.GetReqData<dynamic>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
-
- SignUpHelper.Instance.Start();
- //进队列
- SignUpHelper.AddQueue(account, keyValue);
-
- return Success("操作成功");
- }
- /// <summary>
- /// 删除实体数据 (预)
- /// <param name="_"></param>
- /// <summary>
- /// <returns></returns>
- public Response CancelPre(dynamic _)
- {
- dynamic parameter = this.GetReqData<dynamic>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
- //学员信息
- var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
- if (stuInfoBasicEntity == null)
- {
- return Fail("当前学员不存在!");
- }
- //课程信息
- var olpeEntity = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(keyValue);
- if (olpeEntity == null)
- {
- return Fail("当前课程不存在!");
- }
- //当前学员是否已经报名该课程
- var sslleEntity = stuSelectLessonListOfElectivePreIBLL.GetStuSelectLessonListOfElectivePreEntityByStuNo(account, keyValue);
- if (sslleEntity != null)
- {
- if (sslleEntity.Status != 2)
- {
- stuSelectLessonListOfElectivePreIBLL.DeleteEntity(sslleEntity.Id);
- return Success("取消成功");
- }
- else
- {
- return Fail("取消失败,当前课程已报名成功!");
- }
- }
- else
- {
- return Fail("当前课程未报名,无需取消!");
- }
- }
- /// <summary>
- /// 报名(预)
- /// </summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response SignInPre(dynamic _)
- {
- dynamic parameter = this.GetReqData<dynamic>();
- string keyValue = parameter.keyValue;
- string account = parameter.StuNo;
- //学员信息
- var stuInfoBasicEntity = stuInfoBasicIBLL.GetStuInfoBasicEntityByStuNo(account);
- if (stuInfoBasicEntity == null)
- {
- return Fail("当前学员不存在!");
- }
- //课程信息
- var olpeEntity = openLessonPlanOfElectiveIbll.GetOpenLessonPlanOfElectiveEntity(keyValue);
- if (olpeEntity == null)
- {
- return Fail("当前课程不存在!");
- }
- //所选课程的报名人数是否已满
- var aa = stuSelectLessonListOfElectivePreIBLL.GetStuSelectLessonListOfElectivePreListByOLPEId(olpeEntity.Id);
- var aaa = aa.Where(x => x.Status == 2).Count();
- if (aaa >= olpeEntity.StuNumMax)
- {
- return Fail("当前课程报名人数已满,请选择其他课程!");
- }
- //当前学员本学期是否有报名课程:每学期一门
- //var sslleEntity = stuSelectLessonListOfElectivePreIBLL.GetStuSelectLessonListOfElectivePreEntityByStuNo(account, "");
- //if (sslleEntity != null)
- //{
- // if (sslleEntity.OLPEId != keyValue && sslleEntity.Status != 3)
- // {
- // return Fail("已存在报名课程,每学期只能选择一门选修课!如需报名其他课程请先取消。");
- // }
- // if (sslleEntity.Status == 1)
- // {
- // return Fail("报名审核中,请耐心等待!");
- // }
- // else if (sslleEntity.Status == 2)
- // {
- // return Fail("已存在报名成功的课程,只能选择一门选修课!");
- // }
- // else if (sslleEntity.Status == 3)//移除报名失败的数据
- // {
- // stuSelectLessonListOfElectivePreIBLL.DeleteEntity(sslleEntity.Id);
- // }
-
- //}
-
- //每学期两门
- var sslleList = stuSelectLessonListOfElectivePreIBLL.GetStuSelectLessonListOfElectivePreListByStuNo(account);
- var sslleListOfNow = sslleList.Where(x => x.AcademicYearNo == olpeEntity.AcademicYearNo && x.Semester == olpeEntity.Semester);
- var sslleListOfNow1 = sslleListOfNow.Where(x => x.Status == 1 || x.Status == 2);
- var sslleListOfNow2 = sslleListOfNow.Where(x => x.Status == 3);
- if (sslleListOfNow1.Count() >= Config.GetValue("ElectiveLessonApplyMax").ToInt())
- {
- return Fail("每学期最多选择" + Config.GetValue("ElectiveLessonApplyMax").ToInt() + "门选修课!");
- }
- else
- {
- var m = sslleListOfNow1.FirstOrDefault(x => x.OLPEId == olpeEntity.Id);
- if (m != null)
- {
- if (m.Status == 1)
- {
- return Fail("当前课程报名审核中,请耐心等待!");
- }
- else if (m.Status == 2)
- {
- return Fail("当前课程已报名成功!");
- }
- }
- }
- if (sslleListOfNow2.Count() > 0)
- {
- foreach (var item in sslleListOfNow2)
- {
- stuSelectLessonListOfElectivePreIBLL.DeleteEntity(item.Id);
- }
- }
- //相同时间不能报名
- if (sslleListOfNow1.Select(x => x.LessonSection == olpeEntity.LessonSection).Any())
- {
- //相同时间不能报名
- return Success("本学期此时间段已有报名的选修课!");
- }
- //新增报名数据
- var model = new StuSelectLessonListOfElectivePreEntity()
- {
- OLPEId = olpeEntity.Id,
- NoticeBookNo = stuInfoBasicEntity.NoticeNo,
- StuNo = stuInfoBasicEntity.StuNo,
- DeptNo = stuInfoBasicEntity.DeptNo,
- MajorNo = stuInfoBasicEntity.MajorNo,
- ClassNo = stuInfoBasicEntity.ClassNo,
- MajorDetailNo = stuInfoBasicEntity.MajorDetailNo,
- MajorDetailName = stuInfoBasicEntity.MajorDetailName,
- StuName = stuInfoBasicEntity.StuName,
- GenderNo = stuInfoBasicEntity.GenderNo,
- Grade = stuInfoBasicEntity.Grade,
- AcademicYearNo = olpeEntity.AcademicYearNo,
- Semester = olpeEntity.Semester,
- LessonNo = olpeEntity.LessonNo,
- LessonName = olpeEntity.LessonName,
- LessonSortNo = olpeEntity.LessonSortNo,
- LessonSection = olpeEntity.LessonSection,
- LessonTime = olpeEntity.LessonTime,
- EmpNo = olpeEntity.EmpNo,
- EmpName = olpeEntity.EmpName,
- ClassRoomNo = olpeEntity.ClassRoomNo,
- ClassRoomName = olpeEntity.ClassRoomName,
- StudyScore = olpeEntity.StudyScore,
- StartWeek = olpeEntity.StartWeek,
- EndWeek = olpeEntity.EndWeek,
- StartDate = olpeEntity.StartDate,
- EndDate = olpeEntity.EndDate,
- CreateTime = DateTime.Now,
- Status = 1,
- OrdinaryScoreScale = 1,
- TermInScoreScale = 1,
- TermEndScoreScale = 1,
- OtherScoreScale = 1,
- F_SchoolId = olpeEntity.F_SchoolId
- };
- stuSelectLessonListOfElectivePreIBLL.SaveEntity("", model);
-
- return Success("报名成功");
- }
- #endregion
-
- #region 私有类
-
- /// <summary>
- /// 表单实体类
- /// <summary>
- private class ReqFormEntity
- {
- public string keyValue { get; set; }
- public string strEntity { get; set; }
- }
- /// <summary>
- /// 报名模型
- /// </summary>
- private class SignModel
- {
- public string keyValue { get; set; }
- public string StuNo { get; set; }
- }
- #endregion
-
- }
- }
|