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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.xjrsoft.common.annotation.XjrLog; import com.xjrsoft.common.enums.DeleteMark; import com.xjrsoft.common.enums.EnabledMark; import com.xjrsoft.common.exception.MyException; import com.xjrsoft.common.model.result.RT; import com.xjrsoft.common.page.ConventPage; import com.xjrsoft.common.page.PageOutput; import com.xjrsoft.common.utils.LocalDateTimeUtil; import com.xjrsoft.common.utils.TreeUtil; import com.xjrsoft.common.utils.VoToColumnUtil; import com.xjrsoft.module.banding.entity.BandingTask; import com.xjrsoft.module.base.entity.BaseClass; import com.xjrsoft.module.base.entity.BaseSemester; import com.xjrsoft.module.base.service.IBaseClassService; import com.xjrsoft.module.base.service.IBaseSemesterService; import com.xjrsoft.module.student.dto.AddStudentReportPlanDto; import com.xjrsoft.module.student.dto.StudentReportPlanPageDto; import com.xjrsoft.module.student.dto.StudentReportPlanStatusDto; import com.xjrsoft.module.student.dto.UpdateStudentReportPlanDto; import com.xjrsoft.module.student.entity.EnrollmentPlan; import com.xjrsoft.module.student.entity.StudentReportPlan; import com.xjrsoft.module.student.entity.StudentReportPlanClassRelation; import com.xjrsoft.module.student.service.IEnrollmentPlanService; import com.xjrsoft.module.student.service.IStudentReportPlanService; import com.xjrsoft.module.student.vo.StudentReportPlanClassRelationVo; import com.xjrsoft.module.student.vo.StudentReportPlanPageVo; import com.xjrsoft.module.student.vo.StudentReportPlanTreeVo; import com.xjrsoft.module.student.vo.StudentReportPlanVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; /** * @title: 学生报到计划 * @Author dzx * @Date: 2025-01-21 * @Version 1.0 */ @RestController @RequestMapping("/student" + "/studentReportPlan") @Api(value = "/student" + "/studentReportPlan", tags = "学生报到计划代码") @AllArgsConstructor public class StudentReportPlanController { private final IStudentReportPlanService studentReportPlanService; private final IBaseSemesterService semesterService; private final IBaseClassService classService; private final IEnrollmentPlanService enrollmentPlanService; @GetMapping(value = "/page") @ApiOperation(value = "学生报到计划列表(分页)") @SaCheckPermission("studentreportplan:detail") @XjrLog(value = "学生报到计划列表(分页)") public RT> page(@Valid StudentReportPlanPageDto dto) { Page page = studentReportPlanService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto); PageOutput pageOutput = ConventPage.getPageOutput(page, StudentReportPlanPageVo.class); return RT.ok(pageOutput); } @GetMapping(value = "/info") @ApiOperation(value = "根据id查询学生报到计划信息") @SaCheckPermission("studentreportplan:detail") @XjrLog(value = "根据id查询学生报到计划信息") public RT info(@RequestParam Long id) { StudentReportPlan studentReportPlan = studentReportPlanService.getByIdDeep(id); if (studentReportPlan == null) { return RT.error("找不到此数据!"); } StudentReportPlanVo planVo = BeanUtil.toBean(studentReportPlan, StudentReportPlanVo.class); List classIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList()); List classList = classService.listByIds(classIds); Map classMaps = classList.stream().collect(Collectors.toMap(BaseClass::getId, BaseClass::getName)); List classRelationList = planVo.getStudentReportPlanClassRelationList(); for (StudentReportPlanClassRelationVo baseClass : classRelationList) { baseClass.setClassName(classMaps.get(baseClass.getClassId())); } return RT.ok(planVo); } @PostMapping @ApiOperation(value = "新增学生报到计划") @SaCheckPermission("studentreportplan:add") @XjrLog(value = "新增学生报到计划") public RT add(@Valid @RequestBody AddStudentReportPlanDto dto) { StudentReportPlan studentReportPlan = BeanUtil.toBean(dto, StudentReportPlan.class); studentReportPlan.setCategory(1); boolean isSuccess = studentReportPlanService.add(studentReportPlan); return RT.ok(isSuccess); } @PutMapping @ApiOperation(value = "修改学生报到计划") @SaCheckPermission("studentreportplan:edit") @XjrLog(value = "修改学生报到计划") public RT update(@Valid @RequestBody UpdateStudentReportPlanDto dto) { StudentReportPlan reportPlan = studentReportPlanService.getById(dto.getId()); BeanUtil.copyProperties(dto, reportPlan); if((reportPlan.getCategory() == 2 || reportPlan.getCategory() == 3) && LocalDateTimeUtil.isDateTimeInRange(LocalDateTime.now(), reportPlan.getStartTime(), reportPlan.getEndTime())){ reportPlan.setStatus(1); } return RT.ok(studentReportPlanService.update(reportPlan)); } @DeleteMapping @ApiOperation(value = "删除学生报到计划") @SaCheckPermission("studentreportplan:delete") @XjrLog(value = "删除学生报到计划") public RT delete(@Valid @RequestBody List ids) { return RT.ok(studentReportPlanService.delete(ids)); } @PostMapping(value = "/change-status") @ApiOperation(value = "修改状态") @SaCheckPermission("classroom:detail") @XjrLog(value = "修改状态") public RT changeStatus(@Valid @RequestBody StudentReportPlanStatusDto dto) throws Exception { StudentReportPlan reportPlan = studentReportPlanService.getByIdDeep(dto.getId()); if (reportPlan == null) { throw new MyException("未能找到计划信息"); } //如果发布,需要先验证计划中的班级是否在其他生效的计划内 if (dto.getStatus() != null && dto.getStatus() == 1) { List list = studentReportPlanService.list( new QueryWrapper().lambda() .ne(StudentReportPlan::getId, reportPlan.getId()) .eq(StudentReportPlan::getEnabledMark, EnabledMark.ENABLED.getCode()) .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode()) .eq(StudentReportPlan::getStatus, 1) .ne(StudentReportPlan::getSemesterId, reportPlan.getSemesterId()) ); if (!list.isEmpty()) { throw new MyException("已存在正在进行的计划,无法发布"); } if (reportPlan.getStudentReportPlanClassRelationList() == null || reportPlan.getStudentReportPlanClassRelationList().isEmpty()) { return RT.error("未选择班级,无法进行发布"); } List classIds = reportPlan.getStudentReportPlanClassRelationList() .stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList()); List classList = studentReportPlanService.validateClass(dto.getId(), classIds); if (!classList.isEmpty()) { Set classNames = classList.stream().map(BaseClass::getName).collect(Collectors.toSet()); return RT.error(classNames.toString().replace("[", "").replace("]", "") + "已在其他计划中,无法发布"); } if (reportPlan.getStatus() == 1) { return RT.error("已发布,无法再次发布"); } LocalDateTime now = LocalDateTime.now(); if (now.isAfter(reportPlan.getStartTime())) { studentReportPlanService.release(reportPlan); } reportPlan.setStatus(dto.getStatus()); reportPlan.setModifyDate(new Date()); reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong()); studentReportPlanService.update(reportPlan); } else if (dto.getStatus() != null && dto.getStatus() == 2) { reportPlan.setStatus(dto.getStatus()); reportPlan.setModifyDate(new Date()); reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong()); studentReportPlanService.update(reportPlan); } return RT.ok(true); } @GetMapping(value = "/tree") @ApiOperation(value = "学期计划树") @SaCheckPermission("studentreportplan:detail") @XjrLog(value = "学期计划树") public RT> tree() { List statusList = new ArrayList<>(); statusList.add(1); statusList.add(2); List list = studentReportPlanService.list( new QueryWrapper().lambda() .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode()) .in(StudentReportPlan::getStatus, statusList) ); Set semesterIds = list.stream().map(StudentReportPlan::getSemesterId).collect(Collectors.toSet()); List semesterList = semesterService.list( new QueryWrapper().lambda() .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode()) .orderByDesc(BaseSemester::getName) ); List resultList = new ArrayList<>(); for (BaseSemester baseSemester : semesterList) { if (!semesterIds.contains(baseSemester.getId())) { continue; } resultList.add( new StudentReportPlanTreeVo() {{ setId(baseSemester.getId()); setName(baseSemester.getName()); }} ); } list.forEach((e -> { resultList.add( new StudentReportPlanTreeVo() {{ setId(e.getId()); setName(e.getName()); setParentId(e.getSemesterId()); setStatus(e.getStatus()); }} ); })); List treeVoList = TreeUtil.build(resultList); return RT.ok(treeVoList); } @GetMapping(value = "/try-reading-plan") @ApiOperation(value = "根据招生计划id查询试读报到计划信息") @SaCheckPermission("bandingrule:try-reading-plan") @XjrLog(value = "根据招生计划id查询试读报到计划信息") public RT tryReadingPlan(@RequestParam Long id) { EnrollmentPlan enrollmentPlan = enrollmentPlanService.getById(id); StudentReportPlan plan = studentReportPlanService.getOne( new MPJLambdaWrapper() .select(StudentReportPlan::getId) .select(StudentReportPlan.class, x -> VoToColumnUtil.fieldsToColumns(StudentReportPlan.class).contains(x.getProperty())) .innerJoin(BandingTask.class, BandingTask::getId, StudentReportPlan::getBandingTaskId) .eq(BandingTask::getEnrollType, enrollmentPlan.getEnrollType()) .eq(BandingTask::getGradeId, enrollmentPlan.getGradeId()) .eq(StudentReportPlan::getCategory, 2) ); if (plan == null) { return RT.error("未能查询到有报到学生,无法设置"); } return RT.ok(BeanUtil.toBean(plan, StudentReportPlanVo.class)); } @GetMapping(value = "/new-student-plan") @ApiOperation(value = "根据招生计划id查询新生报到计划信息") @SaCheckPermission("bandingrule:new-student-plan") @XjrLog(value = "根据招生计划id查询新生报到计划信息") public RT newStudentPlan(@RequestParam Long id) { EnrollmentPlan enrollmentPlan = enrollmentPlanService.getById(id); StudentReportPlan plan = studentReportPlanService.getOne( new MPJLambdaWrapper() .select(StudentReportPlan::getId) .select(StudentReportPlan.class, x -> VoToColumnUtil.fieldsToColumns(StudentReportPlan.class).contains(x.getProperty())) .innerJoin(BandingTask.class, BandingTask::getId, StudentReportPlan::getBandingTaskId) .eq(BandingTask::getEnrollType, enrollmentPlan.getEnrollType()) .eq(BandingTask::getGradeId, enrollmentPlan.getGradeId()) .eq(StudentReportPlan::getCategory, 3) ); if (plan == null) { return RT.error("未能查询到有报到学生,无法设置"); } return RT.ok(BeanUtil.toBean(plan, StudentReportPlanVo.class)); } }