2026-06-25 a26b31cc9f3ee9b21b1a754e80fa7359e8a7a8f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package cn.iocoder.yudao.module.infra.controller.admin.demo;
 
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
 
import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;
 
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
 
import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO;
import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService;
 
@Tag(name = "管理后台 - 学生")
@RestController
@RequestMapping("/infra/student")
@Validated
public class InfraStudentController {
 
    @Resource
    private InfraStudentService studentService;
 
    @PostMapping("/create")
    @Operation(summary = "创建学生")
    @PreAuthorize("@ss.hasPermission('infra:student:create')")
    public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) {
        return success(studentService.createStudent(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新学生")
    @PreAuthorize("@ss.hasPermission('infra:student:update')")
    public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) {
        studentService.updateStudent(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除学生")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) {
        studentService.deleteStudent(id);
        return success(true);
    }
 
    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除学生")
                @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudentList(@RequestParam("ids") List<Long> ids) {
        studentService.deleteStudentListByIds(ids);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得学生")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) {
        InfraStudentDO student = studentService.getStudent(id);
        return success(BeanUtils.toBean(student, InfraStudentRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得学生分页")
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) {
        PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出学生 Excel")
    @PreAuthorize("@ss.hasPermission('infra:student:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class,
                        BeanUtils.toBean(list, InfraStudentRespVO.class));
    }
 
    // ==================== 子表(学生联系人) ====================
 
    @GetMapping("/student-contact/page")
    @Operation(summary = "获得学生联系人分页")
    @Parameter(name = "studentId", description = "学生编号")
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<PageResult<InfraStudentContactDO>> getStudentContactPage(PageParam pageReqVO,
                                                                                        @RequestParam("studentId") Long studentId) {
        return success(studentService.getStudentContactPage(pageReqVO, studentId));
    }
 
    @PostMapping("/student-contact/create")
    @Operation(summary = "创建学生联系人")
    @PreAuthorize("@ss.hasPermission('infra:student:create')")
    public CommonResult<Long> createStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) {
        return success(studentService.createStudentContact(studentContact));
    }
 
    @PutMapping("/student-contact/update")
    @Operation(summary = "更新学生联系人")
    @PreAuthorize("@ss.hasPermission('infra:student:update')")
    public CommonResult<Boolean> updateStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) {
        studentService.updateStudentContact(studentContact);
        return success(true);
    }
 
    @DeleteMapping("/student-contact/delete")
    @Parameter(name = "id", description = "编号", required = true)
    @Operation(summary = "删除学生联系人")
    @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudentContact(@RequestParam("id") Long id) {
        studentService.deleteStudentContact(id);
        return success(true);
    }
 
    @DeleteMapping("/student-contact/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除学生联系人")
    @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudentContactList(@RequestParam("ids") List<Long> ids) {
        studentService.deleteStudentContactListByIds(ids);
        return success(true);
    }
 
    @GetMapping("/student-contact/get")
    @Operation(summary = "获得学生联系人")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<InfraStudentContactDO> getStudentContact(@RequestParam("id") Long id) {
        return success(studentService.getStudentContact(id));
    }
 
    // ==================== 子表(学生班主任) ====================
 
    @GetMapping("/student-teacher/page")
    @Operation(summary = "获得学生班主任分页")
    @Parameter(name = "studentId", description = "学生编号")
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<PageResult<InfraStudentTeacherDO>> getStudentTeacherPage(PageParam pageReqVO,
                                                                                        @RequestParam("studentId") Long studentId) {
        return success(studentService.getStudentTeacherPage(pageReqVO, studentId));
    }
 
    @PostMapping("/student-teacher/create")
    @Operation(summary = "创建学生班主任")
    @PreAuthorize("@ss.hasPermission('infra:student:create')")
    public CommonResult<Long> createStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) {
        return success(studentService.createStudentTeacher(studentTeacher));
    }
 
    @PutMapping("/student-teacher/update")
    @Operation(summary = "更新学生班主任")
    @PreAuthorize("@ss.hasPermission('infra:student:update')")
    public CommonResult<Boolean> updateStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) {
        studentService.updateStudentTeacher(studentTeacher);
        return success(true);
    }
 
    @DeleteMapping("/student-teacher/delete")
    @Parameter(name = "id", description = "编号", required = true)
    @Operation(summary = "删除学生班主任")
    @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudentTeacher(@RequestParam("id") Long id) {
        studentService.deleteStudentTeacher(id);
        return success(true);
    }
 
    @DeleteMapping("/student-teacher/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除学生班主任")
    @PreAuthorize("@ss.hasPermission('infra:student:delete')")
    public CommonResult<Boolean> deleteStudentTeacherList(@RequestParam("ids") List<Long> ids) {
        studentService.deleteStudentTeacherListByIds(ids);
        return success(true);
    }
 
    @GetMapping("/student-teacher/get")
    @Operation(summary = "获得学生班主任")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('infra:student:query')")
    public CommonResult<InfraStudentTeacherDO> getStudentTeacher(@RequestParam("id") Long id) {
        return success(studentService.getStudentTeacher(id));
    }
 
}