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.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.SchedulingManage; using EMIS.DataLogic.SchedulingManage.SchedulingSettings; using EMIS.ViewModel.UniversityManage.AdministrativeOrgan; namespace EMIS.CommonLogic.SchedulingManage.SchedulingSettings { public class CollegePriorityServices : BaseServices, ICollegePriorityServices { public CollegePriorityDAL CollegePriorityDAL { get; set; } /// /// 查询院系控制信息CollegePriorityView /// /// /// /// /// /// /// /// public IGridResultSet GetCollegePriorityViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (dateRange.HasValue) { exp = exp.And(x => x.StartDate <= dateRange); } if (dateRange.HasValue) { exp = exp.And(x => x.EndDate >= dateRange); } var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Priority).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系控制信息List /// /// /// /// /// /// public IList GetCollegePriorityViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (dateRange.HasValue) { exp = exp.And(x => x.StartDate <= dateRange); } if (dateRange.HasValue) { exp = exp.And(x => x.EndDate >= dateRange); } var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(exp); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Priority).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList(); } /// /// 查询对应的院系控制信息CollegePriorityView /// /// /// public CollegePriorityView GetCollegePriorityView(Guid? collegePriorityID) { try { var query = CollegePriorityDAL.GetCollegePriorityViewQueryable(x => x.CollegePriorityID == collegePriorityID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改) /// /// public void CollegePriorityEdit(CollegePriorityView collegePriorityView) { try { //查询数据库进行验证 var collegePriorityVerify = CollegePriorityDAL.CollegePriorityRepository.GetList(x => x.CollegePriorityID != collegePriorityView.CollegePriorityID && x.CollegeID == collegePriorityView.CollegeID).SingleOrDefault(); if (collegePriorityVerify == null) { //数据有误验证 if (collegePriorityView.CollegePriorityID != Guid.Empty) { var collegePriority = CollegePriorityDAL.CollegePriorityRepository .GetList(x => x.CollegePriorityID == collegePriorityView.CollegePriorityID).SingleOrDefault(); if (collegePriority == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 collegePriority.CollegeID = collegePriorityView.CollegeID; collegePriority.Priority = collegePriorityView.Priority; collegePriority.StartDate = collegePriorityView.StartDate; collegePriority.EndDate = collegePriorityView.EndDate; SetModifyStatus(collegePriority); } } else { //表示新增 var newCollegePriority = new ES_CollegePriority(); newCollegePriority.CollegePriorityID = Guid.NewGuid(); newCollegePriority.CollegeID = collegePriorityView.CollegeID; newCollegePriority.Priority = collegePriorityView.Priority; newCollegePriority.StartDate = collegePriorityView.StartDate; newCollegePriority.EndDate = collegePriorityView.EndDate; SetNewStatus(newCollegePriority); UnitOfWork.Add(newCollegePriority); } } else { throw new Exception("已存在相同的院系控制信息,请核查。"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 院系控制信息批量新增 /// /// /// /// public string CollegePriorityBatchAdd(List collegeIDList, CollegePriorityView collegePriorityView) { try { //查询对应的院系控制信息List var collegePriorityList = CollegePriorityDAL.CollegePriorityRepository.GetList(x => collegeIDList.Contains(x.CollegeID)).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List collegePriorityInList = new List(); foreach (var collegeID in collegeIDList) { var collegePriorityVerify = collegePriorityList.Where(x => x.CollegeID == collegeID).SingleOrDefault(); if (collegePriorityVerify == null) { //新增 var newCollegePriority = new ES_CollegePriority(); newCollegePriority.CollegePriorityID = Guid.NewGuid(); newCollegePriority.CollegeID = collegeID; newCollegePriority.Priority = collegePriorityView.Priority; newCollegePriority.StartDate = collegePriorityView.StartDate; newCollegePriority.EndDate = collegePriorityView.EndDate; SetNewStatus(newCollegePriority); collegePriorityInList.Add(newCollegePriority); success++; } else { //表示已存在相同的院系控制信息 fail++; } } //批量插入 UnitOfWork.BulkInsert(collegePriorityInList); if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:已存在相同的院系控制信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询院系控制中未新增的院系所信息CollegeView /// /// /// /// /// /// /// /// public IGridResultSet GetCollegeViewNoAddGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID, int pageIndex, int pageSize) { //院系所信息 Expression> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (campusID.HasValue) { expCollege = expCollege.And(x => x.CampusID == campusID); } if (collegeID.HasValue) { expCollege = expCollege.And(x => x.CollegeID == collegeID); } if (unitCategoryID.HasValue) { expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID); } //院系控制 Expression> expCollegePriority = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expCollegePriority = expCollegePriority.And(x => x.CollegeID == collegeID); } var query = CollegePriorityDAL.GetCollegeViewNoAddQueryable(expCollege, expCollegePriority); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToGridResultSet(pageIndex, pageSize); } /// /// 查询院系控制中未新增的院系所信息List /// /// /// /// /// /// public IList GetCollegeViewNoAddList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID) { //院系所信息 Expression> expCollege = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (campusID.HasValue) { expCollege = expCollege.And(x => x.CampusID == campusID); } if (collegeID.HasValue) { expCollege = expCollege.And(x => x.CollegeID == collegeID); } if (unitCategoryID.HasValue) { expCollege = expCollege.And(x => x.CF_CollegeProfile.UnitCategoryID == unitCategoryID); } //院系控制 Expression> expCollegePriority = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) { expCollegePriority = expCollegePriority.And(x => x.CollegeID == collegeID); } var query = CollegePriorityDAL.GetCollegeViewNoAddQueryable(expCollege, expCollegePriority); //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.No.Length).ThenBy(x => x.No).ToList(); } /// /// 删除 /// /// /// public bool CollegePriorityDelete(List collegePriorityIDs) { try { UnitOfWork.Delete(x => collegePriorityIDs.Contains(x.CollegePriorityID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }