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