You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
9.3 KiB
Java
188 lines
9.3 KiB
Java
|
4 weeks ago
|
package com.sztzjy.linkCommerce.controller.stu;
|
||
|
|
|
||
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
||
|
|
import com.sztzjy.linkCommerce.config.security.TokenProvider;
|
||
|
|
import com.sztzjy.linkCommerce.service.ExamService;
|
||
|
|
import com.sztzjy.linkCommerce.util.ResultEntity;
|
||
|
|
import io.swagger.annotations.Api;
|
||
|
|
import org.springframework.http.HttpStatus;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
import org.springframework.web.multipart.MultipartFile;
|
||
|
|
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
@Api(tags = "考试考核")
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("api/exams")
|
||
|
|
public class ExamController {
|
||
|
|
private final ExamService examService;
|
||
|
|
|
||
|
|
public ExamController(ExamService examService) {
|
||
|
|
this.examService = examService;
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/classes")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> classes(HttpServletRequest request) {
|
||
|
|
return ok(examService.teacherClasses(user(request)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/questions")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> questions(@RequestParam(required = false) String type,
|
||
|
|
@RequestParam(required = false) String keyword,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
return ok(examService.questions(user(request), type, keyword));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/questions")
|
||
|
|
public ResultEntity<Map<String, Object>> createQuestion(@RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "新增成功", examService.createQuestion(user(request), payload));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/teacher/questions/{id}")
|
||
|
|
public ResultEntity<Map<String, Object>> updateQuestion(@PathVariable long id, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||
|
|
return ok(examService.updateQuestion(user(request), id, payload));
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/teacher/questions/{id}")
|
||
|
|
public ResultEntity<Void> deleteQuestion(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
examService.deleteQuestion(user(request), id); return new ResultEntity<>(HttpStatus.OK, "删除成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/questions/attachment")
|
||
|
|
public ResultEntity<Map<String, Object>> questionAttachment(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
|
||
|
|
return ok(examService.uploadQuestionAttachment(user(request), file));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/questions/import")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> importQuestions(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功", examService.importQuestions(user(request), file));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/questions/template")
|
||
|
|
public void questionTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||
|
|
examService.teacherClasses(user(request)); examService.questionTemplate(response);
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> exams(@RequestParam(required = false) String keyword, HttpServletRequest request) {
|
||
|
|
return ok(examService.teacherExams(user(request), keyword));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}")
|
||
|
|
public ResultEntity<Map<String, Object>> exam(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
return ok(examService.teacherExam(user(request), id));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher")
|
||
|
|
public ResultEntity<Map<String, Object>> createExam(@RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "保存成功", examService.saveExam(user(request), null, payload));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/teacher/{id}")
|
||
|
|
public ResultEntity<Map<String, Object>> updateExam(@PathVariable long id, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||
|
|
return ok(examService.saveExam(user(request), id, payload));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/{id}/publish")
|
||
|
|
public ResultEntity<Void> publish(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
examService.publish(user(request), id); return new ResultEntity<>(HttpStatus.OK, "发布成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/{id}/withdraw")
|
||
|
|
public ResultEntity<Void> withdraw(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
examService.withdraw(user(request), id); return new ResultEntity<>(HttpStatus.OK, "撤回成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/teacher/{id}")
|
||
|
|
public ResultEntity<Void> deleteExam(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
examService.deleteExam(user(request), id); return new ResultEntity<>(HttpStatus.OK, "删除成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/paper")
|
||
|
|
public void exportPaper(@PathVariable long id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||
|
|
examService.exportPaper(user(request), id, response);
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/review")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> reviewStudents(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
return ok(examService.reviewStudents(user(request), id));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/review/{attemptId}")
|
||
|
|
public ResultEntity<Map<String, Object>> reviewDetail(@PathVariable long id, @PathVariable long attemptId, HttpServletRequest request) {
|
||
|
|
return ok(examService.reviewDetail(user(request), id, attemptId));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/teacher/{id}/review/{attemptId}")
|
||
|
|
public ResultEntity<Map<String, Object>> score(@PathVariable long id, @PathVariable long attemptId,
|
||
|
|
@RequestBody Map<String, Object> scores, HttpServletRequest request) {
|
||
|
|
return ok(examService.scoreSubjective(user(request), id, attemptId, scores));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teacher/{id}/review/{attemptId}/rollback")
|
||
|
|
public ResultEntity<Void> rollback(@PathVariable long id, @PathVariable long attemptId, HttpServletRequest request) {
|
||
|
|
examService.rollback(user(request), id, attemptId); return new ResultEntity<>(HttpStatus.OK, "回退成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/scores")
|
||
|
|
public void exportScores(@PathVariable long id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||
|
|
examService.exportScores(user(request), id, response);
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/analysis")
|
||
|
|
public ResultEntity<Map<String, Object>> analysis(@PathVariable long id, @RequestParam(required = false) String classId, HttpServletRequest request) {
|
||
|
|
return ok(examService.analysis(user(request), id, classId));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teacher/{id}/submissions")
|
||
|
|
public void exportSubmissions(@PathVariable long id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||
|
|
examService.exportSubmissions(user(request), id, response);
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/student")
|
||
|
|
public ResultEntity<List<Map<String, Object>>> studentExams(HttpServletRequest request) {
|
||
|
|
return ok(examService.studentExams(user(request)));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/student/{id}/enter")
|
||
|
|
public ResultEntity<Map<String, Object>> enter(@PathVariable long id, @RequestBody Map<String, String> payload, HttpServletRequest request) {
|
||
|
|
return ok(examService.enterExam(user(request), id, payload.get("deviceToken")));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/student/{id}/paper")
|
||
|
|
public ResultEntity<Map<String, Object>> paper(@PathVariable long id, @RequestParam String deviceToken, HttpServletRequest request) {
|
||
|
|
return ok(examService.activePaper(user(request), id, deviceToken));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/student/{id}/answers/{questionId}")
|
||
|
|
public ResultEntity<Void> saveAnswer(@PathVariable long id, @PathVariable long questionId,
|
||
|
|
@RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
||
|
|
examService.saveAnswer(user(request), id, questionId, String.valueOf(payload.get("deviceToken")), payload.get("answer"));
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "保存成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/student/{id}/answers/{questionId}/file")
|
||
|
|
public ResultEntity<Map<String, Object>> answerFile(@PathVariable long id, @PathVariable long questionId,
|
||
|
|
@RequestParam String deviceToken, @RequestPart("file") MultipartFile file,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
return ok(examService.uploadAnswerFile(user(request), id, questionId, deviceToken, file));
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/student/{id}/submit")
|
||
|
|
public ResultEntity<Map<String, Object>> submit(@PathVariable long id, @RequestBody Map<String, String> payload, HttpServletRequest request) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "交卷成功", examService.submit(user(request), id, payload.get("deviceToken")));
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/student/{id}/result")
|
||
|
|
public ResultEntity<Map<String, Object>> result(@PathVariable long id, HttpServletRequest request) {
|
||
|
|
return ok(examService.studentResult(user(request), id));
|
||
|
|
}
|
||
|
|
|
||
|
|
private JwtUser user(HttpServletRequest request) { return TokenProvider.getJWTUser(request); }
|
||
|
|
private <T> ResultEntity<T> ok(T data) { return new ResultEntity<>(HttpStatus.OK, "查询成功", data); }
|
||
|
|
}
|