ExamPlanController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.xjrsoft.module.xycxedu.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.xjrsoft.common.model.result.RT;
  8. import com.xjrsoft.common.page.ConventPage;
  9. import com.xjrsoft.common.page.PageOutput;
  10. import com.xjrsoft.common.utils.VoToColumnUtil;
  11. import com.xjrsoft.module.xycxedu.dto.AddExamPlanDto;
  12. import com.xjrsoft.module.xycxedu.dto.ExamPlanPageDto;
  13. import com.xjrsoft.module.xycxedu.dto.UpdateExamPlanDto;
  14. import com.xjrsoft.module.xycxedu.entity.ExamPlan;
  15. import com.xjrsoft.module.xycxedu.entity.XycxeduExamList;
  16. import com.xjrsoft.module.xycxedu.service.IExamPlanService;
  17. import com.xjrsoft.module.xycxedu.service.IXycxeduExamListService;
  18. import com.xjrsoft.module.xycxedu.vo.ExamPlanPageVo;
  19. import com.xjrsoft.module.xycxedu.vo.ExamPlanVo;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import lombok.AllArgsConstructor;
  23. import org.springframework.web.bind.annotation.DeleteMapping;
  24. import org.springframework.web.bind.annotation.GetMapping;
  25. import org.springframework.web.bind.annotation.PostMapping;
  26. import org.springframework.web.bind.annotation.PutMapping;
  27. import org.springframework.web.bind.annotation.RequestBody;
  28. import org.springframework.web.bind.annotation.RequestMapping;
  29. import org.springframework.web.bind.annotation.RequestParam;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.validation.Valid;
  33. import java.io.IOException;
  34. import java.util.Arrays;
  35. import java.util.List;
  36. import java.util.stream.Collectors;
  37. /**
  38. * @title: 考试计划维护
  39. * @Author dzx
  40. * @Date: 2024-07-18
  41. * @Version 1.0
  42. */
  43. @RestController
  44. @RequestMapping("/xycxedu" + "/examPlan")
  45. @Api(value = "/xycxedu" + "/examPlan",tags = "考试计划维护代码")
  46. @AllArgsConstructor
  47. public class ExamPlanController {
  48. private final IExamPlanService examPlanService;
  49. private final IXycxeduExamListService examListService;
  50. @GetMapping(value = "/page")
  51. @ApiOperation(value="考试计划维护列表(分页)")
  52. @SaCheckPermission("examplan:detail")
  53. public RT<PageOutput<ExamPlanPageVo>> page(@Valid ExamPlanPageDto dto){
  54. LambdaQueryWrapper<ExamPlan> queryWrapper = new LambdaQueryWrapper<>();
  55. queryWrapper.orderByDesc(ExamPlan::getId)
  56. .eq(ExamPlan::getSemesterId, dto.getSemesterId())
  57. .like(ExamPlan::getName, dto.getName())
  58. .select(ExamPlan.class,x -> VoToColumnUtil.fieldsToColumns(ExamPlanPageVo.class).contains(x.getProperty()));
  59. IPage<ExamPlan> page = examPlanService.page(ConventPage.getPage(dto), queryWrapper);
  60. PageOutput<ExamPlanPageVo> pageOutput = ConventPage.getPageOutput(page, ExamPlanPageVo.class);
  61. for (ExamPlanPageVo record : pageOutput.getList()) {
  62. String[] split = record.getMilexamids().split(",");
  63. List<Long> milexamids = Arrays.asList(split).stream()
  64. .map(Long::parseLong)
  65. .collect(Collectors.toList());
  66. examListService.list(new QueryWrapper<XycxeduExamList>().lambda().in(XycxeduExamList::getMilexamid, milexamids));
  67. }
  68. return RT.ok(pageOutput);
  69. }
  70. @GetMapping(value = "/info")
  71. @ApiOperation(value="根据id查询考试计划维护信息")
  72. @SaCheckPermission("examplan:detail")
  73. public RT<ExamPlanVo> info(@RequestParam Long id){
  74. ExamPlan examPlan = examPlanService.getById(id);
  75. if (examPlan == null) {
  76. return RT.error("找不到此数据!");
  77. }
  78. return RT.ok(BeanUtil.toBean(examPlan, ExamPlanVo.class));
  79. }
  80. @PostMapping
  81. @ApiOperation(value = "新增考试计划维护")
  82. @SaCheckPermission("examplan:add")
  83. public RT<Boolean> add(@Valid @RequestBody AddExamPlanDto dto){
  84. ExamPlan examPlan = BeanUtil.toBean(dto, ExamPlan.class);
  85. boolean isSuccess = examPlanService.save(examPlan);
  86. return RT.ok(isSuccess);
  87. }
  88. @PutMapping
  89. @ApiOperation(value = "修改考试计划维护")
  90. @SaCheckPermission("examplan:edit")
  91. public RT<Boolean> update(@Valid @RequestBody UpdateExamPlanDto dto){
  92. ExamPlan examPlan = BeanUtil.toBean(dto, ExamPlan.class);
  93. return RT.ok(examPlanService.updateById(examPlan));
  94. }
  95. @DeleteMapping
  96. @ApiOperation(value = "删除考试计划维护")
  97. @SaCheckPermission("examplan:delete")
  98. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
  99. return RT.ok(examPlanService.removeBatchByIds(ids));
  100. }
  101. }