Commit 90842542a93b73ff04713ed8aa3743afe2393737

Authored by YunaiV
1 parent a4b1395e

代码生成:主子表(inner)部分模版

Showing 22 changed files with 1134 additions and 13 deletions
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
... ... @@ -57,7 +57,10 @@ public interface ErrorCodeConstants {
57 57 // ========== 学生(CodegenTemplateTypeEnum.ONE 示例) 1-001-201-000 ==========
58 58 ErrorCode DEMO01_STUDENT_NOT_EXISTS = new ErrorCode(1_001_200_000, "学生不存在");
59 59  
60   - // ========== 学生(CodegenTemplateTypeEnum.ONE 示例) 1-001-211-000 ==========
  60 + // ========== 学生(CodegenTemplateTypeEnum.MASTER_NORMAL 示例) 1-001-211-000 ==========
61 61 ErrorCode DEMO11_STUDENT_NOT_EXISTS = new ErrorCode(1_001_211_000, "学生不存在");
62 62  
  63 + // ========== 学生(CodegenTemplateTypeEnum.MASTER_INNER 示例) 1-001-213-000 ==========
  64 + ErrorCode DEMO12_STUDENT_NOT_EXISTS = new ErrorCode(1_001_213_000, "学生不存在");
  65 +
63 66 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/InfraDemo12StudentController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12;
  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 cn.iocoder.yudao.framework.common.pojo.PageResult;
  18 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  19 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  20 +
  21 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  22 +
  23 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  24 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
  25 +
  26 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  27 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  28 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
  29 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
  30 +import cn.iocoder.yudao.module.infra.convert.demo12.InfraDemo12StudentConvert;
  31 +import cn.iocoder.yudao.module.infra.service.demo12.InfraDemo12StudentService;
  32 +
  33 +@Tag(name = "管理后台 - 学生")
  34 +@RestController
  35 +@RequestMapping("/infra/demo12-student")
  36 +@Validated
  37 +public class InfraDemo12StudentController {
  38 +
  39 + @Resource
  40 + private InfraDemo12StudentService demo12StudentService;
  41 +
  42 + @PostMapping("/create")
  43 + @Operation(summary = "创建学生")
  44 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:create')")
  45 + public CommonResult<Long> createDemo12Student(@Valid @RequestBody InfraDemo12StudentCreateReqVO createReqVO) {
  46 + return success(demo12StudentService.createDemo12Student(createReqVO));
  47 + }
  48 +
  49 + @PutMapping("/update")
  50 + @Operation(summary = "更新学生")
  51 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:update')")
  52 + public CommonResult<Boolean> updateDemo12Student(@Valid @RequestBody InfraDemo12StudentUpdateReqVO updateReqVO) {
  53 + demo12StudentService.updateDemo12Student(updateReqVO);
  54 + return success(true);
  55 + }
  56 +
  57 + @DeleteMapping("/delete")
  58 + @Operation(summary = "删除学生")
  59 + @Parameter(name = "id", description = "编号", required = true)
  60 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:delete')")
  61 + public CommonResult<Boolean> deleteDemo12Student(@RequestParam("id") Long id) {
  62 + demo12StudentService.deleteDemo12Student(id);
  63 + return success(true);
  64 + }
  65 +
  66 + @GetMapping("/get")
  67 + @Operation(summary = "获得学生")
  68 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  69 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
  70 + public CommonResult<InfraDemo12StudentRespVO> getDemo12Student(@RequestParam("id") Long id) {
  71 + InfraDemo12StudentDO demo12Student = demo12StudentService.getDemo12Student(id);
  72 + return success(InfraDemo12StudentConvert.INSTANCE.convert(demo12Student));
  73 + }
  74 +
  75 + @GetMapping("/page")
  76 + @Operation(summary = "获得学生分页")
  77 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
  78 + public CommonResult<PageResult<InfraDemo12StudentRespVO>> getDemo12StudentPage(@Valid InfraDemo12StudentPageReqVO pageVO) {
  79 + PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(pageVO);
  80 + return success(InfraDemo12StudentConvert.INSTANCE.convertPage(pageResult));
  81 + }
  82 +
  83 + @GetMapping("/export-excel")
  84 + @Operation(summary = "导出学生 Excel")
  85 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:export')")
  86 + @OperateLog(type = EXPORT)
  87 + public void exportDemo12StudentExcel(@Valid InfraDemo12StudentExportReqVO exportReqVO,
  88 + HttpServletResponse response) throws IOException {
  89 + List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(exportReqVO);
  90 + // 导出 Excel
  91 + List<InfraDemo12StudentExcelVO> datas = InfraDemo12StudentConvert.INSTANCE.convertList02(list);
  92 + ExcelUtils.write(response, "学生.xls", "数据", InfraDemo12StudentExcelVO.class, datas);
  93 + }
  94 +
  95 + // ==================== 子表(学生联系人) ====================
  96 +
  97 + @GetMapping("/demo12-student/list-by-student-id")
  98 + @Operation(summary = "获得学生联系人列表")
  99 + @Parameter(name = "studentId", description = "学生编号")
  100 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
  101 + public CommonResult<List<InfraDemo12StudentContactDO>> getDemo12StudentContactListByStudentId(@RequestParam("studentId") Long studentId) {
  102 + return success(demo12StudentService.getDemo12StudentContactListByStudentId(studentId));
  103 + }
  104 +
  105 + // ==================== 子表(学生班主任) ====================
  106 +
  107 + @GetMapping("/demo12-student/get-by-student-id")
  108 + @Operation(summary = "获得学生班主任")
  109 + @Parameter(name = "studentId", description = "学生编号")
  110 + @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
  111 + public CommonResult<InfraDemo12StudentTeacherDO> getDemo12StudentTeacherByStudentId(@RequestParam("studentId") Long studentId) {
  112 + return success(demo12StudentService.getDemo12StudentTeacherByStudentId(studentId));
  113 + }
  114 +
  115 +}
0 116 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import java.time.LocalDateTime;
  7 +import javax.validation.constraints.*;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
  12 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
  13 +
  14 +/**
  15 + * 学生 Base VO,提供给添加、修改、详细的子 VO 使用
  16 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  17 + */
  18 +@Data
  19 +public class InfraDemo12StudentBaseVO {
  20 +
  21 + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头")
  22 + @NotEmpty(message = "名字不能为空")
  23 + private String name;
  24 +
  25 + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍")
  26 + @NotEmpty(message = "简介不能为空")
  27 + private String description;
  28 +
  29 + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
  30 + @NotNull(message = "出生日期不能为空")
  31 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  32 + private LocalDateTime birthday;
  33 +
  34 + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  35 + @NotNull(message = "性别不能为空")
  36 + private Integer sex;
  37 +
  38 + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  39 + @NotNull(message = "是否有效不能为空")
  40 + private Boolean enabled;
  41 +
  42 + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
  43 + @NotEmpty(message = "头像不能为空")
  44 + private String avatar;
  45 +
  46 + @Schema(description = "附件", example = "https://www.iocoder.cn/1.mp4")
  47 + private String video;
  48 +
  49 + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注")
  50 + @NotEmpty(message = "备注不能为空")
  51 + private String memo;
  52 +
  53 + private List<InfraDemo12StudentContactDO> demo12StudentContacts;
  54 +
  55 + private InfraDemo12StudentTeacherDO demo12StudentTeacher;
  56 +
  57 +}
0 58 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentCreateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@Schema(description = "管理后台 - 学生创建 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class InfraDemo12StudentCreateReqVO extends InfraDemo12StudentBaseVO {
  13 +
  14 +}
0 15 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExcelVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import java.time.LocalDateTime;
  7 +
  8 +import com.alibaba.excel.annotation.ExcelProperty;
  9 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  10 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  11 +
  12 +
  13 +/**
  14 + * 学生 Excel VO
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@Data
  19 +public class InfraDemo12StudentExcelVO {
  20 +
  21 + @ExcelProperty("编号")
  22 + private Long id;
  23 +
  24 + @ExcelProperty("名字")
  25 + private String name;
  26 +
  27 + @ExcelProperty("简介")
  28 + private String description;
  29 +
  30 + @ExcelProperty("出生日期")
  31 + private LocalDateTime birthday;
  32 +
  33 + @ExcelProperty(value = "性别", converter = DictConvert.class)
  34 + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
  35 + private Integer sex;
  36 +
  37 + @ExcelProperty(value = "是否有效", converter = DictConvert.class)
  38 + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
  39 + private Boolean enabled;
  40 +
  41 + @ExcelProperty("头像")
  42 + private String avatar;
  43 +
  44 + @ExcelProperty("附件")
  45 + private String video;
  46 +
  47 + @ExcelProperty("备注")
  48 + private String memo;
  49 +
  50 + @ExcelProperty("创建时间")
  51 + private LocalDateTime createTime;
  52 +
  53 +}
0 54 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExportReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import java.time.LocalDateTime;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Schema(description = "管理后台 - 学生 Excel 导出 Request VO,参数和 InfraDemo12StudentPageReqVO 是一致的")
  13 +@Data
  14 +public class InfraDemo12StudentExportReqVO {
  15 +
  16 + @Schema(description = "名字", example = "芋头")
  17 + private String name;
  18 +
  19 + @Schema(description = "出生日期")
  20 + private LocalDateTime birthday;
  21 +
  22 + @Schema(description = "性别", example = "1")
  23 + private Integer sex;
  24 +
  25 + @Schema(description = "是否有效", example = "true")
  26 + private Boolean enabled;
  27 +
  28 + @Schema(description = "创建时间")
  29 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  30 + private LocalDateTime[] createTime;
  31 +
  32 +}
0 33 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +import java.time.LocalDateTime;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Schema(description = "管理后台 - 学生分页 Request VO")
  13 +@Data
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@ToString(callSuper = true)
  16 +public class InfraDemo12StudentPageReqVO extends PageParam {
  17 +
  18 + @Schema(description = "名字", example = "芋头")
  19 + private String name;
  20 +
  21 + @Schema(description = "出生日期")
  22 + private LocalDateTime birthday;
  23 +
  24 + @Schema(description = "性别", example = "1")
  25 + private Integer sex;
  26 +
  27 + @Schema(description = "是否有效", example = "true")
  28 + private Boolean enabled;
  29 +
  30 + @Schema(description = "创建时间")
  31 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  32 + private LocalDateTime[] createTime;
  33 +
  34 +}
0 35 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.time.LocalDateTime;
  6 +
  7 +@Schema(description = "管理后台 - 学生 Response VO")
  8 +@Data
  9 +@EqualsAndHashCode(callSuper = true)
  10 +@ToString(callSuper = true)
  11 +public class InfraDemo12StudentRespVO extends InfraDemo12StudentBaseVO {
  12 +
  13 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  14 + private Long id;
  15 +
  16 + @Schema(description = "创建时间")
  17 + private LocalDateTime createTime;
  18 +
  19 +}
0 20 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@Schema(description = "管理后台 - 学生更新 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class InfraDemo12StudentUpdateReqVO extends InfraDemo12StudentBaseVO {
  13 +
  14 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  15 + @NotNull(message = "编号不能为空")
  16 + private Long id;
  17 +
  18 +}
0 19 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo12/InfraDemo12StudentConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.convert.demo12;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +
  7 +import org.mapstruct.Mapper;
  8 +import org.mapstruct.factory.Mappers;
  9 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  10 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  11 +
  12 +/**
  13 + * 学生 Convert
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface InfraDemo12StudentConvert {
  19 +
  20 + InfraDemo12StudentConvert INSTANCE = Mappers.getMapper(InfraDemo12StudentConvert.class);
  21 +
  22 + InfraDemo12StudentDO convert(InfraDemo12StudentCreateReqVO bean);
  23 +
  24 + InfraDemo12StudentDO convert(InfraDemo12StudentUpdateReqVO bean);
  25 +
  26 + InfraDemo12StudentRespVO convert(InfraDemo12StudentDO bean);
  27 +
  28 + List<InfraDemo12StudentRespVO> convertList(List<InfraDemo12StudentDO> list);
  29 +
  30 + PageResult<InfraDemo12StudentRespVO> convertPage(PageResult<InfraDemo12StudentDO> page);
  31 +
  32 + List<InfraDemo12StudentExcelVO> convertList02(List<InfraDemo12StudentDO> list);
  33 +
  34 +}
0 35 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentContactDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import com.baomidou.mybatisplus.annotation.*;
  8 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  9 +
  10 +/**
  11 + * 学生联系人 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("infra_demo12_student_contact")
  16 +@KeySequence("infra_demo12_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class InfraDemo12StudentContactDO extends BaseDO {
  24 +
  25 + /**
  26 + * 编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 学生编号
  32 + */
  33 + private Long studentId;
  34 + /**
  35 + * 名字
  36 + */
  37 + private String name;
  38 + /**
  39 + * 简介
  40 + */
  41 + private String description;
  42 + /**
  43 + * 出生日期
  44 + */
  45 + private LocalDateTime birthday;
  46 + /**
  47 + * 性别
  48 + *
  49 + * 枚举 {@link TODO system_user_sex 对应的类}
  50 + */
  51 + private Integer sex;
  52 + /**
  53 + * 是否有效
  54 + *
  55 + * 枚举 {@link TODO infra_boolean_string 对应的类}
  56 + */
  57 + private Boolean enabled;
  58 + /**
  59 + * 头像
  60 + */
  61 + private String avatar;
  62 + /**
  63 + * 附件
  64 + */
  65 + private String video;
  66 + /**
  67 + * 备注
  68 + */
  69 + private String memo;
  70 +
  71 +}
0 72 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import com.baomidou.mybatisplus.annotation.*;
  8 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  9 +
  10 +/**
  11 + * 学生 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("infra_demo12_student")
  16 +@KeySequence("infra_demo12_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class InfraDemo12StudentDO extends BaseDO {
  24 +
  25 + /**
  26 + * 编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 名字
  32 + */
  33 + private String name;
  34 + /**
  35 + * 简介
  36 + */
  37 + private String description;
  38 + /**
  39 + * 出生日期
  40 + */
  41 + private LocalDateTime birthday;
  42 + /**
  43 + * 性别
  44 + *
  45 + * 枚举 {@link TODO system_user_sex 对应的类}
  46 + */
  47 + private Integer sex;
  48 + /**
  49 + * 是否有效
  50 + *
  51 + * 枚举 {@link TODO infra_boolean_string 对应的类}
  52 + */
  53 + private Boolean enabled;
  54 + /**
  55 + * 头像
  56 + */
  57 + private String avatar;
  58 + /**
  59 + * 附件
  60 + */
  61 + private String video;
  62 + /**
  63 + * 备注
  64 + */
  65 + private String memo;
  66 +
  67 +}
0 68 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentTeacherDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import com.baomidou.mybatisplus.annotation.*;
  8 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  9 +
  10 +/**
  11 + * 学生班主任 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("infra_demo12_student_teacher")
  16 +@KeySequence("infra_demo12_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class InfraDemo12StudentTeacherDO extends BaseDO {
  24 +
  25 + /**
  26 + * 编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 学生编号
  32 + */
  33 + private Long studentId;
  34 + /**
  35 + * 名字
  36 + */
  37 + private String name;
  38 + /**
  39 + * 简介
  40 + */
  41 + private String description;
  42 + /**
  43 + * 出生日期
  44 + */
  45 + private LocalDateTime birthday;
  46 + /**
  47 + * 性别
  48 + *
  49 + * 枚举 {@link TODO system_user_sex 对应的类}
  50 + */
  51 + private Integer sex;
  52 + /**
  53 + * 是否有效
  54 + *
  55 + * 枚举 {@link TODO infra_boolean_string 对应的类}
  56 + */
  57 + private Boolean enabled;
  58 + /**
  59 + * 头像
  60 + */
  61 + private String avatar;
  62 + /**
  63 + * 附件
  64 + */
  65 + private String video;
  66 + /**
  67 + * 备注
  68 + */
  69 + private String memo;
  70 +
  71 +}
0 72 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentContactMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  8 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  9 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
  10 +import org.apache.ibatis.annotations.Mapper;
  11 +
  12 +/**
  13 + * 学生联系人 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface InfraDemo12StudentContactMapper extends BaseMapperX<InfraDemo12StudentContactDO> {
  19 +
  20 + default List<InfraDemo12StudentContactDO> selectListByStudentId(Long studentId) {
  21 + return selectList(InfraDemo12StudentContactDO::getStudentId, studentId);
  22 + }
  23 +
  24 + default int deleteByStudentId(Long studentId) {
  25 + return delete(InfraDemo12StudentContactDO::getStudentId, studentId);
  26 + }
  27 +
  28 +}
0 29 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  7 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  9 +import org.apache.ibatis.annotations.Mapper;
  10 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  11 +
  12 +/**
  13 + * 学生 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface InfraDemo12StudentMapper extends BaseMapperX<InfraDemo12StudentDO> {
  19 +
  20 + default PageResult<InfraDemo12StudentDO> selectPage(InfraDemo12StudentPageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<InfraDemo12StudentDO>()
  22 + .likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
  23 + .eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
  24 + .eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
  25 + .eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
  26 + .betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
  27 + .orderByDesc(InfraDemo12StudentDO::getId));
  28 + }
  29 +
  30 + default List<InfraDemo12StudentDO> selectList(InfraDemo12StudentExportReqVO reqVO) {
  31 + return selectList(new LambdaQueryWrapperX<InfraDemo12StudentDO>()
  32 + .likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
  33 + .eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
  34 + .eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
  35 + .eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
  36 + .betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
  37 + .orderByDesc(InfraDemo12StudentDO::getId));
  38 + }
  39 +
  40 +}
0 41 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentTeacherMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  8 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  9 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
  10 +import org.apache.ibatis.annotations.Mapper;
  11 +
  12 +/**
  13 + * 学生班主任 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface InfraDemo12StudentTeacherMapper extends BaseMapperX<InfraDemo12StudentTeacherDO> {
  19 +
  20 + default InfraDemo12StudentTeacherDO selectByStudentId(Long studentId) {
  21 + return selectOne(InfraDemo12StudentTeacherDO::getStudentId, studentId);
  22 + }
  23 +
  24 + default int deleteByStudentId(Long studentId) {
  25 + return delete(InfraDemo12StudentTeacherDO::getStudentId, studentId);
  26 + }
  27 +
  28 +}
0 29 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.service.demo12;
  2 +
  3 +import java.util.*;
  4 +import javax.validation.*;
  5 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  6 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  7 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
  8 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
  9 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  10 +
  11 +/**
  12 + * 学生 Service 接口
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +public interface InfraDemo12StudentService {
  17 +
  18 + /**
  19 + * 创建学生
  20 + *
  21 + * @param createReqVO 创建信息
  22 + * @return 编号
  23 + */
  24 + Long createDemo12Student(@Valid InfraDemo12StudentCreateReqVO createReqVO);
  25 +
  26 + /**
  27 + * 更新学生
  28 + *
  29 + * @param updateReqVO 更新信息
  30 + */
  31 + void updateDemo12Student(@Valid InfraDemo12StudentUpdateReqVO updateReqVO);
  32 +
  33 + /**
  34 + * 删除学生
  35 + *
  36 + * @param id 编号
  37 + */
  38 + void deleteDemo12Student(Long id);
  39 +
  40 + /**
  41 + * 获得学生
  42 + *
  43 + * @param id 编号
  44 + * @return 学生
  45 + */
  46 + InfraDemo12StudentDO getDemo12Student(Long id);
  47 +
  48 + /**
  49 + * 获得学生分页
  50 + *
  51 + * @param pageReqVO 分页查询
  52 + * @return 学生分页
  53 + */
  54 + PageResult<InfraDemo12StudentDO> getDemo12StudentPage(InfraDemo12StudentPageReqVO pageReqVO);
  55 +
  56 + /**
  57 + * 获得学生列表, 用于 Excel 导出
  58 + *
  59 + * @param exportReqVO 查询条件
  60 + * @return 学生列表
  61 + */
  62 + List<InfraDemo12StudentDO> getDemo12StudentList(InfraDemo12StudentExportReqVO exportReqVO);
  63 +
  64 +
  65 + // ==================== 子表(学生联系人) ====================
  66 +
  67 + /**
  68 + * 获得学生联系人列表
  69 + *
  70 + * @param studentId 学生编号
  71 + * @return 学生联系人列表
  72 + */
  73 + List<InfraDemo12StudentContactDO> getDemo12StudentContactListByStudentId(Long studentId);
  74 +
  75 +
  76 + // ==================== 子表(学生班主任) ====================
  77 +
  78 + /**
  79 + * 获得学生班主任
  80 + *
  81 + * @param studentId 学生编号
  82 + * @return 学生班主任
  83 + */
  84 + InfraDemo12StudentTeacherDO getDemo12StudentTeacherByStudentId(Long studentId);
  85 +
  86 +}
0 87 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.service.demo12;
  2 +
  3 +import org.springframework.stereotype.Service;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +import org.springframework.transaction.annotation.Transactional;
  7 +
  8 +import java.util.*;
  9 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  10 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  11 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
  12 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
  13 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  14 +
  15 +import cn.iocoder.yudao.module.infra.convert.demo12.InfraDemo12StudentConvert;
  16 +import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper;
  17 +import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentContactMapper;
  18 +import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentTeacherMapper;
  19 +
  20 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  21 +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
  22 +
  23 +/**
  24 + * 学生 Service 实现类
  25 + *
  26 + * @author 芋道源码
  27 + */
  28 +@Service
  29 +@Validated
  30 +public class InfraDemo12StudentServiceImpl implements InfraDemo12StudentService {
  31 +
  32 + @Resource
  33 + private InfraDemo12StudentMapper demo12StudentMapper;
  34 + @Resource
  35 + private InfraDemo12StudentContactMapper demo12StudentContactMapper;
  36 + @Resource
  37 + private InfraDemo12StudentTeacherMapper demo12StudentTeacherMapper;
  38 +
  39 + @Override
  40 + @Transactional(rollbackFor = Exception.class)
  41 + public Long createDemo12Student(InfraDemo12StudentCreateReqVO createReqVO) {
  42 + // 插入
  43 + InfraDemo12StudentDO demo12Student = InfraDemo12StudentConvert.INSTANCE.convert(createReqVO);
  44 + demo12StudentMapper.insert(demo12Student);
  45 +
  46 + // 插入子表
  47 + createDemo12StudentContactList(demo12Student.getId(), createReqVO.getDemo12StudentContacts());
  48 + createDemo12StudentTeacher(demo12Student.getId(), createReqVO.getDemo12StudentTeacher());
  49 + // 返回
  50 + return demo12Student.getId();
  51 + }
  52 +
  53 + @Override
  54 + @Transactional(rollbackFor = Exception.class)
  55 + public void updateDemo12Student(InfraDemo12StudentUpdateReqVO updateReqVO) {
  56 + // 校验存在
  57 + validateDemo12StudentExists(updateReqVO.getId());
  58 + // 更新
  59 + InfraDemo12StudentDO updateObj = InfraDemo12StudentConvert.INSTANCE.convert(updateReqVO);
  60 + demo12StudentMapper.updateById(updateObj);
  61 +
  62 + // 更新子表
  63 + updateDemo12StudentContactList(updateReqVO.getId(), updateReqVO.getDemo12StudentContacts());
  64 + updateDemo12StudentTeacher(updateReqVO.getId(), updateReqVO.getDemo12StudentTeacher());
  65 + }
  66 +
  67 + @Override
  68 + @Transactional(rollbackFor = Exception.class)
  69 + public void deleteDemo12Student(Long id) {
  70 + // 校验存在
  71 + validateDemo12StudentExists(id);
  72 + // 删除
  73 + demo12StudentMapper.deleteById(id);
  74 +
  75 + // 删除子表
  76 + deleteDemo12StudentContactByStudentId(id);
  77 + deleteDemo12StudentTeacherByStudentId(id);
  78 + }
  79 +
  80 + private void validateDemo12StudentExists(Long id) {
  81 + if (demo12StudentMapper.selectById(id) == null) {
  82 + throw exception(DEMO12_STUDENT_NOT_EXISTS);
  83 + }
  84 + }
  85 +
  86 + @Override
  87 + public InfraDemo12StudentDO getDemo12Student(Long id) {
  88 + return demo12StudentMapper.selectById(id);
  89 + }
  90 +
  91 + @Override
  92 + public PageResult<InfraDemo12StudentDO> getDemo12StudentPage(InfraDemo12StudentPageReqVO pageReqVO) {
  93 + return demo12StudentMapper.selectPage(pageReqVO);
  94 + }
  95 +
  96 + @Override
  97 + public List<InfraDemo12StudentDO> getDemo12StudentList(InfraDemo12StudentExportReqVO exportReqVO) {
  98 + return demo12StudentMapper.selectList(exportReqVO);
  99 + }
  100 +
  101 + // ==================== 子表(学生联系人) ====================
  102 +
  103 + @Override
  104 + public List<InfraDemo12StudentContactDO> getDemo12StudentContactListByStudentId(Long studentId) {
  105 + return demo12StudentContactMapper.selectListByStudentId(studentId);
  106 + }
  107 +
  108 + private void createDemo12StudentContactList(Long studentId, List<InfraDemo12StudentContactDO> list) {
  109 + list.forEach(o -> o.setStudentId(studentId));
  110 + demo12StudentContactMapper.insertBatch(list);
  111 + }
  112 +
  113 + private void updateDemo12StudentContactList(Long studentId, List<InfraDemo12StudentContactDO> list) {
  114 + deleteDemo12StudentContactByStudentId(studentId);
  115 + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
  116 + createDemo12StudentContactList(studentId, list);
  117 + }
  118 +
  119 + private void deleteDemo12StudentContactByStudentId(Long studentId) {
  120 + demo12StudentContactMapper.deleteByStudentId(studentId);
  121 + }
  122 +
  123 + // ==================== 子表(学生班主任) ====================
  124 +
  125 + @Override
  126 + public InfraDemo12StudentTeacherDO getDemo12StudentTeacherByStudentId(Long studentId) {
  127 + return demo12StudentTeacherMapper.selectByStudentId(studentId);
  128 + }
  129 +
  130 + private void createDemo12StudentTeacher(Long studentId, InfraDemo12StudentTeacherDO demo12StudentTeacher) {
  131 + if (demo12StudentTeacher == null) {
  132 + return;
  133 + }
  134 + demo12StudentTeacher.setStudentId(studentId);
  135 + demo12StudentTeacherMapper.insert(demo12StudentTeacher);
  136 + }
  137 +
  138 + private void updateDemo12StudentTeacher(Long studentId, InfraDemo12StudentTeacherDO demo12StudentTeacher) {
  139 + if (demo12StudentTeacher == null) {
  140 + return;
  141 + }
  142 + demo12StudentTeacher.setStudentId(studentId);
  143 + demo12StudentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
  144 + demo12StudentTeacherMapper.insertOrUpdate(demo12StudentTeacher);
  145 + }
  146 +
  147 + private void deleteDemo12StudentTeacherByStudentId(Long studentId) {
  148 + demo12StudentTeacherMapper.deleteByStudentId(studentId);
  149 + }
  150 +
  151 +}
0 152 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm
... ... @@ -69,6 +69,8 @@
69 69 </template>
70 70  
71 71 <script setup lang="ts">
  72 +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
  73 +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
72 74 const props = defineProps<{
73 75 ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
74 76 }>()
... ... @@ -79,15 +81,18 @@ const list = ref([]) // 列表的数据
79 81 const getList = async () => {
80 82 loading.value = true
81 83 try {
82   - #if ( $subTable.subJoinMany )
83   - formData.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val)
84   - #else
85   - const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val)
86   - if (!data) {
87   - return
88   - }
89   - formData.value = data
90   - #end
  84 +#if ($table.templateType == 11)
  85 +#else
  86 + #if ( $subTable.subJoinMany )
  87 + list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}.props)
  88 + #else
  89 + const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}.props)
  90 + if (!data) {
  91 + return
  92 + }
  93 + list.value.push(data)
  94 + #end
  95 +#end
91 96 } finally {
92 97 loading.value = false
93 98 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo12/InfraDemo12StudentMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
0 13 \ No newline at end of file
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java
... ... @@ -467,7 +467,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
467 467 // 主表
468 468 CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene()).setParentMenuId(888L)
469 469 .setTableName("infra_demo12_student").setTableComment("学生表")
470   - .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11Student")
  470 + .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12Student")
471 471 .setClassComment("学生").setAuthor("芋道源码")
472 472 .setTemplateType(CodegenTemplateTypeEnum.MASTER_INNER.getType())
473 473 .setFrontType(CodegenFrontTypeEnum.VUE3.getType());
... ... @@ -549,7 +549,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
549 549 // 子表(联系人)
550 550 CodegenTableDO contactTable = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
551 551 .setTableName("infra_demo12_student_contact").setTableComment("学生联系人表")
552   - .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11StudentContact")
  552 + .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12StudentContact")
553 553 .setClassComment("学生联系人").setAuthor("芋道源码")
554 554 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
555 555 .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
... ... @@ -639,7 +639,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
639 639 // 子表(班主任)
640 640 CodegenTableDO teacherTable = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
641 641 .setTableName("infra_demo12_student_teacher").setTableComment("学生班主任表")
642   - .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11StudentTeacher")
  642 + .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12StudentTeacher")
643 643 .setClassComment("学生班主任").setAuthor("芋道源码")
644 644 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
645 645 .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.service.demo12;
  2 +
  3 +import org.junit.jupiter.api.Disabled;
  4 +import org.junit.jupiter.api.Test;
  5 +import org.springframework.boot.test.mock.mockito.MockBean;
  6 +
  7 +import javax.annotation.Resource;
  8 +
  9 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  10 +
  11 +import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
  12 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
  13 +import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import javax.annotation.Resource;
  17 +import org.springframework.context.annotation.Import;
  18 +import java.util.*;
  19 +import java.time.LocalDateTime;
  20 +
  21 +import static cn.hutool.core.util.RandomUtil.*;
  22 +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
  23 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  24 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  25 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
  26 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  27 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
  28 +import static org.junit.jupiter.api.Assertions.*;
  29 +import static org.mockito.Mockito.*;
  30 +
  31 +/**
  32 + * {@link InfraDemo12StudentServiceImpl} 的单元测试类
  33 + *
  34 + * @author 芋道源码
  35 + */
  36 +@Import(InfraDemo12StudentServiceImpl.class)
  37 +public class InfraDemo12StudentServiceImplTest extends BaseDbUnitTest {
  38 +
  39 + @Resource
  40 + private InfraDemo12StudentServiceImpl demo12StudentService;
  41 +
  42 + @Resource
  43 + private InfraDemo12StudentMapper demo12StudentMapper;
  44 +
  45 + @Test
  46 + public void testCreateDemo12Student_success() {
  47 + // 准备参数
  48 + InfraDemo12StudentCreateReqVO reqVO = randomPojo(InfraDemo12StudentCreateReqVO.class);
  49 +
  50 + // 调用
  51 + Long demo12StudentId = demo12StudentService.createDemo12Student(reqVO);
  52 + // 断言
  53 + assertNotNull(demo12StudentId);
  54 + // 校验记录的属性是否正确
  55 + InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(demo12StudentId);
  56 + assertPojoEquals(reqVO, demo12Student);
  57 + }
  58 +
  59 + @Test
  60 + public void testUpdateDemo12Student_success() {
  61 + // mock 数据
  62 + InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
  63 + demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
  64 + // 准备参数
  65 + InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class, o -> {
  66 + o.setId(dbDemo12Student.getId()); // 设置更新的 ID
  67 + });
  68 +
  69 + // 调用
  70 + demo12StudentService.updateDemo12Student(reqVO);
  71 + // 校验是否更新正确
  72 + InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(reqVO.getId()); // 获取最新的
  73 + assertPojoEquals(reqVO, demo12Student);
  74 + }
  75 +
  76 + @Test
  77 + public void testUpdateDemo12Student_notExists() {
  78 + // 准备参数
  79 + InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class);
  80 +
  81 + // 调用, 并断言异常
  82 + assertServiceException(() -> demo12StudentService.updateDemo12Student(reqVO), DEMO12_STUDENT_NOT_EXISTS);
  83 + }
  84 +
  85 + @Test
  86 + public void testDeleteDemo12Student_success() {
  87 + // mock 数据
  88 + InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
  89 + demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
  90 + // 准备参数
  91 + Long id = dbDemo12Student.getId();
  92 +
  93 + // 调用
  94 + demo12StudentService.deleteDemo12Student(id);
  95 + // 校验数据不存在了
  96 + assertNull(demo12StudentMapper.selectById(id));
  97 + }
  98 +
  99 + @Test
  100 + public void testDeleteDemo12Student_notExists() {
  101 + // 准备参数
  102 + Long id = randomLongId();
  103 +
  104 + // 调用, 并断言异常
  105 + assertServiceException(() -> demo12StudentService.deleteDemo12Student(id), DEMO12_STUDENT_NOT_EXISTS);
  106 + }
  107 +
  108 + @Test
  109 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  110 + public void testGetDemo12StudentPage() {
  111 + // mock 数据
  112 + InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
  113 + o.setName(null);
  114 + o.setBirthday(null);
  115 + o.setSex(null);
  116 + o.setEnabled(null);
  117 + o.setCreateTime(null);
  118 + });
  119 + demo12StudentMapper.insert(dbDemo12Student);
  120 + // 测试 name 不匹配
  121 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
  122 + // 测试 birthday 不匹配
  123 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
  124 + // 测试 sex 不匹配
  125 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
  126 + // 测试 enabled 不匹配
  127 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
  128 + // 测试 createTime 不匹配
  129 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
  130 + // 准备参数
  131 + InfraDemo12StudentPageReqVO reqVO = new InfraDemo12StudentPageReqVO();
  132 + reqVO.setName(null);
  133 + reqVO.setBirthday(null);
  134 + reqVO.setSex(null);
  135 + reqVO.setEnabled(null);
  136 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  137 +
  138 + // 调用
  139 + PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(reqVO);
  140 + // 断言
  141 + assertEquals(1, pageResult.getTotal());
  142 + assertEquals(1, pageResult.getList().size());
  143 + assertPojoEquals(dbDemo12Student, pageResult.getList().get(0));
  144 + }
  145 +
  146 + @Test
  147 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  148 + public void testGetDemo12StudentList() {
  149 + // mock 数据
  150 + InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
  151 + o.setName(null);
  152 + o.setBirthday(null);
  153 + o.setSex(null);
  154 + o.setEnabled(null);
  155 + o.setCreateTime(null);
  156 + });
  157 + demo12StudentMapper.insert(dbDemo12Student);
  158 + // 测试 name 不匹配
  159 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
  160 + // 测试 birthday 不匹配
  161 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
  162 + // 测试 sex 不匹配
  163 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
  164 + // 测试 enabled 不匹配
  165 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
  166 + // 测试 createTime 不匹配
  167 + demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
  168 + // 准备参数
  169 + InfraDemo12StudentExportReqVO reqVO = new InfraDemo12StudentExportReqVO();
  170 + reqVO.setName(null);
  171 + reqVO.setBirthday(null);
  172 + reqVO.setSex(null);
  173 + reqVO.setEnabled(null);
  174 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  175 +
  176 + // 调用
  177 + List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(reqVO);
  178 + // 断言
  179 + assertEquals(1, list.size());
  180 + assertPojoEquals(dbDemo12Student, list.get(0));
  181 + }
  182 +
  183 +}
0 184 \ No newline at end of file
... ...