|
|
@@ -7,6 +7,10 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
@Service
|
|
|
public class ExamService {
|
|
|
private final CourseService courseService;
|
|
|
@@ -19,30 +23,137 @@ public class ExamService {
|
|
|
this.evalService = evalService;
|
|
|
}
|
|
|
|
|
|
- public JSONObject getCoderRecommendExams() {
|
|
|
+ public JSONArray getCoderRecommendExams() {
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
+ JSONObject groupedExams = this.getCoderRecommendExamsGroupByCourse();
|
|
|
+ for (String key : groupedExams.keySet()) {
|
|
|
+ result.addAll(groupedExams.getJSONArray(key));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getCoderRecommendExamsGroupByCourse() {
|
|
|
JSONObject result = new JSONObject();
|
|
|
- result.put("res", new JSONArray());
|
|
|
for (CourseVO courseVO : courseService.getExampleCourses()) {
|
|
|
+ if (courseVO.getCoderId() != null) {
|
|
|
+ result.put(courseVO.getName(),
|
|
|
+ coderService.getRecommendExams(1, 1000, "default", courseVO.getCoderId())
|
|
|
+ .getJSONObject("res").getJSONArray("content"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ public JSONObject getCoderExamsByStudentGroupByCourse() {
|
|
|
+ JSONArray exams = coderService.getPersonExams(1, 1000).getJSONArray("res");
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ for (int i = 0; i < exams.size(); i++) {
|
|
|
+ JSONObject exam = exams.getJSONObject(i);
|
|
|
+ if (result.containsKey(exam.getString("name"))) {
|
|
|
+ result.getJSONArray(exam.getString("name")).add(exam);
|
|
|
+ } else {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array.add(exam);
|
|
|
+ result.put(exam.getString("name"), array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
+ for (String key : result.keySet()) {
|
|
|
+ if (!courseService.isCourseNameExisted(key)) {
|
|
|
+ keys.add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String key : keys) {
|
|
|
+ result.remove(key);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getCoderExamsByTeacherGroupByCourse() {
|
|
|
+ JSONArray exams = coderService.getPersonExams(1, 1000).getJSONArray("res");
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ for (int i = 0; i < exams.size(); i++) {
|
|
|
+ JSONObject exam = exams.getJSONObject(i);
|
|
|
+ if (result.containsKey(exam.getString("course"))) {
|
|
|
+ result.getJSONArray(exam.getString("course")).add(exam);
|
|
|
+ } else {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array.add(exam);
|
|
|
+ result.put(exam.getString("course"), array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
+ for (String key : result.keySet()) {
|
|
|
+ if (!courseService.isCourseNameExisted(key)) {
|
|
|
+ keys.add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String key : keys) {
|
|
|
+ result.remove(key);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public JSONArray getEvalRecommendExams() {
|
|
|
JSONArray result = new JSONArray();
|
|
|
+ JSONObject groupedExams = this.getEvalRecommendExamsGroupByCourse();
|
|
|
+ for (String key : groupedExams.keySet()) {
|
|
|
+ result.addAll(groupedExams.getJSONArray(key));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getEvalRecommendExamsGroupByCourse() {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
for (CourseVO courseVO : courseService.getExampleCourses()) {
|
|
|
- JSONObject res = evalService.getRecommendExams(courseVO.getEvalId());
|
|
|
- result.addAll(res.getJSONArray("result"));
|
|
|
+ if (courseVO.getEvalId() != null) {
|
|
|
+ result.put(courseVO.getName(), evalService.getRecommendExams(courseVO.getEvalId()).getJSONArray("result"));
|
|
|
+ }
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public JSONArray getEvalRecommendExamsGroupByCourse() {
|
|
|
+ public JSONArray getEvalExamsByStudent(Long userId) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
- for (CourseVO courseVO : courseService.getExampleCourses()) {
|
|
|
- JSONObject res = new JSONObject();
|
|
|
- res.put(courseVO.getName(), evalService.getRecommendExams(courseVO.getEvalId()).getJSONArray("result"));
|
|
|
- result.add(res);
|
|
|
+ JSONObject groupedExams = this.getEvalExamsByStudentGroupByCourse(userId);
|
|
|
+ for (String key : groupedExams.keySet()) {
|
|
|
+ result.addAll(groupedExams.getJSONArray(key));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getEvalExamsByStudentGroupByCourse(Long userId) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ List<CourseVO> studentCourses = courseService.getStudentCourses(userId);
|
|
|
+ for (CourseVO courseVO : studentCourses) {
|
|
|
+ if (courseVO.getEvalId() != null) {
|
|
|
+ result.put(courseVO.getName(), evalService.getStudentExamsByCourseId(courseVO.getEvalId()).getJSONArray("result"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getEvalExamsByTeacherGroupByCourse() {
|
|
|
+ JSONArray exams = evalService.getTeacherExams(1000, 1, 0).getJSONObject("result").getJSONArray("examVOList");
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ for (int i = 0; i < exams.size(); i++) {
|
|
|
+ JSONObject exam = exams.getJSONObject(i);
|
|
|
+ if (result.containsKey(exam.getJSONObject("course").getString("name"))) {
|
|
|
+ result.getJSONArray(exam.getJSONObject("course").getString("name")).add(exam);
|
|
|
+ } else {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array.add(exam);
|
|
|
+ result.put(exam.getJSONObject("course").getString("name"), array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
+ for (String key : result.keySet()) {
|
|
|
+ if (!courseService.isCourseNameExisted(key)) {
|
|
|
+ keys.add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String key : keys) {
|
|
|
+ result.remove(key);
|
|
|
}
|
|
|
return result;
|
|
|
}
|