123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.DQPSystem;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.DQPSystem;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using Bowin.Common.Linq;
- using EMIS.ViewModel.Students;
- namespace EMIS.CommonLogic.DQPSystem
- {
- public class SOCDetailGroupServices : BaseServices, ISOCDetailGroupServices
- {
- public SOCDAL SOCDAL { get; set; }
- public SOCDetailGroupDAL SOCDetailGroupDAL { get; set; }
- public IGridResultSet<SOCDetailView> GetSOCDetailViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, int? schoolyearNumID, int? standardID, Guid? coursematerialID, int pageIndex, int pageSize)
- {
- Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == curUser.UserID));
- exp = exp.And(x => x.IsGroup == true);
- if (schoolyearID.HasValue)
- {
- exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- //exp = exp.And(x => x.DQP_SOC == collegeID);
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.DQP_SOC.CoursematerialID == coursematerialID);
- }
- if (!curUser.IsStudent)
- {
- exp = exp.And(x => x.CreateUserID == curUser.UserID);
- }
- var query = SOCDAL.GetSOCDetailViewQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- var result = query
- .OrderBy(x => x.SOCID)
- .ThenBy(x => x.Name.Length).ThenBy(x => x.Name)
- .ToGridResultSet<SOCDetailView>(pageIndex, pageSize);
- return result;
- }
- public IGridResultSet<SOCDetailGroupView> GetSOCDetailGroupViewGrid(ConfiguretView configuretView, Guid? detailID, int pageIndex, int pageSize)
- {
- Expression<Func<DQP_SOCDetailGroup, bool>> exp = x => true;
- if (detailID.HasValue)
- {
- exp = exp.And(x => x.SOCDetailID == detailID);
- }
- var query = SOCDetailGroupDAL.GetSOCDetailGroupViewQueryable(exp);
- return query.OrderBy(x => x.No).ToGridResultSet<SOCDetailGroupView>(pageIndex, pageSize);
- }
- public List<SOCDetailGroupView> GetSOCDetailGroupViewList(ConfiguretView configuretView, Guid? detailID)
- {
- Expression<Func<DQP_SOCDetailGroup, bool>> exp = x => true;
- if (detailID.HasValue)
- {
- exp = exp.And(x => x.SOCDetailID == detailID);
- }
- var query = SOCDetailGroupDAL.GetSOCDetailGroupViewQueryable(exp);
- return query.OrderBy(x => x.No).ToList();
- }
- public GroupSOCDetailView GetGroupSOCDetailViewGrid(Guid? detailID)
- {
- Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
- if (detailID.HasValue)
- {
- exp = exp.And(x => x.SOCDetailID == detailID);
- }
- var query = SOCDetailGroupDAL.GetGroupSOCDetailViewQueryable(exp);
- return query.FirstOrDefault();
- }
- public void GroupSOCDetailSave(GroupSOCDetailView groupSOCDetailView)
- {
- try
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- Expression<Func<DQP_SOC, bool>> exp = x => true;
- if (groupSOCDetailView != null)
- {
- List<DQP_SOCDetailGroup> SOCDetailGroupList = new List<DQP_SOCDetailGroup>();
- exp = exp.And(x => x.DQP_SOCDetail.Any(y => y.SOCDetailID == groupSOCDetailView.SOCDetailID));
- var dbSOCDetailGroupList = SOCDetailGroupDAL.SOCDetailGroupRepository.GetList(x => x.SOCDetailID == groupSOCDetailView.SOCDetailID).ToList() ;
- //var query = SOCDetailGroupDAL.SOCRepository.GetList(exp, (x => x.DQP_SOCStaff.FirstOrDefault(y => y.UserID == curUser.UserID).CF_Student), (x => x.DQP_SOCStaff.FirstOrDefault(y => y.UserID == curUser.UserID).CF_Student.Select(w => w.Sys_User))).ToList();
- var stuIDList = SOCDetailGroupDAL.GetStudentListForGroup(groupSOCDetailView.SOCDetailID).Select(x => x.UserID).ToList();
- var stuList = SOCDetailGroupDAL.studentRepository.GetList(x => stuIDList.Contains(x.UserID), x => x.Sys_User).ToList();
- var stuOrderLoginID = stuList.OrderBy(x => x.ClassmajorID).ThenBy(x => x.Sys_User.LoginID).ToList();
- var stuCount = stuList.Count();
- if (!groupSOCDetailView.IsManual)
- {
- //不是手动分组的,删掉原来的再重新分组
- //UnitOfWork.Delete<DQP_SOCDetailGroup>(x => x.SOCDetailID == groupSOCDetailView.SOCDetailID);
- var socDetailGroupList = SOCDetailGroupDAL.SOCDetailGroupRepository.GetList(x => x.SOCDetailID == groupSOCDetailView.SOCDetailID, x => x.CF_Student);
- //删除学生
- foreach (var socdetailGroup in socDetailGroupList)
- {
- socdetailGroup.CF_Student = new HashSet<CF_Student>();
- }
- UnitOfWork.Remove<DQP_SOCDetailGroup>(x => x.SOCDetailID == groupSOCDetailView.SOCDetailID);
- UnitOfWork.Commit();
- if (groupSOCDetailView.GroupByGroup)
- {
- var groupnum = groupSOCDetailView.GroupNum;
- var other = stuCount % groupnum;
- var stunum = stuCount / groupnum;
- for (var i = 0; i < groupnum; i++)
- {
- DQP_SOCDetailGroup SOCDetailGroup = new DQP_SOCDetailGroup();
- SOCDetailGroup.SOCDetailGroupID = Guid.NewGuid();
- SOCDetailGroup.SOCDetailID = groupSOCDetailView.SOCDetailID;
- SOCDetailGroup.No = (i + 1);
- this.SetNewStatus(SOCDetailGroup);
- if (groupSOCDetailView.IsStudentNo)
- {
- if (other != 0 && (i + 1) == groupnum)
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuOrderLoginID.Take((stunum + other) ?? 0).ToList());
- }
- else
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuOrderLoginID.Take(stunum ?? 0).ToList());
- stuOrderLoginID = stuOrderLoginID.Skip(stunum ?? 0).ToList();
- }
- }
- else if (groupSOCDetailView.IsRandom)
- {
- if (other != 0 && (i + 1) == groupnum)
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuList.Take((stunum + other) ?? 0).ToList());
- }
- else
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuList.Take(stunum ?? 0).ToList());
- stuList = stuList.Skip(stunum ?? 0).ToList();
- }
- }
- SOCDetailGroupList.Add(SOCDetailGroup);
- }
- }
- else if (groupSOCDetailView.GroupByStudent)
- {
- var stuNum = groupSOCDetailView.StudentNum;
- var other = stuCount % stuNum;
- var groupNum = stuCount / stuNum;
- for (var i = 0; i < groupNum; i++)
- {
- DQP_SOCDetailGroup SOCDetailGroup = new DQP_SOCDetailGroup();
- SOCDetailGroup.SOCDetailGroupID = Guid.NewGuid();
- SOCDetailGroup.SOCDetailID = groupSOCDetailView.SOCDetailID;
- SOCDetailGroup.No = (i + 1);
- this.SetNewStatus(SOCDetailGroup);
- if (groupSOCDetailView.IsStudentNo)
- {
- if (other != 0 && (i + 1) == groupNum)
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuOrderLoginID.Take((stuNum + other) ?? 0).ToList());
- }
- else
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuOrderLoginID.Take(stuNum ?? 0).ToList());
- stuOrderLoginID = stuOrderLoginID.Skip(stuNum ?? 0).ToList();
- }
- }
- else if (groupSOCDetailView.IsRandom)
- {
- if (other != 0 && (i + 1) == groupNum)
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuList.Take((stuNum + other) ?? 0).ToList());
- }
- else
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>(stuList.Take(stuNum ?? 0).ToList());
- stuList = stuList.Skip(stuNum ?? 0).ToList();
- }
- }
- SOCDetailGroupList.Add(SOCDetailGroup);
- }
- }
- }
- else if (groupSOCDetailView.IsManual)
- {
- var dbnum = dbSOCDetailGroupList.Max(x => x.No) == null ? 0 : dbSOCDetailGroupList.Max(x => x.No);
- var GroupNo = dbnum + 1;
- var groupNum = groupSOCDetailView.GroupNum;
- for (var i = 0; i < groupNum; i++)
- {
- DQP_SOCDetailGroup SOCDetailGroup = new DQP_SOCDetailGroup();
- SOCDetailGroup.SOCDetailGroupID = Guid.NewGuid();
- SOCDetailGroup.SOCDetailID = groupSOCDetailView.SOCDetailID;
- SOCDetailGroup.No = GroupNo;
- this.SetNewStatus(SOCDetailGroup);
- SOCDetailGroupList.Add(SOCDetailGroup);
- GroupNo++;
- }
- }
- UnitOfWork.BulkInsert(SOCDetailGroupList);
- UnitOfWork.BulkInsert(SOCDetailGroupList, x => x.CF_Student);
- }
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public SOCDetailGroupView GetSOCDetailGroupView(Guid? SOCDetailGroupID)
- {
- var socDetailGroupView = SOCDetailGroupDAL.GetSOCDetailGroupViewQueryable(x => x.SOCDetailGroupID == SOCDetailGroupID).FirstOrDefault();
- return socDetailGroupView;
- }
- public IGridResultSet<BaseStudentView> GetSOCDetailGroupStudent(Guid? SOCDetailGrpuoID)
- {
- return SOCDetailGroupDAL.GetSOCDetailGroupViewStudentList(SOCDetailGrpuoID).OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>();
- }
- public void SOCDetailGroupStudentAdd(Guid? SOCDetailGroupID, List<BaseStudentView> listBaseStudentView)
- {
- if (SOCDetailGroupID.HasValue)
- {
- if (listBaseStudentView.Count > 0)
- {
- var SOCDetailGroup = SOCDetailGroupDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == SOCDetailGroupID, x => x.CF_Student);
- var StuIDList = listBaseStudentView.Select(x => x.UserID).ToList();
- var studentList = SOCDetailGroupDAL.studentRepository.GetList(x => StuIDList.Contains(x.UserID)).ToList();
- if (SOCDetailGroup != null)
- {
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>();
- foreach (var student in studentList)
- {
- SOCDetailGroup.CF_Student.Add(student);
- }
- }
- }
- else {
- var SOCDetailGroup = SOCDetailGroupDAL.SOCDetailGroupRepository.GetSingle(x => x.SOCDetailGroupID == SOCDetailGroupID, x => x.CF_Student);
- SOCDetailGroup.CF_Student = new HashSet<CF_Student>();
- }
- UnitOfWork.Commit();
- }
- }
- public IGridResultSet<BaseStudentView> GetNotGroupStudent(ConfiguretView configuretView, Guid? SOCDetailGrpuoID)
- {
- var query = SOCDetailGroupDAL.GetNotGroupStudentList(SOCDetailGrpuoID);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.LoginID).ToGridResultSet<BaseStudentView>();
- }
- public void SOCDetailGroupDelete(List<Guid?> idList)
- {
- try
- {
- if (idList.Count > 0)
- {
- var socDetailGroupList = SOCDetailGroupDAL.SOCDetailGroupRepository.GetList(x => idList.Contains(x.SOCDetailGroupID), x => x.CF_Student);
- //删除学生
- foreach (var socdetailGroup in socDetailGroupList)
- {
- socdetailGroup.CF_Student = new HashSet<CF_Student>();
- }
-
- UnitOfWork.Remove<DQP_SOCDetailGroup>(x => idList.Contains(x.SOCDetailGroupID));
- UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public List<Guid?> GetUserIDByGroupID(List<Guid> groupIDList)
- {
- var groupList = SOCDetailGroupDAL.SOCDetailGroupRepository.GetList(x => groupIDList.Contains(x.SOCDetailGroupID), (x => x.CF_Student));
- List<Guid?> userIDList = new List<Guid?>();
- foreach (var group in groupList)
- {
- foreach (var stu in group.CF_Student)
- {
- userIDList.Add(stu.UserID);
- }
- }
- return userIDList.Distinct().ToList();
- }
- }
- }
|