123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.Common.CalendarManage;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.ViewModel.CalendarManage;
- namespace EMIS.CommonLogic.CalendarManage
- {
- public class DutyServices : BaseServices, IDutyServices
- {
- public DutyDAL dutyDAL { get; set; }
- /// <summary>
- /// 查询值班管理信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="departmentID">负责部门/科室</param>
- /// <param name="campusID">校区ID</param>
- /// <param name="collegeID">学院ID</param>
- /// <param name="timesSegment">时间段</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<DutyView> GetDutyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? timesSegment, int pageIndex, int pageSize)
- {
- var query = dutyDAL.GetDutyQueryable(x => true);
- if (campusID.HasValue && campusID != Guid.Empty)
- query = query.Where(x => x.CampusID == campusID);
- if (collegeID.HasValue && collegeID != Guid.Empty)
- query = query.Where(x => x.CollegeID == collegeID);
- if (departmentID.HasValue && departmentID != Guid.Empty)
- query = query.Where(x => x.DepartmentID == departmentID);
- if (timesSegment.HasValue && timesSegment != -1)
- query = query.Where(x => x.TimesSegment == timesSegment);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
- .OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToGridResultSet<DutyView>(pageIndex, pageSize);
- return query.OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToGridResultSet<DutyView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询值班管理信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="departmentID">负责部门/科室</param>
- /// <param name="timesSegment">时间段</param>
- /// <returns></returns>
- public List<DutyView> GetDutyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? timesSegment)
- {
- var query = dutyDAL.GetDutyQueryable(x => true);
- if (campusID.HasValue && campusID != Guid.Empty)
- query = query.Where(x => x.CampusID == campusID);
- if (collegeID.HasValue && collegeID != Guid.Empty)
- query = query.Where(x => x.CollegeID == collegeID);
- if (departmentID.HasValue && departmentID != Guid.Empty)
- query = query.Where(x => x.DepartmentID == departmentID);
- if (timesSegment.HasValue && timesSegment != -1)
- query = query.Where(x => x.TimesSegment == timesSegment);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
- .OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToList();
- return query.OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToList();
- }
- /// <summary>
- /// 获取值班管理信息
- /// </summary>
- /// <param name="dutyID">主键ID</param>
- /// <returns></returns>
- public EM_duty GetDuty(Guid? dutyID)
- {
- //查询条件
- Expression<Func<EM_duty, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.DutyID == dutyID);
- return dutyDAL.dutyRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取值班管理信息
- /// </summary>
- /// <param name="userID">值班人ID</param>
- /// <param name="dutyTime">值班日期</param>
- /// <param name="timesSegment">时间段</param>
- /// <param name="departmentID">负责部门/科室</param>
- /// <returns></returns>
- public EM_duty GetDuty(Guid userID, DateTime dutyTime, int timesSegment, Guid departmentID)
- {
- //查询条件
- Expression<Func<EM_duty, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expression = (x => x.UserID == userID && x.DutyTime == dutyTime && x.TimesSegment == timesSegment && x.DepartmentID == departmentID);
- return dutyDAL.dutyRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取值班管理信息
- /// </summary>
- /// <param name="dutyID">主键ID</param>
- /// <returns></returns>
- public DutyView GetDutyView(Guid? dutyID)
- {
- DutyView dutyView = new DutyView();
- if (dutyID.HasValue)
- dutyView = dutyDAL.GetDutyQueryable(x => true).Where(x => x.DutyID == dutyID).FirstOrDefault();
- return dutyView;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="duty">实体</param>
- /// <returns></returns>
- public bool DutyAdd(DutyView dutyView)
- {
- try
- {
- if (this.dutyDAL.dutyRepository
- .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
- && x.UserID == dutyView.UserID && x.DutyTime == dutyView.DutyTime &&
- x.TimesSegment == dutyView.TimesSegment && x.DepartmentID == dutyView.DepartmentID).Count() > 0)
- {
- throw new Exception("值班人、值班日期、时间段、教研室必须唯一,请重新输入!");
- }
- EM_duty duty = new EM_duty();
- duty.DutyID = Guid.NewGuid();
- duty.UserID = dutyView.UserID.Value;
- duty.TimesSegment = dutyView.TimesSegment.Value;
- duty.DutyTime = dutyView.DutyTime;
- duty.StartHour = dutyView.StartHour;
- duty.StartMinutes = dutyView.StartMinutes;
- duty.EndHour = dutyView.EndHour;
- duty.EndMinutes = dutyView.EndMinutes;
- duty.Description = dutyView.Description;
- duty.DepartmentID = dutyView.DepartmentID;
- this.SetNewStatus(duty);
- UnitOfWork.Add(duty);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="duty">实体</param>
- /// <returns></returns>
- public bool DutyUpdate(DutyView dutyView)
- {
- try
- {
- if (this.dutyDAL.dutyRepository
- .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
- && x.UserID == dutyView.UserID && x.DutyTime == dutyView.DutyTime &&
- x.TimesSegment == dutyView.TimesSegment && x.DepartmentID == dutyView.DepartmentID
- && x.DutyID != dutyView.DutyID).Count() > 0)
- {
- throw new Exception("值班人、值班日期、时间段、教研室必须唯一,请重新输入!");
- }
- var duty = GetDuty(dutyView.DutyID);
- if (duty == null)
- {
- throw new Exception("保存失败,未能找到相对应的数据!");
- }
- duty.UserID = dutyView.UserID.Value;
- duty.TimesSegment = dutyView.TimesSegment.Value;
- duty.DutyTime = dutyView.DutyTime;
- duty.StartHour = dutyView.StartHour;
- duty.StartMinutes = dutyView.StartMinutes;
- duty.EndHour = dutyView.EndHour;
- duty.EndMinutes = dutyView.EndMinutes;
- duty.Description = dutyView.Description;
- duty.DepartmentID = dutyView.DepartmentID;
- this.SetModifyStatus(duty);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="dutyIDs"></param>
- /// <returns></returns>
- public bool DutyDelete(List<Guid> dutyIDs)
- {
- try
- {
- UnitOfWork.Delete<EM_duty>(x => dutyIDs.Contains(x.DutyID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|