StudentPrintTimesServices.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel.TerminatePrinter;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.TerminatePrinter;
  11. using EMIS.Entities;
  12. namespace EMIS.CommonLogic.TerminatePrinter
  13. {
  14. public class StudentPrintTimesServices : BaseServices, IStudentPrintTimesServices
  15. {
  16. public StudentPrintTimesDAL StudentPrintTimesDAL { get; set; }
  17. public IGridResultSet<StudentPrintTimesView> GetStudentPrintTimesViewGrid(ConfiguretView conditionView, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, int? pageIndex, int? pageSize)
  18. {
  19. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  20. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  21. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  22. if (collegeID.HasValue)
  23. {
  24. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  25. }
  26. if (yearID.HasValue)
  27. {
  28. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  29. }
  30. if (standardID.HasValue)
  31. {
  32. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  33. }
  34. if (classmajorID.HasValue)
  35. {
  36. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  37. }
  38. var query = StudentPrintTimesDAL.GetStudentPrintTimesViewQueryable(facultyExp, gradeExp, classExp);
  39. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  40. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  41. query = query.OrderByDescending(x => x.YearID)
  42. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  43. .ThenBy(x => x.StandardID)
  44. .ThenBy(x => x.ClassmajorNo)
  45. .ThenBy(x => x.LoginID);
  46. return query.ToGridResultSet(pageIndex, pageSize);
  47. }
  48. public List<StudentPrintTimesView> GetStudentPrintTimesViewGrid(ConfiguretView conditionView, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID)
  49. {
  50. Expression<Func<CF_Facultymajor, bool>> facultyExp = (x => true);
  51. Expression<Func<CF_Grademajor, bool>> gradeExp = (x => true);
  52. Expression<Func<CF_Classmajor, bool>> classExp = (x => true);
  53. if (collegeID.HasValue)
  54. {
  55. facultyExp = facultyExp.And(x => x.CollegeID == collegeID);
  56. }
  57. if (yearID.HasValue)
  58. {
  59. gradeExp = gradeExp.And(x => x.GradeID == yearID);
  60. }
  61. if (standardID.HasValue)
  62. {
  63. facultyExp = facultyExp.And(x => x.StandardID == standardID);
  64. }
  65. if (classmajorID.HasValue)
  66. {
  67. classExp = classExp.And(x => x.ClassmajorID == classmajorID);
  68. }
  69. var query = StudentPrintTimesDAL.GetStudentPrintTimesViewQueryable(facultyExp, gradeExp, classExp);
  70. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  71. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue.Trim());
  72. query = query.OrderByDescending(x => x.YearID)
  73. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  74. .ThenBy(x => x.StandardID)
  75. .ThenBy(x => x.ClassmajorNo)
  76. .ThenBy(x => x.LoginID);
  77. return query.ToList();
  78. }
  79. public StudentPrintMessageView GetStudentPrintMessageView(Guid userID)
  80. {
  81. return StudentPrintTimesDAL.GetStudentPrintMessageViewQueryable(x => x.UserID == userID).FirstOrDefault();
  82. }
  83. public void Count(Guid userID)
  84. {
  85. Tem_StudentPrintTimes printTimes = this.StudentPrintTimesDAL.StudentPrintTimesRepository.GetSingle(x => x.UserID == userID);
  86. if (printTimes == null)
  87. {
  88. printTimes = new Tem_StudentPrintTimes()
  89. {
  90. StudentPrintTimesID = Guid.NewGuid(),
  91. UserID = userID,
  92. Times = 1,
  93. RecordStatus = (int)SYS_STATUS.UNUSABLE,
  94. CreateUserID = userID,
  95. CreateTime = DateTime.Now,
  96. };
  97. this.UnitOfWork.Add(printTimes);
  98. }
  99. else
  100. {
  101. printTimes.Times++;
  102. }
  103. printTimes.ModifyUserID = userID;
  104. printTimes.ModifyTime = DateTime.Now;
  105. this.UnitOfWork.Commit();
  106. }
  107. public void BatchUpdate(IList<Guid> userIDList, int times)
  108. {
  109. var nullableUserIDList = userIDList.Select(x => (Guid?)x).ToList();
  110. var printTimesList = this.StudentPrintTimesDAL.StudentPrintTimesRepository.GetList(x => nullableUserIDList.Contains(x.UserID)).ToList();
  111. var updateList = (from printTimes in printTimesList
  112. from user in userIDList.Where(x => x == printTimes.UserID)
  113. select printTimes).ToList();
  114. updateList.ForEach(x =>
  115. {
  116. x.Times = times;
  117. this.SetModifyStatus(x);
  118. });
  119. var insertList = (from user in userIDList
  120. from printTimes in printTimesList.Where(x => x.UserID == user).DefaultIfEmpty()
  121. where printTimes == null
  122. select new Tem_StudentPrintTimes
  123. {
  124. StudentPrintTimesID = Guid.NewGuid(),
  125. UserID = user,
  126. Times = times
  127. }).ToList();
  128. insertList.ForEach(x =>
  129. {
  130. this.SetNewStatus(x);
  131. });
  132. UnitOfWork.BatchUpdate(updateList);
  133. UnitOfWork.BulkInsert(insertList);
  134. }
  135. }
  136. }