112 lines
2.7 KiB
Java
112 lines
2.7 KiB
Java
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.getAnswer(),
|
|
"A"));
|
|
|
|
System.out.println(MultipleChoiceCompare.compare(question.getPoint(), question.getAnswer(),
|
|
"A, B"));
|
|
System.out.println(MultipleChoiceCompare.compare(question.getPoint(), question.getAnswer(),
|
|
"A, C"));
|
|
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|