|
@@ -9,13 +9,17 @@ import java.util.Set;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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;
|
|
@@ -67,6 +71,7 @@ public class SelectiveGroupController extends BaseExamController {
|
|
if (map.get(examQuestion.getMainNumber()) != null) {
|
|
if (map.get(examQuestion.getMainNumber()) != null) {
|
|
examQuestion.setSelective(true);
|
|
examQuestion.setSelective(true);
|
|
examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
|
|
+ examQuestion.setSelectivePart(map.get(examQuestion.getMainNumber()).getSelectivePart());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
model.addAttribute("subject", subject);
|
|
model.addAttribute("subject", subject);
|
|
@@ -80,41 +85,73 @@ public class SelectiveGroupController extends BaseExamController {
|
|
@RequestMapping("/add")
|
|
@RequestMapping("/add")
|
|
public String add(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
public String add(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
@RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
@RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
- @RequestParam Integer selectivePart) {
|
|
|
|
|
|
+ @RequestParam Integer selectivePart, @RequestParam(required = false) String parts) {
|
|
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/selectiveGroup?subjectCode=" + subjectCode;
|
|
return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
|
|
+ List<SelectivePartDTO> partList = getPartList(parts);
|
|
|
|
+ if (checkTotalScore(examId, subjectCode, partList)) {
|
|
|
|
+ addMessage(redirectAttributes, "选做题区分数必须一样");
|
|
|
|
+ return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
|
|
+ }
|
|
ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
ExamSubject subject = subjectService.find(examId, subjectCode);
|
|
List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
List<SelectiveGroup> list = selectiveGroupService.findByExamIdAndSubjectCode(examId, subjectCode);
|
|
Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
Map<Integer, SelectiveGroup> map = new HashMap<Integer, SelectiveGroup>();
|
|
for (SelectiveGroup selectiveGroup : list) {
|
|
for (SelectiveGroup selectiveGroup : list) {
|
|
map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
map.put(selectiveGroup.getMainNumber(), selectiveGroup);
|
|
}
|
|
}
|
|
-
|
|
|
|
List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
List<ExamQuestion> questions = questionService.findMainByExamAndSubjectAndObjective(examId, subjectCode, false);
|
|
for (ExamQuestion examQuestion : questions) {
|
|
for (ExamQuestion examQuestion : questions) {
|
|
if (map.get(examQuestion.getMainNumber()) != null) {
|
|
if (map.get(examQuestion.getMainNumber()) != null) {
|
|
examQuestion.setSelective(true);
|
|
examQuestion.setSelective(true);
|
|
examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
examQuestion.setSelectiveIndex(map.get(examQuestion.getMainNumber()).getSelectiveIndex());
|
|
}
|
|
}
|
|
|
|
+ for (SelectivePartDTO selectivePartDTO : partList) {
|
|
|
|
+ if (selectivePartDTO.getMainNumbers().contains(examQuestion.getMainNumber())) {
|
|
|
|
+ examQuestion.setSelective(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
model.addAttribute("selectiveCount", selectiveCount);
|
|
model.addAttribute("selectiveCount", selectiveCount);
|
|
model.addAttribute("selectivePart", selectivePart);
|
|
model.addAttribute("selectivePart", selectivePart);
|
|
|
|
+ model.addAttribute("selectivePartNo", partList.size() + 1);
|
|
model.addAttribute("scorePolicy", scorePolicy);
|
|
model.addAttribute("scorePolicy", scorePolicy);
|
|
model.addAttribute("questions", questions);
|
|
model.addAttribute("questions", questions);
|
|
model.addAttribute("subject", subject);
|
|
model.addAttribute("subject", subject);
|
|
|
|
+ model.addAttribute("parts", parts);
|
|
return "modules/exam/selectiveAdd";
|
|
return "modules/exam/selectiveAdd";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private List<SelectivePartDTO> getPartList(String parts) {
|
|
|
|
+ List<SelectivePartDTO> list = new ArrayList<SelectivePartDTO>();
|
|
|
|
+ if (StringUtils.isNotBlank(parts)) {
|
|
|
|
+ parts = StringEscapeUtils.unescapeHtml(parts);
|
|
|
|
+ JSONArray array = JSONArray.fromObject(parts);
|
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
|
+ JSONObject part = array.getJSONObject(i);
|
|
|
|
+ SelectivePartDTO dto = new SelectivePartDTO();
|
|
|
|
+ dto.setSelectivePart(part.getInt("selectivePart"));
|
|
|
|
+ List<Integer> mainNumbers = new ArrayList<Integer>();
|
|
|
|
+ JSONArray mainNumberArr = part.getJSONArray("mainNumbers");
|
|
|
|
+ for (Object object : mainNumberArr) {
|
|
|
|
+ mainNumbers.add(Integer.parseInt(object.toString()));
|
|
|
|
+ }
|
|
|
|
+ dto.setMainNumbers(mainNumbers);
|
|
|
|
+ list.add(dto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Logging(menu = "选做题新增", type = LogType.ADD)
|
|
@Logging(menu = "选做题新增", type = LogType.ADD)
|
|
@RequestMapping("/save")
|
|
@RequestMapping("/save")
|
|
@Transactional
|
|
@Transactional
|
|
public String save(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
public String save(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
@RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
@RequestParam String subjectCode, @RequestParam Integer selectiveCount, @RequestParam Integer scorePolicy,
|
|
- @RequestParam Integer selectivePart, @RequestBody List<SelectivePartDTO> parts) {
|
|
|
|
|
|
+ @RequestParam Integer selectivePart, @RequestParam String parts) {
|
|
int examId = getSessionExamId(request);
|
|
int examId = getSessionExamId(request);
|
|
if (selectiveCount >= selectivePart) {
|
|
if (selectiveCount >= selectivePart) {
|
|
addMessage(redirectAttributes, "选做题数量不能大于已选择题目数量");
|
|
addMessage(redirectAttributes, "选做题数量不能大于已选择题目数量");
|
|
@@ -125,15 +162,17 @@ public class SelectiveGroupController extends BaseExamController {
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
addMessage(redirectAttributes, "该科目已经存在分组,无法设置");
|
|
return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
- if (checkTotalScore(examId, subjectCode, parts)) {
|
|
|
|
|
|
+ List<SelectivePartDTO> partList = getPartList(parts);
|
|
|
|
+ if (checkTotalScore(examId, subjectCode, partList)) {
|
|
addMessage(redirectAttributes, "选做题区分数必须一样");
|
|
addMessage(redirectAttributes, "选做题区分数必须一样");
|
|
return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
return "redirect:/admin/exam/selectiveGroup?subjectCode=" + subjectCode;
|
|
}
|
|
}
|
|
- for (SelectivePartDTO part : parts) {
|
|
|
|
|
|
+ int index = selectiveGroupService.findMaxIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
|
|
+ for (SelectivePartDTO part : partList) {
|
|
List<SelectiveGroup> list = new ArrayList<SelectiveGroup>();
|
|
List<SelectiveGroup> list = new ArrayList<SelectiveGroup>();
|
|
for (Integer mainNumber : part.getMainNumbers()) {
|
|
for (Integer mainNumber : part.getMainNumbers()) {
|
|
- list.add(new SelectiveGroup(examId, subjectCode, mainNumber, part.getSelectivePart(), selectiveCount,
|
|
|
|
- selectivePart, ScorePolicy.findByValue(scorePolicy)));
|
|
|
|
|
|
+ list.add(new SelectiveGroup(examId, subjectCode, mainNumber, index + 1, selectiveCount, part
|
|
|
|
+ .getSelectivePart(), ScorePolicy.findByValue(scorePolicy)));
|
|
}
|
|
}
|
|
selectiveGroupService.save(list);
|
|
selectiveGroupService.save(list);
|
|
}
|
|
}
|
|
@@ -161,7 +200,7 @@ public class SelectiveGroupController extends BaseExamController {
|
|
@Logging(menu = "删除选做题", type = LogType.DELETE)
|
|
@Logging(menu = "删除选做题", type = LogType.DELETE)
|
|
@RequestMapping("/delete")
|
|
@RequestMapping("/delete")
|
|
@Transactional
|
|
@Transactional
|
|
- public String claer(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
|
|
|
|
+ public String delete(HttpServletRequest request, RedirectAttributes redirectAttributes,
|
|
@RequestParam String subjectCode, @RequestParam Integer selectiveIndex) {
|
|
@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);
|
|
@@ -196,7 +235,8 @@ public class SelectiveGroupController extends BaseExamController {
|
|
.findIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
.findIndexByExamIdAndSubjectCode(examId, subjectCode);
|
|
for (SelectiveGroup selectiveGroup : indexGroup) {
|
|
for (SelectiveGroup selectiveGroup : indexGroup) {
|
|
// 选做题分组总分
|
|
// 选做题分组总分
|
|
- totalScore = BigDecimalUtils.add(totalScore, selectiveGroup.getPartScore());
|
|
|
|
|
|
+ totalScore = BigDecimalUtils.add(totalScore,
|
|
|
|
+ selectiveGroup.getPartScore() * selectiveGroup.getSelectiveCount());
|
|
}
|
|
}
|
|
subjectService.updateScore(examId, subjectCode, false, totalScore);
|
|
subjectService.updateScore(examId, subjectCode, false, totalScore);
|
|
} else {
|
|
} else {
|