StudentTryReadingReportController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.xjrsoft.module.student.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import com.alibaba.excel.EasyExcel;
  6. import com.alibaba.excel.support.ExcelTypeEnum;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.xjrsoft.common.annotation.XjrLog;
  9. import com.xjrsoft.common.enums.RoleCodeEnum;
  10. import com.xjrsoft.common.model.result.RT;
  11. import com.xjrsoft.common.page.ConventPage;
  12. import com.xjrsoft.common.page.PageOutput;
  13. import com.xjrsoft.module.banding.service.IBandingTaskClassStudentService;
  14. import com.xjrsoft.module.student.dto.ChangeBandingStatusDto;
  15. import com.xjrsoft.module.student.dto.StudentReportRecordPageDto;
  16. import com.xjrsoft.module.student.dto.StudentReportSignDto;
  17. import com.xjrsoft.module.student.entity.StudentReportPlan;
  18. import com.xjrsoft.module.student.entity.StudentReportRecord;
  19. import com.xjrsoft.module.student.service.IStudentReportPlanService;
  20. import com.xjrsoft.module.student.service.IStudentReportRecordService;
  21. import com.xjrsoft.module.student.vo.StudentReportRecordExcelVo;
  22. import com.xjrsoft.module.student.vo.StudentReportRecordPlanPageVo;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import lombok.AllArgsConstructor;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.web.bind.annotation.GetMapping;
  28. import org.springframework.web.bind.annotation.PostMapping;
  29. import org.springframework.web.bind.annotation.RequestBody;
  30. import org.springframework.web.bind.annotation.RequestMapping;
  31. import org.springframework.web.bind.annotation.RestController;
  32. import javax.validation.Valid;
  33. import java.io.ByteArrayOutputStream;
  34. import java.text.SimpleDateFormat;
  35. import java.util.ArrayList;
  36. import java.util.List;
  37. /**
  38. * @title: 新生维护信息
  39. * @Author dzx
  40. * @Date: 2024-06-27
  41. * @Version 1.0
  42. */
  43. @RestController
  44. @RequestMapping("/student" + "/tryReadingReport")
  45. @Api(value = "/student" + "/tryReadingReport",tags = "试读报到模块代码")
  46. @AllArgsConstructor
  47. public class StudentTryReadingReportController {
  48. private final IStudentReportRecordService recordService;
  49. private final IBandingTaskClassStudentService classStudentService;
  50. private final IStudentReportPlanService reportPlanService;
  51. @GetMapping(value = "/page")
  52. @ApiOperation(value="试读报到(分页)")
  53. @SaCheckPermission("tryreadingreport:detail")
  54. @XjrLog(value="试读报到(分页)")
  55. public RT<PageOutput<StudentReportRecordPlanPageVo>> page(@Valid StudentReportRecordPageDto dto){
  56. List<String> roleList = StpUtil.getRoleList();
  57. if(roleList.contains("CLASSTE") && roleList.contains("TEACHER")){
  58. dto.setTeacherId(StpUtil.getLoginIdAsLong());
  59. }
  60. Page<StudentReportRecordPlanPageVo> page = recordService.getTryReadingPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  61. PageOutput<StudentReportRecordPlanPageVo> pageOutput = ConventPage.getPageOutput(page, StudentReportRecordPlanPageVo.class);
  62. return RT.ok(pageOutput);
  63. }
  64. @PostMapping("/clear-class")
  65. @ApiOperation(value = "非本班学生")
  66. @SaCheckPermission("tryreadingreport:add")
  67. @XjrLog(value="非本班学生")
  68. public RT<Boolean> clearClass(@Valid @RequestBody ChangeBandingStatusDto dto){
  69. StudentReportRecord record = recordService.getById(dto.getId());
  70. StudentReportPlan reportPlan = reportPlanService.getById(record.getStudentReportPlanId());
  71. List<Long> list = new ArrayList<>();
  72. list.add(record.getUserId());
  73. classStudentService.removeStudent(list, reportPlan.getBandingTaskId());
  74. return RT.ok(true);
  75. }
  76. @PostMapping(value = "/sign")
  77. @ApiOperation(value="试读报到")
  78. @SaCheckPermission("tryreadingreport:detail")
  79. @XjrLog(value="试读报到")
  80. public RT<Boolean> sign(@Valid @RequestBody StudentReportSignDto dto){
  81. return RT.ok(recordService.tryReadingSign(dto));
  82. }
  83. @PostMapping(value = "/all-sign")
  84. @ApiOperation(value="变更为已报到")
  85. @SaCheckPermission("tryreadingreport:detail")
  86. @XjrLog(value="试读报到")
  87. public RT<Boolean> sign(@Valid @RequestBody List<Long> ids){
  88. for (Long id : ids) {
  89. recordService.tryReadingSign(new StudentReportSignDto(){{
  90. setId(id);
  91. }});
  92. }
  93. return RT.ok(true);
  94. }
  95. @PostMapping("/change-class")
  96. @ApiOperation(value = "调整班级")
  97. @SaCheckPermission("tryreadingreport:change-class")
  98. @XjrLog(value = "调整班级")
  99. public RT<Boolean> changeClass(@Valid @RequestBody StudentReportSignDto dto){
  100. boolean isSuccess = recordService.changeClass(dto);
  101. return RT.ok(isSuccess);
  102. }
  103. @PostMapping(value = "/update-stduyStatus")
  104. @ApiOperation(value="切换就读方式")
  105. @SaCheckPermission("tryreadingreport:update-stduyStatus")
  106. @XjrLog(value = "切换就读方式")
  107. public RT<Boolean> updateStduyStatus(@Valid @RequestBody StudentReportSignDto dto){
  108. boolean isSuccess = recordService.updateStduyStatusByTryReading(dto);
  109. return RT.ok(isSuccess);
  110. }
  111. @PostMapping(value = "/export-query")
  112. @ApiOperation(value="导出")
  113. @SaCheckPermission("studentreportrecord:detail")
  114. public ResponseEntity<byte[]> exportQuerty(@Valid @RequestBody StudentReportRecordPageDto dto){
  115. List<StudentReportRecordExcelVo> dataList = new ArrayList<>();
  116. List<String> roleList = StpUtil.getRoleList();
  117. if(roleList.contains(RoleCodeEnum.TEACHER.getCode()) && roleList.contains(RoleCodeEnum.CLASSTE.getCode())){
  118. if(dto.getClassId() == null){
  119. dto.setTeacherId(StpUtil.getLoginIdAsLong());
  120. }
  121. }
  122. List<StudentReportRecordPlanPageVo> planPageList = recordService.getTryReadingList(dto);
  123. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  124. for (StudentReportRecordPlanPageVo pageVo : planPageList) {
  125. StudentReportRecordExcelVo excelVo = BeanUtil.toBean(pageVo, StudentReportRecordExcelVo.class);
  126. if(pageVo.getReportTime() != null){
  127. excelVo.setReportTime(sdf.format(pageVo.getReportTime()));
  128. }
  129. excelVo.setIsReport("否");
  130. if(pageVo.getIsReport() != null && pageVo.getIsReport() == 1){
  131. excelVo.setIsReport("是");
  132. }
  133. dataList.add(excelVo);
  134. }
  135. ByteArrayOutputStream bot = new ByteArrayOutputStream();
  136. EasyExcel.write(bot, StudentReportRecordExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList);
  137. String fileName = "exportQuerty" + ExcelTypeEnum.XLSX.getValue();
  138. return RT.fileStream(bot.toByteArray(), fileName);
  139. }
  140. }