using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Bowin.Common.Linq.Entity;
using Bowin.Common.Linq;
using EMIS.DataLogic.RetakeManage;
using EMIS.Entities;
using EMIS.ViewModel;
using EMIS.ViewModel.RetakeManage;
using EMIS.Utility;
using EMIS.CommonLogic.SystemServices;
using EMIS.ViewModel.EducationManage;
using EMIS.DataLogic.EducationManage;
using EMIS.CommonLogic.EducationSchedule;
using EMIS.DataLogic.SystemSetting;
using EMIS.CommonLogic.RetakeManage.General;
using EMIS.CommonLogic.StudentManage.StudentStatistics;
namespace EMIS.CommonLogic.RetakeManage.General
{
public class RetakePlanListServices : BaseServices, IRetakePlanListServices
{
public RetakePlanTaskDAL RetakePlanTaskDAL { get; set; }
public IInSchoolSettingServices InSchoolSettingServices { get; set; }
///
/// 查询重修任务名单View
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetRetakePlanStudentView(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID, int pageIndex, int pageSize)
{
//重修计划
Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (coursematerialID.HasValue)
{
//课程信息
expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
}
if (schoolyearID.HasValue)
{
//重修学年学期
expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
}
if (retakePlanStatusID.HasValue)
{
//重修任务状态
expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
}
//学生信息
Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (classmajorID.HasValue)
{
//班级信息
expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
}
if (inSchoolStatus != null && inSchoolStatus > -1)
{
//在校状态
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = RetakePlanTaskDAL.GetRetakePlanTaskStudentView(expRetakePlan, x => true, expStudent);
if (collegeID.HasValue)
{
//院系所
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
//年级
query = query.Where(x => x.Gradeyear == yearID);
}
if (standardID.HasValue)
{
//专业名称
query = query.Where(x => x.StandardID == standardID);
}
if (educationID.HasValue)
{
//培养层次
query = query.Where(x => x.EducationID == educationID);
}
if (learningformID.HasValue)
{
//学习形式
query = query.Where(x => x.LearningformID == learningformID);
}
if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
{
//学制
var LearnSystems = Convert.ToDecimal(learnSystem);
query = query.Where(x => x.LearnSystem == LearnSystems);
}
if (generalPurposeID.HasValue)
{
//报名状态
if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.ApplyStatus == true);
}
if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.ApplyStatus == false);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
.ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
.ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
.ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
.ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询重修任务名单List
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public List GetRetakePlanStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID,
int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? classmajorID, Guid? coursematerialID,
int? inSchoolStatus, int? retakePlanStatusID, int? generalPurposeID)
{
//重修计划
Expression> expRetakePlan = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (coursematerialID.HasValue)
{
//课程信息
expRetakePlan = expRetakePlan.And(x => x.CoursematerialID == coursematerialID);
}
if (schoolyearID.HasValue)
{
//重修学年学期
expRetakePlan = expRetakePlan.And(x => x.SchoolyearID == schoolyearID);
}
if (retakePlanStatusID.HasValue)
{
//重修任务状态
expRetakePlan = expRetakePlan.And(x => x.RecordStatus == retakePlanStatusID);
}
//学生信息
Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (classmajorID.HasValue)
{
//班级信息
expStudent = expStudent.And(x => x.ClassmajorID == classmajorID);
}
if (inSchoolStatus != null && inSchoolStatus > -1)
{
//在校状态
var inschoolStatusList = InSchoolSettingServices.GetInschoolStatusList(true);
if (inSchoolStatus == 1)
{
//表示在校
expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
}
if (inSchoolStatus == 0)
{
//不在校
expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
}
}
var query = RetakePlanTaskDAL.GetRetakePlanTaskStudentView(expRetakePlan, x => true, expStudent);
if (collegeID.HasValue)
{
//院系所
query = query.Where(x => x.CollegeID == collegeID);
}
if (yearID.HasValue)
{
//年级
query = query.Where(x => x.Gradeyear == yearID);
}
if (standardID.HasValue)
{
//专业名称
query = query.Where(x => x.StandardID == standardID);
}
if (educationID.HasValue)
{
//培养层次
query = query.Where(x => x.EducationID == educationID);
}
if (learningformID.HasValue)
{
//学习形式
query = query.Where(x => x.LearningformID == learningformID);
}
if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
{
//学制
var LearnSystems = Convert.ToDecimal(learnSystem);
query = query.Where(x => x.LearnSystem == LearnSystems);
}
if (generalPurposeID.HasValue)
{
//报名状态
if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.ApplyStatus == true);
}
if (generalPurposeID.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.ApplyStatus == false);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.SchoolyearCode)
.ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
.ThenBy(x => x.CourseTypeID).ThenBy(x => x.CourseCredit)
.ThenBy(x => x.DepartmentCode.Length).ThenBy(x => x.DepartmentCode)
.ThenBy(x => x.LoginID.Length).ThenBy(x => x.LoginID)
.ToList();
}
///
/// 删除重修任务名单
///
///
public void DeleteRetakePlanStudent(IList retakePlanStudentIDsList)
{
try
{
//查询对应的重修计划名单信息
var retakePlanStudentViewList = RetakePlanTaskDAL.RetakePlanStudentRepository
.GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID),
(x => x.ER_RetakePlan), (x => x.ER_RetakePlan.CF_Student)).ToList();
if (retakePlanStudentViewList.Any(x => x.ER_RetakePlan.RecordStatus == (int)EMIS.ViewModel.ER_RetakePlanStatus.Generated))
{
throw new Exception("不能删除已开班状态的重修任务名单。");
}
//查询对应的重修报名信息List
var retakePlanStudentApplyList = RetakePlanTaskDAL.RetakePlanStudentRepository
.GetList(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID),
(x => x.ER_RetakePlan),
(x => x.ER_RetakePlan.CF_Student))
.Where(x => x.ER_RetakePlan.CF_Student.Any(w => w.UserID == x.UserID))
.ToList();
if (retakePlanStudentApplyList.Count() > 0)
{
//查询对应的重修计划信息
var retakePlanViewList = retakePlanStudentApplyList
.Select(x => x.ER_RetakePlan).Distinct().ToList();
//重修报名表
foreach (var retakePlan in retakePlanViewList)
{
//查询存在报名名单的重修计划名单对应的userIDList
var userIDList = retakePlanStudentApplyList
.Where(x => x.RetakePlanID == retakePlan.RetakePlanID)
.Select(x => x.UserID).ToList();
retakePlan.CF_Student.RemoveWhere(x => userIDList.Contains(x.UserID));
}
//throw new Exception("要删除的重修计划名单已进行重修报名。");
}
//重修计划名单表
//UnitOfWork.RemoveRange(new HashSet(retakePlanStudentViewList));
UnitOfWork.Remove(x => retakePlanStudentIDsList.Contains(x.RetakePlanStudentID));
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}