StudentReportPlanController.java 13 KB

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