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.Entities; using EMIS.ViewModel; using EMIS.ViewModel.SchedulingManage.SchedulingSettings; using EMIS.ViewModel.UniversityManage.ClassroomManage; using EMIS.DataLogic.SchedulingManage.SchedulingSettings; namespace EMIS.CommonLogic.SchedulingManage.SchedulingSettings { public class ClassroomReserveServices : BaseServices, IClassroomReserveServices { public ClassroomReserveDAL ClassroomReserveDAL { get; set; } /// /// 查询对应的教室预留信息ClassroomReserveView /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetClassroomReserveViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize) { //教室预留 Expression> expClassroomReserve = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expClassroomReserve = expClassroomReserve.And(x => x.IsReserved == true); var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(expClassroomReserve); if (campusID.HasValue) { //建筑信息对应的校区 query = query.Where(x => x.CampusID == campusID); } if (buildingsInfoID.HasValue) { //建筑信息 query = query.Where(x => x.BuildingsInfoID == buildingsInfoID); } if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1") { //教室名称 query = query.Where(x => x.ClassroomName == classroomName); } if (classroomTypeID.HasValue) { //教室类型(模糊查询) query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID)); } if (isConcurrentUse.HasValue) { //可否多班教学 if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsConcurrentUse == true); } if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsConcurrentUse != true); } } if (isAvailable.HasValue) { //是否可用 if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsAvailable == true); } if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsAvailable != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCampus(query) .OrderBy(x => x.CampusNo.Length).ThenBy(x => x.CampusNo) .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode) .ThenBy(x => x.ClassroomCode.Length).ThenBy(x => x.ClassroomCode).ThenBy(x => x.RoomUseID) .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的教室预留信息List /// /// /// /// /// /// /// /// /// public IList GetClassroomReserveViewList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable) { //教室预留 Expression> expClassroomReserve = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expClassroomReserve = expClassroomReserve.And(x => x.IsReserved == true); var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(expClassroomReserve); if (campusID.HasValue) { //建筑信息对应的校区 query = query.Where(x => x.CampusID == campusID); } if (buildingsInfoID.HasValue) { //建筑信息 query = query.Where(x => x.BuildingsInfoID == buildingsInfoID); } if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1") { //教室名称 query = query.Where(x => x.ClassroomName == classroomName); } if (classroomTypeID.HasValue) { //教室类型(模糊查询) query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID)); } if (isConcurrentUse.HasValue) { //可否多班教学 if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsConcurrentUse == true); } if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsConcurrentUse != true); } } if (isAvailable.HasValue) { //是否可用 if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes) { query = query.Where(x => x.IsAvailable == true); } if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo) { query = query.Where(x => x.IsAvailable != true); } } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return this.GetQueryByDataRangeByCampus(query) .OrderBy(x => x.CampusNo.Length).ThenBy(x => x.CampusNo) .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode) .ThenBy(x => x.ClassroomCode.Length).ThenBy(x => x.ClassroomCode).ThenBy(x => x.RoomUseID) .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ToList(); } /// /// 查询对应的教室预留信息ES_ClassroomReserve(根据教室预留ID) /// /// /// public ES_ClassroomReserve GetClassroomReserve(Guid? classroomReserveID) { try { var query = ClassroomReserveDAL.ClassroomReserveRepository.GetList(x => x.ClassroomReserveID == classroomReserveID); return query.SingleOrDefault(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应的教室预留信息ClassroomReserveView(根据教室预留ID) /// /// /// public ClassroomReserveView GetClassroomReserveView(Guid? classroomReserveID) { try { var query = ClassroomReserveDAL.GetClassroomReserveViewQueryable(x => x.ClassroomReserveID == classroomReserveID); return query.SingleOrDefault(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改) /// /// public void ClassroomReserveEdit(ClassroomReserveView classroomReserveView) { try { //查询数据库进行验证 var classroomReserveVerify = ClassroomReserveDAL.ClassroomReserveRepository .GetList(x => x.ClassroomReserveID != classroomReserveView.ClassroomReserveID && x.ClassroomID == classroomReserveView.ClassroomID).SingleOrDefault(); if (classroomReserveVerify == null) { //数据有误验证 if (classroomReserveView.ClassroomReserveID != Guid.Empty) { var classroomReserve = ClassroomReserveDAL.ClassroomReserveRepository .GetList(x => x.ClassroomReserveID == classroomReserveView.ClassroomReserveID).SingleOrDefault(); if (classroomReserve == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 classroomReserve.ClassroomID = classroomReserveView.ClassroomID; classroomReserve.IsReserved = true; SetModifyStatus(classroomReserve); } } else { //表示新增 var newClassroomReserve = new ES_ClassroomReserve(); newClassroomReserve.ClassroomReserveID = Guid.NewGuid(); newClassroomReserve.ClassroomID = classroomReserveView.ClassroomID; newClassroomReserve.IsReserved = true; SetNewStatus(newClassroomReserve); UnitOfWork.Add(newClassroomReserve); } } else { throw new Exception("已存在相同的教室预留信息,请核查。"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 教室预留信息批量新增(预留) /// /// /// /// public string ClassroomReserveBatchAdd(List classroomIDList, ClassroomReserveView classroomReserveView) { try { //查询对应的教室预留信息List var classroomReserveList = ClassroomReserveDAL.ClassroomReserveRepository .GetList(x => classroomIDList.Contains(x.ClassroomID)).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 List classroomReserveInList = new List(); foreach (var classroomID in classroomIDList) { var classroomReserveVerify = classroomReserveList.Where(x => x.ClassroomID == classroomID).SingleOrDefault(); if (classroomReserveVerify == null) { //新增 var newClassroomReserve = new ES_ClassroomReserve(); newClassroomReserve.ClassroomReserveID = Guid.NewGuid(); newClassroomReserve.ClassroomID = classroomID; newClassroomReserve.IsReserved = true; SetNewStatus(newClassroomReserve); classroomReserveInList.Add(newClassroomReserve); success++; } else { //表示已存在相同的教室预留信息 fail++; } } //批量插入 UnitOfWork.BulkInsert(classroomReserveInList); if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:已存在相同的教室预留信息,请检查"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询未预留的教室信息ClassroomView /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetClassroomViewNoReserveGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize) { //教室信息 Expression> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (buildingsInfoID.HasValue) { //建筑信息 expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID); } if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1") { //教室名称 expClassroom = expClassroom.And(x => x.Name == classroomName); } if (classroomTypeID.HasValue) { //教室类型(模糊查询) expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID)); } if (isConcurrentUse.HasValue) { //可否多班教学 if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes) { expClassroom = expClassroom.And(x => x.IsConcurrentUse == true); } if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo) { expClassroom = expClassroom.And(x => x.IsConcurrentUse != true); } } if (isAvailable.HasValue) { //是否可用 if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes) { expClassroom = expClassroom.And(x => x.IsAvailable == true); } if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo) { expClassroom = expClassroom.And(x => x.IsAvailable != true); } } var query = ClassroomReserveDAL.GetClassroomViewNoReserveQueryable(expClassroom); 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.GetQueryByDataRangeByCampus(query) .OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode) .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode) .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID) .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ToGridResultSet(pageIndex, pageSize); } /// /// 查询未预留的教室信息List /// /// /// /// /// /// /// /// /// public IList GetClassroomViewNoReserveList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable) { //教室信息 Expression> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (buildingsInfoID.HasValue) { //建筑信息 expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID); } if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1") { //教室名称 expClassroom = expClassroom.And(x => x.Name == classroomName); } if (classroomTypeID.HasValue) { //教室类型(模糊查询) expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID)); } if (isConcurrentUse.HasValue) { //可否多班教学 if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes) { expClassroom = expClassroom.And(x => x.IsConcurrentUse == true); } if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo) { expClassroom = expClassroom.And(x => x.IsConcurrentUse != true); } } if (isAvailable.HasValue) { //是否可用 if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes) { expClassroom = expClassroom.And(x => x.IsAvailable == true); } if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo) { expClassroom = expClassroom.And(x => x.IsAvailable != true); } } var query = ClassroomReserveDAL.GetClassroomViewNoReserveQueryable(expClassroom); 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.GetQueryByDataRangeByCampus(query) .OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode) .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode) .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID) .ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode) .ToList(); } /// /// 删除(解除) /// /// /// public bool ClassroomReserveDelete(List classroomReserveIDs) { try { UnitOfWork.Delete(x => classroomReserveIDs.Contains(x.ClassroomReserveID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }