parent
756dea6abf
commit
0c6404829d
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ public class SecurityConstants {
|
|||
"/api/user/getEmailCode", // 获取邮箱验证码
|
||||
"/api/user/getPhoneCode", // 获取手机验证码
|
||||
"/chat.html",
|
||||
|
||||
"/daxz.html/**",
|
||||
|
||||
"/polling-chat.html",
|
||||
|
|
|
@ -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<Page<Questions>> queryByPage(Questions questions, PageRequest pageRequest) {
|
||||
// return Result.success(this.questionsService.queryByPage(questions, pageRequest));
|
||||
|
||||
return Result.success();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public Result<Questions> queryById(@PathVariable("id") Integer id) {
|
||||
return Result.success(this.questionsService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param questions 实体
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Questions> add(Questions questions) {
|
||||
this.questionsService.save(questions);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
*
|
||||
* @param questions 实体
|
||||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<Questions> edit(Questions questions) {
|
||||
//return Result.success(this.questionsService.update(questions));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
public Result<Boolean> 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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -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<Papers> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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<Papers> {
|
||||
|
||||
}
|
|
@ -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<PapersMapper, Papers>
|
||||
implements PapersService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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<Questions> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.guwan.backend.pojo.enums;
|
||||
|
||||
public enum QuestionType {
|
||||
//单选题
|
||||
singleChoiceQuestion,
|
||||
//多选题
|
||||
multipleChoiceQuestion,
|
||||
//判断题
|
||||
trueOrFalseQuestions,
|
||||
//填空题
|
||||
gapFilling,
|
||||
//简答题
|
||||
shortAnswerQuestion,
|
||||
//编程题
|
||||
programmingProblem
|
||||
|
||||
}
|
|
@ -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<Questions> {
|
||||
|
||||
}
|
|
@ -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<QuestionsMapper, Questions>
|
||||
implements QuestionsService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -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<String> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="generator.mapper.PapersMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="generator.domain.Papers">
|
||||
<id property="paperId" column="paper_id" jdbcType="INTEGER"/>
|
||||
<result property="paperName" column="paper_name" jdbcType="VARCHAR"/>
|
||||
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||
<result property="paperSetter" column="paper_setter" jdbcType="VARCHAR"/>
|
||||
<result property="paperReviewer" column="paper_reviewer" jdbcType="VARCHAR"/>
|
||||
<result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="duration" column="duration" jdbcType="INTEGER"/>
|
||||
<result property="status" column="status" jdbcType="OTHER"/>
|
||||
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
paper_id,paper_name,description,
|
||||
paper_setter,paper_reviewer,start_time,
|
||||
end_time,duration,status,
|
||||
created_time,updated_time
|
||||
</sql>
|
||||
</mapper>
|
|
@ -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<String> 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 + "分");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue