|
|
@@ -1,8 +1,10 @@
|
|
|
package cn.seecoder.seecoderportalserver.serviceImpl;
|
|
|
|
|
|
import cn.seecoder.seecoderportalcommon.vo.CourseVO;
|
|
|
+import cn.seecoder.seecoderportalserver.domain.Course;
|
|
|
import cn.seecoder.seecoderportalserver.service.CourseService;
|
|
|
import cn.seecoder.seecoderportalserver.service.ExamService;
|
|
|
+import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -57,53 +59,13 @@ public class ExamServiceImpl implements ExamService {
|
|
|
@Override
|
|
|
public JSONObject findCoderExamsByStudentGroupByCourse() {
|
|
|
JSONArray exams = coderService.findStudentExams(1, 1000, 0).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;
|
|
|
+ return this.groupCoderExamsByCourse(exams);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONObject findCoderExamsByTeacherGroupByCourse() {
|
|
|
JSONArray exams = coderService.findTeacherExams(1, 1000, 0).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;
|
|
|
+ return this.groupCoderExamsByCourse(exams);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -167,26 +129,25 @@ public class ExamServiceImpl implements ExamService {
|
|
|
@Override
|
|
|
public JSONObject findEvalExamsByTeacherGroupByCourse() {
|
|
|
JSONArray exams = evalService.findTeacherExams(1, 1000, 0).getJSONObject("result").getJSONArray("examVOList");
|
|
|
+ JSONObject groupedExams = new JSONObject();
|
|
|
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);
|
|
|
+ if (groupedExams.containsKey(exam.getJSONObject("course").getString("id"))) {
|
|
|
+ groupedExams.getJSONArray(exam.getJSONObject("course").getString("id")).add(exam);
|
|
|
} else {
|
|
|
JSONArray array = new JSONArray();
|
|
|
array.add(exam);
|
|
|
- result.put(exam.getJSONObject("course").getString("name"), array);
|
|
|
+ groupedExams.put(exam.getJSONObject("course").getString("id"), array);
|
|
|
}
|
|
|
}
|
|
|
- List<String> keys = new ArrayList<>();
|
|
|
- for (String key : result.keySet()) {
|
|
|
- if (!courseService.isCourseNameExisted(key)) {
|
|
|
- keys.add(key);
|
|
|
+ for (String key : groupedExams.keySet()) {
|
|
|
+ int evalId = Integer.parseInt(key);
|
|
|
+ try {
|
|
|
+ result.put(courseService.findCourseByEvalId(evalId).getName(), groupedExams.get(key));
|
|
|
+ } catch (Exception ignored) {
|
|
|
}
|
|
|
}
|
|
|
- for (String key : keys) {
|
|
|
- result.remove(key);
|
|
|
- }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -199,4 +160,29 @@ public class ExamServiceImpl implements ExamService {
|
|
|
public JSONArray findEvalTeacherExamsByCourseId(int courseId) {
|
|
|
return evalService.findStudentExamsByCourseId(courseId).getJSONArray("result");
|
|
|
}
|
|
|
+
|
|
|
+ // private
|
|
|
+ private JSONObject groupCoderExamsByCourse(JSONArray exams) {
|
|
|
+ JSONObject groupedExams = new JSONObject();
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+
|
|
|
+ for (int i = 0; i < exams.size(); i++) {
|
|
|
+ JSONObject exam = exams.getJSONObject(i);
|
|
|
+ if (groupedExams.containsKey(exam.getString("courseId"))) {
|
|
|
+ groupedExams.getJSONArray(exam.getString("courseId")).add(exam);
|
|
|
+ } else {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array.add(exam);
|
|
|
+ groupedExams.put(exam.getString("courseId"), array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String key : groupedExams.keySet()) {
|
|
|
+ try {
|
|
|
+ int coderId = Integer.parseInt(key);
|
|
|
+ result.put(courseService.findCourseByCoderId(coderId).getName(), groupedExams.get(key));
|
|
|
+ } catch (CustomErrorException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|