StudentReportPlanController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.annotation.XjrLog;
  8. import com.xjrsoft.common.enums.DeleteMark;
  9. import com.xjrsoft.common.enums.EnabledMark;
  10. import com.xjrsoft.common.exception.MyException;
  11. import com.xjrsoft.common.model.result.RT;
  12. import com.xjrsoft.common.page.ConventPage;
  13. import com.xjrsoft.common.page.PageOutput;
  14. import com.xjrsoft.common.utils.TreeUtil;
  15. import com.xjrsoft.module.banding.entity.BandingTask;
  16. import com.xjrsoft.module.banding.service.IBandingTaskService;
  17. import com.xjrsoft.module.base.entity.BaseClass;
  18. import com.xjrsoft.module.base.entity.BaseSemester;
  19. import com.xjrsoft.module.base.service.IBaseClassService;
  20. import com.xjrsoft.module.base.service.IBaseSemesterService;
  21. import com.xjrsoft.module.student.dto.AddStudentReportPlanDto;
  22. import com.xjrsoft.module.student.dto.StudentReportPlanPageDto;
  23. import com.xjrsoft.module.student.dto.StudentReportPlanStatusDto;
  24. import com.xjrsoft.module.student.dto.UpdateStudentReportPlanDto;
  25. import com.xjrsoft.module.student.entity.StudentReportPlan;
  26. import com.xjrsoft.module.student.entity.StudentReportPlanClassRelation;
  27. import com.xjrsoft.module.student.service.IStudentReportPlanService;
  28. import com.xjrsoft.module.student.vo.StudentReportPlanClassRelationVo;
  29. import com.xjrsoft.module.student.vo.StudentReportPlanPageVo;
  30. import com.xjrsoft.module.student.vo.StudentReportPlanTreeVo;
  31. import com.xjrsoft.module.student.vo.StudentReportPlanVo;
  32. import io.swagger.annotations.Api;
  33. import io.swagger.annotations.ApiOperation;
  34. import lombok.AllArgsConstructor;
  35. import org.springframework.web.bind.annotation.DeleteMapping;
  36. import org.springframework.web.bind.annotation.GetMapping;
  37. import org.springframework.web.bind.annotation.PostMapping;
  38. import org.springframework.web.bind.annotation.PutMapping;
  39. import org.springframework.web.bind.annotation.RequestBody;
  40. import org.springframework.web.bind.annotation.RequestMapping;
  41. import org.springframework.web.bind.annotation.RequestParam;
  42. import org.springframework.web.bind.annotation.RestController;
  43. import javax.validation.Valid;
  44. import java.time.LocalDateTime;
  45. import java.util.ArrayList;
  46. import java.util.Date;
  47. import java.util.List;
  48. import java.util.Map;
  49. import java.util.Set;
  50. import java.util.stream.Collectors;
  51. /**
  52. * @title: 学生报到计划
  53. * @Author dzx
  54. * @Date: 2025-01-21
  55. * @Version 1.0
  56. */
  57. @RestController
  58. @RequestMapping("/student" + "/studentReportPlan")
  59. @Api(value = "/student" + "/studentReportPlan",tags = "学生报到计划代码")
  60. @AllArgsConstructor
  61. public class StudentReportPlanController {
  62. private final IStudentReportPlanService studentReportPlanService;
  63. private final IBaseSemesterService semesterService;
  64. private final IBaseClassService classService;
  65. private final IBandingTaskService taskService;
  66. @GetMapping(value = "/page")
  67. @ApiOperation(value="学生报到计划列表(分页)")
  68. @SaCheckPermission("studentreportplan:detail")
  69. @XjrLog(value="学生报到计划列表(分页)")
  70. public RT<PageOutput<StudentReportPlanPageVo>> page(@Valid StudentReportPlanPageDto dto){
  71. Page<StudentReportPlanPageVo> page = studentReportPlanService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
  72. PageOutput<StudentReportPlanPageVo> pageOutput = ConventPage.getPageOutput(page, StudentReportPlanPageVo.class);
  73. return RT.ok(pageOutput);
  74. }
  75. @GetMapping(value = "/info")
  76. @ApiOperation(value="根据id查询学生报到计划信息")
  77. @SaCheckPermission("studentreportplan:detail")
  78. @XjrLog(value="根据id查询学生报到计划信息")
  79. public RT<StudentReportPlanVo> info(@RequestParam Long id){
  80. StudentReportPlan studentReportPlan = studentReportPlanService.getByIdDeep(id);
  81. if (studentReportPlan == null) {
  82. return RT.error("找不到此数据!");
  83. }
  84. StudentReportPlanVo planVo = BeanUtil.toBean(studentReportPlan, StudentReportPlanVo.class);
  85. List<Long> classIds = studentReportPlan.getStudentReportPlanClassRelationList().stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
  86. List<BaseClass> classList = classService.listByIds(classIds);
  87. Map<Long, String> classMaps = classList.stream().collect(Collectors.toMap(BaseClass::getId, BaseClass::getName));
  88. List<StudentReportPlanClassRelationVo> classRelationList = planVo.getStudentReportPlanClassRelationList();
  89. for (StudentReportPlanClassRelationVo baseClass : classRelationList) {
  90. baseClass.setClassName(classMaps.get(baseClass.getClassId()));
  91. }
  92. return RT.ok(planVo);
  93. }
  94. @PostMapping
  95. @ApiOperation(value = "新增学生报到计划")
  96. @SaCheckPermission("studentreportplan:add")
  97. @XjrLog(value="新增学生报到计划")
  98. public RT<Boolean> add(@Valid @RequestBody AddStudentReportPlanDto dto){
  99. StudentReportPlan studentReportPlan = BeanUtil.toBean(dto, StudentReportPlan.class);
  100. boolean isSuccess = studentReportPlanService.add(studentReportPlan);
  101. return RT.ok(isSuccess);
  102. }
  103. @PutMapping
  104. @ApiOperation(value = "修改学生报到计划")
  105. @SaCheckPermission("studentreportplan:edit")
  106. @XjrLog(value="修改学生报到计划")
  107. public RT<Boolean> update(@Valid @RequestBody UpdateStudentReportPlanDto dto){
  108. StudentReportPlan studentReportPlan = BeanUtil.toBean(dto, StudentReportPlan.class);
  109. return RT.ok(studentReportPlanService.update(studentReportPlan));
  110. }
  111. @DeleteMapping
  112. @ApiOperation(value = "删除学生报到计划")
  113. @SaCheckPermission("studentreportplan:delete")
  114. @XjrLog(value="删除学生报到计划")
  115. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
  116. return RT.ok(studentReportPlanService.delete(ids));
  117. }
  118. @PostMapping(value = "/change-status")
  119. @ApiOperation(value="修改状态")
  120. @SaCheckPermission("classroom:detail")
  121. @XjrLog(value="修改状态")
  122. public RT<Boolean> changeStatus(@Valid @RequestBody StudentReportPlanStatusDto dto) throws Exception {
  123. StudentReportPlan reportPlan = studentReportPlanService.getByIdDeep(dto.getId());
  124. if(reportPlan == null){
  125. throw new MyException("未能找到计划信息");
  126. }
  127. //如果发布,需要先验证计划中的班级是否在其他生效的计划内
  128. if(dto.getStatus() != null && dto.getStatus() == 1){
  129. List<StudentReportPlan> list = studentReportPlanService.list(
  130. new QueryWrapper<StudentReportPlan>().lambda()
  131. .ne(StudentReportPlan::getId, reportPlan.getId())
  132. .eq(StudentReportPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
  133. .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  134. .eq(StudentReportPlan::getStatus, 1)
  135. .ne(StudentReportPlan::getSemesterId, reportPlan.getSemesterId())
  136. );
  137. if(!list.isEmpty()){
  138. throw new MyException("已存在正在进行的计划,无法发布");
  139. }
  140. if(reportPlan.getStudentReportPlanClassRelationList() == null || reportPlan.getStudentReportPlanClassRelationList().isEmpty()){
  141. return RT.error("未选择班级,无法进行发布");
  142. }
  143. List<Long> classIds = reportPlan.getStudentReportPlanClassRelationList()
  144. .stream().map(StudentReportPlanClassRelation::getClassId).collect(Collectors.toList());
  145. List<BaseClass> classList = studentReportPlanService.validateClass(dto.getId(), classIds);
  146. if(!classList.isEmpty()){
  147. Set<String> classNames = classList.stream().map(BaseClass::getName).collect(Collectors.toSet());
  148. return RT.error(classNames.toString().replace("[", "").replace("]", "") + "已在其他计划中,无法发布");
  149. }
  150. if(reportPlan.getStatus() == 1){
  151. return RT.error("已发布,无法再次发布");
  152. }
  153. LocalDateTime now = LocalDateTime.now();
  154. if(now.isAfter(reportPlan.getStartTime())){
  155. studentReportPlanService.release(reportPlan);
  156. }
  157. reportPlan.setStatus(dto.getStatus());
  158. reportPlan.setModifyDate(new Date());
  159. reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong());
  160. studentReportPlanService.update(reportPlan);
  161. }else if(dto.getStatus() != null && dto.getStatus() == 2){
  162. reportPlan.setStatus(dto.getStatus());
  163. reportPlan.setModifyDate(new Date());
  164. reportPlan.setModifyUserId(StpUtil.getLoginIdAsLong());
  165. studentReportPlanService.update(reportPlan);
  166. }
  167. return RT.ok(true);
  168. }
  169. @GetMapping(value = "/tree")
  170. @ApiOperation(value="学期计划树")
  171. @SaCheckPermission("studentreportplan:detail")
  172. @XjrLog(value="学期计划树")
  173. public RT<List<StudentReportPlanTreeVo>> tree(){
  174. List<Integer> statusList = new ArrayList<>();
  175. statusList.add(1);statusList.add(2);
  176. List<StudentReportPlan> list = studentReportPlanService.list(
  177. new QueryWrapper<StudentReportPlan>().lambda()
  178. .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  179. .in(StudentReportPlan::getStatus, statusList)
  180. );
  181. Set<Long> semesterIds = list.stream().map(StudentReportPlan::getSemesterId).collect(Collectors.toSet());
  182. List<BaseSemester> semesterList = semesterService.list(
  183. new QueryWrapper<BaseSemester>().lambda()
  184. .eq(BaseSemester::getDeleteMark, DeleteMark.NODELETE.getCode())
  185. .orderByDesc(BaseSemester::getName)
  186. );
  187. List<StudentReportPlanTreeVo> resultList = new ArrayList<>();
  188. for (BaseSemester baseSemester : semesterList) {
  189. if(!semesterIds.contains(baseSemester.getId())){
  190. continue;
  191. }
  192. resultList.add(
  193. new StudentReportPlanTreeVo(){{
  194. setId(baseSemester.getId());
  195. setName(baseSemester.getName());
  196. }}
  197. );
  198. }
  199. list.forEach((e->{
  200. resultList.add(
  201. new StudentReportPlanTreeVo(){{
  202. setId(e.getId());
  203. setName(e.getName());
  204. setParentId(e.getSemesterId());
  205. setStatus(e.getStatus());
  206. }}
  207. );
  208. }));
  209. List<StudentReportPlanTreeVo> treeVoList = TreeUtil.build(resultList);
  210. return RT.ok(treeVoList);
  211. }
  212. @GetMapping(value = "/try-reading-plan")
  213. @ApiOperation(value="根据分班任务id查询试读报到计划信息")
  214. @SaCheckPermission("bandingrule:try-reading-plan")
  215. @XjrLog(value="根据分班任务id查询试读报到计划信息")
  216. public RT<StudentReportPlanVo> tryReadingPlan(@RequestParam Long bandingTaskId){
  217. BandingTask bandingTask = taskService.getById(bandingTaskId);
  218. BaseSemester semester = semesterService.getCurrentSemester();
  219. StudentReportPlan plan = studentReportPlanService.getOne(
  220. new QueryWrapper<StudentReportPlan>().lambda()
  221. .eq(StudentReportPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  222. .eq(StudentReportPlan::getSemesterId, semester.getId())
  223. .eq(StudentReportPlan::getName, bandingTask.getName())
  224. );
  225. if (plan == null) {
  226. return RT.error("找不到此数据!");
  227. }
  228. return RT.ok(BeanUtil.toBean(plan, StudentReportPlanVo.class));
  229. }
  230. }