dengzedong
2024-12-19 85b2001c0ec2f1adc598db3bf47ad457dcca7074
提交 | 用户 | 时间
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/list-by-student-id")
100     @Operation(summary = "获得学生联系人列表")
101     @Parameter(name = "studentId", description = "学生编号")
102     @PreAuthorize("@ss.hasPermission('infra:student:query')")
103     public CommonResult<List<InfraStudentContactDO>> getStudentContactListByStudentId(@RequestParam("studentId") Long studentId) {
104         return success(studentService.getStudentContactListByStudentId(studentId));
105     }
106
107     // ==================== 子表(学生班主任) ====================
108
109     @GetMapping("/student-teacher/get-by-student-id")
110     @Operation(summary = "获得学生班主任")
111     @Parameter(name = "studentId", description = "学生编号")
112     @PreAuthorize("@ss.hasPermission('infra:student:query')")
113     public CommonResult<InfraStudentTeacherDO> getStudentTeacherByStudentId(@RequestParam("studentId") Long studentId) {
114         return success(studentService.getStudentTeacherByStudentId(studentId));
115     }
116
117 }