MisconductServices.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.CommonLogic.SystemServices;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.DataLogic.ScoreManage;
  12. using EMIS.ViewModel.Cultureplan;
  13. using EMIS.Utility;
  14. namespace EMIS.CommonLogic.ScoreManage
  15. {
  16. public class MisconductServices : BaseWorkflowServices<ER_Misconduct>, IMisconductServices
  17. {
  18. public ExaminationSuspensionDAL ExaminationSuspensionDAL { get; set; }
  19. public MisconductDAL MisconductDAL { get; set; }
  20. public FinalExaminationDAL FinalExaminationDAL { get; set; }
  21. public ExamsStateSettingDAL ExamsStateSettingDAL { get; set; }
  22. public Lazy<IScoreServices> ScoreServices { get; set; }
  23. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.MisconductView> GetMisconductGridView(ViewModel.ConfiguretView conditions,
  24. Guid? schoolyearID, Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? examsStateID,
  25. int? recordStatus, int? learningformID, int? education, string LearnSystem, int? pageIndex = null, int? pageSize = null)
  26. {
  27. Expression<Func<ER_Misconduct, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  28. var statusList = this.GetStatusViewList();
  29. if (schoolyearID.HasValue)
  30. {
  31. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  32. }
  33. if (collegeID.HasValue)
  34. {
  35. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  36. }
  37. if (year.HasValue)
  38. {
  39. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year);
  40. }
  41. if (standardID.HasValue)
  42. {
  43. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  44. }
  45. if (classmajorID.HasValue)
  46. {
  47. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  48. }
  49. if (examsCatagoryID.HasValue)
  50. {
  51. exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID);
  52. }
  53. if (examsStateID.HasValue)
  54. {
  55. exp = exp.And(x => x.ExamsStateID == examsStateID);
  56. }
  57. if (recordStatus.HasValue)
  58. {
  59. exp = exp.And(x => x.RecordStatus == recordStatus);
  60. }
  61. if (learningformID.HasValue)
  62. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  63. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  64. {
  65. var LearnSystems = Convert.ToDecimal(LearnSystem);
  66. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  67. }
  68. if (education.HasValue)
  69. {
  70. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  71. }
  72. var query = this.MisconductDAL.GetMisconductViewQueryable(exp);
  73. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  74. {
  75. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  76. }
  77. query = this.GetQueryByDataRangeByCollege(query);
  78. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToGridResultSet(pageIndex, pageSize);
  79. result.rows.ForEach(x =>
  80. {
  81. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  82. if (currentStatus != null)
  83. {
  84. x.RecordStatusName = currentStatus.Name;
  85. }
  86. else
  87. {
  88. x.RecordStatusName = "";
  89. }
  90. });
  91. return result;
  92. }
  93. public List<ViewModel.ScoreManage.MisconductView> GetMisconductViewList(ViewModel.ConfiguretView conditions, Guid? schoolyearID,
  94. Guid? collegeID, int? year, int? standardID, Guid? classmajorID, int? examsCatagoryID, int? examsStateID, int? recordStatus, int? learningformID, int? education, string LearnSystem)
  95. {
  96. Expression<Func<ER_Misconduct, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  97. var statusList = this.GetStatusViewList();
  98. if (schoolyearID.HasValue)
  99. {
  100. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  101. }
  102. if (collegeID.HasValue)
  103. {
  104. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  105. }
  106. if (year.HasValue)
  107. {
  108. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == year);
  109. }
  110. if (standardID.HasValue)
  111. {
  112. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  113. }
  114. if (classmajorID.HasValue)
  115. {
  116. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  117. }
  118. if (examsCatagoryID.HasValue)
  119. {
  120. exp = exp.And(x => x.ExamsCategoryID == examsCatagoryID);
  121. }
  122. if (examsStateID.HasValue)
  123. {
  124. exp = exp.And(x => x.ExamsStateID == examsStateID);
  125. }
  126. if (recordStatus.HasValue)
  127. {
  128. exp = exp.And(x => x.RecordStatus == recordStatus);
  129. }
  130. if (learningformID.HasValue)
  131. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearningformID == learningformID);
  132. if (!string.IsNullOrEmpty(LearnSystem) && LearnSystem != "-1")
  133. {
  134. var LearnSystems = Convert.ToDecimal(LearnSystem);
  135. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem == LearnSystems);
  136. }
  137. if (education.HasValue)
  138. {
  139. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID == education.Value);
  140. }
  141. var query = this.MisconductDAL.GetMisconductViewQueryable(exp);
  142. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  143. {
  144. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  145. }
  146. query = this.GetQueryByDataRangeByCollege(query);
  147. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  148. result.ForEach(x =>
  149. {
  150. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  151. if (currentStatus != null)
  152. {
  153. x.RecordStatusName = currentStatus.Name;
  154. }
  155. else
  156. {
  157. x.RecordStatusName = "";
  158. }
  159. });
  160. return result;
  161. }
  162. public void Save(ViewModel.ScoreManage.MisconductView misconductView)
  163. {
  164. var dupMisconduct = this.MisconductDAL.MisconductRepository
  165. .GetSingle(x => x.UserID == misconductView.UserID && x.SchoolyearID == misconductView.SchoolyearID
  166. && x.CoursematerialID == misconductView.CoursematerialID && x.ExamsCategoryID == misconductView.ExamsCategoryID);
  167. ER_Misconduct misconduct = this.MisconductDAL.MisconductRepository
  168. .GetSingle(x => x.MisconductID == misconductView.MisconductID);
  169. ER_ExaminationSuspension examinationSuspension = this.ExaminationSuspensionDAL.ExaminationSuspensionRepository
  170. .GetSingle(x => x.SchoolyearID == misconductView.SchoolyearID
  171. &&x.UserID==misconductView.UserID
  172. &&x.ExamsCategoryID==misconductView.ExamsCategoryID
  173. &&x.CoursematerialID==misconductView.CoursematerialID
  174. &&x.RecordStatus==3);
  175. if (examinationSuspension!=null)
  176. {
  177. throw new Exception("该学生有这门考试的缓考申请记录,如需添加违纪请先撤销缓考申请。");
  178. }
  179. if (misconduct == null)
  180. {
  181. if (dupMisconduct != null)
  182. {
  183. throw new Exception("已经有相同的违纪名单,请勿重复申请。");
  184. }
  185. misconduct = new ER_Misconduct();
  186. misconduct.MisconductID = Guid.NewGuid();
  187. this.SetNewStatus(misconduct);
  188. misconduct.RecordStatus = this.GetStartStatus();
  189. this.UnitOfWork.Add(misconduct);
  190. }
  191. else
  192. {
  193. if (dupMisconduct != null && dupMisconduct.MisconductID != misconduct.MisconductID)
  194. {
  195. throw new Exception("已经有相同的违纪名单,请勿重复申请。");
  196. }
  197. this.SetModifyStatus(misconduct);
  198. }
  199. misconduct.UserID = misconductView.UserID;
  200. misconduct.SchoolyearID = misconductView.SchoolyearID;
  201. misconduct.CoursematerialID = misconductView.CoursematerialID;
  202. misconduct.ExamsCategoryID = misconductView.ExamsCategoryID;
  203. misconduct.ExamsStateID = misconductView.ExamsStateID;
  204. misconduct.Reason = misconductView.Reason;
  205. this.UnitOfWork.Commit();
  206. }
  207. public void Delete(IList<Guid> misconductIDList)
  208. {
  209. this.UnitOfWork.Remove<ER_Misconduct>(x => misconductIDList.Contains(x.MisconductID));
  210. this.UnitOfWork.Commit();
  211. }
  212. public List<Sys_DictionaryItem> GetMisconductExamsStateList()
  213. {
  214. var misconductIDList = this.ExamsStateSettingDAL.GetMisconductIDList().ToList();
  215. return DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ExamsState).Where(x => misconductIDList.Contains(x.Value)).ToList();
  216. }
  217. public ViewModel.ScoreManage.MisconductView GetMisconductView(Guid misconductID)
  218. {
  219. var statusList = this.GetStatusViewList();
  220. var misconductView = this.MisconductDAL.GetMisconductViewQueryable(x => x.MisconductID == misconductID)
  221. .FirstOrDefault();
  222. if (misconductView != null)
  223. {
  224. var recordStatus = statusList.FirstOrDefault(x => x.ID == misconductView.RecordStatus);
  225. if (recordStatus != null)
  226. {
  227. misconductView.RecordStatusName = recordStatus.Name;
  228. }
  229. }
  230. return misconductView;
  231. }
  232. public IGridResultSet<CoursematerialView> GetMisconductCoursematerialGridView(
  233. ConfiguretView conditions, Guid? schoolyearID, Guid? userID, int? pageIndex = null, int? pageSize = null)
  234. {
  235. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.SchoolyearID == schoolyearID);
  236. Expression<Func<EMIS.Entities.CF_Student, bool>> studentExp = (x => x.UserID == userID);
  237. var query = this.MisconductDAL.GetMisconductCoursematerialViewQueryable(schoolyearExp, studentExp);
  238. if (!string.IsNullOrEmpty(conditions.ConditionValue))
  239. {
  240. query = query.DynamicWhere(conditions.Attribute, conditions.Condition, conditions.ConditionValue);
  241. }
  242. var result = query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseName).ToGridResultSet(pageIndex, pageSize);
  243. return result;
  244. }
  245. public void OnApproveEnd(IList<Guid> misconductIDList, Guid? userID)
  246. {
  247. ScoreServices.Value.RefreshMisconductState(misconductIDList);
  248. }
  249. public void OnApproveEnds(IList<Guid> misconductIDList, Guid? userID)
  250. {
  251. ScoreServices.Value.RefreshCancelMisconductState(misconductIDList);
  252. }
  253. public List<ViewModel.ScoreManage.MisconductView> GetMisconductViewListByFinalExamination(Guid? finalExaminationID)
  254. {
  255. var endStatus = this.GetCorrectEndStatus();
  256. var finalExaminationView = FinalExaminationDAL.GetFinalExaminationViewQueryable(x => x.FinalExaminationID == finalExaminationID).FirstOrDefault();
  257. if (finalExaminationView == null)
  258. {
  259. return new List<ViewModel.ScoreManage.MisconductView>();
  260. }
  261. Expression<Func<ER_Misconduct, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  262. && x.SchoolyearID == finalExaminationView.SchoolyearID && x.CoursematerialID == finalExaminationView.CoursematerialID
  263. && x.ExamsCategoryID == finalExaminationView.ExamsCategoryID && x.RecordStatus == 3);
  264. var statusList = this.GetStatusViewList();
  265. var query = this.MisconductDAL.GetMisconductViewQueryable(exp);
  266. var result = query.OrderByDescending(x => x.CreateTime).ThenBy(x => x.Year).ThenBy(x => x.StandardID).ToList();
  267. result.ForEach(x =>
  268. {
  269. var currentStatus = statusList.FirstOrDefault(w => w.ID == x.RecordStatus);
  270. if (currentStatus != null)
  271. {
  272. x.RecordStatusName = currentStatus.Name;
  273. }
  274. else
  275. {
  276. x.RecordStatusName = "";
  277. }
  278. });
  279. return result;
  280. }
  281. public void Cancel(List<Guid> misconductIDList, Guid userID, string comment)
  282. {
  283. var endStatusID = GetEndStatusID();
  284. var misconductList = MisconductDAL.MisconductRepository.GetList(x => misconductIDList.Contains(x.MisconductID)).ToList();
  285. if (misconductList.Any(x => x.RecordStatus != endStatusID))
  286. {
  287. throw new Exception("只能撤回已通过状态的记录。");
  288. }
  289. var actionViewList = this.GetActionView(misconductIDList[0], userID);
  290. var actionView = actionViewList.FirstOrDefault();
  291. this.Approve(misconductIDList, userID, actionView.ActionID, comment);
  292. }
  293. public int? GetEndStatusID()
  294. {
  295. var endStatus = this.GetStatusViewList().FirstOrDefault(x => x.Description.Contains("[End]"));
  296. if (endStatus != null)
  297. {
  298. return endStatus.ID;
  299. }
  300. else
  301. {
  302. return null;
  303. }
  304. }
  305. }
  306. }