Jelajahi Sumber

feat: 添加了eval考试相关的接口

yhd12345 4 tahun lalu
induk
melakukan
7e5704244f

+ 70 - 0
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/CreateEvalExamVO.java

@@ -0,0 +1,70 @@
+package cn.seecoder.seecoderportalcommon.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+import java.util.List;
+
+public class CreateEvalExamVO {
+
+    private Integer courseId;
+    private String position;
+
+    private Integer creatorId;
+
+    private List<String> skills;
+
+    private Integer difficulty;
+
+    private String startTime;
+
+    private String endTime;
+
+    private String comment;
+
+    private Boolean antiCheating;
+
+    private Boolean isPublic;
+
+    private String examName;
+    public String getExamName() {
+        return examName;
+    }
+
+    public Integer getCourseId() {return courseId;}
+    public String getPosition() {
+        return position;
+    }
+
+    public Integer getCreatorId() {
+        return creatorId;
+    }
+
+    public List<String> getSkills() {
+        return skills;
+    }
+
+    public Integer getDifficulty() {
+        return difficulty;
+    }
+
+    public String getStartTime() {
+        return startTime;
+    }
+
+    public String getEndTime() {
+        return endTime;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public Boolean getAntiCheating() {
+        return antiCheating;
+    }
+
+    public Boolean getIsPublic() {
+        return isPublic;
+    }
+}

+ 7 - 0
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/QuestionScoreMapVO.java

@@ -0,0 +1,7 @@
+package cn.seecoder.seecoderportalcommon.vo;
+
+import java.util.Map;
+
+public class QuestionScoreMapVO {
+    Map<String, Double> questionScoreMap;
+}

+ 19 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/ExamService.java

@@ -1,10 +1,14 @@
 package cn.seecoder.seecoderportalserver.service;
 
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
+import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
+
 public interface ExamService {
     JSONArray findCoderRecommendExams();
 
@@ -74,4 +78,19 @@ public interface ExamService {
 
     JSONObject retrievePageProblem(int page, int limit, String typeStr, String name);
 
+    JSONObject createEvalExam(CreateEvalExamVO createEvalExamVO);
+
+    JSONObject getSampleExamPaperList();
+
+    JSONObject getExamQuestionAndScoreById(Integer examId);
+
+    JSONObject getQuestionById(String id);
+
+    void setExamQuestionsBySampleExamPaper(int examId, int sampleExamPaperId);
+
+    JSONObject getQuestionRecordsOfExamByUserId(Integer examId);
+
+    JSONObject getQuestionList(String stem, List<String> tags, String knowledgeName, int pageSize, int pageNum);
+
+    void updateQuestionsOfExam(Integer examId, QuestionScoreMapVO questionScoreMapVO);
 }

+ 3 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/subsystem/SubsystemService.java

@@ -1,6 +1,8 @@
 package cn.seecoder.seecoderportalserver.service.subsystem;
 
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 
 import java.io.UnsupportedEncodingException;
@@ -21,4 +23,5 @@ public interface SubsystemService {
     JSONObject findTeacherExams(int page, int limit, int state);
 
     JSONObject findStudentExams(int page, int limit, int state);
+
 }

+ 42 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/ExamServiceImpl.java

@@ -1,6 +1,8 @@
 package cn.seecoder.seecoderportalserver.serviceImpl;
 
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
+import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
 import cn.seecoder.seecoderportalserver.service.CourseService;
 import cn.seecoder.seecoderportalserver.service.ExamService;
 import cn.seecoder.seecoderportalserver.serviceImpl.subsystem.CoderService;
@@ -134,6 +136,46 @@ public class ExamServiceImpl implements ExamService {
         return coderService.retrievePageProblem(page, limit, typeStr, name);
     }
 
+    @Override
+    public JSONObject createEvalExam(CreateEvalExamVO createEvalExamVO) {
+        return evalService.createEvalExam(createEvalExamVO);
+    }
+
+    @Override
+    public JSONObject getSampleExamPaperList() {
+        return evalService.getSampleExamPaperList();
+    }
+
+    @Override
+    public JSONObject getExamQuestionAndScoreById(Integer examId) {
+        return evalService.getExamQuestionAndScoreById(examId);
+    }
+
+    @Override
+    public JSONObject getQuestionById(String id) {
+        return evalService.getQuestionById(id);
+    }
+
+    @Override
+    public void setExamQuestionsBySampleExamPaper(int examId, int sampleExamPaperId) {
+        evalService.setExamQuestionsBySampleExamPaper(examId,sampleExamPaperId);
+    }
+
+    @Override
+    public JSONObject getQuestionRecordsOfExamByUserId(Integer examId) {
+        return evalService.getQuestionRecordsOfExamByUserId(examId);
+    }
+
+    @Override
+    public JSONObject getQuestionList(String stem, List<String> tags, String knowledgeName, int pageSize, int pageNum) {
+        return evalService.getQuestionList(stem,tags,knowledgeName,pageSize,pageNum);
+    }
+
+    @Override
+    public void updateQuestionsOfExam(Integer examId, QuestionScoreMapVO questionScoreMapVO) {
+        evalService.updateQuestionsOfExam(examId,questionScoreMapVO);
+    }
+
     @Override
     public JSONObject getResultByExamId(int examId) {
         return coderService.getResultByExamId(examId);

+ 1 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/subsystem/CoderService.java

@@ -1,6 +1,7 @@
 package cn.seecoder.seecoderportalserver.serviceImpl.subsystem;
 
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
 import cn.seecoder.seecoderportalserver.service.HttpService;
 import cn.seecoder.seecoderportalserver.service.subsystem.SubsystemService;
 import com.alibaba.fastjson.JSON;

+ 119 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/subsystem/EvalService.java

@@ -1,9 +1,12 @@
 package cn.seecoder.seecoderportalserver.serviceImpl.subsystem;
 
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
+import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
 import cn.seecoder.seecoderportalserver.service.HttpService;
 import cn.seecoder.seecoderportalserver.service.subsystem.SubsystemService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.http.NameValuePair;
 import org.apache.http.message.BasicNameValuePair;
@@ -97,6 +100,33 @@ public class EvalService implements SubsystemService {
         return null;
     }
 
+
+    public JSONObject createEvalExam(CreateEvalExamVO createEvalExamVO) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/exam";
+//        String uri = "http://localhost:8081/api/exam";
+        String token = httpService.getToken();
+        JSONObject requestBody = new JSONObject();
+        requestBody.put("examName",createEvalExamVO.getExamName());
+        requestBody.put("skills",createEvalExamVO.getSkills());
+        requestBody.put("difficulty",createEvalExamVO.getDifficulty());
+        requestBody.put("startTime",createEvalExamVO.getStartTime());
+        requestBody.put("endTime",createEvalExamVO.getEndTime());
+        requestBody.put("comment",createEvalExamVO.getComment());
+        requestBody.put("antiCheating",createEvalExamVO.getAntiCheating());
+        requestBody.put("isPublic",createEvalExamVO.getIsPublic());
+        requestBody.put("position",createEvalExamVO.getPosition());
+        requestBody.put("courseId",createEvalExamVO.getCourseId());
+        System.out.println(requestBody);
+        String result = null;
+        try {
+            result = httpService.sendPost(uri, requestBody,null, token);
+            System.out.println(result);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
+
     @Override
     public JSONObject findRecommendExamsByCourseId(int courseId) {
         String uri = "https://eval-server.seec.seecoder.cn/api/exam/recommend/" + courseId;
@@ -108,4 +138,93 @@ public class EvalService implements SubsystemService {
         }
         return JSONObject.parseObject(result);
     }
+
+    public JSONObject getSampleExamPaperList() {
+        String uri = "https://eval-server.seec.seecoder.cn/api/question/sample";
+        String result = null;
+        try {
+            result = httpService.sendGet(uri,new ArrayList<>(),null);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return JSONObject.parseObject(result);
+    }
+
+    public JSONObject getExamQuestionAndScoreById(Integer examId) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/exam/" + examId +"/questions";
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, new ArrayList<>(), null);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
+
+    public JSONObject getQuestionById(String id) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/question/" + id;
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, new ArrayList<>(), null);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
+
+    public void setExamQuestionsBySampleExamPaper(int examId, int sampleExamPaperId) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/exam/question/sample/" + examId + "/?sampleExamPaperId=" + sampleExamPaperId;
+        String token = httpService.getToken();
+        try {
+            httpService.sendPost(uri, null,null,token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public JSONObject getQuestionRecordsOfExamByUserId(Integer examId) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/record/all" + "?examId=" + examId;
+        String token = httpService.getToken();
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, new ArrayList<>(), token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
+
+    public JSONObject getQuestionList(String stem, List<String> tags, String knowledgeName, int pageSize, int pageNum) {
+        String params = "";
+        if(stem!=null){
+            params+=("stem=" + stem + "&");
+        }
+        if(tags!=null){
+            params+=("tags=" + tags + "&");
+        }
+        if(knowledgeName!=null){
+            params+=("knowledgeName=" + knowledgeName + "&");
+        }
+        String uri = "https://eval-server.seec.seecoder.cn/api/question/question" + "?" + params + "pageSize=" + pageSize + "&pageNum=" + pageNum;
+        String token = httpService.getToken();
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, new ArrayList<>(), token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
+
+    public void updateQuestionsOfExam(Integer examId, QuestionScoreMapVO questionScoreMapVO) {
+        String uri = "https://eval-server.seec.seecoder.cn/api/exam/" + examId + "/questions/";
+        String token = httpService.getToken();
+        JSONObject requestBody = new JSONObject();
+        requestBody.put("questionScoreMap",questionScoreMapVO);
+        try {
+            httpService.sendPut(uri, requestBody,token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 75 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/ExamController.java

@@ -1,13 +1,19 @@
 package cn.seecoder.seecoderportalserver.web.rest;
 
+import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
+import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
 import cn.seecoder.seecoderportalserver.security.SecurityUtils;
 import cn.seecoder.seecoderportalserver.service.ExamService;
 import cn.seecoder.seecoderportalserver.utility.OkResponse;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+import springfox.documentation.annotations.ApiIgnore;
+
+import java.util.List;
 
 @RestController
 @RequestMapping("/api")
@@ -249,4 +255,73 @@ public class ExamController {
     public OkResponse<JSONArray> findEvalTeacherExamsByCourseId(@RequestParam int courseId) {
         return OkResponse.of(examService.findEvalTeacherExamsByCourseId(courseId));
     }
+
+    /*
+ * @author     :YHD
+ * @description:创建Eval测试接口
+ * @date       :Created in 2022/11/9 15:19
+ **/
+    @PostMapping("/eval/exam/create")
+    public OkResponse<JSONObject> createEvalExam(@RequestBody CreateEvalExamVO examVO){
+        return OkResponse.of(examService.createEvalExam(examVO));
+    }
+
+
+    /*
+ * @author     :YHD
+ * @description:获取所有样卷
+ * @date       :Created in 2022/11/15 11:30
+ **/
+    @ApiOperation("获得所有的固定试卷")
+    @GetMapping("/eval/exam/sample")
+    public OkResponse<JSONObject> getSampleExamPaperList(){
+        return OkResponse.of(examService.getSampleExamPaperList());
+    }
+
+    @ApiOperation("根据考试id获得对应考试的题目")
+    @GetMapping("/eval/exam/{examId}/questions")
+    public OkResponse<JSONObject> getExamQuestionAndScoreById(@PathVariable Integer examId) {
+        return OkResponse.of(examService.getExamQuestionAndScoreById(examId));
+    }
+
+    @ApiOperation("根据Id获得题目的全部信息,包括解答")
+    @GetMapping("/eval/questions/{id}")
+    public OkResponse<JSONObject> getQuestionById(@PathVariable String id) {
+        return OkResponse.of(examService.getQuestionById(id));
+    }
+
+    @ApiOperation("为创建的考试通过样卷来设置题目")
+    @PostMapping("/eval/exam/question/sample/{examId}/")
+    public OkResponse<JSONObject> setExamQuestionsBySampleExamPaper(@PathVariable int examId,
+                                                      @RequestParam(value = "sampleExamPaperId") int sampleExamPaperId) {
+        examService.setExamQuestionsBySampleExamPaper(examId, sampleExamPaperId);
+        return OkResponse.of(null);
+    }
+
+    @ApiOperation("获得某次考试某个同学所有提交记录")
+    @GetMapping("/eval/exam/record/all")
+    public OkResponse<JSONObject> getQuestionRecordsOfExamByUserId(@RequestParam(value = "examId") Integer examId) {
+        return OkResponse.of(examService.getQuestionRecordsOfExamByUserId(examId));
+    }
+
+    @ApiOperation("根据题干,知识点,获得题目")
+    @GetMapping("/eval/exam/question")
+    public OkResponse<JSONObject> getQuestionList(@RequestParam(value = "stem", required = false) String stem,
+                                    @RequestParam(value = "tags", required = false) List<String> tags,
+                                    @RequestParam(value = "knowledgeName", required = false) String knowledgeName,
+                                    @RequestParam(value = "pageSize") int pageSize,
+                                    @RequestParam(value = "pageNum") int pageNum
+    ) {
+        return OkResponse.of(examService.getQuestionList(stem, tags, knowledgeName, pageSize, pageNum));
+    }
+
+
+    @ApiOperation("为考试更新题目及对应分值")
+    @PutMapping("/eval/exam/{examId}/questions/")
+    public OkResponse<JSONObject> updateQuestionsOfExam(@PathVariable Integer examId,
+                                          @RequestBody QuestionScoreMapVO questionScoreMapVO) {
+        examService.updateQuestionsOfExam(examId, questionScoreMapVO);
+        return OkResponse.of(null);
+    }
+
 }