2025年3月20日16:16:40
parent
de8bc9b718
commit
8d3cea76e1
6
pom.xml
6
pom.xml
|
|
@ -65,7 +65,11 @@
|
|||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.52</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.zhangmeng.online.exam.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.util.JSONPObject;
|
||||
import com.zhangmeng.online.exam.dao.PaperDao;
|
||||
import com.zhangmeng.online.exam.dao.QuestionDao;
|
||||
import com.zhangmeng.online.exam.dto.Result;
|
||||
import com.zhangmeng.online.exam.entity.Paper;
|
||||
import com.zhangmeng.online.exam.entity.Question;
|
||||
import com.zhangmeng.online.exam.entity.User;
|
||||
import com.zhangmeng.online.exam.utils.PageUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -13,10 +17,7 @@ import org.springframework.data.domain.Sort;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
|
|
@ -31,6 +32,9 @@ public class PaperController {
|
|||
@Autowired
|
||||
private PaperDao paperDao;
|
||||
|
||||
@Autowired
|
||||
private QuestionDao questionDao;
|
||||
|
||||
@RequestMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize) {
|
||||
|
||||
|
|
@ -44,11 +48,49 @@ public class PaperController {
|
|||
map.put("name", paper.getName());
|
||||
map.put("creator_username", paper.getCreator().getUsername());
|
||||
map.put("subject_name", paper.getSubject().getName());
|
||||
map.put("totalScore",paper.getTotalScore());//总分
|
||||
map.put("examTime",paper.getExamTime());//考试时间
|
||||
map.put("totalScore", paper.getTotalScore());//总分
|
||||
map.put("examTime", paper.getExamTime());//考试时间
|
||||
resultList.add(map);
|
||||
}
|
||||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||
}
|
||||
|
||||
@RequestMapping("/chooseQuestion/save")
|
||||
public Result chooseQuestionSave(String id, String ids) {
|
||||
|
||||
Optional<Paper> paperOptional = paperDao.findById(Long.valueOf(id));
|
||||
if (!paperOptional.isPresent()){
|
||||
return Result.error("试卷不存在");
|
||||
}
|
||||
Paper paper = paperOptional.get();
|
||||
for (String questionId : JSONObject.parseArray(ids, String.class)) {
|
||||
Optional<Question> question = this.questionDao.findById(Long.valueOf(questionId));
|
||||
if (question.isPresent()){
|
||||
paper.getQuestions().add(question.get());
|
||||
}
|
||||
}
|
||||
paperDao.save(paper);
|
||||
return Result.success(null);
|
||||
}
|
||||
|
||||
@RequestMapping("/chooseQuestion/list")
|
||||
public Result chooseQuestionList(String id) {
|
||||
Optional<Paper> paperOptional = paperDao.findById(Long.valueOf(id));
|
||||
if (!paperOptional.isPresent()){
|
||||
return Result.error("试卷不存在");
|
||||
}
|
||||
Paper paper = paperOptional.get();
|
||||
List<Question> questions = paper.getQuestions();
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
for (Question question : questions) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", question.getId());
|
||||
map.put("name", question.getName());
|
||||
map.put("type", question.getType().getDesc());
|
||||
map.put("subject", question.getSubject().getName());
|
||||
map.put("score", question.getScore());
|
||||
resultList.add(map);
|
||||
}
|
||||
return Result.success(resultList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class QuestionController {
|
|||
map.put("name", question.getName());
|
||||
map.put("type", question.getType().getDesc());
|
||||
map.put("subject", question.getSubject().getName());
|
||||
map.put("score", question.getScore());
|
||||
resultList.add(map);
|
||||
}
|
||||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ public class Result {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.setCode(ERROR);
|
||||
result.setMessage(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class Question extends BaseEntity<Long> {
|
|||
MULTIPLE_CHOICE("多选题", 1),//多选题
|
||||
JUDGMENT("判断题", 2),//判断题
|
||||
SHORT_ANSWER("简答题", 3),//简答题
|
||||
TRUE_OR_FALSE("判断题",4),//判断题
|
||||
Fill_IN_THE_BLANKS("填空题", 4),//填空题
|
||||
NUMERICAL("计算题",5);//计算题
|
||||
|
||||
private String desc;
|
||||
|
|
@ -63,6 +63,10 @@ public class Question extends BaseEntity<Long> {
|
|||
|
||||
private Type type;
|
||||
|
||||
private Integer score;//分值
|
||||
|
||||
private String explanation;//问题解析
|
||||
|
||||
@OneToMany(mappedBy = "question")
|
||||
private List<QuestionOption> options = new ArrayList<>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue