فهرست منبع

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

YunaiV 1 سال پیش
والد
کامیت
90842542a9
22فایلهای تغییر یافته به همراه1134 افزوده شده و 13 حذف شده
  1. 4 1
      yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
  2. 115 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/InfraDemo12StudentController.java
  3. 57 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentBaseVO.java
  4. 14 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentCreateReqVO.java
  5. 53 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExcelVO.java
  6. 32 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExportReqVO.java
  7. 34 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentPageReqVO.java
  8. 19 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentRespVO.java
  9. 18 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentUpdateReqVO.java
  10. 34 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo12/InfraDemo12StudentConvert.java
  11. 71 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentContactDO.java
  12. 67 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentDO.java
  13. 71 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentTeacherDO.java
  14. 28 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentContactMapper.java
  15. 40 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentMapper.java
  16. 28 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentTeacherMapper.java
  17. 86 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentService.java
  18. 151 0
      yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImpl.java
  19. 14 9
      yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm
  20. 12 0
      yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo12/InfraDemo12StudentMapper.xml
  21. 3 3
      yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java
  22. 183 0
      yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImplTest.java

+ 4 - 1
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 {
     // ========== 学生(CodegenTemplateTypeEnum.ONE 示例) 1-001-201-000 ==========
     ErrorCode DEMO01_STUDENT_NOT_EXISTS = new ErrorCode(1_001_200_000, "学生不存在");
 
-    // ========== 学生(CodegenTemplateTypeEnum.ONE 示例) 1-001-211-000 ==========
+    // ========== 学生(CodegenTemplateTypeEnum.MASTER_NORMAL 示例) 1-001-211-000 ==========
     ErrorCode DEMO11_STUDENT_NOT_EXISTS = new ErrorCode(1_001_211_000, "学生不存在");
 
+    // ========== 学生(CodegenTemplateTypeEnum.MASTER_INNER 示例) 1-001-213-000 ==========
+    ErrorCode DEMO12_STUDENT_NOT_EXISTS = new ErrorCode(1_001_213_000, "学生不存在");
+
 }

+ 115 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/InfraDemo12StudentController.java

@@ -0,0 +1,115 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12;
+
+import org.springframework.web.bind.annotation.*;
+import javax.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 javax.validation.constraints.*;
+import javax.validation.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+
+import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
+import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
+
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
+import cn.iocoder.yudao.module.infra.convert.demo12.InfraDemo12StudentConvert;
+import cn.iocoder.yudao.module.infra.service.demo12.InfraDemo12StudentService;
+
+@Tag(name = "管理后台 - 学生")
+@RestController
+@RequestMapping("/infra/demo12-student")
+@Validated
+public class InfraDemo12StudentController {
+
+    @Resource
+    private InfraDemo12StudentService demo12StudentService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建学生")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:create')")
+    public CommonResult<Long> createDemo12Student(@Valid @RequestBody InfraDemo12StudentCreateReqVO createReqVO) {
+        return success(demo12StudentService.createDemo12Student(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新学生")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:update')")
+    public CommonResult<Boolean> updateDemo12Student(@Valid @RequestBody InfraDemo12StudentUpdateReqVO updateReqVO) {
+        demo12StudentService.updateDemo12Student(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除学生")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:delete')")
+    public CommonResult<Boolean> deleteDemo12Student(@RequestParam("id") Long id) {
+        demo12StudentService.deleteDemo12Student(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得学生")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
+    public CommonResult<InfraDemo12StudentRespVO> getDemo12Student(@RequestParam("id") Long id) {
+        InfraDemo12StudentDO demo12Student = demo12StudentService.getDemo12Student(id);
+        return success(InfraDemo12StudentConvert.INSTANCE.convert(demo12Student));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得学生分页")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
+    public CommonResult<PageResult<InfraDemo12StudentRespVO>> getDemo12StudentPage(@Valid InfraDemo12StudentPageReqVO pageVO) {
+        PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(pageVO);
+        return success(InfraDemo12StudentConvert.INSTANCE.convertPage(pageResult));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出学生 Excel")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:export')")
+    @OperateLog(type = EXPORT)
+    public void exportDemo12StudentExcel(@Valid InfraDemo12StudentExportReqVO exportReqVO,
+              HttpServletResponse response) throws IOException {
+        List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(exportReqVO);
+        // 导出 Excel
+        List<InfraDemo12StudentExcelVO> datas = InfraDemo12StudentConvert.INSTANCE.convertList02(list);
+        ExcelUtils.write(response, "学生.xls", "数据", InfraDemo12StudentExcelVO.class, datas);
+    }
+
+    // ==================== 子表(学生联系人) ====================
+
+    @GetMapping("/demo12-student/list-by-student-id")
+    @Operation(summary = "获得学生联系人列表")
+    @Parameter(name = "studentId", description = "学生编号")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
+    public CommonResult<List<InfraDemo12StudentContactDO>> getDemo12StudentContactListByStudentId(@RequestParam("studentId") Long studentId) {
+        return success(demo12StudentService.getDemo12StudentContactListByStudentId(studentId));
+    }
+
+    // ==================== 子表(学生班主任) ====================
+
+    @GetMapping("/demo12-student/get-by-student-id")
+    @Operation(summary = "获得学生班主任")
+    @Parameter(name = "studentId", description = "学生编号")
+    @PreAuthorize("@ss.hasPermission('infra:demo12-student:query')")
+    public CommonResult<InfraDemo12StudentTeacherDO> getDemo12StudentTeacherByStudentId(@RequestParam("studentId") Long studentId) {
+        return success(demo12StudentService.getDemo12StudentTeacherByStudentId(studentId));
+    }
+
+}

+ 57 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentBaseVO.java

@@ -0,0 +1,57 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import javax.validation.constraints.*;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
+
+/**
+ * 学生 Base VO,提供给添加、修改、详细的子 VO 使用
+ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
+ */
+@Data
+public class InfraDemo12StudentBaseVO {
+
+    @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头")
+    @NotEmpty(message = "名字不能为空")
+    private String name;
+
+    @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍")
+    @NotEmpty(message = "简介不能为空")
+    private String description;
+
+    @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "出生日期不能为空")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime birthday;
+
+    @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @NotNull(message = "性别不能为空")
+    private Integer sex;
+
+    @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @NotNull(message = "是否有效不能为空")
+    private Boolean enabled;
+
+    @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
+    @NotEmpty(message = "头像不能为空")
+    private String avatar;
+
+    @Schema(description = "附件", example = "https://www.iocoder.cn/1.mp4")
+    private String video;
+
+    @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注")
+    @NotEmpty(message = "备注不能为空")
+    private String memo;
+
+    private List<InfraDemo12StudentContactDO> demo12StudentContacts;
+
+    private InfraDemo12StudentTeacherDO demo12StudentTeacher;
+
+}

+ 14 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentCreateReqVO.java

@@ -0,0 +1,14 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import lombok.*;
+import java.util.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import javax.validation.constraints.*;
+
+@Schema(description = "管理后台 - 学生创建 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class InfraDemo12StudentCreateReqVO extends InfraDemo12StudentBaseVO {
+
+}

+ 53 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExcelVO.java

@@ -0,0 +1,53 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
+import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+
+
+/**
+ * 学生 Excel VO
+ *
+ * @author 芋道源码
+ */
+@Data
+public class InfraDemo12StudentExcelVO {
+
+    @ExcelProperty("编号")
+    private Long id;
+
+    @ExcelProperty("名字")
+    private String name;
+
+    @ExcelProperty("简介")
+    private String description;
+
+    @ExcelProperty("出生日期")
+    private LocalDateTime birthday;
+
+    @ExcelProperty(value = "性别", converter = DictConvert.class)
+    @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
+    private Integer sex;
+
+    @ExcelProperty(value = "是否有效", converter = DictConvert.class)
+    @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
+    private Boolean enabled;
+
+    @ExcelProperty("头像")
+    private String avatar;
+
+    @ExcelProperty("附件")
+    private String video;
+
+    @ExcelProperty("备注")
+    private String memo;
+
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+}

+ 32 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentExportReqVO.java

@@ -0,0 +1,32 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import lombok.*;
+import java.util.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import java.time.LocalDateTime;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 学生 Excel 导出 Request VO,参数和 InfraDemo12StudentPageReqVO 是一致的")
+@Data
+public class InfraDemo12StudentExportReqVO {
+
+    @Schema(description = "名字", example = "芋头")
+    private String name;
+
+    @Schema(description = "出生日期")
+    private LocalDateTime birthday;
+
+    @Schema(description = "性别", example = "1")
+    private Integer sex;
+
+    @Schema(description = "是否有效", example = "true")
+    private Boolean enabled;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 34 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentPageReqVO.java

@@ -0,0 +1,34 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import lombok.*;
+import java.util.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+
+import static cn.iocoder.yudao.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 InfraDemo12StudentPageReqVO extends PageParam {
+
+    @Schema(description = "名字", example = "芋头")
+    private String name;
+
+    @Schema(description = "出生日期")
+    private LocalDateTime birthday;
+
+    @Schema(description = "性别", example = "1")
+    private Integer sex;
+
+    @Schema(description = "是否有效", example = "true")
+    private Boolean enabled;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 19 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentRespVO.java

@@ -0,0 +1,19 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 学生 Response VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class InfraDemo12StudentRespVO extends InfraDemo12StudentBaseVO {
+
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    private Long id;
+
+    @Schema(description = "创建时间")
+    private LocalDateTime createTime;
+
+}

+ 18 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo12/vo/InfraDemo12StudentUpdateReqVO.java

@@ -0,0 +1,18 @@
+package cn.iocoder.yudao.module.infra.controller.admin.demo12.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.util.*;
+import javax.validation.constraints.*;
+
+@Schema(description = "管理后台 - 学生更新 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class InfraDemo12StudentUpdateReqVO extends InfraDemo12StudentBaseVO {
+
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @NotNull(message = "编号不能为空")
+    private Long id;
+
+}

+ 34 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/demo12/InfraDemo12StudentConvert.java

@@ -0,0 +1,34 @@
+package cn.iocoder.yudao.module.infra.convert.demo12;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+
+/**
+ * 学生 Convert
+ *
+ * @author 芋道源码
+ */
+@Mapper
+public interface InfraDemo12StudentConvert {
+
+    InfraDemo12StudentConvert INSTANCE = Mappers.getMapper(InfraDemo12StudentConvert.class);
+
+    InfraDemo12StudentDO convert(InfraDemo12StudentCreateReqVO bean);
+
+    InfraDemo12StudentDO convert(InfraDemo12StudentUpdateReqVO bean);
+
+    InfraDemo12StudentRespVO convert(InfraDemo12StudentDO bean);
+
+    List<InfraDemo12StudentRespVO> convertList(List<InfraDemo12StudentDO> list);
+
+    PageResult<InfraDemo12StudentRespVO> convertPage(PageResult<InfraDemo12StudentDO> page);
+
+    List<InfraDemo12StudentExcelVO> convertList02(List<InfraDemo12StudentDO> list);
+
+}

+ 71 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentContactDO.java

@@ -0,0 +1,71 @@
+package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
+
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 学生联系人 DO
+ *
+ * @author 芋道源码
+ */
+@TableName("infra_demo12_student_contact")
+@KeySequence("infra_demo12_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class InfraDemo12StudentContactDO extends BaseDO {
+
+    /**
+     * 编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 学生编号
+     */
+    private Long studentId;
+    /**
+     * 名字
+     */
+    private String name;
+    /**
+     * 简介
+     */
+    private String description;
+    /**
+     * 出生日期
+     */
+    private LocalDateTime birthday;
+    /**
+     * 性别
+     *
+     * 枚举 {@link TODO system_user_sex 对应的类}
+     */
+    private Integer sex;
+    /**
+     * 是否有效
+     *
+     * 枚举 {@link TODO infra_boolean_string 对应的类}
+     */
+    private Boolean enabled;
+    /**
+     * 头像
+     */
+    private String avatar;
+    /**
+     * 附件
+     */
+    private String video;
+    /**
+     * 备注
+     */
+    private String memo;
+
+}

+ 67 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentDO.java

@@ -0,0 +1,67 @@
+package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
+
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 学生 DO
+ *
+ * @author 芋道源码
+ */
+@TableName("infra_demo12_student")
+@KeySequence("infra_demo12_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class InfraDemo12StudentDO extends BaseDO {
+
+    /**
+     * 编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 名字
+     */
+    private String name;
+    /**
+     * 简介
+     */
+    private String description;
+    /**
+     * 出生日期
+     */
+    private LocalDateTime birthday;
+    /**
+     * 性别
+     *
+     * 枚举 {@link TODO system_user_sex 对应的类}
+     */
+    private Integer sex;
+    /**
+     * 是否有效
+     *
+     * 枚举 {@link TODO infra_boolean_string 对应的类}
+     */
+    private Boolean enabled;
+    /**
+     * 头像
+     */
+    private String avatar;
+    /**
+     * 附件
+     */
+    private String video;
+    /**
+     * 备注
+     */
+    private String memo;
+
+}

+ 71 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo12/InfraDemo12StudentTeacherDO.java

@@ -0,0 +1,71 @@
+package cn.iocoder.yudao.module.infra.dal.dataobject.demo12;
+
+import lombok.*;
+import java.util.*;
+import java.time.LocalDateTime;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 学生班主任 DO
+ *
+ * @author 芋道源码
+ */
+@TableName("infra_demo12_student_teacher")
+@KeySequence("infra_demo12_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class InfraDemo12StudentTeacherDO extends BaseDO {
+
+    /**
+     * 编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 学生编号
+     */
+    private Long studentId;
+    /**
+     * 名字
+     */
+    private String name;
+    /**
+     * 简介
+     */
+    private String description;
+    /**
+     * 出生日期
+     */
+    private LocalDateTime birthday;
+    /**
+     * 性别
+     *
+     * 枚举 {@link TODO system_user_sex 对应的类}
+     */
+    private Integer sex;
+    /**
+     * 是否有效
+     *
+     * 枚举 {@link TODO infra_boolean_string 对应的类}
+     */
+    private Boolean enabled;
+    /**
+     * 头像
+     */
+    private String avatar;
+    /**
+     * 附件
+     */
+    private String video;
+    /**
+     * 备注
+     */
+    private String memo;
+
+}

+ 28 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentContactMapper.java

@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 学生联系人 Mapper
+ *
+ * @author 芋道源码
+ */
+@Mapper
+public interface InfraDemo12StudentContactMapper extends BaseMapperX<InfraDemo12StudentContactDO> {
+
+    default List<InfraDemo12StudentContactDO> selectListByStudentId(Long studentId) {
+        return selectList(InfraDemo12StudentContactDO::getStudentId, studentId);
+    }
+
+    default int deleteByStudentId(Long studentId) {
+        return delete(InfraDemo12StudentContactDO::getStudentId, studentId);
+    }
+
+}

+ 40 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentMapper.java

@@ -0,0 +1,40 @@
+package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+import org.apache.ibatis.annotations.Mapper;
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+
+/**
+ * 学生 Mapper
+ *
+ * @author 芋道源码
+ */
+@Mapper
+public interface InfraDemo12StudentMapper extends BaseMapperX<InfraDemo12StudentDO> {
+
+    default PageResult<InfraDemo12StudentDO> selectPage(InfraDemo12StudentPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<InfraDemo12StudentDO>()
+                .likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
+                .eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
+                .eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
+                .eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
+                .betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(InfraDemo12StudentDO::getId));
+    }
+
+    default List<InfraDemo12StudentDO> selectList(InfraDemo12StudentExportReqVO reqVO) {
+        return selectList(new LambdaQueryWrapperX<InfraDemo12StudentDO>()
+                .likeIfPresent(InfraDemo12StudentDO::getName, reqVO.getName())
+                .eqIfPresent(InfraDemo12StudentDO::getBirthday, reqVO.getBirthday())
+                .eqIfPresent(InfraDemo12StudentDO::getSex, reqVO.getSex())
+                .eqIfPresent(InfraDemo12StudentDO::getEnabled, reqVO.getEnabled())
+                .betweenIfPresent(InfraDemo12StudentDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(InfraDemo12StudentDO::getId));
+    }
+
+}

+ 28 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo12/InfraDemo12StudentTeacherMapper.java

@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.infra.dal.mysql.demo12;
+
+import java.util.*;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 学生班主任 Mapper
+ *
+ * @author 芋道源码
+ */
+@Mapper
+public interface InfraDemo12StudentTeacherMapper extends BaseMapperX<InfraDemo12StudentTeacherDO> {
+
+    default InfraDemo12StudentTeacherDO selectByStudentId(Long studentId) {
+        return selectOne(InfraDemo12StudentTeacherDO::getStudentId, studentId);
+    }
+
+    default int deleteByStudentId(Long studentId) {
+        return delete(InfraDemo12StudentTeacherDO::getStudentId, studentId);
+    }
+
+}

+ 86 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentService.java

@@ -0,0 +1,86 @@
+package cn.iocoder.yudao.module.infra.service.demo12;
+
+import java.util.*;
+import javax.validation.*;
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+
+/**
+ * 学生 Service 接口
+ *
+ * @author 芋道源码
+ */
+public interface InfraDemo12StudentService {
+
+    /**
+     * 创建学生
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createDemo12Student(@Valid InfraDemo12StudentCreateReqVO createReqVO);
+
+    /**
+     * 更新学生
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateDemo12Student(@Valid InfraDemo12StudentUpdateReqVO updateReqVO);
+
+    /**
+     * 删除学生
+     *
+     * @param id 编号
+     */
+    void deleteDemo12Student(Long id);
+
+    /**
+     * 获得学生
+     *
+     * @param id 编号
+     * @return 学生
+     */
+    InfraDemo12StudentDO getDemo12Student(Long id);
+
+    /**
+     * 获得学生分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 学生分页
+     */
+    PageResult<InfraDemo12StudentDO> getDemo12StudentPage(InfraDemo12StudentPageReqVO pageReqVO);
+
+    /**
+     * 获得学生列表, 用于 Excel 导出
+     *
+     * @param exportReqVO 查询条件
+     * @return 学生列表
+     */
+    List<InfraDemo12StudentDO> getDemo12StudentList(InfraDemo12StudentExportReqVO exportReqVO);
+
+
+    // ==================== 子表(学生联系人) ====================
+
+    /**
+     * 获得学生联系人列表
+     *
+     * @param studentId 学生编号
+     * @return 学生联系人列表
+     */
+    List<InfraDemo12StudentContactDO> getDemo12StudentContactListByStudentId(Long studentId);
+
+
+    // ==================== 子表(学生班主任) ====================
+
+    /**
+     * 获得学生班主任
+     *
+     * @param studentId 学生编号
+     * @return 学生班主任
+     */
+    InfraDemo12StudentTeacherDO getDemo12StudentTeacherByStudentId(Long studentId);
+
+}

+ 151 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImpl.java

@@ -0,0 +1,151 @@
+package cn.iocoder.yudao.module.infra.service.demo12;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentContactDO;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentTeacherDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+
+import cn.iocoder.yudao.module.infra.convert.demo12.InfraDemo12StudentConvert;
+import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper;
+import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentContactMapper;
+import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentTeacherMapper;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
+
+/**
+ * 学生 Service 实现类
+ *
+ * @author 芋道源码
+ */
+@Service
+@Validated
+public class InfraDemo12StudentServiceImpl implements InfraDemo12StudentService {
+
+    @Resource
+    private InfraDemo12StudentMapper demo12StudentMapper;
+    @Resource
+    private InfraDemo12StudentContactMapper demo12StudentContactMapper;
+    @Resource
+    private InfraDemo12StudentTeacherMapper demo12StudentTeacherMapper;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Long createDemo12Student(InfraDemo12StudentCreateReqVO createReqVO) {
+        // 插入
+        InfraDemo12StudentDO demo12Student = InfraDemo12StudentConvert.INSTANCE.convert(createReqVO);
+        demo12StudentMapper.insert(demo12Student);
+
+        // 插入子表
+        createDemo12StudentContactList(demo12Student.getId(), createReqVO.getDemo12StudentContacts());
+        createDemo12StudentTeacher(demo12Student.getId(), createReqVO.getDemo12StudentTeacher());
+        // 返回
+        return demo12Student.getId();
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateDemo12Student(InfraDemo12StudentUpdateReqVO updateReqVO) {
+        // 校验存在
+        validateDemo12StudentExists(updateReqVO.getId());
+        // 更新
+        InfraDemo12StudentDO updateObj = InfraDemo12StudentConvert.INSTANCE.convert(updateReqVO);
+        demo12StudentMapper.updateById(updateObj);
+
+        // 更新子表
+        updateDemo12StudentContactList(updateReqVO.getId(), updateReqVO.getDemo12StudentContacts());
+        updateDemo12StudentTeacher(updateReqVO.getId(), updateReqVO.getDemo12StudentTeacher());
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteDemo12Student(Long id) {
+        // 校验存在
+        validateDemo12StudentExists(id);
+        // 删除
+        demo12StudentMapper.deleteById(id);
+
+        // 删除子表
+        deleteDemo12StudentContactByStudentId(id);
+        deleteDemo12StudentTeacherByStudentId(id);
+    }
+
+    private void validateDemo12StudentExists(Long id) {
+        if (demo12StudentMapper.selectById(id) == null) {
+            throw exception(DEMO12_STUDENT_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public InfraDemo12StudentDO getDemo12Student(Long id) {
+        return demo12StudentMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<InfraDemo12StudentDO> getDemo12StudentPage(InfraDemo12StudentPageReqVO pageReqVO) {
+        return demo12StudentMapper.selectPage(pageReqVO);
+    }
+
+    @Override
+    public List<InfraDemo12StudentDO> getDemo12StudentList(InfraDemo12StudentExportReqVO exportReqVO) {
+        return demo12StudentMapper.selectList(exportReqVO);
+    }
+
+    // ==================== 子表(学生联系人) ====================
+
+    @Override
+    public List<InfraDemo12StudentContactDO> getDemo12StudentContactListByStudentId(Long studentId) {
+        return demo12StudentContactMapper.selectListByStudentId(studentId);
+    }
+
+    private void createDemo12StudentContactList(Long studentId, List<InfraDemo12StudentContactDO> list) {
+        list.forEach(o -> o.setStudentId(studentId));
+        demo12StudentContactMapper.insertBatch(list);
+    }
+
+    private void updateDemo12StudentContactList(Long studentId, List<InfraDemo12StudentContactDO> list) {
+        deleteDemo12StudentContactByStudentId(studentId);
+		list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新
+        createDemo12StudentContactList(studentId, list);
+    }
+
+    private void deleteDemo12StudentContactByStudentId(Long studentId) {
+        demo12StudentContactMapper.deleteByStudentId(studentId);
+    }
+
+    // ==================== 子表(学生班主任) ====================
+
+    @Override
+    public InfraDemo12StudentTeacherDO getDemo12StudentTeacherByStudentId(Long studentId) {
+        return demo12StudentTeacherMapper.selectByStudentId(studentId);
+    }
+
+    private void createDemo12StudentTeacher(Long studentId, InfraDemo12StudentTeacherDO demo12StudentTeacher) {
+        if (demo12StudentTeacher == null) {
+            return;
+        }
+        demo12StudentTeacher.setStudentId(studentId);
+        demo12StudentTeacherMapper.insert(demo12StudentTeacher);
+    }
+
+    private void updateDemo12StudentTeacher(Long studentId, InfraDemo12StudentTeacherDO demo12StudentTeacher) {
+        if (demo12StudentTeacher == null) {
+			return;
+        }
+        demo12StudentTeacher.setStudentId(studentId);
+        demo12StudentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新
+        demo12StudentTeacherMapper.insertOrUpdate(demo12StudentTeacher);
+    }
+
+    private void deleteDemo12StudentTeacherByStudentId(Long studentId) {
+        demo12StudentTeacherMapper.deleteByStudentId(studentId);
+    }
+
+}

+ 14 - 9
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm

@@ -69,6 +69,8 @@
 </template>
 
 <script setup lang="ts">
+import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
+import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
 const props = defineProps<{
   ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段)
 }>()
@@ -79,15 +81,18 @@ const list = ref([]) // 列表的数据
 const getList = async () => {
   loading.value = true
   try {
-      #if ( $subTable.subJoinMany )
-        formData.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val)
-      #else
-        const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val)
-        if (!data) {
-          return
-        }
-        formData.value = data
-      #end
+#if ($table.templateType == 11)
+#else
+  #if ( $subTable.subJoinMany )
+    list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}.props)
+  #else
+    const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}.props)
+    if (!data) {
+      return
+    }
+    list.value.push(data)
+  #end
+#end
   } finally {
     loading.value = false
   }

+ 12 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo12/InfraDemo12StudentMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper">
+
+    <!--
+        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
+        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
+        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
+        文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
+     -->
+
+</mapper>

+ 3 - 3
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 {
         // 主表
         CodegenTableDO table = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene()).setParentMenuId(888L)
                 .setTableName("infra_demo12_student").setTableComment("学生表")
-                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11Student")
+                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12Student")
                 .setClassComment("学生").setAuthor("芋道源码")
                 .setTemplateType(CodegenTemplateTypeEnum.MASTER_INNER.getType())
                 .setFrontType(CodegenFrontTypeEnum.VUE3.getType());
@@ -549,7 +549,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
         // 子表(联系人)
         CodegenTableDO contactTable = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
                 .setTableName("infra_demo12_student_contact").setTableComment("学生联系人表")
-                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11StudentContact")
+                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12StudentContact")
                 .setClassComment("学生联系人").setAuthor("芋道源码")
                 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
                 .setFrontType(CodegenFrontTypeEnum.VUE3.getType())
@@ -639,7 +639,7 @@ public class CodegenEngineTest extends BaseMockitoUnitTest {
         // 子表(班主任)
         CodegenTableDO teacherTable = new CodegenTableDO().setScene(CodegenSceneEnum.ADMIN.getScene())
                 .setTableName("infra_demo12_student_teacher").setTableComment("学生班主任表")
-                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo11StudentTeacher")
+                .setModuleName("infra").setBusinessName("demo12").setClassName("InfraDemo12StudentTeacher")
                 .setClassComment("学生班主任").setAuthor("芋道源码")
                 .setTemplateType(CodegenTemplateTypeEnum.SUB.getType())
                 .setFrontType(CodegenFrontTypeEnum.VUE3.getType())

+ 183 - 0
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo12/InfraDemo12StudentServiceImplTest.java

@@ -0,0 +1,183 @@
+package cn.iocoder.yudao.module.infra.service.demo12;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.mock.mockito.MockBean;
+
+import javax.annotation.Resource;
+
+import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
+
+import cn.iocoder.yudao.module.infra.controller.admin.demo12.vo.*;
+import cn.iocoder.yudao.module.infra.dal.dataobject.demo12.InfraDemo12StudentDO;
+import cn.iocoder.yudao.module.infra.dal.mysql.demo12.InfraDemo12StudentMapper;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+
+import javax.annotation.Resource;
+import org.springframework.context.annotation.Import;
+import java.util.*;
+import java.time.LocalDateTime;
+
+import static cn.hutool.core.util.RandomUtil.*;
+import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
+import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
+import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
+import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+/**
+ * {@link InfraDemo12StudentServiceImpl} 的单元测试类
+ *
+ * @author 芋道源码
+ */
+@Import(InfraDemo12StudentServiceImpl.class)
+public class InfraDemo12StudentServiceImplTest extends BaseDbUnitTest {
+
+    @Resource
+    private InfraDemo12StudentServiceImpl demo12StudentService;
+
+    @Resource
+    private InfraDemo12StudentMapper demo12StudentMapper;
+
+    @Test
+    public void testCreateDemo12Student_success() {
+        // 准备参数
+        InfraDemo12StudentCreateReqVO reqVO = randomPojo(InfraDemo12StudentCreateReqVO.class);
+
+        // 调用
+        Long demo12StudentId = demo12StudentService.createDemo12Student(reqVO);
+        // 断言
+        assertNotNull(demo12StudentId);
+        // 校验记录的属性是否正确
+        InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(demo12StudentId);
+        assertPojoEquals(reqVO, demo12Student);
+    }
+
+    @Test
+    public void testUpdateDemo12Student_success() {
+        // mock 数据
+        InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
+        demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
+        // 准备参数
+        InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class, o -> {
+            o.setId(dbDemo12Student.getId()); // 设置更新的 ID
+        });
+
+        // 调用
+        demo12StudentService.updateDemo12Student(reqVO);
+        // 校验是否更新正确
+        InfraDemo12StudentDO demo12Student = demo12StudentMapper.selectById(reqVO.getId()); // 获取最新的
+        assertPojoEquals(reqVO, demo12Student);
+    }
+
+    @Test
+    public void testUpdateDemo12Student_notExists() {
+        // 准备参数
+        InfraDemo12StudentUpdateReqVO reqVO = randomPojo(InfraDemo12StudentUpdateReqVO.class);
+
+        // 调用, 并断言异常
+        assertServiceException(() -> demo12StudentService.updateDemo12Student(reqVO), DEMO12_STUDENT_NOT_EXISTS);
+    }
+
+    @Test
+    public void testDeleteDemo12Student_success() {
+        // mock 数据
+        InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class);
+        demo12StudentMapper.insert(dbDemo12Student);// @Sql: 先插入出一条存在的数据
+        // 准备参数
+        Long id = dbDemo12Student.getId();
+
+        // 调用
+        demo12StudentService.deleteDemo12Student(id);
+       // 校验数据不存在了
+       assertNull(demo12StudentMapper.selectById(id));
+    }
+
+    @Test
+    public void testDeleteDemo12Student_notExists() {
+        // 准备参数
+        Long id = randomLongId();
+
+        // 调用, 并断言异常
+        assertServiceException(() -> demo12StudentService.deleteDemo12Student(id), DEMO12_STUDENT_NOT_EXISTS);
+    }
+
+    @Test
+    @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
+    public void testGetDemo12StudentPage() {
+       // mock 数据
+       InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
+           o.setName(null);
+           o.setBirthday(null);
+           o.setSex(null);
+           o.setEnabled(null);
+           o.setCreateTime(null);
+       });
+       demo12StudentMapper.insert(dbDemo12Student);
+       // 测试 name 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
+       // 测试 birthday 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
+       // 测试 sex 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
+       // 测试 enabled 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
+       // 测试 createTime 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
+       // 准备参数
+       InfraDemo12StudentPageReqVO reqVO = new InfraDemo12StudentPageReqVO();
+       reqVO.setName(null);
+       reqVO.setBirthday(null);
+       reqVO.setSex(null);
+       reqVO.setEnabled(null);
+       reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
+
+       // 调用
+       PageResult<InfraDemo12StudentDO> pageResult = demo12StudentService.getDemo12StudentPage(reqVO);
+       // 断言
+       assertEquals(1, pageResult.getTotal());
+       assertEquals(1, pageResult.getList().size());
+       assertPojoEquals(dbDemo12Student, pageResult.getList().get(0));
+    }
+
+    @Test
+    @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
+    public void testGetDemo12StudentList() {
+       // mock 数据
+       InfraDemo12StudentDO dbDemo12Student = randomPojo(InfraDemo12StudentDO.class, o -> { // 等会查询到
+           o.setName(null);
+           o.setBirthday(null);
+           o.setSex(null);
+           o.setEnabled(null);
+           o.setCreateTime(null);
+       });
+       demo12StudentMapper.insert(dbDemo12Student);
+       // 测试 name 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setName(null)));
+       // 测试 birthday 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setBirthday(null)));
+       // 测试 sex 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setSex(null)));
+       // 测试 enabled 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setEnabled(null)));
+       // 测试 createTime 不匹配
+       demo12StudentMapper.insert(cloneIgnoreId(dbDemo12Student, o -> o.setCreateTime(null)));
+       // 准备参数
+       InfraDemo12StudentExportReqVO reqVO = new InfraDemo12StudentExportReqVO();
+       reqVO.setName(null);
+       reqVO.setBirthday(null);
+       reqVO.setSex(null);
+       reqVO.setEnabled(null);
+       reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
+
+       // 调用
+       List<InfraDemo12StudentDO> list = demo12StudentService.getDemo12StudentList(reqVO);
+       // 断言
+       assertEquals(1, list.size());
+       assertPojoEquals(dbDemo12Student, list.get(0));
+    }
+
+}