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 0000000000000000000000000000000000000000..ce0569b57841f2f1a95075827e140a9d54048ff3 --- /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 0000000000000000000000000000000000000000..1c036933bb2c2eea900dd3622eb62769537f6f35 --- /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 0000000000000000000000000000000000000000..245e816ee28d09725d8779d70449a5d03b943693 --- /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 0c0312f62328bbb9a4218ca45f330714f72ff281..c56a572bbbff1c1a6aab0ac5223b086c9d9fc82c 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 0000000000000000000000000000000000000000..f48a8395320513000a604d99900ce719fd2289fb --- /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 0000000000000000000000000000000000000000..826ff1e8f7c15b5753e5ca8801437feb2270d172 --- /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 0000000000000000000000000000000000000000..9e88c8a285d67052723f2ecde3f63fc52bf1f88d --- /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 0000000000000000000000000000000000000000..83da51574f6ecfb69651b5037aea6d836f498f93 --- /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 0000000000000000000000000000000000000000..f0c40aac2f3b11da25af223345b7fd8213186baa --- /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 0000000000000000000000000000000000000000..de75a6a5defc723b4b29a7ada026572d64dec339 --- /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 0000000000000000000000000000000000000000..dae5046f8cc1270b8d0eeded6be48ec18c3c0815 --- /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 0000000000000000000000000000000000000000..8683a2ee82dcf806197153841e416dd0f8fc7a9a --- /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 0000000000000000000000000000000000000000..83900fa04f7287d44cd350e93deae33e159f28b8 --- /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 0000000000000000000000000000000000000000..beabddba62f29a263549024638e19d7f09a8a1f4 --- /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 bcd2b5973c618cd6165e68bf4713a443ca9de699..f35df98dd23c9a50b0dfdce83ab174a227797d71 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: root + password: z075722271630 mybatis: mapper-locations: classpath:mapper/*.xml @@ -19,4 +19,4 @@ server: port: 8090 logging: level: - com.lyt: debug \ No newline at end of file + com.lyt.dao: debug \ No newline at end of file