public ResultEntity correctAll(List <int?> scores, int?studentId, int?chapterId, String type) { ResultEntity resultEntity = new ResultEntity(); if (studentId != null && chapterId != null && type != null) { int trueType = 0; int type1 = 0; int type2 = 0; if (type.Equals("preview")) { trueType = 3; type1 = 1; type2 = 2; } else { trueType = 6; type1 = 4; type2 = 5; } List <Exercise> exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, trueType); List <int?> exerciseIds = new List <int?>(); foreach (Exercise exercise in exercises) { exerciseIds.Add(exercise.exerciseId); } StudentExerciseScore studentExerciseScore; for (int i = 0; i < scores.Count; i++) { studentExerciseScore = StudentExerciseScoreApi.findByExerciseIdAndStudentId(exerciseIds[i], studentId); studentExerciseScore.exerciseScore = scores[i].ToString(); studentExerciseScore.corrected = 1; StudentExerciseScoreApi.insert(studentExerciseScore); } exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type1); foreach (Exercise exercise in exercises) { exerciseIds.Add(exercise.exerciseId); } exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type2); foreach (Exercise exercise in exercises) { exerciseIds.Add(exercise.exerciseId); } int score = 0; foreach (int?exerciseId in exerciseIds) { score += int.Parse(StudentExerciseScoreApi.findByExerciseIdAndStudentId(exerciseId, studentId).exerciseScore); } if (type.Equals("preview")) { StudentChapter studentChapter = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId); studentChapter.totalScore_1 = score; studentChapter.scored_1 = 1; StudentChapterApi.insert(studentChapter); } else { StudentChapter studentChapter = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId); studentChapter.totalScore_2 = score; studentChapter.scored_2 = 1; StudentChapterApi.insert(studentChapter); } resultEntity.setState(1); resultEntity.setMessage("批改成功 !"); } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }
public ResultEntity answerAll(List <String> answers, int?studentId, int?chapterId, String type, String comment, int?rate) { ResultEntity resultEntity = new ResultEntity(); if (answers != null && type != null && chapterId != null && studentId != null) { List <ExerciseSet> exerciseSets = new List <ExerciseSet>(); int type1 = 0; int type2 = 0; int type3 = 0; if (type.Equals("preview")) { type1 = 1; type3 = 2; type2 = 3; } else { type1 = 4; type3 = 5; type2 = 6; } List <int?> exerciseIds = new List <int?>(); List <Exercise> exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type1); foreach (Exercise exercise in exercises) { exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId))); exerciseIds.Add(exercise.exerciseId); } exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type3); foreach (Exercise exercise in exercises) { exerciseSets.Add(new ExerciseSet(exercise, ExerciseChoiceApi.findByExerciseIdOrderByExerciceChoiceId(exercise.exerciseId))); exerciseIds.Add(exercise.exerciseId); } exercises = ExerciseApi.findByChapterIdAndExerciseTypeOrderByExerciseNumber(chapterId, type2); foreach (Exercise exercise in exercises) { exerciseSets.Add(new ExerciseSet(exercise)); } for (int i = 0; i < answers.Count; i++) { answerOne(answers[i], exerciseSets[i].getExercise().exerciseId, studentId); } int score = 0; foreach (int?exerciseId in exerciseIds) { score += int.Parse(StudentExerciseScoreApi.findByExerciseIdAndStudentId(exerciseId, studentId).exerciseScore); } StudentChapter studentChapter; if (!StudentChapterApi.existsByChapterIDAndStudentID(chapterId, studentId)) { studentChapter = new StudentChapter(); studentChapter.chapterID = chapterId; studentChapter.studentID = studentId; StudentChapterApi.insert(studentChapter); } if (!type.Equals("preview")) { studentChapter = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId); studentChapter.rate = rate; studentChapter.comment = comment; studentChapter.totalScore_2 = score; studentChapter.scored_2 = 0; StudentChapterApi.insert(studentChapter); //LaterImplementation //new NLPUtil().setCommentNLPRate(comment, chapterId, studentId); } else { studentChapter = StudentChapterApi.findByChapterIDAndStudentID(chapterId, studentId); studentChapter.totalScore_1 = score; studentChapter.scored_1 = 0; StudentChapterApi.insert(studentChapter); } resultEntity.setState(1); resultEntity.setMessage("答题成功 !"); } else { resultEntity.setMessage("传入参数有空值!"); resultEntity.setState(0); } return(resultEntity); }