|
@@ -1,10 +1,16 @@
|
|
|
package cn.com.qmth.stmms.admin.exam;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import net.sf.json.JsonConfig;
|
|
|
+
|
|
|
import org.apache.commons.lang.StringEscapeUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -18,9 +24,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-
|
|
|
import cn.com.qmth.stmms.admin.dto.ExamQuestionDTO;
|
|
|
import cn.com.qmth.stmms.biz.campus.model.Campus;
|
|
|
import cn.com.qmth.stmms.biz.campus.service.CampusService;
|
|
@@ -46,9 +49,9 @@ import cn.com.qmth.stmms.common.enums.Role;
|
|
|
import cn.com.qmth.stmms.common.enums.ScorePolicy;
|
|
|
import cn.com.qmth.stmms.common.utils.PictureUrlBuilder;
|
|
|
import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
-import net.sf.json.JSONArray;
|
|
|
-import net.sf.json.JSONObject;
|
|
|
-import net.sf.json.JsonConfig;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
@Controller("markGroupController")
|
|
|
@RequestMapping("/admin/exam/group")
|
|
@@ -100,9 +103,8 @@ public class MarkGroupController extends BaseExamController {
|
|
|
false, group.getNumber()));
|
|
|
group.setMarkerCount(markerService.countByExamAndSubjectAndGroup(examId, subjectCode, group.getNumber()));
|
|
|
group.setCurrentCount(markService.applyCount(group));
|
|
|
- int percent = group.getLibraryCount() > 0
|
|
|
- ? (int) (group.getMarkedCount() * 100.00 / group.getLibraryCount())
|
|
|
- : 0;
|
|
|
+ int percent = group.getLibraryCount() > 0 ? (int) (group.getMarkedCount() * 100.00 / group
|
|
|
+ .getLibraryCount()) : 0;
|
|
|
group.setPercent(percent);
|
|
|
}
|
|
|
model.addAttribute("resultList", list);
|
|
@@ -117,11 +119,13 @@ public class MarkGroupController extends BaseExamController {
|
|
|
@RequestParam(required = false) Boolean withDouble, @RequestParam(required = false) MarkStatus status) {
|
|
|
int examId = getSessionExamId(request);
|
|
|
JSONArray array = new JSONArray();
|
|
|
- List<MarkGroup> list = withDouble != null && withDouble
|
|
|
- ? groupService.findByExamAndSubjectWithDouble(examId, subjectCode)
|
|
|
- : (status != null ? groupService.findByExamAndSubjectAndStatus(examId, subjectCode, status)
|
|
|
- : groupService.findByExamAndSubject(examId, subjectCode));
|
|
|
+ List<MarkGroup> list = withDouble != null && withDouble ? groupService.findByExamAndSubjectWithDouble(examId,
|
|
|
+ subjectCode) : (status != null ? groupService
|
|
|
+ .findByExamAndSubjectAndStatus(examId, subjectCode, status) : groupService.findByExamAndSubject(examId,
|
|
|
+ subjectCode));
|
|
|
for (MarkGroup group : list) {
|
|
|
+ group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode,
|
|
|
+ false, group.getNumber()));
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.accumulate("number", group.getNumber());
|
|
|
obj.accumulate("title", group.getTitle());
|
|
@@ -251,9 +255,13 @@ public class MarkGroupController extends BaseExamController {
|
|
|
if (group != null) {
|
|
|
String pictureConfig = buildPictureConfig(group);
|
|
|
group.setPicList(pictureConfig);
|
|
|
+ group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode,
|
|
|
+ false, group.getNumber()));
|
|
|
model.addAttribute("group", group);
|
|
|
- model.addAttribute("questions", questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(
|
|
|
- group.getExamId(), group.getSubjectCode(), false, group.getNumber()));
|
|
|
+ model.addAttribute(
|
|
|
+ "questions",
|
|
|
+ questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(group.getExamId(),
|
|
|
+ group.getSubjectCode(), false, group.getNumber()));
|
|
|
model.addAttribute("pictureConfig", pictureConfig);
|
|
|
model.addAttribute("markModeList", MarkMode.values());
|
|
|
model.addAttribute("scorePolicyList", ScorePolicy.values());
|
|
@@ -273,9 +281,30 @@ public class MarkGroupController extends BaseExamController {
|
|
|
if (group != null) {
|
|
|
String pictureConfig = buildPictureConfig(group);
|
|
|
group.setPicList(pictureConfig);
|
|
|
- group.setQuestionList(
|
|
|
- questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode, false, number));
|
|
|
+ group.setQuestionList(questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(examId, subjectCode,
|
|
|
+ false, number));
|
|
|
+ List<MarkGroup> questionList = new ArrayList<MarkGroup>();
|
|
|
+ String[] mainNumbers = group.getMainNumber().split(",");
|
|
|
+ for (String mainNumber : mainNumbers) {
|
|
|
+ List<ExamQuestion> list = questionService.findByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, false, Integer.parseInt(mainNumber));
|
|
|
+ StringBuilder score = new StringBuilder();
|
|
|
+ DecimalFormat format = new DecimalFormat("###.#");
|
|
|
+ String title = "";
|
|
|
+ for (ExamQuestion question : list) {
|
|
|
+ if (score.length() > 0) {
|
|
|
+ score.append(",");
|
|
|
+ }
|
|
|
+ score.append(format.format(question.getTotalScore()));
|
|
|
+ title = question.getMainTitle();
|
|
|
+ }
|
|
|
+ MarkGroup question = new MarkGroup();
|
|
|
+ question.setMainNumber(mainNumber);
|
|
|
+ question.setTitle(title);
|
|
|
+ question.setScoreList(score.toString());
|
|
|
+ questionList.add(question);
|
|
|
+ }
|
|
|
model.addAttribute("group", group);
|
|
|
+ model.addAttribute("questionList", questionList);
|
|
|
model.addAttribute("pictureConfig", pictureConfig);
|
|
|
model.addAttribute("markModeList", MarkMode.values());
|
|
|
model.addAttribute("scorePolicyList", ScorePolicy.values());
|
|
@@ -319,7 +348,8 @@ public class MarkGroupController extends BaseExamController {
|
|
|
@RequestParam(required = false) Double arbitrateThreshold,
|
|
|
@RequestParam(required = false) Integer scorePolicy, @RequestParam(required = false) MarkMode markMode,
|
|
|
@RequestParam(required = false) Integer trialCount, @RequestParam(required = false) boolean sheetView,
|
|
|
- @RequestParam(required = false) String questionDetail) {
|
|
|
+ @RequestParam(required = false) String questionDetail,
|
|
|
+ @RequestParam(required = false) String intervalScoreList) {
|
|
|
int examId = getSessionExamId(request);
|
|
|
MarkGroup group = groupService.findOne(examId, subjectCode, number);
|
|
|
if (group != null) {
|
|
@@ -341,35 +371,42 @@ public class MarkGroupController extends BaseExamController {
|
|
|
groupService.updateTrialCount(examId, subjectCode, number, trialCount);
|
|
|
}
|
|
|
groupService.updateSheetView(examId, subjectCode, number, sheetView);
|
|
|
- // build questionDetail
|
|
|
- questionDetail = StringEscapeUtils.unescapeHtml(questionDetail);
|
|
|
- array = JSONArray.fromObject(picList);
|
|
|
- List<ExamQuestionDTO> detailList = JSONArray.toList(array, new ExamQuestionDTO(), new JsonConfig());
|
|
|
- if (detailList != null && detailList.size() > 0) {
|
|
|
+ if (questionDetail != null && reset.booleanValue()) {
|
|
|
// advance update
|
|
|
- if (reset != null && reset.booleanValue()) {
|
|
|
+ questionDetail = StringEscapeUtils.unescapeHtml(questionDetail);
|
|
|
+ array = JSONArray.fromObject(questionDetail);
|
|
|
+ List<ExamQuestionDTO> detailList = JSONArray.toList(array, new ExamQuestionDTO(), new JsonConfig());
|
|
|
+ for (int i = 0; i < detailList.size(); i++) {
|
|
|
+ ExamQuestionDTO dto = detailList.get(i);
|
|
|
+ Object scoreListArray[] = array.getJSONObject(i).getJSONArray("scoreList").toArray();
|
|
|
+ List<Double> scoreList = new ArrayList<Double>();
|
|
|
+ for (int j = 0; j < scoreListArray.length; j++) {
|
|
|
+ scoreList.add(Double.parseDouble(scoreListArray[j].toString()));
|
|
|
+ }
|
|
|
+ dto.setScoreList(scoreList);
|
|
|
+ }
|
|
|
+ if (detailList != null && detailList.size() > 0) {
|
|
|
ScorePolicy policy = scorePolicy != null ? ScorePolicy.findByValue(scorePolicy) : null;
|
|
|
try {
|
|
|
- lockService.waitlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),
|
|
|
- group.getNumber());
|
|
|
+ lockService.waitlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),group.getNumber());
|
|
|
markService.updateGroup(group, buildQuestionList(group, detailList), policy);
|
|
|
} catch (Exception e) {
|
|
|
log.error("update group error", e);
|
|
|
throw new RuntimeException("重置更新大题失败", e);
|
|
|
} finally {
|
|
|
- lockService.unlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),
|
|
|
- group.getNumber());
|
|
|
+ lockService.unlock(LockType.GROUP, true, group.getExamId(), group.getSubjectCode(),group.getNumber());
|
|
|
}
|
|
|
- } else {
|
|
|
- for (ExamQuestionDTO detail : detailList) {
|
|
|
- List<ExamQuestion> subList = questionService.findByExamAndSubjectAndObjectiveAndMainNumber(
|
|
|
- examId, subjectCode, false, detail.getMainNumber());
|
|
|
- for (int i = 0; i < subList.size(); i++) {
|
|
|
- ExamQuestion question = subList.get(i);
|
|
|
- question.setMainTitle(detail.getMainTitle());
|
|
|
- question.setIntervalScore(detail.getIntervalScoreList()[i]);
|
|
|
- questionService.save(question);
|
|
|
- }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // simple update
|
|
|
+ List<Double> intervalScores = buildDoubleList(intervalScoreList);
|
|
|
+ List<ExamQuestion> questionList = questionService.findByExamAndSubjectAndObjectiveAndGroupNumber(
|
|
|
+ examId, subjectCode, false, number);
|
|
|
+ if (intervalScores.size() == questionList.size()) {
|
|
|
+ for (int i = 0; i < questionList.size(); i++) {
|
|
|
+ ExamQuestion q = questionList.get(i);
|
|
|
+ q.setIntervalScore(intervalScores.get(i));
|
|
|
+ questionService.save(q);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -415,9 +452,17 @@ public class MarkGroupController extends BaseExamController {
|
|
|
List<PictureConfigItem> picConfigList = JSONArray.toList(array, new PictureConfigItem(), new JsonConfig());
|
|
|
// build questionDetail
|
|
|
questionDetail = StringEscapeUtils.unescapeHtml(questionDetail);
|
|
|
- array = JSONArray.fromObject(picList);
|
|
|
+ array = JSONArray.fromObject(questionDetail);
|
|
|
List<ExamQuestionDTO> detailList = JSONArray.toList(array, new ExamQuestionDTO(), new JsonConfig());
|
|
|
-
|
|
|
+ for (int i = 0; i < detailList.size(); i++) {
|
|
|
+ ExamQuestionDTO dto = detailList.get(i);
|
|
|
+ Object o[] = array.getJSONObject(i).getJSONArray("scoreList").toArray();
|
|
|
+ List<Double> scoreList = new ArrayList<Double>();
|
|
|
+ for (int j = 0; j < o.length; j++) {
|
|
|
+ scoreList.add(Double.parseDouble(o[j].toString()));
|
|
|
+ }
|
|
|
+ dto.setScoreList(scoreList);
|
|
|
+ }
|
|
|
if (picConfigList != null && detailList != null && picConfigList.size() > 0 && detailList.size() > 0) {
|
|
|
for (ExamQuestionDTO detail : detailList) {
|
|
|
if (questionService.countByExamAndSubjectAndObjectiveAndMainNumber(examId, subjectCode, false,
|
|
@@ -515,4 +560,25 @@ public class MarkGroupController extends BaseExamController {
|
|
|
group.setTotalScore(totalScore);
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ private List<Double> buildDoubleList(String content) {
|
|
|
+ List<Double> list = new ArrayList<Double>();
|
|
|
+ content = StringUtils.trimToNull(content);
|
|
|
+ if (content != null) {
|
|
|
+ String[] values = StringUtils.split(content, ",");
|
|
|
+ if (values != null) {
|
|
|
+ for (String value : values) {
|
|
|
+ try {
|
|
|
+ Double number = Double.valueOf(value);
|
|
|
+ if (number != null) {
|
|
|
+ list.add(number);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|