using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.CommonLogic.SystemServices; using EMIS.DataLogic.DQPSystem; using EMIS.ViewModel.DQPSystem; using Bowin.Common.Linq.Entity; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.DataLogic.CultureplanManage.PlanManagement; namespace EMIS.CommonLogic.DQPSystem { public class SOCTemplateServices : BaseServices, ISOCTemplateServices, IFileUploadServices { public SOCTemplateDAL SOCTemplateDAL { get; set; } public SpecialtyCourseDAL specialtyCourseDAL { get; set; } public List GetFileList(Guid? formID) { return SOCTemplateDAL.GetFileUploadViewQueryable(x => x.SOCTemplateItemID == formID).ToList(); } public void SaveFile(IList fileList) { throw new NotImplementedException(); } /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSOCTemplateViewGrid(ConfiguretView configuretView, int? standardID, Guid? facultymajorID, Guid? departmentID, int? educationID, int? learningformID, string learnSystem, Guid? coursematerialID, int? schoolyearNumID, int? schoolcodeID, int? recordStatus, int pageIndex, int pageSize) { Expression> exp = x => true; Expression> facexp = x => true; if (standardID.HasValue) { facexp = facexp.And(x => x.StandardID == standardID); } if (facultymajorID.HasValue) { exp = exp.And(x => x.FacultymajorID == facultymajorID); } if (educationID.HasValue) { facexp = facexp.And(x => x.EducationID == educationID); } if (learningformID.HasValue) { facexp = facexp.And(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); facexp = facexp.And(x => x.LearnSystem == LearnSystems); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (schoolyearNumID.HasValue) { exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID); } if (schoolcodeID.HasValue) { exp = exp.And(x => x.SchoolcodeID == schoolcodeID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var query = SOCTemplateDAL.GetSOCTemplateViewQueryable(exp, facexp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByDepartment(query) .OrderBy(x => x.StandardID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenBy(x => x.SchoolyearNumID).ThenBy(x => x.SchoolcodeID) .ToGridResultSet(pageIndex, pageSize); return result; } /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public List GetSOCTemplateViewList(ConfiguretView configuretView, int? standardID, Guid? facultymajorID, Guid? departmentID, int? educationID, int? learningformID, string learnSystem, Guid? coursematerialID, int? schoolyearNumID, int? schoolcodeID, int? recordStatus, List idList) { Expression> exp = x => true; Expression> facexp = x => true; if (standardID.HasValue) { facexp = facexp.And(x => x.StandardID == standardID); } if (facultymajorID.HasValue) { exp = exp.And(x => x.FacultymajorID == facultymajorID); } if (educationID.HasValue) { facexp = facexp.And(x => x.EducationID == educationID); } if (learningformID.HasValue) { facexp = facexp.And(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { //学制 var LearnSystems = Convert.ToDecimal(learnSystem); facexp = facexp.And(x => x.LearnSystem == LearnSystems); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } if (schoolyearNumID.HasValue) { exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID); } if (schoolcodeID.HasValue) { exp = exp.And(x => x.SchoolcodeID == schoolcodeID); } if (recordStatus.HasValue) { exp = exp.And(x => x.RecordStatus == recordStatus); } if (idList.Count > 0) { exp = exp.And(x => idList.Contains(x.SOCTemplateID)); } var query = SOCTemplateDAL.GetSOCTemplateViewQueryable(exp, facexp); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByDataRangeByDepartment(query) .OrderBy(x => x.StandardID) .ThenBy(x => x.SchoolyearNumID).ThenBy(x => x.SchoolcodeID) .ToList(); return result; } public SOCTemplateView GetSOCTemplateViewByID(Guid? SOCTemplateID) { Expression> exp = x => true; exp = exp.And(x => x.SOCTemplateID == SOCTemplateID); var query = SOCTemplateDAL.GetSOCTemplateViewQueryable(exp, x => true).FirstOrDefault(); return query; } public void GenerateTemplate(Guid? collegeID, int? standardID, Guid? facultymajorID, Guid? coursematerialID) { try { Expression> exp = x => true; exp = exp.And(x => x.RecordStatus == (int)SYS_STATUS.USABLE); Expression> facexp = x => true; if (collegeID.HasValue) { exp = exp.And(x => x.CF_Department.CollegeID == collegeID); } if (standardID.HasValue) { exp = exp.And(x => x.CF_Specialty.StandardID == standardID); } if (facultymajorID.HasValue) { facexp = facexp.And(x => x.FacultymajorID == facultymajorID); } if (coursematerialID.HasValue) { exp = exp.And(x => x.CoursematerialID == coursematerialID); } var query = SOCTemplateDAL.GetSpecialtyCourseViewQueryable(exp, facexp).ToList(); Expression> dbexp = x => true; Expression> dbfacexp = x => true; var dbTemplate = SOCTemplateDAL.GetSOCTemplateViewQueryable(dbexp, dbfacexp).ToList(); List templList = new List(); foreach (var sc in query) { if (dbTemplate.Any(x => x.CoursematerialID == sc.CoursematerialID && x.FacultymajorID == sc.FacultymajorID && x.DepartmentID == sc.DepartmentID && x.SchoolyearNumID == sc.SchoolyearNumID && x.SchoolcodeID == sc.SchoolcodeID)) { continue; } DQP_SOCTemplate templ = new DQP_SOCTemplate(); templ.SOCTemplateID = Guid.NewGuid(); templ.FacultymajorID = sc.FacultymajorID; templ.CoursematerialID = sc.CoursematerialID; templ.Credit = sc.Credit; templ.SchoolyearNumID = sc.SchoolyearNumID; templ.SchoolcodeID = sc.SchoolcodeID; templ.DepartmentID = sc.DepartmentID; templ.HandleModeID = (int)CF_HandleMode.RequiredCourse; this.SetNewStatus(templ); templ.RecordStatus = (int)SYS_STATUS.UNUSABLE; List detailList = new List(); DQP_SOCTemplateDetail detail = new DQP_SOCTemplateDetail(); detail.SOCTemplateItemID = Guid.NewGuid(); detail.SOCTemplateID = templ.SOCTemplateID; detail.Name = "SOC0"; detail.IsGroup = false; this.SetNewStatus(detail); detailList.Add(detail); templ.DQP_SOCTemplateDetail = new HashSet(detailList); templList.Add(templ); } UnitOfWork.BulkInsert(templList); UnitOfWork.BulkInsert(templList.SelectMany(x => x.DQP_SOCTemplateDetail).ToList()); } catch (Exception) { throw; } } public IGridResultSet GetSOCTemplateDetailViewGrid(Guid? SOCTemplateID, int pageIndex, int pageSize) { Expression> exp = x => true; //if (SOCTemplateID.HasValue) //{ exp = exp.And(x => x.SOCTemplateID == SOCTemplateID); //} var query = SOCTemplateDAL.GetSOCTemplateDetailViewByIDQueryable(exp); return query.OrderBy(x => x.Name.Length).ThenBy(x => x.Name).ToGridResultSet(pageIndex, pageSize); } public void SOCTemplateDelete(List idList) { try { if (idList.Count > 0) { UnitOfWork.Delete(x => idList.Contains(x.DQP_SOCTemplateDetail.SOCTemplateID)); UnitOfWork.Delete(x => idList.Contains(x.SOCTemplateID)); UnitOfWork.Delete(x => idList.Contains(x.SOCTemplateID)); } } catch (Exception ex) { throw new Exception(ex.Message); } } public void SOCTemplateEdit(SOCTemplateView SOCTemplateView, List SOCTemplateDetailViewList, List fileList) { try { DQP_SOCTemplate SOCTemplate = new DQP_SOCTemplate(); List attachmentList = new List(); List SOCTemplateDetailList = new List(); var totalWeight = SOCTemplateDetailViewList.Sum(x => x.Weight); var totalCredit = SOCTemplateDetailViewList.Sum(x => x.Credit); SOCTemplateView.HandleModeID = SOCTemplateView.HandleModeID == -1 ? null : SOCTemplateView.HandleModeID; SOCTemplateView.SchoolyearNumID = SOCTemplateView.SchoolyearNumID == -1 ? null : SOCTemplateView.SchoolyearNumID; SOCTemplateView.SchoolcodeID = SOCTemplateView.SchoolcodeID == -1 ? null : SOCTemplateView.SchoolcodeID; if (totalWeight != 100) { throw new Exception("SOC的权重之和必须是100"); } if (SOCTemplateView.Credit != totalCredit) { throw new Exception("SOC的学分之和必须等于课程学分"); } //新增 if (SOCTemplateView.SOCTemplateID == null || SOCTemplateView.SOCTemplateID == Guid.Empty) { SOCTemplate = SOCTemplateDAL.SOCTemplateRepository.GetSingle(x => x.FacultymajorID == SOCTemplateView.FacultymajorID && x.CoursematerialID == SOCTemplateView.CoursematerialID && x.SchoolyearNumID == SOCTemplateView.SchoolyearNumID && x.SchoolcodeID == SOCTemplateView.SchoolcodeID && x.DepartmentID == SOCTemplateView.DepartmentID); if (SOCTemplate != null) { throw new Exception("已存在相同的课程SOC设置信息"); } SOCTemplate = new DQP_SOCTemplate(); SOCTemplate.SOCTemplateID = Guid.NewGuid(); SOCTemplate.FacultymajorID = SOCTemplateView.FacultymajorID; SOCTemplate.CoursematerialID = SOCTemplateView.CoursematerialID; SOCTemplate.Credit = SOCTemplateView.Credit; SOCTemplate.HandleModeID = SOCTemplateView.HandleModeID; SOCTemplate.SchoolyearNumID = SOCTemplateView.SchoolyearNumID; SOCTemplate.SchoolcodeID = SOCTemplateView.SchoolcodeID; SOCTemplate.DepartmentID = SOCTemplateView.DepartmentID; this.SetNewStatus(SOCTemplate); SOCTemplate.RecordStatus = SOCTemplateView.IsEnable ? 1 : 0; foreach (var view in SOCTemplateDetailViewList) { var itemID = view.SOCTemplateItemID; DQP_SOCTemplateDetail detail = new DQP_SOCTemplateDetail(); detail.SOCTemplateItemID = Guid.NewGuid(); detail.SOCTemplateID = SOCTemplate.SOCTemplateID; detail.Name = view.Name; detail.Credit = view.Credit; detail.Weight = view.Weight; detail.Description = view.Description; detail.IsGroup = view.IsGroup == null ? false : view.IsGroup; this.SetNewStatus(detail); foreach (var file in fileList) { if (file.FormID == itemID) { DQP_SOCTemplateDetailAttachment attachment = new DQP_SOCTemplateDetailAttachment(); attachment.SOCTemplateDetailAttachmentID = Guid.NewGuid(); attachment.SOCTemplateItemID = detail.SOCTemplateItemID; attachment.Name = file.FileName; attachment.Url = file.FileUrl; this.SetNewStatus(attachment); detail.DQP_SOCTemplateDetailAttachment.Add(attachment); } } SOCTemplate.DQP_SOCTemplateDetail.Add(detail); } UnitOfWork.Add(SOCTemplate); UnitOfWork.Commit(); } else {//修改 SOCTemplate = SOCTemplateDAL.SOCTemplateRepository.GetSingle(x => x.SOCTemplateID != SOCTemplateView.SOCTemplateID && x.FacultymajorID == SOCTemplateView.FacultymajorID && x.CoursematerialID == SOCTemplateView.CoursematerialID && x.SchoolyearNumID == SOCTemplateView.SchoolyearNumID && x.SchoolcodeID == SOCTemplateView.SchoolcodeID && x.DepartmentID == SOCTemplateView.DepartmentID); if (SOCTemplate != null) { throw new Exception("已存在相同的课程SOC设置信息"); } SOCTemplate = SOCTemplateDAL.SOCTemplateRepository.GetSingle(x => x.SOCTemplateID == SOCTemplateView.SOCTemplateID, x => x.DQP_SOCTemplateDetail); SOCTemplate.SOCTemplateID = SOCTemplateView.SOCTemplateID; SOCTemplate.FacultymajorID = SOCTemplateView.FacultymajorID; SOCTemplate.CoursematerialID = SOCTemplateView.CoursematerialID; SOCTemplate.RecordStatus = SOCTemplateView.IsEnable ? 1 : 0 ; SOCTemplate.Credit = SOCTemplateView.Credit; SOCTemplate.HandleModeID = SOCTemplateView.HandleModeID; SOCTemplate.SchoolyearNumID = SOCTemplateView.SchoolyearNumID; SOCTemplate.SchoolcodeID = SOCTemplateView.SchoolcodeID; SOCTemplate.DepartmentID = SOCTemplateView.DepartmentID; SOCTemplate.ModifyUserID = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; SOCTemplate.ModifyTime = DateTime.Now; //SOCTemplate.DQP_SOCTemplateDetail = new HashSet(); //UnitOfWork.Remove(x => x.SOCTemplateID == SOCTemplate.SOCTemplateID); foreach (var view in SOCTemplateDetailViewList) { var itemID = view.SOCTemplateItemID; DQP_SOCTemplateDetail detail = new DQP_SOCTemplateDetail(); if (SOCTemplate.DQP_SOCTemplateDetail.Any(x => x.SOCTemplateItemID == view.SOCTemplateItemID)) { detail = SOCTemplateDAL.SOCTemplateDetailRepository.GetSingle(x => x.SOCTemplateItemID == view.SOCTemplateItemID); detail.SOCTemplateItemID = view.SOCTemplateItemID; detail.SOCTemplateID = SOCTemplate.SOCTemplateID; detail.Name = view.Name; detail.Credit = view.Credit; detail.Weight = view.Weight; detail.Description = view.Description; detail.IsGroup = view.IsGroup == null ? false : view.IsGroup; this.SetModifyStatus(detail); //UnitOfWork.Update(detail); SOCTemplateDetailList.Add(detail); } else { detail.SOCTemplateItemID = Guid.NewGuid(); detail.SOCTemplateID = SOCTemplate.SOCTemplateID; detail.DQP_SOCTemplate = SOCTemplate; detail.Name = view.Name; detail.Credit = view.Credit; detail.Weight = view.Weight; detail.Description = view.Description; detail.IsGroup = view.IsGroup == null ? false : view.IsGroup; this.SetNewStatus(detail); SOCTemplate.DQP_SOCTemplateDetail.Add(detail); } //detail.DQP_SOCTemplateDetailAttachment = new HashSet(); if (view.IsChangeAttachment == 1) { UnitOfWork.Remove(x => x.SOCTemplateItemID == detail.SOCTemplateItemID); foreach (var file in fileList) { if (file.FormID == itemID) { DQP_SOCTemplateDetailAttachment attachment = new DQP_SOCTemplateDetailAttachment(); attachment.SOCTemplateDetailAttachmentID = Guid.NewGuid(); attachment.SOCTemplateItemID = detail.SOCTemplateItemID; attachment.Name = file.FileName; attachment.Url = file.FileUrl; this.SetNewStatus(attachment); attachmentList.Add(attachment); //detail.DQP_SOCTemplateDetailAttachment.Add(attachment); } } } //SOCTemplateDetailList.Add(detail); //SOCTemplate.DQP_SOCTemplateDetail.Add(detail); } UnitOfWork.BatchUpdate(SOCTemplateDetailList); UnitOfWork.Commit(); //UnitOfWork.BulkInsert(SOCTemplateDetailList); UnitOfWork.BulkInsert(attachmentList); } } catch (Exception) { throw; } } public void AttachmentUpload(List fileList) { List attachmentList = new List(); foreach (var file in fileList) { //var detail = SOCTemplateDAL.SOCTemplateDetailRepository.GetSingle(x => x.SOCTemplateItemID == file.FormID, (x => x.DQP_SOCTemplateDetailAttachment)); DQP_SOCTemplateDetailAttachment attachment = new DQP_SOCTemplateDetailAttachment(); attachment.SOCTemplateDetailAttachmentID = Guid.NewGuid(); attachment.Name = file.FileName; attachment.Url = file.FileUrl; attachment.SOCTemplateItemID = file.FormID; this.SetNewStatus(file); attachmentList.Add(attachment); } } } }