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