DutyServices.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.CalendarManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.CalendarManage;
  11. namespace EMIS.CommonLogic.CalendarManage
  12. {
  13. public class DutyServices : BaseServices, IDutyServices
  14. {
  15. public DutyDAL dutyDAL { get; set; }
  16. /// <summary>
  17. /// 查询值班管理信息
  18. /// </summary>
  19. /// <param name="configuretView">查询条件实体</param>
  20. /// <param name="departmentID">负责部门/科室</param>
  21. /// <param name="campusID">校区ID</param>
  22. /// <param name="collegeID">学院ID</param>
  23. /// <param name="timesSegment">时间段</param>
  24. /// <param name="pageIndex">页码</param>
  25. /// <param name="pageSize">显示页数</param>
  26. /// <returns></returns>
  27. public IGridResultSet<DutyView> GetDutyViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? timesSegment, int pageIndex, int pageSize)
  28. {
  29. var query = dutyDAL.GetDutyQueryable(x => true);
  30. if (campusID.HasValue && campusID != Guid.Empty)
  31. query = query.Where(x => x.CampusID == campusID);
  32. if (collegeID.HasValue && collegeID != Guid.Empty)
  33. query = query.Where(x => x.CollegeID == collegeID);
  34. if (departmentID.HasValue && departmentID != Guid.Empty)
  35. query = query.Where(x => x.DepartmentID == departmentID);
  36. if (timesSegment.HasValue && timesSegment != -1)
  37. query = query.Where(x => x.TimesSegment == timesSegment);
  38. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  39. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  40. .OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToGridResultSet<DutyView>(pageIndex, pageSize);
  41. return query.OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToGridResultSet<DutyView>(pageIndex, pageSize);
  42. }
  43. /// <summary>
  44. /// 查询值班管理信息
  45. /// </summary>
  46. /// <param name="configuretView">查询条件实体</param>
  47. /// <param name="departmentID">负责部门/科室</param>
  48. /// <param name="timesSegment">时间段</param>
  49. /// <returns></returns>
  50. public List<DutyView> GetDutyViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? timesSegment)
  51. {
  52. var query = dutyDAL.GetDutyQueryable(x => true);
  53. if (campusID.HasValue && campusID != Guid.Empty)
  54. query = query.Where(x => x.CampusID == campusID);
  55. if (collegeID.HasValue && collegeID != Guid.Empty)
  56. query = query.Where(x => x.CollegeID == collegeID);
  57. if (departmentID.HasValue && departmentID != Guid.Empty)
  58. query = query.Where(x => x.DepartmentID == departmentID);
  59. if (timesSegment.HasValue && timesSegment != -1)
  60. query = query.Where(x => x.TimesSegment == timesSegment);
  61. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  62. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
  63. .OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToList();
  64. return query.OrderBy(x => x.DutyTime).ThenBy(x => x.TimesSegment).ToList();
  65. }
  66. /// <summary>
  67. /// 获取值班管理信息
  68. /// </summary>
  69. /// <param name="dutyID">主键ID</param>
  70. /// <returns></returns>
  71. public EM_duty GetDuty(Guid? dutyID)
  72. {
  73. //查询条件
  74. Expression<Func<EM_duty, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  75. expression = (x => x.DutyID == dutyID);
  76. return dutyDAL.dutyRepository.GetSingle(expression);
  77. }
  78. /// <summary>
  79. /// 获取值班管理信息
  80. /// </summary>
  81. /// <param name="userID">值班人ID</param>
  82. /// <param name="dutyTime">值班日期</param>
  83. /// <param name="timesSegment">时间段</param>
  84. /// <param name="departmentID">负责部门/科室</param>
  85. /// <returns></returns>
  86. public EM_duty GetDuty(Guid userID, DateTime dutyTime, int timesSegment, Guid departmentID)
  87. {
  88. //查询条件
  89. Expression<Func<EM_duty, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  90. expression = (x => x.UserID == userID && x.DutyTime == dutyTime && x.TimesSegment == timesSegment && x.DepartmentID == departmentID);
  91. return dutyDAL.dutyRepository.GetSingle(expression);
  92. }
  93. /// <summary>
  94. /// 获取值班管理信息
  95. /// </summary>
  96. /// <param name="dutyID">主键ID</param>
  97. /// <returns></returns>
  98. public DutyView GetDutyView(Guid? dutyID)
  99. {
  100. DutyView dutyView = new DutyView();
  101. if (dutyID.HasValue)
  102. dutyView = dutyDAL.GetDutyQueryable(x => true).Where(x => x.DutyID == dutyID).FirstOrDefault();
  103. return dutyView;
  104. }
  105. /// <summary>
  106. /// 添加
  107. /// </summary>
  108. /// <param name="duty">实体</param>
  109. /// <returns></returns>
  110. public bool DutyAdd(DutyView dutyView)
  111. {
  112. try
  113. {
  114. if (this.dutyDAL.dutyRepository
  115. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  116. && x.UserID == dutyView.UserID && x.DutyTime == dutyView.DutyTime &&
  117. x.TimesSegment == dutyView.TimesSegment && x.DepartmentID == dutyView.DepartmentID).Count() > 0)
  118. {
  119. throw new Exception("值班人、值班日期、时间段、教研室必须唯一,请重新输入!");
  120. }
  121. EM_duty duty = new EM_duty();
  122. duty.DutyID = Guid.NewGuid();
  123. duty.UserID = dutyView.UserID.Value;
  124. duty.TimesSegment = dutyView.TimesSegment.Value;
  125. duty.DutyTime = dutyView.DutyTime;
  126. duty.StartHour = dutyView.StartHour;
  127. duty.StartMinutes = dutyView.StartMinutes;
  128. duty.EndHour = dutyView.EndHour;
  129. duty.EndMinutes = dutyView.EndMinutes;
  130. duty.Description = dutyView.Description;
  131. duty.DepartmentID = dutyView.DepartmentID;
  132. this.SetNewStatus(duty);
  133. UnitOfWork.Add(duty);
  134. UnitOfWork.Commit();
  135. return true;
  136. }
  137. catch (Exception)
  138. {
  139. throw;
  140. }
  141. }
  142. /// <summary>
  143. /// 修改
  144. /// </summary>
  145. /// <param name="duty">实体</param>
  146. /// <returns></returns>
  147. public bool DutyUpdate(DutyView dutyView)
  148. {
  149. try
  150. {
  151. if (this.dutyDAL.dutyRepository
  152. .GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  153. && x.UserID == dutyView.UserID && x.DutyTime == dutyView.DutyTime &&
  154. x.TimesSegment == dutyView.TimesSegment && x.DepartmentID == dutyView.DepartmentID
  155. && x.DutyID != dutyView.DutyID).Count() > 0)
  156. {
  157. throw new Exception("值班人、值班日期、时间段、教研室必须唯一,请重新输入!");
  158. }
  159. var duty = GetDuty(dutyView.DutyID);
  160. if (duty == null)
  161. {
  162. throw new Exception("保存失败,未能找到相对应的数据!");
  163. }
  164. duty.UserID = dutyView.UserID.Value;
  165. duty.TimesSegment = dutyView.TimesSegment.Value;
  166. duty.DutyTime = dutyView.DutyTime;
  167. duty.StartHour = dutyView.StartHour;
  168. duty.StartMinutes = dutyView.StartMinutes;
  169. duty.EndHour = dutyView.EndHour;
  170. duty.EndMinutes = dutyView.EndMinutes;
  171. duty.Description = dutyView.Description;
  172. duty.DepartmentID = dutyView.DepartmentID;
  173. this.SetModifyStatus(duty);
  174. UnitOfWork.Commit();
  175. return true;
  176. }
  177. catch (Exception)
  178. {
  179. throw;
  180. }
  181. }
  182. /// <summary>
  183. /// 删除
  184. /// </summary>
  185. /// <param name="dutyIDs"></param>
  186. /// <returns></returns>
  187. public bool DutyDelete(List<Guid> dutyIDs)
  188. {
  189. try
  190. {
  191. UnitOfWork.Delete<EM_duty>(x => dutyIDs.Contains(x.DutyID));
  192. UnitOfWork.Commit();
  193. return true;
  194. }
  195. catch (Exception)
  196. {
  197. throw;
  198. }
  199. }
  200. }
  201. }