StudentReportPlanController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.xjrsoft.common.enums.DeleteMark;
  8. import com.xjrsoft.common.exception.MyException;
  9. import com.xjrsoft.common.model.result.RT;
  10. import com.xjrsoft.common.page.ConventPage;
  11. import com.xjrsoft.common.page.PageOutput;
  12. import com.xjrsoft.common.utils.TreeUtil;
  13. import com.xjrsoft.module.base.entity.BaseClass;
  14. import com.xjrsoft.module.base.entity.BaseSemester;
  15. import com.xjrsoft.module.base.service.IBaseSemesterService;
  16. import com.xjrsoft.module.student.dto.AddStudentReportPlanDto;
  17. import com.xjrsoft.module.student.dto.StudentReportPlanPageDto;
  18. import com.xjrsoft.module.student.dto.StudentReportPlanStatusDto;
  19. import com.xjrsoft.module.student.dto.UpdateStudentReportPlanDto;
  20. import com.xjrsoft.module.student.entity.StudentReportPlan;
  21. import com.xjrsoft.module.student.entity.StudentReportPlanClassRelation;
  22. import com.xjrsoft.module.student.service.IStudentReportPlanService;
  23. import com.xjrsoft.module.student.vo.BaseStudentTreeVo;
  24. import com.xjrsoft.module.student.vo.StudentReportPlanPageVo;
  25. import com.xjrsoft.module.student.vo.StudentReportPlanTreeVo;
  26. import com.xjrsoft.module.student.vo.StudentReportPlanVo;
  27. import io.swagger.annotations.Api;
  28. import io.swagger.annotations.ApiOperation;
  29. import lombok.AllArgsConstructor;
  30. import org.springframework.web.bind.annotation.DeleteMapping;
  31. import org.springframework.web.bind.annotation.GetMapping;
  32. import org.springframework.web.bind.annotation.PostMapping;
  33. import org.springframework.web.bind.annotation.PutMapping;
  34. import org.springframework.web.bind.annotation.RequestBody;
  35. import org.springframework.web.bind.annotation.RequestMapping;
  36. import org.springframework.web.bind.annotation.RequestParam;
  37. import org.springframework.web.bind.annotation.RestController;
  38. import javax.validation.Valid;
  39. import java.util.ArrayList;
  40. import java.util.Date;
  41. import java.util.List;
  42. import java.util.Set;
  43. import java.util.stream.Collectors;
  44. /**
  45. * @title: 学生报到计划
  46. * @Author dzx
  47. * @Date: 2025-01-21
  48. * @Version 1.0
  49. */
  50. @RestController
  51. @RequestMapping("/student" + "/studentReportPlan")
  52. @Api(value = "/student" + "/studentReportPlan",tags = "学生报到计划代码")
  53. @AllArgsConstructor
  54. public class StudentReportPlanController {
  55. private final IStudentReportPlanService studentReportPlanService;
  56. private final IBaseSemesterService semesterService;
  57. @GetMapping(value = "/page")
  58. @ApiOperation(value="学生报到计划列表(分页)")
  59. @SaCheckPermission("studentreportplan:detail")
  60. public RT<PageOutput<StudentReportPlanPageVo>> page(@Valid StudentReportPlanPageDto dto){
  61. Page<StudentReportPlanPageVo> page = studentReportPlanService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  62. PageOutput<StudentReportPlanPageVo> pageOutput = ConventPage.getPageOutput(page, StudentReportPlanPageVo.class);
  63. return RT.ok(pageOutput);
  64. }
  65. @GetMapping(value = "/info")
  66. @ApiOperation(value="根据id查询学生报到计划信息")
  67. @SaCheckPermission("studentreportplan:detail")
  68. public RT<StudentReportPlanVo> info(@RequestParam Long id){
  69. StudentReportPlan studentReportPlan = studentReportPlanService.getByIdDeep(id);
  70. if (studentReportPlan == null) {
  71. return RT.error("找不到此数据!");
  72. }
  73. return RT.ok(BeanUtil.toBean(studentReportPlan, StudentReportPlanVo.class));
  74. }
  75. @PostMapping
  76. @ApiOperation(value = "新增学生报到计划")
  77. @SaCheckPermission("studentreportplan:add")
  78. public RT<Boolean> add(@Valid @RequestBody AddStudentReportPlanDto dto){
  79. StudentReportPlan studentReportPlan = BeanUtil.toBean(dto, StudentReportPlan.class);
  80. boolean isSuccess = studentReportPlanService.add(studentReportPlan);
  81. return RT.ok(isSuccess);
  82. }
  83. @PutMapping
  84. @ApiOperation(value = "修改学生报到计划")
  85. @SaCheckPermission("studentreportplan:edit")
  86. public RT<Boolean> update(@Valid @RequestBody UpdateStudentReportPlanDto dto){
  87. StudentReportPlan studentReportPlan = BeanUtil.toBean(dto, StudentReportPlan.class);
  88. return RT.ok(studentReportPlanService.update(studentReportPlan));
  89. }
  90. @DeleteMapping
  91. @ApiOperation(value = "删除学生报到计划")
  92. @SaCheckPermission("studentreportplan:delete")
  93. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
  94. return RT.ok(studentReportPlanService.delete(ids));
  95. }
  96. @PostMapping(value = "/change-status")
  97. @ApiOperation(value="修改状态")
  98. @SaCheckPermission("classroom:detail")
  99. public RT<Boolean> changeStatus(@Valid @RequestBody StudentReportPlanStatusDto dto) throws Exception {
  100. StudentReportPlan reportPlan = studentReportPlanService.getByIdDeep(dto.getId());
  101. if(reportPlan == null){
  102. throw new MyException("未能找到计划信息");
  103. }
  104. //如果发布,需要先验证计划中的班级是否在其他生效的计划内
  105. if(dto.getStatus() != null && dto.getStatus() == 1){
  106. if(reportPlan.getStudentReportPlanClassRelationList() == null || !reportPlan.getStudentReportPlanClassRelationList().isEmpty()){
  107. return RT.error("未选择班级,无法进行发布");
  108. }
  109. List<Long> classIds = reportPlan.getStudentReportPlanClassRelationList()
  110. .stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
  111. List<BaseClass> classList = studentReportPlanService.validateClass(dto.getId(), classIds);
  112. if(classList.isEmpty()){
  113. Set<String> classNames = classList.stream().map(BaseClass::getName).collect(Collectors.toSet());
  114. return RT.error(classNames.toString().replace("[", "").replace("]", "") + "已在其他计划中,无法发布");
  115. }
  116. if(reportPlan.getStatus() == 1){
  117. return RT.error("已发布,无法再次发布");
  118. }
  119. studentReportPlanService.release(reportPlan);
  120. reportPlan.setStatus(dto.getStatus());
  121. reportPlan.setModifyDate(new Date());
  122. reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong());
  123. studentReportPlanService.update(reportPlan);
  124. }else if(dto.getStatus() != null && dto.getStatus() == 2){
  125. reportPlan.setStatus(dto.getStatus());
  126. reportPlan.setModifyDate(new Date());
  127. reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong());
  128. studentReportPlanService.update(reportPlan);
  129. }
  130. return RT.ok(true);
  131. }
  132. @GetMapping(value = "/tree")
  133. @ApiOperation(value="学期计划树")
  134. @SaCheckPermission("studentreportplan:detail")
  135. public RT<List<StudentReportPlanTreeVo>> tree(@RequestParam Long id){
  136. List<Integer> statusList = new ArrayList<>();
  137. statusList.add(1);statusList.add(2);
  138. List<StudentReportPlan> list = studentReportPlanService.list(
  139. new QueryWrapper<StudentReportPlan>().lambda()
  140. .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  141. .in(StudentReportPlan::getStatus, statusList)
  142. );
  143. Set<Long> semesterIds = list.stream().map(StudentReportPlan::getSemesterId).collect(Collectors.toSet());
  144. List<BaseSemester> semesterList = semesterService.list(
  145. new QueryWrapper<BaseSemester>().lambda()
  146. .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
  147. .orderByDesc(BaseSemester::getName)
  148. );
  149. List<StudentReportPlanTreeVo> resultList = new ArrayList<>();
  150. for (BaseSemester baseSemester : semesterList) {
  151. if(!semesterIds.contains(baseSemester.getId())){
  152. continue;
  153. }
  154. resultList.add(
  155. new StudentReportPlanTreeVo(){{
  156. setId(baseSemester.getId());
  157. setName(baseSemester.getName());
  158. }}
  159. );
  160. }
  161. list.forEach((e->{
  162. resultList.add(
  163. new StudentReportPlanTreeVo(){{
  164. setId(e.getId());
  165. setName(e.getName());
  166. setParentId(e.getSemesterId());
  167. }}
  168. );
  169. }));
  170. List<StudentReportPlanTreeVo> treeVoList = TreeUtil.build(resultList);
  171. return RT.ok(treeVoList);
  172. }
  173. }