SOCDetailServices.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.DQPSystem;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.DQPSystem;
  12. using EMIS.CommonLogic.SystemServices;
  13. namespace EMIS.CommonLogic.DQPSystem
  14. {
  15. public class SOCDetailServices : BaseServices, ISOCDetailServices, IFileUploadServices
  16. {
  17. public SOCDetailDAL SOCDetailDAL { get; set; }
  18. public SOCDAL SOCDAL { get; set; }
  19. public IRoleServices RoleServices { get; set; }
  20. public IGridResultSet<SOCDetailView> GetSOCDetailViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? staffID, int pageIndex, int pageSize)
  21. {
  22. Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
  23. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  24. if (schoolyearID.HasValue)
  25. {
  26. exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID);
  27. }
  28. if (coursematerialID.HasValue)
  29. {
  30. exp = exp.And(x => x.DQP_SOC.CoursematerialID == coursematerialID);
  31. }
  32. if (collegeID.HasValue)
  33. {
  34. exp = exp.And(x => x.DQP_SOC.CF_Department.CollegeID == collegeID);
  35. }
  36. if (staffID.HasValue)
  37. {
  38. exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == staffID));
  39. }
  40. var role = RoleServices.GetEnabledTeacherRoleViewList();
  41. var teacherRole = role.Where(x => x.RoleName == "教师");
  42. var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  43. if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID)
  44. {
  45. exp = exp.And(x => x.CreateUserID == curUser.UserID);
  46. exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == curUser.UserID));
  47. query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  48. }
  49. else
  50. {
  51. query = this.GetQueryByDataRangeByDepartment(query);
  52. }
  53. //查询条件
  54. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  55. {
  56. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  57. }
  58. //query = this.GetQueryByDataRangeByDepartment(query);
  59. var result = query
  60. .OrderBy(x => x.SchoolyearCode.Length)
  61. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.Name.Length).ThenBy(x => x.Name)
  62. .ToGridResultSet<SOCDetailView>(pageIndex, pageSize);
  63. return result;
  64. }
  65. public IGridResultSet<SOCDetailView> GetSOCDetailViewByIDGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? socID, Guid? userID, int pageIndex, int pageSize)
  66. {
  67. Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
  68. if (schoolyearID.HasValue)
  69. {
  70. exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID);
  71. }
  72. if (socID.HasValue)
  73. {
  74. exp = exp.And(x => x.SOCID == socID);
  75. }
  76. if (userID.HasValue)
  77. {
  78. exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == userID));
  79. exp = exp.And(x => x.CreateUserID == userID);
  80. }
  81. var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  82. //查询条件
  83. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  84. {
  85. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  86. }
  87. //query = this.GetQueryByDataRangeByDepartment(query);
  88. var result = query
  89. .OrderBy(x => x.SchoolyearCode.Length)
  90. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.Name.Length).ThenBy(x => x.Name)
  91. .ToGridResultSet<SOCDetailView>(pageIndex, pageSize);
  92. return result;
  93. }
  94. public List<SOCDetailView> GetSOCDetailViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? coursematerialID, Guid? collegeID, Guid? staffID, List<Guid?> idList)
  95. {
  96. Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
  97. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  98. if (schoolyearID.HasValue)
  99. {
  100. exp = exp.And(x => x.DQP_SOC.SchoolyearID == schoolyearID);
  101. }
  102. if (coursematerialID.HasValue)
  103. {
  104. exp = exp.And(x => x.DQP_SOC.CoursematerialID == coursematerialID);
  105. }
  106. if (collegeID.HasValue)
  107. {
  108. exp = exp.And(x => x.DQP_SOC.CF_Department.CollegeID == collegeID);
  109. }
  110. if (staffID.HasValue)
  111. {
  112. exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == staffID));
  113. }
  114. if (idList.Count > 0)
  115. {
  116. exp = exp.And(x => idList.Contains(x.SOCDetailID));
  117. }
  118. var role = RoleServices.GetEnabledTeacherRoleViewList();
  119. var teacherRole = role.Where(x => x.RoleName == "教师");
  120. var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  121. if (curUser.RoleID == teacherRole.FirstOrDefault().RoleID)
  122. {
  123. exp = exp.And(x => x.CreateUserID == curUser.UserID);
  124. exp = exp.And(x => x.DQP_SOC.DQP_SOCStaff.Any(y => y.UserID == curUser.UserID));
  125. query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  126. }
  127. else
  128. {
  129. query = this.GetQueryByDataRangeByDepartment(query);
  130. }
  131. //var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp);
  132. //查询条件
  133. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  134. {
  135. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  136. }
  137. var result = query
  138. .OrderBy(x => x.SchoolyearCode.Length)
  139. .ThenByDescending(x => x.SchoolyearCode).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
  140. .ToList();
  141. return result;
  142. }
  143. public SOCDetailView GetSOCDetailView(Guid? SOCDetailID)
  144. {
  145. Expression<Func<DQP_SOCDetail, bool>> exp = x => true;
  146. if (SOCDetailID.HasValue)
  147. {
  148. exp = exp.And(x => x.SOCDetailID == SOCDetailID);
  149. }
  150. var query = SOCDetailDAL.GetSOCDetailViewQueryable(exp).FirstOrDefault();
  151. return query;
  152. }
  153. public void SOCDetailEdit(SOCDetailView SOCDetailView, List<FileUploadView> fileList)
  154. {
  155. try
  156. {
  157. var detail = SOCDetailDAL.SOCDetailRepository.GetSingle(x => x.SOCDetailID == SOCDetailView.SOCDetailID, x => x.DQP_SOCDetailAttachment);
  158. if (detail != null)
  159. {
  160. detail.Name = SOCDetailView.Name;
  161. //detail.Credit = SOCDetailView.Credit;
  162. detail.Description = SOCDetailView.Description;
  163. detail.IsGroup = SOCDetailView.IsGroupin;
  164. detail.StartTime = SOCDetailView.StartTime;
  165. detail.EndTime = SOCDetailView.EndTime;
  166. this.SetModifyStatus(detail);
  167. if (SOCDetailView.IsChangeAttachment == 1)
  168. {
  169. UnitOfWork.Remove<DQP_SOCDetailAttachment>(x => x.SOCDetailID == SOCDetailView.SOCDetailID);
  170. foreach (var file in fileList)
  171. {
  172. DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  173. if (!detail.DQP_SOCDetailAttachment.Any(x => x.SOCDetailAttachmentID == file.FileID))
  174. {
  175. //新增
  176. attachment.SOCDetailAttachmentID = file.FileID;
  177. attachment.SOCDetailID = file.FormID;
  178. attachment.Name = file.FileName;
  179. attachment.Url = file.FileUrl;
  180. this.SetNewStatus(attachment);
  181. detail.DQP_SOCDetailAttachment.Add(attachment);
  182. }
  183. }
  184. }
  185. }
  186. UnitOfWork.Commit();
  187. }
  188. catch (Exception)
  189. {
  190. throw;
  191. }
  192. }
  193. public void SOCDetailAttachmentSave(Guid? SOCDetailID, List<FileUploadView> fileList)
  194. {
  195. var detail = SOCDetailDAL.SOCDetailRepository.GetSingle(x => x.SOCDetailID == SOCDetailID, x => x.DQP_SOCDetailAttachment);
  196. if (detail != null)
  197. {
  198. UnitOfWork.Delete<DQP_SOCDetailAttachment>(x => x.SOCDetailID == SOCDetailID);
  199. foreach (var file in fileList)
  200. {
  201. DQP_SOCDetailAttachment attachment = new DQP_SOCDetailAttachment();
  202. attachment.SOCDetailAttachmentID = Guid.NewGuid();
  203. attachment.SOCDetailID = file.FormID;
  204. attachment.Name = file.FileName;
  205. attachment.Url = file.FileUrl;
  206. this.SetNewStatus(attachment);
  207. detail.DQP_SOCDetailAttachment.Add(attachment);
  208. }
  209. }
  210. UnitOfWork.Commit();
  211. }
  212. public void SOCDetailDelete(List<Guid?> idList)
  213. {
  214. UnitOfWork.Delete<DQP_SOCDetail>(w => idList.Contains(w.SOCDetailID));
  215. }
  216. public List<FileUploadView> GetFileList(Guid? formID)
  217. {
  218. //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
  219. var fileList = SOCDAL.GetSOCDetailAttachmentView(x => x.SOCDetailID == formID).ToList();
  220. return fileList;
  221. }
  222. public IGridResultSet<FileUploadView> GetSOCDetailAttachmentViewList(ConfiguretView studentAttachmentConditionView, Guid? socDetailID, int? pageIndex, int? pageSize)
  223. {
  224. if (!socDetailID.HasValue)
  225. {
  226. return new GridResultSet<FileUploadView>();
  227. }
  228. Expression<Func<DQP_SOCDetail, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  229. && x.SOCDetailID == socDetailID);
  230. var query = SOCDetailDAL.GetSOCDetailAttachmentView(exp);
  231. return query.ToGridResultSet(pageIndex, pageSize);
  232. }
  233. }
  234. }