StudentApplyController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.qmth.exam.reserve.controller.admin;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.net.URLEncoder;
  5. import java.util.*;
  6. import javax.servlet.http.HttpServletResponse;
  7. import com.qmth.boot.core.cache.service.CacheService;
  8. import com.qmth.boot.tools.excel.ExcelWriter;
  9. import com.qmth.boot.tools.excel.enums.ExcelType;
  10. import com.qmth.exam.reserve.bean.stdapply.*;
  11. import com.qmth.exam.reserve.service.*;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Qualifier;
  14. import org.springframework.web.bind.annotation.*;
  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.controller.BaseController;
  23. import com.qmth.exam.reserve.enums.Role;
  24. import com.qmth.exam.reserve.util.ResourceUtil;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import io.swagger.annotations.ApiParam;
  28. @RestController
  29. @Api(tags = "【管理端】考生预约明细相关接口")
  30. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/apply")
  31. @Aac(strict = false, auth = true)
  32. public class StudentApplyController extends BaseController {
  33. @Autowired
  34. private StudentApplyService studentApplyService;
  35. @Autowired
  36. private ApplyTaskService applyTaskService;
  37. @Autowired
  38. private CategoryService categoryService;
  39. @Autowired
  40. private ExamSiteService examSiteService;
  41. @ApiOperation(value = "预约任务列表")
  42. @PostMapping(value = "/task/list")
  43. public List<CategoryVO> listTask() {
  44. return applyTaskService.listTask();
  45. }
  46. @ApiOperation(value = "教学点列表")
  47. @PostMapping(value = "/teaching/list")
  48. public List<CategoryVO> listTeaching(@ApiParam("查询启用的教学点或查询所有的教学点") @RequestParam(required = false) Boolean flag) {
  49. LoginUser user = this.curLoginUser();
  50. return categoryService.listTeaching(user, flag);
  51. }
  52. @ApiOperation(value = "考点列表")
  53. @PostMapping(value = "/agent/list")
  54. public List<CategoryVO> listAgent(@ApiParam("教学点ID") @RequestParam Long id,
  55. @ApiParam("查询启用的考点或查询所有的考点") @RequestParam(required = false) Boolean flag) {
  56. return examSiteService.listExamSite(id, flag);
  57. }
  58. @ApiOperation(value = "考生预约名单详情分页")
  59. @PostMapping(value = "/std/page")
  60. public PageResult<StudentApplyVO> page(@RequestBody StudentApplyReq req) {
  61. LoginUser user = this.curLoginUser();
  62. if (user.getRole().equals(Role.TEACHING)) {
  63. req.setTeachingId(user.getCategoryId());
  64. }
  65. return studentApplyService.page(req);
  66. }
  67. @ApiOperation(value = "取消预约")
  68. @PostMapping(value = "/std/cancel")
  69. public void cancel(@ApiParam("预约结果ID") @RequestParam Long id) {
  70. LoginUser user = this.curLoginUser();
  71. studentApplyService.cancel(user, id);
  72. }
  73. @ApiOperation(value = "导入预考模版下载")
  74. @PostMapping(value = "/imp/template")
  75. public void download(HttpServletResponse response) {
  76. exportFile("导入预考模板.xlsx", ResourceUtil.getStream("templates/preExamImport.xlsx"));
  77. }
  78. @ApiOperation(value = "导入预考")
  79. @PostMapping(value = "/import")
  80. public Map<String, Object> importPreExamStd(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
  81. @ApiParam("教学点所在的层级") @RequestParam(required = false) Integer level, @RequestParam MultipartFile file) {
  82. LoginUser user = this.curLoginUser();
  83. if (Role.TEACHING.equals(user.getRole())) {
  84. teachingId = user.getCategoryId();
  85. }
  86. List<Map<String, Object>> failRecords = new ArrayList<>();
  87. try {
  88. failRecords = studentApplyService.importPreExam(user, teachingId, level, file.getInputStream());
  89. } catch (IOException e) {
  90. throw new StatusException("文件读取出错", e);
  91. }
  92. Map<String, Object> map = new HashMap<>();
  93. map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
  94. map.put("failRecords", failRecords);
  95. return map;
  96. }
  97. @ApiOperation(value = "一键自动分配")
  98. @PostMapping(value = "/std/auto/assign")
  99. public String autoAssign(@ApiParam("任务ID") @RequestParam Long taskId) {
  100. if (taskId == null) {
  101. throw new StatusException("请选择预约任务");
  102. }
  103. LoginUser user = this.curLoginUser();
  104. if (!Role.ADMIN.equals(user.getRole())) {
  105. throw new StatusException("没有权限");
  106. }
  107. studentApplyService.autoAssign(taskId, user.getId());
  108. return "后台正在执行中,请耐心等待!";
  109. }
  110. @ApiOperation(value = "打印签到表")
  111. @PostMapping(value = "/std/auto/sign/in/print")
  112. public void printSignIn(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
  113. @ApiParam("考点ID") @RequestParam(required = false) Long agentId,
  114. @ApiParam("考试日期") @RequestParam(required = true) Long examDate) {
  115. LoginUser user = this.curLoginUser();
  116. if (Role.ADMIN.equals(user.getRole()) && teachingId == null) {
  117. throw new StatusException("请选择教学点");
  118. }
  119. if (Role.TEACHING.equals(user.getRole())) {
  120. teachingId = user.getCategoryId();
  121. }
  122. File signInZip = studentApplyService.downloadSignIn(teachingId, agentId, examDate);
  123. exportFile(signInZip.getName(), signInZip);
  124. signInZip.delete();
  125. }
  126. @Aac(strict = false, auth = false)
  127. @ApiOperation(value = "自动排考")
  128. @PostMapping(value = "/std/auto/layout")
  129. public void autoLayout(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId) {
  130. // LoginUser user = this.curLoginUser();
  131. // if (!Role.ADMIN.equals(user.getRole())) {
  132. // throw new StatusException("没有权限");
  133. // }
  134. studentApplyService.autoLayout(teachingId);
  135. }
  136. @ApiOperation(value = "可打印签到表的日期")
  137. @PostMapping(value = "/sign/in/date")
  138. public List<SignInVO> listSignInDate(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
  139. return studentApplyService.listSignInDate(taskId);
  140. }
  141. @ApiOperation(value = "导出考场预约情况表")
  142. @PostMapping(value = "/export/teaching/available")
  143. public void exportApplyAvailable(@ApiParam("教学点ID") @RequestParam Long teachingId, HttpServletResponse response) {
  144. try {
  145. String fileName = URLEncoder.encode("考点预约情况表", "UTF-8");
  146. response.setHeader("Content-Disposition", "inline; filename=" + fileName + ".xlsx");
  147. response.setContentType("application/vnd.ms-excel");
  148. ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
  149. List<CategoryVO> examSiteList = examSiteService.listExamSite(teachingId, Boolean.FALSE);
  150. if(examSiteList == null || examSiteList.isEmpty()) {
  151. throw new StatusException("当前教学点下没有考点");
  152. }
  153. String[] columnNames = getColumnNames(examSiteList);
  154. String[] firstLineContents = getFirstLineContents(examSiteList);
  155. List<String[]> exportList = new ArrayList<>();
  156. exportList.add(firstLineContents);
  157. List<String[]> avaiableList = studentApplyService.listExamSiteAvailable(examSiteList);
  158. exportList.addAll(avaiableList);
  159. writer.writeDataArrays("考点预约情况表", null, columnNames, exportList.iterator());
  160. writer.output(response.getOutputStream());
  161. } catch (IOException e) {
  162. throw new StatusException(e.getMessage());
  163. }
  164. }
  165. private String[] getFirstLineContents(List<CategoryVO> examSiteList) {
  166. String[] result = new String[examSiteList.size()+1];
  167. result[0] = "考点容量";
  168. for (int i = 0; i < examSiteList.size(); i++) {
  169. CategoryVO category = examSiteList.get(i);
  170. result[i+1] = String.valueOf(category.getCapacity());
  171. }
  172. return result;
  173. }
  174. private String[] getColumnNames(List<CategoryVO> examSiteList) {
  175. String[] columnNames = new String[examSiteList.size()+1];
  176. columnNames[0] = "时段";
  177. for (int i = 0; i < examSiteList.size(); i++) {
  178. CategoryVO category = examSiteList.get(i);
  179. columnNames[i+1] = category.getName();
  180. }
  181. return columnNames;
  182. }
  183. }