using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq.Entity; using Bowin.Common.Linq; using EMIS.DataLogic.RetakeManage; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.RetakeManage; using EMIS.Utility; using EMIS.CommonLogic.SystemServices; using EMIS.ViewModel.EducationManage; using EMIS.DataLogic.EducationManage; using EMIS.CommonLogic.EducationSchedule; namespace EMIS.CommonLogic.RetakeManage { public class RetakePlanServices : BaseServices, IRetakePlanServices { public RetakeConditionDAL RetakeConditionDAL { get; set; } public Lazy ParameterServices { get; set; } public void Generate() { var schoolyearID = ParameterServices.Value.GetParameterValue(CF_ParameterType.RetakeSchoolyearID); var retakeStudentViewQueryable = this.RetakeConditionDAL.GetRetakeStudentView(); var retakeConditionList = RetakeConditionDAL.GetRetakeConditionView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList(); foreach (var condition in retakeConditionList) { retakeStudentViewQueryable = (IQueryable)ReflectorHelper.RunDALMethod(condition.MethodFullName, retakeStudentViewQueryable); } var retakeStudentViewList = retakeStudentViewQueryable.ToList(); var retakePlanGroup = retakeStudentViewList .GroupBy(x => new { x.CoursematerialID, x.Abbreviation, x.CourseName, x.CourseTypeID, x.CourseTypeDesc, x.Credit }); var planInsertList = new List(); var planStudentInsertList = new List(); foreach (var retakePlan in retakePlanGroup) { var plan = new ER_RetakePlan { RetakePlanID = Guid.NewGuid(), CoursematerialID = retakePlan.Key.CoursematerialID, ClassName = (retakePlan.Key.Abbreviation ?? retakePlan.Key.CourseName) + "-重修(" + retakePlan.Key.CourseTypeDesc + string.Format("{0:#.00}", retakePlan.Key.Credit) + "学分)", SchoolyearID = schoolyearID, CourseTypeID = retakePlan.Key.CourseTypeID, Credit = retakePlan.Key.Credit }; this.SetNewStatus(plan); foreach (var retakePlanStudent in retakePlan.Select(w => w).ToList()) { var planStudent = new ER_RetakePlanStudent { RetakePlanStudentID = Guid.NewGuid(), RetakePlanID = plan.RetakePlanID, UserID = retakePlanStudent.UserID.Value, SchoolyearNumID = retakePlanStudent.SchoolyearNumID, StarttermID = retakePlanStudent.StarttermID }; this.SetNewStatus(planStudent); planStudentInsertList.Add(planStudent); } planInsertList.Add(plan); } UnitOfWork.BulkInsert(planInsertList); UnitOfWork.BulkInsert(planStudentInsertList); } } }