StudentAdminController.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.qmth.exam.reserve.controller.admin;
  2. import com.qmth.boot.api.annotation.Aac;
  3. import com.qmth.boot.api.constant.ApiConstant;
  4. import com.qmth.boot.core.collection.PageResult;
  5. import com.qmth.boot.core.exception.StatusException;
  6. import com.qmth.exam.reserve.bean.Constants;
  7. import com.qmth.exam.reserve.bean.login.LoginUser;
  8. import com.qmth.exam.reserve.bean.student.StudentReq;
  9. import com.qmth.exam.reserve.bean.student.StudentVO;
  10. import com.qmth.exam.reserve.controller.BaseController;
  11. import com.qmth.exam.reserve.enums.Role;
  12. import com.qmth.exam.reserve.service.StudentService;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.annotations.ApiParam;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.io.IOException;
  20. import java.util.Objects;
  21. @RestController
  22. @Api(tags = "【管理端】考生相关接口")
  23. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/student")
  24. @Aac(strict = false, auth = true)
  25. public class StudentAdminController extends BaseController {
  26. @Autowired
  27. private StudentService studentService;
  28. @ApiOperation(value = "考生管理分页")
  29. @PostMapping(value = "/page")
  30. public PageResult<StudentVO> page(@RequestBody StudentReq req) {
  31. LoginUser loginUser = this.curLoginUser();
  32. if(loginUser.getRole().equals(Role.TEACHING)) {
  33. req.setTeachingId(loginUser.getCategoryId());
  34. }
  35. return studentService.pageStudent(req);
  36. }
  37. @ApiOperation(value = "删除考生")
  38. @PostMapping(value = "/delete")
  39. public void delete(@ApiParam("考生ID") @RequestParam Long id) {
  40. LoginUser loginUser = this.curLoginUser();
  41. studentService.delete(id, loginUser.getId());
  42. }
  43. @ApiOperation(value = "修改考生可预约次数")
  44. @PostMapping(value = "/modify/apply/number")
  45. public void modifyApplyNumber(@ApiParam("考生ID") @RequestParam Long id, @ApiParam("可预约次数") @RequestParam Integer applyNumber) {
  46. LoginUser loginUser = this.curLoginUser();
  47. if (!loginUser.getRole().equals(Role.ADMIN)) {
  48. throw new StatusException("没有权限");
  49. }
  50. studentService.modifyApplyNumber(id, loginUser.getId(), applyNumber);
  51. }
  52. @ApiOperation(value = "上传考生的照片")
  53. @PostMapping(value = "upload/student/photo")
  54. public String uploadStudentPhoto(MultipartFile file) throws IOException {
  55. if (!Objects.requireNonNull(file.getOriginalFilename()).endsWith(".zip")) {
  56. throw new StatusException("请上传zip文件");
  57. }
  58. LoginUser loginUser = this.curLoginUser();
  59. studentService.uploadStudentPhoto(loginUser.getId(), file);
  60. return Constants.ASYNC_TIPS;
  61. }
  62. }