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 { 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 查询学生征订记录 /// /// 查询学生征订记录 /// public IGridResultSet 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> 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(pageIndex, pageSize); var specialtyPlanIDLists = result.rows.Select(x => x.SpecialtyPlanID).ToList(); List teachingMaterialPoolViews; //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出 Expression> 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(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(pageIndex, pageSize);//.ThenByDescending(x => x.TeachingMaterialCode) var specialtyPlanIDList = resultSet.rows.Select(x => x.SpecialtyPlanID).ToList(); List teachingMaterialPoolView; //基于性能考虑,如果单页数据少于20,则用ID匹配比较好,否则,只能按查询条件列出 Expression> 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(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID).Distinct())); return resultSet; } #endregion #region 2.0 生成征订计划 /// /// 生成征订计划 /// /// public void CreateStudentOrder(Guid schoolyearID, Guid userID) { //Stopwatch sw = new Stopwatch();//记录代码运行时间 //Stopwatch sw2 = new Stopwatch();//记录代码运行时间 try { //sw.Start(); Expression> 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(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 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 listStudentsOrder = new List();//学生征订集合 // 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 指定征订教材 /// /// 指定征订教材 /// /// /// /// public void SpecifiedTeachingMaterialPool(List studentsOrderID, List teachingMaterialPoolID, List specialtyPlanID, Guid userID) { try { List listStudentsOrder = new List();//学生征订集合 //List PreIncreaseQty = new List(); 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 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(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 删除征订的信息 /// /// 删除征订的信息 /// /// public void DeleteStudentsOrders(List 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(x => specialtyPlanIDs.Contains(x.SpecialtyPlanID)); } catch (Exception ex) { throw ex; } } #endregion #region 5.0 确认征订 /// /// 确认征订 /// /// /// /// public void ComfirmStudentOrder(List 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 查询学生征订记录(导出) /// /// 查询学生征订记录(导出) /// public IList GetStudentsOrderViewExcle(ViewModel.ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID) { Expression> 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> expSp = (w => true); var specialtyPlanIDList = resultSet.Select(x => x.SpecialtyPlanID).ToList(); List 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(teachingMaterialPoolView.Where(y => y.SpecialtyPlanID == x.SpecialtyPlanID))); return resultSet; } #endregion #region 7.0 学生征订统计 /// /// 学生征订统计 /// public IGridResultSet GetStudentsOrderStatisticalViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID, int pageIndex, int pageSize) { Expression> 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 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(pageIndex, pageSize); return studentsOrderShowReportView; } #endregion #region 8.0 学生征订统计(导出) /// /// 学生征订统计(导出) /// public IList GetStudentsOrderStatisticalExcel(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? grademajorID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID) { Expression> 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 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 /// /// 批量添加预加设置 /// /// /// /// public void BatchUpdatePreAddedValue(List 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; } } /// /// 修改征订数量 /// /// /// /// public void UpdateOrderQty(List 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 GetStudentsOrderViewAggregateExcle(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? years, Guid? grademajorID, Guid? coursematerialID, int? courseCategoryID, int? isOrdered, Guid? schoolyearID, Guid? teachingMaterialID) { Expression> 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 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