Commit ee918a6d3f6a3b1c6bd62c19cebddb7444b98d83

Authored by YunaiV
1 parent d2aee55e

代码生成:增加主子表 erp 模式的示例

Showing 18 changed files with 349 additions and 191 deletions
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
@@ -67,4 +67,7 @@ public interface ErrorCodeConstants { @@ -67,4 +67,7 @@ public interface ErrorCodeConstants {
67 ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); 67 ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类");
68 ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); 68 ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类");
69 ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); 69 ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在");
  70 + ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生班级不存在");
  71 + ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_009, "学生班级已存在");
  72 +
70 } 73 }
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/Demo03StudentController.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/Demo03StudentController.java
1 -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal;  
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.*;  
12 -import javax.servlet.http.*;  
13 -import java.util.*;  
14 -import java.io.IOException; 1 +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03;
15 2
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
16 import cn.iocoder.yudao.framework.common.pojo.PageParam; 4 import cn.iocoder.yudao.framework.common.pojo.PageParam;
17 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
18 -import cn.iocoder.yudao.framework.common.pojo.CommonResult;  
19 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
20 -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;  
21 -  
22 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 7 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
23 -  
24 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 8 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
25 -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;  
26 -  
27 -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*;  
28 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; 9 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
  10 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentRespVO;
  11 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
29 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; 12 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
30 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; 13 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
  14 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
31 import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService; 15 import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentService;
  16 +import io.swagger.v3.oas.annotations.Operation;
  17 +import io.swagger.v3.oas.annotations.Parameter;
  18 +import io.swagger.v3.oas.annotations.tags.Tag;
  19 +import org.springframework.security.access.prepost.PreAuthorize;
  20 +import org.springframework.validation.annotation.Validated;
  21 +import org.springframework.web.bind.annotation.*;
  22 +
  23 +import javax.annotation.Resource;
  24 +import javax.servlet.http.HttpServletResponse;
  25 +import javax.validation.Valid;
  26 +import java.io.IOException;
  27 +import java.util.List;
  28 +
  29 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  30 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
32 31
33 @Tag(name = "管理后台 - 学生") 32 @Tag(name = "管理后台 - 学生")
34 @RestController 33 @RestController
@@ -95,6 +94,47 @@ public class Demo03StudentController { @@ -95,6 +94,47 @@ public class Demo03StudentController {
95 94
96 // ==================== 子表(学生课程) ==================== 95 // ==================== 子表(学生课程) ====================
97 96
  97 + @GetMapping("/demo03-course/page")
  98 + @Operation(summary = "获得学生课程分页")
  99 + @Parameter(name = "studentId", description = "学生编号")
  100 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
  101 + public CommonResult<PageResult<Demo03CourseDO>> getDemo03CoursePage(PageParam pageReqVO,
  102 + @RequestParam("studentId") Long studentId) {
  103 + return success(demo03StudentService.getDemo03CoursePage(pageReqVO, studentId));
  104 + }
  105 +
  106 + @PostMapping("/demo03-course/create")
  107 + @Operation(summary = "创建学生课程")
  108 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
  109 + public CommonResult<Long> createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
  110 + return success(demo03StudentService.createDemo03Course(demo03Course));
  111 + }
  112 +
  113 + @PutMapping("/demo03-course/update")
  114 + @Operation(summary = "更新学生课程")
  115 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
  116 + public CommonResult<Boolean> updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) {
  117 + demo03StudentService.updateDemo03Course(demo03Course);
  118 + return success(true);
  119 + }
  120 +
  121 + @DeleteMapping("/demo03-course/delete")
  122 + @Parameter(name = "id", description = "编号", required = true)
  123 + @Operation(summary = "删除学生课程")
  124 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
  125 + public CommonResult<Boolean> deleteDemo03Course(@RequestParam("id") Long id) {
  126 + demo03StudentService.deleteDemo03Course(id);
  127 + return success(true);
  128 + }
  129 +
  130 + @GetMapping("/demo03-course/get")
  131 + @Operation(summary = "获得学生课程")
  132 + @Parameter(name = "id", description = "编号", required = true)
  133 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
  134 + public CommonResult<Demo03CourseDO> getDemo03Course(@RequestParam("id") Long id) {
  135 + return success(demo03StudentService.getDemo03Course(id));
  136 + }
  137 +
98 @GetMapping("/demo03-course/list-by-student-id") 138 @GetMapping("/demo03-course/list-by-student-id")
99 @Operation(summary = "获得学生课程列表") 139 @Operation(summary = "获得学生课程列表")
100 @Parameter(name = "studentId", description = "学生编号") 140 @Parameter(name = "studentId", description = "学生编号")
@@ -105,6 +145,47 @@ public class Demo03StudentController { @@ -105,6 +145,47 @@ public class Demo03StudentController {
105 145
106 // ==================== 子表(学生班级) ==================== 146 // ==================== 子表(学生班级) ====================
107 147
  148 + @GetMapping("/demo03-grade/page")
  149 + @Operation(summary = "获得学生班级分页")
  150 + @Parameter(name = "studentId", description = "学生编号")
  151 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
  152 + public CommonResult<PageResult<Demo03GradeDO>> getDemo03GradePage(PageParam pageReqVO,
  153 + @RequestParam("studentId") Long studentId) {
  154 + return success(demo03StudentService.getDemo03GradePage(pageReqVO, studentId));
  155 + }
  156 +
  157 + @PostMapping("/demo03-grade/create")
  158 + @Operation(summary = "创建学生班级")
  159 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')")
  160 + public CommonResult<Long> createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
  161 + return success(demo03StudentService.createDemo03Grade(demo03Grade));
  162 + }
  163 +
  164 + @PutMapping("/demo03-grade/update")
  165 + @Operation(summary = "更新学生班级")
  166 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')")
  167 + public CommonResult<Boolean> updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) {
  168 + demo03StudentService.updateDemo03Grade(demo03Grade);
  169 + return success(true);
  170 + }
  171 +
  172 + @DeleteMapping("/demo03-grade/delete")
  173 + @Parameter(name = "id", description = "编号", required = true)
  174 + @Operation(summary = "删除学生班级")
  175 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')")
  176 + public CommonResult<Boolean> deleteDemo03Grade(@RequestParam("id") Long id) {
  177 + demo03StudentService.deleteDemo03Grade(id);
  178 + return success(true);
  179 + }
  180 +
  181 + @GetMapping("/demo03-grade/get")
  182 + @Operation(summary = "获得学生班级")
  183 + @Parameter(name = "id", description = "编号", required = true)
  184 + @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')")
  185 + public CommonResult<Demo03GradeDO> getDemo03Grade(@RequestParam("id") Long id) {
  186 + return success(demo03StudentService.getDemo03Grade(id));
  187 + }
  188 +
108 @GetMapping("/demo03-grade/get-by-student-id") 189 @GetMapping("/demo03-grade/get-by-student-id")
109 @Operation(summary = "获得学生班级") 190 @Operation(summary = "获得学生班级")
110 @Parameter(name = "studentId", description = "学生编号") 191 @Parameter(name = "studentId", description = "学生编号")
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentPageReqVO.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentPageReqVO.java
1 -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; 1 +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import io.swagger.v3.oas.annotations.media.Schema; 4 import io.swagger.v3.oas.annotations.media.Schema;
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentRespVO.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentRespVO.java
1 -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; 1 +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.*; 4 import lombok.*;
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentSaveReqVO.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/demo03/vo/Demo03StudentSaveReqVO.java
1 -package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo; 1 +package cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo;
2 2
3 import io.swagger.v3.oas.annotations.media.Schema; 3 import io.swagger.v3.oas.annotations.media.Schema;
4 import lombok.*; 4 import lombok.*;
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/package-info.java
@@ -3,8 +3,6 @@ @@ -3,8 +3,6 @@
3 * 3 *
4 * 1. demo01:单表(增删改查) 4 * 1. demo01:单表(增删改查)
5 * 2. demo02:单表(树形结构) 5 * 2. demo02:单表(树形结构)
6 - * 3.1 demo03/normal:主子表(标准模式)  
7 - * 3.2 demo03/erp:主子表(ERP 模式)  
8 - * 3.3 demo03/inner:主子表(内嵌模式) 6 + * 3. demo03:主子表(标准模式)+ 主子表(ERP 模式)+ 主子表(内嵌模式)
9 */ 7 */
10 package cn.iocoder.yudao.module.infra.controller.admin.demo; 8 package cn.iocoder.yudao.module.infra.controller.admin.demo;
11 \ No newline at end of file 9 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03CourseMapper.java
1 package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; 1 package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
2 2
3 -import java.util.*;  
4 - 3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; 7 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
7 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
8 9
  10 +import java.util.List;
  11 +
9 /** 12 /**
10 * 学生课程 Mapper 13 * 学生课程 Mapper
11 * 14 *
@@ -14,6 +17,12 @@ import org.apache.ibatis.annotations.Mapper; @@ -14,6 +17,12 @@ import org.apache.ibatis.annotations.Mapper;
14 @Mapper 17 @Mapper
15 public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> { 18 public interface Demo03CourseMapper extends BaseMapperX<Demo03CourseDO> {
16 19
  20 + default PageResult<Demo03CourseDO> selectPage(PageParam reqVO, Long studentId) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03CourseDO>()
  22 + .eq(Demo03CourseDO::getStudentId, studentId)
  23 + .orderByDesc(Demo03CourseDO::getId));
  24 + }
  25 +
17 default List<Demo03CourseDO> selectListByStudentId(Long studentId) { 26 default List<Demo03CourseDO> selectListByStudentId(Long studentId) {
18 return selectList(Demo03CourseDO::getStudentId, studentId); 27 return selectList(Demo03CourseDO::getStudentId, studentId);
19 } 28 }
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03GradeMapper.java
1 package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03; 1 package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03;
2 2
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
4 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; 7 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
5 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
6 9
@@ -12,6 +15,12 @@ import org.apache.ibatis.annotations.Mapper; @@ -12,6 +15,12 @@ import org.apache.ibatis.annotations.Mapper;
12 @Mapper 15 @Mapper
13 public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> { 16 public interface Demo03GradeMapper extends BaseMapperX<Demo03GradeDO> {
14 17
  18 + default PageResult<Demo03GradeDO> selectPage(PageParam reqVO, Long studentId) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<Demo03GradeDO>()
  20 + .eq(Demo03GradeDO::getStudentId, studentId)
  21 + .orderByDesc(Demo03GradeDO::getId));
  22 + }
  23 +
15 default Demo03GradeDO selectByStudentId(Long studentId) { 24 default Demo03GradeDO selectByStudentId(Long studentId) {
16 return selectOne(Demo03GradeDO::getStudentId, studentId); 25 return selectOne(Demo03GradeDO::getStudentId, studentId);
17 } 26 }
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/demo03/Demo03StudentMapper.java
@@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; 6 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
7 import org.apache.ibatis.annotations.Mapper; 7 import org.apache.ibatis.annotations.Mapper;
8 -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*; 8 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.*;
9 9
10 /** 10 /**
11 * 学生 Mapper 11 * 学生 Mapper
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
@@ -344,6 +344,7 @@ public class CodegenEngine { @@ -344,6 +344,7 @@ public class CodegenEngine {
344 List<String> subJoinColumnStrikeCases = new ArrayList<>(); 344 List<String> subJoinColumnStrikeCases = new ArrayList<>();
345 List<String> subSimpleClassNames = new ArrayList<>(); 345 List<String> subSimpleClassNames = new ArrayList<>();
346 List<String> subClassNameVars = new ArrayList<>(); 346 List<String> subClassNameVars = new ArrayList<>();
  347 + List<String> simpleClassNameUnderlineCases = new ArrayList<>();
347 List<String> subSimpleClassNameStrikeCases = new ArrayList<>(); 348 List<String> subSimpleClassNameStrikeCases = new ArrayList<>();
348 for (int i = 0; i < subTables.size(); i++) { 349 for (int i = 0; i < subTables.size(); i++) {
349 CodegenTableDO subTable = subTables.get(i); 350 CodegenTableDO subTable = subTables.get(i);
@@ -356,6 +357,7 @@ public class CodegenEngine { @@ -356,6 +357,7 @@ public class CodegenEngine {
356 // className 相关 357 // className 相关
357 String subSimpleClassName = removePrefix(subTable.getClassName(), upperFirst(subTable.getModuleName())); 358 String subSimpleClassName = removePrefix(subTable.getClassName(), upperFirst(subTable.getModuleName()));
358 subSimpleClassNames.add(subSimpleClassName); 359 subSimpleClassNames.add(subSimpleClassName);
  360 + simpleClassNameUnderlineCases.add(toUnderlineCase(subSimpleClassName)); // 将 DictType 转换成 dict_type
359 subClassNameVars.add(lowerFirst(subSimpleClassName)); // 将 DictType 转换成 dictType,用于变量 361 subClassNameVars.add(lowerFirst(subSimpleClassName)); // 将 DictType 转换成 dictType,用于变量
360 subSimpleClassNameStrikeCases.add(toSymbolCase(subSimpleClassName, '-')); // 将 DictType 转换成 dict-type 362 subSimpleClassNameStrikeCases.add(toSymbolCase(subSimpleClassName, '-')); // 将 DictType 转换成 dict-type
361 } 363 }
@@ -363,6 +365,7 @@ public class CodegenEngine { @@ -363,6 +365,7 @@ public class CodegenEngine {
363 bindingMap.put("subJoinColumns", subJoinColumns); 365 bindingMap.put("subJoinColumns", subJoinColumns);
364 bindingMap.put("subJoinColumn_strikeCases", subJoinColumnStrikeCases); 366 bindingMap.put("subJoinColumn_strikeCases", subJoinColumnStrikeCases);
365 bindingMap.put("subSimpleClassNames", subSimpleClassNames); 367 bindingMap.put("subSimpleClassNames", subSimpleClassNames);
  368 + bindingMap.put("simpleClassNameUnderlineCases", simpleClassNameUnderlineCases);
366 bindingMap.put("subClassNameVars", subClassNameVars); 369 bindingMap.put("subClassNameVars", subClassNameVars);
367 bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases); 370 bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases);
368 } 371 }
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentService.java
1 package cn.iocoder.yudao.module.infra.service.demo.demo03; 1 package cn.iocoder.yudao.module.infra.service.demo.demo03;
2 2
3 -import java.util.*;  
4 -import javax.validation.*;  
5 -import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.normal.vo.*;  
6 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; 3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
  6 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
7 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; 7 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
8 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; 8 import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
9 -import cn.iocoder.yudao.framework.common.pojo.PageResult; 9 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
  10 +
  11 +import javax.validation.Valid;
  12 +import java.util.List;
10 13
11 /** 14 /**
12 * 学生 Service 接口 15 * 学生 Service 接口
@@ -64,6 +67,44 @@ public interface Demo03StudentService { @@ -64,6 +67,44 @@ public interface Demo03StudentService {
64 */ 67 */
65 List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId); 68 List<Demo03CourseDO> getDemo03CourseListByStudentId(Long studentId);
66 69
  70 + /**
  71 + * 获得学生课程分页
  72 + *
  73 + * @param pageReqVO 分页查询
  74 + * @param studentId 学生编号
  75 + * @return 学生课程分页
  76 + */
  77 + PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId);
  78 +
  79 + /**
  80 + * 创建学生课程
  81 + *
  82 + * @param demo03Course 创建信息
  83 + * @return 编号
  84 + */
  85 + Long createDemo03Course(@Valid Demo03CourseDO demo03Course);
  86 +
  87 + /**
  88 + * 更新学生课程
  89 + *
  90 + * @param demo03Course 更新信息
  91 + */
  92 + void updateDemo03Course(@Valid Demo03CourseDO demo03Course);
  93 +
  94 + /**
  95 + * 删除学生课程
  96 + *
  97 + * @param id 编号
  98 + */
  99 + void deleteDemo03Course(Long id);
  100 +
  101 + /**
  102 + * 获得学生课程
  103 + *
  104 + * @param id 编号
  105 + * @return 学生课程
  106 + */
  107 + Demo03CourseDO getDemo03Course(Long id);
67 108
68 // ==================== 子表(学生班级) ==================== 109 // ==================== 子表(学生班级) ====================
69 110
@@ -75,4 +116,43 @@ public interface Demo03StudentService { @@ -75,4 +116,43 @@ public interface Demo03StudentService {
75 */ 116 */
76 Demo03GradeDO getDemo03GradeByStudentId(Long studentId); 117 Demo03GradeDO getDemo03GradeByStudentId(Long studentId);
77 118
  119 + /**
  120 + * 获得学生班级分页
  121 + *
  122 + * @param pageReqVO 分页查询
  123 + * @param studentId 学生编号
  124 + * @return 学生班级分页
  125 + */
  126 + PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId);
  127 +
  128 + /**
  129 + * 创建学生班级
  130 + *
  131 + * @param demo03Grade 创建信息
  132 + * @return 编号
  133 + */
  134 + Long createDemo03Grade(@Valid Demo03GradeDO demo03Grade);
  135 +
  136 + /**
  137 + * 更新学生班级
  138 + *
  139 + * @param demo03Grade 更新信息
  140 + */
  141 + void updateDemo03Grade(@Valid Demo03GradeDO demo03Grade);
  142 +
  143 + /**
  144 + * 删除学生班级
  145 + *
  146 + * @param id 编号
  147 + */
  148 + void deleteDemo03Grade(Long id);
  149 +
  150 + /**
  151 + * 获得学生班级
  152 + *
  153 + * @param id 编号
  154 + * @return 学生班级
  155 + */
  156 + Demo03GradeDO getDemo03Grade(Long id);
  157 +
78 } 158 }
79 \ No newline at end of file 159 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/demo03/Demo03StudentServiceImpl.java
1 package cn.iocoder.yudao.module.infra.service.demo.demo03; 1 package cn.iocoder.yudao.module.infra.service.demo.demo03;
2 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.demo.demo03.normal.vo.*;  
10 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;  
11 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;  
12 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; 3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
13 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
14 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
15 -  
16 -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper; 6 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentPageReqVO;
  7 +import cn.iocoder.yudao.module.infra.controller.admin.demo.demo03.vo.Demo03StudentSaveReqVO;
  8 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO;
  9 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO;
  10 +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;
17 import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper; 11 import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03CourseMapper;
18 import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper; 12 import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03GradeMapper;
  13 +import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper;
  14 +import org.springframework.stereotype.Service;
  15 +import org.springframework.transaction.annotation.Transactional;
  16 +import org.springframework.validation.annotation.Validated;
  17 +
  18 +import javax.annotation.Resource;
  19 +import java.util.List;
19 20
20 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; 22 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
@@ -101,7 +102,9 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { @@ -101,7 +102,9 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
101 } 102 }
102 103
103 private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) { 104 private void createDemo03CourseList(Long studentId, List<Demo03CourseDO> list) {
104 - list.forEach(o -> o.setStudentId(studentId)); 105 + if (list != null) {
  106 + list.forEach(o -> o.setStudentId(studentId));
  107 + }
105 demo03CourseMapper.insertBatch(list); 108 demo03CourseMapper.insertBatch(list);
106 } 109 }
107 110
@@ -115,6 +118,32 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { @@ -115,6 +118,32 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
115 demo03CourseMapper.deleteByStudentId(studentId); 118 demo03CourseMapper.deleteByStudentId(studentId);
116 } 119 }
117 120
  121 + @Override
  122 + public PageResult<Demo03CourseDO> getDemo03CoursePage(PageParam pageReqVO, Long studentId) {
  123 + return demo03CourseMapper.selectPage(pageReqVO, studentId);
  124 + }
  125 +
  126 + @Override
  127 + public Long createDemo03Course(Demo03CourseDO demo03Course) {
  128 + demo03CourseMapper.insert(demo03Course);
  129 + return demo03Course.getId();
  130 + }
  131 +
  132 + @Override
  133 + public void updateDemo03Course(Demo03CourseDO demo03Course) {
  134 + demo03CourseMapper.updateById(demo03Course);
  135 + }
  136 +
  137 + @Override
  138 + public void deleteDemo03Course(Long id) {
  139 + demo03CourseMapper.deleteById(id);
  140 + }
  141 +
  142 + @Override
  143 + public Demo03CourseDO getDemo03Course(Long id) {
  144 + return demo03CourseMapper.selectById(id);
  145 + }
  146 +
118 // ==================== 子表(学生班级) ==================== 147 // ==================== 子表(学生班级) ====================
119 148
120 @Override 149 @Override
@@ -143,4 +172,46 @@ public class Demo03StudentServiceImpl implements Demo03StudentService { @@ -143,4 +172,46 @@ public class Demo03StudentServiceImpl implements Demo03StudentService {
143 demo03GradeMapper.deleteByStudentId(studentId); 172 demo03GradeMapper.deleteByStudentId(studentId);
144 } 173 }
145 174
  175 + @Override
  176 + public PageResult<Demo03GradeDO> getDemo03GradePage(PageParam pageReqVO, Long studentId) {
  177 + return demo03GradeMapper.selectPage(pageReqVO, studentId);
  178 + }
  179 +
  180 + @Override
  181 + public Long createDemo03Grade(Demo03GradeDO demo03Grade) {
  182 + // 校验是否已经存在
  183 + if (demo03GradeMapper.selectByStudentId(demo03Grade.getStudentId()) != null) {
  184 + throw exception(DEMO03_GRADE_EXISTS);
  185 + }
  186 + demo03GradeMapper.insert(demo03Grade);
  187 + return demo03Grade.getId();
  188 + }
  189 +
  190 + @Override
  191 + public void updateDemo03Grade(Demo03GradeDO demo03Grade) {
  192 + // 校验存在
  193 + validateDemo03GradeExists(demo03Grade.getId());
  194 + // 更新
  195 + demo03GradeMapper.updateById(demo03Grade);
  196 + }
  197 +
  198 + @Override
  199 + public void deleteDemo03Grade(Long id) {
  200 + // 校验存在
  201 + validateDemo03GradeExists(id);
  202 + // 删除
  203 + demo03GradeMapper.deleteById(id);
  204 + }
  205 +
  206 + @Override
  207 + public Demo03GradeDO getDemo03Grade(Long id) {
  208 + return demo03GradeMapper.selectById(id);
  209 + }
  210 +
  211 + private void validateDemo03GradeExists(Long id) {
  212 + if (demo03GradeMapper.selectById(id) == null) {
  213 + throw exception(DEMO03_GRADE_NOT_EXISTS);
  214 + }
  215 + }
  216 +
146 } 217 }
147 \ No newline at end of file 218 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/enums/errorcode.vm
@@ -8,4 +8,15 @@ ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS = new @@ -8,4 +8,15 @@ ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS = new
8 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR = new ErrorCode(TODO 补充编号, "不能设置自己为父${table.classComment}"); 8 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR = new ErrorCode(TODO 补充编号, "不能设置自己为父${table.classComment}");
9 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE = new ErrorCode(TODO 补充编号, "已经存在该${treeNameColumn.columnComment}的${table.classComment}"); 9 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE = new ErrorCode(TODO 补充编号, "已经存在该${treeNameColumn.columnComment}的${table.classComment}");
10 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD = new ErrorCode(TODO 补充编号, "不能设置自己的子${table.className}为父${table.className}"); 10 ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD = new ErrorCode(TODO 补充编号, "不能设置自己的子${table.className}为父${table.className}");
  11 +#end
  12 +## 特殊:主子表专属逻辑
  13 +#if ( $table.templateType == 11 )## 特殊:ERP 情况
  14 +#foreach ($subTable in $subTables)
  15 +#set ($index = $foreach.count - 1)
  16 +#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
  17 +ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}不存在");
  18 +#if ( !$subTable.subJoinMany )
  19 +ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}已存在");
  20 +#end
  21 +#end
11 #end 22 #end
12 \ No newline at end of file 23 \ No newline at end of file
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm
@@ -75,7 +75,6 @@ public interface ${table.className}Service { @@ -75,7 +75,6 @@ public interface ${table.className}Service {
75 #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 75 #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
76 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 76 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
77 #set ($subClassNameVar = $subClassNameVars.get($index)) 77 #set ($subClassNameVar = $subClassNameVars.get($index))
78 -  
79 // ==================== 子表($subTable.classComment) ==================== 78 // ==================== 子表($subTable.classComment) ====================
80 79
81 ## 情况一:MASTER_ERP 时,需要分查询页子表 80 ## 情况一:MASTER_ERP 时,需要分查询页子表
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm
@@ -235,6 +235,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service @@ -235,6 +235,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
235 #foreach ($subTable in $subTables) 235 #foreach ($subTable in $subTables)
236 #set ($index = $foreach.count - 1) 236 #set ($index = $foreach.count - 1)
237 #set ($subSimpleClassName = $subSimpleClassNames.get($index)) 237 #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  238 +#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
238 #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 239 #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
239 #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 240 #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
240 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 241 #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
@@ -268,24 +269,44 @@ public class ${table.className}ServiceImpl implements ${table.className}Service @@ -268,24 +269,44 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
268 #if ( $table.templateType == 11 ) 269 #if ( $table.templateType == 11 )
269 @Override 270 @Override
270 public ${subPrimaryColumn.javaType} create${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) { 271 public ${subPrimaryColumn.javaType} create${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
  272 +## 特殊:一对一时,需要保证只有一条,不能重复插入
  273 +#if ( !$subTable.subJoinMany)
  274 + // 校验是否已经存在
  275 + if (${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subClassNameVar}.get${SubJoinColumnName}()) != null) {
  276 + throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS);
  277 + }
  278 + // 插入
  279 +#end
271 ${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar}); 280 ${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
272 return ${subClassNameVar}.getId(); 281 return ${subClassNameVar}.getId();
273 } 282 }
274 283
275 @Override 284 @Override
276 public void update${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) { 285 public void update${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
  286 + // 校验存在
  287 + validate${subSimpleClassName}Exists(${subClassNameVar}.getId());
  288 + // 更新
277 ${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar}); 289 ${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar});
278 } 290 }
279 291
280 @Override 292 @Override
281 public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) { 293 public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
  294 + // 校验存在
  295 + validate${subSimpleClassName}Exists(id);
  296 + // 删除
282 ${subClassNameVars.get($index)}Mapper.deleteById(id); 297 ${subClassNameVars.get($index)}Mapper.deleteById(id);
283 } 298 }
284 299
285 - @Override  
286 - public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) { 300 + @Override
  301 + public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
287 return ${subClassNameVars.get($index)}Mapper.selectById(id); 302 return ${subClassNameVars.get($index)}Mapper.selectById(id);
288 - } 303 + }
  304 +
  305 + private void validate${subSimpleClassName}Exists(${subPrimaryColumn.javaType} id) {
  306 + if (${subClassNameVar}Mapper.selectById(id) == null) {
  307 + throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS);
  308 + }
  309 + }
289 310
290 ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 311 ## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作
291 #else 312 #else
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/components/form_sub_erp.vue.vm
@@ -25,7 +25,8 @@ @@ -25,7 +25,8 @@
25 #elseif ($javaType == "Boolean") 25 #elseif ($javaType == "Boolean")
26 #set ($dictMethod = "getBoolDictOptions") 26 #set ($dictMethod = "getBoolDictOptions")
27 #end 27 #end
28 - #if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 TODO 芋艿:这里要忽略下 join 字段; 28 + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
  29 + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
29 <el-form-item label="${comment}" prop="${javaField}"> 30 <el-form-item label="${comment}" prop="${javaField}">
30 <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" /> 31 <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
31 </el-form-item> 32 </el-form-item>
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm
@@ -118,7 +118,7 @@ @@ -118,7 +118,7 @@
118 #end 118 #end
119 </el-form> 119 </el-form>
120 ## 特殊:主子表专属逻辑 120 ## 特殊:主子表专属逻辑
121 -#if ( $subTables && $subTables.size() > 0 ) 121 +#if ( $table.templateType == 10 || $table.templateType == 12 )
122 <!-- 子表的表单 --> 122 <!-- 子表的表单 -->
123 <el-tabs v-model="subTabsName"> 123 <el-tabs v-model="subTabsName">
124 #foreach ($subTable in $subTables) 124 #foreach ($subTable in $subTables)
@@ -146,9 +146,11 @@ import * as ${simpleClassName}Api from &#39;@/api/${table.moduleName}/${table.busine @@ -146,9 +146,11 @@ import * as ${simpleClassName}Api from &#39;@/api/${table.moduleName}/${table.busine
146 import { defaultProps, handleTree } from '@/utils/tree' 146 import { defaultProps, handleTree } from '@/utils/tree'
147 #end 147 #end
148 ## 特殊:主子表专属逻辑 148 ## 特殊:主子表专属逻辑
  149 +#if ( $table.templateType == 10 || $table.templateType == 12 )
149 #foreach ($subSimpleClassName in $subSimpleClassNames) 150 #foreach ($subSimpleClassName in $subSimpleClassNames)
150 import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue' 151 import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
151 #end 152 #end
  153 +#end
152 154
153 const { t } = useI18n() // 国际化 155 const { t } = useI18n() // 国际化
154 const message = useMessage() // 消息弹窗 156 const message = useMessage() // 消息弹窗
@@ -182,6 +184,7 @@ const formRef = ref() // 表单 Ref @@ -182,6 +184,7 @@ const formRef = ref() // 表单 Ref
182 const ${classNameVar}Tree = ref() // 树形结构 184 const ${classNameVar}Tree = ref() // 树形结构
183 #end 185 #end
184 ## 特殊:主子表专属逻辑 186 ## 特殊:主子表专属逻辑
  187 +#if ( $table.templateType == 10 || $table.templateType == 12 )
185 #if ( $subTables && $subTables.size() > 0 ) 188 #if ( $subTables && $subTables.size() > 0 )
186 189
187 /** 子表的表单 */ 190 /** 子表的表单 */
@@ -190,6 +193,7 @@ const subTabsName = ref(&#39;$subClassNameVars.get(0)&#39;) @@ -190,6 +193,7 @@ const subTabsName = ref(&#39;$subClassNameVars.get(0)&#39;)
190 const ${subClassNameVar}FormRef = ref() 193 const ${subClassNameVar}FormRef = ref()
191 #end 194 #end
192 #end 195 #end
  196 +#end
193 197
194 /** 打开弹窗 */ 198 /** 打开弹窗 */
195 const open = async (type: string, id?: number) => { 199 const open = async (type: string, id?: number) => {
@@ -219,6 +223,7 @@ const submitForm = async () =&gt; { @@ -219,6 +223,7 @@ const submitForm = async () =&gt; {
219 // 校验表单 223 // 校验表单
220 await formRef.value.validate() 224 await formRef.value.validate()
221 ## 特殊:主子表专属逻辑 225 ## 特殊:主子表专属逻辑
  226 +#if ( $table.templateType == 10 || $table.templateType == 12 )
222 #if ( $subTables && $subTables.size() > 0 ) 227 #if ( $subTables && $subTables.size() > 0 )
223 // 校验子表单 228 // 校验子表单
224 #foreach ($subTable in $subTables) 229 #foreach ($subTable in $subTables)
@@ -232,11 +237,13 @@ const submitForm = async () =&gt; { @@ -232,11 +237,13 @@ const submitForm = async () =&gt; {
232 } 237 }
233 #end 238 #end
234 #end 239 #end
  240 +#end
235 // 提交请求 241 // 提交请求
236 formLoading.value = true 242 formLoading.value = true
237 try { 243 try {
238 const data = formData.value as unknown as ${simpleClassName}Api.${simpleClassName}VO 244 const data = formData.value as unknown as ${simpleClassName}Api.${simpleClassName}VO
239 ## 特殊:主子表专属逻辑 245 ## 特殊:主子表专属逻辑
  246 +#if ( $table.templateType == 10 || $table.templateType == 12 )
240 #if ( $subTables && $subTables.size() > 0 ) 247 #if ( $subTables && $subTables.size() > 0 )
241 // 拼接子表的数据 248 // 拼接子表的数据
242 #foreach ($subTable in $subTables) 249 #foreach ($subTable in $subTables)
@@ -245,6 +252,7 @@ const submitForm = async () =&gt; { @@ -245,6 +252,7 @@ const submitForm = async () =&gt; {
245 data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData() 252 data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
246 #end 253 #end
247 #end 254 #end
  255 +#end
248 if (formType.value === 'create') { 256 if (formType.value === 'create') {
249 await ${simpleClassName}Api.create${simpleClassName}(data) 257 await ${simpleClassName}Api.create${simpleClassName}(data)
250 message.success(t('common.createSuccess')) 258 message.success(t('common.createSuccess'))
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo03/Demo03StudentServiceImplTest.java deleted
1 -package cn.iocoder.yudao.module.infra.service.demo03;  
2 -  
3 -import cn.iocoder.yudao.module.infra.service.demo.demo03.Demo03StudentServiceImpl;  
4 -import org.junit.jupiter.api.Disabled;  
5 -import org.junit.jupiter.api.Test;  
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.demo.demo03.normal.vo.*;  
12 -import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO;  
13 -import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo03.Demo03StudentMapper;  
14 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
15 -  
16 -import org.springframework.context.annotation.Import;  
17 -  
18 -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;  
19 -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;  
20 -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;  
21 -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;  
22 -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;  
23 -import static org.junit.jupiter.api.Assertions.*;  
24 -  
25 -/**  
26 - * {@link Demo03StudentServiceImpl} 的单元测试类  
27 - *  
28 - * @author 芋道源码  
29 - */  
30 -@Import(Demo03StudentServiceImpl.class)  
31 -public class Demo03StudentServiceImplTest extends BaseDbUnitTest {  
32 -  
33 - @Resource  
34 - private Demo03StudentServiceImpl demo03StudentService;  
35 -  
36 - @Resource  
37 - private Demo03StudentMapper demo03StudentMapper;  
38 -  
39 - @Test  
40 - public void testCreateDemo03Student_success() {  
41 - // 准备参数  
42 - Demo03StudentSaveReqVO createReqVO = randomPojo(Demo03StudentSaveReqVO.class).setId(null);  
43 -  
44 - // 调用  
45 - Long demo03StudentId = demo03StudentService.createDemo03Student(createReqVO);  
46 - // 断言  
47 - assertNotNull(demo03StudentId);  
48 - // 校验记录的属性是否正确  
49 - Demo03StudentDO demo03Student = demo03StudentMapper.selectById(demo03StudentId);  
50 - assertPojoEquals(createReqVO, demo03Student, "id");  
51 - }  
52 -  
53 - @Test  
54 - public void testUpdateDemo03Student_success() {  
55 - // mock 数据  
56 - Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class);  
57 - demo03StudentMapper.insert(dbDemo03Student);// @Sql: 先插入出一条存在的数据  
58 - // 准备参数  
59 - Demo03StudentSaveReqVO updateReqVO = randomPojo(Demo03StudentSaveReqVO.class, o -> {  
60 - o.setId(dbDemo03Student.getId()); // 设置更新的 ID  
61 - });  
62 -  
63 - // 调用  
64 - demo03StudentService.updateDemo03Student(updateReqVO);  
65 - // 校验是否更新正确  
66 - Demo03StudentDO demo03Student = demo03StudentMapper.selectById(updateReqVO.getId()); // 获取最新的  
67 - assertPojoEquals(updateReqVO, demo03Student);  
68 - }  
69 -  
70 - @Test  
71 - public void testUpdateDemo03Student_notExists() {  
72 - // 准备参数  
73 - Demo03StudentSaveReqVO updateReqVO = randomPojo(Demo03StudentSaveReqVO.class);  
74 -  
75 - // 调用, 并断言异常  
76 - assertServiceException(() -> demo03StudentService.updateDemo03Student(updateReqVO), DEMO03_STUDENT_NOT_EXISTS);  
77 - }  
78 -  
79 - @Test  
80 - public void testDeleteDemo03Student_success() {  
81 - // mock 数据  
82 - Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class);  
83 - demo03StudentMapper.insert(dbDemo03Student);// @Sql: 先插入出一条存在的数据  
84 - // 准备参数  
85 - Long id = dbDemo03Student.getId();  
86 -  
87 - // 调用  
88 - demo03StudentService.deleteDemo03Student(id);  
89 - // 校验数据不存在了  
90 - assertNull(demo03StudentMapper.selectById(id));  
91 - }  
92 -  
93 - @Test  
94 - public void testDeleteDemo03Student_notExists() {  
95 - // 准备参数  
96 - Long id = randomLongId();  
97 -  
98 - // 调用, 并断言异常  
99 - assertServiceException(() -> demo03StudentService.deleteDemo03Student(id), DEMO03_STUDENT_NOT_EXISTS);  
100 - }  
101 -  
102 - @Test  
103 - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解  
104 - public void testGetDemo03StudentPage() {  
105 - // mock 数据  
106 - Demo03StudentDO dbDemo03Student = randomPojo(Demo03StudentDO.class, o -> { // 等会查询到  
107 - o.setName(null);  
108 - o.setSex(null);  
109 - o.setDescription(null);  
110 - o.setCreateTime(null);  
111 - });  
112 - demo03StudentMapper.insert(dbDemo03Student);  
113 - // 测试 name 不匹配  
114 - demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setName(null)));  
115 - // 测试 sex 不匹配  
116 - demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setSex(null)));  
117 - // 测试 description 不匹配  
118 - demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setDescription(null)));  
119 - // 测试 createTime 不匹配  
120 - demo03StudentMapper.insert(cloneIgnoreId(dbDemo03Student, o -> o.setCreateTime(null)));  
121 - // 准备参数  
122 - Demo03StudentPageReqVO reqVO = new Demo03StudentPageReqVO();  
123 - reqVO.setName(null);  
124 - reqVO.setSex(null);  
125 - reqVO.setDescription(null);  
126 - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));  
127 -  
128 - // 调用  
129 - PageResult<Demo03StudentDO> pageResult = demo03StudentService.getDemo03StudentPage(reqVO);  
130 - // 断言  
131 - assertEquals(1, pageResult.getTotal());  
132 - assertEquals(1, pageResult.getList().size());  
133 - assertPojoEquals(dbDemo03Student, pageResult.getList().get(0));  
134 - }  
135 -  
136 -}  
137 \ No newline at end of file 0 \ No newline at end of file