|
@@ -15,10 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
|
|
+import cn.com.qmth.stmms.admin.dto.SelectivePartDTO;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamQuestion;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
|
|
import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
import cn.com.qmth.stmms.biz.exam.model.MarkGroup;
|
|
@@ -29,6 +31,7 @@ import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
|
|
import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
|
|
import cn.com.qmth.stmms.biz.exam.service.SelectiveGroupService;
|
|
import cn.com.qmth.stmms.common.annotation.Logging;
|
|
import cn.com.qmth.stmms.common.annotation.Logging;
|
|
import cn.com.qmth.stmms.common.enums.LogType;
|
|
import cn.com.qmth.stmms.common.enums.LogType;
|
|
|
|
+import cn.com.qmth.stmms.common.enums.ScorePolicy;
|
|
import cn.com.qmth.stmms.common.utils.BigDecimalUtils;
|
|
import cn.com.qmth.stmms.common.utils.BigDecimalUtils;
|
|
|
|
|
|
@Controller("selectiveGroupController")
|
|
@Controller("selectiveGroupController")
|
|
@@ -54,93 +57,151 @@ public class SelectiveGroupController extends BaseExamController {
|
|
public String list(HttpServletRequest request, Model model, @RequestParam String subjectCode) {
|
|
public String list(HttpServletRequest request, Model model, @RequestParam String subjectCode) {
|
|
int examId = getSessionExamId(request);
|
|
int examId = getSessionExamId(request);
|
|
ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
- List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
|
|
List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
- Set<Integer> mainNumbers = new HashSet<Integer>();
|
|
|
|
|
|
+ Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
for (SelectiveGroup selectiveGroup : list) {
|
|
for (SelectiveGroup selectiveGroup : list) {
|
|
- mainNumbers.add(selectiveGroup.getMainNumber());
|
|
|
|
|
|
+ map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
}
|
|
}
|
|
|
|
+ List<ExamQuestion> questions = questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
for (ExamQuestion examQuestion : questions) {
|
|
for (ExamQuestion examQuestion : questions) {
|
|
- if (mainNumbers.contains(examQuestion.getMainNumber())) {
|
|
|
|
|
|
+ if (map.get(examQuestion.getMainNumber()) != null) {
|
|
examQuestion.setSelective(true);
|
|
examQuestion.setSelective(true);
|
|
|
|
+ examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (!list.isEmpty()) {
|
|
|
|
- model.addAttribute("selectiveCount", list.get(0).getSelectiveCount());
|
|
|
|
- }
|
|
|
|
model.addAttribute("subject", subject);
|
|
model.addAttribute("subject", subject);
|
|
- model.addAttribute("list", list);
|
|
|
|
|
|
+ model.addAttribute("list", selectiveGroupService.findIndexByExamIdAndSubjectCode(examId, subjectCode));
|
|
model.addAttribute("questions", questions);
|
|
model.addAttribute("questions", questions);
|
|
|
|
+ ScorePolicy[] scorePolicyList = { ScorePolicy.MAX, ScorePolicy.MIN };
|
|
|
|
+ model.addAttribute("scorePolicyList", scorePolicyList);
|
|
return "modules/exam/selectiveList";
|
|
return "modules/exam/selectiveList";
|
|
}
|
|
}
|
|
|
|
|
|
- @Logging(menu = "选做题设置", type = LogType.ADD)
|
|
|
|
@RequestMapping("/add")
|
|
@RequestMapping("/add")
|
|
|
|
+ public String add(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
|
|
+ @RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
|
|
+ @RequestParam Integer selectivePart) {
|
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
|
+ List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
|
|
+ if (groups != null && groups.size() > 0) {
|
|
|
|
+ addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
|
|
+ }
|
|
|
|
+ ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
|
|
+ List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
+ Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
|
|
+ for (SelectiveGroup selectiveGroup : list) {
|
|
|
|
+ map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
|
|
+ for (ExamQuestion examQuestion : questions) {
|
|
|
|
+ if (map.get(examQuestion.getMainNumber()) != null) {
|
|
|
|
+ examQuestion.setSelective(true);
|
|
|
|
+ examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ model.addAttribute("selectiveCount", selectiveCount);
|
|
|
|
+ model.addAttribute("selectivePart", selectivePart);
|
|
|
|
+ model.addAttribute("scorePolicy", scorePolicy);
|
|
|
|
+ model.addAttribute("questions", questions);
|
|
|
|
+ model.addAttribute("subject", subject);
|
|
|
|
+ return "modules/exam/selectiveAdd";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Logging(menu = "选做题新增", type = LogType.ADD)
|
|
|
|
+ @RequestMapping("/save")
|
|
@Transactional
|
|
@Transactional
|
|
- public String add(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
|
|
- @RequestParam String subjectCode, @RequestParam Integer[] mainNumbers, @RequestParam Integer selectiveCount) {
|
|
|
|
|
|
+ public String save(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
|
|
+ @RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
|
|
+ @RequestParam Integer selectivePart, @RequestBody List<SelectivePartDTO> parts) {
|
|
int examId = getSessionExamId(request);
|
|
int examId = getSessionExamId(request);
|
|
- if (selectiveCount >= mainNumbers.length) {
|
|
|
|
|
|
+ if (selectiveCount >= selectivePart) {
|
|
addMessage(redirectAttributes, "选做题数量不能大于已选择题目数量");
|
|
addMessage(redirectAttributes, "选做题数量不能大于已选择题目数量");
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
if (groups != null && groups.size() > 0) {
|
|
if (groups != null && groups.size() > 0) {
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
- Double questionScore = checkTotalScore(examId, subjectCode, mainNumbers);
|
|
|
|
- if (questionScore == null) {
|
|
|
|
- addMessage(redirectAttributes, "选做题分数必须一样");
|
|
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
|
|
+ if (checkTotalScore(examId, subjectCode, parts)) {
|
|
|
|
+ addMessage(redirectAttributes, "选做题区分数必须一样");
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
- selectiveGroupService.deleteByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
- if (mainNumbers.length > 0) {
|
|
|
|
|
|
+ for (SelectivePartDTO part : parts) {
|
|
List<SelectiveGroup> list = new ArrayList<SelectiveGroup>();
|
|
List<SelectiveGroup> list = new ArrayList<SelectiveGroup>();
|
|
- for (Integer mainNumber : mainNumbers) {
|
|
|
|
- list.add(new SelectiveGroup(examId, subjectCode, mainNumber, 1, selectiveCount));
|
|
|
|
|
|
+ for (Integer mainNumber : part.getMainNumbers()) {
|
|
|
|
+ list.add(new SelectiveGroup(examId, subjectCode, mainNumber, part.getSelectivePart(), selectiveCount,
|
|
|
|
+ selectivePart, ScorePolicy.findByValue(scorePolicy)));
|
|
}
|
|
}
|
|
selectiveGroupService.save(list);
|
|
selectiveGroupService.save(list);
|
|
- Double totalScore = questionService.sumTotalScore(examId, subjectCode, false);
|
|
|
|
- totalScore = BigDecimalUtils.sub(totalScore,
|
|
|
|
- BigDecimalUtils.mul(BigDecimalUtils.sub(mainNumbers.length, selectiveCount), questionScore));
|
|
|
|
- subjectService.updateScore(examId, subjectCode, false, totalScore);
|
|
|
|
}
|
|
}
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
|
|
+ calculate(examId, subjectCode);
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
|
|
|
|
- private Double checkTotalScore(int examId, String subjectCode, Integer[] mainNumbers) {
|
|
|
|
|
|
+ private boolean checkTotalScore(int examId, String subjectCode, List<SelectivePartDTO> parts) {
|
|
List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
Map<Integer, ExamQuestion> map = new HashMap<Integer, ExamQuestion>();
|
|
Map<Integer, ExamQuestion> map = new HashMap<Integer, ExamQuestion>();
|
|
for (ExamQuestion examQuestion : questions) {
|
|
for (ExamQuestion examQuestion : questions) {
|
|
map.put(examQuestion.getMainNumber(), examQuestion);
|
|
map.put(examQuestion.getMainNumber(), examQuestion);
|
|
}
|
|
}
|
|
- Double totalScore = null;
|
|
|
|
- for (Integer mainNumber : mainNumbers) {
|
|
|
|
- if (totalScore == null) {
|
|
|
|
- totalScore = map.get(mainNumber).getTotalScore();
|
|
|
|
- }
|
|
|
|
- if (totalScore.doubleValue() != map.get(mainNumber).getTotalScore().doubleValue()) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ Set<Double> scores = new HashSet<Double>();
|
|
|
|
+ for (SelectivePartDTO part : parts) {
|
|
|
|
+ double totalScore = 0;
|
|
|
|
+ for (Integer mainNumber : part.getMainNumbers()) {
|
|
|
|
+ totalScore = totalScore + map.get(mainNumber).getTotalScore();
|
|
}
|
|
}
|
|
|
|
+ scores.add(totalScore);
|
|
}
|
|
}
|
|
- return totalScore;
|
|
|
|
|
|
+ return scores.size() > 1;
|
|
}
|
|
}
|
|
|
|
|
|
- @Logging(menu = "清空选做题设置", type = LogType.ADD)
|
|
|
|
- @RequestMapping("/clear")
|
|
|
|
|
|
+ @Logging(menu = "删除选做题", type = LogType.DELETE)
|
|
|
|
+ @RequestMapping("/delete")
|
|
@Transactional
|
|
@Transactional
|
|
public String claer(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
public String claer(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
- @RequestParam String subjectCode) {
|
|
|
|
|
|
+ @RequestParam String subjectCode, @RequestParam Integer selectiveIndex) {
|
|
int examId = getSessionExamId(request);
|
|
int examId = getSessionExamId(request);
|
|
List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
List<MarkGroup> groups = groupService.findByExamAndSubject(examId, subjectCode);
|
|
if (groups != null && groups.size() > 0) {
|
|
if (groups != null && groups.size() > 0) {
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
|
|
+ }
|
|
|
|
+ selectiveGroupService.deleteByExamIdAndSubjectCodeAndSelectiveIndex(examId, subjectCode, selectiveIndex);
|
|
|
|
+ calculate(examId, subjectCode);
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calculate(int examId, String subjectCode) {
|
|
|
|
+ List<SelectiveGroup> selectiveGroups = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
+ if (!selectiveGroups.isEmpty()) {
|
|
|
|
+ double totalScore = 0;
|
|
|
|
+ Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
|
|
+ for (SelectiveGroup selectiveGroup : selectiveGroups) {
|
|
|
|
+ map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
|
|
+ }
|
|
|
|
+ List<ExamQuestion> questions = questionService.findByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
|
|
+ for (ExamQuestion examQuestion : questions) {
|
|
|
|
+ if (map.get(examQuestion.getMainNumber()) != null) {
|
|
|
|
+ examQuestion.setSelective(true);
|
|
|
|
+ examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
|
|
+ } else {
|
|
|
|
+ // 非选做题总分
|
|
|
|
+ totalScore = BigDecimalUtils.add(totalScore, examQuestion.getTotalScore());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<SelectiveGroup> indexGroup = selectiveGroupService
|
|
|
|
+ .findIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
+ for (SelectiveGroup selectiveGroup : indexGroup) {
|
|
|
|
+ // 选做题分组总分
|
|
|
|
+ totalScore = BigDecimalUtils.add(totalScore, selectiveGroup.getPartScore());
|
|
|
|
+ }
|
|
|
|
+ subjectService.updateScore(examId, subjectCode, false, totalScore);
|
|
|
|
+ } else {
|
|
|
|
+ subjectService.updateScore(examId, subjectCode, false,
|
|
|
|
+ questionService.sumTotalScore(examId, subjectCode, false));
|
|
}
|
|
}
|
|
- selectiveGroupService.deleteByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
- subjectService.updateScore(examId, subjectCode, false,
|
|
|
|
- questionService.sumTotalScore(examId, subjectCode, false));
|
|
|
|
- return "redirect:/admin/exam/paper";
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|