From 18f84d24f3ba28a80cb75636d49c012f5324dd85 Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Thu, 4 May 2023 17:59:14 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E6=B7=BB=E5=8A=A0=E8=AF=95=E5=8D=B7=E5=92=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=95=E9=A2=98=E7=AD=94=E6=A1=88=E7=9A=84=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=B3=A8=E9=87=8A=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?Answervo=E7=B1=BB=E7=94=A8=E4=BA=8E=E5=A4=9A=E9=80=89=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E7=AD=94=E6=A1=88=E7=9A=84=E6=B7=BB=E5=8A=A0=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86Question=E5=92=8CQuestionVo=E7=9A=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=B3=A8=E9=87=8A=E5=92=8C=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lyt/bean/Course.java | 5 ++ src/main/java/com/lyt/bean/Paper.java | 9 ++-- src/main/java/com/lyt/bean/PaperQuestion.java | 8 ++- src/main/java/com/lyt/bean/Question.java | 12 +++-- .../com/lyt/controller/PaperController.java | 10 +++- .../lyt/controller/QuestionController.java | 25 ++++++--- src/main/java/com/lyt/dao/CourseDao.java | 5 ++ src/main/java/com/lyt/dao/PaperDao.java | 5 ++ src/main/java/com/lyt/dao/QuestionDao.java | 8 ++- .../java/com/lyt/service/CourseService.java | 5 ++ .../java/com/lyt/service/PaperService.java | 52 ++++++++++++++----- .../java/com/lyt/service/QuestionService.java | 24 ++++++--- src/main/java/com/lyt/vo/Answervo.java | 12 +++++ src/main/java/com/lyt/vo/ItemVo.java | 4 +- src/main/java/com/lyt/vo/PaperVo.java | 6 +-- src/main/java/com/lyt/vo/QuestionVo.java | 10 ++-- src/main/java/com/lyt/vo/QuestionsVo.java | 4 +- src/main/resources/application.yml | 4 +- 18 files changed, 146 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/lyt/vo/Answervo.java diff --git a/src/main/java/com/lyt/bean/Course.java b/src/main/java/com/lyt/bean/Course.java index 17a3542..bdf54f8 100644 --- a/src/main/java/com/lyt/bean/Course.java +++ b/src/main/java/com/lyt/bean/Course.java @@ -3,6 +3,11 @@ package com.lyt.bean; import lombok.AllArgsConstructor; import lombok.Data; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: 课程 + */ //课程类 @Data @AllArgsConstructor diff --git a/src/main/java/com/lyt/bean/Paper.java b/src/main/java/com/lyt/bean/Paper.java index 9c396ae..cca7df2 100644 --- a/src/main/java/com/lyt/bean/Paper.java +++ b/src/main/java/com/lyt/bean/Paper.java @@ -1,15 +1,18 @@ package com.lyt.bean; -import lombok.AllArgsConstructor; import lombok.Data; -import java.util.List; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: 试卷 + */ @Data //试卷类 public class Paper { private Integer paperId;//试卷编号 private String paperName;//试卷名字 - private String score;//分数 + private Integer score;//分数 2023/5/4/zjx private Integer courseId;//课程编号 private String course;//课程 // private int paperType; diff --git a/src/main/java/com/lyt/bean/PaperQuestion.java b/src/main/java/com/lyt/bean/PaperQuestion.java index f659bca..42ccead 100644 --- a/src/main/java/com/lyt/bean/PaperQuestion.java +++ b/src/main/java/com/lyt/bean/PaperQuestion.java @@ -1,13 +1,11 @@ package com.lyt.bean; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; /** * @Author: zjx - * @Date: 2023/04/09/20:03 - * @Description: + * @Date: 2023/04/27/20:03 + * @Description: 试卷和试题关系 */ @Data @AllArgsConstructor diff --git a/src/main/java/com/lyt/bean/Question.java b/src/main/java/com/lyt/bean/Question.java index 556e724..884387b 100644 --- a/src/main/java/com/lyt/bean/Question.java +++ b/src/main/java/com/lyt/bean/Question.java @@ -1,9 +1,11 @@ package com.lyt.bean; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - +import lombok.*; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: 试题 + */ //试题类 @Data @AllArgsConstructor @@ -12,7 +14,7 @@ public class Question { private Integer questionId;//试题编号 private String questionName;//试题名 - private Integer type;//试卷类型,0单选题,1多选题,2判断题,3问答题 + private Integer type;//试卷类型,1单选题,2多选题,3问答题,4判断题 private String courseId;//课程编号 private String content; // 试题内容 最后需要将这个json串转换为 options diff --git a/src/main/java/com/lyt/controller/PaperController.java b/src/main/java/com/lyt/controller/PaperController.java index d21b0bc..887516e 100644 --- a/src/main/java/com/lyt/controller/PaperController.java +++ b/src/main/java/com/lyt/controller/PaperController.java @@ -10,10 +10,16 @@ import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @RestController @CrossOrigin public class PaperController { + + //添加试卷,lyt @Autowired PaperService paperService; @RequestMapping("/edit/paper") @@ -23,7 +29,7 @@ public class PaperController { return "okkkk"; } - + //根据试卷编号获取试卷,lyt @RequestMapping("/get/paper") public PaperVo getPaper(@Param("id") Integer id){ PaperVo paperVo = paperService.getPaperById(id); diff --git a/src/main/java/com/lyt/controller/QuestionController.java b/src/main/java/com/lyt/controller/QuestionController.java index 23b31fa..4d26982 100644 --- a/src/main/java/com/lyt/controller/QuestionController.java +++ b/src/main/java/com/lyt/controller/QuestionController.java @@ -7,20 +7,21 @@ import com.lyt.service.QuestionService; import com.lyt.vo.QuestionVo; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; - +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @RestController @CrossOrigin public class QuestionController { @Autowired QuestionService questionService; - @RequestMapping("/question/edit") + @RequestMapping("/question/edit")//添加试题 public String addQuestion(@RequestBody QuestionVo questionVo)throws Exception{ // System.out.println(questionVo); questionService.addQuestion(questionVo); @@ -29,14 +30,15 @@ public class QuestionController { return "ok"; } - @RequestMapping("/question/get") + @RequestMapping("/question/get")//查询所有试题 public List getQuestionList()throws Exception{ // System.out.println(questionVo); // questionService.addQuestion(questionVo); return questionService.getAllQuestion(); } - @RequestMapping("/question/id") + + @RequestMapping("/question/id")//根据id查询试题 public QuestionVo getQuestionListById(@Param("id") Integer id)throws Exception{ // System.out.println(questionVo); @@ -51,4 +53,11 @@ public class QuestionController { // questionService.addQuestion(questionVo); return questionService.questionList(); } + + //zjx + @RequestMapping("/question/delete/{id}") + public String deleteQuestion(@PathVariable("id") Integer id)throws Exception{ + questionService.deleteQuestion(id); + return "ok"; + } } diff --git a/src/main/java/com/lyt/dao/CourseDao.java b/src/main/java/com/lyt/dao/CourseDao.java index 01b6f49..31cdec9 100644 --- a/src/main/java/com/lyt/dao/CourseDao.java +++ b/src/main/java/com/lyt/dao/CourseDao.java @@ -5,6 +5,11 @@ import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Repository public interface CourseDao { @Select("select * from course") diff --git a/src/main/java/com/lyt/dao/PaperDao.java b/src/main/java/com/lyt/dao/PaperDao.java index 7cb71b0..c1054fb 100644 --- a/src/main/java/com/lyt/dao/PaperDao.java +++ b/src/main/java/com/lyt/dao/PaperDao.java @@ -7,6 +7,11 @@ import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Repository public interface PaperDao { diff --git a/src/main/java/com/lyt/dao/QuestionDao.java b/src/main/java/com/lyt/dao/QuestionDao.java index 6febf7b..dd7242b 100644 --- a/src/main/java/com/lyt/dao/QuestionDao.java +++ b/src/main/java/com/lyt/dao/QuestionDao.java @@ -6,13 +6,19 @@ import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Repository public interface QuestionDao { @Select("select * from paper_question where paper_id =#{id}") public List getPaperQuestionById(int id); + @Select("select * from question where question_id =#{id}") - public Question getQuestionById( int id); + public Question getQuestionById(int id); @Select("select question_id,question_name,type from question ") public List getQuestionList(); diff --git a/src/main/java/com/lyt/service/CourseService.java b/src/main/java/com/lyt/service/CourseService.java index 240d1f1..5ca2199 100644 --- a/src/main/java/com/lyt/service/CourseService.java +++ b/src/main/java/com/lyt/service/CourseService.java @@ -6,6 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Service public class CourseService { diff --git a/src/main/java/com/lyt/service/PaperService.java b/src/main/java/com/lyt/service/PaperService.java index 81d8ff1..360a67a 100644 --- a/src/main/java/com/lyt/service/PaperService.java +++ b/src/main/java/com/lyt/service/PaperService.java @@ -19,7 +19,11 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; - +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Service public class PaperService { @Autowired @@ -111,14 +115,19 @@ public class PaperService { public int addPaper(PaperVo paperVo){ Paper paper = new Paper(); - BeanUtil.beanConvert(paperVo,paper); + BeanUtil.beanConvert(paperVo,paper);//将paperVo转为paper //先写paper表 // TODO: 2023/5/2 还有很多逻辑需要处理 例如 one two three - + // TODO: 2023/5/4 完成 one two three 和 score逻辑 //因为id是自增的 取数据库中最大id然后+1即可 ,但是这样处理存在并发风险 int newId = paperDao.getPaperMaxId()+1; + int one = 0;//记录选择题数量 + int two = 0;//记录判断题数量 + int three = 0;//记录问答题数量 + int score = 0;//记录试卷总分分数 paper.setPaperId(newId); //这个是自增的 + paper.setStatus(0);//试卷状态初始化为0(zjx) System.out.println("转换后的paper "+paper); //处理 titleContent @@ -129,29 +138,48 @@ public class PaperService { for (int i = 0; i < titleItems.size(); i++) { QuestionsVo titleItem = titleItems.get(i); TitleContent titleContent = new TitleContent(); - titleContent.setTitleName(titleItem.getQuestionName()); - titleContent.setSort(i); + titleContent.setTitleName(titleItem.getQuestionName());//大题名字 + titleContent.setSort(i);//大题编号 titleContents.add(titleContent); } - String titleContentJson = JSON.toJSONString(titleContents); + String titleContentJson = JSON.toJSONString(titleContents);//转为json格式 paper.setTitleContent(titleContentJson); - paperDao.addPaper(paper); +// paperDao.addPaper(paper);//zjx //再写试卷 -- 题目关系表 List paperQuestions = new ArrayList<>(); //建立 试卷 试题关系映射 - for (QuestionsVo titleItem : paperVo.getTitleItems()) { - for (QuestionVo questionItem : titleItem.getQuestionItems()) { - int questionId = questionItem.getQuestionId(); - PaperQuestion paperQuestion = new PaperQuestion(); + for (QuestionsVo titleItem : paperVo.getTitleItems()) {//遍历大题 + for (QuestionVo questionItem : titleItem.getQuestionItems()) {//遍历大题中的小题 + int questionId = questionItem.getQuestionId();//获取小题中的id + PaperQuestion paperQuestion = new PaperQuestion();//创建一个试卷试题关联对象 //设置paperId paperQuestion.setPaperId(paper.getPaperId()); // 设置questionId paperQuestion.setQuestionId(questionId); - paperQuestions.add(paperQuestion); + //zjx + int type = questionDao.getQuestionById(questionId).getType(); + if (type == 1 || type == 2){ + one++; + }else if (type == 4){ + two++; + }else if (type == 3){ + three++; + } + score = score + questionDao.getQuestionById(questionId).getScore(); + + paperQuestions.add(paperQuestion);//添加关联 } } + + //zjx + paper.setOne(one); + paper.setTwo(two); + paper.setThree(three); + paper.setScore(score); + paperDao.addPaper(paper); + System.out.println("打印一下 paperQuestion "+paperQuestions); for (PaperQuestion paperQuestion : paperQuestions) { diff --git a/src/main/java/com/lyt/service/QuestionService.java b/src/main/java/com/lyt/service/QuestionService.java index 9d9cc1f..637a85e 100644 --- a/src/main/java/com/lyt/service/QuestionService.java +++ b/src/main/java/com/lyt/service/QuestionService.java @@ -11,7 +11,11 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; - +/** + * @Author: zjx + * @Date: 2023/04/27/20:03 + * @Description: + */ @Service public class QuestionService { @Autowired @@ -22,7 +26,7 @@ public class QuestionService { System.out.println("查询到的question"+question); QuestionVo questionVo = new QuestionVo(); - BeanUtil.beanConvert(question,questionVo); + BeanUtil.beanConvert(question,questionVo);//将questionVo转换为question List items = (List) JSON.parse(question.getContent()); questionVo.setItems(items); return questionVo; @@ -32,7 +36,7 @@ public class QuestionService { List questions = questionDao.getAllQuestion(); List questionVos = new ArrayList<>(); for (Question question : questions) { - QuestionVo questionVo = new QuestionVo(); + QuestionVo questionVo = new QuestionVo(); BeanUtil.beanConvert(question,questionVo); List items = (List) JSON.parse(question.getContent()); questionVo.setItems(items); @@ -53,13 +57,19 @@ public class QuestionService { public int addQuestion(QuestionVo questionVo){ System.out.println("执行 addQuestion"); Question question = new Question(); - - Question newQuestion = BeanUtil.beanConvert(questionVo,question); + Question newQuestion = BeanUtil.beanConvert(questionVo,question);//将questionVo转换为question String contentJson = JSON.toJSONString(questionVo.getItems()); + System.out.println("选项的json串"+contentJson); newQuestion.setContent(contentJson); System.out.println("这是新创建的 对象"+ newQuestion); + //zjx + if (newQuestion.getType() == 2){ + String answerJson = JSON.toJSONString(questionVo.getAnswervos()); + newQuestion.setAnswer(answerJson); + } + //将选项转换为 json 串 int num = questionDao.addQuestion(newQuestion); if(num >0){ @@ -67,9 +77,7 @@ public class QuestionService { return 1; } return 0; - };//创建试卷 - - + };//创建试题 public List getAllByCourseQuestion(int courseId){ return questionDao.getAllByCourseQuestion(courseId); diff --git a/src/main/java/com/lyt/vo/Answervo.java b/src/main/java/com/lyt/vo/Answervo.java new file mode 100644 index 0000000..adb18b0 --- /dev/null +++ b/src/main/java/com/lyt/vo/Answervo.java @@ -0,0 +1,12 @@ +package com.lyt.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Answervo { + private String prefix; +} diff --git a/src/main/java/com/lyt/vo/ItemVo.java b/src/main/java/com/lyt/vo/ItemVo.java index cdf4e05..0da556c 100644 --- a/src/main/java/com/lyt/vo/ItemVo.java +++ b/src/main/java/com/lyt/vo/ItemVo.java @@ -1,8 +1,6 @@ package com.lyt.vo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; /** * @Author: lyt diff --git a/src/main/java/com/lyt/vo/PaperVo.java b/src/main/java/com/lyt/vo/PaperVo.java index 9386955..6e60770 100644 --- a/src/main/java/com/lyt/vo/PaperVo.java +++ b/src/main/java/com/lyt/vo/PaperVo.java @@ -1,9 +1,7 @@ package com.lyt.vo; import com.lyt.bean.OnlineExam.Question; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.List; @@ -26,7 +24,7 @@ public class PaperVo { private String paperName;//试卷名字 private String suggestTime; private Integer status;//试卷状态 - private String score;//试卷总分分数 + private Integer score;//试卷总分分数 private List titleItems; //大题 // private String limitTime; // diff --git a/src/main/java/com/lyt/vo/QuestionVo.java b/src/main/java/com/lyt/vo/QuestionVo.java index 312c9fb..9b2e837 100644 --- a/src/main/java/com/lyt/vo/QuestionVo.java +++ b/src/main/java/com/lyt/vo/QuestionVo.java @@ -1,8 +1,6 @@ package com.lyt.vo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.List; @@ -19,15 +17,15 @@ public class QuestionVo { private int gradeLevel; //班级 private String courseId; //subjectId; private String questionName; // (title)标题:例如第一题。。。 - private Integer type; //试卷类型,0单选题,1多选题,2判断题,3问答题 + private Integer type; //试卷类型,1单选题,2多选题,3问答题, 4判断题 zjx private String detail; //详细解答 private String answer; //答案 - private Integer score; //总分 + private Integer score; //总分 zjx private String difficult; //难度 private Integer userId;//用户编号 private String time;//创建时间 List items; //选择题选项 后面会转换成json - + List answervos; //多选题答案 } diff --git a/src/main/java/com/lyt/vo/QuestionsVo.java b/src/main/java/com/lyt/vo/QuestionsVo.java index 6ba93e5..692f179 100644 --- a/src/main/java/com/lyt/vo/QuestionsVo.java +++ b/src/main/java/com/lyt/vo/QuestionsVo.java @@ -1,8 +1,6 @@ package com.lyt.vo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import java.util.List; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 580cb45..f35df98 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,9 +4,9 @@ spring: datasource: #MySQL配置 driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/onlineexamsystem?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC + url: jdbc:mysql://localhost:3306/onlineexamsystem?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC username: root - password: root + password: z075722271630 mybatis: mapper-locations: classpath:mapper/*.xml -- Gitee From b72058edab0597b05c16f4c971479502dd9ded4b Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Fri, 5 May 2023 15:09:57 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=BB=84=E5=8D=B7=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AAmaven=E4=BE=9D=E8=B5=96=EF=BC=88huto?= =?UTF-8?q?ol=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=89=EF=BC=8C=E5=9C=A8PaperVo?= =?UTF-8?q?=E7=B1=BB=E4=B8=AD=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=90=84=E7=B1=BB?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +- .../com/lyt/controller/PaperController.java | 21 ++++ .../java/com/lyt/service/PaperService.java | 112 ++++++++++++++++++ src/main/java/com/lyt/vo/PaperVo.java | 3 + 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c4adc0d..d86132b 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,12 @@ 4.7 - + + + cn.hutool + hutool-all + 4.5.16 + diff --git a/src/main/java/com/lyt/controller/PaperController.java b/src/main/java/com/lyt/controller/PaperController.java index 887516e..af81c3e 100644 --- a/src/main/java/com/lyt/controller/PaperController.java +++ b/src/main/java/com/lyt/controller/PaperController.java @@ -29,10 +29,31 @@ public class PaperController { return "okkkk"; } + //自动添加试卷,zjx + @RequestMapping("/addPaperAut") + public String addPaperAut(@RequestBody PaperVo paperVo ){ + int i = paperService.addPaperAut(paperVo); + if (i == 2){ + return "选择题数量不足"; + }else if (i == 3){ + return "判断题数量不足"; + }else if (i == 4){ + return "问答题数量不足"; + } + return "okkkk"; + } + //根据试卷编号获取试卷,lyt @RequestMapping("/get/paper") public PaperVo getPaper(@Param("id") Integer id){ PaperVo paperVo = paperService.getPaperById(id); return paperVo; } + + //根据试卷编号删除试卷,zjx + @RequestMapping("/paper/delete/id") + public String deletePaper(@Param("id") Integer id){ + paperService.deletePaper(id); + return "ok"; + } } diff --git a/src/main/java/com/lyt/service/PaperService.java b/src/main/java/com/lyt/service/PaperService.java index 360a67a..42dafec 100644 --- a/src/main/java/com/lyt/service/PaperService.java +++ b/src/main/java/com/lyt/service/PaperService.java @@ -1,5 +1,6 @@ package com.lyt.service; +import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.lyt.bean.Paper; @@ -17,8 +18,12 @@ import org.apache.ibatis.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.rmi.server.ServerCloneException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import cn.hutool.core.util.RandomUtil; + /** * @Author: zjx * @Date: 2023/04/27/20:03 @@ -189,6 +194,113 @@ public class PaperService { return 1; };//创建试卷 + + //自动添加大题封装,zjx 2023/5/5 + private void settitleContents(int paperquestionSize,List titleContents,String TitleName,int Sort){ + if (paperquestionSize > 0){ + TitleContent titleContent = new TitleContent(); + titleContent.setTitleName(TitleName); + titleContent.setSort(Sort); + titleContents.add(titleContent); + } + } + + //试卷和试题关联关系封装方法,zjx 2023/5/5 + private int getPaperQuestion(int questionSize,int paperquestionSize,List source,int paperId,List paperQuestions){ + int score = 0; + List typeRandomList = getEleList(questionSize,paperquestionSize); + for (Integer index : typeRandomList){ + Question question = source.get(index);//在各题目数组中取 + score = score + question.getScore(); + PaperQuestion paperQuestion = new PaperQuestion(); + paperQuestion.setPaperId(paperId); + paperQuestion.setQuestionId(question.getQuestionId()); + paperQuestions.add(paperQuestion); + } + return score; + } + + //不重复随机数,zjx 2023/5/5 + private List getEleList(int sourceSize,int resultSize){ + List list = CollUtil.newArrayList(); + for (int i = 0; i < sourceSize ;i++){ + list.add(i); + } + return RandomUtil.randomEles(list,resultSize); + } + + + //zjx 2023/5/5 自动组卷 + public int addPaperAut(PaperVo paperVo){ + Paper paper = new Paper(); + BeanUtil.beanConvert(paperVo,paper);//将paperVo转为paper + + //因为id是自增的 取数据库中最大id然后+1即可 ,但是这样处理存在并发风险 + int newId = paperDao.getPaperMaxId()+1; + int score = 0;//记录试卷总分分数 + paper.setPaperId(newId); //这个是自增的 + paper.setStatus(0);//试卷状态初始化为0 + //首先根据课程编号获取所有试题 + List questions = questionDao.getAllByCourseQuestion(paper.getCourseId()); + //根据题目类型查询所有题目,将各类题目放入到数组中,重新排序 + //选择 + List type1list = questions.stream().filter(question -> question.getType().equals(1) || question.getType().equals(2)).collect(Collectors.toList()); + //判断 + List type2list = questions.stream().filter(question -> question.getType().equals(4)).collect(Collectors.toList()); + //问答 + List type3list = questions.stream().filter(question -> question.getType().equals(3)).collect(Collectors.toList()); + System.out.println("转换后的paper "+paper); + + if ( type1list.size() < paper.getOne()){ + System.out.println("选择题数量不足"); + return 2; + } + if ( type2list.size() < paper.getTwo()){ + System.out.println("判断题数量不足"); + return 3; + } + if ( type3list.size() < paper.getThree()){ + System.out.println("问答题数量不足"); + return 4; + } + + List paperQuestions = new ArrayList<>();//存放试卷和试题关系集合 + + //开始自动组卷 + //从选择题中随机抽取指定数量的题目放入到paperQuestions集合,平且获取各大题分数 + int score1 = getPaperQuestion(type1list.size(),paper.getOne(),type1list,paper.getPaperId(),paperQuestions); + //从判断题中随机抽取指定数量的题目放入到paperQuestions集合 + int score2 = getPaperQuestion(type2list.size(),paper.getTwo(),type2list,paper.getPaperId(),paperQuestions); + //从问答题中随机抽取指定数量的题目放入到paperQuestions集合 + int score3 = getPaperQuestion(type3list.size(),paper.getThree(),type3list,paper.getPaperId(),paperQuestions); + + //总分 + score = score1 + score2 + score3; + + System.out.println("打印一下 paperQuestion "+paperQuestions); + for (PaperQuestion paperQuestion : paperQuestions) { + paperDao.addPaperQuestion(paperQuestion);//添加试卷试题关联关系 + } + + //处理 titleContent + List titleContents = new ArrayList<>(); + + //如果选择题数量大于0,自动创建选择大题 + settitleContents(paper.getOne(),titleContents,"选择题",0); + //如果判断题数量大于0,自动创建判断题大题 + settitleContents(paper.getTwo(),titleContents,"判断题",1); + //如果问答题数量大于0,自动创建问答题大题 + settitleContents(paper.getThree(),titleContents,"问答题",2); + + String titleContentJson = JSON.toJSONString(titleContents);//转为json格式 + paper.setTitleContent(titleContentJson); + + paper.setScore(score); + paperDao.addPaper(paper); + + return 1; + };//自动创建试卷 + public List getAllByCoursePaper(int courseId){ return paperDao.getAllByCoursePaper(courseId); };//根据课程获取所有试卷中的试题 diff --git a/src/main/java/com/lyt/vo/PaperVo.java b/src/main/java/com/lyt/vo/PaperVo.java index 6e60770..329ca41 100644 --- a/src/main/java/com/lyt/vo/PaperVo.java +++ b/src/main/java/com/lyt/vo/PaperVo.java @@ -20,6 +20,9 @@ public class PaperVo { private int paperType; //试卷类型 ab卷? private Integer grade;//试卷年级 private Integer courseId;//课程编号 + private Integer one;//选择题 + private Integer two;//判断题 + private Integer three;//问答题 private String paperName;//试卷名字 private String suggestTime; -- Gitee From bafaa5271d0ccaa8328aee92637fb1e57e456158 Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Mon, 8 May 2023 16:31:00 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=AF=95?= =?UTF-8?q?=E9=A2=98=E5=88=A0=E9=99=A4=EF=BC=8C=E8=AF=BE=E7=A8=8B=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E6=A0=B9=E6=8D=AE=E8=AF=95=E9=A2=98=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E3=80=82=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E8=AF=95=E9=A2=98=E6=B7=BB=E5=8A=A0=E5=92=8C=E8=AF=95?= =?UTF-8?q?=E5=8D=B7=E6=B7=BB=E5=8A=A0=E4=B8=9A=E5=8A=A1=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E4=BA=86=E6=97=B6=E9=97=B4=E7=9A=84=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lyt/controller/CourseContoller.java | 24 ++++++++++ .../lyt/controller/QuestionController.java | 17 +++++-- src/main/java/com/lyt/dao/QuestionDao.java | 3 ++ .../java/com/lyt/service/PaperService.java | 15 ++++++ .../java/com/lyt/service/QuestionService.java | 47 ++++++++++++++----- 5 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/lyt/controller/CourseContoller.java diff --git a/src/main/java/com/lyt/controller/CourseContoller.java b/src/main/java/com/lyt/controller/CourseContoller.java new file mode 100644 index 0000000..b72e0e3 --- /dev/null +++ b/src/main/java/com/lyt/controller/CourseContoller.java @@ -0,0 +1,24 @@ +package com.lyt.controller; + +import com.lyt.bean.Course; +import com.lyt.service.CourseService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class CourseContoller { + + @Autowired + CourseService courseService; + + @RequestMapping("/course/get") + public List getAllCourse(){ + return courseService.getAllCourse(); + } + // public String getAllCourse(){ +// return JSON.toJSONString(courseService.getAllCourse()); +// } +} diff --git a/src/main/java/com/lyt/controller/QuestionController.java b/src/main/java/com/lyt/controller/QuestionController.java index 4d26982..fac4251 100644 --- a/src/main/java/com/lyt/controller/QuestionController.java +++ b/src/main/java/com/lyt/controller/QuestionController.java @@ -56,8 +56,19 @@ public class QuestionController { //zjx @RequestMapping("/question/delete/{id}") - public String deleteQuestion(@PathVariable("id") Integer id)throws Exception{ - questionService.deleteQuestion(id); - return "ok"; + public int deleteQuestion(@PathVariable("id") Integer id)throws Exception{ + return questionService.deleteQuestion(id); + } + + //zjx 5/7 + @RequestMapping("/question/courseId")//根据课程Id查询试题 + public List getAllByCourseQuestion(@Param("courseId") Integer courseId)throws Exception{ + return questionService.getAllByCourseQuestion(courseId); + } + + //zjx 5/7 + @RequestMapping("/question/type")//根据课程Id查询试题 + public List getAllBytypeuestion(@Param("type") Integer type)throws Exception{ + return questionService.getAllBytypeuestion(type); } } diff --git a/src/main/java/com/lyt/dao/QuestionDao.java b/src/main/java/com/lyt/dao/QuestionDao.java index dd7242b..26c340a 100644 --- a/src/main/java/com/lyt/dao/QuestionDao.java +++ b/src/main/java/com/lyt/dao/QuestionDao.java @@ -46,6 +46,9 @@ public interface QuestionDao { @Select("select * from question where user_id = #{userId}") public List getAllByUserIdQuestion(int userId);//根据创建者id获取所有试题 + @Select("select * from question where type = #{type}") + public List getAllBytypeuestion(int type);//根据创建者id获取所有试题 zjx + @Select("select * from paper_question pq,question q where pq.question_id = q.question_id and pq.paper_id = #{paperId}") public List selectUnion(int paperId);//获取所有试卷中的试题 } diff --git a/src/main/java/com/lyt/service/PaperService.java b/src/main/java/com/lyt/service/PaperService.java index 42dafec..b5b4d6e 100644 --- a/src/main/java/com/lyt/service/PaperService.java +++ b/src/main/java/com/lyt/service/PaperService.java @@ -19,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.rmi.server.ServerCloneException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; import cn.hutool.core.util.RandomUtil; @@ -134,6 +136,12 @@ public class PaperService { paper.setPaperId(newId); //这个是自增的 paper.setStatus(0);//试卷状态初始化为0(zjx) + //添加时间 + SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(System.currentTimeMillis()); + System.out.println(formatter.format(date)); + paper.setTime(formatter.format(date)); + System.out.println("转换后的paper "+paper); //处理 titleContent List titleContents = new ArrayList<>(); @@ -240,6 +248,13 @@ public class PaperService { int score = 0;//记录试卷总分分数 paper.setPaperId(newId); //这个是自增的 paper.setStatus(0);//试卷状态初始化为0 + + //添加时间 + SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(System.currentTimeMillis()); + System.out.println(formatter.format(date)); + paper.setTime(formatter.format(date)); + //首先根据课程编号获取所有试题 List questions = questionDao.getAllByCourseQuestion(paper.getCourseId()); //根据题目类型查询所有题目,将各类题目放入到数组中,重新排序 diff --git a/src/main/java/com/lyt/service/QuestionService.java b/src/main/java/com/lyt/service/QuestionService.java index 637a85e..c153c9e 100644 --- a/src/main/java/com/lyt/service/QuestionService.java +++ b/src/main/java/com/lyt/service/QuestionService.java @@ -9,7 +9,9 @@ import com.lyt.vo.QuestionVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** * @Author: zjx @@ -32,18 +34,24 @@ public class QuestionService { return questionVo; }; + //封装Question转为QuestionVo + private List questionVos(List questions){ + List questionVos = new ArrayList<>(); + for (Question question : questions) { + QuestionVo questionVo = new QuestionVo(); + BeanUtil.beanConvert(question,questionVo); + List items = (List) JSON.parse(question.getContent()); + questionVo.setItems(items); + questionVos.add(questionVo); + //将content转换 + } + return questionVos; + } + + //zjx 2023/5/7 public List getAllQuestion(){ List questions = questionDao.getAllQuestion(); - List questionVos = new ArrayList<>(); - for (Question question : questions) { - QuestionVo questionVo = new QuestionVo(); - BeanUtil.beanConvert(question,questionVo); - List items = (List) JSON.parse(question.getContent()); - questionVo.setItems(items); - questionVos.add(questionVo); - //将content转换 - } - return questionVos; + return questionVos(questions); }; public int updateQuestion(Question question){ @@ -60,6 +68,13 @@ public class QuestionService { Question newQuestion = BeanUtil.beanConvert(questionVo,question);//将questionVo转换为question String contentJson = JSON.toJSONString(questionVo.getItems()); + //zjx +// SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); + SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(System.currentTimeMillis()); + System.out.println(formatter.format(date)); + newQuestion.setTime(formatter.format(date)); + System.out.println("选项的json串"+contentJson); newQuestion.setContent(contentJson); System.out.println("这是新创建的 对象"+ newQuestion); @@ -79,10 +94,18 @@ public class QuestionService { return 0; };//创建试题 - public List getAllByCourseQuestion(int courseId){ - return questionDao.getAllByCourseQuestion(courseId); + //zjx 5/7 + public List getAllByCourseQuestion(int courseId){ + List questions = questionDao.getAllByCourseQuestion(courseId); + return questionVos(questions); };//根据课程获取所有试题 + //zjx 5/7 + public List getAllBytypeuestion(int type){ + List questions = questionDao.getAllBytypeuestion(type); + return questionVos(questions); + }; + public List getAllByUserIdQuestion(int userId){ return questionDao.getAllByUserIdQuestion(userId); };//根据创建者获取所有试题 -- Gitee From 49733e43ebf07925d0a61f1604f36fc8f3891652 Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Tue, 9 May 2023 20:46:08 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=BA=8C=E7=BA=A7=E6=9F=A5=E8=AF=A2=E5=92=8C=E8=AF=95?= =?UTF-8?q?=E9=A2=98=E8=AF=95=E5=8D=B7=E7=9A=84=E6=9B=B4=E6=96=B0=E5=80=9F?= =?UTF-8?q?=E5=8F=A3=E3=80=82=20=E8=AF=95=E5=8D=B7=E7=9A=84=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=89=8D=E7=94=A8=E7=9B=B4=E6=8E=A5=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=90=8E=E9=87=8D=E6=96=B0=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lyt/controller/PaperController.java | 35 +++++++++++----- .../lyt/controller/QuestionController.java | 13 ++++++ src/main/java/com/lyt/dao/PaperDao.java | 6 +++ src/main/java/com/lyt/dao/QuestionDao.java | 5 ++- .../java/com/lyt/service/PaperService.java | 40 ++++++++++++++++--- .../java/com/lyt/service/QuestionService.java | 37 ++++++++++++++++- src/main/resources/mapper/QuestionMapper.xml | 18 +++++++++ src/test/java/com/lyt/QuestionTest.java | 10 +++++ 8 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/mapper/QuestionMapper.xml diff --git a/src/main/java/com/lyt/controller/PaperController.java b/src/main/java/com/lyt/controller/PaperController.java index af81c3e..c44e488 100644 --- a/src/main/java/com/lyt/controller/PaperController.java +++ b/src/main/java/com/lyt/controller/PaperController.java @@ -6,10 +6,10 @@ import com.lyt.vo.QuestionVo; import com.lyt.vo.QuestionsVo; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + /** * @Author: zjx * @Date: 2023/04/27/20:03 @@ -40,7 +40,7 @@ public class PaperController { }else if (i == 4){ return "问答题数量不足"; } - return "okkkk"; + return "创建成功"; } //根据试卷编号获取试卷,lyt @@ -51,9 +51,26 @@ public class PaperController { } //根据试卷编号删除试卷,zjx - @RequestMapping("/paper/delete/id") - public String deletePaper(@Param("id") Integer id){ - paperService.deletePaper(id); - return "ok"; + @RequestMapping("/paper/delete/{id}") + public int deletePaper(@PathVariable("id") Integer id){ + return paperService.deletePaper(id); + } + + //根据年级查询所有试卷,zjx + @RequestMapping("/paper/grade") + public List getAllByGradePaper(@Param("grade") Integer grade){ + return paperService.getAllByGradePaper(grade); + } + + //查询所有试卷,zjx + @RequestMapping("/paper/get") + public List getAllPaper(){ + return paperService.getAllPaper(); + } + + //根据试卷编号删除试卷,zjx + @RequestMapping("/paper/courseId") + public List getAllByCoursePaper(@Param("courseId") Integer courseId){ + return paperService.getAllByCoursePaper(courseId); } } diff --git a/src/main/java/com/lyt/controller/QuestionController.java b/src/main/java/com/lyt/controller/QuestionController.java index fac4251..58170d4 100644 --- a/src/main/java/com/lyt/controller/QuestionController.java +++ b/src/main/java/com/lyt/controller/QuestionController.java @@ -60,6 +60,12 @@ public class QuestionController { return questionService.deleteQuestion(id); } + //zjx + @RequestMapping("/question/courseIdortype") + public List getAllQuestionByCourseIdOrType(@Param("type") Integer type,@Param("courseId")Integer courseId)throws Exception{ + return questionService.getAllQuestionByCourseIdOrType(type,courseId); + } + //zjx 5/7 @RequestMapping("/question/courseId")//根据课程Id查询试题 public List getAllByCourseQuestion(@Param("courseId") Integer courseId)throws Exception{ @@ -71,4 +77,11 @@ public class QuestionController { public List getAllBytypeuestion(@Param("type") Integer type)throws Exception{ return questionService.getAllBytypeuestion(type); } + + //zjx 5/8 + @RequestMapping("/question/update")//根据课程Id查询试题 + public int getAllBytypeuestion(@RequestBody QuestionVo questionVo)throws Exception{ + questionService.updateQuestion(questionVo); + return 1; + } } diff --git a/src/main/java/com/lyt/dao/PaperDao.java b/src/main/java/com/lyt/dao/PaperDao.java index c1054fb..a701a08 100644 --- a/src/main/java/com/lyt/dao/PaperDao.java +++ b/src/main/java/com/lyt/dao/PaperDao.java @@ -42,9 +42,15 @@ public interface PaperDao { @Select("select * from paper where course_id = #{courseId}") public List getAllByCoursePaper(int courseId);//根据课程获取所有试卷中的试题 + @Select("select * from paper where grade = #{grade}") + public List getAllByGradePaper(Integer grade);//根据课程获取所有试卷中的试题 + @Update("update paper set status=#{status} where paper_id = #{paperId}") public int commitPaper(@Param("status")Integer status,@Param("paperId")Integer paperId);//发布试卷 + @Select("select * from paper") + public List getAllPaper();//获取所有试卷 + // @Results(value = {@Result(id = true,column="paper_id",property="paperId"), // @Result(property="questions",column="paper_id",javaType = List.class, // many = @Many(select = "com.lyt.dao.QuestionDao.selectByQuestionId")) diff --git a/src/main/java/com/lyt/dao/QuestionDao.java b/src/main/java/com/lyt/dao/QuestionDao.java index 26c340a..b790253 100644 --- a/src/main/java/com/lyt/dao/QuestionDao.java +++ b/src/main/java/com/lyt/dao/QuestionDao.java @@ -26,7 +26,7 @@ public interface QuestionDao { @Select("select * from question ") public List getAllQuestion(); - @Update("update question set question_name=#{questionName},a=#{a},b=#{b},c=#{c},d=#{d},score=#{score}," + + @Update("update question set question_name=#{questionName},content=#{content},score=#{score}," + "answer=#{answer},detail=#{detail} where question_id = #{questionId}") public int updateQuestion(Question question);//根据试卷编号更新试题 @@ -51,4 +51,7 @@ public interface QuestionDao { @Select("select * from paper_question pq,question q where pq.question_id = q.question_id and pq.paper_id = #{paperId}") public List selectUnion(int paperId);//获取所有试卷中的试题 + + //二级查询 + public List getAllQuestionByCourseIdOrType(Integer type,Integer courseId); } diff --git a/src/main/java/com/lyt/service/PaperService.java b/src/main/java/com/lyt/service/PaperService.java index b5b4d6e..6db70f5 100644 --- a/src/main/java/com/lyt/service/PaperService.java +++ b/src/main/java/com/lyt/service/PaperService.java @@ -107,6 +107,38 @@ public class PaperService { } + //zjx 封装paper转为PaperVo + private List papersVos(List papers){ + List paperVos = new ArrayList<>(); + for (Paper paper : papers) { + PaperVo paperVo = new PaperVo(); + BeanUtil.beanConvert(paper,paperVo); + List questionsVos = (List) JSON.parse(paper.getTitleContent());//获取大题 + paperVo.setTitleItems(questionsVos); + paperVos.add(paperVo); + //将content转换 + } + return paperVos; + } + + //zjx 获取所有试卷 + public List getAllPaper(){ + List papers = paperDao.getAllPaper(); + return papersVos(papers); + }; + + //zjx 根据年级获取所有试卷 + public List getAllByGradePaper(Integer grade){ + List papers = paperDao.getAllByGradePaper(grade); + return papersVos(papers); + }; + + //根据课程获取所有试卷 + public List getAllByCoursePaper(int courseId){ + List papers = paperDao.getAllByCoursePaper(courseId); + return papersVos(papers); + }; + public int updatePaper(Paper paper){ return paperDao.updatePaper(paper); };//根据试卷编号更新试卷名字,年级 @@ -128,12 +160,12 @@ public class PaperService { // TODO: 2023/5/2 还有很多逻辑需要处理 例如 one two three // TODO: 2023/5/4 完成 one two three 和 score逻辑 //因为id是自增的 取数据库中最大id然后+1即可 ,但是这样处理存在并发风险 - int newId = paperDao.getPaperMaxId()+1; +// int newId = paperDao.getPaperMaxId()+1; int one = 0;//记录选择题数量 int two = 0;//记录判断题数量 int three = 0;//记录问答题数量 int score = 0;//记录试卷总分分数 - paper.setPaperId(newId); //这个是自增的 +// paper.setPaperId(newId); //这个是自增的 paper.setStatus(0);//试卷状态初始化为0(zjx) //添加时间 @@ -316,10 +348,6 @@ public class PaperService { return 1; };//自动创建试卷 - public List getAllByCoursePaper(int courseId){ - return paperDao.getAllByCoursePaper(courseId); - };//根据课程获取所有试卷中的试题 - public int commitPaper(@Param("status")Integer status, @Param("paperId")Integer paperId){ return paperDao.commitPaper(1,paperId); };//发布试卷 diff --git a/src/main/java/com/lyt/service/QuestionService.java b/src/main/java/com/lyt/service/QuestionService.java index c153c9e..190a3c8 100644 --- a/src/main/java/com/lyt/service/QuestionService.java +++ b/src/main/java/com/lyt/service/QuestionService.java @@ -54,8 +54,41 @@ public class QuestionService { return questionVos(questions); }; - public int updateQuestion(Question question){ - return questionDao.updateQuestion(question); + public List getAllQuestionByCourseIdOrType(Integer type,Integer courseId){ + List questions = questionDao.getAllQuestionByCourseIdOrType(type,courseId); + return questionVos(questions); + } + + public int updateQuestion(QuestionVo questionVo){ + System.out.println("执行 updateQuestion"); + Question question = new Question(); + Question newQuestion = BeanUtil.beanConvert(questionVo,question);//将questionVo转换为question + String contentJson = JSON.toJSONString(questionVo.getItems()); + + //zjx +// SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); + SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(System.currentTimeMillis()); + System.out.println(formatter.format(date)); + newQuestion.setTime(formatter.format(date)); + + System.out.println("选项的json串"+contentJson); + newQuestion.setContent(contentJson); + System.out.println("这是新创建的 对象"+ newQuestion); + + //zjx + if (newQuestion.getType() == 2){ + String answerJson = JSON.toJSONString(questionVo.getAnswervos()); + newQuestion.setAnswer(answerJson); + } + + //将选项转换为 json 串 + int num = questionDao.updateQuestion(newQuestion); + if(num >0){ + System.out.println("修改试题成功"); + return 1; + } + return 1; };//根据试卷编号更新试卷 public int deleteQuestion(Integer questionId){ diff --git a/src/main/resources/mapper/QuestionMapper.xml b/src/main/resources/mapper/QuestionMapper.xml new file mode 100644 index 0000000..4037abb --- /dev/null +++ b/src/main/resources/mapper/QuestionMapper.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/src/test/java/com/lyt/QuestionTest.java b/src/test/java/com/lyt/QuestionTest.java index e66bf67..5945a11 100644 --- a/src/test/java/com/lyt/QuestionTest.java +++ b/src/test/java/com/lyt/QuestionTest.java @@ -36,6 +36,16 @@ public class QuestionTest { List questions = questionDao.getAllQuestion(); System.out.println(questions); } + + //二级查询 + @Test + public void getAllQuestionByCourseIdOrType(){ + List questions = questionDao.getAllQuestionByCourseIdOrType(null,1); + for (Question question : questions){ + System.out.println(question.toString()); + } + + } // // //测试根据试卷编号查看试卷中所有试题 // @Test -- Gitee From dc845eeeffe7e02e6a2c26687cfacfcd7eb37948 Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Wed, 10 May 2023 21:09:50 +0800 Subject: [PATCH 5/7] =?UTF-8?q?AnswerVo=E5=8A=A0=E5=85=A5=E4=BA=86type?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=B1=95=E7=A4=BA=E5=92=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lyt/bean/TitleContent.java | 1 + .../com/lyt/controller/PaperController.java | 7 ++ .../lyt/controller/QuestionController.java | 2 +- .../java/com/lyt/service/PaperService.java | 78 +++++++++++++------ .../java/com/lyt/service/QuestionService.java | 17 +++- .../lyt/vo/{Answervo.java => AnswerVo.java} | 2 +- src/main/java/com/lyt/vo/QuestionVo.java | 2 +- src/main/java/com/lyt/vo/QuestionsVo.java | 1 + 8 files changed, 82 insertions(+), 28 deletions(-) rename src/main/java/com/lyt/vo/{Answervo.java => AnswerVo.java} (88%) diff --git a/src/main/java/com/lyt/bean/TitleContent.java b/src/main/java/com/lyt/bean/TitleContent.java index 88b852e..18284ce 100644 --- a/src/main/java/com/lyt/bean/TitleContent.java +++ b/src/main/java/com/lyt/bean/TitleContent.java @@ -15,4 +15,5 @@ import lombok.NoArgsConstructor; public class TitleContent { private String titleName; private int sort; + private int type; } diff --git a/src/main/java/com/lyt/controller/PaperController.java b/src/main/java/com/lyt/controller/PaperController.java index c44e488..0c0312f 100644 --- a/src/main/java/com/lyt/controller/PaperController.java +++ b/src/main/java/com/lyt/controller/PaperController.java @@ -73,4 +73,11 @@ public class PaperController { public List getAllByCoursePaper(@Param("courseId") Integer courseId){ return paperService.getAllByCoursePaper(courseId); } + + //发布试卷,zjx + @RequestMapping("/commit/paper") + public String commitPaper(@Param("paperId")Integer paperId){ + paperService.commitPaper(1,paperId); + return "okkkk"; + } } diff --git a/src/main/java/com/lyt/controller/QuestionController.java b/src/main/java/com/lyt/controller/QuestionController.java index 58170d4..35b05b5 100644 --- a/src/main/java/com/lyt/controller/QuestionController.java +++ b/src/main/java/com/lyt/controller/QuestionController.java @@ -31,7 +31,7 @@ public class QuestionController { } @RequestMapping("/question/get")//查询所有试题 - public List getQuestionList()throws Exception{ + public List getAllQuestion()throws Exception{ // System.out.println(questionVo); // questionService.addQuestion(questionVo); diff --git a/src/main/java/com/lyt/service/PaperService.java b/src/main/java/com/lyt/service/PaperService.java index 6db70f5..3a851e8 100644 --- a/src/main/java/com/lyt/service/PaperService.java +++ b/src/main/java/com/lyt/service/PaperService.java @@ -49,6 +49,7 @@ public class PaperService { //根据paperId获取 试题 List paperQuestions = questionDao.getPaperQuestionById(id); // System.out.println("打印一下 paperQuestions"+paperQuestions); + //获取所有小题 List questionVos = new ArrayList<>(); //获取所有的相关题目 并写入 item中 for (PaperQuestion paperQuestion : paperQuestions) { @@ -85,24 +86,45 @@ public class PaperService { System.out.println("遍历输出 titleName"+titleContent.getTitleName()); QuestionsVo questionsVo = new QuestionsVo(); questionsVo.setQuestionName(titleContent.getTitleName()); - questionsVos.add(questionsVo); + questionsVo.setType(titleContent.getType()); + questionsVos.add(questionsVo);//将titleContent转为questionsVos } for (QuestionsVo questionsVo : questionsVos) { //把小题塞进大题里面 - questionsVo.setQuestionItems(questionVos); - - + List questionVo1 = new ArrayList<>(); +// for (int i=0 ; i titleItems = paperVo.getTitleItems(); - for (int i = 0; i < titleItems.size(); i++) { - QuestionsVo titleItem = titleItems.get(i); - TitleContent titleContent = new TitleContent(); - titleContent.setTitleName(titleItem.getQuestionName());//大题名字 - titleContent.setSort(i);//大题编号 - titleContents.add(titleContent); - } - String titleContentJson = JSON.toJSONString(titleContents);//转为json格式 - paper.setTitleContent(titleContentJson); +// for (int i = 0; i < titleItems.size(); i++) { +// QuestionsVo titleItem = titleItems.get(i); +// TitleContent titleContent = new TitleContent(); +// titleContent.setTitleName(titleItem.getQuestionName());//大题名字 +// titleContent.setSort(i);//大题编号 +// titleContents.add(titleContent); +// } // paperDao.addPaper(paper);//zjx + int index = 0; + //再写试卷 -- 题目关系表 List paperQuestions = new ArrayList<>(); //建立 试卷 试题关系映射 for (QuestionsVo titleItem : paperVo.getTitleItems()) {//遍历大题 + titleItem = titleItems.get(index); + TitleContent titleContent = new TitleContent(); + titleContent.setTitleName(titleItem.getQuestionName());//大题名字 + titleContent.setSort(index);//大题编号 + index++; for (QuestionVo questionItem : titleItem.getQuestionItems()) {//遍历大题中的小题 int questionId = questionItem.getQuestionId();//获取小题中的id PaperQuestion paperQuestion = new PaperQuestion();//创建一个试卷试题关联对象 @@ -202,9 +229,9 @@ public class PaperService { paperQuestion.setPaperId(paper.getPaperId()); // 设置questionId paperQuestion.setQuestionId(questionId); - //zjx int type = questionDao.getQuestionById(questionId).getType(); + titleContent.setType(type); if (type == 1 || type == 2){ one++; }else if (type == 4){ @@ -216,8 +243,12 @@ public class PaperService { paperQuestions.add(paperQuestion);//添加关联 } + titleContents.add(titleContent); } + String titleContentJson = JSON.toJSONString(titleContents);//转为json格式 + paper.setTitleContent(titleContentJson); + //zjx paper.setOne(one); paper.setTwo(two); @@ -225,6 +256,8 @@ public class PaperService { paper.setScore(score); paperDao.addPaper(paper); + + System.out.println("打印一下 paperQuestion "+paperQuestions); for (PaperQuestion paperQuestion : paperQuestions) { @@ -236,11 +269,12 @@ public class PaperService { //自动添加大题封装,zjx 2023/5/5 - private void settitleContents(int paperquestionSize,List titleContents,String TitleName,int Sort){ + private void settitleContents(int paperquestionSize,List titleContents,String TitleName,int Sort,int type){ if (paperquestionSize > 0){ TitleContent titleContent = new TitleContent(); titleContent.setTitleName(TitleName); titleContent.setSort(Sort); + titleContent.setType(type); titleContents.add(titleContent); } } @@ -333,11 +367,11 @@ public class PaperService { List titleContents = new ArrayList<>(); //如果选择题数量大于0,自动创建选择大题 - settitleContents(paper.getOne(),titleContents,"选择题",0); + settitleContents(paper.getOne(),titleContents,"选择题",0,1); //如果判断题数量大于0,自动创建判断题大题 - settitleContents(paper.getTwo(),titleContents,"判断题",1); + settitleContents(paper.getTwo(),titleContents,"判断题",1,2); //如果问答题数量大于0,自动创建问答题大题 - settitleContents(paper.getThree(),titleContents,"问答题",2); + settitleContents(paper.getThree(),titleContents,"问答题",2,3); String titleContentJson = JSON.toJSONString(titleContents);//转为json格式 paper.setTitleContent(titleContentJson); diff --git a/src/main/java/com/lyt/service/QuestionService.java b/src/main/java/com/lyt/service/QuestionService.java index 190a3c8..56c7155 100644 --- a/src/main/java/com/lyt/service/QuestionService.java +++ b/src/main/java/com/lyt/service/QuestionService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.lyt.bean.Question; import com.lyt.dao.QuestionDao; import com.lyt.util.BeanUtil; +import com.lyt.vo.AnswerVo; import com.lyt.vo.ItemVo; import com.lyt.vo.QuestionVo; import org.springframework.beans.factory.annotation.Autowired; @@ -28,9 +29,13 @@ public class QuestionService { System.out.println("查询到的question"+question); QuestionVo questionVo = new QuestionVo(); - BeanUtil.beanConvert(question,questionVo);//将questionVo转换为question + BeanUtil.beanConvert(question,questionVo);//将question转换为questionVo List items = (List) JSON.parse(question.getContent()); questionVo.setItems(items); + if (questionVo.getType() == 2){ + List answerVos = (List) JSON.parse(question.getAnswer());//转为数组传送给前端 + questionVo.setAnswerVos(answerVos); + } return questionVo; }; @@ -41,7 +46,12 @@ public class QuestionService { QuestionVo questionVo = new QuestionVo(); BeanUtil.beanConvert(question,questionVo); List items = (List) JSON.parse(question.getContent()); + if (question.getType() == 2){//数据库的所有数据都要按最新标准,不然格式出错 + List answerVos = (List) JSON.parse(question.getAnswer());//转为数组传送给前端 + questionVo.setAnswerVos(answerVos); + } questionVo.setItems(items); + System.out.println(questionVo.toString()); questionVos.add(questionVo); //将content转换 } @@ -51,6 +61,7 @@ public class QuestionService { //zjx 2023/5/7 public List getAllQuestion(){ List questions = questionDao.getAllQuestion(); + System.out.println(11111); return questionVos(questions); }; @@ -78,7 +89,7 @@ public class QuestionService { //zjx if (newQuestion.getType() == 2){ - String answerJson = JSON.toJSONString(questionVo.getAnswervos()); + String answerJson = JSON.toJSONString(questionVo.getAnswerVos()); newQuestion.setAnswer(answerJson); } @@ -114,7 +125,7 @@ public class QuestionService { //zjx if (newQuestion.getType() == 2){ - String answerJson = JSON.toJSONString(questionVo.getAnswervos()); + String answerJson = JSON.toJSONString(questionVo.getAnswerVos()); newQuestion.setAnswer(answerJson); } diff --git a/src/main/java/com/lyt/vo/Answervo.java b/src/main/java/com/lyt/vo/AnswerVo.java similarity index 88% rename from src/main/java/com/lyt/vo/Answervo.java rename to src/main/java/com/lyt/vo/AnswerVo.java index adb18b0..af27ee8 100644 --- a/src/main/java/com/lyt/vo/Answervo.java +++ b/src/main/java/com/lyt/vo/AnswerVo.java @@ -7,6 +7,6 @@ import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor -public class Answervo { +public class AnswerVo { private String prefix; } diff --git a/src/main/java/com/lyt/vo/QuestionVo.java b/src/main/java/com/lyt/vo/QuestionVo.java index 9b2e837..f9b5d4a 100644 --- a/src/main/java/com/lyt/vo/QuestionVo.java +++ b/src/main/java/com/lyt/vo/QuestionVo.java @@ -26,6 +26,6 @@ public class QuestionVo { private String time;//创建时间 List items; //选择题选项 后面会转换成json - List answervos; //多选题答案 + List answerVos; //多选题答案 } diff --git a/src/main/java/com/lyt/vo/QuestionsVo.java b/src/main/java/com/lyt/vo/QuestionsVo.java index 692f179..bc86c93 100644 --- a/src/main/java/com/lyt/vo/QuestionsVo.java +++ b/src/main/java/com/lyt/vo/QuestionsVo.java @@ -15,4 +15,5 @@ import java.util.List; public class QuestionsVo { private String questionName; private List questionItems; + private int type; } -- Gitee From 0468a7a1215f548490137f1111c06d5b079e41de Mon Sep 17 00:00:00 2001 From: zjxxxxxx02 Date: Thu, 11 May 2023 12:15:56 +0800 Subject: [PATCH 6/7] =?UTF-8?q?QuestionVo=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AA=E5=B1=9E=E6=80=A7=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=89=8D=E7=AB=AF=E4=BF=AE=E6=94=B9=E5=89=8D?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E6=95=B0=E7=BB=84=E7=9A=84=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=A4=9A=E9=80=89=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lyt/service/QuestionService.java | 13 ++++++++++++- src/main/java/com/lyt/vo/QuestionVo.java | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/lyt/service/QuestionService.java b/src/main/java/com/lyt/service/QuestionService.java index 56c7155..6510dcd 100644 --- a/src/main/java/com/lyt/service/QuestionService.java +++ b/src/main/java/com/lyt/service/QuestionService.java @@ -87,9 +87,20 @@ public class QuestionService { newQuestion.setContent(contentJson); System.out.println("这是新创建的 对象"+ newQuestion); + //zjx if (newQuestion.getType() == 2){ - String answerJson = JSON.toJSONString(questionVo.getAnswerVos()); + List answerVos2 = new ArrayList<>();//用于重新接收答案数组,直接添加会添加修改前的数据 + for (int i = questionVo.getLength();i items; //选择题选项 后面会转换成json List answerVos; //多选题答案 + private int length;//接收answerVos数组原始长度 } -- Gitee From a461dd1f031e75366d587f1961a87888ca34ccd1 Mon Sep 17 00:00:00 2001 From: unissww Date: Thu, 18 May 2023 18:53:32 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=9C=89=EF=BC=9A=20=E6=B7=BB=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E8=80=83=E8=AF=95=E7=9A=84=E5=AD=A6=E7=94=9F=20?= =?UTF-8?q?=E8=80=83=E8=AF=95=E6=8F=90=E4=BA=A4=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E8=AE=BE=E8=AE=A1=E8=BF=98=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=20=E8=83=BD=E5=AE=9E=E7=8E=B0=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=80=BC=E6=95=B0=E6=8D=AE=E5=BA=93=E4=BF=9D=E5=AD=98--?= =?UTF-8?q?=E8=BF=98=E5=B7=AE=E5=A6=82=E6=9E=9C=E8=80=83=E7=94=9F=E5=88=87?= =?UTF-8?q?=E8=BF=87=E5=90=8E=E5=8F=B0=E9=87=8D=E6=96=B0=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E8=80=83=E8=AF=95=E5=90=8E=E5=86=8D=E6=AC=A1=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=97=B6=E5=BA=94=E8=AF=A5=E5=88=A0=E9=99=A4=E5=8E=9F=E5=85=88?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9A=84=E7=AD=94=E6=A1=88=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E8=80=83=E7=94=9F=E6=9F=90=E5=9C=BA=E8=80=83=E8=AF=95?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lyt/bean/LinkAnswer.java | 75 +++++++++++++++++ src/main/java/com/lyt/bean/TestAnswer.java | 59 ++++++++++++++ src/main/java/com/lyt/bean/TestStatus.java | 23 ++++++ .../com/lyt/controller/PaperController.java | 1 + .../lyt/controller/TestAnswerController.java | 45 +++++++++++ .../lyt/controller/TestStatusController.java | 45 +++++++++++ src/main/java/com/lyt/dao/TestAnswerDao.java | 35 ++++++++ src/main/java/com/lyt/dao/TestStatusDao.java | 21 +++++ .../com/lyt/service/TestAnswerService.java | 72 +++++++++++++++++ .../com/lyt/service/TestStatuService.java | 32 ++++++++ src/main/java/com/lyt/vo/LinkAnswerVo.java | 81 +++++++++++++++++++ src/main/java/com/lyt/vo/RetAnswerVo.java | 49 +++++++++++ src/main/java/com/lyt/vo/TestAnswerVo.java | 65 +++++++++++++++ src/main/java/com/lyt/vo/TestStatusVo.java | 40 +++++++++ src/main/resources/application.yml | 2 +- 15 files changed, 644 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/lyt/bean/LinkAnswer.java create mode 100644 src/main/java/com/lyt/bean/TestAnswer.java create mode 100644 src/main/java/com/lyt/bean/TestStatus.java create mode 100644 src/main/java/com/lyt/controller/TestAnswerController.java create mode 100644 src/main/java/com/lyt/controller/TestStatusController.java create mode 100644 src/main/java/com/lyt/dao/TestAnswerDao.java create mode 100644 src/main/java/com/lyt/dao/TestStatusDao.java create mode 100644 src/main/java/com/lyt/service/TestAnswerService.java create mode 100644 src/main/java/com/lyt/service/TestStatuService.java create mode 100644 src/main/java/com/lyt/vo/LinkAnswerVo.java create mode 100644 src/main/java/com/lyt/vo/RetAnswerVo.java create mode 100644 src/main/java/com/lyt/vo/TestAnswerVo.java create mode 100644 src/main/java/com/lyt/vo/TestStatusVo.java diff --git a/src/main/java/com/lyt/bean/LinkAnswer.java b/src/main/java/com/lyt/bean/LinkAnswer.java new file mode 100644 index 0000000..ce0569b --- /dev/null +++ b/src/main/java/com/lyt/bean/LinkAnswer.java @@ -0,0 +1,75 @@ +package com.lyt.bean; + +/** + * @Author:张勇 + * @Date:2023/5/18 10:10 + * @Info: + */ +public class LinkAnswer { + private Integer id; + private Integer stuTestId; + private Integer paperId; + private Integer _index; + private Integer questionId; + private String answer; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getStu_test_id() { + return stuTestId; + } + + public void setStu_test_id(Integer stu_test_id) { + this.stuTestId = stu_test_id; + } + + public Integer getPaper_id() { + return paperId; + } + + public void setPaper_id(Integer paper_id) { + this.paperId = paper_id; + } + + public Integer getIndex() { + return _index; + } + + public void setIndex(Integer index) { + this._index = index; + } + + public Integer getQuestion_id() { + return questionId; + } + + public void setQuestion_id(Integer question_id) { + this.questionId = question_id; + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + @Override + public String toString() { + return "LinkAnswer{" + + "id=" + id + + ", stu_test_id=" + stuTestId + + ", paper_id=" + paperId + + ", _index=" + _index + + ", question_id=" + questionId + + ", answer='" + answer + '\'' + + '}'; + } +} diff --git a/src/main/java/com/lyt/bean/TestAnswer.java b/src/main/java/com/lyt/bean/TestAnswer.java new file mode 100644 index 0000000..1c03693 --- /dev/null +++ b/src/main/java/com/lyt/bean/TestAnswer.java @@ -0,0 +1,59 @@ +package com.lyt.bean; + +import com.lyt.vo.LinkAnswerVo; + +import java.util.List; + +/** + * @Author:张勇 + * @Date:2023/5/16 19:46 + * @Info: + */ +public class TestAnswer { + private Integer test_id; + private Integer stu_test_id; + private Integer paper_id; + private String linkAnswers; + + public Integer getTest_id() { + return test_id; + } + + public void setTest_id(Integer test_id) { + this.test_id = test_id; + } + + public Integer getStu_test_id() { + return stu_test_id; + } + + public void setStu_test_id(Integer stu_test_id) { + this.stu_test_id = stu_test_id; + } + + public Integer getPaper_id() { + return paper_id; + } + + public void setPaper_id(Integer paper_id) { + this.paper_id = paper_id; + } + + public String getLinkAnswers() { + return linkAnswers; + } + + public void setLinkAnswers(String linkAnswers) { + this.linkAnswers = linkAnswers; + } + + @Override + public String toString() { + return "TestAnswer{" + + "test_id=" + test_id + + ", stu_test_id=" + stu_test_id + + ", paper_id=" + paper_id + + ", linkAnswer='" + linkAnswers + '\'' + + '}'; + } +} diff --git a/src/main/java/com/lyt/bean/TestStatus.java b/src/main/java/com/lyt/bean/TestStatus.java new file mode 100644 index 0000000..245e816 --- /dev/null +++ b/src/main/java/com/lyt/bean/TestStatus.java @@ -0,0 +1,23 @@ +package com.lyt.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * @Author:张勇 + * @Date:2023/5/11 22:46 + * @Info: + */ +@Data +@AllArgsConstructor +public class TestStatus { + private Integer stu_test_id; + private Integer student_id; + private Integer cutNum; + private String name; + private String date; + + public TestStatus() { + + } +} diff --git a/src/main/java/com/lyt/controller/PaperController.java b/src/main/java/com/lyt/controller/PaperController.java index 0c0312f..c56a572 100644 --- a/src/main/java/com/lyt/controller/PaperController.java +++ b/src/main/java/com/lyt/controller/PaperController.java @@ -46,6 +46,7 @@ public class PaperController { //根据试卷编号获取试卷,lyt @RequestMapping("/get/paper") public PaperVo getPaper(@Param("id") Integer id){ + System.out.println("---------------------"+id); PaperVo paperVo = paperService.getPaperById(id); return paperVo; } diff --git a/src/main/java/com/lyt/controller/TestAnswerController.java b/src/main/java/com/lyt/controller/TestAnswerController.java new file mode 100644 index 0000000..f48a839 --- /dev/null +++ b/src/main/java/com/lyt/controller/TestAnswerController.java @@ -0,0 +1,45 @@ +package com.lyt.controller; + +import com.lyt.bean.LinkAnswer; +import com.lyt.service.TestAnswerService; +import com.lyt.vo.LinkAnswerVo; +import com.lyt.vo.RetAnswerVo; +import com.lyt.vo.TestAnswerVo; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Author:张勇 + * @Date:2023/5/16 19:44 + * @Info: + */ +@RestController +@CrossOrigin +public class TestAnswerController { + @Autowired + public TestAnswerService testAnswerservice; + + @RequestMapping("/testAnswer/add") + public int addAnswer(@RequestBody TestAnswerVo testAnswerVo)throws Exception{ + + System.out.println(testAnswerVo); + int xx = testAnswerservice.addTestStatus(testAnswerVo); + return 1; + } + + @RequestMapping("/testAnswer/selAnswer") + public List selAnswer(@Param("paper_id")Integer paper_id, @Param("stu_id") Integer stu_id)throws Exception{ + List list = testAnswerservice.selAnswerByPaperIdAndStuId(paper_id, stu_id); + System.out.println(list); + return list; + } + +} + diff --git a/src/main/java/com/lyt/controller/TestStatusController.java b/src/main/java/com/lyt/controller/TestStatusController.java new file mode 100644 index 0000000..826ff1e --- /dev/null +++ b/src/main/java/com/lyt/controller/TestStatusController.java @@ -0,0 +1,45 @@ +package com.lyt.controller; + + +import com.lyt.bean.TestStatus; +import com.lyt.service.TestStatuService; +import com.lyt.vo.TestStatusVo; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.sql.Date; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; + +/** + * @Author: 张勇 + * @Date: 2023/05/11 + * @Info: + */ +@RestController +@CrossOrigin +public class TestStatusController { + @Autowired + public TestStatuService service; + + @RequestMapping("/testStatus/add") //添加考试的学生 + public int addTestStuts(@Param("id")Integer stu_id,@Param("name") String name)throws Exception{ + Integer stuId = service.selStuByStuId(stu_id); + int xx = 0; + if(stuId != null){ + System.out.println("我找到你了"); + return stuId; + }else { + System.out.println("我没找到你 我要添加你"); + LocalDateTime dateTime = LocalDateTime.now(); + TestStatusVo testStatusVo = new TestStatusVo(stu_id,name,dateTime.toString(),0); + System.out.println(testStatusVo.toString()); + //xx = service.addTestStatus(studentInfo); + } + return xx; + } +} diff --git a/src/main/java/com/lyt/dao/TestAnswerDao.java b/src/main/java/com/lyt/dao/TestAnswerDao.java new file mode 100644 index 0000000..9e88c8a --- /dev/null +++ b/src/main/java/com/lyt/dao/TestAnswerDao.java @@ -0,0 +1,35 @@ +package com.lyt.dao; + +import com.lyt.bean.LinkAnswer; +import com.lyt.bean.TestAnswer; +import com.lyt.vo.TestAnswerVo; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @Author:张勇 + * @Date:2023/5/18 10:47 + * @Info: + */ +@Repository +public interface TestAnswerDao { + + @Insert("insert into test_answer (stu_test_id,paper_id,linkAnswers) " + + "values(#{stu_test_id},#{paper_id},#{linkAnswers})") + public int addAnswer(TestAnswer testAnswer); + + @Insert("insert into link_answer (stu_test_id,paper_id,_index,question_id,answer) " + + "values(#{stu_test_id},#{paper_id},#{index},#{question_id},#{answer})") + public void addLinkAnswer(LinkAnswer linkAnswer); + + @Select("select * from link_answer where paper_id = #{id} and stu_test_id = #{stu_id}") + public List selAnswerByPaperIdAndStuId(@Param("id") Integer id,@Param("stu_id") Integer stu_id); + + @Delete("delete from link_answer where paper_id = #{id} and stu_test_id = #{stu_id}") + public Integer delAnswerByPaperIdAndStuId(Integer id,Integer stu_id); +} diff --git a/src/main/java/com/lyt/dao/TestStatusDao.java b/src/main/java/com/lyt/dao/TestStatusDao.java new file mode 100644 index 0000000..83da515 --- /dev/null +++ b/src/main/java/com/lyt/dao/TestStatusDao.java @@ -0,0 +1,21 @@ +package com.lyt.dao; + +import com.lyt.bean.TestStatus; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +/** + * @Author:张勇 + * @Date:2023/5/11 22:36 + * @Info: + */ +@Repository +public interface TestStatusDao { + + @Insert("insert into test_status values(#{stu_test_id},#{student_id},#{name},#{date},#{cutNum})") + public int addTestStatus(TestStatus testStatus); + + @Select("select student_id from test_status where student_id = #{0}") + public Integer selStuByStuId(Integer id); +} diff --git a/src/main/java/com/lyt/service/TestAnswerService.java b/src/main/java/com/lyt/service/TestAnswerService.java new file mode 100644 index 0000000..f0c40aa --- /dev/null +++ b/src/main/java/com/lyt/service/TestAnswerService.java @@ -0,0 +1,72 @@ +package com.lyt.service; + + +import com.alibaba.fastjson.JSON; +import com.lyt.bean.LinkAnswer; +import com.lyt.bean.TestAnswer; +import com.lyt.dao.TestAnswerDao; +import com.lyt.util.BeanUtil; +import com.lyt.vo.LinkAnswerVo; +import com.lyt.vo.RetAnswerVo; +import com.lyt.vo.TestAnswerVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author:张勇 + * @Date:2023/5/18 10:47 + * @Info: + */ +@Service +public class TestAnswerService { + + @Autowired + TestAnswerDao dao; + + public Integer addTestStatus(TestAnswerVo testAnswerVo) { + + System.out.println("---------------------------------"); + TestAnswer testAnswer = new TestAnswer(); + TestAnswer newTestAnswer = BeanUtil.beanConvert(testAnswerVo, testAnswer); + List linkAnswers = new ArrayList<>(); + for(LinkAnswerVo linkAnswerVo: testAnswerVo.getLinkAnswerVos()){ + LinkAnswer linkAnswer = new LinkAnswer(); + linkAnswer.setStu_test_id(testAnswerVo.getStu_test_id()); + linkAnswer.setPaper_id(testAnswerVo.getPaper_id()); + linkAnswer.setIndex(linkAnswerVo.getIndex()); + linkAnswer.setQuestion_id(linkAnswerVo.getQuestion_id()); + linkAnswer.setAnswer(JSON.toJSONString(linkAnswerVo.getAnswer())); + linkAnswers.add(linkAnswer); + } + for (LinkAnswer linkAnswer : linkAnswers){ + dao.addLinkAnswer(linkAnswer); + } + testAnswer.setLinkAnswers(JSON.toJSONString(linkAnswers)); + int flag = dao.addAnswer(testAnswer); + return 1; +} + //找出关联表中某个学生答的某张试卷的所有答案 + public List selAnswerByPaperIdAndStuId(Integer id,Integer stuId){ + List list = dao.selAnswerByPaperIdAndStuId(id,stuId); + System.out.println(list); + List voList = new ArrayList<>(); + for (LinkAnswer linkAnswer:list){ + RetAnswerVo linkAnswerVo = new RetAnswerVo(); + linkAnswerVo.setIndex(linkAnswer.getIndex()); + linkAnswerVo.setQuestion_id(linkAnswer.getQuestion_id()); + linkAnswerVo.setAnswer(linkAnswer.getAnswer()); + voList.add(linkAnswerVo); + System.out.println(linkAnswerVo.toString()); + } + return voList; + } + + //删除关联表中某个学生答的某张试卷的所有答案--》修改不如删除 + public Integer delAnswerByPaperIdAndStuId(Integer id,Integer stuId){ + Integer num = dao.delAnswerByPaperIdAndStuId(id,stuId); + return num; + } +} \ No newline at end of file diff --git a/src/main/java/com/lyt/service/TestStatuService.java b/src/main/java/com/lyt/service/TestStatuService.java new file mode 100644 index 0000000..de75a6a --- /dev/null +++ b/src/main/java/com/lyt/service/TestStatuService.java @@ -0,0 +1,32 @@ +package com.lyt.service; + +import com.lyt.bean.TestStatus; +import com.lyt.dao.TestStatusDao; +import com.lyt.util.BeanUtil; +import com.lyt.vo.TestStatusVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @Author:张勇 + * @Date:2023/5/11 22:34 + * @Info: + */ +@Service +public class TestStatuService { + @Autowired + TestStatusDao dao; + + public int addTestStatus(TestStatusVo testStatusVo){ + TestStatus testStatus = new TestStatus(); + TestStatus newTestStatus = BeanUtil.beanConvert(testStatusVo,testStatus); + int num = dao.addTestStatus(newTestStatus); + + return num; + } + public Integer selStuByStuId(Integer id){ + Integer num = dao.selStuByStuId(id); + return num; + } + +} diff --git a/src/main/java/com/lyt/vo/LinkAnswerVo.java b/src/main/java/com/lyt/vo/LinkAnswerVo.java new file mode 100644 index 0000000..dae5046 --- /dev/null +++ b/src/main/java/com/lyt/vo/LinkAnswerVo.java @@ -0,0 +1,81 @@ +package com.lyt.vo; + +/** + * @Author:张勇 + * @Date:2023/5/18 10:10 + * @Info: + */ +public class LinkAnswerVo { + private Integer id; + private Integer stu_test_id; + private Integer paper_id; + private Integer index; + private Integer question_id; + private String[] answer; + + public LinkAnswerVo() { + } + + public LinkAnswerVo(Integer index, Integer questionId, String[] answer) { + this.index = index; + this.question_id = questionId; + this.answer = answer; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getStu_test_id() { + return stu_test_id; + } + + public void setStu_test_id(Integer stu_test_id) { + this.stu_test_id = stu_test_id; + } + + public Integer getPaper_id() { + return paper_id; + } + + public void setPaper_id(Integer paper_id) { + this.paper_id = paper_id; + } + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } + + public Integer getQuestion_id() { + return question_id; + } + + public void setQuestion_id(Integer question_id) { + this.question_id = question_id; + } + + public String[] getAnswer() { + return answer; + } + + public void setAnswer(String[] answer) { + this.answer = answer; + } + + @Override + public String toString() { + return "LinkAnswerVo{" + + "index=" + index + + ",question_id=" + question_id + + ", answer='" + answer + '\'' + + '}'; + } +} diff --git a/src/main/java/com/lyt/vo/RetAnswerVo.java b/src/main/java/com/lyt/vo/RetAnswerVo.java new file mode 100644 index 0000000..8683a2e --- /dev/null +++ b/src/main/java/com/lyt/vo/RetAnswerVo.java @@ -0,0 +1,49 @@ +package com.lyt.vo; + +import com.alibaba.fastjson.JSONArray; + +import java.lang.reflect.Array; + +/** + * @Author:张勇 + * @Date:2023/5/18 17:55 + * @Info: + */ +public class RetAnswerVo { + private Integer index; + private Integer question_id; + private String answer; + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } + + public Integer getQuestion_id() { + return question_id; + } + + public void setQuestion_id(Integer question_id) { + this.question_id = question_id; + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + @Override + public String toString() { + return "RetAnswerVo{" + + "index=" + index + + ", question_id=" + question_id + + ", answer='" + answer + '\'' + + '}'; + } +} diff --git a/src/main/java/com/lyt/vo/TestAnswerVo.java b/src/main/java/com/lyt/vo/TestAnswerVo.java new file mode 100644 index 0000000..83900fa --- /dev/null +++ b/src/main/java/com/lyt/vo/TestAnswerVo.java @@ -0,0 +1,65 @@ +package com.lyt.vo; + +import java.util.List; + +/** + * @Author:张勇 + * @Date:2023/5/16 19:46 + * @Info: + */ +public class TestAnswerVo { + private Integer test_id; + private Integer stu_test_id; + private Integer paper_id; + private List linkAnswerVos; + + + + public Integer getTest_id() { + return test_id; + } + + public void setTest_id(Integer test_id) { + this.test_id = test_id; + } + + public Integer getStu_test_id() { + return stu_test_id; + } + + public void setStu_test_id(Integer stu_test_id) { + this.stu_test_id = stu_test_id; + } + + public Integer getPaper_id() { + return paper_id; + } + + public void setPaper_id(Integer paper_id) { + this.paper_id = paper_id; + } + + public List getLinkAnswerVos() { + return linkAnswerVos; + } + + public void setLinkAnswerVos(List linkAnswerVos) { + this.linkAnswerVos = linkAnswerVos; + } + + public TestAnswerVo(Integer stu_test_id, Integer paper_id, List stu_answer) { + this.stu_test_id = stu_test_id; + this.paper_id = paper_id; + this.linkAnswerVos = stu_answer; + } + + @Override + public String toString() { + return "TestAnswerVo{" + + "test_id=" + test_id + + ", stu_test_id=" + stu_test_id + + ", paper_id=" + paper_id + + ", linkAnswerVos=" + linkAnswerVos + + '}'; + } +} diff --git a/src/main/java/com/lyt/vo/TestStatusVo.java b/src/main/java/com/lyt/vo/TestStatusVo.java new file mode 100644 index 0000000..beabddb --- /dev/null +++ b/src/main/java/com/lyt/vo/TestStatusVo.java @@ -0,0 +1,40 @@ +package com.lyt.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:张勇 + * @Date:2023/5/11 22:03 + * @Info: 参加考试的学生实体类 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TestStatusVo { + private Integer stu_test_id; + private Integer student_id; + private Integer cutNum; + private String name; + private String date; + + + public TestStatusVo(Integer student_idm, String name, String date, Integer cutNu) { + this.student_id = student_id; + this.name = name; + this.date = date; + this.cutNum = cutNum; + } + + @Override + public String toString() { + return "TestStatusVo{" + + "stu_test_id=" + stu_test_id + + ", student_id=" + student_id + + ", cutNum=" + cutNum + + ", name='" + name + '\'' + + ", date='" + date + '\'' + + '}'; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f35df98..778081a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/onlineexamsystem?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC username: root - password: z075722271630 + password: ZY584726 mybatis: mapper-locations: classpath:mapper/*.xml -- Gitee