GradeBatchController.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.qmth.distributed.print.api;
  2. import com.qmth.boot.api.constant.ApiConstant;
  3. import com.qmth.distributed.print.business.bean.params.analyze.GradeBatchParam;
  4. import com.qmth.distributed.print.business.bean.result.EditResult;
  5. import com.qmth.distributed.print.business.bean.result.analyze.GradeBatchResult;
  6. import com.qmth.distributed.print.business.entity.GradeBatch;
  7. import com.qmth.distributed.print.business.service.GradeBatchService;
  8. import com.qmth.distributed.print.business.templete.execute.AsyncTeachCloudReportService;
  9. import com.qmth.teachcloud.common.contant.SystemConstant;
  10. import com.qmth.teachcloud.common.entity.SysUser;
  11. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  12. import com.qmth.teachcloud.common.util.Result;
  13. import com.qmth.teachcloud.common.util.ResultUtil;
  14. import com.qmth.teachcloud.common.util.ServletUtil;
  15. import io.swagger.annotations.*;
  16. import org.springframework.validation.BindingResult;
  17. import org.springframework.validation.annotation.Validated;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.annotation.Resource;
  21. import javax.validation.Valid;
  22. import javax.validation.constraints.Max;
  23. import javax.validation.constraints.Min;
  24. import java.io.IOException;
  25. /**
  26. * <p>
  27. * 分析-批次表 前端控制器
  28. * </p>
  29. *
  30. * @author wangliang
  31. * @since 2022-05-20
  32. */
  33. @Api(tags = "分析批次管理Controller")
  34. @RestController
  35. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.grade}/batch")
  36. @Validated
  37. //@Aac(strict = BOOL.FALSE, auth = BOOL.FALSE)
  38. public class GradeBatchController {
  39. @Resource
  40. private GradeBatchService gradeBatchService;
  41. @Resource
  42. private AsyncTeachCloudReportService asyncTeachCloudReportService;
  43. @ApiOperation(value = "成绩分析批次-查询")
  44. @RequestMapping(value = "/page", method = RequestMethod.POST)
  45. @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = GradeBatchResult.class)})
  46. public Result findGradeBatchPage(@ApiParam(value = "分析批次名称") @RequestParam(required = false) String gradeBatchName,
  47. @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  48. @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  49. SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
  50. return ResultUtil.ok(gradeBatchService.gradeBatchPage(gradeBatchName, pageNumber, pageSize, requestUser));
  51. }
  52. @ApiOperation(value = "成绩分析批次-新建")
  53. @RequestMapping(value = "/save", method = RequestMethod.POST)
  54. @ApiResponses({@ApiResponse(code = 200, message = "更新成功", response = Result.class)})
  55. public Result saveGradeBatch(@Valid @RequestBody GradeBatchParam gradeBatchParam, BindingResult bindingResult) {
  56. if (bindingResult.hasErrors()) {
  57. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  58. }
  59. SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
  60. return ResultUtil.ok(gradeBatchService.editGradeBatch(gradeBatchParam, requestUser));
  61. }
  62. @ApiOperation(value = "成绩分析批次-删除")
  63. @RequestMapping(value = "/delete", method = RequestMethod.POST)
  64. @ApiResponses({@ApiResponse(code = 200, message = "删除成功", response = EditResult.class)})
  65. public Result deleteGradeBatch(@ApiParam(value = "选择的要删除的成绩分析批次id", required = true) @RequestParam String id) {
  66. GradeBatch gradeBatch = gradeBatchService.getById(SystemConstant.convertIdToLong(id));
  67. if(gradeBatch == null){
  68. throw ExceptionResultEnum.ERROR.exception("没有批次信息");
  69. }
  70. asyncTeachCloudReportService.deleteGradeBatch(gradeBatch);
  71. return ResultUtil.ok();
  72. }
  73. /**
  74. * 按批次下载考务数据
  75. *
  76. * @param batchId 批次ID
  77. */
  78. @ApiOperation(value = "成绩分析批次课程-考务数据下载")
  79. @RequestMapping(value = "/download", method = RequestMethod.POST)
  80. @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = EditResult.class)})
  81. public void downloadFile(@RequestParam Long batchId) throws IOException {
  82. gradeBatchService.downloadFile(batchId, ServletUtil.getResponse());
  83. }
  84. /**
  85. * 导入考务数据-包含任课老师信息
  86. *
  87. * @param batchId 批次ID
  88. * @param file 上传文件
  89. * @return
  90. */
  91. @ApiOperation(value = "成绩分析批次课程-考务数据导入")
  92. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  93. @ApiResponses({@ApiResponse(code = 200, message = "上传成功", response = EditResult.class)})
  94. public Result upload(@RequestParam Long batchId,
  95. @RequestParam MultipartFile file) throws IOException, NoSuchFieldException {
  96. gradeBatchService.uploadFile(batchId, file);
  97. return ResultUtil.success(true);
  98. }
  99. /**
  100. * 导入考务数据-包含任课老师信息
  101. *
  102. * @param batchId 批次ID
  103. */
  104. @ApiOperation(value = "成绩分析批次课程-批次同步")
  105. @RequestMapping(value = "/push", method = RequestMethod.POST)
  106. @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
  107. public Result batchSync(@RequestParam Long batchId) {
  108. GradeBatch gradeBatch = gradeBatchService.getById(batchId);
  109. if(gradeBatch == null){
  110. throw ExceptionResultEnum.ERROR.exception("没有批次信息");
  111. }
  112. asyncTeachCloudReportService.syncGradeBatch(gradeBatch);
  113. return ResultUtil.success(true);
  114. }
  115. /**
  116. * 成绩分析批次课程-开始计算
  117. *
  118. * @param batchId 批次ID
  119. */
  120. @ApiOperation(value = "成绩分析批次课程-开始计算")
  121. @RequestMapping(value = "/start_calc", method = RequestMethod.POST)
  122. @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
  123. public Result startCalc(@RequestParam Long batchId) {
  124. GradeBatch gradeBatch = gradeBatchService.getById(batchId);
  125. if(gradeBatch == null){
  126. throw ExceptionResultEnum.ERROR.exception("没有批次信息");
  127. }
  128. asyncTeachCloudReportService.startCalc(gradeBatch);
  129. return ResultUtil.success(true);
  130. }
  131. }