潘志宝
4 天以前 e14de70a3c4b393498d3e95717b19240c4426c22
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.controller.admin.demo.demo03;
H 2
3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageParam;
6 import com.iailab.framework.common.pojo.PageResult;
7 import com.iailab.framework.common.util.object.BeanUtils;
8 import com.iailab.framework.excel.core.util.ExcelUtils;
9 import com.iailab.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
10 import com.iailab.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO;
11 import com.iailab.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
12 import com.iailab.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
13 import com.iailab.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
14 import com.iailab.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
15 import com.iailab.module.infra.service.demo.demo03.Demo03StudentService;
16 import io.swagger.v3.oas.annotations.Operation;
17 import io.swagger.v3.oas.annotations.Parameter;
18 import io.swagger.v3.oas.annotations.tags.Tag;
19 import org.springframework.security.access.prepost.PreAuthorize;
20 import org.springframework.validation.annotation.Validated;
21 import org.springframework.web.bind.annotation.*;
22
23 import javax.annotation.Resource;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.validation.Valid;
26 import java.io.IOException;
27 import java.util.List;
28
29 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
30 import static com.iailab.framework.common.pojo.CommonResult.success;
31
32 @Tag(name = "管理后台 - 学生")
33 @RestController
34 @RequestMapping("/infra/demo03-student")
35 @Validated
36 public class Demo03StudentController {
37
38     @Resource
39     private Demo03StudentService demo03StudentService;
40
41     @PostMapping("/create")
42     @Operation(summary = "创建学生")
43     @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
44     public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO createReqVO) {
45         return success(demo03StudentService.createDemo03Student(createReqVO));
46     }
47
48     @PutMapping("/update")
49     @Operation(summary = "更新学生")
50     @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
51     public CommonResult<Boolean> updateDemo03Student(@Valid @RequestBody Demo03StudentSaveReqVO updateReqVO) {
52         demo03StudentService.updateDemo03Student(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:demo03-student:delete')")
60     public CommonResult<Boolean> deleteDemo03Student(@RequestParam("id") Long id) {
61         demo03StudentService.deleteDemo03Student(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:demo03-student:query')")
69     public CommonResult<Demo03StudentRespVO> getDemo03Student(@RequestParam("id") Long id) {
70         Demo03StudentDO demo03Student = demo03StudentService.getDemo03Student(id);
71         return success(BeanUtils.toBean(demo03Student, Demo03StudentRespVO.class));
72     }
73
74     @GetMapping("/page")
75     @Operation(summary = "获得学生分页")
76     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
77     public CommonResult<PageResult<Demo03StudentRespVO>> getDemo03StudentPage(@Valid Demo03StudentPageReqVO pageReqVO) {
78         PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(pageReqVO);
79         return success(BeanUtils.toBean(pageResult, Demo03StudentRespVO.class));
80     }
81
82     @GetMapping("/export-excel")
83     @Operation(summary = "导出学生 Excel")
84     @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')")
85     @ApiAccessLog(operateType = EXPORT)
86     public void exportDemo03StudentExcel(@Valid Demo03StudentPageReqVO pageReqVO,
87               HttpServletResponse response) throws IOException {
88         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
89         List<Demo03StudentDO> list = demo03StudentService.getDemo03StudentPage(pageReqVO).getList();
90         // 导出 Excel
91         ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentRespVO.class,
92                         BeanUtils.toBean(list, Demo03StudentRespVO.class));
93     }
94
95     // ==================== 子表(学生课程) ====================
96
97     @GetMapping("/demo03-course/page")
98     @Operation(summary = "获得学生课程分页")
99     @Parameter(name = "studentId", description = "学生编号")
100     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
101     public CommonResult<PageResult<Demo03CourseDO>> getDemo03CoursePage(PageParam pageReqVO,
102                                                                         @RequestParam("studentId") Long studentId) {
103         return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId));
104     }
105
106     @PostMapping("/demo03-course/create")
107     @Operation(summary = "创建学生课程")
108     @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
109     public CommonResult<Long> createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
110         return success(demo03StudentService.createDemo03Course(demo03Course));
111     }
112
113     @PutMapping("/demo03-course/update")
114     @Operation(summary = "更新学生课程")
115     @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
116     public CommonResult<Boolean> updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
117         demo03StudentService.updateDemo03Course(demo03Course);
118         return success(true);
119     }
120
121     @DeleteMapping("/demo03-course/delete")
122     @Parameter(name = "id", description = "编号", required = true)
123     @Operation(summary = "删除学生课程")
124     @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
125     public CommonResult<Boolean> deleteDemo03Course(@RequestParam("id") Long id) {
126         demo03StudentService.deleteDemo03Course(id);
127         return success(true);
128     }
129
130     @GetMapping("/demo03-course/get")
131     @Operation(summary = "获得学生课程")
132     @Parameter(name = "id", description = "编号", required = true)
133     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
134     public CommonResult<Demo03CourseDO> getDemo03Course(@RequestParam("id") Long id) {
135         return success(demo03StudentService.getDemo03Course(id));
136     }
137
138     @GetMapping("/demo03-course/list-by-student-id")
139     @Operation(summary = "获得学生课程列表")
140     @Parameter(name = "studentId", description = "学生编号")
141     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
142     public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) {
143         return success(demo03StudentService.getDemo03CourseListByStudentId(studentId));
144     }
145
146     // ==================== 子表(学生班级) ====================
147
148     @GetMapping("/demo03-grade/page")
149     @Operation(summary = "获得学生班级分页")
150     @Parameter(name = "studentId", description = "学生编号")
151     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
152     public CommonResult<PageResult<Demo03GradeDO>> getDemo03GradePage(PageParam pageReqVO,
153                                                                       @RequestParam("studentId") Long studentId) {
154         return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId));
155     }
156
157     @PostMapping("/demo03-grade/create")
158     @Operation(summary = "创建学生班级")
159     @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
160     public CommonResult<Long> createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
161         return success(demo03StudentService.createDemo03Grade(demo03Grade));
162     }
163
164     @PutMapping("/demo03-grade/update")
165     @Operation(summary = "更新学生班级")
166     @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
167     public CommonResult<Boolean> updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
168         demo03StudentService.updateDemo03Grade(demo03Grade);
169         return success(true);
170     }
171
172     @DeleteMapping("/demo03-grade/delete")
173     @Parameter(name = "id", description = "编号", required = true)
174     @Operation(summary = "删除学生班级")
175     @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
176     public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("id") Long id) {
177         demo03StudentService.deleteDemo03Grade(id);
178         return success(true);
179     }
180
181     @GetMapping("/demo03-grade/get")
182     @Operation(summary = "获得学生班级")
183     @Parameter(name = "id", description = "编号", required = true)
184     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
185     public CommonResult<Demo03GradeDO> getDemo03Grade(@RequestParam("id") Long id) {
186         return success(demo03StudentService.getDemo03Grade(id));
187     }
188
189     @GetMapping("/demo03-grade/get-by-student-id")
190     @Operation(summary = "获得学生班级")
191     @Parameter(name = "studentId", description = "学生编号")
192     @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
193     public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) {
194         return success(demo03StudentService.getDemo03GradeByStudentId(studentId));
195     }
196
197 }