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; } /// /// 查询值班管理信息 /// /// 查询条件实体 /// 负责部门/科室 /// 校区ID /// 学院ID /// 时间段 /// 页码 /// 显示页数 /// public IGridResultSet 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(pageIndex, pageSize); return query.OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToGridResultSet(pageIndex, pageSize); } /// /// 查询值班管理信息 /// /// 查询条件实体 /// 负责部门/科室 /// 时间段 /// public List 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(); } /// /// 获取值班管理信息 /// /// 主键ID /// public EM_duty GetDuty(Guid? dutyID) { //查询条件 Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.DutyID == dutyID); return dutyDAL.dutyRepository.GetSingle(expression); } /// /// 获取值班管理信息 /// /// 值班人ID /// 值班日期 /// 时间段 /// 负责部门/科室 /// public EM_duty GetDuty(Guid userID, DateTime dutyTime, int timesSegment, Guid departmentID) { //查询条件 Expression> 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); } /// /// 获取值班管理信息 /// /// 主键ID /// 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; } /// /// 添加 /// /// 实体 /// 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; } } /// /// 修改 /// /// 实体 /// 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; } } /// /// 删除 /// /// /// public bool DutyDelete(List dutyIDs) { try { UnitOfWork.Delete(x => dutyIDs.Contains(x.DutyID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }