ProjectRecordServices.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.ViewModel.SupervisionManage;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.SupervisionManage;
  12. using EMIS.CommonLogic.SystemServices;
  13. using EMIS.CommonLogic.CalendarManage;
  14. using System.Web;
  15. namespace EMIS.CommonLogic.SupervisionManage
  16. {
  17. public class ProjectRecordServices : BaseServices, IProjectRecordServices, IFileUploadServices
  18. {
  19. public ProjectRecordDAL projectRecordDAL { get; set; }
  20. public ISchoolYearServices schoolYearServices { get; set; }
  21. public IGridResultSet<ProjectRecordView> GetProjectRecordViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType,
  22. Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate,int DataRange, int? pageIndex = null, int? pageSize = null)
  23. {
  24. Expression<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  25. Expression<Func<CF_Staff, bool>> supervisorExp = (x => true);
  26. if (schoolyearID.HasValue)
  27. {
  28. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  29. }
  30. if (collegeID.HasValue)
  31. {
  32. supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID);
  33. }
  34. if (supervisionType.HasValue)
  35. {
  36. exp = exp.And(x => x.SupervisionTypeID == supervisionType);
  37. }
  38. if (supervisionCollegeID.HasValue)
  39. {
  40. exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID);
  41. }
  42. if (startDate.HasValue)
  43. {
  44. exp = exp.And(x => x.ProjectDate >= startDate);
  45. }
  46. if (endDate.HasValue)
  47. {
  48. var correctEndDate = endDate.Value.Date.AddDays(1);
  49. exp = exp.And(x => x.ProjectDate < correctEndDate);
  50. }
  51. var query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp,null,null);
  52. if (DataRange == (int)SYS_DataRange.Teacher)
  53. {
  54. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  55. var curUserID = curUser.UserID;
  56. query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID,null);
  57. }
  58. if(DataRange != (int)SYS_DataRange.All&&DataRange!=(int)SYS_DataRange.Teacher)
  59. {
  60. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  61. var curUserID = curUser.UserID;
  62. var CollegeID = projectRecordDAL.StaffRepository.GetList(x => x.UserID == curUserID).Select(w => w.CollegeID).FirstOrDefault();
  63. query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID, CollegeID);
  64. }
  65. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  66. {
  67. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  68. }
  69. //query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  70. // .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode);
  71. query=query.OrderByDescending(x => x.SchoolyearID).OrderByDescending(x => x.CreateTime);
  72. return query.ToGridResultSet(pageIndex, pageSize);
  73. }
  74. public List<ProjectRecordView> GetProjectRecordViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID, int? supervisionType,
  75. Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate, List<Guid?> idList, int DataRange)
  76. {
  77. Expression<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  78. Expression<Func<CF_Staff, bool>> supervisorExp = (x => true);
  79. if (schoolyearID.HasValue)
  80. {
  81. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  82. }
  83. if (collegeID.HasValue)
  84. {
  85. supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID);
  86. }
  87. if (supervisionType.HasValue)
  88. {
  89. exp = exp.And(x => x.SupervisionTypeID == supervisionType);
  90. }
  91. if (supervisionCollegeID.HasValue)
  92. {
  93. exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID);
  94. }
  95. if (startDate.HasValue)
  96. {
  97. exp = exp.And(x => x.ProjectDate >= startDate);
  98. }
  99. if (endDate.HasValue)
  100. {
  101. var correctEndDate = endDate.Value.Date.AddDays(1);
  102. exp = exp.And(x => x.ProjectDate < correctEndDate);
  103. }
  104. if (idList != null && idList.Count > 0)
  105. {
  106. exp = exp.And(x => idList.Contains(x.ProjectRecordID));
  107. }
  108. var query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, null,null);
  109. if (DataRange == (int)SYS_DataRange.Teacher)
  110. {
  111. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  112. var curUserID = curUser.UserID;
  113. var User = projectRecordDAL.UserRepository.Entities.Where(x => x.UserID == curUserID).FirstOrDefault();
  114. query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID,null);
  115. }
  116. if (DataRange != (int)SYS_DataRange.All && DataRange != (int)SYS_DataRange.Teacher)
  117. {
  118. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  119. var curUserID = curUser.UserID;
  120. var CollegeID = projectRecordDAL.StaffRepository.GetList(x => x.UserID == curUserID).Select(w => w.CollegeID).FirstOrDefault();
  121. query = projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp, curUserID, CollegeID);
  122. }
  123. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  124. {
  125. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  126. }
  127. //query = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo)
  128. // .ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode);
  129. query = this.GetQueryByDataRangeByCollege(query).OrderByDescending(x => x.SchoolyearID).OrderByDescending(x => x.CreateTime);
  130. return query.ToList();
  131. }
  132. public ProjectRecordView GetProjectRecordView(Guid? projectRecordID)
  133. {
  134. Expression<Func<SUP_ProjectRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  135. Expression<Func<CF_Staff, bool>> supervisorExp = (x => true);
  136. if(projectRecordID.HasValue)
  137. {
  138. exp = exp.And(x => x.ProjectRecordID == projectRecordID);
  139. }
  140. return projectRecordDAL.GetProjectRecordViewQueryable(exp, supervisorExp,null,null).FirstOrDefault();
  141. }
  142. public void Save(ProjectRecordView projectRecordView, List<ProjectRecordTeacherView> teacherList, List<FileUploadView> fileList)
  143. {
  144. try
  145. {
  146. var schoolyear = schoolYearServices.GetCurrentSchoolYear();
  147. if (projectRecordView.SupervisionTypeID == (int)SUP_SupervisionType.Evaluation)
  148. {
  149. SUP_ProjectRecord dbProjectRecordView = projectRecordDAL.ProjectRecordRepository.Entities.Where(x =>
  150. x.ProjectRecordID != projectRecordView.ProjectRecordID
  151. && x.UserID == projectRecordView.UserID
  152. && x.SupervisionTypeID == projectRecordView.SupervisionTypeID
  153. && x.SchoolyearID == projectRecordView.SchoolyearID
  154. && x.CoursematerialID == projectRecordView.CoursematerialID).FirstOrDefault();
  155. if (dbProjectRecordView != null)
  156. {
  157. throw new Exception("该教师对应的课程信息已经存在督导项目。");
  158. }
  159. }
  160. SUP_ProjectRecord projectRecord = null;
  161. List<SUP_ProjectRecordAttachment> addAttachmentList = new List<SUP_ProjectRecordAttachment>();
  162. var dbProjectRecord = projectRecordDAL.ProjectRecordRepository.GetSingle(x => x.ProjectRecordID == projectRecordView.ProjectRecordID);
  163. if (dbProjectRecord == null)
  164. {
  165. projectRecord = new SUP_ProjectRecord();
  166. projectRecord.ProjectRecordID = Guid.NewGuid();
  167. SetNewStatus(projectRecord);
  168. UnitOfWork.Add(projectRecord);
  169. }
  170. else
  171. {
  172. projectRecord = this.projectRecordDAL.ProjectRecordRepository
  173. .GetSingle(x => x.ProjectRecordID == projectRecordView.ProjectRecordID, (x => x.SUP_ProjectRecord_CF_Staff), (x => x.SUP_ProjectRecordAttachment));
  174. if (projectRecord == null)
  175. {
  176. throw new Exception("当前编辑的记录可能已被其他人删除。");
  177. }
  178. projectRecord.SUP_ProjectRecord_CF_Staff = new HashSet<CF_Staff>();
  179. SetModifyStatus(projectRecord);
  180. }
  181. projectRecord.SchoolyearID = projectRecordView.SchoolyearID;//schoolyear.SchoolYearID;
  182. projectRecord.ProjectDate = projectRecordView.ProjectDate;
  183. projectRecord.Location = projectRecordView.Location;
  184. projectRecord.SupervisionCollegeID = projectRecordView.SupervisionCollegeID;
  185. projectRecord.SupervisionTypeID = projectRecordView.SupervisionTypeID;
  186. projectRecord.UserID = projectRecordView.UserID;
  187. projectRecord.TotalScore = projectRecordView.TotalScore;
  188. projectRecord.CoursematerialID = projectRecordView.CoursematerialID;
  189. projectRecord.OtherTarget = projectRecordView.OtherTarget;
  190. projectRecord.Weekday = projectRecordView.Weekday;
  191. projectRecord.CoursesTimeID = projectRecordView.CoursesTimeID;
  192. projectRecord.Content = HttpUtility.HtmlDecode(projectRecordView.Content);
  193. //projectRecordView.Content;
  194. projectRecord.Advise = HttpUtility.HtmlDecode(projectRecordView.Advise);
  195. //projectRecordView.Advise;
  196. HashSet<CF_Staff> addStaff = new HashSet<CF_Staff>();
  197. teacherList.ForEach(x =>
  198. {
  199. CF_Staff staff = projectRecordDAL.StaffRepository.GetSingle(y => y.UserID == x.UserID);
  200. //educationMissionClassCheck.Sys_User = new HashSet<Sys_User>();
  201. addStaff.Add(staff);
  202. });
  203. projectRecord.SUP_ProjectRecord_CF_Staff = addStaff;
  204. projectRecord.SUP_ProjectRecordAttachment = new HashSet<SUP_ProjectRecordAttachment>();
  205. fileList.ToList().ForEach(x =>
  206. {
  207. var attachment = new SUP_ProjectRecordAttachment();
  208. attachment.ProjectRecordAttachmentID = Guid.NewGuid();
  209. attachment.ProjectRecordID = projectRecord.ProjectRecordID;
  210. attachment.Name = x.FileName;
  211. attachment.Url = x.FileUrl;
  212. this.SetNewStatus(attachment);
  213. UnitOfWork.Add(attachment);
  214. });
  215. UnitOfWork.Commit();
  216. }
  217. catch (Exception)
  218. {
  219. throw;
  220. }
  221. }
  222. public void Delete(IList<Guid?> projectRecordIDList)
  223. {
  224. var projectRecordList = projectRecordDAL.ProjectRecordRepository.GetList(x => projectRecordIDList.Contains(x.ProjectRecordID), (x => x.SUP_ProjectRecord_CF_Staff));
  225. foreach (var projectRecord in projectRecordList)
  226. {
  227. projectRecord.SUP_ProjectRecord_CF_Staff = new HashSet<CF_Staff>();
  228. }
  229. UnitOfWork.Remove<SUP_ProjectRecordAttachment>(x => projectRecordIDList.Contains(x.ProjectRecordID));
  230. UnitOfWork.Remove<SUP_ProjectRecord>(x => projectRecordIDList.Contains(x.ProjectRecordID));
  231. UnitOfWork.Commit();
  232. }
  233. public IGridResultSet<ProjectRecordTeacherView> GetProjectRecordTeacherViewGridByID(Guid? projectRecordID, int? pageIndex, int? pageSize)
  234. {
  235. return projectRecordDAL.GetProjectRecordTeacherView(projectRecordID).OrderBy(x => x.LoginID.Length).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
  236. }
  237. public IGridResultSet<ProjectRecordTeacherView> GetDefaultTeacherViewGrid(int? pageIndex, int? pageSize)
  238. {
  239. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  240. return projectRecordDAL.GetDefaultTeacherView(curUser.UserID).OrderBy(x => x.LoginID.Length).OrderBy(x => x.LoginID).ToGridResultSet(pageIndex, pageSize);
  241. }
  242. public List<FileUploadView> GetFileList(Guid? formID)
  243. {
  244. //var socDetailAttachment = SOCDAL.SOCDetailAttachmentRepository.GetSingle(x => x.SOCDetailID == formID);
  245. var fileList = projectRecordDAL.GetProjectRecordAttachmentView(x => x.ProjectRecordID == formID).ToList();
  246. return fileList;
  247. }
  248. }
  249. }