package org.springblade.modules.exam.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.springblade.core.excel.util.ExcelUtil;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.exam.entity.ExamSubjectChoices;
|
import org.springblade.modules.exam.excel.ExamScoreExcel;
|
import org.springblade.modules.exam.excel.ExamScoreImporter;
|
import org.springblade.modules.exam.excel.ExamSubjectExcel;
|
import org.springblade.modules.exam.excel.ExamSubjectImporter;
|
import org.springblade.modules.exam.service.ExamSubjectChoicesService;
|
import org.springblade.modules.exam.vo.ExamSubjectChoicesVO;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author zhongrj
|
* @time 2021-07-16
|
* @desc 选择题管理控制层
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/examSubjectChoices")
|
public class ExamSubjectChoicesController {
|
|
private final ExamSubjectChoicesService examSubjectChoicesService;
|
|
/**
|
* 自定义分页
|
*
|
* @param query page,size
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@GetMapping("/page")
|
public R<IPage<ExamSubjectChoicesVO>> page(ExamSubjectChoicesVO examSubjectChoices, Query query) {
|
IPage<ExamSubjectChoicesVO> pages = examSubjectChoicesService.selectExamSubjectChoicesPage(Condition.getPage(query), examSubjectChoices);
|
return R.data(pages);
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
public R<IPage<ExamSubjectChoices>> list(ExamSubjectChoices examSubjectChoices, Query query) {
|
IPage<ExamSubjectChoices> pages = examSubjectChoicesService.page(Condition.getPage(query), Condition.getQueryWrapper(examSubjectChoices));
|
return R.data(pages);
|
}
|
|
|
/**
|
* 新增
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@PostMapping("/save")
|
@ApiOperation(value = "新增", notes = "传入examSubjectChoices")
|
public R save(@RequestBody ExamSubjectChoices examSubjectChoices) {
|
return R.status(examSubjectChoicesService.save(examSubjectChoices));
|
}
|
|
|
/**
|
* 新增题目及选项信息
|
*
|
* @param examSubjectChoices 题目信息对象
|
*/
|
@PostMapping("/saveSubjectChoicesAndOption")
|
@ApiOperation(value = "新增", notes = "传入examSubjectChoices")
|
public R saveSubjectChoicesAndOption(@RequestBody ExamSubjectChoicesVO examSubjectChoices) {
|
return R.status(examSubjectChoicesService.saveSubjectChoicesAndOption(examSubjectChoices));
|
}
|
|
/**
|
* 修改
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@PostMapping("/update")
|
public R update(@RequestBody ExamSubjectChoices examSubjectChoices) {
|
return R.status(examSubjectChoicesService.updateById(examSubjectChoices));
|
}
|
|
/**
|
* 新增或修改
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@PostMapping("/submit")
|
public R submit(@RequestBody ExamSubjectChoices examSubjectChoices) {
|
if (null != examSubjectChoices.getId()) {
|
examSubjectChoices.setCreateDate(new Date());
|
} else {
|
examSubjectChoices.setModifyDate(new Date());
|
}
|
return R.status(examSubjectChoicesService.saveOrUpdate(examSubjectChoices));
|
}
|
|
/**
|
* 删除
|
*
|
* @param ids 选择题信息ids 数组
|
*/
|
@PostMapping("/remove")
|
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
|
return R.status(examSubjectChoicesService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/**
|
* 详情
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@GetMapping("/detail")
|
@ApiOperation(value = "详情", notes = "传入examSubjectChoices")
|
public R<ExamSubjectChoices> detail(ExamSubjectChoices examSubjectChoices) {
|
//查询选择题详情
|
ExamSubjectChoices detail = examSubjectChoicesService.getOne(Condition.getQueryWrapper(examSubjectChoices));
|
//返回
|
return R.data(detail);
|
}
|
|
|
/**
|
* 详情(包含选项信息)
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@GetMapping("/details")
|
@ApiOperation(value = "详情", notes = "传入examSubjectChoices")
|
public R<ExamSubjectChoicesVO> details(ExamSubjectChoices examSubjectChoices) {
|
//查询选择题详情
|
ExamSubjectChoicesVO detail = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
|
//返回
|
return R.data(detail);
|
}
|
|
/**
|
* 获取下一题的题目,并判断上一题的答案,且返回上一题答题结果
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@GetMapping("/getSubjectResultInfo")
|
@ApiOperation(value = "详情", notes = "传入examSubjectChoices")
|
public R<ExamSubjectChoicesVO> getSubjectResultInfo(ExamSubjectChoicesVO examSubjectChoices) {
|
//查询下一题题目详情
|
ExamSubjectChoicesVO detail = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
|
//判断当前题目的答题结果
|
if (examSubjectChoices.getPreSubJectId() != null) {
|
if (null != examSubjectChoices.getPreResult() && examSubjectChoices.getPreResult() != "" && !examSubjectChoices.getPreResult().equals("")) {
|
detail.setResult(examSubjectChoicesService.getAnswerResult(examSubjectChoices.getPreSubJectId(), examSubjectChoices.getPreResult(), examSubjectChoices.getScoreId()));
|
} else {
|
//无
|
detail.setResult(3);
|
}
|
}
|
//返回
|
return R.data(detail);
|
}
|
|
/**
|
* 查询试卷包含的题目
|
*/
|
@GetMapping("/getEexPaperChoices")
|
public R<IPage<ExamSubjectChoicesVO>> getEexPaperChoices(ExamSubjectChoicesVO examSubjectChoices, Query query) {
|
IPage<ExamSubjectChoicesVO> pages = examSubjectChoicesService.getEexPaperChoices(Condition.getPage(query), examSubjectChoices);
|
return R.data(pages);
|
}
|
|
/**
|
* 修改单项题目分值
|
*/
|
@PostMapping("/updateChoicesValue")
|
public R updateChoicesValue(String id, String value) {
|
return R.status(examSubjectChoicesService.updateChoicesValue(id, value));
|
}
|
|
/**
|
* 导入题库
|
*
|
* @param isCovered 1 覆盖 0不覆盖
|
* @return
|
*/
|
@PostMapping("import-examSubject")
|
@ApiOperation(value = "导入题库", notes = "传入excel")
|
public R importExamScore(MultipartFile file, Integer isCovered) {
|
ExamSubjectImporter examSubjectImporter = new ExamSubjectImporter(examSubjectChoicesService, false);
|
ExcelUtil.save(file, examSubjectImporter, ExamSubjectExcel.class);
|
return R.success("操作成功");
|
}
|
|
/**
|
* 导出模板
|
*/
|
@GetMapping("export-template")
|
@ApiOperation(value = "导出模板")
|
public void exportUser(HttpServletResponse response) {
|
List<ExamSubjectExcel> list = new ArrayList<>();
|
ExcelUtil.export(response, "题库导入数据模板", "题库导入数据表", list, ExamSubjectExcel.class);
|
}
|
|
|
/**
|
* 获取下一题的题目,并判断上一题的答案,且返回上一题答题结果(app 模拟考试)
|
*
|
* @param examSubjectChoices 选择题信息对象
|
*/
|
@GetMapping("/getSubjectResultInfoBySimulate")
|
public R<ExamSubjectChoicesVO> getSubjectResultInfoBySimulate(ExamSubjectChoicesVO examSubjectChoices) {
|
//查询下一题题目详情
|
ExamSubjectChoicesVO detail = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
|
//判断当前题目的答题结果
|
if (examSubjectChoices.getPreSubJectId() != null) {
|
if (null != examSubjectChoices.getPreResult() && examSubjectChoices.getPreResult() != "" && !examSubjectChoices.getPreResult().equals("")) {
|
detail.setResult(examSubjectChoicesService.getAnswerResultBySimulate(examSubjectChoices.getPreSubJectId(), examSubjectChoices.getPreResult(), examSubjectChoices.getSimulateExamId()));
|
} else {
|
//无
|
detail.setResult(3);
|
}
|
}
|
//返回
|
return R.data(detail);
|
}
|
|
}
|