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 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2023-06-05 17:06
/// 描 述:线上选修选课
///
public class LessonInfoOfElectiveOnlineApi : BaseNoAuthentication
{
private LessonInfoOfElectiveOnlineIBLL lessonInfoOfElectiveOnlineIbll = new LessonInfoOfElectiveOnlineBLL();
private StuSelectLessonListOfElectiveOnlineIBLL stuSelectLessonListOfElectiveOnlineIBLL = new StuSelectLessonListOfElectiveOnlineBLL();
private StuInfoBasicIBLL stuInfoBasicIBLL = new StuInfoBasicBLL();
LessonInfoIBLL lessonInfoIbll = new LessonInfoBLL();
EmpInfoIBLL empInfoIbll = new EmpInfoBLL();
private LessonInfoIBLL lessonInfoIBLL = new LessonInfoBLL();
///
/// 注册接口
///
public LessonInfoOfElectiveOnlineApi()
: base("/Learun/LessonInfoOfElectiveOnline")
{
Get["/pagelist"] = GetPageList;
Get["/studentpagelist"] = StudentGetPageList;
Get["/form"] = GetForm;
Post["/Cancel"] = Cancel;
Post["/SignIn"] = SignIn;
Post["/SignInByMobile"] = SignInByMobile;
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 Success(new { msg = "当前学员不存在!" });
}
//课程信息
var olpeEntity = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
if (olpeEntity == null)
{
return Success(new { msg = "当前课程不存在!" });
}
//当前学员本学期是否有报名课程:每学期一门
//var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(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 = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(keyValue);
// var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
// if (aaa >= olpeEntity.StuNumMax)
// {
// return Success("当前课程报名人数已满,请选择其他课程!");
// }
//}
//每学期两门(几门根据系统配置文件值确定)
var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(account, keyValue);
if (sslleEntity != null)
{
if (sslleEntity.Status == 1)
{
return Success(new { msg = "当前课程报名审核中,请耐心等待!" });
}
else if (sslleEntity.Status == 2)
{
return Success(new { msg = "当前课程已报名成功!" });
}
}
else
{
//所选课程的报名人数是否已满
var aa = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByOLPEId(keyValue);
var aaa = aa.Count(x => x.Status == 1 || x.Status == 2);
if (aaa >= olpeEntity.StuNumMax)
{
return Success(new { msg = "当前课程报名人数已满,请选择其他课程!" });
}
//每学期最多两门
var sslleList = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineListByStuNo(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("OnlineElectiveLessonApplyMax").ToInt())
{
return Success(new { msg = "每学期最多选择" + Config.GetValue("OnlineElectiveLessonApplyMax").ToInt() + "门线上选修课!" });
}
//相同时间不能报名
if (!string.IsNullOrEmpty(olpeEntity.LessonSection) && sslleListOfNow1.Where(x => x.LessonSection == olpeEntity.LessonSection).Any())
{
//相同时间不能报名
return Success(new { msg = "本学期此时间段已有报名的选修课!" });
}
}
return Fail("正在提交,请等待!");
}
#region 获取数据
///
/// 获取页面显示列表分页数据
///
///
///
public Response GetPageList(dynamic _)
{
ReqPageParam parameter = this.GetReqData();
var data = lessonInfoOfElectiveOnlineIbll.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 = stuSelectLessonListOfElectiveOnlineIBLL.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 Data = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
var jsonData = new
{
data = Data,
};
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 = lessonInfoOfElectiveOnlineIbll.GetLessonInfoOfElectiveOnlineEntity(keyValue);
if (olpeEntity == null)
{
return Fail("当前课程不存在!");
}
//当前学员是否已经报名该课程
var sslleEntity = stuSelectLessonListOfElectiveOnlineIBLL.GetStuSelectLessonListOfElectiveOnlineEntityByStuNo(account, keyValue);
if (sslleEntity != null)
{
if (sslleEntity.Status != 2)
{
stuSelectLessonListOfElectiveOnlineIBLL.DeleteEntity(sslleEntity.Id);
return Success("取消成功");
}
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;
SignUpOnlineHelper.Instance.Start();
//进队列
SignUpOnlineHelper.AddQueue(account, keyValue);
return Success("操作成功");
}
public Response SignInByMobile(dynamic _)
{
dynamic parameter = this.GetReqData();
string keyValue = parameter.keyValue;
string account = parameter.StuNo;
SignUpOnlineHelper.Instance.Start();
//进队列
SignUpOnlineHelper.AddQueue(account, keyValue);
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
}
}