123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.MinorManage.MinorClass;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.MinorManage.MinorClass;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using Bowin.Common.Linq;
- using EMIS.DataLogic.MinorManage.MinorApply;
- using EMIS.CommonLogic.MinorManage.MinorApply;
- using EMIS.ViewModel.MinorManage.MinorApply;
- using EMIS.ViewModel.Students;
- using EMIS.DataLogic.MinorManage.MinorPlanManage;
- using EMIS.ViewModel.CacheManage;
- namespace EMIS.CommonLogic.MinorManage.MinorClass
- {
- public class MinorClassServices : BaseServices, IMinorClassServices
- {
- public MinorClassDAL minorClassDAL { get; set; }
- public MinorApplyDAL minorApplyDAL { get; set; }
- public IMinorApplyServices minorApplyServices { get; set; }
- public MinorSpecialtyDAL minorSpecialtyDAL { get; set; }
- /// <summary>
- /// 获取辅修班级信息
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="yearID"></param>
- /// <param name="standardID"></param>
- /// <param name="approvalStatus"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<MinorClassView> GetMinorClassViewGrid(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? classminorStatus, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Classminor, bool>> exp = (x => true);
- Expression<Func<CF_Grademinor, bool>> expgm = (x => true);
- if (collegeID.HasValue)
- {
- expgm = expgm.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- expgm = expgm.And(x => x.YearID == yearID);
- }
- if (standardID.HasValue)
- {
- expgm = expgm.And(x => x.StandardID == standardID);
- }
- if (classminorStatus.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == classminorStatus);
- }
- var query = minorClassDAL.GetMinorClassViewQueryable(exp, expgm);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.GradeYearID).ThenBy(x => x.StandardID).ToGridResultSet<MinorClassView>(pageIndex, pageSize);
- return result;
- }
- /// <summary>
- /// 获取辅修班级信息(Excel)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="yearID"></param>
- /// <param name="standardID"></param>
- /// <param name="approvalStatus"></param>
- /// <param name="idList"></param>
- /// <returns></returns>
- public List<MinorClassView> GetMinorClassViewList(ConfiguretView configuretView, Guid? collegeID, int? yearID, int? standardID, int? classminorStatus, List<Guid?> idList)
- {
- Expression<Func<CF_Classminor, bool>> exp = (x => true);
- Expression<Func<CF_Grademinor, bool>> expgm = (x => true);
- if (collegeID.HasValue)
- {
- expgm = expgm.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- expgm = expgm.And(x => x.YearID == yearID);
- }
- if (standardID.HasValue)
- {
- expgm = expgm.And(x => x.StandardID == standardID);
- }
- if (classminorStatus.HasValue)
- {
- exp = exp.And(x => x.RecordStatus == classminorStatus);
- }
- if (idList.Count > 0 && idList != null)
- {
- exp = exp.And(x => idList.Contains(x.ClassminorID));
- }
- var query = minorClassDAL.GetMinorClassViewQueryable(exp, expgm);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- var result = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.GradeYearID).ThenBy(x => x.StandardID).ToList();
- return result;
- }
- public void GenerateMinorClass()
- {
- try
- {
- Expression<Func<EM_StudentMinorRegist, bool>> exp = x => true;
- Expression<Func<CF_Classmajor, bool>> expcla = x => true;
- Expression<Func<CF_College, bool>> expcol = x => true;
- List<CF_Classminor> addClassminorList = new List<CF_Classminor>();
- List<CF_Classminor> updateClassminorList = new List<CF_Classminor>();
- var endStatusID = minorApplyServices.GetCorrectEndStatus();
- exp = exp.And(x => x.RecordStatus == endStatusID);
- var minorStudentList = minorApplyDAL.GetMinorApplyViewQueryable(exp, expcla, expcol);
- var dbClassList = minorClassDAL.GetMinorClassViewQueryable(x => true, x => true).ToList();
- //Expression<Func<CF_ClassminorStudent, bool>> stuexp = x => true;
- //var dbstudent = minorClassDAL.GetStudentsQueryable(stuexp);
- var gradeMinorList = minorSpecialtyDAL.GetMinorSpecialtyViewQueryable(x => x.RecordStatus == (int)CF_GrademinorStatus.Opened);
- var minorApplyViewList = this.GetQueryByDataRangeByCollege(minorStudentList).ToList();
- var gmquery = gradeMinorList.GroupBy(x => new
- {
- x.SchoolyearID,
- x.GrademinorID,
- x.YearID,
- x.StandardID,
- }).ToList();
- var query = minorApplyViewList.GroupBy(x => new
- {
- x.SchoolyearID,
- x.GrademinorID,
- x.GradeYearID,
- x.GrademinorName
- }).ToList();
- foreach (var grademinor in gmquery)
- {
- CF_Classminor classminor = new CF_Classminor();
- if (dbClassList.Any(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID && x.RecordStatus != (int)CF_ClassminorStatus.NotOpen))
- {
- continue;
- }
- //未开班的更新学生名单
- if (dbClassList.Any(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID && x.RecordStatus == (int)CF_ClassminorStatus.NotOpen))
- {
- classminor = minorClassDAL.classminorRepository.GetSingle(x => x.GrademinorID == grademinor.Key.GrademinorID && x.CF_Grademinor.YearID == grademinor.Key.YearID, (x => x.CF_Grademinor));
- UnitOfWork.Delete<CF_ClassminorStudent>(x => x.ClassminorID == classminor.ClassminorID);
- //UnitOfWork.Delete<CF_Classminor>(x => x.ClassminorID == classminor.ClassminorID);
- classminor.RecordStatus = (int)CF_ClassminorStatus.NotOpen;
- classminor.ModifyTime = DateTime.Now;
- classminor.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
- if (minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Count() > 0)
- {
- var Student = minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Select(x => new CF_ClassminorStudent
- {
- ClassminorStudentID = Guid.NewGuid(),
- ClassminorID = classminor.ClassminorID,
- UserID = x.UserID.Value,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateTime = DateTime.Now,
- CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
- ModifyTime = DateTime.Now,
- ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
- });
- classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>(Student.ToList());
- }
- else
- {
- classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>();
- }
- updateClassminorList.Add(classminor);
- //UnitOfWork.Update(classminorList);
- //UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
- }
- else {
- //未生成过班级的生成班级
- var standardName = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard.ToString()).Where(x => x.Value == grademinor.Key.StandardID).Select(x => x.Name).FirstOrDefault();
- classminor.ClassminorID = Guid.NewGuid();
- classminor.GrademinorID = grademinor.Key.GrademinorID;
- classminor.Name = grademinor.Key.YearID.ToString() + standardName + "辅修班";
- classminor.Abbreviation = classminor.Name;
- classminor.ClassNum = 1;
- classminor.RecordStatus = (int)CF_ClassminorStatus.NotOpen;
- classminor.CreateTime = DateTime.Now;
- classminor.CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
- classminor.ModifyTime = DateTime.Now;
- classminor.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
- if (minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Count() > 0)
- {
- var Student = minorApplyViewList.Where(x => x.GrademinorID == grademinor.Key.GrademinorID && x.GradeYearID == grademinor.Key.YearID).Select(x => new CF_ClassminorStudent
- {
- ClassminorStudentID = Guid.NewGuid(),
- ClassminorID = classminor.ClassminorID,
- UserID = x.UserID.Value,
- RecordStatus = (int)SYS_STATUS.USABLE,
- CreateTime = DateTime.Now,
- CreateUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
- ModifyTime = DateTime.Now,
- ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID,
- });
- classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>(Student.ToList());
- }
- else
- {
- classminor.CF_ClassminorStudent = new HashSet<CF_ClassminorStudent>();
- }
- addClassminorList.Add(classminor);
- //UnitOfWork.BulkInsert(classminorList);
- //UnitOfWork.BulkInsert(classminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
- }
- }
- //UnitOfWork.BulkInsert(updateClassminorList);
- UnitOfWork.BulkInsert(updateClassminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
- UnitOfWork.BulkInsert(addClassminorList);
- UnitOfWork.BulkInsert(addClassminorList.SelectMany(x => x.CF_ClassminorStudent).ToList());
- //UnitOfWork.Commit();
-
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public void MinorClassEdit(MinorClassView minorClassView)
- {
- try
- {
- CF_Classminor classminor = new CF_Classminor();
- if (minorClassView.ClassminorID == null || minorClassView.ClassminorID == Guid.Empty)
- {
- //新增、复制新增
- classminor = minorClassDAL.classminorRepository
- .GetSingle(x => x.GrademinorID == minorClassView.GrademinorID && x.Name == minorClassView.Name);
- if (classminor != null)
- {
- throw new Exception("已存在名称相同的辅修班级信息。");
- }
- classminor = new CF_Classminor();
- classminor.ClassminorID = Guid.NewGuid();
- classminor.GrademinorID = minorClassView.GrademinorID;
- classminor.Name = minorClassView.Name;
- classminor.ClassNum = minorClassView.ClassNum ?? 1;
- classminor.Abbreviation = minorClassView.ClassAbbreviation ?? minorClassView.Name;
- SetNewStatus(classminor);
- UnitOfWork.Add(classminor);
- }
- else
- {
- //修改
- classminor = minorClassDAL.classminorRepository
- .GetSingle(x => x.ClassminorID != minorClassView.ClassminorID
- && x.GrademinorID == minorClassView.GrademinorID && x.Name == minorClassView.Name);
- if (classminor != null)
- {
- throw new Exception("已存在名称相同的辅修班级信息。");
- }
- classminor = minorClassDAL.classminorRepository
- .GetSingle(x => x.ClassminorID == minorClassView.ClassminorID);
- if (classminor == null)
- {
- throw new Exception("数据有误,请核查。");
- }
- classminor.GrademinorID = minorClassView.GrademinorID;
- classminor.Name = minorClassView.Name;
- classminor.ClassNum = minorClassView.ClassNum;
- classminor.Abbreviation = minorClassView.ClassAbbreviation;
- SetModifyStatus(classminor);
- }
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public void MinorClassDelete(IList<Guid?> minorClassIDList)
- {
- try
- {
- if (minorClassIDList.Count > 0)
- {
- UnitOfWork.Delete<CF_ClassminorStudent>(x => minorClassIDList.Contains(x.ClassminorID));
- UnitOfWork.Delete<CF_Classminor>(x => minorClassIDList.Contains(x.ClassminorID));
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public IGridResultSet<StudentsView> GetStudentsByMinorClassID(Guid minorClassID)
- {
- Expression<Func<CF_ClassminorStudent, bool>> exp = x => x.ClassminorID == minorClassID;
- var query = minorClassDAL.GetStudentsQueryable(exp);
- return query.OrderBy(x => x.LoginID).ToGridResultSet<StudentsView>();
- }
- public void OpenClassMinor(List<Guid?> minorClassIDList)
- {
- try
- {
- var classminorList = minorClassDAL.classminorRepository.GetList(x => minorClassIDList.Contains(x.ClassminorID));
- foreach (var classMinor in classminorList)
- {
- if (classMinor.RecordStatus != (int)CF_ClassminorStatus.NotOpen)
- {
- throw new Exception("只能对未开班的数据进行开班");
- }
- classMinor.RecordStatus = (int)CF_ClassminorStatus.Open;
- }
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public void CancelOpenClassMinor(List<Guid?> minorClassIDList)
- {
- try
- {
- var classminorList = minorClassDAL.classminorRepository.GetList(x => minorClassIDList.Contains(x.ClassminorID));
- foreach (var classMinor in classminorList)
- {
- if (classMinor.RecordStatus != (int)CF_ClassminorStatus.Open)
- {
- throw new Exception("只能对已开班的数据进行开班");
- }
- classMinor.RecordStatus = (int)CF_ClassminorStatus.Cancel;
- }
- UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|