123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- 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; }
- /// <summary>
- /// 查询院系控制信息CollegePriorityView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="dateRange"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<CollegePriorityView> GetCollegePriorityViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange, int pageIndex, int pageSize)
- {
- Expression<Func<ES_CollegePriority, bool>> 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<CollegePriorityView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询院系控制信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="dateRange"></param>
- /// <returns></returns>
- public IList<CollegePriorityView> GetCollegePriorityViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, DateTime? dateRange)
- {
- Expression<Func<ES_CollegePriority, bool>> 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();
- }
- /// <summary>
- /// 查询对应的院系控制信息CollegePriorityView
- /// </summary>
- /// <param name="collegePriorityID"></param>
- /// <returns></returns>
- 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);
- }
- }
- /// <summary>
- /// 编辑(新增、修改)
- /// </summary>
- /// <param name="collegePriorityView"></param>
- 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);
- }
- }
- /// <summary>
- /// 院系控制信息批量新增
- /// </summary>
- /// <param name="collegeIDList"></param>
- /// <param name="collegePriorityView"></param>
- /// <returns></returns>
- public string CollegePriorityBatchAdd(List<Guid?> 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<ES_CollegePriority> collegePriorityInList = new List<ES_CollegePriority>();
- 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<ES_CollegePriority>(collegePriorityInList);
- if (success > 0 && fail <= 0)
- {
- tipMessage = success + "条";
- }
- else
- {
- tipMessage = success + "条," + fail + "条失败,原因:已存在相同的院系控制信息,请检查";
- }
- return tipMessage;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 查询院系控制中未新增的院系所信息CollegeView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="unitCategoryID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<CollegeView> GetCollegeViewNoAddGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID, int pageIndex, int pageSize)
- {
- //院系所信息
- Expression<Func<CF_College, bool>> 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<Func<ES_CollegePriority, bool>> 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<CollegeView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询院系控制中未新增的院系所信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="unitCategoryID"></param>
- /// <returns></returns>
- public IList<CollegeView> GetCollegeViewNoAddList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? unitCategoryID)
- {
- //院系所信息
- Expression<Func<CF_College, bool>> 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<Func<ES_CollegePriority, bool>> 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();
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="collegePriorityIDs"></param>
- /// <returns></returns>
- public bool CollegePriorityDelete(List<Guid?> collegePriorityIDs)
- {
- try
- {
- UnitOfWork.Delete<ES_CollegePriority>(x => collegePriorityIDs.Contains(x.CollegePriorityID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|