| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- 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<PageOutput<StudentReportPlanPageVo>> page(@Valid StudentReportPlanPageDto dto) {
- Page<StudentReportPlanPageVo> page = studentReportPlanService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
- PageOutput<StudentReportPlanPageVo> pageOutput = ConventPage.getPageOutput(page, StudentReportPlanPageVo.class);
- return RT.ok(pageOutput);
- }
- @GetMapping(value = "/info")
- @ApiOperation(value = "根据id查询学生报到计划信息")
- @SaCheckPermission("studentreportplan:detail")
- @XjrLog(value = "根据id查询学生报到计划信息")
- public RT<StudentReportPlanVo> info(@RequestParam Long id) {
- StudentReportPlan studentReportPlan = studentReportPlanService.getByIdDeep(id);
- if (studentReportPlan == null) {
- return RT.error("找不到此数据!");
- }
- StudentReportPlanVo planVo = BeanUtil.toBean(studentReportPlan, StudentReportPlanVo.class);
- List<Long> classIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
- List<BaseClass> classList = classService.listByIds(classIds);
- Map<Long, String> classMaps = classList.stream().collect(Collectors.toMap(BaseClass::getId, BaseClass::getName));
- List<StudentReportPlanClassRelationVo> 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<Boolean> 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<Boolean> 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<Boolean> delete(@Valid @RequestBody List<Long> ids) {
- return RT.ok(studentReportPlanService.delete(ids));
- }
- @PostMapping(value = "/change-status")
- @ApiOperation(value = "修改状态")
- @SaCheckPermission("classroom:detail")
- @XjrLog(value = "修改状态")
- public RT<Boolean> 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<StudentReportPlan> list = studentReportPlanService.list(
- new QueryWrapper<StudentReportPlan>().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<Long> classIds = reportPlan.getStudentReportPlanClassRelationList()
- .stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
- List<BaseClass> classList = studentReportPlanService.validateClass(dto.getId(), classIds);
- if (!classList.isEmpty()) {
- Set<String> 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<List<StudentReportPlanTreeVo>> tree() {
- List<Integer> statusList = new ArrayList<>();
- statusList.add(1);
- statusList.add(2);
- List<StudentReportPlan> list = studentReportPlanService.list(
- new QueryWrapper<StudentReportPlan>().lambda()
- .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
- .in(StudentReportPlan::getStatus, statusList)
- );
- Set<Long> semesterIds = list.stream().map(StudentReportPlan::getSemesterId).collect(Collectors.toSet());
- List<BaseSemester> semesterList = semesterService.list(
- new QueryWrapper<BaseSemester>().lambda()
- .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
- .orderByDesc(BaseSemester::getName)
- );
- List<StudentReportPlanTreeVo> 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<StudentReportPlanTreeVo> 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<StudentReportPlanVo> tryReadingPlan(@RequestParam Long id) {
- EnrollmentPlan enrollmentPlan = enrollmentPlanService.getById(id);
- StudentReportPlan plan = studentReportPlanService.getOne(
- new MPJLambdaWrapper<StudentReportPlan>()
- .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<StudentReportPlanVo> newStudentPlan(@RequestParam Long id) {
- EnrollmentPlan enrollmentPlan = enrollmentPlanService.getById(id);
- StudentReportPlan plan = studentReportPlanService.getOne(
- new MPJLambdaWrapper<StudentReportPlan>()
- .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));
- }
- }
|