From 0c6404829d7747fd4472b2336a8e8e12a03d98b3 Mon Sep 17 00:00:00 2001 From: ovo Date: Sat, 11 Jan 2025 19:13:39 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=88=A0=E9=99=A4=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=202.=E6=96=B0=E5=A2=9E=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=A2=98=E7=AE=97=E5=88=86=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/Handler/MyMetaObjectHandler.java | 1 + .../backend/constant/SecurityConstants.java | 1 - .../controller/QuestionsController.java | 111 ++++++++++++++++++ .../backend/generator/domain/Papers.java | 76 ------------ .../generator/mapper/PapersMapper.java | 18 --- .../generator/service/PapersService.java | 13 -- .../service/impl/PapersServiceImpl.java | 22 ---- .../guwan/backend/mapper/QuestionsMapper.java | 18 +++ .../guwan/backend/pojo/entity/Questions.java | 71 +++++++++++ .../backend/pojo/enums/QuestionType.java | 17 +++ .../backend/service/QuestionsService.java | 13 ++ .../service/impl/QuestionsServiceImpl.java | 22 ++++ .../backend/util/MultipleChoiceCompare.java | 61 ++++++++++ src/main/resources/mapper/PapersMapper.xml | 27 ----- .../backend/TestMultipleChoiceQuestion.java | 74 ++++++++++++ 15 files changed, 388 insertions(+), 157 deletions(-) create mode 100644 src/main/java/com/guwan/backend/controller/QuestionsController.java delete mode 100644 src/main/java/com/guwan/backend/generator/domain/Papers.java delete mode 100644 src/main/java/com/guwan/backend/generator/mapper/PapersMapper.java delete mode 100644 src/main/java/com/guwan/backend/generator/service/PapersService.java delete mode 100644 src/main/java/com/guwan/backend/generator/service/impl/PapersServiceImpl.java create mode 100644 src/main/java/com/guwan/backend/mapper/QuestionsMapper.java create mode 100644 src/main/java/com/guwan/backend/pojo/entity/Questions.java create mode 100644 src/main/java/com/guwan/backend/pojo/enums/QuestionType.java create mode 100644 src/main/java/com/guwan/backend/service/QuestionsService.java create mode 100644 src/main/java/com/guwan/backend/service/impl/QuestionsServiceImpl.java create mode 100644 src/main/java/com/guwan/backend/util/MultipleChoiceCompare.java delete mode 100644 src/main/resources/mapper/PapersMapper.xml create mode 100644 src/test/java/com/guwan/backend/TestMultipleChoiceQuestion.java diff --git a/src/main/java/com/guwan/backend/Handler/MyMetaObjectHandler.java b/src/main/java/com/guwan/backend/Handler/MyMetaObjectHandler.java index cd2e87f..7fe889d 100644 --- a/src/main/java/com/guwan/backend/Handler/MyMetaObjectHandler.java +++ b/src/main/java/com/guwan/backend/Handler/MyMetaObjectHandler.java @@ -16,5 +16,6 @@ public class MyMetaObjectHandler implements MetaObjectHandler { @Override public void updateFill(MetaObject metaObject) { this.strictUpdateFill(metaObject, "lastLoginTime", LocalDateTime.class, LocalDateTime.now()); + this.strictUpdateFill(metaObject, "updatedTime", LocalDateTime.class, LocalDateTime.now()); } } \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/constant/SecurityConstants.java b/src/main/java/com/guwan/backend/constant/SecurityConstants.java index cb5a127..7335200 100644 --- a/src/main/java/com/guwan/backend/constant/SecurityConstants.java +++ b/src/main/java/com/guwan/backend/constant/SecurityConstants.java @@ -20,7 +20,6 @@ public class SecurityConstants { "/api/user/getEmailCode", // 获取邮箱验证码 "/api/user/getPhoneCode", // 获取手机验证码 "/chat.html", - "/daxz.html/**", "/polling-chat.html", diff --git a/src/main/java/com/guwan/backend/controller/QuestionsController.java b/src/main/java/com/guwan/backend/controller/QuestionsController.java new file mode 100644 index 0000000..efa943c --- /dev/null +++ b/src/main/java/com/guwan/backend/controller/QuestionsController.java @@ -0,0 +1,111 @@ +package com.guwan.backend.controller; + + +import com.guwan.backend.common.Result; +import com.guwan.backend.pojo.entity.Questions; +import com.guwan.backend.service.QuestionsService; +import com.guwan.backend.util.MultipleChoiceCompare; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.web.bind.annotation.*; + +import org.springframework.beans.factory.annotation.Autowired; + +/** + * (Questions)表控制层 + * + * @author Guwan + * @since 2025-01-11 18:02:34 + */ +@RestController +@RequestMapping("api/common/questions") +public class QuestionsController { + /** + * 服务对象 + */ + @Autowired + private QuestionsService questionsService; + + /** + * 分页查询 + * + * @param questions 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @GetMapping + public Result> queryByPage(Questions questions, PageRequest pageRequest) { + // return Result.success(this.questionsService.queryByPage(questions, pageRequest)); + + return Result.success(); + + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + public Result queryById(@PathVariable("id") Integer id) { + return Result.success(this.questionsService.getById(id)); + } + + /** + * 新增数据 + * + * @param questions 实体 + * @return 新增结果 + */ + @PostMapping + public Result add(Questions questions) { + this.questionsService.save(questions); + return Result.success(); + } + + /** + * 编辑数据 + * + * @param questions 实体 + * @return 编辑结果 + */ + @PutMapping + public Result edit(Questions questions) { + //return Result.success(this.questionsService.update(questions)); + return Result.success(); + } + + /** + * 删除数据 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping + public Result deleteById(Integer id) { + return Result.success(this.questionsService.removeById(id)); + } + + @GetMapping("/compare") + public Result compare(Integer id) { + + Questions question = questionsService.getById(id); + + + System.out.println(MultipleChoiceCompare.compare(question.getPoint(), question.getChoices(), + "A")); + + System.out.println(MultipleChoiceCompare.compare(question.getPoint(), question.getChoices(), + "A, B")); + System.out.println(MultipleChoiceCompare.compare(question.getPoint(), question.getChoices(), + "A, C")); + + + return Result.success(); + + } + + +} + diff --git a/src/main/java/com/guwan/backend/generator/domain/Papers.java b/src/main/java/com/guwan/backend/generator/domain/Papers.java deleted file mode 100644 index a51ead0..0000000 --- a/src/main/java/com/guwan/backend/generator/domain/Papers.java +++ /dev/null @@ -1,76 +0,0 @@ -package generator.domain; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.util.Date; -import lombok.Data; - -/** - * - * @TableName papers - */ -@TableName(value ="papers") -@Data -public class Papers implements Serializable { - /** - * 试卷编号 - */ - @TableId(type = IdType.AUTO) - private Integer paperId; - - /** - * 试卷名称 - */ - private String paperName; - - /** - * 试卷描述 - */ - private String description; - - /** - * 命题人 - */ - private String paperSetter; - - /** - * 校对人 - */ - private String paperReviewer; - - /** - * 开始时间 - */ - private Date startTime; - - /** - * 结束时间 - */ - private Date endTime; - - /** - * 考试时间 - */ - private Integer duration; - - /** - * 试卷状态 - */ - private Object status; - - /** - * 创建时间 - */ - private Date createdTime; - - /** - * 修改时间 - */ - private Date updatedTime; - - @TableField(exist = false) - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/generator/mapper/PapersMapper.java b/src/main/java/com/guwan/backend/generator/mapper/PapersMapper.java deleted file mode 100644 index 85e43bf..0000000 --- a/src/main/java/com/guwan/backend/generator/mapper/PapersMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package generator.mapper; - -import generator.domain.Papers; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** -* @author 12455 -* @description 针对表【papers】的数据库操作Mapper -* @createDate 2025-01-11 12:09:52 -* @Entity generator.domain.Papers -*/ -public interface PapersMapper extends BaseMapper { - -} - - - - diff --git a/src/main/java/com/guwan/backend/generator/service/PapersService.java b/src/main/java/com/guwan/backend/generator/service/PapersService.java deleted file mode 100644 index 012e9f1..0000000 --- a/src/main/java/com/guwan/backend/generator/service/PapersService.java +++ /dev/null @@ -1,13 +0,0 @@ -package generator.service; - -import generator.domain.Papers; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 12455 -* @description 针对表【papers】的数据库操作Service -* @createDate 2025-01-11 12:09:52 -*/ -public interface PapersService extends IService { - -} diff --git a/src/main/java/com/guwan/backend/generator/service/impl/PapersServiceImpl.java b/src/main/java/com/guwan/backend/generator/service/impl/PapersServiceImpl.java deleted file mode 100644 index 5d1c0a7..0000000 --- a/src/main/java/com/guwan/backend/generator/service/impl/PapersServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package generator.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import generator.domain.Papers; -import generator.service.PapersService; -import generator.mapper.PapersMapper; -import org.springframework.stereotype.Service; - -/** -* @author 12455 -* @description 针对表【papers】的数据库操作Service实现 -* @createDate 2025-01-11 12:09:52 -*/ -@Service -public class PapersServiceImpl extends ServiceImpl - implements PapersService{ - -} - - - - diff --git a/src/main/java/com/guwan/backend/mapper/QuestionsMapper.java b/src/main/java/com/guwan/backend/mapper/QuestionsMapper.java new file mode 100644 index 0000000..d831d3a --- /dev/null +++ b/src/main/java/com/guwan/backend/mapper/QuestionsMapper.java @@ -0,0 +1,18 @@ +package com.guwan.backend.mapper; + +import com.guwan.backend.pojo.entity.Questions; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author 12455 +* @description 针对表【questions】的数据库操作Mapper +* @createDate 2025-01-11 17:53:58 +* @Entity com.guwan.backend.pojo.entity.Questions +*/ +public interface QuestionsMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/guwan/backend/pojo/entity/Questions.java b/src/main/java/com/guwan/backend/pojo/entity/Questions.java new file mode 100644 index 0000000..756f4a0 --- /dev/null +++ b/src/main/java/com/guwan/backend/pojo/entity/Questions.java @@ -0,0 +1,71 @@ +package com.guwan.backend.pojo.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * + * @TableName questions + */ +@TableName(value ="questions") +@Data +public class Questions implements Serializable { + /** + * 试题编号 + */ + @TableId(type = IdType.AUTO) + private Integer questionId; + + /** + * 试题类型 + */ + + private String questionType; + + + /** + * 内容 + */ + private String content; + + /** + * 参考答案 + */ + private String answer; + + /** + * 选项 + */ + private String choices; + + /** + * 分数 + */ + private Double point; + + /** + * 创建时间 + */ + @DateTimeFormat + @JsonFormat + private LocalDateTime createdTime; + + /** + * 修改时间 + */ + @DateTimeFormat + @JsonFormat + private LocalDateTime updatedTime; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/pojo/enums/QuestionType.java b/src/main/java/com/guwan/backend/pojo/enums/QuestionType.java new file mode 100644 index 0000000..d0e883c --- /dev/null +++ b/src/main/java/com/guwan/backend/pojo/enums/QuestionType.java @@ -0,0 +1,17 @@ +package com.guwan.backend.pojo.enums; + +public enum QuestionType { + //单选题 + singleChoiceQuestion, + //多选题 + multipleChoiceQuestion, + //判断题 + trueOrFalseQuestions, + //填空题 + gapFilling, + //简答题 + shortAnswerQuestion, + //编程题 + programmingProblem + +} diff --git a/src/main/java/com/guwan/backend/service/QuestionsService.java b/src/main/java/com/guwan/backend/service/QuestionsService.java new file mode 100644 index 0000000..b4d9207 --- /dev/null +++ b/src/main/java/com/guwan/backend/service/QuestionsService.java @@ -0,0 +1,13 @@ +package com.guwan.backend.service; + +import com.guwan.backend.pojo.entity.Questions; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author 12455 +* @description 针对表【questions】的数据库操作Service +* @createDate 2025-01-11 17:53:58 +*/ +public interface QuestionsService extends IService { + +} diff --git a/src/main/java/com/guwan/backend/service/impl/QuestionsServiceImpl.java b/src/main/java/com/guwan/backend/service/impl/QuestionsServiceImpl.java new file mode 100644 index 0000000..c450356 --- /dev/null +++ b/src/main/java/com/guwan/backend/service/impl/QuestionsServiceImpl.java @@ -0,0 +1,22 @@ +package com.guwan.backend.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.guwan.backend.pojo.entity.Questions; +import com.guwan.backend.service.QuestionsService; +import com.guwan.backend.mapper.QuestionsMapper; +import org.springframework.stereotype.Service; + +/** +* @author 12455 +* @description 针对表【questions】的数据库操作Service实现 +* @createDate 2025-01-11 17:53:58 +*/ +@Service +public class QuestionsServiceImpl extends ServiceImpl + implements QuestionsService{ + +} + + + + diff --git a/src/main/java/com/guwan/backend/util/MultipleChoiceCompare.java b/src/main/java/com/guwan/backend/util/MultipleChoiceCompare.java new file mode 100644 index 0000000..03a9c83 --- /dev/null +++ b/src/main/java/com/guwan/backend/util/MultipleChoiceCompare.java @@ -0,0 +1,61 @@ +package com.guwan.backend.util; + +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +public class MultipleChoiceCompare { + + public static Double compare(Double point, String rightAnswer, + String input) { + + + String cleanedAnswer = rightAnswer.replaceAll("[\\[\\]]", ""); + + + String[] split = cleanedAnswer.split(","); + + + // 创建 Set 存储正确答案 + Set correctAnswersSet = new HashSet<>(); + + int correctAnswerNum = 0; + + for (String s : split) { + correctAnswersSet.add(s.trim()); // 将每个元素加入 Set + correctAnswerNum++; + } + + + + + String[] split2 = input.split(","); + + + int answerNum = 0; + + // 判断 split2 中的元素是否在 split 中 + for (String userAnswer : split2) { + if (correctAnswersSet.contains(userAnswer.trim())) { + answerNum++; + } else { + answerNum = -99; + } + } + + if (answerNum < 0) { + + return 0.0; + } + if (answerNum < correctAnswerNum) { + return point * 0.6; + } + if (answerNum == correctAnswerNum) { + return point; + } + + return null; + } + + +} diff --git a/src/main/resources/mapper/PapersMapper.xml b/src/main/resources/mapper/PapersMapper.xml deleted file mode 100644 index 7583364..0000000 --- a/src/main/resources/mapper/PapersMapper.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - paper_id,paper_name,description, - paper_setter,paper_reviewer,start_time, - end_time,duration,status, - created_time,updated_time - - diff --git a/src/test/java/com/guwan/backend/TestMultipleChoiceQuestion.java b/src/test/java/com/guwan/backend/TestMultipleChoiceQuestion.java new file mode 100644 index 0000000..2ccd65e --- /dev/null +++ b/src/test/java/com/guwan/backend/TestMultipleChoiceQuestion.java @@ -0,0 +1,74 @@ +package com.guwan.backend; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; + +public class TestMultipleChoiceQuestion { + public static void main(String[] args) { + + + Integer point = 5; + + + String rightAnswer = "[A, C]"; + + String cleanedAnswer = rightAnswer.replaceAll("[\\[\\]]", ""); + + Scanner scanner = new Scanner(System.in); + + // String input = scanner.nextLine(); + + + String[] split = cleanedAnswer.split(","); + + + // 创建 Set 存储正确答案 + Set correctAnswersSet = new HashSet<>(); + + int correctAnswerNum = 0; + + for (String s : split) { + correctAnswersSet.add(s.trim()); // 将每个元素加入 Set + correctAnswerNum++; + } + + + String input = scanner.nextLine(); + + String[] split2 = input.split(","); + + + int answerNum = 0; + + // 判断 split2 中的元素是否在 split 中 + for (String userAnswer : split2) { + if (correctAnswersSet.contains(userAnswer.trim())) { + answerNum++; + System.out.println(userAnswer + " is incorrect."); + } else { + answerNum = -99; + System.out.println(userAnswer + " is correct."); + } + } + + System.out.println("answerNum = " + answerNum); + + if (answerNum < 0) { + System.out.println("该题目得分为0分"); + return; + } + if (answerNum < correctAnswerNum) { + System.out.println("该题目得分为" + point * 0.6 + "分"); + return; + } + if (answerNum == correctAnswerNum) { + System.out.println("该题目得分为" + point + "分"); + } + + + } + +} +