using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.Students.HighBaseTable; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; namespace EMIS.CommonLogic.Students.HighBaseTable { public class StudentChangeServices : BaseServices, IStudentChangeServices { public StudentChangeDAL StudentChangeDAL { get; set; } public Lazy WorkflowServices { get; set; } public void GenerateReport(int year) { var endStatusID = WorkflowServices.Value.GetCorrectEndStatus(typeof(CF_DifferentDynamic).Name); //获取上学年初报表在校生数 var lastReportList = StudentChangeDAL.GetLastInschoolStudentCount(year).ToList(); //获取招生数 var recruitStudentList = StudentChangeDAL.GetRecruitStudentCount(year).ToList(); //获取毕业数 var graduationStudentList = StudentChangeDAL.GetGraduationStudentCount(year).ToList(); //获取结业数 var graduationOverStudentList = StudentChangeDAL.GetGraduationOverStudentCount(year).ToList(); //获取本学期报表在校学生数 var currentStudentList = StudentChangeDAL.GetCurrentInschoolStudentCount().ToList(); //获取异动学生数 var studentChangeList = StudentChangeDAL.GetStudentChangeCount(year, endStatusID).ToList(); this.UnitOfWork.Remove(x => x.HB_StudentChange.Year == year); this.UnitOfWork.Remove(x => x.Year == year); #region 合并各种主表数据,并生成主表实体 var studentChangeTableList = lastReportList .Select(x => new { x.EducationTypeID, LastInschoolCount = x.CurrentInschoolCount, RecruitCount = (int?)0, GraduationCount = (int?)0, CompleteCount = (int?)0, CurrentInschoolCount = (int?)0 }).Concat(recruitStudentList .Select(x => new { x.EducationTypeID, LastInschoolCount = (int?)0, RecruitCount = x.StudentCount, GraduationCount = (int?)0, CompleteCount = (int?)0, CurrentInschoolCount = (int?)0 })).Concat(graduationStudentList .Select(x => new { x.EducationTypeID, LastInschoolCount = (int?)0, RecruitCount = (int?)0, GraduationCount = x.StudentCount, CompleteCount = (int?)0, CurrentInschoolCount = (int?)0 })).Concat(graduationOverStudentList .Select(x => new { x.EducationTypeID, LastInschoolCount = (int?)0, RecruitCount = (int?)0, GraduationCount = (int?)0, CompleteCount = x.StudentCount, CurrentInschoolCount = (int?)0 })).Concat(currentStudentList .Select(x => new { x.EducationTypeID, LastInschoolCount = (int?)0, RecruitCount = (int?)0, GraduationCount = (int?)0, CompleteCount = (int?)0, CurrentInschoolCount = x.StudentCount })) .GroupBy(x => x.EducationTypeID).Select(x => new HB_StudentChange { StudentChangeID = Guid.NewGuid(), Year = year, EducationTypeID = x.Key, LastInschoolCount = x.Sum(w => w.LastInschoolCount), RecruitCount = x.Sum(w => w.RecruitCount), GraduationCount = x.Sum(w => w.GraduationCount), CompleteCount = x.Sum(w => w.CompleteCount), CurrentInschoolCount = x.Sum(w => w.CurrentInschoolCount) }) .ToList(); #endregion studentChangeTableList.ForEach(x => { this.SetNewStatus(x); var detailList = studentChangeList.Where(w => w.EducationTypeID == x.EducationTypeID) .Select(w => new HB_StudentChangeDetail { StudentChangeDetailID = Guid.NewGuid(), StudentChangeID = x.StudentChangeID, DifferentDynamicType = w.DifferentDynamicType ?? 0, StudentInCount = w.StudentInCount, StudentOutCount = w.StudentOutCount }).ToList(); detailList.ForEach(w => this.SetNewStatus(w)); x.HB_StudentChangeDetail = new HashSet(detailList); this.UnitOfWork.Add(x); }); this.UnitOfWork.Commit(); } } }