EvaluationStudentSettingScoreServices.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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.EvaluationManage.EvaluationManage;
  15. using EMIS.CommonLogic.SystemServices;
  16. namespace EMIS.CommonLogic.EvaluationManage.StudentEvaluation
  17. {
  18. public class EvaluationStudentSettingScoreServices : BaseServices, IEvaluationStudentSettingScoreServices
  19. {
  20. public EvaluationStudentSettingScoreDAL EvaluationStudentSettingScoreDAL { get; set; }
  21. public EvaluationStudentSettingDAL EvaluationStudentSettingDAL { get; set; }
  22. public Lazy<IEvaluationStudentScoreServices> EvaluationStudentScoreServices { get; set; }
  23. public Lazy<IParameterServices> ParameterServices { get; set; }
  24. /// <summary>
  25. /// 查询对应的学评评分信息View
  26. /// </summary>
  27. /// <param name="configuretView"></param>
  28. /// <param name="schoolyearID"></param>
  29. /// <param name="campusID"></param>
  30. /// <param name="collegeID"></param>
  31. /// <param name="departmentID"></param>
  32. /// <param name="coursematerialID"></param>
  33. /// <param name="courseTypeID"></param>
  34. /// <param name="handleModeID"></param>
  35. /// <param name="teachingModeID"></param>
  36. /// <param name="staffID"></param>
  37. /// <param name="teachingMethodID"></param>
  38. /// <param name="evaluationTableID"></param>
  39. /// <param name="openState"></param>
  40. /// <param name="pageIndex"></param>
  41. /// <param name="pageSize"></param>
  42. /// <returns></returns>
  43. public IGridResultSet<EvaluationStudentSettingScoreView> GetEvaluationStudentSettingScoreViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID,
  44. Guid? coursematerialID, int? courseTypeID, int? handleModeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? openState, int pageIndex, int pageSize)
  45. {
  46. Expression<Func<EM_EvaluationStudentSettingScore, bool>> expEvaluationStudentSettingScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  47. Expression<Func<EM_EvaluationStudentSetting, bool>> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  48. if (staffID.HasValue)
  49. {
  50. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.UserID == staffID);
  51. }
  52. if (teachingMethodID.HasValue)
  53. {
  54. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.TeachingMethodID == teachingMethodID);
  55. }
  56. if (evaluationTableID.HasValue)
  57. {
  58. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.EvaluationTableID == evaluationTableID);
  59. }
  60. if (openState.HasValue)
  61. {
  62. if (openState.Value == (int)CF_GeneralPurpose.IsYes)
  63. {
  64. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true);
  65. }
  66. if (openState.Value == (int)CF_GeneralPurpose.IsNo)
  67. {
  68. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState != true);
  69. }
  70. }
  71. var query = EvaluationStudentSettingScoreDAL.GetEvaluationStudentSettingScoreViewQueryable(expEvaluationStudentSettingScore, expEvaluationStudentSetting);
  72. if (schoolyearID.HasValue)
  73. {
  74. query = query.Where(x => x.SchoolyearID == schoolyearID);
  75. }
  76. if (campusID.HasValue)
  77. {
  78. query = query.Where(x => x.CampusID == campusID);
  79. }
  80. if (collegeID.HasValue)
  81. {
  82. query = query.Where(x => x.CollegeID == collegeID);
  83. }
  84. if (departmentID.HasValue)
  85. {
  86. query = query.Where(x => x.DepartmentID == departmentID);
  87. }
  88. if (coursematerialID.HasValue)
  89. {
  90. query = query.Where(x => x.CoursematerialID == coursematerialID);
  91. }
  92. if (courseTypeID.HasValue)
  93. {
  94. query = query.Where(x => x.CourseTypeID == courseTypeID);
  95. }
  96. if (handleModeID.HasValue)
  97. {
  98. query = query.Where(x => x.HandleModeID == handleModeID);
  99. }
  100. if (teachingModeID.HasValue)
  101. {
  102. query = query.Where(x => x.TeachingModeID == teachingModeID);
  103. }
  104. //查询条件
  105. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  106. {
  107. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  108. }
  109. return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length)
  110. .ThenBy(x => x.DepartmentNo).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ToGridResultSet<EvaluationStudentSettingScoreView>(pageIndex, pageSize);
  111. }
  112. /// <summary>
  113. /// 查询对应的学评评分信息List
  114. /// </summary>
  115. /// <param name="configuretView"></param>
  116. /// <param name="schoolyearID"></param>
  117. /// <param name="campusID"></param>
  118. /// <param name="collegeID"></param>
  119. /// <param name="departmentID"></param>
  120. /// <param name="coursematerialID"></param>
  121. /// <param name="courseTypeID"></param>
  122. /// <param name="handleModeID"></param>
  123. /// <param name="teachingModeID"></param>
  124. /// <param name="staffID"></param>
  125. /// <param name="teachingMethodID"></param>
  126. /// <param name="evaluationTableID"></param>
  127. /// <param name="openState"></param>
  128. /// <returns></returns>
  129. public IList<EvaluationStudentSettingScoreView> GetEvaluationStudentSettingScoreViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID,
  130. Guid? coursematerialID, int? courseTypeID, int? handleModeID, int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? evaluationTableID, int? openState)
  131. {
  132. Expression<Func<EM_EvaluationStudentSettingScore, bool>> expEvaluationStudentSettingScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  133. Expression<Func<EM_EvaluationStudentSetting, bool>> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  134. if (staffID.HasValue)
  135. {
  136. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.UserID == staffID);
  137. }
  138. if (teachingMethodID.HasValue)
  139. {
  140. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.TeachingMethodID == teachingMethodID);
  141. }
  142. if (evaluationTableID.HasValue)
  143. {
  144. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.EvaluationTableID == evaluationTableID);
  145. }
  146. if (openState.HasValue)
  147. {
  148. if (openState.Value == (int)CF_GeneralPurpose.IsYes)
  149. {
  150. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState == true);
  151. }
  152. if (openState.Value == (int)CF_GeneralPurpose.IsNo)
  153. {
  154. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.OpenState != true);
  155. }
  156. }
  157. var query = EvaluationStudentSettingScoreDAL.GetEvaluationStudentSettingScoreViewQueryable(expEvaluationStudentSettingScore, expEvaluationStudentSetting);
  158. if (schoolyearID.HasValue)
  159. {
  160. query = query.Where(x => x.SchoolyearID == schoolyearID);
  161. }
  162. if (campusID.HasValue)
  163. {
  164. query = query.Where(x => x.CampusID == campusID);
  165. }
  166. if (collegeID.HasValue)
  167. {
  168. query = query.Where(x => x.CollegeID == collegeID);
  169. }
  170. if (departmentID.HasValue)
  171. {
  172. query = query.Where(x => x.DepartmentID == departmentID);
  173. }
  174. if (coursematerialID.HasValue)
  175. {
  176. query = query.Where(x => x.CoursematerialID == coursematerialID);
  177. }
  178. if (courseTypeID.HasValue)
  179. {
  180. query = query.Where(x => x.CourseTypeID == courseTypeID);
  181. }
  182. if (handleModeID.HasValue)
  183. {
  184. query = query.Where(x => x.HandleModeID == handleModeID);
  185. }
  186. if (teachingModeID.HasValue)
  187. {
  188. query = query.Where(x => x.TeachingModeID == teachingModeID);
  189. }
  190. //查询条件
  191. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  192. {
  193. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  194. }
  195. return this.GetQueryByDataRangeByDepartment(query, x => x.DepartmentID).OrderBy(x => x.SchoolyearValue).ThenBy(x => x.DepartmentNo.Length)
  196. .ThenBy(x => x.DepartmentNo).ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ThenBy(x => x.CourseTypeID).ThenBy(x => x.TeachingModeID).ToList();
  197. }
  198. /// <summary>
  199. /// 查询对应的学评评分信息EvaluationStudentSettingScoreView
  200. /// </summary>
  201. /// <param name="evaluationStudentSettingScoreID"></param>
  202. /// <returns></returns>
  203. public EvaluationStudentSettingScoreView GetEvaluationStudentSettingScoreView(Guid? evaluationStudentSettingScoreID)
  204. {
  205. try
  206. {
  207. Expression<Func<EM_EvaluationStudentSettingScore, bool>> exp = (x => x.EvaluationStudentSettingScoreID == evaluationStudentSettingScoreID);
  208. var query = EvaluationStudentSettingScoreDAL.GetEvaluationStudentSettingScoreViewQueryable(exp).SingleOrDefault();
  209. return query;
  210. }
  211. catch (Exception ex)
  212. {
  213. throw new Exception(ex.Message);
  214. }
  215. }
  216. /// <summary>
  217. /// 评分生成
  218. /// </summary>
  219. /// <param name="campusID"></param>
  220. /// <param name="collegeID"></param>
  221. /// <param name="departmentID"></param>
  222. /// <param name="gradeID"></param>
  223. /// <param name="standardID"></param>
  224. /// <param name="coursematerialID"></param>
  225. /// <param name="courseTypeID"></param>
  226. /// <param name="handleModeID"></param>
  227. /// <param name="teachingModeID"></param>
  228. /// <param name="staffID"></param>
  229. /// <param name="teachingMethodID"></param>
  230. /// <param name="schoolyearID"></param>
  231. /// <returns></returns>
  232. public string EvaluationStudentSettingScoreCreate(Guid? campusID, Guid? collegeID, Guid? departmentID, int? gradeID, int? standardID, Guid? coursematerialID, int? courseTypeID, int? handleModeID,
  233. int? teachingModeID, Guid? staffID, int? teachingMethodID, Guid? schoolyearID)
  234. {
  235. try
  236. {
  237. var schoolyear = EvaluationStudentSettingScoreDAL.SchoolyearRepository.GetList(x => x.SchoolyearID == schoolyearID).SingleOrDefault();
  238. if (schoolyear == null)
  239. {
  240. throw new Exception("选择的学年学期有误,请核查。");
  241. }
  242. var setParticipateCountScope = ParameterServices.Value.GetParameterValue(CF_ParameterType.ParticipateCountScope);
  243. if (setParticipateCountScope == null)
  244. {
  245. throw new Exception("未设置参评人数范围,请设置。");
  246. }
  247. var participateCountScope = Convert.ToInt32(setParticipateCountScope);
  248. decimal? evStudentSettingScore = 0;
  249. Expression<Func<EM_EvaluationStudentSetting, bool>> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  250. if (staffID.HasValue)
  251. {
  252. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.UserID == staffID);
  253. }
  254. if (teachingMethodID.HasValue)
  255. {
  256. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.TeachingMethodID == teachingMethodID);
  257. }
  258. Expression<Func<EM_EducationMissionClass, bool>> expEducationMissionClass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  259. Expression<Func<CF_Classmajor, bool>> expClassmajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  260. bool classmajorHasValue = false;
  261. if (gradeID.HasValue)
  262. {
  263. expClassmajor = expClassmajor.And(x => x.CF_Grademajor.GradeID == gradeID);
  264. classmajorHasValue = true;
  265. }
  266. if (standardID.HasValue)
  267. {
  268. expClassmajor = expClassmajor.And(x => x.CF_Grademajor.CF_Facultymajor.StandardID == standardID);
  269. classmajorHasValue = true;
  270. }
  271. if (classmajorHasValue)
  272. {
  273. expEducationMissionClass = expEducationMissionClass.And(x => x.CF_Classmajor.AsQueryable().Any(expClassmajor));
  274. }
  275. if (coursematerialID.HasValue)
  276. {
  277. expEducationMissionClass = expEducationMissionClass.And(x => x.CoursematerialID == coursematerialID);
  278. }
  279. if (courseTypeID.HasValue)
  280. {
  281. expEducationMissionClass = expEducationMissionClass.And(x => x.CourseTypeID == courseTypeID);
  282. }
  283. if (handleModeID.HasValue)
  284. {
  285. expEducationMissionClass = expEducationMissionClass.And(x => x.HandleModeID == handleModeID);
  286. }
  287. if (teachingModeID.HasValue)
  288. {
  289. expEducationMissionClass = expEducationMissionClass.And(x => x.TeachingModeID == teachingModeID);
  290. }
  291. Expression<Func<EM_EducationMission, bool>> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  292. if (collegeID.HasValue)
  293. {
  294. expEducationMission = expEducationMission.And(x => x.CollegeID == collegeID);
  295. }
  296. if (departmentID.HasValue)
  297. {
  298. expEducationMission = expEducationMission.And(x => x.DepartmentID == departmentID);
  299. }
  300. if (schoolyearID.HasValue)
  301. {
  302. expEducationMission = expEducationMission.And(x => x.SchoolyearID == schoolyearID);
  303. }
  304. var query = EvaluationStudentSettingDAL.GetEvaluationStudentSettingViewQueryable(expEvaluationStudentSetting, expEducationMissionClass, expEducationMission);
  305. if (campusID.HasValue)
  306. {
  307. query = query.Where(x => x.CampusID == campusID);
  308. }
  309. var evaluationStudentSettingViewList = this.GetQueryByDataRangeByDepartment(query).ToList();
  310. var evaluationStudentSettingIDList = evaluationStudentSettingViewList.Select(x => x.EvaluationStudentSettingID).ToList();
  311. Expression<Func<EM_EvaluationStudent, bool>> expEvaluationStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  312. expEvaluationStudent = expEvaluationStudent.And(x => evaluationStudentSettingIDList.Contains(x.EvaluationStudentSettingID.Value));
  313. expEvaluationStudent = expEvaluationStudent.And(x => x.IsValidity == true);
  314. var evaluationStudentList = EvaluationStudentSettingScoreDAL.EvaluationStudentRepository.GetList(expEvaluationStudent).ToList();
  315. var evaluationStudentSettingScoreList = EvaluationStudentSettingScoreDAL.EvaluationStudentSettingScoreRepository.GetList(x => evaluationStudentSettingIDList.Contains(x.EvaluationStudentSettingID.Value)).ToList();
  316. int inSuccess = 0;
  317. int upSuccess = 0;
  318. string tipMessage = null;
  319. var evaluationStudentSettingScoreInList = new List<EM_EvaluationStudentSettingScore>();
  320. var evaluationStudentSettingScoreUpList = new List<EM_EvaluationStudentSettingScore>();
  321. foreach (var evaluationStudentSettingView in evaluationStudentSettingViewList)
  322. {
  323. var evaluationStudentVerifyList = evaluationStudentList.Where(x => x.EvaluationStudentSettingID == evaluationStudentSettingView.EvaluationStudentSettingID).OrderBy(x => x.TotalScore ?? 0).ToList();
  324. if (evaluationStudentVerifyList == null || evaluationStudentVerifyList.Count() <= 0)
  325. {
  326. evStudentSettingScore = 0;
  327. }
  328. else
  329. {
  330. if (evaluationStudentVerifyList.Count() < participateCountScope)
  331. {
  332. evStudentSettingScore = evaluationStudentVerifyList.Average(x => x.TotalScore ?? 0);
  333. }
  334. else
  335. {
  336. var differenceNumber = Convert.ToInt32(Math.Round(((decimal)evaluationStudentVerifyList.Count() * (decimal)0.05), 0, MidpointRounding.AwayFromZero));
  337. evaluationStudentVerifyList.RemoveRange(evaluationStudentVerifyList.Count() - differenceNumber, differenceNumber);
  338. evaluationStudentVerifyList.RemoveRange(0, differenceNumber);
  339. evStudentSettingScore = evaluationStudentVerifyList.Average(x => x.TotalScore ?? 0);
  340. }
  341. }
  342. var evaluationStudentSettingScoreVerify = evaluationStudentSettingScoreList.Where(x => x.EvaluationStudentSettingID == evaluationStudentSettingView.EvaluationStudentSettingID).SingleOrDefault();
  343. if (evaluationStudentSettingScoreVerify == null)
  344. {
  345. var newEvaluationStudentSettingScore = new EM_EvaluationStudentSettingScore();
  346. newEvaluationStudentSettingScore.EvaluationStudentSettingScoreID = Guid.NewGuid();
  347. newEvaluationStudentSettingScore.EvaluationStudentSettingID = evaluationStudentSettingView.EvaluationStudentSettingID;
  348. newEvaluationStudentSettingScore.TotalScore = evStudentSettingScore;
  349. newEvaluationStudentSettingScore.Remark = null;
  350. SetNewStatus(newEvaluationStudentSettingScore);
  351. evaluationStudentSettingScoreInList.Add(newEvaluationStudentSettingScore);
  352. inSuccess++;
  353. }
  354. else
  355. {
  356. evaluationStudentSettingScoreVerify.TotalScore = evStudentSettingScore;
  357. SetModifyStatus(evaluationStudentSettingScoreVerify);
  358. evaluationStudentSettingScoreUpList.Add(evaluationStudentSettingScoreVerify);
  359. upSuccess++;
  360. }
  361. }
  362. using (TransactionScope ts = new TransactionScope())
  363. {
  364. UnitOfWork.BulkInsert(evaluationStudentSettingScoreInList);
  365. if (evaluationStudentSettingScoreUpList != null && evaluationStudentSettingScoreUpList.Count() > 0)
  366. {
  367. UnitOfWork.BatchUpdate(evaluationStudentSettingScoreUpList);
  368. }
  369. ts.Complete();
  370. }
  371. if (inSuccess > 0 && upSuccess <= 0)
  372. {
  373. tipMessage = inSuccess + "条";
  374. }
  375. else
  376. {
  377. tipMessage = inSuccess + "条,更新成功" + upSuccess + "条";
  378. }
  379. return tipMessage;
  380. }
  381. catch (Exception ex)
  382. {
  383. throw new Exception(ex.Message);
  384. }
  385. }
  386. /// <summary>
  387. /// 编辑
  388. /// </summary>
  389. /// <param name="evaluationStudentSettingScoreView"></param>
  390. public void EvaluationStudentSettingScoreEdit(EvaluationStudentSettingScoreView evaluationStudentSettingScoreView)
  391. {
  392. try
  393. {
  394. if (!evaluationStudentSettingScoreView.EvaluationStudentSettingID.HasValue || evaluationStudentSettingScoreView.EvaluationStudentSettingID == Guid.Empty)
  395. {
  396. throw new Exception("对应的学评设定数据有误,请核查。");
  397. }
  398. var evaluationStudentSettingScoreVerify = EvaluationStudentSettingScoreDAL.EvaluationStudentSettingScoreRepository.GetList(x => x.EvaluationStudentSettingScoreID != evaluationStudentSettingScoreView.EvaluationStudentSettingScoreID && x.EvaluationStudentSettingID == evaluationStudentSettingScoreView.EvaluationStudentSettingID).SingleOrDefault();
  399. if (evaluationStudentSettingScoreVerify == null)
  400. {
  401. var setPassParticipateRate = ParameterServices.Value.GetParameterValue(CF_ParameterType.PassParticipateRate);
  402. if (setPassParticipateRate == null)
  403. {
  404. throw new Exception("未设置达标参评率,请设置。");
  405. }
  406. var startStatusID = EvaluationStudentScoreServices.Value.GetStartStatus();
  407. if (startStatusID == null)
  408. {
  409. throw new Exception("工作流平台中,学生评分流程开始环节未配置,请核查。");
  410. }
  411. var passParticipateRate = Convert.ToDecimal(setPassParticipateRate);
  412. decimal? evStudentTotalScore = 0;
  413. Expression<Func<EM_EvaluationStudentSetting, bool>> expEvaluationStudentSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  414. expEvaluationStudentSetting = expEvaluationStudentSetting.And(x => x.UserID == evaluationStudentSettingScoreView.UserID);
  415. Expression<Func<EM_EducationMission, bool>> expEducationMission = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  416. expEducationMission = expEducationMission.And(x => x.SchoolyearID == evaluationStudentSettingScoreView.SchoolyearID);
  417. expEducationMission = expEducationMission.And(x => x.DepartmentID == evaluationStudentSettingScoreView.DepartmentID);
  418. Expression<Func<EM_EducationMissionClass, bool>> expEducationMissionClass = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  419. expEducationMissionClass = expEducationMissionClass.And(x => x.CoursematerialID == evaluationStudentSettingScoreView.CoursematerialID);
  420. var evaluationStudentSettingViewList = EvaluationStudentSettingDAL.GetEvaluationStudentSettingViewQueryable(expEvaluationStudentSetting).ToList();
  421. var evaluationStudentSettingView = evaluationStudentSettingViewList.Where(x => x.EvaluationStudentSettingID == evaluationStudentSettingScoreView.EvaluationStudentSettingID).SingleOrDefault();
  422. if (evaluationStudentSettingView == null)
  423. {
  424. throw new Exception("对应的学评设定数据有误,请核查。");
  425. }
  426. else
  427. {
  428. var evaluationStudentSettingScoreViewList = EvaluationStudentSettingScoreDAL.GetEvaluationStudentSettingScoreViewQueryable(expEvaluationStudentSetting, expEducationMission, expEducationMissionClass).ToList();
  429. if (evaluationStudentSettingScoreViewList != null && evaluationStudentSettingScoreViewList.Count() > 0)
  430. {
  431. var evaStuSettingScoreView = evaluationStudentSettingScoreViewList.Where(x => x.EvaluationStudentSettingID == evaluationStudentSettingScoreView.EvaluationStudentSettingID).SingleOrDefault();
  432. if (evaStuSettingScoreView == null)
  433. {
  434. var passEvaStuSettingScoreViewList = evaluationStudentSettingScoreViewList.Where(x => x.ValidityParticipateRate >= passParticipateRate).ToList();
  435. if (evaluationStudentSettingView.ValidityParticipateRate >= passParticipateRate)
  436. {
  437. evStudentTotalScore = Math.Round((decimal)((decimal?)((passEvaStuSettingScoreViewList.Sum(x => x.TotalScore) ?? 0) + (evaluationStudentSettingScoreView.TotalScore ?? 0)) * (decimal?)1.00 / (decimal?)(evaluationStudentSettingScoreViewList.Count() + 1)), 1);
  438. }
  439. else
  440. {
  441. evStudentTotalScore = Math.Round((decimal)((decimal?)(passEvaStuSettingScoreViewList.Sum(x => x.TotalScore) ?? 0) * (decimal?)1.00 / (decimal?)(evaluationStudentSettingScoreViewList.Count() + 1)), 1);
  442. }
  443. }
  444. else
  445. {
  446. var passEvaStuSettingScoreViewList = evaluationStudentSettingScoreViewList.Where(x => x.EvaluationStudentSettingID != evaluationStudentSettingScoreView.EvaluationStudentSettingID && x.ValidityParticipateRate >= passParticipateRate).ToList();
  447. if (evaStuSettingScoreView.ValidityParticipateRate >= passParticipateRate)
  448. {
  449. evStudentTotalScore = Math.Round((decimal)((decimal?)((passEvaStuSettingScoreViewList.Sum(x => x.TotalScore) ?? 0) + (evaluationStudentSettingScoreView.TotalScore ?? 0)) * (decimal?)1.00 / (decimal?)evaluationStudentSettingScoreViewList.Count()), 1);
  450. }
  451. else
  452. {
  453. evStudentTotalScore = Math.Round((decimal)((decimal?)(passEvaStuSettingScoreViewList.Sum(x => x.TotalScore) ?? 0) * (decimal?)1.00 / (decimal?)evaluationStudentSettingScoreViewList.Count()), 1);
  454. }
  455. }
  456. }
  457. else
  458. {
  459. if (evaluationStudentSettingView.ValidityParticipateRate >= passParticipateRate)
  460. {
  461. evStudentTotalScore = evaluationStudentSettingScoreView.TotalScore;
  462. }
  463. else
  464. {
  465. evStudentTotalScore = 0;
  466. }
  467. }
  468. }
  469. var evaluationStudentScoreInList = new List<EM_EvaluationStudentScore>();
  470. var evaluationStudentScoreUpList = new List<EM_EvaluationStudentScore>();
  471. Expression<Func<EM_EvaluationStudentScore, bool>> expEvaluationStudentScore = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  472. expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.SchoolyearID == evaluationStudentSettingScoreView.SchoolyearID);
  473. expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.UserID == evaluationStudentSettingScoreView.UserID);
  474. expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.CoursematerialID == evaluationStudentSettingScoreView.CoursematerialID);
  475. expEvaluationStudentScore = expEvaluationStudentScore.And(x => x.DepartmentID == evaluationStudentSettingScoreView.DepartmentID);
  476. var evaluationStudentScore = EvaluationStudentSettingScoreDAL.EvaluationStudentScoreRepository.GetList(expEvaluationStudentScore).SingleOrDefault();
  477. if (evaluationStudentScore == null)
  478. {
  479. var newEvaluationStudentScore = new EM_EvaluationStudentScore();
  480. newEvaluationStudentScore.EvaluationStudentScoreID = Guid.NewGuid();
  481. newEvaluationStudentScore.SchoolyearID = evaluationStudentSettingScoreView.SchoolyearID;
  482. newEvaluationStudentScore.UserID = evaluationStudentSettingScoreView.UserID;
  483. newEvaluationStudentScore.CoursematerialID = evaluationStudentSettingScoreView.CoursematerialID;
  484. newEvaluationStudentScore.DepartmentID = evaluationStudentSettingScoreView.DepartmentID;
  485. newEvaluationStudentScore.TotalScore = evStudentTotalScore;
  486. newEvaluationStudentScore.ApprovalStatus = startStatusID;
  487. SetNewStatus(newEvaluationStudentScore);
  488. evaluationStudentScoreInList.Add(newEvaluationStudentScore);
  489. }
  490. else
  491. {
  492. if (evaluationStudentScore.ApprovalStatus == startStatusID)
  493. {
  494. evaluationStudentScore.TotalScore = evStudentTotalScore;
  495. SetModifyStatus(evaluationStudentScore);
  496. evaluationStudentScoreUpList.Add(evaluationStudentScore);
  497. }
  498. else
  499. {
  500. throw new Exception("对应的学生评分信息已在工作流程中,请核查。");
  501. }
  502. }
  503. var evaluationStudentSettingScoreInList = new List<EM_EvaluationStudentSettingScore>();
  504. var evaluationStudentSettingScoreUpList = new List<EM_EvaluationStudentSettingScore>();
  505. if (evaluationStudentSettingScoreView.EvaluationStudentSettingScoreID != Guid.Empty)
  506. {
  507. var evaluationStudentSettingScore = EvaluationStudentSettingScoreDAL.EvaluationStudentSettingScoreRepository.GetList(x => x.EvaluationStudentSettingScoreID == evaluationStudentSettingScoreView.EvaluationStudentSettingScoreID).SingleOrDefault();
  508. if (evaluationStudentSettingScore == null)
  509. {
  510. throw new Exception("数据有误,请核查。");
  511. }
  512. else
  513. {
  514. //表示修改
  515. evaluationStudentSettingScore.TotalScore = evaluationStudentSettingScoreView.TotalScore;
  516. evaluationStudentSettingScore.Remark = evaluationStudentSettingScoreView.Remark;
  517. SetModifyStatus(evaluationStudentSettingScore);
  518. evaluationStudentSettingScoreUpList.Add(evaluationStudentSettingScore);
  519. }
  520. }
  521. else
  522. {
  523. //表示新增
  524. var newEvaluationStudentSettingScore = new EM_EvaluationStudentSettingScore();
  525. newEvaluationStudentSettingScore.EvaluationStudentSettingScoreID = Guid.NewGuid();
  526. newEvaluationStudentSettingScore.EvaluationStudentSettingID = evaluationStudentSettingScoreView.EvaluationStudentSettingID;
  527. newEvaluationStudentSettingScore.TotalScore = evaluationStudentSettingScoreView.TotalScore;
  528. newEvaluationStudentSettingScore.Remark = evaluationStudentSettingScoreView.Remark;
  529. SetNewStatus(newEvaluationStudentSettingScore);
  530. evaluationStudentSettingScoreInList.Add(newEvaluationStudentSettingScore);
  531. }
  532. using (TransactionScope ts = new TransactionScope())
  533. {
  534. UnitOfWork.BulkInsert(evaluationStudentScoreInList);
  535. if (evaluationStudentScoreUpList != null && evaluationStudentScoreUpList.Count() > 0)
  536. {
  537. UnitOfWork.BatchUpdate(evaluationStudentScoreUpList);
  538. }
  539. UnitOfWork.BulkInsert(evaluationStudentSettingScoreInList);
  540. if (evaluationStudentSettingScoreUpList != null && evaluationStudentSettingScoreUpList.Count() > 0)
  541. {
  542. UnitOfWork.BatchUpdate(evaluationStudentSettingScoreUpList);
  543. }
  544. ts.Complete();
  545. }
  546. }
  547. else
  548. {
  549. throw new Exception("已存在相同的学评评分信息(学评设定信息唯一),请核查。");
  550. }
  551. }
  552. catch (Exception ex)
  553. {
  554. throw new Exception(ex.Message);
  555. }
  556. }
  557. /// <summary>
  558. /// 删除
  559. /// </summary>
  560. /// <param name="evaluationStudentSettingScoreIDs"></param>
  561. /// <returns></returns>
  562. public bool EvaluationStudentSettingScoreDelete(List<Guid?> evaluationStudentSettingScoreIDs)
  563. {
  564. try
  565. {
  566. Expression<Func<EM_EvaluationStudentSettingScore, bool>> expEvaluationStudentSetting = (x => evaluationStudentSettingScoreIDs.Contains(x.EvaluationStudentSettingScoreID));
  567. var evaluationStudentSettingScoreViewList = EvaluationStudentSettingScoreDAL.GetEvaluationStudentSettingScoreViewQueryable(expEvaluationStudentSetting).ToList();
  568. var userIDList = evaluationStudentSettingScoreViewList.Select(x => x.UserID).Distinct().ToList();
  569. var evaluationStudentScoreList = EvaluationStudentSettingScoreDAL.EvaluationStudentScoreRepository.GetList(x => userIDList.Contains(x.UserID)).ToList();
  570. var evaluationStudentSettingIDList = evaluationStudentSettingScoreViewList.Select(x => x.EvaluationStudentSettingID).ToList();
  571. var evaluationStudentList = EvaluationStudentSettingScoreDAL.EvaluationStudentRepository.GetList(x => evaluationStudentSettingIDList.Contains(x.EvaluationStudentSettingID)).ToList();
  572. var evaluationStudentIDList = evaluationStudentList.Select(x => x.EvaluationStudentID).ToList();
  573. foreach (var evaluationStudentSettingScoreView in evaluationStudentSettingScoreViewList)
  574. {
  575. var evaluationStudentScore = evaluationStudentScoreList.Where(x => x.SchoolyearID == evaluationStudentSettingScoreView.SchoolyearID && x.UserID == evaluationStudentSettingScoreView.UserID
  576. && x.CoursematerialID == evaluationStudentSettingScoreView.CoursematerialID && x.DepartmentID == evaluationStudentSettingScoreView.DepartmentID).SingleOrDefault();
  577. if (evaluationStudentScore != null)
  578. {
  579. throw new Exception("选择删除的信息中存在对应的学生评分信息,无法删除,请核查。");
  580. }
  581. }
  582. using (TransactionScope ts = new TransactionScope())
  583. {
  584. UnitOfWork.Delete<EM_EvaluationStudentSettingScore>(x => evaluationStudentSettingScoreIDs.Contains(x.EvaluationStudentSettingScoreID));
  585. UnitOfWork.Delete<EM_EvaluationStudentDetail>(x => evaluationStudentIDList.Contains(x.EvaluationStudentID.Value));
  586. UnitOfWork.Delete<EM_EvaluationStudent>(x => evaluationStudentIDList.Contains(x.EvaluationStudentID));
  587. ts.Complete();
  588. }
  589. return true;
  590. }
  591. catch (Exception)
  592. {
  593. throw;
  594. }
  595. }
  596. }
  597. }