InfraStudentController 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.dal.dataobject.demo.InfraStudentContactDO;
  25. import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO;
  26. import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService;
  27. @Tag(name = "管理后台 - 学生")
  28. @RestController
  29. @RequestMapping("/infra/student")
  30. @Validated
  31. public class InfraStudentController {
  32. @Resource
  33. private InfraStudentService studentService;
  34. @PostMapping("/create")
  35. @Operation(summary = "创建学生")
  36. @PreAuthorize("@ss.hasPermission('infra:student:create')")
  37. public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) {
  38. return success(studentService.createStudent(createReqVO));
  39. }
  40. @PutMapping("/update")
  41. @Operation(summary = "更新学生")
  42. @PreAuthorize("@ss.hasPermission('infra:student:update')")
  43. public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) {
  44. studentService.updateStudent(updateReqVO);
  45. return success(true);
  46. }
  47. @DeleteMapping("/delete")
  48. @Operation(summary = "删除学生")
  49. @Parameter(name = "id", description = "编号", required = true)
  50. @PreAuthorize("@ss.hasPermission('infra:student:delete')")
  51. public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) {
  52. studentService.deleteStudent(id);
  53. return success(true);
  54. }
  55. @GetMapping("/get")
  56. @Operation(summary = "获得学生")
  57. @Parameter(name = "id", description = "编号", required = true, example = "1024")
  58. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  59. public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) {
  60. InfraStudentDO student = studentService.getStudent(id);
  61. return success(BeanUtils.toBean(student, InfraStudentRespVO.class));
  62. }
  63. @GetMapping("/page")
  64. @Operation(summary = "获得学生分页")
  65. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  66. public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) {
  67. PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO);
  68. return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class));
  69. }
  70. @GetMapping("/export-excel")
  71. @Operation(summary = "导出学生 Excel")
  72. @PreAuthorize("@ss.hasPermission('infra:student:export')")
  73. @OperateLog(type = EXPORT)
  74. public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO,
  75. HttpServletResponse response) throws IOException {
  76. pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  77. List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList();
  78. // 导出 Excel
  79. ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class,
  80. BeanUtils.toBean(list, InfraStudentRespVO.class));
  81. }
  82. // ==================== 子表(学生联系人) ====================
  83. @GetMapping("/student-contact/page")
  84. @Operation(summary = "获得学生联系人分页")
  85. @Parameter(name = "studentId", description = "学生编号")
  86. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  87. public CommonResult<PageResult<InfraStudentContactDO>> getStudentContactPage(PageParam pageReqVO,
  88. @RequestParam("studentId") Long studentId) {
  89. return success(studentService.getStudentContactPage(pageReqVO, studentId));
  90. }
  91. @PostMapping("/student-contact/create")
  92. @Operation(summary = "创建学生联系人")
  93. @PreAuthorize("@ss.hasPermission('infra:student:create')")
  94. public CommonResult<Long> createStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) {
  95. return success(studentService.createStudentContact(studentContact));
  96. }
  97. @PutMapping("/student-contact/update")
  98. @Operation(summary = "更新学生联系人")
  99. @PreAuthorize("@ss.hasPermission('infra:student:update')")
  100. public CommonResult<Boolean> updateStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) {
  101. studentService.updateStudentContact(studentContact);
  102. return success(true);
  103. }
  104. @DeleteMapping("/student-contact/delete")
  105. @Parameter(name = "id", description = "编号", required = true)
  106. @Operation(summary = "删除学生联系人")
  107. @PreAuthorize("@ss.hasPermission('infra:student:delete')")
  108. public CommonResult<Boolean> deleteStudentContact(@RequestParam("id") Long id) {
  109. studentService.deleteStudentContact(id);
  110. return success(true);
  111. }
  112. @GetMapping("/student-contact/get")
  113. @Operation(summary = "获得学生联系人")
  114. @Parameter(name = "id", description = "编号", required = true)
  115. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  116. public CommonResult<InfraStudentContactDO> getStudentContact(@RequestParam("id") Long id) {
  117. return success(studentService.getStudentContact(id));
  118. }
  119. // ==================== 子表(学生班主任) ====================
  120. @GetMapping("/student-teacher/page")
  121. @Operation(summary = "获得学生班主任分页")
  122. @Parameter(name = "studentId", description = "学生编号")
  123. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  124. public CommonResult<PageResult<InfraStudentTeacherDO>> getStudentTeacherPage(PageParam pageReqVO,
  125. @RequestParam("studentId") Long studentId) {
  126. return success(studentService.getStudentTeacherPage(pageReqVO, studentId));
  127. }
  128. @PostMapping("/student-teacher/create")
  129. @Operation(summary = "创建学生班主任")
  130. @PreAuthorize("@ss.hasPermission('infra:student:create')")
  131. public CommonResult<Long> createStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) {
  132. return success(studentService.createStudentTeacher(studentTeacher));
  133. }
  134. @PutMapping("/student-teacher/update")
  135. @Operation(summary = "更新学生班主任")
  136. @PreAuthorize("@ss.hasPermission('infra:student:update')")
  137. public CommonResult<Boolean> updateStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) {
  138. studentService.updateStudentTeacher(studentTeacher);
  139. return success(true);
  140. }
  141. @DeleteMapping("/student-teacher/delete")
  142. @Parameter(name = "id", description = "编号", required = true)
  143. @Operation(summary = "删除学生班主任")
  144. @PreAuthorize("@ss.hasPermission('infra:student:delete')")
  145. public CommonResult<Boolean> deleteStudentTeacher(@RequestParam("id") Long id) {
  146. studentService.deleteStudentTeacher(id);
  147. return success(true);
  148. }
  149. @GetMapping("/student-teacher/get")
  150. @Operation(summary = "获得学生班主任")
  151. @Parameter(name = "id", description = "编号", required = true)
  152. @PreAuthorize("@ss.hasPermission('infra:student:query')")
  153. public CommonResult<InfraStudentTeacherDO> getStudentTeacher(@RequestParam("id") Long id) {
  154. return success(studentService.getStudentTeacher(id));
  155. }
  156. }