package com.xjrsoft.module.student.controller; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xjrsoft.common.annotation.XjrLog; import com.xjrsoft.common.enums.RoleCodeEnum; import com.xjrsoft.common.model.result.RT; import com.xjrsoft.common.page.ConventPage; import com.xjrsoft.common.page.PageOutput; import com.xjrsoft.module.banding.service.IBandingTaskClassStudentService; import com.xjrsoft.module.student.dto.ChangeBandingStatusDto; import com.xjrsoft.module.student.dto.StudentReportRecordPageDto; import com.xjrsoft.module.student.dto.StudentReportSignDto; import com.xjrsoft.module.student.entity.StudentReportPlan; import com.xjrsoft.module.student.entity.StudentReportRecord; import com.xjrsoft.module.student.service.IStudentReportPlanService; import com.xjrsoft.module.student.service.IStudentReportRecordService; import com.xjrsoft.module.student.vo.StudentReportRecordExcelVo; import com.xjrsoft.module.student.vo.StudentReportRecordPlanPageVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.io.ByteArrayOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; /** * @title: 新生维护信息 * @Author dzx * @Date: 2024-06-27 * @Version 1.0 */ @RestController @RequestMapping("/student" + "/tryReadingReport") @Api(value = "/student" + "/tryReadingReport",tags = "试读报到模块代码") @AllArgsConstructor public class StudentTryReadingReportController { private final IStudentReportRecordService recordService; private final IBandingTaskClassStudentService classStudentService; private final IStudentReportPlanService reportPlanService; @GetMapping(value = "/page") @ApiOperation(value="试读报到(分页)") @SaCheckPermission("tryreadingreport:detail") @XjrLog(value="试读报到(分页)") public RT> page(@Valid StudentReportRecordPageDto dto){ List roleList = StpUtil.getRoleList(); if(roleList.contains("CLASSTE") && roleList.contains("TEACHER")){ dto.setTeacherId(StpUtil.getLoginIdAsLong()); } Page page = recordService.getTryReadingPage(new Page<>(dto.getLimit(), dto.getSize()), dto); PageOutput pageOutput = ConventPage.getPageOutput(page, StudentReportRecordPlanPageVo.class); return RT.ok(pageOutput); } @PostMapping("/clear-class") @ApiOperation(value = "非本班学生") @SaCheckPermission("tryreadingreport:add") @XjrLog(value="非本班学生") public RT clearClass(@Valid @RequestBody ChangeBandingStatusDto dto){ StudentReportRecord record = recordService.getById(dto.getId()); StudentReportPlan reportPlan = reportPlanService.getById(record.getStudentReportPlanId()); List list = new ArrayList<>(); list.add(record.getUserId()); classStudentService.removeStudent(list, reportPlan.getBandingTaskId()); return RT.ok(true); } @PostMapping(value = "/sign") @ApiOperation(value="试读报到") @SaCheckPermission("tryreadingreport:detail") @XjrLog(value="试读报到") public RT sign(@Valid @RequestBody StudentReportSignDto dto){ return RT.ok(recordService.tryReadingSign(dto)); } @PostMapping(value = "/all-sign") @ApiOperation(value="变更为已报到") @SaCheckPermission("tryreadingreport:detail") @XjrLog(value="试读报到") public RT sign(@Valid @RequestBody List ids){ for (Long id : ids) { recordService.tryReadingSign(new StudentReportSignDto(){{ setId(id); }}); } return RT.ok(true); } @PostMapping("/change-class") @ApiOperation(value = "调整班级") @SaCheckPermission("tryreadingreport:change-class") @XjrLog(value = "调整班级") public RT changeClass(@Valid @RequestBody StudentReportSignDto dto){ boolean isSuccess = recordService.changeClass(dto); return RT.ok(isSuccess); } @PostMapping(value = "/update-stduyStatus") @ApiOperation(value="切换就读方式") @SaCheckPermission("tryreadingreport:update-stduyStatus") @XjrLog(value = "切换就读方式") public RT updateStduyStatus(@Valid @RequestBody StudentReportSignDto dto){ boolean isSuccess = recordService.updateStduyStatusByTryReading(dto); return RT.ok(isSuccess); } @PostMapping(value = "/export-query") @ApiOperation(value="导出") @SaCheckPermission("studentreportrecord:detail") public ResponseEntity exportQuerty(@Valid @RequestBody StudentReportRecordPageDto dto){ List dataList = new ArrayList<>(); List roleList = StpUtil.getRoleList(); if(roleList.contains(RoleCodeEnum.TEACHER.getCode()) && roleList.contains(RoleCodeEnum.CLASSTE.getCode())){ if(dto.getClassId() == null){ dto.setTeacherId(StpUtil.getLoginIdAsLong()); } } List planPageList = recordService.getTryReadingList(dto); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (StudentReportRecordPlanPageVo pageVo : planPageList) { StudentReportRecordExcelVo excelVo = BeanUtil.toBean(pageVo, StudentReportRecordExcelVo.class); if(pageVo.getReportTime() != null){ excelVo.setReportTime(sdf.format(pageVo.getReportTime())); } excelVo.setIsReport("否"); if(pageVo.getIsReport() != null && pageVo.getIsReport() == 1){ excelVo.setIsReport("是"); } dataList.add(excelVo); } ByteArrayOutputStream bot = new ByteArrayOutputStream(); EasyExcel.write(bot, StudentReportRecordExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(dataList); String fileName = "exportQuerty" + ExcelTypeEnum.XLSX.getValue(); return RT.fileStream(bot.toByteArray(), fileName); } }