diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java index c09ac2fcf..5d44c3014 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ExamPaperController.java @@ -1,14 +1,17 @@ package com.ruoyi.exam.controller; -import java.util.ArrayList; -import java.util.Date; +import java.awt.*; +import java.util.*; import java.util.List; -import com.ruoyi.exam.domain.ExamPaperCategory; -import com.ruoyi.exam.domain.ExamQuestion; -import com.ruoyi.exam.domain.ExamQuestionCategory; +import cn.hutool.core.lang.*; +import cn.hutool.json.JSON; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import com.ruoyi.exam.domain.*; import com.ruoyi.exam.service.IExamPaperCategoryService; import com.ruoyi.exam.service.IExamPaperQuestionService; +import com.ruoyi.exam.service.IExamQuestionService; import com.ruoyi.framework.web.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -17,7 +20,6 @@ import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.exam.domain.ExamPaper; import com.ruoyi.exam.service.IExamPaperService; import com.ruoyi.framework.web.base.BaseController; import com.ruoyi.framework.web.page.TableDataInfo; @@ -44,6 +46,9 @@ public class ExamPaperController extends BaseController @Autowired private IExamPaperQuestionService examPaperQuestionService; + + @Autowired + private IExamQuestionService examQuestionService; @RequiresPermissions("exam:examPaper:view") @GetMapping() @@ -119,6 +124,8 @@ public class ExamPaperController extends BaseController { examPaper.setCreateBy(ShiroUtils.getLoginName()); examPaper.setCreateDate(new Date()); + examPaper.setScore(0); + examPaper.setQuestionNumber(0); examPaper.setDelFlag("0"); return toAjax(examPaperService.insert(examPaper)); } @@ -162,21 +169,117 @@ public class ExamPaperController extends BaseController @GetMapping("/addQuestion/{id}") - public String addQuestion(@PathVariable("id") Integer id, ModelMap mmap) + public String addQuestion(@PathVariable("id") String ids, ModelMap mmap) { - mmap.put("examPaperId", id); - mmap.put("examPaperQuestionIds",examPaperQuestionService.selectQuestionIdsForPaperId(id)); + String[] split = ids.split(","); + List strings = Arrays.asList(split); + mmap.put("examPaperId", strings.get(0)); + mmap.put("examPaperQuestionIds",strings.subList(1,strings.size())); return prefix + "/examQuestion"; } - @RequiresPermissions("exam:examPaper:remove") - @Log(title = "试卷", businessType = BusinessType.DELETE) +// @RequiresPermissions("exam:examPaper:add") +// @Log(title = "试卷", businessType = BusinessType.DELETE) @PostMapping( "/saveQuestion") @ResponseBody - public AjaxResult saveQuestion(@RequestParam(value = "questionId[]" ,required = false) String[] questionId,@RequestParam("paperId")String paperId) + public AjaxResult saveQuestion(@RequestBody List paperQuestionList) { - - return toAjax(examPaperQuestionService.saveQuestion(paperId,questionId)); + ExamPaperQuestion examPaperQuestion = paperQuestionList.get(0); + ExamPaperQuestion delete = new ExamPaperQuestion(); + delete.setExamPaperId(examPaperQuestion.getExamPaperId()); + ExamPaper examPaper = new ExamPaper(); + examPaper.setId(examPaperQuestion.getExamPaperId()); + examPaperQuestionService.delete(delete); + int num =0; + int score = 0; + for (int i = 1; i < paperQuestionList.size(); i++) { + ExamPaperQuestion item = paperQuestionList.get(i); + item.setDelFlag("0"); + examPaperQuestionService.insert(item); + num++; + score+=item.getScore(); + } + examPaper.setQuestionNumber(num); + examPaper.setScore(score); + examPaperService.updateSelectiveById(examPaper); + return AjaxResult.success(); + } + + + @GetMapping("/toManagerPaperQuestion/{id}") + public String toManagerPaperQuestion(@PathVariable("id") Integer id, ModelMap mmap) + { + mmap.put("examPaper", examPaperService.selectById(id)); + JSONObject json = new JSONObject(); + List examPaperQuestions = examPaperQuestionService.selectQuestionForPaperId(id); + for (ExamPaperQuestionVO examPaperQuestion : examPaperQuestions) { + //排序用 + json.append(examPaperQuestion.getOrderNum().toString()+examPaperQuestion.getExamQuestionId().toString(),new JSONObject(examPaperQuestion).toString()); + } + mmap.put("examPaperQuestion",json.toString()); + return prefix + "/managerPaperQuestion"; + } + + @RequiresPermissions("exam:examPaper:add") + @Log(title = "试卷", businessType = BusinessType.DELETE) + @PostMapping( "/addQuestionForModel") + @ResponseBody + public AjaxResult addQuestionForModel(@RequestParam(value = "questionId[]" ,required = false) String[] questionId,@RequestParam("paperId")String paperId) + { + //题目数量和总分数 + int questionNum = 0; + int score = 0; + ExamPaperQuestion examPaperQuestion = new ExamPaperQuestion(); + examPaperQuestion.setExamPaperId(Integer.parseInt(paperId)); + ExamPaper examPaper = new ExamPaper(); + if(questionId==null){ + examPaperQuestionService.delete(examPaperQuestion); + examPaper.setId(Integer.parseInt(paperId)); + examPaper.setQuestionNumber(0); + examPaper.setScore(0); + examPaperService.updateSelectiveById(examPaper); + return AjaxResult.success(); + } + List dbDatas = examPaperQuestionService.selectExamPaperQuestionList(examPaperQuestion); + questionNum +=dbDatas.size(); + HashSet dbSet = new HashSet<>(); + for (ExamPaperQuestionVO dbData : dbDatas) { + dbSet.add(dbData.getExamQuestionId()); + score+=dbData.getScore(); + } + + HashSet htmlSet = new HashSet<>(); + //新增的 + for (String s : questionId) { + Integer i = Integer.parseInt(s); + if(!dbSet.contains(i)){ + ExamPaperQuestion insert = new ExamPaperQuestion(); + insert.setExamPaperId(Integer.parseInt(paperId)); + insert.setDelFlag("0"); + insert.setCreateDate(new Date()); + insert.setCreateBy(ShiroUtils.getLoginName()); + insert.setExamQuestionId(i); + insert.setOrderNum(9999); + insert.setScore(0); + examPaperQuestionService.insert(insert); + questionNum++; + } + htmlSet.add(i); + } + + for (ExamPaperQuestionVO dbData : dbDatas) { + if(!htmlSet.contains(dbData.getExamQuestionId())){ + examPaperQuestionService.delete(dbData); + questionNum--; + score-=dbData.getScore(); + } + } + + examPaper.setId(Integer.parseInt(paperId)); + examPaper.setQuestionNumber(questionNum); + examPaper.setScore(score); + examPaperService.updateSelectiveById(examPaper); + + return AjaxResult.success(); } - } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestion.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestion.java index e6de8b5e1..3072c6bca 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestion.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestion.java @@ -35,8 +35,30 @@ private static final long serialVersionUID = 1L; private String remarks; /** 删除标记 */ private String delFlag; - - /** 设置试卷题目ID */ + + private Integer score; + + private Integer orderNum; + + + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + /** 设置试卷题目ID */ public void setId(Integer id) { this.id = id; diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestionVO.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestionVO.java new file mode 100644 index 000000000..9a06a93fe --- /dev/null +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/domain/ExamPaperQuestionVO.java @@ -0,0 +1,27 @@ +package com.ruoyi.exam.domain; + +/** + * Created by flower on 2018/12/23. + */ +public class ExamPaperQuestionVO extends ExamPaperQuestion { + + private Integer questionType; + + private String questionName; + + public Integer getQuestionType() { + return questionType; + } + + public void setQuestionType(Integer questionType) { + this.questionType = questionType; + } + + public String getQuestionName() { + return questionName; + } + + public void setQuestionName(String questionName) { + this.questionName = questionName; + } +} diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/mapper/ExamPaperQuestionMapper.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/mapper/ExamPaperQuestionMapper.java index 4e4d7014e..f34b6fc25 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/mapper/ExamPaperQuestionMapper.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/mapper/ExamPaperQuestionMapper.java @@ -2,6 +2,8 @@ package com.ruoyi.exam.mapper; import com.ruoyi.exam.domain.ExamPaperQuestion; import java.util.List; + +import com.ruoyi.exam.domain.ExamPaperQuestionVO; import com.ruoyi.framework.web.base.MyMapper; /** @@ -19,6 +21,7 @@ public interface ExamPaperQuestionMapper extends MyMapper * @param examPaperQuestion 试卷题目信息 * @return 试卷题目集合 */ - public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); - + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); + + List selectquestionByIds(List ids); } \ No newline at end of file diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamPaperQuestionService.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamPaperQuestionService.java index 3c8fe3b8d..f0f710e0c 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamPaperQuestionService.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamPaperQuestionService.java @@ -2,6 +2,8 @@ package com.ruoyi.exam.service; import com.ruoyi.exam.domain.ExamPaperQuestion; import java.util.List; + +import com.ruoyi.exam.domain.ExamPaperQuestionVO; import com.ruoyi.framework.web.base.AbstractBaseService; /** * 试卷题目 服务层 @@ -17,17 +19,22 @@ public interface IExamPaperQuestionService extends AbstractBaseService selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion); + public List selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion); /** * 查询试卷题目列表 * * @param examPaperQuestion 试卷题目信息 * @return 试卷题目集合 */ - public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion); int saveQuestion(String paperId, String[] questionId); List selectQuestionIdsForPaperId(Integer id); + + List selectQuestionForPaperId(Integer id); + + List selectquestionByIds(List ids); + } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamQuestionService.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamQuestionService.java index c8070081f..bc58175a9 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamQuestionService.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/IExamQuestionService.java @@ -54,4 +54,6 @@ public interface IExamQuestionService extends AbstractBaseService int insertQuestion(ExamQuestion examQuestion, String[] number, String[] content); int updateQuestion(ExamQuestion examQuestion, String[] number, String[] content); + + List selectByIds(List ids); } diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamPaperQuestionServiceImpl.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamPaperQuestionServiceImpl.java index a4f52fe35..029834dee 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamPaperQuestionServiceImpl.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamPaperQuestionServiceImpl.java @@ -4,15 +4,13 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import com.ruoyi.exam.domain.ExamPaper; -import com.ruoyi.exam.mapper.ExamPaperMapper; +import com.ruoyi.exam.domain.ExamPaperQuestionVO; import com.ruoyi.framework.web.util.ShiroUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.exam.mapper.ExamPaperQuestionMapper; import com.ruoyi.exam.domain.ExamPaperQuestion; import com.ruoyi.exam.service.IExamPaperQuestionService; -import com.ruoyi.common.support.Convert; import com.ruoyi.framework.web.base.AbstractBaseServiceImpl; /** * 试卷题目 服务层实现 @@ -35,7 +33,7 @@ public class ExamPaperQuestionServiceImpl extends AbstractBaseServiceImpl selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion) + public List selectExamPaperQuestionList(ExamPaperQuestion examPaperQuestion) { return examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); } @@ -69,15 +67,30 @@ public class ExamPaperQuestionServiceImpl extends AbstractBaseServiceImpl selectQuestionIdsForPaperId(Integer id) { ExamPaperQuestion examPaperQuestion = new ExamPaperQuestion(); examPaperQuestion.setExamPaperId(id); - List examPaperQuestions = examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); + List examPaperQuestions = examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); List ids = new ArrayList<>(); - for (ExamPaperQuestion paperQuestion : examPaperQuestions) { + for (ExamPaperQuestionVO paperQuestion : examPaperQuestions) { ids.add(paperQuestion.getExamQuestionId().toString()); } return ids; } + @Override + public List selectQuestionForPaperId(Integer id) { + ExamPaperQuestion examPaperQuestion = new ExamPaperQuestion(); + examPaperQuestion.setExamPaperId(id); + List examPaperQuestions = examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); + return examPaperQuestions; + } + + @Override + public List selectquestionByIds(List ids) { + return examPaperQuestionMapper.selectquestionByIds(ids); + } + + + /** * 查询试卷题目分页列表 * @@ -85,7 +98,7 @@ public class ExamPaperQuestionServiceImpl extends AbstractBaseServiceImpl selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion) + public List selectExamPaperQuestionPage(ExamPaperQuestion examPaperQuestion) { startPage(); return examPaperQuestionMapper.selectExamPaperQuestionList(examPaperQuestion); diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamQuestionServiceImpl.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamQuestionServiceImpl.java index 94c0b842c..3bd4ff96a 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamQuestionServiceImpl.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/service/impl/ExamQuestionServiceImpl.java @@ -140,4 +140,14 @@ public class ExamQuestionServiceImpl extends AbstractBaseServiceImpl selectByIds(List ids) { + StringBuffer sb = new StringBuffer(); + for (String id : ids) { + sb.append(id+","); + } + String substring = sb.substring(0, sb.length() - 1); + return examQuestionMapper.selectByIds(substring.toString()); + } + } diff --git a/ruoyi-exam/src/main/resources/mapper/exam/ExamPaperQuestionMapper.xml b/ruoyi-exam/src/main/resources/mapper/exam/ExamPaperQuestionMapper.xml index 18e477e97..02489dca7 100644 --- a/ruoyi-exam/src/main/resources/mapper/exam/ExamPaperQuestionMapper.xml +++ b/ruoyi-exam/src/main/resources/mapper/exam/ExamPaperQuestionMapper.xml @@ -1,40 +1,56 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - + + + + + + + + + + + + + + + - - - id, exam_paper_id, exam_question_id, create_by, create_date, update_by, update_date, remarks, del_flag - + + + epq.id, epq.exam_paper_id, epq.exam_question_id, epq.create_by, epq.create_date, epq.update_by, epq.update_date, epq.remarks, epq.del_flag,epq.score,epq.order_num + + - + \ No newline at end of file diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/add.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/add.html index 6750daa8b..4f1af559b 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaper/add.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/add.html @@ -14,12 +14,12 @@ -
- -
- -
-
+ + + + + +
diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/edit.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/edit.html index acaa2e96a..df37f37a9 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaper/edit.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/edit.html @@ -14,12 +14,12 @@
-
- -
- -
-
+ + + + + +
diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html index 5b11cb819..3c20e68a7 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examPaper.html @@ -14,7 +14,7 @@
@@ -121,11 +121,7 @@ title: '名称', sortable: true }, - { - field: 'type', - title: '试卷类型(1-固定试卷;2-随机试卷)', - sortable: true - }, + { field: 'score', title: '总分数', @@ -158,7 +154,7 @@ formatter: function (value, row, index) { var actions = []; actions.push('编辑 '); - actions.push('添加试题 '); + actions.push('管理试题 '); actions.push('删除'); return actions.join(''); } @@ -209,6 +205,10 @@ if(!$.tree.notAllowParents($._tree)){ return ; } + if($("#examPaperCategoryId").val()==1){ + $.modal.alertWarning("请选择试卷分类"); + return; + } var url = prefix + "/add/"+$("#examPaperCategoryId").val(); $.operate.jumpModeltoUrl("添加试卷",url); } @@ -217,6 +217,12 @@ var url = prefix + "/addQuestion/"+id; $.operate.jumpModeltoUrl("添加试题",url,1000,600); } + + + function toPaperquestion(id) { + var url = ctx + "exam/examPaper/toManagerPaperQuestion/"+id; + createMenuItem(url, "试卷题目管理"); + } \ No newline at end of file diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examQuestion.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examQuestion.html index 5122a5ff3..d98f17dc5 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examPaper/examQuestion.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/examQuestion.html @@ -76,11 +76,14 @@ diff --git a/ruoyi-exam/src/main/resources/templates/exam/examPaper/managerPaperQuestion.html b/ruoyi-exam/src/main/resources/templates/exam/examPaper/managerPaperQuestion.html new file mode 100644 index 000000000..0987b72ce --- /dev/null +++ b/ruoyi-exam/src/main/resources/templates/exam/examPaper/managerPaperQuestion.html @@ -0,0 +1,239 @@ + + + + + + + + +
+
+
+
+
+ + + + + +
+ + +
+
+ 设置默认单选题分数: + +
+
+ 设置默认多选题分数: + +
+
+ 设置默认选择题分数: + +
+ +
+ 试卷名称: +
+ +
+ 题目数量: +
+ +
+ 总分数: +
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + +
题目题型分数向上移动向上移动删除
+
+
+
+
+
+
+ + + + + + + diff --git a/ruoyi-exam/src/main/resources/templates/exam/examQuestion/examQuestion.html b/ruoyi-exam/src/main/resources/templates/exam/examQuestion/examQuestion.html index 0300b199a..b80e707b4 100644 --- a/ruoyi-exam/src/main/resources/templates/exam/examQuestion/examQuestion.html +++ b/ruoyi-exam/src/main/resources/templates/exam/examQuestion/examQuestion.html @@ -200,6 +200,10 @@ if(!$.tree.notAllowParents($._tree)){ return ; } + if($("#categoryId").val()==1){ + $.modal.alertWarning("请选择试题分类"); + return; + } var url = prefix + "/choiceadd/"+$("#categoryId").val(); $.operate.jumpModeltoUrl("添加单选题",url); } @@ -208,6 +212,10 @@ if(!$.tree.notAllowParents($._tree)){ return ; } + if($("#categoryId").val()==1){ + $.modal.alertWarning("请选择试题分类"); + return; + } var url = prefix + "/morechoiceadd/"+$("#categoryId").val(); $.operate.jumpModeltoUrl("添加多选题",url); } @@ -216,6 +224,10 @@ if(!$.tree.notAllowParents($._tree)){ return ; } + if($("#categoryId").val()==1){ + $.modal.alertWarning("请选择试题分类"); + return; + } var url = prefix + "/judgeadd/"+$("#categoryId").val(); $.operate.jumpModeltoUrl("添加多选题",url); }