SOCDocServices.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.DQPSystem;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.DQPSystem;
  11. using EMIS.Entities;
  12. using EMIS.DataLogic.Repositories;
  13. using System.Web;
  14. namespace EMIS.CommonLogic.DQPSystem
  15. {
  16. public class SOCDocServices : BaseServices, ISOCDocServices
  17. {
  18. public RoleRepository RoleRepository { get; set; }
  19. public CollegeRepository CollegeRepository { get; set; }
  20. public DepartmentRepository DepartmentRepository { get; set; }
  21. public SOCDocDAL SOCDocDAL { get; set; }
  22. public IGridResultSet<SOCDocView> GetSOCDocViewList(ConfiguretView socDocConditionView, int? socDocTypeID, Guid? createCollegeID,
  23. Guid? targetRoleID, Guid? targetCollegeID, int? pageIndex, int? pageSize)
  24. {
  25. Expression<Func<DQP_Document, bool>> exp = (x => true);
  26. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  27. if (socDocTypeID.HasValue)
  28. {
  29. exp = exp.And(x => x.SOCDocTypeID == socDocTypeID);
  30. }
  31. if (createCollegeID.HasValue)
  32. {
  33. staffExp = staffExp.And(x => x.CollegeID == createCollegeID);
  34. }
  35. if (targetRoleID.HasValue)
  36. {
  37. exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID));
  38. }
  39. if (targetCollegeID.HasValue)
  40. {
  41. exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID));
  42. }
  43. var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp);
  44. if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute))
  45. query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue);
  46. query = this.GetQueryByDataRangeByCollege(query, (x => x.CreateCollegeID));
  47. query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime);
  48. return query.ToGridResultSet(pageIndex, pageSize);
  49. }
  50. public List<SOCDocView> GetSOCDocViewList(ConfiguretView socDocConditionView, int? socDocTypeID, Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID)
  51. {
  52. Expression<Func<DQP_Document, bool>> exp = (x => true);
  53. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  54. if (socDocTypeID.HasValue)
  55. {
  56. exp = exp.And(x => x.SOCDocTypeID == socDocTypeID);
  57. }
  58. if (createCollegeID.HasValue)
  59. {
  60. staffExp = staffExp.And(x => x.CollegeID == createCollegeID);
  61. }
  62. if (targetRoleID.HasValue)
  63. {
  64. exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID));
  65. }
  66. if (targetCollegeID.HasValue)
  67. {
  68. exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID));
  69. }
  70. var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp);
  71. if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute))
  72. query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue);
  73. query = this.GetQueryByDataRangeByCollege(query, (x => x.CreateCollegeID));
  74. query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime);
  75. return query.ToList();
  76. }
  77. public IGridResultSet<SOCDocView> GetUserSOCDocViewList(ConfiguretView socDocConditionView, Guid roleID, int? socDocTypeID,
  78. Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID, int? pageIndex, int? pageSize)
  79. {
  80. Expression<Func<DQP_Document, bool>> exp = (x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes);
  81. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  82. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  83. var DepartmentID=SOCDocDAL.StaffRepository.GetList(x=>x.UserID==curUser.UserID).Select(x=>x.DepartmentID).FirstOrDefault();
  84. exp=exp.And(x=>(x.CF_Department.Count()==0||x.CF_Department.Any(w=>w.DepartmentID==DepartmentID)));
  85. exp = exp.And(x => (x.CF_College.Count() == 0 || x.CF_College.AsQueryable().Any(this.GetDataRageExpressionByCollege<CF_College>(w => w.CollegeID))));
  86. exp = exp.And(x => (x.Sys_Role.Count() == 0 || x.Sys_Role.Any(w => w.RoleID == roleID)));
  87. if (socDocTypeID.HasValue)
  88. {
  89. exp = exp.And(x => x.SOCDocTypeID == socDocTypeID);
  90. }
  91. if (createCollegeID.HasValue)
  92. {
  93. staffExp = staffExp.And(x => x.CollegeID == createCollegeID);
  94. }
  95. if (targetRoleID.HasValue)
  96. {
  97. exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID));
  98. }
  99. if (targetCollegeID.HasValue)
  100. {
  101. exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID));
  102. }
  103. var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp);
  104. if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute))
  105. query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue);
  106. query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime);
  107. return query.ToGridResultSet(pageIndex, pageSize);
  108. }
  109. public List<SOCDocView> GetUserSOCDocViewList(ConfiguretView socDocConditionView, Guid roleID, int? socDocTypeID,
  110. Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID)
  111. {
  112. Expression<Func<DQP_Document, bool>> exp = (x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes);
  113. Expression<Func<CF_Staff, bool>> staffExp = (x => true);
  114. exp = exp.And(x => (x.CF_College.Count() == 0 || x.CF_College.AsQueryable().Any(this.GetDataRageExpressionByCollege<CF_College>(w => w.CollegeID))));
  115. exp = exp.And(x => (x.Sys_Role.Count() == 0 || x.Sys_Role.Any(w => w.RoleID == roleID)));
  116. if (socDocTypeID.HasValue)
  117. {
  118. exp = exp.And(x => x.SOCDocTypeID == socDocTypeID);
  119. }
  120. if (createCollegeID.HasValue)
  121. {
  122. staffExp = staffExp.And(x => x.CollegeID == createCollegeID);
  123. }
  124. if (targetRoleID.HasValue)
  125. {
  126. exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID));
  127. }
  128. if (targetCollegeID.HasValue)
  129. {
  130. exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID));
  131. }
  132. var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp);
  133. if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute))
  134. query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue);
  135. query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime);
  136. return query.ToList();
  137. }
  138. public void Save(SOCDocView documentView, IList<Guid?> targetRoleIDList, IList<Guid?> targetDepartmentIDList)
  139. {
  140. var document = new DQP_Document();
  141. var targetRoleList = this.RoleRepository.GetList(x => targetRoleIDList.Contains(x.RoleID)).ToList();
  142. var targetDepartmentList = this.DepartmentRepository.GetList(x => targetDepartmentIDList.Contains(x.DepartmentID)).ToList();
  143. if (documentView.DocumentID != Guid.Empty)
  144. {
  145. document = this.SOCDocDAL.DocumentRepository.GetSingle(x => x.DocumentID == documentView.DocumentID, (x => x.Sys_Role), (x => x.CF_College));
  146. this.SetModifyStatus(document);
  147. }
  148. else
  149. {
  150. document.DocumentID = Guid.NewGuid();
  151. this.SetNewStatus(document);
  152. this.UnitOfWork.Add(document);
  153. }
  154. document.SOCDocTypeID = documentView.SOCDocTypeID;
  155. document.Title = documentView.Title;
  156. document.Content = documentView.Content;
  157. document.Sys_Role = new HashSet<Sys_Role>();
  158. document.Sys_Role = new HashSet<Sys_Role>(targetRoleList);
  159. document.CF_Department = new HashSet<CF_Department>();
  160. document.CF_Department = new HashSet<CF_Department>(targetDepartmentList);
  161. document.RecordStatus = (int)(documentView.IsShow ? CF_GeneralPurpose.IsYes : CF_GeneralPurpose.IsNo);
  162. UnitOfWork.Commit();
  163. }
  164. public void Delete(IList<Guid?> documentIDList)
  165. {
  166. var documentList = this.SOCDocDAL.DocumentRepository.GetList(x => documentIDList.Contains(x.DocumentID), (x => x.Sys_Role), (x => x.CF_College)).ToList();
  167. this.UnitOfWork.Delete(documentList, (x => x.Sys_Role));
  168. this.UnitOfWork.Delete(documentList, (x => x.CF_College));
  169. this.UnitOfWork.Delete(documentList, (x => x.CF_Department));
  170. this.UnitOfWork.Delete(documentList);
  171. }
  172. public SOCDocView GetSOCDocView(Guid documentID)
  173. {
  174. var documentView = SOCDocDAL.GetSOCDocViewQueryable((x => x.DocumentID == documentID), (x => true)).FirstOrDefault();
  175. return documentView;
  176. }
  177. }
  178. }