123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.TeachingMaterial;
- using EMIS.DataLogic.Common.TeachingMaterial;
- using EMIS.DataLogic.Repositories;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using System.Diagnostics;
- using Bowin.Common.Linq;
- using System.Linq.Expressions;
- using System.Web;
- using EMIS.Utility;
- using EMIS.DataLogic.SystemDAL;
- using System.Collections;
- namespace EMIS.CommonLogic.TeachingMaterial
- {
- public class StudentsOrderServices : BaseServices, IStudentsOrderServices
- {
- #region --0.0 定义--
- public StudentsOrderDAL StudentsOrderDAL { get; set; }
- public StudentsOrderRepository StudentsOrderRepository { get; set; }
- public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
- public SchoolyearRepository SchoolyearRepository { get; set; }
- public UserRepository UserRepository { get; set; }
- public Lazy<StudentRepository> StudentRepository { get; set; }
- public CoursematerialRepository CoursematerialRepository { get; set; }
- public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
- public CollegeRepository CollegeRepository { get; set; }
- public DictionaryItemRepository DictionaryItemRepository { get; set; }
- public GrademajorRepository GrademajorRepository { get; set; }
- public FacultymajorRepository FacultymajorRepository { get; set; }
- public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
- public ClassmajorRepository ClassmajorRepository { get; set; }
- public PublishRepository PublishRepository { get; set; }
- public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }
- #region 1.0 查询学生征订记录
- /// <summary>
- /// 查询学生征订记录
- /// </summary>
- public IGridResultSet<StudentsOrderView> GetStudentsOrderViewGrid(ViewModel.ConfiguretView configuretView, Guid? campusID,
- Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID,
- Guid? teachingMaterialID, int pageIndex, int pageSize)
- {
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (teachingMaterialID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (years.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (courseCategoryID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
- }
- if (isOrdered.HasValue && isOrdered > -1)
- {
-
- exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
- }
- var query = StudentsOrderDAL.GetStudentsOrderGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- var result = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).Distinct().OrderBy(x => x.CreateTime).ToGridResultSet<StudentsOrderView>(pageIndex, pageSize);
- var specialtyPlanIDLists = result.rows.Select(x => x.SpecialtyPlanID).ToList();
- List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolViews;
- //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
- Expression<Func<EM_SpecialtyPlan, bool>> expSps = (w => true);
- if (schoolyearID.HasValue)
- {
- expSps = expSps.And(w => w.SchoolyearID == schoolyearID);
- }
- if (grademajorID.HasValue)
- {
- expSps = expSps.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (collegeID.HasValue)
- {
- expSps = expSps.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
- }
- if (coursematerialID.HasValue)
- {
- expSps = expSps.And(w => w.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (pageSize <= 20)
- {
- teachingMaterialPoolViews = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDLists.Contains(x.SpecialtyPlanID), w => true).ToList();
- }
- else
- {
- teachingMaterialPoolViews = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDLists.Contains(x.SpecialtyPlanID), expSps).Distinct().ToList();
- }
- result.rows.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolViews.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID).Distinct()));
- return result;
- }
- var resultSet = this.GetQueryByDataRangeByCollege(query).Distinct().OrderBy(x => x.SchoolyearCode).
- ThenByDescending(x => x.GrademajorCode).ToGridResultSet<StudentsOrderView>(pageIndex, pageSize);//.ThenByDescending(x => x.TeachingMaterialCode)
- var specialtyPlanIDList = resultSet.rows.Select(x => x.SpecialtyPlanID).ToList();
- List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolView;
- //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
- Expression<Func<EM_SpecialtyPlan, bool>> expSp = (w => true);
- if (schoolyearID.HasValue)
- {
- expSp = expSp.And(w => w.SchoolyearID == schoolyearID);
- }
- if (grademajorID.HasValue)
- {
- expSp = expSp.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (collegeID.HasValue)
- {
- expSp = expSp.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
- }
- if (coursematerialID.HasValue)
- {
- expSp = expSp.And(w => w.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (pageSize <= 20)
- {
- teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), w => true).ToList();
- }
- else
- {
- teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), expSp).Distinct().ToList();
- }
- resultSet.rows.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID).Distinct()));
- return resultSet;
- }
- #endregion
- #region 2.0 生成征订计划
- /// <summary>
- /// 生成征订计划
- /// </summary>
- /// <param name="schoolyearID"></param>
- public void CreateStudentOrder(Guid schoolyearID, Guid userID)
- {
- //Stopwatch sw = new Stopwatch();//记录代码运行时间
- //Stopwatch sw2 = new Stopwatch();//记录代码运行时间
- try
- {
- //sw.Start();
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- var planIdsList = StudentsOrderDAL.GetSpecialtyPlanBySchool(schoolyearID);
- var specialtyIdsList = planIdsList.Select(x => x.SpecialtyPlanID).ToList();
- var dbList = StudentsOrderDAL.GetStudentsOrderGridView(exp);
- var dbIdList = dbList.Select(x => x.SpecialtyPlanID).ToList();
- var newIdList = specialtyIdsList.Except(dbIdList).ToList();
- //if (specialtyIdsList.Count > 0)
- //{
- // UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyIdsList.Contains(x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
- // //sw.Stop();
- //}
- //先删除再增加的做法不合适
- //TimeSpan TotalTime = sw.Elapsed;//sw.Elapsed记录了刚刚运行的代码段总时间
- var planQuery = StudentsOrderDAL.GetStudentsOrderBySpecialtyPlan(schoolyearID);
- var newplanQuery = planQuery.Where(x => newIdList.Contains(x.SpecialtyPlanID));
- List<StudentOrderPrePlanView> planList = this.GetQueryByDataRangeByCollege(newplanQuery).ToList();
- #region 0.0 废弃
- //foreach (var planView in planList)
- //{
- // var studentsOrderList = (from a in StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.TeachingMaterialPoolID == planView.TeachingMaterialPoolID)
- // group a by new { a.TeachingMaterialPoolID, a.SpecialtyPlanID, a.IsOrdered } into g
- // select new { SpecialtyPlanID = g.Key.SpecialtyPlanID, TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID, g.Key.IsOrdered }).ToList();
- // bool IsCreate = true;
- // foreach (var studentsOrder in studentsOrderList)
- // {
- // if (studentsOrder.IsOrdered != true)//已提交
- // {
- // IsCreate = false;
- // }
- // }
- // //如果该专业计划对应的课程信息 已提交、 那么可以再次生成、
- // if (IsCreate)
- // {
- // }
- // var StudentsOrderEntity = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == planView.SpecialtyPlanID && x.IsOrdered == false).FirstOrDefault();
- // if (StudentsOrderEntity != null && planView.TeachingMaterialPoolID != null)
- // {
- // StudentsOrderEntity.TeachingMaterialPoolID = planView.TeachingMaterialPoolID;
- // StudentsOrderEntity.ModifyTime = DateTime.Now;
- // StudentsOrderRepository.UnitOfWork.Update(StudentsOrderEntity);
- // }
- // else
- // {
- // var studentOrder = new ET_StudentsOrder
- // {
- // StudentsOrderID = Guid.NewGuid(),
- // IsOrdered = false,
- // OrderQty = planView.OrderQty.GetValueOrDefault(),
- // SpecialtyPlanID = planView.SpecialtyPlanID,
- // TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
- // CreateTime = DateTime.Now,
- // CreateUserID = userID,
- // ModifyUserID = userID,
- // ModifyTime = DateTime.Now
- // };
- // StudentsOrderRepository.UnitOfWork.Add(studentOrder);
- // }
- //}
- //StudentsOrderRepository.UnitOfWork.Commit();
- #endregion
- List<ET_StudentsOrder> listStudentsOrder = new List<ET_StudentsOrder>();//学生征订集合
- // sw2.Start();
- foreach (var planView in planList)
- {
- var studentOrder = new ET_StudentsOrder
- {
- StudentsOrderID = Guid.NewGuid(),
- IsOrdered = false,
- OrderQty = planView.OrderQty.GetValueOrDefault(),
- SpecialtyPlanID = planView.SpecialtyPlanID,
- TeachingMaterialPoolID = planView.TeachingMaterialPoolID,
- CreateTime = DateTime.Now,
- CreateUserID = userID,
- ModifyUserID = userID,
- ModifyTime = DateTime.Now
- };
- listStudentsOrder.Add(studentOrder);
- // StudentsOrderRepository.UnitOfWork.Add(studentOrder);
- }
- UnitOfWork.BulkInsert(listStudentsOrder);
- // StudentsOrderRepository.UnitOfWork.Commit();
- //sw2.Stop();
- //TimeSpan TotalTime2 = sw2.Elapsed;//sw.Elapsed记录了刚刚运行的代码段总时间
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 3.0 指定征订教材
- /// <summary>
- /// 指定征订教材
- /// </summary>
- /// <param name="studentsOrderID"></param>
- /// <param name="teachingMaterialPoolID"></param>
- /// <param name="userID"></param>
- public void SpecifiedTeachingMaterialPool(List<Guid> studentsOrderID, List<Guid> teachingMaterialPoolID, List<Guid> specialtyPlanID, Guid userID)
- {
- try
- {
- List<ET_StudentsOrder> listStudentsOrder = new List<ET_StudentsOrder>();//学生征订集合
- //List<int> PreIncreaseQty = new List<int>();
- Hashtable QtyPre = new Hashtable();
- //指定教材后预加数量不变
- if (studentsOrderID.Count() > 0)
- {
- foreach (var ID in specialtyPlanID)
- {
- ET_StudentsOrder order = new ET_StudentsOrder();
- order = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == ID).FirstOrDefault();
- if (order != null)
- {
- //int qty = (int)(order.PreIncreaseQty == null ? 0 : order.PreIncreaseQty);
- QtyPre.Add(order.SpecialtyPlanID, order.PreIncreaseQty);
- }
- }
- }
- // var studentOrders = StudentsOrderDAL.GetStudentsOrderListByStudentsOrderIDs(studentsOrderID);
- List<EM_SpecialtyPlan> specialtyPlanList = SpecialtyPlanRepository.GetList(x => specialtyPlanID.Contains(x.SpecialtyPlanID), (x => x.CF_Grademajor), (x => x.EM_Coursematerial.CF_TeachingMaterialPool), (x => x.CF_Grademajor.CF_Classmajor)).ToList();
- // int studentCount = specialtyPlanEntity.CF_Grademajor.CF_Classmajor.Select(w => w.CF_Student).Count();
- if (specialtyPlanID.Count > 0)
- {
- UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyPlanID.Contains(x.SpecialtyPlanID));//先删除、在生成、防止教材没有更新进去
- }
- if (specialtyPlanList.Count > 0)
- {
- foreach (var specialtyPlan in specialtyPlanList)
- {
- var ClassmajorIDList = specialtyPlan.CF_Grademajor.CF_Classmajor.Select(x => x.ClassmajorID).ToList();
- // var ClassmajorList = ClassmajorRepository.GetList(x => ClassmajorIDList.Contains(x.ClassmajorID), x => x.CF_Student).ToList();
-
- var studentCount = StudentRepository.Value.GetList(x => ClassmajorIDList.Contains((Guid)x.ClassmajorID)).Where(x => x.InSchoolStatusID==1).Count();
- //只获取在校的学生人数
- var specialtyTeachingMaterialPoolList = teachingMaterialPoolID;
- specialtyTeachingMaterialPoolList.ForEach(x =>
- {
- var studentOrder = new ET_StudentsOrder
- {
- StudentsOrderID = Guid.NewGuid(),
- IsOrdered = false,
- OrderQty = studentCount,
- PreIncreaseQty = (int?)QtyPre[specialtyPlan.SpecialtyPlanID],
- SpecialtyPlanID = specialtyPlan.SpecialtyPlanID,
- TeachingMaterialPoolID = x,
- CreateTime = DateTime.Now,
- CreateUserID = userID,
- ModifyUserID = userID,
- ModifyTime = DateTime.Now
- };
- listStudentsOrder.Add(studentOrder);
- });
- }
- }
- UnitOfWork.BulkInsert(listStudentsOrder);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 4.0 删除征订的信息
- /// <summary>
- /// 删除征订的信息
- /// </summary>
- /// <param name="publishID"></param>
- public void DeleteStudentsOrders(List<Guid> specialtyPlanIDs)
- {
- try
- {
- //屏蔽已提交状态不可删除代码段
- //var stidentsOrderList = StudentsOrderRepository.GetList(x => studentsOrderIDs.Contains(x.StudentsOrderID)).ToList();
- //foreach (var stidentsOrder in stidentsOrderList)
- //{
- // if (stidentsOrder.IsOrdered == true)
- // {
- // throw new Exception("勾选信息包含已征订状态,不能删除!");
- // }
- //}
- UnitOfWork.Delete<ET_StudentsOrder>(x => specialtyPlanIDs.Contains(x.SpecialtyPlanID));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 5.0 确认征订
- /// <summary>
- /// 确认征订
- /// </summary>
- /// <param name="studentsOrderID"></param>
- /// <param name="teachingMaterialPoolID"></param>
- /// <param name="userID"></param>
- public void ComfirmStudentOrder(List<Guid> specialtyPlanIs, Guid userID)
- {
- try
- {
- var studentOrders = StudentsOrderRepository.GetList(x => specialtyPlanIs.Contains(x.SpecialtyPlanID)).ToList();
- if (studentOrders.Any(x => x.TeachingMaterialPoolID == null))
- {
- throw new Exception("勾选的征订计划中,存在教材未指定。");
- }
- if (studentOrders.Any(x => x.IsOrdered == true))
- {
- throw new Exception("勾选的征订计划中,存在已征订状态。");
- }
- foreach (var studentOrder in studentOrders)
- {
- studentOrder.IsOrdered = true;
- studentOrder.ModifyTime = DateTime.Now;
- studentOrder.ModifyUserID = userID;
- }
- foreach (var studentsOrder in studentOrders.ToList())
- {
- UnitOfWork.Update(studentsOrder);
- }
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 6.0 查询学生征订记录(导出)
- /// <summary>
- /// 查询学生征订记录(导出)
- /// </summary>
- public IList<StudentsOrderView> GetStudentsOrderViewExcle(ViewModel.ConfiguretView configuretView, Guid? campusID,
- Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID)
- {
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (teachingMaterialID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (years.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (courseCategoryID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
- }
- if (isOrdered.HasValue && isOrdered > -1)
- {
- exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
- }
- var query = StudentsOrderDAL.GetStudentsOrderGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToList();
- // this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToList();
- var resultSet = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToList();//.ThenByDescending(x => x.TeachingMaterialCode)
- Expression<Func<EM_SpecialtyPlan, bool>> expSp = (w => true);
- var specialtyPlanIDList = resultSet.Select(x => x.SpecialtyPlanID).ToList();
- List<SpecialtyPlanTeachingMaterPoolView> teachingMaterialPoolView;
- //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出
- if (schoolyearID.HasValue)
- {
- expSp = expSp.And(w => w.SchoolyearID == schoolyearID);
- }
- if (grademajorID.HasValue)
- {
- expSp = expSp.And(w => w.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (collegeID.HasValue)
- {
- expSp = expSp.And(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
- }
- if (coursematerialID.HasValue)
- {
- expSp = expSp.And(w => w.EM_Coursematerial.CoursematerialID == collegeID);
- }
- if (resultSet.Count() <= 20)
- {
- teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), w => true).ToList();
- }
- else
- {
- teachingMaterialPoolView = StudentsOrderDAL.GetSpecialtyPlanTeachingMaterPoolView(x => specialtyPlanIDList.Contains(x.SpecialtyPlanID), expSp).ToList();
- }
- resultSet.ForEach(x => x.SpecialtyPlanTeachingMaterPoolViewList = new HashSet<SpecialtyPlanTeachingMaterPoolView>(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID)));
- return resultSet;
- }
- #endregion
- #region 7.0 学生征订统计
- /// <summary>
- /// 学生征订统计
- /// </summary>
- public IGridResultSet<StudentsOrderShowReportView> GetStudentsOrderStatisticalViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
- Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID,
- int pageIndex, int pageSize)
- {
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (teachingMaterialPoolID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (publishID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.CF_Publish.PublishID == publishID);
- }
- var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp.And(x => x.IsOrdered == true));
- //if (campusID.HasValue)
- // query = query.Where(x => x.CampusID == campusID);
- //if (collegeID.HasValue)
- // query = query.Where(x => x.CollegeID == collegeID);
- //if (schoolyearID.HasValue)
- // query = query.Where(x => x.SchoolyearID == schoolyearID);
- //if (grademajorID.HasValue)
- // query = query.Where(x => x.GrademajorID == grademajorID);
- //if (coursematerialID.HasValue)
- // query = query.Where(x => x.CoursematerialID == coursematerialID);
- //if (teachingMaterialPoolID.HasValue)
- // query = query.Where(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
- //if (publishID.HasValue)
- // query = query.Where(x => x.PublishID == publishID);
- IQueryable<StudentsOrderDataReportView> preGroupSql = null;
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
- var studentsOrderShowReportView = (from pg in preGroupSql
- group pg by new
- {
- SchoolyearCode = pg.SchoolyearCode,
- CollegeName = pg.CollegeName,
- GrademajorName = pg.GrademajorName,
- CourseCode = pg.CourseCode,
- CourseName = pg.CourseName,
- TeachingMaterialCode = pg.TeachingMaterialCode,
- TeachingMaterialName = pg.TeachingMaterialName,
- ISBN = pg.ISBN,
- PublishTime = pg.PublishTime,
- PublishName = pg.PublishName,
- Author = pg.Author,
- Price = pg.Price,
- } into g
- select new StudentsOrderShowReportView
- {
- Price = g.Key.Price,
- Author = g.Key.Author,
- GrademajorName = g.Key.GrademajorName,
- CollegeName = g.Key.CollegeName,
- CourseCode = g.Key.CourseCode,
- CourseName = g.Key.CourseName,
- ISBN = g.Key.ISBN,
- PublishName = g.Key.PublishName,
- PublishTime = g.Key.PublishTime,
- SchoolyearCode = g.Key.SchoolyearCode,
- TeachingMaterialCode = g.Key.TeachingMaterialCode,
- OrderQty = g.Sum(x => x.OrderQty),
- PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
- Count = g.Sum(x => x.OrderQty) + (g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty)),
- ClassNum = g.Sum(x => x.ClassNum),
- TeachingMaterialName = g.Key.TeachingMaterialName
- }).OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.CollegeName).ThenBy(x => x.GrademajorName).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<StudentsOrderShowReportView>(pageIndex, pageSize);
- return studentsOrderShowReportView;
- }
- #endregion
- #region 8.0 学生征订统计(导出)
- /// <summary>
- /// 学生征订统计(导出)
- /// </summary>
- public IList<StudentsOrderShowReportView> GetStudentsOrderStatisticalExcel(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID,
- Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID)
- {
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (teachingMaterialPoolID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialPoolID);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (publishID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.CF_Publish.PublishID == publishID);
- }
- var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp.And(x => x.IsOrdered == true));
- IQueryable<StudentsOrderDataReportView> preGroupSql = null;
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
- var studentsOrderShowReportView = (from pg in preGroupSql
- group pg by new
- {
- SchoolyearCode = pg.SchoolyearCode,
- CollegeName = pg.CollegeName,
- GrademajorName = pg.GrademajorName,
- CourseCode = pg.CourseCode,
- CourseName = pg.CourseName,
- TeachingMaterialCode = pg.TeachingMaterialCode,
- TeachingMaterialName = pg.TeachingMaterialName,
- ISBN = pg.ISBN,
- PublishTime = pg.PublishTime,
- PublishName = pg.PublishName,
- PreIncreaseQty = pg.PreIncreaseQty,
- //Count = pg.Count,
- Author = pg.Author,
- Price = pg.Price
- } into g
- select new StudentsOrderShowReportView
- {
- Author = g.Key.Author,
- GrademajorName = g.Key.GrademajorName,
- CollegeName = g.Key.CollegeName,
- CourseCode = g.Key.CourseCode,
- CourseName = g.Key.CourseName,
- ISBN = g.Key.ISBN,
- PublishName = g.Key.PublishName,
- PublishTime = g.Key.PublishTime,
- Price = g.Key.Price,
- SchoolyearCode = g.Key.SchoolyearCode,
- TeachingMaterialCode = g.Key.TeachingMaterialCode,
- PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
- Count = g.Sum(x => x.OrderQty) + (g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty)),
- OrderQty = g.Sum(x => x.OrderQty),
- ClassNum = g.Sum(x => x.ClassNum),
- TeachingMaterialName = g.Key.TeachingMaterialName
- }).OrderBy(x => x.GrademajorName).ToList();
- return studentsOrderShowReportView;
- }
- #endregion
- /// <summary>
- /// 批量添加预加设置
- /// </summary>
- /// <param name="teachersOrderList"></param>
- /// <param name="preAddedValue"></param>
- /// <param name="userId"></param>
- public void BatchUpdatePreAddedValue(List<StudentsOrderView> studentsOrderList, int preAddedValue, Guid userId)
- {
- try
- {
- if (studentsOrderList.Count > 0)
- {
- //int? ApprovalStatus = (int)CF_TeachersOrderStatus.Completed;//提取已通过
- foreach (var studentsOrder in studentsOrderList)
- {
- var studentsPreOrderEnt = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == studentsOrder.SpecialtyPlanID);//.FirstOrDefault();//&& x.SchoolyearID == teachersOrder.SchoolyearID && x.ApprovalStatus == ApprovalStatus
- foreach (var s in studentsPreOrderEnt)
- {
- ET_StudentsOrder studentsPreOrder = s;
- studentsPreOrder.ModifyTime = DateTime.Now;
- studentsPreOrder.ModifyUserID = userId;
- //studentsPreOrder.Desc = "预加值";
- studentsPreOrder.PreIncreaseQty = preAddedValue;//设置预加值;
- StudentsOrderRepository.UnitOfWork.Update(studentsPreOrder);
- }
-
- }
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 修改征订数量
- /// </summary>
- /// <param name="teachersOrderList"></param>
- /// <param name="preAddedValue"></param>
- /// <param name="userId"></param>
- public void UpdateOrderQty(List<StudentsOrderView> studentsOrderList, int orderQty, Guid userId)
- {
- try
- {
- if (studentsOrderList.Count > 0)
- {
- //int? ApprovalStatus = (int)CF_TeachersOrderStatus.Completed;//提取已通过
- foreach (var studentsOrder in studentsOrderList)
- {
- var studentsPreOrderEnt = StudentsOrderRepository.Entities.Where(x => x.SpecialtyPlanID == studentsOrder.SpecialtyPlanID);//.FirstOrDefault();//&& x.SchoolyearID == teachersOrder.SchoolyearID && x.ApprovalStatus == ApprovalStatus
- foreach (var s in studentsPreOrderEnt)
- {
- ET_StudentsOrder studentsPreOrder = s;
- studentsPreOrder.ModifyTime = DateTime.Now;
- studentsPreOrder.ModifyUserID = userId;
- //studentsPreOrder.Desc = "预加值";
- studentsPreOrder.OrderQty = orderQty;//设置预加值;
- StudentsOrderRepository.UnitOfWork.Update(studentsPreOrder);
- }
- }
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public IList<StudentsOrderShowReportView> GetStudentsOrderViewAggregateExcle(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID)
- {
- Expression<Func<ET_StudentsOrder, bool>> exp = x => true;
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
- }
- if (teachingMaterialID.HasValue)
- {
- exp = exp.And(x => x.CF_TeachingMaterialPool.TeachingMaterialPoolID == teachingMaterialID);
- }
- if (campusID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.CF_Facultymajor.CF_College.CollegeID == collegeID);
- }
- if (years.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GradeID == years);
- }
- if (grademajorID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CF_Grademajor.GrademajorID == grademajorID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.EM_Coursematerial.CoursematerialID == coursematerialID);
- }
- if (courseCategoryID.HasValue)
- {
- exp = exp.And(x => x.EM_SpecialtyPlan.CourseCategoryID == courseCategoryID);
- }
- if (isOrdered.HasValue && isOrdered > -1)
- {
- exp = exp.And(x => x.IsOrdered == (isOrdered == (int)CF_YesOrNoStatus.No ? false : true));
- }
- var query = StudentsOrderDAL.GetStudentsOrderStatisticalView(exp);
- IQueryable<StudentsOrderDataReportView> preGroupSql = null;
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- preGroupSql = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- }
- else { preGroupSql = this.GetQueryByDataRangeByCollege(query); }
- var studentsOrderShowReportView = (from pg in preGroupSql
- group pg by new
- {
- SchoolyearCode = pg.SchoolyearCode,
- CollegeName = pg.CollegeName,
- GrademajorName = pg.GrademajorName,
- CourseCode = pg.CourseCode,
- CourseName = pg.CourseName,
- TeachingMaterialCode = pg.TeachingMaterialCode,
- TeachingMaterialName = pg.TeachingMaterialName,
- ISBN = pg.ISBN,
- PublishTime = pg.PublishTime,
- PublishName = pg.PublishName,
- Author = pg.Author,
- Price = pg.Price,
- TeachingMaterialTypeID = pg.TeachingMaterialTypeID,
- } into g
- select new StudentsOrderShowReportView
- {
- Author = g.Key.Author,
- GrademajorName = g.Key.GrademajorName,
- CollegeName = g.Key.CollegeName,
- CourseCode = g.Key.CourseCode,
- CourseName = g.Key.CourseName,
- ISBN = g.Key.ISBN,
- PublishName = g.Key.PublishName,
- PublishTime = g.Key.PublishTime,
- SchoolyearCode = g.Key.SchoolyearCode,
- TeachingMaterialCode = g.Key.TeachingMaterialCode,
- OrderQty = g.Sum(x => x.OrderQty),
- Count = g.Sum(x => x.Count),
- PreIncreaseQty = g.Sum(x => x.PreIncreaseQty) == null ? 0 : g.Sum(x => x.PreIncreaseQty),
- ClassNum = g.Sum(x => x.ClassNum),
- TeachingMaterialName = g.Key.TeachingMaterialName,
- Price = g.Key.Price,
- TeachingMaterialTypeID = g.Key.TeachingMaterialTypeID
- }).OrderBy(x => x.GrademajorName).ToList();
- return studentsOrderShowReportView;
- }
- }
- }
- #endregion
|