123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- 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; }
- /// <summary>
- /// 查询对应的教室预留信息ClassroomReserveView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isAvailable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<ClassroomReserveView> GetClassroomReserveViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
- string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize)
- {
- //教室预留
- Expression<Func<ES_ClassroomReserve, bool>> 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<ClassroomReserveView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的教室预留信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isAvailable"></param>
- /// <returns></returns>
- public IList<ClassroomReserveView> GetClassroomReserveViewList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
- string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable)
- {
- //教室预留
- Expression<Func<ES_ClassroomReserve, bool>> 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();
- }
- /// <summary>
- /// 查询对应的教室预留信息ES_ClassroomReserve(根据教室预留ID)
- /// </summary>
- /// <param name="classroomReserveID"></param>
- /// <returns></returns>
- 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);
- }
- }
- /// <summary>
- /// 查询对应的教室预留信息ClassroomReserveView(根据教室预留ID)
- /// </summary>
- /// <param name="classroomReserveID"></param>
- /// <returns></returns>
- 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);
- }
- }
- /// <summary>
- /// 编辑(新增、修改)
- /// </summary>
- /// <param name="classroomReserveView"></param>
- 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);
- }
- }
- /// <summary>
- /// 教室预留信息批量新增(预留)
- /// </summary>
- /// <param name="classroomIDList"></param>
- /// <param name="classroomReserveView"></param>
- /// <returns></returns>
- public string ClassroomReserveBatchAdd(List<Guid?> 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<ES_ClassroomReserve> classroomReserveInList = new List<ES_ClassroomReserve>();
- 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<ES_ClassroomReserve>(classroomReserveInList);
- if (success > 0 && fail <= 0)
- {
- tipMessage = success + "条";
- }
- else
- {
- tipMessage = success + "条," + fail + "条失败,原因:已存在相同的教室预留信息,请检查";
- }
- return tipMessage;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 查询未预留的教室信息ClassroomView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isAvailable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<ClassroomView> GetClassroomViewNoReserveGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
- string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable, int pageIndex, int pageSize)
- {
- //教室信息
- Expression<Func<CF_Classroom, bool>> 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<ClassroomView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询未预留的教室信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isAvailable"></param>
- /// <returns></returns>
- public IList<ClassroomView> GetClassroomViewNoReserveList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID,
- string classroomName, int? classroomTypeID, int? isConcurrentUse, int? isAvailable)
- {
- //教室信息
- Expression<Func<CF_Classroom, bool>> 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();
- }
- /// <summary>
- /// 删除(解除)
- /// </summary>
- /// <param name="classroomReserveIDs"></param>
- /// <returns></returns>
- public bool ClassroomReserveDelete(List<Guid?> classroomReserveIDs)
- {
- try
- {
- UnitOfWork.Delete<ES_ClassroomReserve>(x => classroomReserveIDs.Contains(x.ClassroomReserveID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|