StudentApplyController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.qmth.exam.reserve.controller.admin;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.servlet.http.HttpServletResponse;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import org.springframework.web.multipart.MultipartFile;
  16. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  17. import com.qmth.boot.api.annotation.Aac;
  18. import com.qmth.boot.api.constant.ApiConstant;
  19. import com.qmth.boot.core.collection.PageResult;
  20. import com.qmth.boot.core.exception.StatusException;
  21. import com.qmth.exam.reserve.bean.login.LoginUser;
  22. import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
  23. import com.qmth.exam.reserve.bean.stdapply.SignInVO;
  24. import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
  25. import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
  26. import com.qmth.exam.reserve.controller.BaseController;
  27. import com.qmth.exam.reserve.enums.Role;
  28. import com.qmth.exam.reserve.service.ApplyTaskService;
  29. import com.qmth.exam.reserve.service.CategoryService;
  30. import com.qmth.exam.reserve.service.ExamSiteService;
  31. import com.qmth.exam.reserve.service.StudentApplyService;
  32. import com.qmth.exam.reserve.util.ResourceUtil;
  33. import io.swagger.annotations.Api;
  34. import io.swagger.annotations.ApiOperation;
  35. import io.swagger.annotations.ApiParam;
  36. @RestController
  37. @Api(tags = "考生预约明细相关接口")
  38. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/apply")
  39. @Aac(strict = false, auth = true)
  40. public class StudentApplyController extends BaseController {
  41. @Autowired
  42. private StudentApplyService studentApplyService;
  43. @Autowired
  44. private ApplyTaskService applyTaskService;
  45. @Autowired
  46. private CategoryService categoryService;
  47. @Autowired
  48. private ExamSiteService examSiteService;
  49. @ApiOperation(value = "预约任务列表")
  50. @PostMapping(value = "/task/list")
  51. public List<CategoryVO> listTask() {
  52. return applyTaskService.listTask();
  53. }
  54. @ApiOperation(value = "教学点列表")
  55. @PostMapping(value = "/teaching/list")
  56. public List<CategoryVO> listTeaching() {
  57. LoginUser user = this.curLoginUser();
  58. return categoryService.listTeaching(user);
  59. }
  60. @ApiOperation(value = "考点列表")
  61. @PostMapping(value = "/agent/list")
  62. public List<CategoryVO> listAgent(@ApiParam("教学点ID") @RequestParam Long id) {
  63. return examSiteService.listExamSite(id);
  64. }
  65. @ApiOperation(value = "考生预约名单详情分页")
  66. @PostMapping(value = "/std/page")
  67. public PageResult<StudentApplyVO> page(@RequestBody StudentApplyReq req) {
  68. LoginUser user = this.curLoginUser();
  69. if (user.getRole().equals(Role.TEACHING)) {
  70. req.setTeachingId(user.getCategoryId());
  71. }
  72. return studentApplyService.page(req);
  73. }
  74. @ApiOperation(value = "取消预约")
  75. @PostMapping(value = "/std/cancel")
  76. public void cancel(@ApiParam("预约结果ID") @RequestParam Long id) {
  77. LoginUser user = this.curLoginUser();
  78. studentApplyService.cancel(user, id);
  79. }
  80. @ApiOperation(value = "导入预考模版下载")
  81. @PostMapping(value = "/imp/template")
  82. public void download(HttpServletResponse response) {
  83. exportFile("导入预考模板.xlsx", ResourceUtil.getStream("templates/preExamImport.xlsx"));
  84. }
  85. @ApiOperation(value = "导入预考")
  86. @PostMapping(value = "/import")
  87. public Map<String, Object> importPreExamStd(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
  88. @ApiParam("教学点所在的层级") @RequestParam(required = false) Integer level, @RequestParam MultipartFile file) {
  89. LoginUser user = this.curLoginUser();
  90. if (Role.TEACHING.equals(user.getRole())) {
  91. teachingId = user.getCategoryId();
  92. }
  93. List<Map<String, Object>> failRecords = new ArrayList<Map<String, Object>>();
  94. try {
  95. failRecords = studentApplyService.importPreExam(user, teachingId, level, file.getInputStream());
  96. } catch (IOException e) {
  97. throw new StatusException("文件读取出错", e);
  98. }
  99. Map<String, Object> map = new HashMap<>();
  100. map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
  101. map.put("failRecords", failRecords);
  102. return map;
  103. }
  104. @ApiOperation(value = "一键自动分配")
  105. @PostMapping(value = "/std/auto/assign")
  106. public String autoAssign(@ApiParam("任务ID") @RequestParam Long taskId) {
  107. if (taskId == null) {
  108. throw new StatusException("请选择预约任务");
  109. }
  110. LoginUser user = this.curLoginUser();
  111. if (!Role.ADMIN.equals(user.getRole())) {
  112. throw new StatusException("没有权限");
  113. }
  114. studentApplyService.autoAssign(taskId, user.getId());
  115. return "后台正在执行中,请耐心等待!";
  116. }
  117. @ApiOperation(value = "打印签到表")
  118. @PostMapping(value = "/std/auto/sign/in/print")
  119. public void printSignIn(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
  120. @ApiParam("考点ID") @RequestParam(required = false) Long agentId,
  121. @ApiParam("考试日期") @RequestParam(required = true) Long examDate) {
  122. LoginUser user = this.curLoginUser();
  123. if (Role.ADMIN.equals(user.getRole()) && teachingId == null) {
  124. throw new StatusException("请选择教学点");
  125. }
  126. if (Role.TEACHING.equals(user.getRole())) {
  127. teachingId = user.getCategoryId();
  128. }
  129. File signInZip = studentApplyService.downloadSignIn(teachingId, agentId, examDate);
  130. exportFile(signInZip.getName(), signInZip);
  131. signInZip.delete();
  132. }
  133. @Aac(strict = false, auth = false)
  134. @ApiOperation(value = "自动排考")
  135. @PostMapping(value = "/std/auto/layout")
  136. public void autoLayout(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId) {
  137. // LoginUser user = this.curLoginUser();
  138. // if (!Role.ADMIN.equals(user.getRole())) {
  139. // throw new StatusException("没有权限");
  140. // }
  141. studentApplyService.autoLayout(teachingId);
  142. }
  143. @ApiOperation(value = "可打印签到表的日期")
  144. @PostMapping(value = "/sign/in/date")
  145. public List<SignInVO> listSignInDate(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
  146. return studentApplyService.listSignInDate(taskId);
  147. }
  148. }