|
@@ -8,6 +8,8 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamService;
|
|
|
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
|
|
|
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
|
|
|
import cn.com.qmth.stmms.biz.report.model.ReportSubject;
|
|
|
import cn.com.qmth.stmms.biz.report.model.ReportSubjectClass;
|
|
@@ -43,6 +46,8 @@ import cn.com.qmth.stmms.biz.school.service.SchoolService;
|
|
|
@RequestMapping("/report")
|
|
|
public class ReportController {
|
|
|
|
|
|
+ protected static Logger log = LoggerFactory.getLogger(ReportController.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamService examService;
|
|
|
|
|
@@ -76,6 +81,9 @@ public class ReportController {
|
|
|
@Autowired
|
|
|
private ReportSubjectService reportSubjectService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService studentService;
|
|
|
+
|
|
|
public static final String ANSWER_SPLIT = ",";
|
|
|
|
|
|
@RequestMapping(value = "/teachAndResearch/{examId}/{subjectCode}", method = RequestMethod.GET)
|
|
@@ -95,44 +103,63 @@ public class ReportController {
|
|
|
}
|
|
|
|
|
|
private JSONObject getJson(Integer examId, String subjectCode, String paperType) {
|
|
|
- Exam exam = examService.findById(examId);
|
|
|
- School school = schoolService.findById(exam.getSchoolId());
|
|
|
- ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
JSONObject result = new JSONObject();
|
|
|
- result.accumulate("examName", exam.getName());
|
|
|
- result.accumulate("schoolName", school.getName());
|
|
|
- result.accumulate("subjectName", paperType == null ? subject.getName() : subject.getName() + "_" + paperType);
|
|
|
- ReportSubjectQuery query = new ReportSubjectQuery();
|
|
|
- query.setExamId(examId);
|
|
|
- query.setSubjectCode(subjectCode);
|
|
|
- query.setPaperType(paperType);
|
|
|
- query.setPageSize(Integer.MAX_VALUE);
|
|
|
- ReportSubject reportSubject = reportSubjectService.findOne(query.getExamId(), query.getSubjectCode());
|
|
|
- List<ReportSubjectClass> subjectClasses = classService.findByQuery(query);
|
|
|
- List<ReportSubjectGroup> subjectGroups = new ArrayList<ReportSubjectGroup>();
|
|
|
- query.setObjective(true);
|
|
|
- List<ReportSubjectGroup> subjectGroupO = groupService.findByQuery(query);
|
|
|
- query.setObjective(false);
|
|
|
- List<ReportSubjectGroup> subjectGroupsS = groupService.findByQuery(query);
|
|
|
- subjectGroups.addAll(subjectGroupO);
|
|
|
- subjectGroups.addAll(subjectGroupsS);
|
|
|
- result.accumulate("basic_paper", getPaperJson(reportSubject));
|
|
|
- result.accumulate("basic_question_subjective", getQuestionJson(query, false, paperType));
|
|
|
- result.accumulate("basic_question_objective", getQuestionJson(query, true, paperType));
|
|
|
- result.accumulate("basic_class", getClassJson(subjectClasses));
|
|
|
- result.accumulate("basic_teacher", getTeacerJson(query));
|
|
|
- result.accumulate("basic_college", getCollegeJson(query));
|
|
|
- result.accumulate("basic_main_question", getGroupJson(subjectGroups));
|
|
|
- result.accumulate("basic_question_option", getOptionJson(query, reportSubject, paperType));
|
|
|
- result.accumulate("discrimination_level",
|
|
|
- getDiscrimination(query, paperType, reportSubject, subjectClasses, subjectGroups));
|
|
|
- result.accumulate("difficulty_level",
|
|
|
- getDifficulty(query, paperType, reportSubject, subjectClasses, subjectGroups));
|
|
|
- result.accumulate("range_level", getRangeLevel(query, reportSubject, subjectClasses));
|
|
|
- result.accumulate("range_10_totalScore", getRange10(reportSubject, subjectClasses));
|
|
|
- result.accumulate("range_1_totalScore", getRange1(reportSubject, subjectClasses));
|
|
|
- result.accumulate("range_segment_6", getRange6(reportSubject, subjectClasses));
|
|
|
- return result;
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
+ if (subject == null) {
|
|
|
+ result.accumulate("code", "500");
|
|
|
+ result.accumulate("message", "找不到对应科目");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<String> paperTypes = studentService.findDistinctPaperType(examId, subjectCode);
|
|
|
+ if (!paperTypes.contains(paperType)) {
|
|
|
+ result.accumulate("code", "500");
|
|
|
+ result.accumulate("message", "没有对应的卷型");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ School school = schoolService.findById(exam.getSchoolId());
|
|
|
+ result.accumulate("examName", exam.getName());
|
|
|
+ result.accumulate("schoolName", school.getName());
|
|
|
+ result.accumulate("subjectName", paperType == null ? subject.getName() : subject.getName() + "_"
|
|
|
+ + paperType);
|
|
|
+ ReportSubjectQuery query = new ReportSubjectQuery();
|
|
|
+ query.setExamId(examId);
|
|
|
+ query.setSubjectCode(subjectCode);
|
|
|
+ query.setPaperType(paperType);
|
|
|
+ query.setPageSize(Integer.MAX_VALUE);
|
|
|
+ ReportSubject reportSubject = reportSubjectService.findOne(query.getExamId(), query.getSubjectCode());
|
|
|
+ List<ReportSubjectClass> subjectClasses = classService.findByQuery(query);
|
|
|
+ List<ReportSubjectGroup> subjectGroups = new ArrayList<ReportSubjectGroup>();
|
|
|
+ query.setObjective(true);
|
|
|
+ List<ReportSubjectGroup> subjectGroupO = groupService.findByQuery(query);
|
|
|
+ query.setObjective(false);
|
|
|
+ List<ReportSubjectGroup> subjectGroupsS = groupService.findByQuery(query);
|
|
|
+ subjectGroups.addAll(subjectGroupO);
|
|
|
+ subjectGroups.addAll(subjectGroupsS);
|
|
|
+ result.accumulate("basic_paper", getPaperJson(reportSubject));
|
|
|
+ result.accumulate("basic_question_subjective", getQuestionJson(query, false, null));
|
|
|
+ result.accumulate("basic_question_objective", getQuestionJson(query, true, paperType));
|
|
|
+ result.accumulate("basic_class", getClassJson(subjectClasses));
|
|
|
+ result.accumulate("basic_teacher", getTeacerJson(query));
|
|
|
+ result.accumulate("basic_college", getCollegeJson(query));
|
|
|
+ result.accumulate("basic_main_question", getGroupJson(subjectGroups));
|
|
|
+ result.accumulate("basic_question_option", getOptionJson(query, reportSubject, paperType));
|
|
|
+ result.accumulate("discrimination_level",
|
|
|
+ getDiscrimination(query, paperType, reportSubject, subjectClasses, subjectGroups));
|
|
|
+ result.accumulate("difficulty_level",
|
|
|
+ getDifficulty(query, paperType, reportSubject, subjectClasses, subjectGroups));
|
|
|
+ result.accumulate("range_level", getRangeLevel(query, reportSubject, subjectClasses));
|
|
|
+ result.accumulate("range_10_totalScore", getRange10(reportSubject, subjectClasses));
|
|
|
+ result.accumulate("range_1_totalScore", getRange1(reportSubject, subjectClasses));
|
|
|
+ result.accumulate("range_segment_6", getRange6(reportSubject, subjectClasses));
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("report for examId=" + examId + "&subjectCode=" + subjectCode + "&paperType=" + paperType, e);
|
|
|
+ result.accumulate("code", "500");
|
|
|
+ result.accumulate("message", "系统异常");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private String getPaperJson(ReportSubject r) {
|
|
@@ -176,13 +203,13 @@ public class ReportController {
|
|
|
private String getRange1(ReportSubject subject, List<ReportSubjectClass> list) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.accumulate("total",
|
|
|
- getScoreRange(subject.getScoreRange(), subject.getTotalScore(), 1, subject.getRealityCount()));
|
|
|
+ getScoreRange1(subject.getScoreRange(), subject.getTotalScore(), subject.getRealityCount()));
|
|
|
JSONArray classes = new JSONArray();
|
|
|
for (ReportSubjectClass c : list) {
|
|
|
JSONObject classValue = new JSONObject();
|
|
|
classValue.accumulate("name", c.getClassName());
|
|
|
classValue.accumulate("ranges",
|
|
|
- getScoreRange(c.getScoreRange(), subject.getTotalScore(), 1, c.getRealityCount()));
|
|
|
+ getScoreRange1(c.getScoreRange(), subject.getTotalScore(), c.getRealityCount()));
|
|
|
classes.add(classValue);
|
|
|
}
|
|
|
result.accumulate("classes", classes);
|
|
@@ -205,28 +232,16 @@ public class ReportController {
|
|
|
return result.toString();
|
|
|
}
|
|
|
|
|
|
- private JSONArray getScoreRange(String scoreRange, double totalScore, int range, Integer totalCount) {
|
|
|
+ private JSONArray getScoreRange1(String scoreRange, double totalScore, Integer totalCount) {
|
|
|
JSONArray result = new JSONArray();
|
|
|
JSONObject jsonObject = JSONObject.fromObject(scoreRange);
|
|
|
int rangeCount = 0;
|
|
|
int sumCount = 0;
|
|
|
int total = (int) Math.ceil(totalScore);
|
|
|
for (int i = total; i >= 0; i--) {
|
|
|
- if (i % range == 0) {
|
|
|
- if (i == 0) {
|
|
|
- rangeCount = jsonObject.getInt(String.valueOf(i));
|
|
|
- } else {
|
|
|
- rangeCount = getSumCount(jsonObject, i, i - range + 1);
|
|
|
- }
|
|
|
- sumCount = sumCount + rangeCount;
|
|
|
- JSONObject value = new JSONObject();
|
|
|
- value.accumulate("score", i);
|
|
|
- value.accumulate("rangeCount", rangeCount);
|
|
|
- value.accumulate("rangeRate", rangeCount * 100.0 / totalCount);
|
|
|
- value.accumulate("sumCount", sumCount);
|
|
|
- value.accumulate("sumRate", sumCount * 100.0 / totalCount);
|
|
|
- result.add(value);
|
|
|
- }
|
|
|
+ rangeCount = jsonObject.getInt(String.valueOf(i));
|
|
|
+ sumCount = sumCount + rangeCount;
|
|
|
+ result.add(getRangeJson(totalCount, rangeCount, sumCount, i));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -249,13 +264,7 @@ public class ReportController {
|
|
|
}
|
|
|
rangeCount = getSumCount(jsonObject, start, end);
|
|
|
sumCount = sumCount + rangeCount;
|
|
|
- JSONObject value = new JSONObject();
|
|
|
- value.accumulate("score", i * range);
|
|
|
- value.accumulate("rangeCount", rangeCount);
|
|
|
- value.accumulate("rangeRate", rangeCount * 100.0 / totalCount);
|
|
|
- value.accumulate("sumCount", sumCount);
|
|
|
- value.accumulate("sumRate", sumCount * 100.0 / totalCount);
|
|
|
- result.add(value);
|
|
|
+ result.add(getRangeJson(totalCount, rangeCount, sumCount, i * range));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -280,6 +289,16 @@ public class ReportController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private JSONObject getRangeJson(Integer totalCount, int rangeCount, int sumCount, int score) {
|
|
|
+ JSONObject value = new JSONObject();
|
|
|
+ value.accumulate("score", score);
|
|
|
+ value.accumulate("rangeCount", rangeCount);
|
|
|
+ value.accumulate("rangeRate", rangeCount * 100.0 / totalCount);
|
|
|
+ value.accumulate("sumCount", sumCount);
|
|
|
+ value.accumulate("sumRate", sumCount * 100.0 / totalCount);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
private JSONObject getRangeJson(Integer totalCount, int rangeCount, int sumCount, int start, int end) {
|
|
|
JSONObject value = new JSONObject();
|
|
|
if (start == 0 && end == 0) {
|
|
@@ -479,13 +498,11 @@ public class ReportController {
|
|
|
|
|
|
private String getOptionJson(ReportSubjectQuery query, ReportSubject reportSubject, String paperType) {
|
|
|
JSONObject value = new JSONObject();
|
|
|
- if (reportSubject.getOptions() != null) {
|
|
|
- value.accumulate("options", reportSubject.getOptions().split(ANSWER_SPLIT));
|
|
|
- }
|
|
|
- JSONArray array = new JSONArray();
|
|
|
+ value.accumulate("options", reportSubject.getOptions() == null?new JSONArray().toString():reportSubject.getOptions().split(ANSWER_SPLIT));
|
|
|
query.setObjective(true);
|
|
|
query.setPaperType(paperType);
|
|
|
List<ReportSubjectQuestion> list = questionService.findByQuery(query);
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
for (ReportSubjectQuestion r : list) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.accumulate("number", r.getMainNumber() + "-" + r.getSubNumber());
|