WorktimeRateServices.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel.PaymentManage;
  9. using EMIS.ViewModel;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.PaymentManage;
  12. namespace EMIS.CommonLogic.PaymentManage
  13. {
  14. public class WorktimeRateServices : BaseServices, IWorktimeRateServices
  15. {
  16. public WorktimeRateDAL WorktimeRateDAL { get; set; }
  17. public IGridResultSet<WorktimeRateView> GetWorktimeRateViewList(ConfiguretView worktimeRateConditionView,
  18. Guid? collegeID, int? teachingModeID, int? teachingMethodID, int? paymentLevelID, int? pageIndex, int? pageSize)
  19. {
  20. Expression<Func<TP_WorktimeRate, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  21. if (collegeID.HasValue)
  22. {
  23. exp = exp.And(x => x.CollegeID == collegeID);
  24. }
  25. if (teachingModeID.HasValue)
  26. {
  27. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  28. }
  29. if (teachingMethodID.HasValue)
  30. {
  31. exp = exp.And(x => x.TeachingMethodID == teachingMethodID);
  32. }
  33. if (paymentLevelID.HasValue)
  34. {
  35. exp = exp.And(x => x.PaymentLevelID == paymentLevelID);
  36. }
  37. var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(exp);
  38. if (!string.IsNullOrEmpty(worktimeRateConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeRateConditionView.Attribute))
  39. query = query.DynamicWhere(worktimeRateConditionView.Attribute, worktimeRateConditionView.Condition, worktimeRateConditionView.ConditionValue);
  40. query = this.GetQueryByDataRangeByCollege(query);
  41. query = query.OrderBy(x => x.CollegeNo.Length)
  42. .ThenBy(x => x.CollegeNo)
  43. .ThenBy(x => x.TeachingModeID)
  44. .ThenBy(x => x.TeachingMethodID)
  45. .ThenBy(x => x.PaymentLevelID)
  46. .ThenBy(x => x.StudentCountStart);
  47. return query.ToGridResultSet(pageIndex, pageSize);
  48. }
  49. public List<WorktimeRateView> GetWorktimeRateViewList(ConfiguretView worktimeRateConditionView,
  50. Guid? collegeID, int? teachingModeID, int? teachingMethodID, int? paymentLevelID)
  51. {
  52. Expression<Func<TP_WorktimeRate, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  53. if (collegeID.HasValue)
  54. {
  55. exp = exp.And(x => x.CollegeID == collegeID);
  56. }
  57. if (teachingModeID.HasValue)
  58. {
  59. exp = exp.And(x => x.TeachingModeID == teachingModeID);
  60. }
  61. if (teachingMethodID.HasValue)
  62. {
  63. exp = exp.And(x => x.TeachingMethodID == teachingMethodID);
  64. }
  65. if (paymentLevelID.HasValue)
  66. {
  67. exp = exp.And(x => x.PaymentLevelID == paymentLevelID);
  68. }
  69. var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(exp);
  70. if (!string.IsNullOrEmpty(worktimeRateConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeRateConditionView.Attribute))
  71. query = query.DynamicWhere(worktimeRateConditionView.Attribute, worktimeRateConditionView.Condition, worktimeRateConditionView.ConditionValue);
  72. query = this.GetQueryByDataRangeByCollege(query);
  73. query = query.OrderBy(x => x.CollegeNo.Length)
  74. .ThenBy(x => x.CollegeNo)
  75. .ThenBy(x => x.TeachingModeID)
  76. .ThenBy(x => x.TeachingMethodID)
  77. .ThenBy(x => x.PaymentLevelID)
  78. .ThenBy(x => x.StudentCountStart);
  79. return query.ToList();
  80. }
  81. public WorktimeRateView GetWorktimeRateView(Guid? worktimeRateID)
  82. {
  83. var query = WorktimeRateDAL.GetWorktimeRateViewQueryable(x => x.WorktimeRateID == worktimeRateID);
  84. return query.FirstOrDefault();
  85. }
  86. public void Save(WorktimeRateView worktimeRateView)
  87. {
  88. TP_WorktimeRate worktimeRate = new TP_WorktimeRate();
  89. var dupWorktimeRate = WorktimeRateDAL.WorktimeRateRepository.GetSingle(x => x.CollegeID == worktimeRateView.CollegeID
  90. && x.TeachingModeID == worktimeRateView.TeachingModeID && x.TeachingMethodID == worktimeRateView.TeachingMethodID
  91. && x.PaymentLevelID == worktimeRateView.PaymentLevelID
  92. && (
  93. (worktimeRateView.StudentCountEnd == null || x.StudentCountStart <= worktimeRateView.StudentCountEnd)
  94. && (x.StudentCountEnd == null || x.StudentCountEnd >= worktimeRateView.StudentCountStart)
  95. )
  96. && x.WorktimeRateID != worktimeRateView.WorktimeRateID
  97. );
  98. if (dupWorktimeRate != null)
  99. {
  100. throw new Exception("已有相同的工作量系数设置,请勿重复设置。");
  101. }
  102. if (worktimeRateView.WorktimeRateID == null || worktimeRateView.WorktimeRateID == Guid.Empty)
  103. {
  104. worktimeRate = new TP_WorktimeRate();
  105. worktimeRate.WorktimeRateID = Guid.NewGuid();
  106. SetNewStatus(worktimeRate);
  107. UnitOfWork.Add(worktimeRate);
  108. }
  109. else
  110. {
  111. worktimeRate = WorktimeRateDAL.WorktimeRateRepository.GetSingle(x => x.WorktimeRateID == worktimeRateView.WorktimeRateID);
  112. if (worktimeRate == null)
  113. {
  114. throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。");
  115. }
  116. SetModifyStatus(worktimeRate);
  117. }
  118. worktimeRate.CollegeID = worktimeRateView.CollegeID;
  119. worktimeRate.TeachingModeID = worktimeRateView.TeachingModeID;
  120. worktimeRate.TeachingMethodID = worktimeRateView.TeachingMethodID;
  121. worktimeRate.PaymentLevelID = worktimeRateView.PaymentLevelID;
  122. worktimeRate.StudentCountStart = worktimeRateView.StudentCountStart;
  123. worktimeRate.StudentCountEnd = worktimeRateView.StudentCountEnd;
  124. worktimeRate.WorktimeRate = worktimeRateView.WorktimeRate;
  125. UnitOfWork.Commit();
  126. }
  127. public void Delete(IList<Guid?> worktimeRateIDList)
  128. {
  129. if (worktimeRateIDList.Count > 0)
  130. {
  131. UnitOfWork.Delete<TP_WorktimeRate>(x => worktimeRateIDList.Contains(x.WorktimeRateID));
  132. }
  133. }
  134. }
  135. }