Commit 05bf229a3c91b9e74c11b380703ba5dd42e89fa2
1 parent
e10425e0
perf:【INFRA 基础设施】vben5-antd-schema 主主子表inner代码生成时,可生成批量删除
Showing
9 changed files
with
586 additions
and
0 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO; | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 14 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 15 | +import cn.iocoder.yudao.module.infra.service.demo.demo03.inner.Demo03StudentInnerService; | |
| 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 jakarta.annotation.Resource; | |
| 20 | +import jakarta.servlet.http.HttpServletResponse; | |
| 21 | +import jakarta.validation.Valid; | |
| 22 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 23 | +import org.springframework.validation.annotation.Validated; | |
| 24 | +import org.springframework.web.bind.annotation.*; | |
| 25 | + | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.util.List; | |
| 28 | + | |
| 29 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | |
| 30 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 学生") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/demo03-student-inner") | |
| 35 | +@Validated | |
| 36 | +public class Demo03StudentInnerController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private Demo03StudentInnerService demo03StudentInnerService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建学生") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") | |
| 44 | + public CommonResult<Long> createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) { | |
| 45 | + return success(demo03StudentInnerService.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 Demo03StudentInnerSaveReqVO updateReqVO) { | |
| 52 | + demo03StudentInnerService.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 | + demo03StudentInnerService.deleteDemo03Student(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @DeleteMapping("/delete-batch") | |
| 66 | + @Parameter(name = "ids", description = "编号", required = true) | |
| 67 | + @Operation(summary = "批量删除学生") | |
| 68 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") | |
| 69 | + public CommonResult<Boolean> deleteDemo03Student(@RequestParam("ids") List<Long> ids) { | |
| 70 | + demo03StudentInnerService.deleteDemo03StudentByIds(ids); | |
| 71 | + return success(true); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/get") | |
| 75 | + @Operation(summary = "获得学生") | |
| 76 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 77 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 78 | + public CommonResult<Demo03StudentInnerRespVO> getDemo03Student(@RequestParam("id") Long id) { | |
| 79 | + Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id); | |
| 80 | + return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class)); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @GetMapping("/page") | |
| 84 | + @Operation(summary = "获得学生分页") | |
| 85 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 86 | + public CommonResult<PageResult<Demo03StudentInnerRespVO>> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) { | |
| 87 | + PageResult<Demo03StudentDO> pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO); | |
| 88 | + return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class)); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @GetMapping("/export-excel") | |
| 92 | + @Operation(summary = "导出学生 Excel") | |
| 93 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") | |
| 94 | + @ApiAccessLog(operateType = EXPORT) | |
| 95 | + public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO, | |
| 96 | + HttpServletResponse response) throws IOException { | |
| 97 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 98 | + List<Demo03StudentDO> list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList(); | |
| 99 | + // 导出 Excel | |
| 100 | + ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class, | |
| 101 | + BeanUtils.toBean(list, Demo03StudentInnerRespVO.class)); | |
| 102 | + } | |
| 103 | + | |
| 104 | + // ==================== 子表(学生课程) ==================== | |
| 105 | + | |
| 106 | + @GetMapping("/demo03-course/list-by-student-id") | |
| 107 | + @Operation(summary = "获得学生课程列表") | |
| 108 | + @Parameter(name = "studentId", description = "学生编号") | |
| 109 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 110 | + public CommonResult<List<Demo03CourseDO>> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 111 | + return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId)); | |
| 112 | + } | |
| 113 | + | |
| 114 | + // ==================== 子表(学生班级) ==================== | |
| 115 | + | |
| 116 | + @GetMapping("/demo03-grade/get-by-student-id") | |
| 117 | + @Operation(summary = "获得学生班级") | |
| 118 | + @Parameter(name = "studentId", description = "学生编号") | |
| 119 | + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") | |
| 120 | + public CommonResult<Demo03GradeDO> getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { | |
| 121 | + return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId)); | |
| 122 | + } | |
| 123 | + | |
| 124 | +} | |
| 0 | 125 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class Demo03StudentInnerPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "名字", example = "芋艿") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @Schema(description = "性别") | |
| 24 | + private Integer sex; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", example = "随便") | |
| 27 | + private String description; | |
| 28 | + | |
| 29 | + @Schema(description = "创建时间") | |
| 30 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 31 | + private LocalDateTime[] createTime; | |
| 32 | + | |
| 33 | +} | |
| 0 | 34 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 13 | +@Data | |
| 14 | +@ExcelIgnoreUnannotated | |
| 15 | +public class Demo03StudentInnerRespVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 18 | + @ExcelProperty("编号") | |
| 19 | + private Long id; | |
| 20 | + | |
| 21 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 22 | + @ExcelProperty("名字") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 26 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 27 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 28 | + private Integer sex; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 35 | + @ExcelProperty("简介") | |
| 36 | + private String description; | |
| 37 | + | |
| 38 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 39 | + @ExcelProperty("创建时间") | |
| 40 | + private LocalDateTime createTime; | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 7 | +import jakarta.validation.constraints.NotNull; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class Demo03StudentInnerSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + @NotNull(message = "性别不能为空") | |
| 26 | + private Integer sex; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") | |
| 33 | + @NotEmpty(message = "简介不能为空") | |
| 34 | + private String description; | |
| 35 | + | |
| 36 | + @Schema(description = "学生课程列表") | |
| 37 | + private List<Demo03CourseDO> demo03Courses; | |
| 38 | + | |
| 39 | + @Schema(description = "学生班级") | |
| 40 | + private Demo03GradeDO demo03Grade; | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生课程 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03CourseInnerMapper extends BaseMapperX<Demo03CourseDO> { | |
| 16 | + | |
| 17 | + default List<Demo03CourseDO> selectListByStudentId(Long studentId) { | |
| 18 | + return selectList(Demo03CourseDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03CourseDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03CourseDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 学生班级 Mapper | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@Mapper | |
| 15 | +public interface Demo03GradeInnerMapper extends BaseMapperX<Demo03GradeDO> { | |
| 16 | + | |
| 17 | + default Demo03GradeDO selectByStudentId(Long studentId) { | |
| 18 | + return selectOne(Demo03GradeDO::getStudentId, studentId); | |
| 19 | + } | |
| 20 | + | |
| 21 | + default int deleteByStudentId(Long studentId) { | |
| 22 | + return delete(Demo03GradeDO::getStudentId, studentId); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default int deleteByStudentIds(List<Long> studentIds) { | |
| 26 | + return delete(Demo03GradeDO::getStudentId, studentIds); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface Demo03StudentInnerMapper extends BaseMapperX<Demo03StudentDO> { | |
| 17 | + | |
| 18 | + default PageResult<Demo03StudentDO> selectPage(Demo03StudentInnerPageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03StudentDO>() | |
| 20 | + .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) | |
| 21 | + .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) | |
| 22 | + .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) | |
| 23 | + .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(Demo03StudentDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 9 | +import jakarta.validation.Valid; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 学生 Service 接口 | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +public interface Demo03StudentInnerService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 创建学生 | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新学生 | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 删除学生 | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + */ | |
| 40 | + void deleteDemo03Student(Long id); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 批量删除学生 | |
| 44 | + * | |
| 45 | + * @param ids 编号 | |
| 46 | + */ | |
| 47 | + void deleteDemo03StudentByIds(List<Long> ids); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生 | |
| 51 | + * | |
| 52 | + * @param id 编号 | |
| 53 | + * @return 学生 | |
| 54 | + */ | |
| 55 | + Demo03StudentDO getDemo03Student(Long id); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 获得学生分页 | |
| 59 | + * | |
| 60 | + * @param pageReqVO 分页查询 | |
| 61 | + * @return 学生分页 | |
| 62 | + */ | |
| 63 | + PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO); | |
| 64 | + | |
| 65 | + // ==================== 子表(学生课程) ==================== | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获得学生课程列表 | |
| 69 | + * | |
| 70 | + * @param studentId 学生编号 | |
| 71 | + * @return 学生课程列表 | |
| 72 | + */ | |
| 73 | + List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); | |
| 74 | + | |
| 75 | + // ==================== 子表(学生班级) ==================== | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 获得学生班级 | |
| 79 | + * | |
| 80 | + * @param studentId 学生编号 | |
| 81 | + * @return 学生班级 | |
| 82 | + */ | |
| 83 | + Demo03GradeDO getDemo03GradeByStudentId(Long studentId); | |
| 84 | + | |
| 85 | +} | |
| 0 | 86 | \ No newline at end of file | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo.demo03.inner; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper; | |
| 14 | +import jakarta.annotation.Resource; | |
| 15 | +import org.springframework.stereotype.Service; | |
| 16 | +import org.springframework.transaction.annotation.Transactional; | |
| 17 | +import org.springframework.validation.annotation.Validated; | |
| 18 | + | |
| 19 | +import java.util.List; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private Demo03StudentInnerMapper demo03StudentInnerMapper; | |
| 35 | + @Resource | |
| 36 | + private Demo03CourseInnerMapper demo03CourseInnerMapper; | |
| 37 | + @Resource | |
| 38 | + private Demo03GradeInnerMapper demo03GradeInnerMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + @Transactional(rollbackFor = Exception.class) | |
| 42 | + public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) { | |
| 43 | + // 插入 | |
| 44 | + Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); | |
| 45 | + demo03StudentInnerMapper.insert(demo03Student); | |
| 46 | + | |
| 47 | + // 插入子表 | |
| 48 | + createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); | |
| 49 | + createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); | |
| 50 | + // 返回 | |
| 51 | + return demo03Student.getId(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + @Transactional(rollbackFor = Exception.class) | |
| 56 | + public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) { | |
| 57 | + // 校验存在 | |
| 58 | + validateDemo03StudentExists(updateReqVO.getId()); | |
| 59 | + // 更新 | |
| 60 | + Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); | |
| 61 | + demo03StudentInnerMapper.updateById(updateObj); | |
| 62 | + | |
| 63 | + // 更新子表 | |
| 64 | + updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); | |
| 65 | + updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + public void deleteDemo03Student(Long id) { | |
| 71 | + // 校验存在 | |
| 72 | + validateDemo03StudentExists(id); | |
| 73 | + // 删除 | |
| 74 | + demo03StudentInnerMapper.deleteById(id); | |
| 75 | + | |
| 76 | + // 删除子表 | |
| 77 | + deleteDemo03CourseByStudentId(id); | |
| 78 | + deleteDemo03GradeByStudentId(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + @Transactional(rollbackFor = Exception.class) | |
| 83 | + public void deleteDemo03StudentByIds(List<Long> ids) { | |
| 84 | + // 校验存在 | |
| 85 | + validateDemo03StudentExists(ids); | |
| 86 | + // 删除 | |
| 87 | + demo03StudentInnerMapper.deleteByIds(ids); | |
| 88 | + | |
| 89 | + // 删除子表 | |
| 90 | + deleteDemo03CourseByStudentIds(ids); | |
| 91 | + deleteDemo03GradeByStudentIds(ids); | |
| 92 | + } | |
| 93 | + | |
| 94 | + private void validateDemo03StudentExists(List<Long> ids) { | |
| 95 | + List<Demo03StudentDO> list = demo03StudentInnerMapper.selectByIds(ids); | |
| 96 | + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { | |
| 97 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + private void validateDemo03StudentExists(Long id) { | |
| 102 | + if (demo03StudentInnerMapper.selectById(id) == null) { | |
| 103 | + throw exception(DEMO03_STUDENT_NOT_EXISTS); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public Demo03StudentDO getDemo03Student(Long id) { | |
| 109 | + return demo03StudentInnerMapper.selectById(id); | |
| 110 | + } | |
| 111 | + | |
| 112 | + @Override | |
| 113 | + public PageResult<Demo03StudentDO> getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) { | |
| 114 | + return demo03StudentInnerMapper.selectPage(pageReqVO); | |
| 115 | + } | |
| 116 | + | |
| 117 | + // ==================== 子表(学生课程) ==================== | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId) { | |
| 121 | + return demo03CourseInnerMapper.selectListByStudentId(studentId); | |
| 122 | + } | |
| 123 | + | |
| 124 | + private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 125 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 126 | + demo03CourseInnerMapper.insertBatch(list); | |
| 127 | + } | |
| 128 | + | |
| 129 | + private void updateDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { | |
| 130 | + deleteDemo03CourseByStudentId(studentId); | |
| 131 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 132 | + createDemo03CourseList(studentId, list); | |
| 133 | + } | |
| 134 | + | |
| 135 | + private void deleteDemo03CourseByStudentId(Long studentId) { | |
| 136 | + demo03CourseInnerMapper.deleteByStudentId(studentId); | |
| 137 | + } | |
| 138 | + | |
| 139 | + private void deleteDemo03CourseByStudentIds(List<Long> studentIds) { | |
| 140 | + demo03CourseInnerMapper.deleteByStudentIds(studentIds); | |
| 141 | + } | |
| 142 | + | |
| 143 | + // ==================== 子表(学生班级) ==================== | |
| 144 | + | |
| 145 | + @Override | |
| 146 | + public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { | |
| 147 | + return demo03GradeInnerMapper.selectByStudentId(studentId); | |
| 148 | + } | |
| 149 | + | |
| 150 | + private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 151 | + if (demo03Grade == null) { | |
| 152 | + return; | |
| 153 | + } | |
| 154 | + demo03Grade.setStudentId(studentId); | |
| 155 | + demo03GradeInnerMapper.insert(demo03Grade); | |
| 156 | + } | |
| 157 | + | |
| 158 | + private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { | |
| 159 | + if (demo03Grade == null) { | |
| 160 | + return; | |
| 161 | + } | |
| 162 | + demo03Grade.setStudentId(studentId); | |
| 163 | + demo03Grade.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 164 | + demo03GradeInnerMapper.insertOrUpdate(demo03Grade); | |
| 165 | + } | |
| 166 | + | |
| 167 | + private void deleteDemo03GradeByStudentId(Long studentId) { | |
| 168 | + demo03GradeInnerMapper.deleteByStudentId(studentId); | |
| 169 | + } | |
| 170 | + | |
| 171 | + private void deleteDemo03GradeByStudentIds(List<Long> studentIds) { | |
| 172 | + demo03GradeInnerMapper.deleteByStudentIds(studentIds); | |
| 173 | + } | |
| 174 | + | |
| 175 | +} | |
| 0 | 176 | \ No newline at end of file | ... | ... |