UserDAL.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMIS.Entities;
  7. using EMIS.DataLogic.Repositories;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.SystemView;
  10. using System.Linq.Expressions;
  11. using EMIS.ViewModel.SystemManage.UserManage;
  12. namespace EMIS.DataLogic.SystemDAL
  13. {
  14. public class UserDAL
  15. {
  16. public UserRepository UserRepository { get; set; }
  17. public StaffRepository StaffRepository { get; set; }
  18. public RoleRepository RoleRepository { get; set; }
  19. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. /// <param name="expression"></param>
  24. /// <returns></returns>
  25. public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression<Func<Sys_User, bool>> expression)
  26. {
  27. System.Linq.Expressions.Expression<Func<Sys_User, bool>> newExp = expression.And(u => true);
  28. return UserRepository.GetSingle(newExp,
  29. (x => x.CF_Staff.CF_College.CF_Campus.CF_University),
  30. (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University));
  31. }
  32. /// <summary>
  33. ///
  34. /// </summary>
  35. /// <param name="userExpression"></param>
  36. /// <param name="roleExpression"></param>
  37. /// <returns></returns>
  38. public IQueryable<UserView> GetUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  39. {
  40. var q = (from u in UserRepository.GetList(userExpression)
  41. from ur in u.Sys_Role.DefaultIfEmpty()
  42. join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr
  43. from er in dr.DefaultIfEmpty()
  44. join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu
  45. from ecu in dcu.DefaultIfEmpty()
  46. join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu
  47. from emu in dmu.DefaultIfEmpty()
  48. where u.CF_Staff != null
  49. select new UserView
  50. {
  51. UserID = u.UserID,
  52. LoginID = u.LoginID,
  53. Name = u.Name,
  54. SexID = u.CF_Staff.SexID,
  55. BirthDate = u.CF_Staff.BirthDate,
  56. CollegeID = u.CF_Staff.CollegeID,
  57. CollegeCode = u.CF_Staff.CF_College.No,
  58. CollegeName = u.CF_Staff.CF_College.Name,
  59. DepartmentID = u.CF_Staff.DepartmentID,
  60. DepartmentCode = u.CF_Staff.CF_Department.No,
  61. DepartmentName = u.CF_Staff.CF_Department.Name,
  62. RoleOrderNo = er.OrderNo,
  63. RoleID = er.RoleID,
  64. RoleName = er.RoleName,
  65. TypeID = er.TypeID,
  66. DataRange = er.DefaultDataRange,
  67. RoleStatus = er.RecordStatus,
  68. Remark = u.CF_Staff.Remark,
  69. RecordStatus = u.RecordStatus,
  70. CreateUserID = u.CreateUserID,
  71. CreateUserName = ecu.Name,
  72. CreateTime = u.CreateTime,
  73. ModifyUserID = u.ModifyUserID,
  74. ModifyUserName = emu.Name,
  75. ModifyTime = u.ModifyTime
  76. });
  77. return q;
  78. }
  79. /// <summary>
  80. ///
  81. /// </summary>
  82. /// <param name="userExpression"></param>
  83. /// <param name="roleExpression"></param>
  84. /// <returns></returns>
  85. public IQueryable<StudentUserView> GetStudentUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  86. {
  87. var q = (from u in UserRepository.GetList(userExpression).Where(x => x.CF_Student.UserID != null)
  88. from ur in u.Sys_Role.DefaultIfEmpty()
  89. join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr
  90. from er in dr.DefaultIfEmpty()
  91. join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_RoleType).Name) on ur.TypeID equals dis.Value into ddis
  92. from edis in ddis.DefaultIfEmpty()
  93. join dirs in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_STATUS).Name) on u.RecordStatus equals dirs.Value into ddirs
  94. from edirs in ddirs.DefaultIfEmpty()
  95. join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu
  96. from ecu in dcu.DefaultIfEmpty()
  97. join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu
  98. from emu in dmu.DefaultIfEmpty()
  99. select new StudentUserView
  100. {
  101. UserID = u.UserID,
  102. LoginID = u.LoginID,
  103. Name = u.Name,
  104. SexID = u.CF_Student.SexID,
  105. BirthDate = u.CF_Student.BirthDate,
  106. Grade = u.CF_Student.CF_Classmajor.CF_Grademajor.GradeID,
  107. ClassmajorID = u.CF_Student.ClassmajorID,
  108. ClassNo = u.CF_Student.CF_Classmajor.No,
  109. ClassmajorName = u.CF_Student.CF_Classmajor.Name,
  110. CollegeID=u.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  111. InSchool = u.CF_Student.InSchoolStatusID,
  112. RoleTypeName = edis.Name,//角色类型名称(教师、学生)
  113. RoleID = er.RoleID,
  114. RoleName = er.RoleName,
  115. Remarks = u.CF_Student.Remark,
  116. RecordStatus = u.RecordStatus,
  117. RecordStatusDesc = edirs.Name,
  118. CreateUserID = u.CreateUserID,
  119. CreateUserName = ecu.Name,
  120. CreateTime = u.CreateTime,
  121. ModifyUserID = u.ModifyUserID,
  122. ModifyUserName = emu.Name,
  123. ModifyTime = u.ModifyTime
  124. });
  125. return q;
  126. }
  127. }
  128. }