EvaluationControlServices.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.EvaluationManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.EvaluationManage;
  11. using EMIS.CommonLogic.SystemServices;
  12. namespace EMIS.CommonLogic.EvaluationManage
  13. {
  14. public class EvaluationControlServices : BaseServices, IEvaluationControlServices
  15. {
  16. public EvaluationControlDAL evaluationControlDAL { get; set; }
  17. public Lazy<IControlItemServices> ControlItemServices { get; set; }
  18. /// <summary>
  19. /// 查询评价控制信息
  20. /// </summary>
  21. /// <param name="configuretView">查询条件实体</param>
  22. /// <param name="pageIndex">页码</param>
  23. /// <param name="pageSize">显示页数</param>
  24. /// <returns></returns>
  25. public IGridResultSet<EvaluationControlView> GetEvaluationControlViewGrid(ConfiguretView configuretView, int? isResult, int? isCourse, int pageIndex, int pageSize)
  26. {
  27. var query = evaluationControlDAL.GetEvaluationControlQueryable(x => true);
  28. if (isResult.HasValue && isResult > -1)
  29. {
  30. bool result = isResult == 1 ? true : false;
  31. query = query.Where(x => x.IsResult == result);
  32. }
  33. if (isCourse.HasValue && isCourse > -1)
  34. {
  35. bool course = isCourse == 1 ? true : false;
  36. query = query.Where(x => x.IsCourse == course);
  37. }
  38. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  39. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToGridResultSet<EvaluationControlView>(pageIndex, pageSize);
  40. return query.OrderByDescending(x => x.CreateTime).ToGridResultSet<EvaluationControlView>(pageIndex, pageSize);
  41. }
  42. /// <summary>
  43. /// 查询评价控制信息
  44. /// </summary>
  45. /// <param name="configuretView">查询条件实体</param>
  46. /// <returns></returns>
  47. public List<EvaluationControlView> GetEvaluationControlViewList(ConfiguretView configuretView, int? isResult, int? isCourse)
  48. {
  49. var query = evaluationControlDAL.GetEvaluationControlQueryable(x => true);
  50. if (isResult.HasValue && isResult > -1)
  51. {
  52. bool result = isResult == 1 ? true : false;
  53. query = query.Where(x => x.IsResult == result);
  54. }
  55. if (isCourse.HasValue && isCourse > -1)
  56. {
  57. bool course = isCourse == 1 ? true : false;
  58. query = query.Where(x => x.IsCourse == course);
  59. }
  60. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  61. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList();
  62. return query.OrderByDescending(x => x.CreateTime).ToList();
  63. }
  64. /// <summary>
  65. /// 获取评价控制信息
  66. /// </summary>
  67. /// <param name="controlID">主键ID</param>
  68. /// <returns></returns>
  69. public EM_EvaluationControl GetEvaluationControl(Guid? controlID)
  70. {
  71. //查询条件
  72. Expression<Func<EM_EvaluationControl, bool>> expression = (x => x.EvaluationControlID == controlID.Value);
  73. return evaluationControlDAL.evaluationControlRepository.GetSingle(expression);
  74. }
  75. /// <summary>
  76. /// 获取评价控制信息
  77. /// </summary>
  78. /// <param name="schoolyearID">学年学期ID</param>
  79. /// <returns></returns>
  80. public EM_EvaluationControl GetEvaluationControl(Guid schoolyearID)
  81. {
  82. //查询条件
  83. Expression<Func<EM_EvaluationControl, bool>> expression = (x => x.SchoolyearID == schoolyearID);
  84. return evaluationControlDAL.evaluationControlRepository.GetSingle(expression);
  85. }
  86. /// <summary>
  87. /// 获取评价控制信息
  88. /// </summary>
  89. /// <param name="controlID">主键ID</param>
  90. /// <returns></returns>
  91. public EvaluationControlView GetEvaluationControlView()
  92. {
  93. var evaluationControlView = new EvaluationControlView();
  94. //数据字典配置控制类型(费用控制-1,注册控制-2,评价控制-3)
  95. var type = SYS_ControlItemType.Evaluation;
  96. var controlItemList = ControlItemServices.Value.GetControlItemList(type);
  97. evaluationControlView = evaluationControlDAL.GetEvaluationControlQueryable(x => true).FirstOrDefault();
  98. if (evaluationControlView==null)
  99. {
  100. evaluationControlView = new EvaluationControlView();
  101. evaluationControlView.IsCourse = false;
  102. evaluationControlView.IsResult = false;
  103. evaluationControlView.IsStudentExaminationApply = false;
  104. evaluationControlView.IsStudentLevelScore = false;
  105. evaluationControlView.IsCourseDisplay = "none";
  106. evaluationControlView.IsResultDisplay = "none";
  107. evaluationControlView.IsStudentExaminationApplyDisplay = "none";
  108. evaluationControlView.IsStudentLevelScoreDisplay = "none";
  109. return evaluationControlView;
  110. }
  111. if (controlItemList == null || controlItemList.Count <= 0)
  112. {
  113. evaluationControlView.IsCourse = false;
  114. evaluationControlView.IsResult = false;
  115. evaluationControlView.IsStudentExaminationApply = false;
  116. evaluationControlView.IsStudentLevelScore = false;
  117. evaluationControlView.IsCourseDisplay = "none";
  118. evaluationControlView.IsResultDisplay = "none";
  119. evaluationControlView.IsStudentExaminationApplyDisplay = "none";
  120. evaluationControlView.IsStudentLevelScoreDisplay = "none";
  121. }
  122. else
  123. {
  124. var CourseLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationSelectCourse");
  125. var ResultLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationScore");
  126. var StudentExaminationApplyLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationExaminationApply");
  127. var StudentLevelScoreLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationLevelScore");
  128. if (CourseLock != null)
  129. {
  130. evaluationControlView.IsCourse = CourseLock.IsEnable ?? false;
  131. evaluationControlView.Course = CourseLock.Message;
  132. evaluationControlView.IsCourseDisplay = "table-row";
  133. }
  134. else
  135. {
  136. evaluationControlView.IsCourse = false;
  137. evaluationControlView.Course = "";
  138. evaluationControlView.IsCourseDisplay = "none";
  139. }
  140. if (ResultLock != null)
  141. {
  142. evaluationControlView.IsResult = ResultLock.IsEnable ?? false;
  143. evaluationControlView.Result = ResultLock.Message;
  144. evaluationControlView.IsResultDisplay = "table-row";
  145. }
  146. else
  147. {
  148. evaluationControlView.IsResult = false;
  149. evaluationControlView.Result = "";
  150. evaluationControlView.IsResultDisplay = "none";
  151. }
  152. if (StudentExaminationApplyLock != null)
  153. {
  154. evaluationControlView.IsStudentExaminationApply = StudentExaminationApplyLock.IsEnable ?? false;
  155. evaluationControlView.StudentExaminationApply = StudentExaminationApplyLock.Message;
  156. evaluationControlView.IsStudentExaminationApplyDisplay = "table-row";
  157. }
  158. else
  159. {
  160. evaluationControlView.IsStudentExaminationApply = false;
  161. evaluationControlView.StudentExaminationApply = "";
  162. evaluationControlView.IsStudentExaminationApplyDisplay = "none";
  163. }
  164. if (StudentLevelScoreLock != null)
  165. {
  166. evaluationControlView.IsStudentLevelScore = StudentLevelScoreLock.IsEnable ?? false;
  167. evaluationControlView.StudentLevelScore = StudentLevelScoreLock.Message;
  168. evaluationControlView.IsStudentLevelScoreDisplay = "table-row";
  169. }
  170. else
  171. {
  172. evaluationControlView.IsStudentLevelScore = false;
  173. evaluationControlView.StudentLevelScore = "";
  174. evaluationControlView.IsStudentLevelScoreDisplay = "none";
  175. }
  176. }
  177. return evaluationControlView;
  178. }
  179. /// <summary>
  180. /// 保存
  181. /// </summary>
  182. /// <param name="evaluationControl">实体</param>
  183. /// <returns></returns>
  184. public bool EvaluationControlSave(EvaluationControlView evaluationControlView)
  185. {
  186. try
  187. {
  188. UnitOfWork.Delete<EM_EvaluationControl>(x => true);
  189. var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  190. var controlItemList = ControlItemServices.Value.GetControlItemList(SYS_ControlItemType.Evaluation);
  191. var CourseLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationSelectCourse");
  192. var StudentExaminationApplyLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationExaminationApply");
  193. var ResultLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationScore");
  194. var StudentLevelScoreLock = controlItemList.FirstOrDefault(x => x.ControlItemCode == "EvaluationStudentLevelScore");
  195. if (CourseLock != null)
  196. {
  197. CourseLock.IsEnable = evaluationControlView.IsCourse;
  198. //CourseLock.Message = evaluationControlView.Course;
  199. }
  200. if (ResultLock != null)
  201. {
  202. ResultLock.IsEnable = evaluationControlView.IsResult;
  203. //ResultLock.Message = evaluationControlView.Result;
  204. }
  205. if (StudentExaminationApplyLock != null)
  206. {
  207. StudentExaminationApplyLock.IsEnable = evaluationControlView.IsStudentExaminationApply;
  208. //StudentExaminationApplyLock.Message = evaluationControlView.StudentExaminationApply;
  209. }
  210. if (StudentLevelScoreLock != null)
  211. {
  212. StudentLevelScoreLock.IsEnable = evaluationControlView.IsStudentLevelScore;
  213. //StudentLevelScoreLock.Message = evaluationControlView.StudentLevelScore;
  214. }
  215. EM_EvaluationControl evaluationControl = new EM_EvaluationControl();
  216. evaluationControl.EvaluationControlID = Guid.NewGuid();
  217. evaluationControl.SchoolyearID = evaluationControlView.SchoolyearID.Value;
  218. evaluationControl.IsCourseScoreLock = evaluationControlView.IsResult;
  219. evaluationControl.IsSelectCourseLock = evaluationControlView.IsCourse;
  220. evaluationControl.IsExaminationApplyLock = evaluationControlView.IsStudentExaminationApply;
  221. evaluationControl.IsLevelScoreLock = evaluationControlView.IsStudentLevelScore;
  222. evaluationControl.NoNumber = evaluationControlView.AllowNotEvaluationCount;
  223. evaluationControl.CreateTime = DateTime.Now;
  224. evaluationControl.CreateUserID = curUser.UserID;
  225. evaluationControl.ModifyUserID = curUser.UserID;
  226. evaluationControl.ModifyTime = DateTime.Now;
  227. UnitOfWork.Add(evaluationControl);
  228. UnitOfWork.Commit();
  229. ControlItemServices.Value.RefreshCache();
  230. return true;
  231. }
  232. catch (Exception)
  233. {
  234. throw new Exception("控制项目表中评价控制数据为空,请配置。");
  235. }
  236. }
  237. public bool CanViewScore(Guid userID)
  238. {
  239. var evaluationControl = this.GetEvaluationControlView();
  240. var notEvaluationCount = evaluationControlDAL.GetStudentNotEvaluationList(x => x.UserID == userID, x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  241. && x.OpenStatus == (int)CF_GeneralPurpose.IsYes && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == evaluationControl.SchoolyearID).Count();
  242. if (notEvaluationCount > evaluationControl.AllowNotEvaluationCount && evaluationControl.IsResult)
  243. {
  244. return false;
  245. }
  246. return true;
  247. }
  248. public bool CanSelectCourse(Guid userID)
  249. {
  250. var evaluationControl = this.GetEvaluationControlView();
  251. var notEvaluationCount = evaluationControlDAL.GetStudentNotEvaluationList(x => x.UserID == userID, x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  252. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == evaluationControl.SchoolyearID).Count();
  253. if (notEvaluationCount > evaluationControl.AllowNotEvaluationCount && evaluationControl.IsCourse)
  254. {
  255. return false;
  256. }
  257. return true;
  258. }
  259. public bool CanExaminationApply(Guid userID)
  260. {
  261. var evaluationControl = this.GetEvaluationControlView();
  262. var notEvaluationCount = evaluationControlDAL.GetStudentNotEvaluationList(x => x.UserID == userID, x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  263. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == evaluationControl.SchoolyearID).Count();
  264. if (notEvaluationCount > evaluationControl.AllowNotEvaluationCount && evaluationControl.IsStudentExaminationApply)
  265. {
  266. return false;
  267. }
  268. return true;
  269. }
  270. public bool CanViewLevelScore(Guid userID)
  271. {
  272. var evaluationControl = this.GetEvaluationControlView();
  273. var notEvaluationCount = evaluationControlDAL.GetStudentNotEvaluationList(x => x.UserID == userID, x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  274. && x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID == evaluationControl.SchoolyearID).Count();
  275. if (notEvaluationCount > evaluationControl.AllowNotEvaluationCount && evaluationControl.IsStudentLevelScore)
  276. {
  277. return false;
  278. }
  279. return true;
  280. }
  281. }
  282. }