Commit 7c09a1fc86dbb50b453dafb2e7c8d2e41cd4c9cc
1 parent
2f6456e2
代码生成器:主子表,支持普通、内嵌、ERP 三种模式
Showing
11 changed files
with
462 additions
and
114 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo02/InfraDemoStudentController.java
| 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo02; | 1 | package cn.iocoder.yudao.module.infra.controller.admin.demo02; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | +import org.springframework.web.bind.annotation.*; |
| 4 | +import javax.annotation.Resource; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 9 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 10 | + | ||
| 11 | +import javax.validation.constraints.*; | ||
| 12 | +import javax.validation.*; | ||
| 13 | +import javax.servlet.http.*; | ||
| 14 | +import java.util.*; | ||
| 15 | +import java.io.IOException; | ||
| 16 | + | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 17 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 20 | + | ||
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 21 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 22 | + | ||
| 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 23 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 24 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 25 | + | ||
| 7 | import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; | 26 | import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; |
| 8 | -import cn.iocoder.yudao.module.infra.convert.demo02.InfraDemoStudentConvert; | ||
| 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; | 27 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; |
| 28 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentContactDO; | ||
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentAddressDO; | ||
| 30 | +import cn.iocoder.yudao.module.infra.convert.demo02.InfraDemoStudentConvert; | ||
| 10 | import cn.iocoder.yudao.module.infra.service.demo02.InfraDemoStudentService; | 31 | import cn.iocoder.yudao.module.infra.service.demo02.InfraDemoStudentService; |
| 11 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 12 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 13 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 14 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 15 | -import org.springframework.validation.annotation.Validated; | ||
| 16 | -import org.springframework.web.bind.annotation.*; | ||
| 17 | - | ||
| 18 | -import javax.annotation.Resource; | ||
| 19 | -import javax.servlet.http.HttpServletResponse; | ||
| 20 | -import javax.validation.Valid; | ||
| 21 | -import java.io.IOException; | ||
| 22 | -import java.util.Collection; | ||
| 23 | -import java.util.List; | ||
| 24 | - | ||
| 25 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 26 | -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||
| 27 | 32 | ||
| 28 | @Tag(name = "管理后台 - 学生") | 33 | @Tag(name = "管理后台 - 学生") |
| 29 | @RestController | 34 | @RestController |
| @@ -87,4 +92,24 @@ public class InfraDemoStudentController { | @@ -87,4 +92,24 @@ public class InfraDemoStudentController { | ||
| 87 | ExcelUtils.write(response, "学生.xls", "数据", InfraDemoStudentExcelVO.class, datas); | 92 | ExcelUtils.write(response, "学生.xls", "数据", InfraDemoStudentExcelVO.class, datas); |
| 88 | } | 93 | } |
| 89 | 94 | ||
| 95 | + // ==================== 子表(学生联系人) ==================== | ||
| 96 | + | ||
| 97 | + @GetMapping("/demo-student/list-by-student-id") | ||
| 98 | + @Operation(summary = "获得学生联系人列表") | ||
| 99 | + @Parameter(name = "studentId", description = "学生编号") | ||
| 100 | + @PreAuthorize("@ss.hasPermission('infra:demo-student:query')") | ||
| 101 | + public CommonResult<List<InfraDemoStudentContactDO>> getDemoStudentContactListByStudentId(@RequestParam("studentId") Long studentId) { | ||
| 102 | + return success(demoStudentService.getDemoStudentContactListByStudentId(studentId)); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + // ==================== 子表(学生地址) ==================== | ||
| 106 | + | ||
| 107 | + @GetMapping("/demo-student/get-by-student-id") | ||
| 108 | + @Operation(summary = "获得学生地址") | ||
| 109 | + @Parameter(name = "studentId", description = "学生编号") | ||
| 110 | + @PreAuthorize("@ss.hasPermission('infra:demo-student:query')") | ||
| 111 | + public CommonResult<InfraDemoStudentAddressDO> getDemoStudentAddressByStudentId(@RequestParam("studentId") Long studentId) { | ||
| 112 | + return success(demoStudentService.getDemoStudentAddressByStudentId(studentId)); | ||
| 113 | + } | ||
| 114 | + | ||
| 90 | } | 115 | } |
| 91 | \ No newline at end of file | 116 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo02/InfraDemoStudentContactMapper.java
| 1 | package cn.iocoder.yudao.module.infra.dal.mysql.demo02; | 1 | package cn.iocoder.yudao.module.infra.dal.mysql.demo02; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentContactDO; | 5 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentContactDO; |
| 5 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenTemplateTypeEnum.java
| @@ -14,8 +14,11 @@ public enum CodegenTemplateTypeEnum { | @@ -14,8 +14,11 @@ public enum CodegenTemplateTypeEnum { | ||
| 14 | 14 | ||
| 15 | ONE(1), // 单表(增删改查) | 15 | ONE(1), // 单表(增删改查) |
| 16 | TREE(2), // 树表(增删改查) | 16 | TREE(2), // 树表(增删改查) |
| 17 | - MASTER(10), // 主子表 - 主表 | ||
| 18 | - SUB(11), // 主子表 - 子表 | 17 | + |
| 18 | + MASTER_NORMAL(10), // 主子表 - 主表 - 普通模式 | ||
| 19 | + MASTER_ERP(11), // 主子表 - 主表 - ERP 模式 | ||
| 20 | + MASTER_INNER(12), // 主子表 - 主表 - 内嵌模式 | ||
| 21 | + SUB(15), // 主子表 - 子表 | ||
| 19 | ; | 22 | ; |
| 20 | 23 | ||
| 21 | /** | 24 | /** |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| @@ -193,6 +193,44 @@ public class CodegenEngine { | @@ -193,6 +193,44 @@ public class CodegenEngine { | ||
| 193 | */ | 193 | */ |
| 194 | public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns, | 194 | public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns, |
| 195 | List<CodegenTableDO> subTables, List<List<CodegenColumnDO>> subColumnsList) { | 195 | List<CodegenTableDO> subTables, List<List<CodegenColumnDO>> subColumnsList) { |
| 196 | + // 1.1 初始化 bindMap 上下文 | ||
| 197 | + Map<String, Object> bindingMap = initBindingMap(table, columns, subTables, subColumnsList); | ||
| 198 | + // 1.2 获得模版 | ||
| 199 | + Map<String, String> templates = getTemplates(table.getFrontType()); | ||
| 200 | + | ||
| 201 | + // 2. 执行生成 | ||
| 202 | + Map<String, String> result = Maps.newLinkedHashMapWithExpectedSize(templates.size()); // 有序 | ||
| 203 | + templates.forEach((vmPath, filePath) -> { | ||
| 204 | + // 2.1 特殊:主子表专属逻辑 | ||
| 205 | + if (isSubTemplate(vmPath)) { | ||
| 206 | + if (CollUtil.isEmpty(subTables)) { | ||
| 207 | + return; | ||
| 208 | + } | ||
| 209 | + for (int i = 0; i < subTables.size(); i++) { | ||
| 210 | + bindingMap.put("subIndex", i); | ||
| 211 | + generateCode(result, vmPath, filePath, bindingMap); | ||
| 212 | + } | ||
| 213 | + bindingMap.remove("subIndex"); | ||
| 214 | + return; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + // 2.2 默认生成 | ||
| 218 | + generateCode(result, vmPath, filePath, bindingMap); | ||
| 219 | + }); | ||
| 220 | + return result; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + private void generateCode(Map<String, String> result, String vmPath, | ||
| 224 | + String filePath, Map<String, Object> bindingMap) { | ||
| 225 | + filePath = formatFilePath(filePath, bindingMap); | ||
| 226 | + String content = templateEngine.getTemplate(vmPath).render(bindingMap); | ||
| 227 | + // 去除字段后面多余的 , 逗号 | ||
| 228 | + content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); | ||
| 229 | + result.put(filePath, content); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + private Map<String, Object> initBindingMap(CodegenTableDO table, List<CodegenColumnDO> columns, | ||
| 233 | + List<CodegenTableDO> subTables, List<List<CodegenColumnDO>> subColumnsList) { | ||
| 196 | // 创建 bindingMap | 234 | // 创建 bindingMap |
| 197 | Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); | 235 | Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); |
| 198 | bindingMap.put("table", table); | 236 | bindingMap.put("table", table); |
| @@ -217,60 +255,40 @@ public class CodegenEngine { | @@ -217,60 +255,40 @@ public class CodegenEngine { | ||
| 217 | // 创建 bindingMap | 255 | // 创建 bindingMap |
| 218 | bindingMap.put("subTables", subTables); | 256 | bindingMap.put("subTables", subTables); |
| 219 | bindingMap.put("subColumnsList", subColumnsList); | 257 | bindingMap.put("subColumnsList", subColumnsList); |
| 258 | + List<CodegenColumnDO> subPrimaryColumns = new ArrayList<>(); | ||
| 220 | List<CodegenColumnDO> subJoinColumns = new ArrayList<>(); | 259 | List<CodegenColumnDO> subJoinColumns = new ArrayList<>(); |
| 260 | + List<String> subJoinColumnStrikeCases = new ArrayList<>(); | ||
| 221 | List<String> subSimpleClassNames = new ArrayList<>(); | 261 | List<String> subSimpleClassNames = new ArrayList<>(); |
| 222 | List<String> subClassNameVars = new ArrayList<>(); | 262 | List<String> subClassNameVars = new ArrayList<>(); |
| 263 | + List<String> subSimpleClassNameStrikeCases = new ArrayList<>(); | ||
| 223 | for (int i = 0; i < subTables.size(); i++) { | 264 | for (int i = 0; i < subTables.size(); i++) { |
| 224 | CodegenTableDO subTable = subTables.get(i); | 265 | CodegenTableDO subTable = subTables.get(i); |
| 225 | List<CodegenColumnDO> subColumns = subColumnsList.get(i); | 266 | List<CodegenColumnDO> subColumns = subColumnsList.get(i); |
| 226 | - subJoinColumns.add(CollectionUtils.findFirst(subColumns, // 关联的字段 | ||
| 227 | - column -> Objects.equals(column.getId(), subTable.getSubJoinColumnId()))); | 267 | + subPrimaryColumns.add(CollectionUtils.findFirst(subColumns, CodegenColumnDO::getPrimaryKey)); // |
| 268 | + CodegenColumnDO subColumn = CollectionUtils.findFirst(subColumns, // 关联的字段 | ||
| 269 | + column -> Objects.equals(column.getId(), subTable.getSubJoinColumnId())); | ||
| 270 | + subJoinColumns.add(subColumn); | ||
| 271 | + subJoinColumnStrikeCases.add(toSymbolCase(subColumn.getJavaField(), '-')); // 将 DictType 转换成 dict-type | ||
| 228 | // className 相关 | 272 | // className 相关 |
| 229 | String subSimpleClassName = removePrefix(subTable.getClassName(), upperFirst(subTable.getModuleName())); | 273 | String subSimpleClassName = removePrefix(subTable.getClassName(), upperFirst(subTable.getModuleName())); |
| 230 | subSimpleClassNames.add(subSimpleClassName); | 274 | subSimpleClassNames.add(subSimpleClassName); |
| 231 | subClassNameVars.add(lowerFirst(subSimpleClassName)); // 将 DictType 转换成 dictType,用于变量 | 275 | subClassNameVars.add(lowerFirst(subSimpleClassName)); // 将 DictType 转换成 dictType,用于变量 |
| 276 | + subSimpleClassNameStrikeCases.add(toSymbolCase(simpleClassName, '-')); // 将 DictType 转换成 dict-type | ||
| 232 | } | 277 | } |
| 278 | + bindingMap.put("subPrimaryColumns", subPrimaryColumns); | ||
| 233 | bindingMap.put("subJoinColumns", subJoinColumns); | 279 | bindingMap.put("subJoinColumns", subJoinColumns); |
| 280 | + bindingMap.put("subJoinColumn_strikeCases", subJoinColumnStrikeCases); | ||
| 234 | bindingMap.put("subSimpleClassNames", subSimpleClassNames); | 281 | bindingMap.put("subSimpleClassNames", subSimpleClassNames); |
| 235 | bindingMap.put("subClassNameVars", subClassNameVars); | 282 | bindingMap.put("subClassNameVars", subClassNameVars); |
| 283 | + bindingMap.put("subSimpleClassName_strikeCases", subSimpleClassNameStrikeCases); | ||
| 236 | } | 284 | } |
| 237 | - | ||
| 238 | - // 执行生成 | ||
| 239 | - Map<String, String> templates = getTemplates(table.getTemplateType(), table.getFrontType()); | ||
| 240 | - Map<String, String> result = Maps.newLinkedHashMapWithExpectedSize(templates.size()); // 有序 | ||
| 241 | - templates.forEach((vmPath, filePath) -> { | ||
| 242 | - // 特殊:主子表专属逻辑 | ||
| 243 | - if (isSubTemplate(vmPath)) { | ||
| 244 | - for (int i = 0; i < subTables.size(); i++) { | ||
| 245 | - bindingMap.put("subIndex", i); | ||
| 246 | - // TODO 芋艿:这块需要优化下逻辑 | ||
| 247 | - String newFilePath = formatFilePath(filePath, bindingMap); | ||
| 248 | - String content = templateEngine.getTemplate(vmPath).render(bindingMap); | ||
| 249 | - // 去除字段后面多余的 , 逗号 | ||
| 250 | - content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); | ||
| 251 | - result.put(newFilePath, content); | ||
| 252 | - bindingMap.remove("subIndex"); | ||
| 253 | - } | ||
| 254 | - } else { | ||
| 255 | - filePath = formatFilePath(filePath, bindingMap); | ||
| 256 | - String content = templateEngine.getTemplate(vmPath).render(bindingMap); | ||
| 257 | - // 去除字段后面多余的 , 逗号 | ||
| 258 | - content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); | ||
| 259 | - result.put(filePath, content); | ||
| 260 | - } | ||
| 261 | - }); | ||
| 262 | - return result; | 285 | + return bindingMap; |
| 263 | } | 286 | } |
| 264 | 287 | ||
| 265 | - private Map<String, String> getTemplates(Integer templateType, Integer frontType) { | 288 | + private Map<String, String> getTemplates(Integer frontType) { |
| 266 | Map<String, String> templates = new LinkedHashMap<>(); | 289 | Map<String, String> templates = new LinkedHashMap<>(); |
| 267 | templates.putAll(SERVER_TEMPLATES); | 290 | templates.putAll(SERVER_TEMPLATES); |
| 268 | templates.putAll(FRONT_TEMPLATES.row(frontType)); | 291 | templates.putAll(FRONT_TEMPLATES.row(frontType)); |
| 269 | - // 特殊:主子表专属逻辑 | ||
| 270 | - if (ObjUtil.notEqual(templateType, CodegenTemplateTypeEnum.MASTER.getType())) { | ||
| 271 | - templates.remove(javaTemplatePath("dal/do_sub")); | ||
| 272 | - templates.remove(javaTemplatePath("dal/mapper_sub")); | ||
| 273 | - } | ||
| 274 | return templates; | 292 | return templates; |
| 275 | } | 293 | } |
| 276 | 294 |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo02/InfraDemoStudentService.java
| 1 | package cn.iocoder.yudao.module.infra.service.demo02; | 1 | package cn.iocoder.yudao.module.infra.service.demo02; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.InfraDemoStudentCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.InfraDemoStudentExportReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.InfraDemoStudentPageReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.InfraDemoStudentUpdateReqVO; | 3 | +import java.util.*; |
| 4 | +import javax.validation.*; | ||
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; | ||
| 8 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; | 6 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; |
| 9 | - | ||
| 10 | -import javax.validation.Valid; | ||
| 11 | -import java.util.Collection; | ||
| 12 | -import java.util.List; | 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentContactDO; |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentAddressDO; | ||
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 13 | 10 | ||
| 14 | /** | 11 | /** |
| 15 | * 学生 Service 接口 | 12 | * 学生 Service 接口 |
| @@ -65,4 +62,25 @@ public interface InfraDemoStudentService { | @@ -65,4 +62,25 @@ public interface InfraDemoStudentService { | ||
| 65 | List<InfraDemoStudentDO> getDemoStudentList(InfraDemoStudentExportReqVO exportReqVO); | 62 | List<InfraDemoStudentDO> getDemoStudentList(InfraDemoStudentExportReqVO exportReqVO); |
| 66 | 63 | ||
| 67 | 64 | ||
| 65 | + // ==================== 子表(学生联系人) ==================== | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获得学生联系人列表 | ||
| 69 | + * | ||
| 70 | + * @param studentId 学生编号 | ||
| 71 | + * @return 学生联系人列表 | ||
| 72 | + */ | ||
| 73 | + List<InfraDemoStudentContactDO> getDemoStudentContactListByStudentId(Long studentId); | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + // ==================== 子表(学生地址) ==================== | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 获得学生地址 | ||
| 80 | + * | ||
| 81 | + * @param studentId 学生编号 | ||
| 82 | + * @return 学生地址 | ||
| 83 | + */ | ||
| 84 | + InfraDemoStudentAddressDO getDemoStudentAddressByStudentId(Long studentId); | ||
| 85 | + | ||
| 68 | } | 86 | } |
| 69 | \ No newline at end of file | 87 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo02/InfraDemoStudentServiceImpl.java
| @@ -8,6 +8,8 @@ import org.springframework.transaction.annotation.Transactional; | @@ -8,6 +8,8 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 8 | import java.util.*; | 8 | import java.util.*; |
| 9 | import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; | 9 | import cn.iocoder.yudao.module.infra.controller.admin.demo02.vo.*; |
| 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentDO; |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentContactDO; | ||
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo02.InfraDemoStudentAddressDO; | ||
| 11 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 13 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 12 | 14 | ||
| 13 | import cn.iocoder.yudao.module.infra.convert.demo02.InfraDemoStudentConvert; | 15 | import cn.iocoder.yudao.module.infra.convert.demo02.InfraDemoStudentConvert; |
| @@ -43,12 +45,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | @@ -43,12 +45,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | ||
| 43 | // 插入 | 45 | // 插入 |
| 44 | InfraDemoStudentDO demoStudent = InfraDemoStudentConvert.INSTANCE.convert(createReqVO); | 46 | InfraDemoStudentDO demoStudent = InfraDemoStudentConvert.INSTANCE.convert(createReqVO); |
| 45 | demoStudentMapper.insert(demoStudent); | 47 | demoStudentMapper.insert(demoStudent); |
| 46 | - // 插入子表(学生联系人) | ||
| 47 | - createReqVO.getDemoStudentContacts().forEach(o -> o.setStudentId(demoStudent.getId())); | ||
| 48 | - demoStudentContactMapper.insertBatch(createReqVO.getDemoStudentContacts()); | ||
| 49 | - // 插入子表(学生地址) | ||
| 50 | - createReqVO.getDemoStudentAddress().setStudentId(demoStudent.getId()); | ||
| 51 | - demoStudentAddressMapper.insert(createReqVO.getDemoStudentAddress()); | 48 | + |
| 49 | + // 插入子表($subTable.classComment) | ||
| 50 | + createDemoStudentContactList(demoStudent.getId(), createReqVO.getDemoStudentContacts()); | ||
| 51 | + createDemoStudentAddress(demoStudent.getId(), createReqVO.getDemoStudentAddress()); | ||
| 52 | // 返回 | 52 | // 返回 |
| 53 | return demoStudent.getId(); | 53 | return demoStudent.getId(); |
| 54 | } | 54 | } |
| @@ -61,13 +61,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | @@ -61,13 +61,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | ||
| 61 | // 更新 | 61 | // 更新 |
| 62 | InfraDemoStudentDO updateObj = InfraDemoStudentConvert.INSTANCE.convert(updateReqVO); | 62 | InfraDemoStudentDO updateObj = InfraDemoStudentConvert.INSTANCE.convert(updateReqVO); |
| 63 | demoStudentMapper.updateById(updateObj); | 63 | demoStudentMapper.updateById(updateObj); |
| 64 | - // 更新子表(学生联系人) | ||
| 65 | - demoStudentContactMapper.deleteByStudentId(updateReqVO.getId()); | ||
| 66 | - updateReqVO.getDemoStudentContacts().forEach(o -> o.setStudentId(updateReqVO.getId())); | ||
| 67 | - demoStudentContactMapper.insertBatch(updateReqVO.getDemoStudentContacts()); | ||
| 68 | - // 更新子表(学生地址) | ||
| 69 | - updateReqVO.getDemoStudentAddress().setStudentId(updateReqVO.getId()); | ||
| 70 | - demoStudentAddressMapper.updateById(updateReqVO.getDemoStudentAddress()); | 64 | + |
| 65 | + // 更新子表 | ||
| 66 | + updateDemoStudentContactList(updateReqVO.getId(), updateReqVO.getDemoStudentContacts()); | ||
| 67 | + updateDemoStudentAddress(updateReqVO.getId(), updateReqVO.getDemoStudentAddress()); | ||
| 71 | } | 68 | } |
| 72 | 69 | ||
| 73 | @Override | 70 | @Override |
| @@ -77,10 +74,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | @@ -77,10 +74,10 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | ||
| 77 | validateDemoStudentExists(id); | 74 | validateDemoStudentExists(id); |
| 78 | // 删除 | 75 | // 删除 |
| 79 | demoStudentMapper.deleteById(id); | 76 | demoStudentMapper.deleteById(id); |
| 80 | - // 删除子表(学生联系人) | ||
| 81 | - demoStudentContactMapper.deleteByStudentId(id); | ||
| 82 | - // 删除子表(学生地址) | ||
| 83 | - demoStudentAddressMapper.deleteByStudentId(id); | 77 | + |
| 78 | + // 删除子表 | ||
| 79 | + deleteDemoStudentContactByStudentId(id); | ||
| 80 | + deleteDemoStudentAddressByStudentId(id); | ||
| 84 | } | 81 | } |
| 85 | 82 | ||
| 86 | private void validateDemoStudentExists(Long id) { | 83 | private void validateDemoStudentExists(Long id) { |
| @@ -104,4 +101,46 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | @@ -104,4 +101,46 @@ public class InfraDemoStudentServiceImpl implements InfraDemoStudentService { | ||
| 104 | return demoStudentMapper.selectList(exportReqVO); | 101 | return demoStudentMapper.selectList(exportReqVO); |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 104 | + // ==================== 子表(学生联系人) ==================== | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public List<InfraDemoStudentContactDO> getDemoStudentContactListByStudentId(Long studentId) { | ||
| 108 | + return demoStudentContactMapper.selectListByStudentId(studentId); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + private void createDemoStudentContactList(Long studentId, List<InfraDemoStudentContactDO> list) { | ||
| 112 | + list.forEach(o -> o.setStudentId(studentId)); | ||
| 113 | + demoStudentContactMapper.insertBatch(list); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + private void updateDemoStudentContactList(Long studentId, List<InfraDemoStudentContactDO> list) { | ||
| 117 | + deleteDemoStudentContactByStudentId(studentId); | ||
| 118 | + createDemoStudentContactList(studentId, list); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + private void deleteDemoStudentContactByStudentId(Long studentId) { | ||
| 122 | + demoStudentContactMapper.deleteByStudentId(studentId); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + // ==================== 子表(学生地址) ==================== | ||
| 126 | + | ||
| 127 | + @Override | ||
| 128 | + public InfraDemoStudentAddressDO getDemoStudentAddressByStudentId(Long studentId) { | ||
| 129 | + return demoStudentAddressMapper.selectByStudentId(studentId); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + private void createDemoStudentAddress(Long studentId, InfraDemoStudentAddressDO demoStudentAddress) { | ||
| 133 | + demoStudentAddress.setStudentId(studentId); | ||
| 134 | + demoStudentAddressMapper.insert(demoStudentAddress); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + private void updateDemoStudentAddress(Long studentId, InfraDemoStudentAddressDO demoStudentAddress) { | ||
| 138 | + demoStudentAddress.setStudentId(studentId); | ||
| 139 | + demoStudentAddressMapper.updateById(demoStudentAddress); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + private void deleteDemoStudentAddressByStudentId(Long studentId) { | ||
| 143 | + demoStudentAddressMapper.deleteByStudentId(studentId); | ||
| 144 | + } | ||
| 145 | + | ||
| 107 | } | 146 | } |
| 108 | \ No newline at end of file | 147 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/controller/controller.vm
| @@ -26,6 +26,10 @@ import static ${OperateTypeEnumClassName}.*; | @@ -26,6 +26,10 @@ import static ${OperateTypeEnumClassName}.*; | ||
| 26 | 26 | ||
| 27 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; | 27 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
| 28 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; | 28 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
| 29 | +## 特殊:主子表专属逻辑 | ||
| 30 | +#foreach ($subTable in $subTables) | ||
| 31 | +import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; | ||
| 32 | +#end | ||
| 29 | import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; | 33 | import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; |
| 30 | import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service; | 34 | import ${basePackage}.module.${table.moduleName}.service.${table.businessName}.${table.className}Service; |
| 31 | 35 | ||
| @@ -41,16 +45,18 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -41,16 +45,18 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 41 | 45 | ||
| 42 | @PostMapping("/create") | 46 | @PostMapping("/create") |
| 43 | @Operation(summary = "创建${table.classComment}") | 47 | @Operation(summary = "创建${table.classComment}") |
| 44 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')")#end | ||
| 45 | - | 48 | +#if ($sceneEnum.scene == 1) |
| 49 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") | ||
| 50 | +#end | ||
| 46 | public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { | 51 | public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { |
| 47 | return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); | 52 | return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | @PutMapping("/update") | 55 | @PutMapping("/update") |
| 51 | @Operation(summary = "更新${table.classComment}") | 56 | @Operation(summary = "更新${table.classComment}") |
| 52 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')")#end | ||
| 53 | - | 57 | +#if ($sceneEnum.scene == 1) |
| 58 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") | ||
| 59 | +#end | ||
| 54 | public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { | 60 | public CommonResult<Boolean> update${simpleClassName}(@Valid @RequestBody ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { |
| 55 | ${classNameVar}Service.update${simpleClassName}(updateReqVO); | 61 | ${classNameVar}Service.update${simpleClassName}(updateReqVO); |
| 56 | return success(true); | 62 | return success(true); |
| @@ -59,8 +65,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -59,8 +65,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 59 | @DeleteMapping("/delete") | 65 | @DeleteMapping("/delete") |
| 60 | @Operation(summary = "删除${table.classComment}") | 66 | @Operation(summary = "删除${table.classComment}") |
| 61 | @Parameter(name = "id", description = "编号", required = true) | 67 | @Parameter(name = "id", description = "编号", required = true) |
| 62 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")#end | ||
| 63 | - | 68 | +#if ($sceneEnum.scene == 1) |
| 69 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | ||
| 70 | +#end | ||
| 64 | public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { | 71 | public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { |
| 65 | ${classNameVar}Service.delete${simpleClassName}(id); | 72 | ${classNameVar}Service.delete${simpleClassName}(id); |
| 66 | return success(true); | 73 | return success(true); |
| @@ -69,8 +76,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -69,8 +76,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 69 | @GetMapping("/get") | 76 | @GetMapping("/get") |
| 70 | @Operation(summary = "获得${table.classComment}") | 77 | @Operation(summary = "获得${table.classComment}") |
| 71 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 78 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 72 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end | ||
| 73 | - | 79 | +#if ($sceneEnum.scene == 1) |
| 80 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | ||
| 81 | +#end | ||
| 74 | public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { | 82 | public CommonResult<${sceneEnum.prefixClass}${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { |
| 75 | ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); | 83 | ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); |
| 76 | return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); | 84 | return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); |
| @@ -78,8 +86,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -78,8 +86,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 78 | 86 | ||
| 79 | @GetMapping("/page") | 87 | @GetMapping("/page") |
| 80 | @Operation(summary = "获得${table.classComment}分页") | 88 | @Operation(summary = "获得${table.classComment}分页") |
| 81 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')")#end | ||
| 82 | - | 89 | +#if ($sceneEnum.scene == 1) |
| 90 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | ||
| 91 | +#end | ||
| 83 | public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) { | 92 | public CommonResult<PageResult<${sceneEnum.prefixClass}${table.className}RespVO>> get${simpleClassName}Page(@Valid ${sceneEnum.prefixClass}${table.className}PageReqVO pageVO) { |
| 84 | PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO); | 93 | PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO); |
| 85 | return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); | 94 | return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); |
| @@ -87,8 +96,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -87,8 +96,9 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 87 | 96 | ||
| 88 | @GetMapping("/export-excel") | 97 | @GetMapping("/export-excel") |
| 89 | @Operation(summary = "导出${table.classComment} Excel") | 98 | @Operation(summary = "导出${table.classComment} Excel") |
| 90 | -#if ($sceneEnum.scene == 1) @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")#end | ||
| 91 | - | 99 | +#if ($sceneEnum.scene == 1) |
| 100 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')") | ||
| 101 | +#end | ||
| 92 | @OperateLog(type = EXPORT) | 102 | @OperateLog(type = EXPORT) |
| 93 | public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO, | 103 | public void export${simpleClassName}Excel(@Valid ${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO, |
| 94 | HttpServletResponse response) throws IOException { | 104 | HttpServletResponse response) throws IOException { |
| @@ -98,4 +108,89 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | @@ -98,4 +108,89 @@ public class ${sceneEnum.prefixClass}${table.className}Controller { | ||
| 98 | ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); | 108 | ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas); |
| 99 | } | 109 | } |
| 100 | 110 | ||
| 111 | +## 特殊:主子表专属逻辑 | ||
| 112 | +#foreach ($subTable in $subTables) | ||
| 113 | +#set ($index = $foreach.count - 1) | ||
| 114 | +#set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 115 | +#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 | ||
| 116 | +#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | ||
| 117 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | ||
| 118 | +#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index)) | ||
| 119 | +#set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | ||
| 120 | +#set ($subClassNameVar = $subClassNameVars.get($index)) | ||
| 121 | + // ==================== 子表($subTable.classComment) ==================== | ||
| 122 | + | ||
| 123 | +## 情况一:MASTER_ERP 时,需要分查询页子表 | ||
| 124 | +#if ( $table.templateType == 11 ) | ||
| 125 | + @GetMapping("/${subSimpleClassName_strikeCase}/page") | ||
| 126 | + @Operation(summary = "获得${subTable.classComment}分页") | ||
| 127 | + @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}") | ||
| 128 | +#if ($sceneEnum.scene == 1) | ||
| 129 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | ||
| 130 | +#end | ||
| 131 | + public CommonResult<PageResult<${subTable.className}DO>> get${subSimpleClassName}Page(PageParam pageReqVO, | ||
| 132 | + @RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 133 | + return success(${classNameVar}Service.get${subSimpleClassName}Page(pageReqVO, ${subJoinColumn.javaField})); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | +## 情况二:非 MASTER_ERP 时,需要列表查询子表 | ||
| 137 | +#else | ||
| 138 | + #if ( $subTable.subJoinMany ) | ||
| 139 | + @GetMapping("/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}") | ||
| 140 | + @Operation(summary = "获得${subTable.classComment}列表") | ||
| 141 | + @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}") | ||
| 142 | +#if ($sceneEnum.scene == 1) | ||
| 143 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | ||
| 144 | +#end | ||
| 145 | + public CommonResult<List<${subTable.className}DO>> get${subSimpleClassName}ListBy${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 146 | + return success(${classNameVar}Service.get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField})); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + #else | ||
| 150 | + @GetMapping("/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}") | ||
| 151 | + @Operation(summary = "获得${subTable.classComment}") | ||
| 152 | + @Parameter(name = "${subJoinColumn.javaField}", description = "${subJoinColumn.columnComment}") | ||
| 153 | +#if ($sceneEnum.scene == 1) | ||
| 154 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:query')") | ||
| 155 | +#end | ||
| 156 | + public CommonResult<${subTable.className}DO> get${subSimpleClassName}By${SubJoinColumnName}(@RequestParam("${subJoinColumn.javaField}") ${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 157 | + return success(${classNameVar}Service.get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField})); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + #end | ||
| 161 | +#end | ||
| 162 | +## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 | ||
| 163 | +#if ( $table.templateType == 11 ) | ||
| 164 | + @PostMapping("/${subSimpleClassName_strikeCase}/create") | ||
| 165 | + @Operation(summary = "创建${subTable.classComment}") | ||
| 166 | +#if ($sceneEnum.scene == 1) | ||
| 167 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:create')") | ||
| 168 | +#end | ||
| 169 | + public CommonResult<${subPrimaryColumn.javaType}> create${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) { | ||
| 170 | + return success(${classNameVar}Service.create${subSimpleClassName}(${subClassNameVar})); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + @PutMapping("/${subSimpleClassName_strikeCase}/update") | ||
| 174 | + @Operation(summary = "更新${subTable.classComment}") | ||
| 175 | +#if ($sceneEnum.scene == 1) | ||
| 176 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:update')") | ||
| 177 | +#end | ||
| 178 | + public CommonResult<Booealn> update${subSimpleClassName}(@Valid @RequestBody ${subTable.className}DO ${subClassNameVar}) { | ||
| 179 | + ${classNameVar}Service.update${subSimpleClassName}(${subClassNameVar}); | ||
| 180 | + return success(true); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + @DeleteMapping("/${subSimpleClassName_strikeCase}/delete") | ||
| 184 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 185 | + @Operation(summary = "删除${subTable.classComment}") | ||
| 186 | +#if ($sceneEnum.scene == 1) | ||
| 187 | + @PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')") | ||
| 188 | +#end | ||
| 189 | + public CommonResult<Booealn> delete${subSimpleClassName}(@RequestParam("id") ${subPrimaryColumn.javaType} id) { | ||
| 190 | + ${classNameVar}Service.delete${subSimpleClassName}(${subClassNameVar}); | ||
| 191 | + return success(true); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | +#end | ||
| 195 | +#end | ||
| 101 | } | 196 | } |
| 102 | \ No newline at end of file | 197 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/dal/mapper_sub.vm
| @@ -6,6 +6,9 @@ package ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.busine | @@ -6,6 +6,9 @@ package ${basePackage}.module.${subTable.moduleName}.dal.mysql.${subTable.busine | ||
| 6 | 6 | ||
| 7 | import java.util.*; | 7 | import java.util.*; |
| 8 | 8 | ||
| 9 | +import ${PageResultClassName}; | ||
| 10 | +import ${PageParamClassName}; | ||
| 11 | +import ${QueryWrapperClassName}; | ||
| 9 | import ${BaseMapperClassName}; | 12 | import ${BaseMapperClassName}; |
| 10 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; | 13 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; |
| 11 | import org.apache.ibatis.annotations.Mapper; | 14 | import org.apache.ibatis.annotations.Mapper; |
| @@ -18,21 +21,29 @@ import org.apache.ibatis.annotations.Mapper; | @@ -18,21 +21,29 @@ import org.apache.ibatis.annotations.Mapper; | ||
| 18 | @Mapper | 21 | @Mapper |
| 19 | public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.className}DO> { | 22 | public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.className}DO> { |
| 20 | 23 | ||
| 21 | -#if ( $subTable.subJoinMany) | 24 | +## 情况一:MASTER_ERP 时,需要分查询页子表 |
| 25 | +#if ( $table.templateType == 11 ) | ||
| 26 | + default PageResult<${subTable.className}DO> selectPage(PageParam reqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 27 | + return selectPage(reqVO, new LambdaQueryWrapperX<${subTable.className}DO>() | ||
| 28 | + .eq(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}) | ||
| 29 | + .orderByDesc(${subTable.className}DO::getId));## 大多数情况下,id 倒序 | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +## 情况二:非 MASTER_ERP 时,需要列表查询子表 | ||
| 34 | +#else | ||
| 35 | + #if ( $subTable.subJoinMany) | ||
| 22 | default List<${subTable.className}DO> selectListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | 36 | default List<${subTable.className}DO> selectListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { |
| 23 | return selectList(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); | 37 | return selectList(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); |
| 24 | } | 38 | } |
| 25 | 39 | ||
| 26 | -#else | 40 | + #else |
| 27 | default ${subTable.className}DO selectBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | 41 | default ${subTable.className}DO selectBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { |
| 28 | return selectOne(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); | 42 | return selectOne(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); |
| 29 | } | 43 | } |
| 30 | 44 | ||
| 31 | -#end | ||
| 32 | - default List<${subTable.className}DO> selectListBy${SubJoinColumnName}(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { | ||
| 33 | - return selectList(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); | ||
| 34 | - } | ||
| 35 | - | 45 | + #end |
| 46 | + #end | ||
| 36 | default int deleteBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | 47 | default int deleteBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { |
| 37 | return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); | 48 | return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); |
| 38 | } | 49 | } |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/service.vm
| @@ -4,6 +4,10 @@ import java.util.*; | @@ -4,6 +4,10 @@ import java.util.*; | ||
| 4 | import javax.validation.*; | 4 | import javax.validation.*; |
| 5 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; | 5 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
| 6 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; | 6 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
| 7 | +## 特殊:主子表专属逻辑 | ||
| 8 | +#foreach ($subTable in $subTables) | ||
| 9 | +import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; | ||
| 10 | +#end | ||
| 7 | import ${PageResultClassName}; | 11 | import ${PageResultClassName}; |
| 8 | 12 | ||
| 9 | /** | 13 | /** |
| @@ -63,8 +67,26 @@ public interface ${table.className}Service { | @@ -63,8 +67,26 @@ public interface ${table.className}Service { | ||
| 63 | #foreach ($subTable in $subTables) | 67 | #foreach ($subTable in $subTables) |
| 64 | #set ($index = $foreach.count - 1) | 68 | #set ($index = $foreach.count - 1) |
| 65 | #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | 69 | #set ($subSimpleClassName = $subSimpleClassNames.get($index)) |
| 70 | +#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 | ||
| 66 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 71 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 67 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 72 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 73 | +#set ($subClassNameVar = $subClassNameVars.get($index)) | ||
| 74 | + | ||
| 75 | + // ==================== 子表($subTable.classComment) ==================== | ||
| 76 | + | ||
| 77 | +## 情况一:MASTER_ERP 时,需要分查询页子表 | ||
| 78 | +#if ( $table.templateType == 11 ) | ||
| 79 | + /** | ||
| 80 | + * 获得${subTable.classComment}分页 | ||
| 81 | + * | ||
| 82 | + * @param pageReqVO 分页查询 | ||
| 83 | + * @param ${subJoinColumn.javaField} ${subJoinColumn.columnComment} | ||
| 84 | + * @return ${subTable.classComment}分页 | ||
| 85 | + */ | ||
| 86 | + PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) | ||
| 87 | + | ||
| 88 | +## 情况二:非 MASTER_ERP 时,需要列表查询子表 | ||
| 89 | +#else | ||
| 68 | #if ( $subTable.subJoinMany ) | 90 | #if ( $subTable.subJoinMany ) |
| 69 | /** | 91 | /** |
| 70 | * 获得${subTable.classComment}列表 | 92 | * 获得${subTable.classComment}列表 |
| @@ -85,4 +107,30 @@ public interface ${table.className}Service { | @@ -85,4 +107,30 @@ public interface ${table.className}Service { | ||
| 85 | 107 | ||
| 86 | #end | 108 | #end |
| 87 | #end | 109 | #end |
| 110 | +## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 | ||
| 111 | +#if ( $table.templateType == 11 ) | ||
| 112 | + /** | ||
| 113 | + * 创建${subTable.classComment} | ||
| 114 | + * | ||
| 115 | + * @param ${subClassNameVar} 创建信息 | ||
| 116 | + * @return 编号 | ||
| 117 | + */ | ||
| 118 | + ${subPrimaryColumn.javaType} create${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar}); | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 更新${subTable.classComment} | ||
| 122 | + * | ||
| 123 | + * @param ${subClassNameVar} 更新信息 | ||
| 124 | + */ | ||
| 125 | + void update${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar}); | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 删除${subTable.classComment} | ||
| 129 | + * | ||
| 130 | + * @param id 编号 | ||
| 131 | + */ | ||
| 132 | + void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); | ||
| 133 | + | ||
| 134 | +#end | ||
| 135 | +#end | ||
| 88 | } | 136 | } |
| 89 | \ No newline at end of file | 137 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/java/service/serviceImpl.vm
| @@ -9,7 +9,7 @@ import java.util.*; | @@ -9,7 +9,7 @@ import java.util.*; | ||
| 9 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; | 9 | import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
| 10 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; | 10 | import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
| 11 | ## 特殊:主子表专属逻辑 | 11 | ## 特殊:主子表专属逻辑 |
| 12 | -#if( $subTable ) | 12 | +#foreach ($subTable in $subTables) |
| 13 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; | 13 | import ${basePackage}.module.${subTable.moduleName}.dal.dataobject.${subTable.businessName}.${subTable.className}DO; |
| 14 | #end | 14 | #end |
| 15 | import ${PageResultClassName}; | 15 | import ${PageResultClassName}; |
| @@ -56,19 +56,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -56,19 +56,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 56 | ${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO); | 56 | ${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO); |
| 57 | ${classNameVar}Mapper.insert(${classNameVar}); | 57 | ${classNameVar}Mapper.insert(${classNameVar}); |
| 58 | ## 特殊:主子表专属逻辑 | 58 | ## 特殊:主子表专属逻辑 |
| 59 | +#if ( $subTables.size() > 0) | ||
| 60 | + | ||
| 61 | + // 插入子表($subTable.classComment) | ||
| 59 | #foreach ($subTable in $subTables) | 62 | #foreach ($subTable in $subTables) |
| 60 | #set ($index = $foreach.count - 1) | 63 | #set ($index = $foreach.count - 1) |
| 64 | +#set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 61 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 65 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 62 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 66 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 63 | - // 插入子表($subTable.classComment) | ||
| 64 | #if ( $subTable.subJoinMany) | 67 | #if ( $subTable.subJoinMany) |
| 65 | - createReqVO.get${subSimpleClassNames.get($index)}s().forEach(o -> o.set$SubJoinColumnName(${classNameVar}.getId())); | ||
| 66 | - ${subClassNameVars.get($index)}Mapper.insertBatch(createReqVO.get${subSimpleClassNames.get($index)}s()); | 68 | + create${subSimpleClassName}List(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}s()); |
| 67 | #else | 69 | #else |
| 68 | - createReqVO.get${subSimpleClassNames.get($index)}().set$SubJoinColumnName(${classNameVar}.getId()); | ||
| 69 | - ${subClassNameVars.get($index)}Mapper.insert(createReqVO.get${subSimpleClassNames.get($index)}()); | 70 | + create${subSimpleClassName}(${classNameVar}.getId(), createReqVO.get${subSimpleClassNames.get($index)}()); |
| 70 | #end | 71 | #end |
| 71 | #end | 72 | #end |
| 73 | +#end | ||
| 72 | // 返回 | 74 | // 返回 |
| 73 | return ${classNameVar}.getId(); | 75 | return ${classNameVar}.getId(); |
| 74 | } | 76 | } |
| @@ -85,20 +87,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -85,20 +87,21 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 85 | ${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO); | 87 | ${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO); |
| 86 | ${classNameVar}Mapper.updateById(updateObj); | 88 | ${classNameVar}Mapper.updateById(updateObj); |
| 87 | ## 特殊:主子表专属逻辑 | 89 | ## 特殊:主子表专属逻辑 |
| 90 | +#if ( $subTables.size() > 0) | ||
| 91 | + | ||
| 92 | + // 更新子表 | ||
| 88 | #foreach ($subTable in $subTables) | 93 | #foreach ($subTable in $subTables) |
| 89 | #set ($index = $foreach.count - 1) | 94 | #set ($index = $foreach.count - 1) |
| 95 | +#set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 90 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 96 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 91 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 97 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 92 | - // 更新子表($subTable.classComment) | ||
| 93 | #if ( $subTable.subJoinMany) | 98 | #if ( $subTable.subJoinMany) |
| 94 | - ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(updateReqVO.getId()); | ||
| 95 | - updateReqVO.get${subSimpleClassNames.get($index)}s().forEach(o -> o.set$SubJoinColumnName(updateReqVO.getId())); | ||
| 96 | - ${subClassNameVars.get($index)}Mapper.insertBatch(updateReqVO.get${subSimpleClassNames.get($index)}s()); | 99 | + update${subSimpleClassName}List(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}s()); |
| 97 | #else | 100 | #else |
| 98 | - updateReqVO.get${subSimpleClassNames.get($index)}().set$SubJoinColumnName(updateReqVO.getId()); | ||
| 99 | - ${subClassNameVars.get($index)}Mapper.updateById(updateReqVO.get${subSimpleClassNames.get($index)}()); | 101 | + update${subSimpleClassName}(updateReqVO.getId(), updateReqVO.get${subSimpleClassNames.get($index)}()); |
| 100 | #end | 102 | #end |
| 101 | #end | 103 | #end |
| 104 | +#end | ||
| 102 | } | 105 | } |
| 103 | 106 | ||
| 104 | @Override | 107 | @Override |
| @@ -112,12 +115,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -112,12 +115,16 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 112 | // 删除 | 115 | // 删除 |
| 113 | ${classNameVar}Mapper.deleteById(id); | 116 | ${classNameVar}Mapper.deleteById(id); |
| 114 | ## 特殊:主子表专属逻辑 | 117 | ## 特殊:主子表专属逻辑 |
| 118 | +#if ( $subTables.size() > 0) | ||
| 119 | + | ||
| 120 | + // 删除子表 | ||
| 115 | #foreach ($subTable in $subTables) | 121 | #foreach ($subTable in $subTables) |
| 116 | #set ($index = $foreach.count - 1) | 122 | #set ($index = $foreach.count - 1) |
| 123 | +#set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 117 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | 124 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 118 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 125 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 119 | - // 删除子表($subTable.classComment) | ||
| 120 | - ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(id); | 126 | + delete${subSimpleClassName}By${SubJoinColumnName}(id); |
| 127 | +#end | ||
| 121 | #end | 128 | #end |
| 122 | } | 129 | } |
| 123 | 130 | ||
| @@ -142,4 +149,86 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | @@ -142,4 +149,86 @@ public class ${table.className}ServiceImpl implements ${table.className}Service | ||
| 142 | return ${classNameVar}Mapper.selectList(exportReqVO); | 149 | return ${classNameVar}Mapper.selectList(exportReqVO); |
| 143 | } | 150 | } |
| 144 | 151 | ||
| 152 | +## 特殊:主子表专属逻辑 | ||
| 153 | +#foreach ($subTable in $subTables) | ||
| 154 | +#set ($index = $foreach.count - 1) | ||
| 155 | +#set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 156 | +#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 | ||
| 157 | +#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | ||
| 158 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | ||
| 159 | +#set ($subClassNameVar = $subClassNameVars.get($index)) | ||
| 160 | + // ==================== 子表($subTable.classComment) ==================== | ||
| 161 | + | ||
| 162 | +## 情况一:MASTER_ERP 时,需要分查询页子表 | ||
| 163 | +#if ( $table.templateType == 11 ) | ||
| 164 | + @Override | ||
| 165 | + public PageResult<${subTable.className}DO> get${subSimpleClassName}Page(PageParam pageReqVO, ${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 166 | + return ${subClassNameVars.get($index)}Mapper.selectPage(pageReqVO, ${subJoinColumn.javaField}); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | +## 情况二:非 MASTER_ERP 时,需要列表查询子表 | ||
| 170 | +#else | ||
| 171 | + #if ( $subTable.subJoinMany ) | ||
| 172 | + @Override | ||
| 173 | + public List<${subTable.className}DO> get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 174 | + return ${subClassNameVars.get($index)}Mapper.selectListBy${SubJoinColumnName}(${subJoinColumn.javaField}); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + #else | ||
| 178 | + @Override | ||
| 179 | + public ${subTable.className}DO get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 180 | + return ${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subJoinColumn.javaField}); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + #end | ||
| 184 | +#end | ||
| 185 | +## 情况一:MASTER_ERP 时,支持单个的新增、修改、删除操作 | ||
| 186 | +#if ( $table.templateType == 11 ) | ||
| 187 | + @Override | ||
| 188 | + public ${subPrimaryColumn.javaType} create${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar}) { | ||
| 189 | + ${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar}); | ||
| 190 | + return ${subClassNameVar}.getId(); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + @Override | ||
| 194 | + public void update${subSimpleClassName}(@Valid ${subTable.className}DO ${subClassNameVar}) { | ||
| 195 | + ${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar}); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + @Override | ||
| 199 | + public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) { | ||
| 200 | + ${subClassNameVars.get($index)}Mapper.deleteById(id); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | +## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作 | ||
| 204 | +#else | ||
| 205 | + #if ( $subTable.subJoinMany) | ||
| 206 | + private void create${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) { | ||
| 207 | + list.forEach(o -> o.set$SubJoinColumnName(${subJoinColumn.javaField})); | ||
| 208 | + ${subClassNameVars.get($index)}Mapper.insertBatch(list); | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + private void update${subSimpleClassName}List(${primaryColumn.javaType} ${subJoinColumn.javaField}, List<${subTable.className}DO> list) { | ||
| 212 | + delete${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}); | ||
| 213 | + create${subSimpleClassName}List(${subJoinColumn.javaField}, list); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + #else | ||
| 217 | + private void create${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) { | ||
| 218 | + ${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField}); | ||
| 219 | + ${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar}); | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + private void update${subSimpleClassName}(${primaryColumn.javaType} ${subJoinColumn.javaField}, ${subTable.className}DO ${subClassNameVar}) { | ||
| 223 | + ${subClassNameVar}.set$SubJoinColumnName(${subJoinColumn.javaField}); | ||
| 224 | + ${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar}); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + #end | ||
| 228 | + private void delete${subSimpleClassName}By${SubJoinColumnName}(${primaryColumn.javaType} ${subJoinColumn.javaField}) { | ||
| 229 | + ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField}); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | +#end | ||
| 233 | +#end | ||
| 145 | } | 234 | } |
| 146 | \ No newline at end of file | 235 | \ No newline at end of file |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java
| @@ -173,7 +173,8 @@ public class CodegenEngineTest extends BaseMockitoUnitTest { | @@ -173,7 +173,8 @@ public class CodegenEngineTest extends BaseMockitoUnitTest { | ||
| 173 | .setTableName("infra_demo_student").setTableComment("学生表") | 173 | .setTableName("infra_demo_student").setTableComment("学生表") |
| 174 | .setModuleName("infra").setBusinessName("demo02").setClassName("InfraDemoStudent") | 174 | .setModuleName("infra").setBusinessName("demo02").setClassName("InfraDemoStudent") |
| 175 | .setClassComment("学生").setAuthor("芋道源码") | 175 | .setClassComment("学生").setAuthor("芋道源码") |
| 176 | - .setTemplateType(CodegenTemplateTypeEnum.MASTER.getType()) | 176 | + .setTemplateType(CodegenTemplateTypeEnum.MASTER_NORMAL.getType()) |
| 177 | +// .setTemplateType(CodegenTemplateTypeEnum.MASTER_ERP.getType()) | ||
| 177 | .setFrontType(CodegenFrontTypeEnum.VUE3.getType()); | 178 | .setFrontType(CodegenFrontTypeEnum.VUE3.getType()); |
| 178 | CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name()) | 179 | CodegenColumnDO idColumn = new CodegenColumnDO().setColumnName("id").setDataType(JdbcType.BIGINT.name()) |
| 179 | .setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true) | 180 | .setColumnComment("编号").setNullable(false).setPrimaryKey(true).setAutoIncrement(true) |