EvaluationStudentServices.cs 17 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 System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Data;
  9. using Bowin.Common.Linq.Entity;
  10. using EMIS.Entities;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.EvaluationManage.StudentEvaluation;
  13. using EMIS.DataLogic.EvaluationManage.StudentEvaluation;
  14. using EMIS.CommonLogic.StudentManage.StudentStatistics;
  15. namespace EMIS.CommonLogic.EvaluationManage.StudentEvaluation
  16. {
  17. public class EvaluationStudentServices : BaseServices, IEvaluationStudentServices
  18. {
  19. public EvaluationStudentDAL EvaluationStudentDAL { get; set; }
  20. public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }
  21. /// <summary>
  22. /// 查询对应的学评学生信息View
  23. /// </summary>
  24. /// <param name="configuretView"></param>
  25. /// <param name="schoolyearID"></param>
  26. /// <param name="campusID"></param>
  27. /// <param name="collegeID"></param>
  28. /// <param name="departmentID"></param>
  29. /// <param name="coursematerialID"></param>
  30. /// <param name="courseTypeID"></param>
  31. /// <param name="teachingModeID"></param>
  32. /// <param name="staffID"></param>
  33. /// <param name="teachingMethodID"></param>
  34. /// <param name="evaluationTableID"></param>
  35. /// <param name="isValidity"></param>
  36. /// <param name="inSchoolStatus"></param>
  37. /// <param name="pageIndex"></param>
  38. /// <param name="pageSize"></param>
  39. /// <returns></returns>
  40. public IGridResultSet<EvaluationStudentView> GetEvaluationStudentViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID,
  41. Guid? coursematerialID, int? courseTypeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? isValidity, int? inSchoolStatus, int pageIndex, int pageSize)
  42. {
  43. Expression<Func<EM_EvaluationStudent, bool>> expEvaluationStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  44. if (isValidity.HasValue)
  45. {
  46. if (isValidity.Value == (int)CF_GeneralPurpose.IsYes)
  47. {
  48. expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity == true);
  49. }
  50. if (isValidity.Value == (int)CF_GeneralPurpose.IsNo)
  51. {
  52. expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity != true);
  53. }
  54. }
  55. Expression<Func<EM_EducationMission, bool>> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  56. if (schoolyearID.HasValue)
  57. {
  58. expEducationMission = expEducationMission.And(x => x.SchoolyearID == schoolyearID);
  59. }
  60. if (collegeID.HasValue)
  61. {
  62. expEducationMission = expEducationMission.And(x => x.CollegeID == collegeID);
  63. }
  64. if (departmentID.HasValue)
  65. {
  66. expEducationMission = expEducationMission.And(x => x.DepartmentID == departmentID);
  67. }
  68. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  69. if (inSchoolStatus != null && inSchoolStatus > -1)
  70. {
  71. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  72. if (inSchoolStatus == 1)
  73. {
  74. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  75. }
  76. if (inSchoolStatus == 0)
  77. {
  78. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  79. }
  80. }
  81. var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(expEvaluationStudent, expEducationMission, expStudent);
  82. if (campusID.HasValue)
  83. {
  84. query = query.Where(x => x.CampusID == campusID);
  85. }
  86. if (coursematerialID.HasValue)
  87. {
  88. query = query.Where(x => x.CoursematerialID == coursematerialID);
  89. }
  90. if (courseTypeID.HasValue)
  91. {
  92. query = query.Where(x => x.CourseTypeID == courseTypeID);
  93. }
  94. if (teachingModeID.HasValue)
  95. {
  96. query = query.Where(x => x.TeachingModeID == teachingModeID);
  97. }
  98. if (staffID.HasValue)
  99. {
  100. query = query.Where(x => x.StaffUserID == staffID);
  101. }
  102. if (teachingMethodID.HasValue)
  103. {
  104. query = query.Where(x => x.TeachingMethodID == teachingMethodID);
  105. }
  106. if (evaluationTableID.HasValue)
  107. {
  108. query = query.Where(x => x.EvaluationTableID == evaluationTableID);
  109. }
  110. //查询条件
  111. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  112. {
  113. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  114. }
  115. return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length).ThenBy(x => x.DepartmentNo)
  116. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ThenBy(x => x.StudentNo).ToGridResultSet<EvaluationStudentView>(pageIndex, pageSize);
  117. }
  118. /// <summary>
  119. /// 查询对应的学评学生信息List
  120. /// </summary>
  121. /// <param name="configuretView"></param>
  122. /// <param name="schoolyearID"></param>
  123. /// <param name="campusID"></param>
  124. /// <param name="collegeID"></param>
  125. /// <param name="departmentID"></param>
  126. /// <param name="coursematerialID"></param>
  127. /// <param name="courseTypeID"></param>
  128. /// <param name="teachingModeID"></param>
  129. /// <param name="staffID"></param>
  130. /// <param name="teachingMethodID"></param>
  131. /// <param name="evaluationTableID"></param>
  132. /// <param name="isValidity"></param>
  133. /// <param name="inSchoolStatus"></param>
  134. /// <returns></returns>
  135. public IList<EvaluationStudentView> GetEvaluationStudentViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID,
  136. Guid? coursematerialID, int? courseTypeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? isValidity, int? inSchoolStatus)
  137. {
  138. Expression<Func<EM_EvaluationStudent, bool>> expEvaluationStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  139. if (isValidity.HasValue)
  140. {
  141. if (isValidity.Value == (int)CF_GeneralPurpose.IsYes)
  142. {
  143. expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity == true);
  144. }
  145. if (isValidity.Value == (int)CF_GeneralPurpose.IsNo)
  146. {
  147. expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity != true);
  148. }
  149. }
  150. Expression<Func<EM_EducationMission, bool>> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  151. if (schoolyearID.HasValue)
  152. {
  153. expEducationMission = expEducationMission.And(x => x.SchoolyearID == schoolyearID);
  154. }
  155. if (collegeID.HasValue)
  156. {
  157. expEducationMission = expEducationMission.And(x => x.CollegeID == collegeID);
  158. }
  159. if (departmentID.HasValue)
  160. {
  161. expEducationMission = expEducationMission.And(x => x.DepartmentID == departmentID);
  162. }
  163. Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  164. if (inSchoolStatus != null && inSchoolStatus > -1)
  165. {
  166. var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
  167. if (inSchoolStatus == 1)
  168. {
  169. expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
  170. }
  171. if (inSchoolStatus == 0)
  172. {
  173. expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
  174. }
  175. }
  176. var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(expEvaluationStudent, expEducationMission, expStudent);
  177. if (campusID.HasValue)
  178. {
  179. query = query.Where(x => x.CampusID == campusID);
  180. }
  181. if (coursematerialID.HasValue)
  182. {
  183. query = query.Where(x => x.CoursematerialID == coursematerialID);
  184. }
  185. if (courseTypeID.HasValue)
  186. {
  187. query = query.Where(x => x.CourseTypeID == courseTypeID);
  188. }
  189. if (teachingModeID.HasValue)
  190. {
  191. query = query.Where(x => x.TeachingModeID == teachingModeID);
  192. }
  193. if (staffID.HasValue)
  194. {
  195. query = query.Where(x => x.StaffUserID == staffID);
  196. }
  197. if (teachingMethodID.HasValue)
  198. {
  199. query = query.Where(x => x.TeachingMethodID == teachingMethodID);
  200. }
  201. if (evaluationTableID.HasValue)
  202. {
  203. query = query.Where(x => x.EvaluationTableID == evaluationTableID);
  204. }
  205. //查询条件
  206. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  207. {
  208. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  209. }
  210. return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length).ThenBy(x => x.DepartmentNo)
  211. .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ThenBy(x => x.StudentNo).ToList();
  212. }
  213. /// <summary>
  214. /// 查询对应的学评学生信息EvaluationStudentView
  215. /// </summary>
  216. /// <param name="evaluationStudentID"></param>
  217. /// <returns></returns>
  218. public EvaluationStudentView GetEvaluationStudentView(Guid? evaluationStudentID)
  219. {
  220. try
  221. {
  222. Expression<Func<EM_EvaluationStudent, bool>> exp = (x => x.EvaluationStudentID == evaluationStudentID);
  223. var query = EvaluationStudentDAL.GetEvaluationStudentViewQueryable(exp).SingleOrDefault();
  224. return query;
  225. }
  226. catch (Exception ex)
  227. {
  228. throw new Exception(ex.Message);
  229. }
  230. }
  231. /// <summary>
  232. /// 编辑
  233. /// </summary>
  234. /// <param name="evaluationStudentView"></param>
  235. public void EvaluationStudentEdit(EvaluationStudentView evaluationStudentView)
  236. {
  237. try
  238. {
  239. if (!evaluationStudentView.EvaluationStudentSettingID.HasValue || evaluationStudentView.EvaluationStudentSettingID == Guid.Empty)
  240. {
  241. throw new Exception("对应的学评设定信息数据有误,请核查。");
  242. }
  243. var evaluationStudentVerify = EvaluationStudentDAL.EvaluationStudentRepository.GetList(x => x.EvaluationStudentID != evaluationStudentView.EvaluationStudentID && x.UserID == evaluationStudentView.UserID && x.EvaluationStudentSettingID == evaluationStudentView.EvaluationStudentSettingID).SingleOrDefault();
  244. if (evaluationStudentVerify == null)
  245. {
  246. var evaluationStudentInList = new List<EM_EvaluationStudent>();
  247. var evaluationStudentUpList = new List<EM_EvaluationStudent>();
  248. if (evaluationStudentView.EvaluationStudentID != Guid.Empty)
  249. {
  250. var evaluationStudent = EvaluationStudentDAL.EvaluationStudentRepository.GetList(x => x.EvaluationStudentID == evaluationStudentView.EvaluationStudentID).SingleOrDefault();
  251. if (evaluationStudent == null)
  252. {
  253. throw new Exception("数据有误,请核查。");
  254. }
  255. else
  256. {
  257. //表示修改
  258. evaluationStudent.Numbered = (evaluationStudent.Numbered ?? 0) + 1;
  259. evaluationStudent.IsValidity = evaluationStudentView.IsValidity;
  260. evaluationStudent.TotalScore = evaluationStudentView.TotalScore;
  261. evaluationStudent.Advice = evaluationStudentView.Advice;
  262. evaluationStudent.Remark = evaluationStudentView.Remark;
  263. SetModifyStatus(evaluationStudent);
  264. evaluationStudentUpList.Add(evaluationStudent);
  265. }
  266. }
  267. else
  268. {
  269. //表示新增
  270. var newEvaluationStudent = new EM_EvaluationStudent();
  271. newEvaluationStudent.EvaluationStudentID = Guid.NewGuid();
  272. newEvaluationStudent.UserID = evaluationStudentView.UserID;
  273. newEvaluationStudent.EvaluationStudentSettingID = evaluationStudentView.EvaluationStudentSettingID;
  274. newEvaluationStudent.Numbered = evaluationStudentView.Numbered;
  275. newEvaluationStudent.IsValidity = evaluationStudentView.IsValidity;
  276. newEvaluationStudent.TotalScore = evaluationStudentView.TotalScore;
  277. newEvaluationStudent.Advice = evaluationStudentView.Remark;
  278. newEvaluationStudent.Remark = evaluationStudentView.Remark;
  279. SetNewStatus(newEvaluationStudent);
  280. evaluationStudentInList.Add(newEvaluationStudent);
  281. }
  282. using (TransactionScope ts = new TransactionScope())
  283. {
  284. UnitOfWork.BulkInsert(evaluationStudentInList);
  285. if (evaluationStudentInList != null && evaluationStudentInList.Count() > 0)
  286. {
  287. UnitOfWork.BatchUpdate(evaluationStudentInList);
  288. }
  289. ts.Complete();
  290. }
  291. }
  292. else
  293. {
  294. throw new Exception("已存在相同的学评明细信息(学生信息、学评设定信息唯一),请核查。");
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. throw new Exception(ex.Message);
  300. }
  301. }
  302. /// <summary>
  303. /// 删除
  304. /// </summary>
  305. /// <param name="evaluationStudentIDs"></param>
  306. /// <returns></returns>
  307. public bool EvaluationStudentDelete(List<Guid?> evaluationStudentIDs)
  308. {
  309. try
  310. {
  311. Expression<Func<EM_EvaluationStudent, bool>> expEvaluationStudent = (x => evaluationStudentIDs.Contains(x.EvaluationStudentID));
  312. var evaluationStudentList = EvaluationStudentDAL.EvaluationStudentRepository.GetList(expEvaluationStudent).ToList();
  313. var evaluationStudentSettingIDList = evaluationStudentList.Select(x => x.EvaluationStudentSettingID).Distinct().ToList();
  314. var evaluationStudentSettingScoreList = EvaluationStudentDAL.EvaluationStudentSettingScoreRepository.GetList(x => evaluationStudentSettingIDList.Contains(x.EvaluationStudentSettingID)).ToList();
  315. if (evaluationStudentSettingScoreList != null && evaluationStudentSettingScoreList.Count() > 0)
  316. {
  317. throw new Exception("选择删除的信息中存在对应的学评评分信息,无法删除,请核查。");
  318. }
  319. using (TransactionScope ts = new TransactionScope())
  320. {
  321. UnitOfWork.Delete<EM_EvaluationStudentDetail>(x => evaluationStudentIDs.Contains(x.EvaluationStudentID));
  322. UnitOfWork.Delete<EM_EvaluationStudent>(x => evaluationStudentIDs.Contains(x.EvaluationStudentID));
  323. ts.Complete();
  324. }
  325. return true;
  326. }
  327. catch (Exception)
  328. {
  329. throw;
  330. }
  331. }
  332. }
  333. }