using System;
using Nancy;
using Learun.Util;
using System.Collections.Generic;
using Learun.Application.TwoDevelopment.EducationalAdministration;
using System.Linq;
namespace Learun.Application.WebApi
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2019-07-01 17:06
/// 描 述:邮件查看
///
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();
private OLPElectiveStuSelectCountIBLL oLPElectiveStuSelectCountIBLL = new OLPElectiveStuSelectCountBLL();
private LessonInfoIBLL lessonInfoIBLL = new LessonInfoBLL();
///
/// 注册接口
///
public OpenLessonPlanOfElectiveStudentApi()
: base("/Learun/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();
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, "");
//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 Fail("当前课程报名审核中,请耐心等待!");
}
else if (sslleEntity.Status == 2)
{
return Fail("当前课程已报名成功!");
}
}
else
{
//所选课程的报名人数是否已满
var aa = stuSelectLessonListOfElectiveIBLL.GetStuSelectLessonListOfElectiveListByOLPEId(keyValue);
var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
if (aaa >= olpeEntity.StuNumMax)
{
return Fail("当前课程报名人数已满,请选择其他课程!");
}
//每学期最多两门
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 Fail("每学期最多选择" + Config.GetValue("ElectiveLessonApplyMax").ToInt() + "门选修课!");
}
//相同时间不能报名
if (sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
{
//相同时间不能报名
return Fail("本学期此时间段已有报名的选修课!");
}
//专业选修课根据学生选课次数表判断选课上限
var lesson = lessonInfoIBLL.GetLessonInfoAndTypeByLessonNo(olpeEntity.LessonNo);
if (lesson != null && lesson.LessonTypeCode.Contains("Professional"))
{
var oLPElectiveStuSelectCount = oLPElectiveStuSelectCountIBLL.GetOLPElectiveStuSelectCountEntity(olpeEntity.AcademicYearNo, olpeEntity.Semester, stuInfoBasicEntity.DeptNo);
if (oLPElectiveStuSelectCount != null && sslleListOfNow1.Count() > oLPElectiveStuSelectCount.SelectMaxCount)
{
return Fail("本系部最多选择" + oLPElectiveStuSelectCount.SelectMaxCount + "门专业选修课!");
}
}
}
return Fail("正在提交,请等待!");
}
#region 获取数据
///
/// 获取页面显示列表分页数据
///
///
///
public Response GetPageList(dynamic _)
{
ReqPageParam parameter = this.GetReqData();
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();
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);
}
///
/// 获取表单数据
///
///
///
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 提交数据
///
/// 删除实体数据
///
///
///
public Response Cancel(dynamic _)
{
dynamic parameter = this.GetReqData();
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 Fail("取消成功");
}
else
{
return Fail("取消失败,当前课程已报名成功!");
}
}
else
{
return Fail("当前课程未报名,无需取消!");
}
}
///
/// 报名
///
///
///
public Response SignIn(dynamic _)
{
//dynamic parameter = this.GetReqData();
//string keyValue = parameter.keyValue;
//string account = parameter.StuNo;
var parameter = this.GetReq();
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();
string keyValue = parameter.keyValue;
string account = parameter.StuNo;
SignUpHelper.Instance.Start();
//进队列
SignUpHelper.AddQueue(account, keyValue);
return Success("操作成功");
}
///
/// 删除实体数据 (预)
///
///
///
public Response CancelPre(dynamic _)
{
dynamic parameter = this.GetReqData();
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("当前课程未报名,无需取消!");
}
}
///
/// 报名(预)
///
///
///
public Response SignInPre(dynamic _)
{
dynamic parameter = this.GetReqData();
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("当前课程已报名成功!");
}
}
}
//专业选修课根据学生选课次数表判断选课上限
var lesson = lessonInfoIBLL.GetLessonInfoAndTypeByLessonNo(olpeEntity.LessonNo);
if (lesson != null && lesson.LessonTypeCode.Contains("Professional"))
{
var oLPElectiveStuSelectCount = oLPElectiveStuSelectCountIBLL.GetOLPElectiveStuSelectCountEntity(olpeEntity.AcademicYearNo, olpeEntity.Semester, stuInfoBasicEntity.DeptNo);
if (oLPElectiveStuSelectCount != null && sslleListOfNow1.Count() > oLPElectiveStuSelectCount.SelectMaxCount)
{
return Fail("本系部最多选择" + oLPElectiveStuSelectCount.SelectMaxCount + "门专业选修课!");
}
}
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 私有类
///
/// 表单实体类
///
private class ReqFormEntity
{
public string keyValue { get; set; }
public string strEntity { get; set; }
}
///
/// 报名模型
///
private class SignModel
{
public string keyValue { get; set; }
public string StuNo { get; set; }
}
#endregion
}
}