From 121da7c76a80eb6a1ced56301a47f99a2b1aa917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E7=BB=B4=E7=82=B3?= Date: Wed, 23 Apr 2025 17:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/student/ErrorStudentEnums.java | 14 +++ .../admin/student/StudentController.java | 101 ++++++++++++++++++ .../admin/student/vo/StudentPageReqVO.java | 53 +++++++++ .../admin/student/vo/StudentRespVO.java | 66 ++++++++++++ .../admin/student/vo/StudentSaveReqVO.java | 47 ++++++++ .../dataobject/student/StudentClassDO.java | 34 ++++++ .../dal/dataobject/student/StudentDO.java | 72 +++++++++++++ .../dal/mysql/student/StudentClassMapper.java | 12 +++ .../exam/dal/mysql/student/StudentMapper.java | 62 +++++++++++ .../exam/service/student/StudentService.java | 69 ++++++++++++ .../service/student/StudentServiceImpl.java | 78 ++++++++++++++ .../mapper/student/StudentClassMapper.xml | 12 +++ .../mapper/student/StudentMapper.xml | 20 ++++ 13 files changed, 640 insertions(+) create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/enums/student/ErrorStudentEnums.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/StudentController.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentPageReqVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentRespVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentSaveReqVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentClassDO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentDO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentClassMapper.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentMapper.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentService.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentServiceImpl.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentClassMapper.xml create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentMapper.xml diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/enums/student/ErrorStudentEnums.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/enums/student/ErrorStudentEnums.java new file mode 100644 index 00000000..58384fbd --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/enums/student/ErrorStudentEnums.java @@ -0,0 +1,14 @@ +package pc.exam.pp.module.exam.controller.admin.enums.student; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorStudentEnums { + + STUDENT_NOT_EXISTS("没有"); + + private final String description; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/StudentController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/StudentController.java new file mode 100644 index 00000000..44798f4b --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/StudentController.java @@ -0,0 +1,101 @@ +package pc.exam.pp.module.exam.controller.admin.student; + +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.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import pc.exam.pp.framework.common.pojo.PageParam; +import pc.exam.pp.framework.common.pojo.PageResult; +import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.framework.common.util.object.BeanUtils; +import static pc.exam.pp.framework.common.pojo.CommonResult.success; + +import pc.exam.pp.framework.excel.core.util.ExcelUtils; + +import pc.exam.pp.framework.apilog.core.annotation.ApiAccessLog; +import static pc.exam.pp.framework.apilog.core.enums.OperateTypeEnum.*; + +import pc.exam.pp.module.exam.controller.admin.student.vo.*; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO; +import pc.exam.pp.module.exam.service.student.StudentService; + +@Tag(name = "管理后台 - 学生") +@RestController +@RequestMapping("/exam/student") +@Validated +public class StudentController { + + @Resource + private StudentService studentService; + + @PostMapping("/create") + @Operation(summary = "创建学生") + @PreAuthorize("@ss.hasPermission('exam:student:create')") + public CommonResult createStudent(@Valid @RequestBody StudentSaveReqVO createReqVO) { + return success(studentService.createStudent(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新学生") + @PreAuthorize("@ss.hasPermission('exam:student:update')") + public CommonResult updateStudent(@Valid @RequestBody StudentSaveReqVO updateReqVO) { + studentService.updateStudent(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除学生") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('exam:student:delete')") + public CommonResult deleteStudent(@RequestParam("id") Long id) { + studentService.deleteStudent(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得学生") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('exam:student:query')") + public CommonResult getStudent(@RequestParam("id") Long id) { + StudentDO student = studentService.getStudent(id); + return success(BeanUtils.toBean(student, StudentRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得学生分页") + @PreAuthorize("@ss.hasPermission('exam:student:query')") + public CommonResult> getStudentPage(@Valid StudentPageReqVO pageReqVO) { + PageResult pageResult = studentService.getStudentPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, StudentRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出学生 Excel") + @PreAuthorize("@ss.hasPermission('exam:student:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportStudentExcel(@Valid StudentPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = studentService.getStudentPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "学生.xls", "数据", StudentRespVO.class, + BeanUtils.toBean(list, StudentRespVO.class)); + } + + @GetMapping("/getStuList") + @Operation(summary = "获得没有绑定过班级的学生列表") + public CommonResult> getStudentPage() { + List pageResult = studentService.getNobindingStudents(); + return success(BeanUtils.toBean(pageResult, StudentRespVO.class)); + } + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentPageReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentPageReqVO.java new file mode 100644 index 00000000..098f597e --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentPageReqVO.java @@ -0,0 +1,53 @@ +package pc.exam.pp.module.exam.controller.admin.student.vo; + +import lombok.*; +import io.swagger.v3.oas.annotations.media.Schema; +import pc.exam.pp.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static pc.exam.pp.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 学生分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class StudentPageReqVO extends PageParam { + + @Schema(description = "名字", example = "李四") + private String name; + + @Schema(description = "学号") + private String code; + + @Schema(description = "状态", example = "1") + private Integer status; + + @Schema(description = "学生用户名", example = "王五") + private String userName; + + @Schema(description = "学生密码") + private String passWord; + + @Schema(description = "性别") + private Integer sex; + + @Schema(description = "电子邮件") + private String email; + + @Schema(description = "学生电话") + private String phone; + + @Schema(description = "简介", example = "随便") + private String description; + + @Schema(description = "头像") + private String avatar; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + + private Long classId; + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentRespVO.java new file mode 100644 index 00000000..4413c6ec --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentRespVO.java @@ -0,0 +1,66 @@ +package pc.exam.pp.module.exam.controller.admin.student.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; +import pc.exam.pp.framework.excel.core.annotations.DictFormat; +import pc.exam.pp.framework.excel.core.convert.DictConvert; + +@Schema(description = "管理后台 - 学生 Response VO") +@Data +@ExcelIgnoreUnannotated +public class StudentRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25172") + @ExcelProperty("编号") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @ExcelProperty("名字") + private String name; + + @Schema(description = "学号") + @ExcelProperty("学号") + private String code; + + @Schema(description = "状态", example = "1") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat("common_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 + private Integer status; + + @Schema(description = "学生用户名", example = "王五") + @ExcelProperty("学生用户名") + private String userName; + + @Schema(description = "学生密码") + @ExcelProperty("学生密码") + private String passWord; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty(value = "性别", converter = DictConvert.class) + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 + private Integer sex; + + @Schema(description = "电子邮件") + @ExcelProperty("电子邮件") + private String email; + + @Schema(description = "学生电话") + @ExcelProperty("学生电话") + private String phone; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @ExcelProperty("简介") + private String description; + + @Schema(description = "头像") + @ExcelProperty("头像") + private String avatar; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentSaveReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentSaveReqVO.java new file mode 100644 index 00000000..0af3b8ef --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/student/vo/StudentSaveReqVO.java @@ -0,0 +1,47 @@ +package pc.exam.pp.module.exam.controller.admin.student.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import jakarta.validation.constraints.*; + +@Schema(description = "管理后台 - 学生新增/修改 Request VO") +@Data +public class StudentSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25172") + private Long id; + + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @NotEmpty(message = "名字不能为空") + private String name; + + @Schema(description = "学号") + private String code; + + @Schema(description = "状态", example = "1") + private Integer status; + + @Schema(description = "学生用户名", example = "王五") + private String userName; + + @Schema(description = "学生密码") + private String passWord; + + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "性别不能为空") + private Integer sex; + + @Schema(description = "电子邮件") + private String email; + + @Schema(description = "学生电话") + private String phone; + + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") + @NotEmpty(message = "简介不能为空") + private String description; + + @Schema(description = "头像") + private String avatar; + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentClassDO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentClassDO.java new file mode 100644 index 00000000..5358fb1c --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentClassDO.java @@ -0,0 +1,34 @@ +package pc.exam.pp.module.exam.dal.dataobject.student; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import pc.exam.pp.framework.tenant.core.db.TenantBaseDO; + +/** + * 学生班级 DO + * + * @author rwb + */ +@TableName("exam_student_class") +@Data +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class StudentClassDO extends TenantBaseDO { + + /** + * Id + */ + @TableId + private Long id; + /** + * 班级编号 + */ + private Long classId; + /** + * 学生编号 + */ + private Long studentId; +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentDO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentDO.java new file mode 100644 index 00000000..28cf7d9b --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StudentDO.java @@ -0,0 +1,72 @@ +package pc.exam.pp.module.exam.dal.dataobject.student; + +import lombok.*; +import com.baomidou.mybatisplus.annotation.*; +import pc.exam.pp.framework.mybatis.core.dataobject.BaseDO; + +/** + * 学生 DO + * + * @author rwb + */ +@TableName("exam_student") +@KeySequence("exam_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class StudentDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 名字 + */ + private String name; + /** + * 学号 + */ + private String code; + /** + * 状态 + * + * 枚举 {@link TODO common_status 对应的类} + */ + private Integer status; + /** + * 学生用户名 + */ + private String userName; + /** + * 学生密码 + */ + private String passWord; + /** + * 性别 + * + * 枚举 {@link TODO system_user_sex 对应的类} + */ + private Integer sex; + /** + * 电子邮件 + */ + private String email; + /** + * 学生电话 + */ + private String phone; + /** + * 简介 + */ + private String description; + /** + * 头像 + */ + private String avatar; + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentClassMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentClassMapper.java new file mode 100644 index 00000000..7d22d607 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentClassMapper.java @@ -0,0 +1,12 @@ +package pc.exam.pp.module.exam.dal.mysql.student; + + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; +import pc.exam.pp.module.exam.controller.admin.classs.vo.ClassStudentSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentClassDO; + +@Mapper +public interface StudentClassMapper extends BaseMapperX { +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentMapper.java new file mode 100644 index 00000000..b1707db1 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StudentMapper.java @@ -0,0 +1,62 @@ +package pc.exam.pp.module.exam.dal.mysql.student; + +import pc.exam.pp.framework.common.pojo.PageResult; +import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; +import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; +import pc.exam.pp.framework.mybatis.core.query.MPJLambdaWrapperX; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentClassDO; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO; +import org.apache.ibatis.annotations.Mapper; +import pc.exam.pp.module.exam.controller.admin.student.vo.*; + +import java.util.List; + +/** + * 学生 Mapper + * + * @author rwb + */ +@Mapper +public interface StudentMapper extends BaseMapperX { + +// default PageResult selectPage(StudentPageReqVO reqVO) { +// return selectPage(reqVO, new LambdaQueryWrapperX() +// .likeIfPresent(StudentDO::getName, reqVO.getName()) +// .eqIfPresent(StudentDO::getCode, reqVO.getCode()) +// .eqIfPresent(StudentDO::getStatus, reqVO.getStatus()) +// .likeIfPresent(StudentDO::getUserName, reqVO.getUserName()) +// .eqIfPresent(StudentDO::getPassWord, reqVO.getPassWord()) +// .eqIfPresent(StudentDO::getSex, reqVO.getSex()) +// .eqIfPresent(StudentDO::getEmail, reqVO.getEmail()) +// .eqIfPresent(StudentDO::getPhone, reqVO.getPhone()) +// .eqIfPresent(StudentDO::getDescription, reqVO.getDescription()) +// .eqIfPresent(StudentDO::getAvatar, reqVO.getAvatar()) +// .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime()) +// .orderByDesc(StudentDO::getId)); +// } + + default PageResult selectPage(StudentPageReqVO reqVO) { + MPJLambdaWrapperX query = new MPJLambdaWrapperX() + .likeIfPresent(StudentDO::getName, reqVO.getName()) + .eqIfPresent(StudentDO::getCode, reqVO.getCode()) + .eqIfPresent(StudentDO::getStatus, reqVO.getStatus()) + .likeIfPresent(StudentDO::getUserName, reqVO.getUserName()) + .eqIfPresent(StudentDO::getPassWord, reqVO.getPassWord()) + .eqIfPresent(StudentDO::getSex, reqVO.getSex()) + .eqIfPresent(StudentDO::getEmail, reqVO.getEmail()) + .eqIfPresent(StudentDO::getPhone, reqVO.getPhone()) + .eqIfPresent(StudentDO::getDescription, reqVO.getDescription()) + .eqIfPresent(StudentDO::getAvatar, reqVO.getAvatar()) + .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(StudentDO::getId); + if (reqVO.getClassId() != null) { + query.leftJoin(StudentClassDO.class, StudentClassDO::getStudentId, StudentDO::getId) + .eq(reqVO.getClassId() != null, StudentClassDO::getClassId, reqVO.getClassId()); // 避免 1 对多查询,产生相同的 1 + } + return selectJoinPage(reqVO, StudentDO.class, query); + } + + + List getBindingStudents(); + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentService.java new file mode 100644 index 00000000..9a82d2dd --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentService.java @@ -0,0 +1,69 @@ +package pc.exam.pp.module.exam.service.student; + +import jakarta.validation.*; +import pc.exam.pp.module.exam.controller.admin.student.vo.*; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO; +import pc.exam.pp.framework.common.pojo.PageResult; + +import java.util.List; + +/** + * 学生 Service 接口 + * + * @author rwb + */ +public interface StudentService { + + /** + * 创建学生 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createStudent(@Valid StudentSaveReqVO createReqVO); + + /** + * 更新学生 + * + * @param updateReqVO 更新信息 + */ + void updateStudent(@Valid StudentSaveReqVO updateReqVO); + + /** + * 删除学生 + * + * @param id 编号 + */ + void deleteStudent(Long id); + + /** + * 根据班级ID查询学生列表(分页) + * + * @param id 编号 + */ +// PageResult getStudentListByClassId(Long id); + + /** + * 获得学生 + * + * @param id 编号 + * @return 学生 + */ + StudentDO getStudent(Long id); + + /** + * 获得学生分页 + * + * @param pageReqVO 分页查询 + * @return 学生分页 + */ + PageResult getStudentPage(StudentPageReqVO pageReqVO); + + /** + * 获得学生没有绑定班级的学生列表 + * + * @return 学生列表 + */ + List getNobindingStudents(); + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentServiceImpl.java new file mode 100644 index 00000000..de3ea520 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/student/StudentServiceImpl.java @@ -0,0 +1,78 @@ +package pc.exam.pp.module.exam.service.student; + +import org.springframework.stereotype.Service; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import pc.exam.pp.module.exam.controller.admin.student.vo.*; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO; +import pc.exam.pp.framework.common.pojo.PageResult; +import pc.exam.pp.framework.common.util.object.BeanUtils; + +import pc.exam.pp.module.exam.dal.mysql.student.StudentMapper; + +import java.util.List; + +import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; +import static pc.exam.pp.module.system.enums.ErrorCodeConstants.STUDENT_NOT_EXISTS; + +/** + * 学生 Service 实现类 + * + * @author rwb + */ +@Service +@Validated +public class StudentServiceImpl implements StudentService { + + @Resource + private StudentMapper studentMapper; + + @Override + public Long createStudent(StudentSaveReqVO createReqVO) { + // 插入 + StudentDO student = BeanUtils.toBean(createReqVO, StudentDO.class); + studentMapper.insert(student); + // 返回 + return student.getId(); + } + + @Override + public void updateStudent(StudentSaveReqVO updateReqVO) { + // 校验存在 + validateStudentExists(updateReqVO.getId()); + // 更新 + StudentDO updateObj = BeanUtils.toBean(updateReqVO, StudentDO.class); + studentMapper.updateById(updateObj); + } + + @Override + public void deleteStudent(Long id) { + // 校验存在 + validateStudentExists(id); + // 删除 + studentMapper.deleteById(id); + } + + private void validateStudentExists(Long id) { + if (studentMapper.selectById(id) == null) { + throw exception(STUDENT_NOT_EXISTS); + } + } + + @Override + public StudentDO getStudent(Long id) { + return studentMapper.selectById(id); + } + + @Override + public PageResult getStudentPage(StudentPageReqVO pageReqVO) { + return studentMapper.selectPage(pageReqVO); + } + + @Override + public List getNobindingStudents() { + return studentMapper.getBindingStudents(); + } + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentClassMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentClassMapper.xml new file mode 100644 index 00000000..e912b4ea --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentClassMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentMapper.xml new file mode 100644 index 00000000..3c079c7d --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StudentMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file