InfraStudentController 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package cn.iocoder.yudao.module.infra.controller.admin.demo;
  2. import org.springframework.web.bind.annotation.*;
  3. import javax.annotation.Resource;
  4. import org.springframework.validation.annotation.Validated;
  5. import org.springframework.security.access.prepost.PreAuthorize;
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import io.swagger.v3.oas.annotations.Parameter;
  8. import io.swagger.v3.oas.annotations.Operation;
  9. import javax.validation.constraints.*;
  10. import javax.validation.*;
  11. import javax.servlet.http.*;
  12. import java.util.*;
  13. import java.io.IOException;
  14. import cn.iocoder.yudao.framework.common.pojo.PageParam;
  15. import cn.iocoder.yudao.framework.common.pojo.PageResult;
  16. import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  17. import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  18. import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  19. import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  20. import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  21. import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
  22. import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*;
  23. import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO;
  24. import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService;
  25. @Tag(name = "管理后台 - 学生")
  26. @RestController
  27. @RequestMapping("/infra/student")
  28. @Validated
  29. public class InfraStudentController {
  30. @Resource
  31. private InfraStudentService studentService;
  32. @PostMapping("/create")
  33. @Operation(summary = "创建学生")
  34. @PreAuthorize("@ss.hasPermission('infra:student:create')")
  35. public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) {
  36. return success(studentService.createStudent(createReqVO));
  37. }
  38. @PutMapping("/update")
  39. @Operation(summary = "更新学生")
  40. @PreAuthorize("@ss.hasPermission('infra:student:update')")
  41. public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) {
  42. studentService.updateStudent(updateReqVO);
  43. return success(true);
  44. }
  45. @DeleteMapping("/delete")
  46. @Operation(summary = "删除学生")
  47. @Parameter(name = "id", description = "编号", required = true)
  48. @PreAuthorize("@ss.hasPermission('infra:student:delete')")
  49. public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) {
  50. studentService.deleteStudent(id);
  51. return success(true);
  52. }
  53. @GetMapping("/get")
  54. @Operation(summary = "获得学生")
  55. @Parameter(name = "id", description = "编号", required = true, example = "1024")
  56. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  57. public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) {
  58. InfraStudentDO student = studentService.getStudent(id);
  59. return success(BeanUtils.toBean(student, InfraStudentRespVO.class));
  60. }
  61. @GetMapping("/page")
  62. @Operation(summary = "获得学生分页")
  63. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  64. public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) {
  65. PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO);
  66. return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class));
  67. }
  68. @GetMapping("/export-excel")
  69. @Operation(summary = "导出学生 Excel")
  70. @PreAuthorize("@ss.hasPermission('infra:student:export')")
  71. @OperateLog(type = EXPORT)
  72. public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO,
  73. HttpServletResponse response) throws IOException {
  74. pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  75. List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList();
  76. // 导出 Excel
  77. ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class,
  78. BeanUtils.toBean(list, InfraStudentRespVO.class));
  79. }
  80. }