Commit 6f8baa3110608891e429e1898b44c753a87de234
1 parent
b6272259
代码生成时,如果是管理后台,必须设置菜单
Showing
4 changed files
with
26 additions
and
31 deletions
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/CodegenUpdateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjectUtil; | |
| 3 | 4 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.column.CodegenColumnBaseVO; |
| 4 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO; |
| 6 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; | |
| 5 | 7 | import io.swagger.annotations.ApiModel; |
| 6 | 8 | import io.swagger.annotations.ApiModelProperty; |
| 7 | 9 | import lombok.Data; |
| ... | ... | @@ -9,6 +11,7 @@ import lombok.EqualsAndHashCode; |
| 9 | 11 | import lombok.ToString; |
| 10 | 12 | |
| 11 | 13 | import javax.validation.Valid; |
| 14 | +import javax.validation.constraints.AssertTrue; | |
| 12 | 15 | import javax.validation.constraints.NotNull; |
| 13 | 16 | import java.util.List; |
| 14 | 17 | |
| ... | ... | @@ -28,11 +31,19 @@ public class CodegenUpdateReqVO { |
| 28 | 31 | @Data |
| 29 | 32 | @EqualsAndHashCode(callSuper = true) |
| 30 | 33 | @ToString(callSuper = true) |
| 34 | + @Valid | |
| 31 | 35 | public static class Table extends CodegenTableBaseVO { |
| 32 | 36 | |
| 33 | 37 | @ApiModelProperty(value = "编号", required = true, example = "1") |
| 34 | 38 | private Long id; |
| 35 | 39 | |
| 40 | + @AssertTrue(message = "生成失败,必须设置上级菜单") | |
| 41 | + public boolean isParentMenuIdValid() { | |
| 42 | + // 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的 | |
| 43 | + return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene()) | |
| 44 | + || getParentMenuId() != null; | |
| 45 | + } | |
| 46 | + | |
| 36 | 47 | } |
| 37 | 48 | |
| 38 | 49 | @ApiModel("更新表定义") | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.service.codegen; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 5 | 6 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.CodegenUpdateReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.infra.convert.codegen.CodegenConvert; |
| ... | ... | @@ -14,21 +15,18 @@ import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper; |
| 14 | 15 | import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaColumnMapper; |
| 15 | 16 | import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaTableMapper; |
| 16 | 17 | import cn.iocoder.yudao.module.infra.enums.codegen.CodegenImportTypeEnum; |
| 18 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; | |
| 17 | 19 | import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; |
| 18 | 20 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; |
| 19 | 21 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; |
| 20 | 22 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser; |
| 21 | 23 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 22 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 23 | 24 | import org.apache.commons.collections4.KeyValue; |
| 24 | 25 | import org.springframework.stereotype.Service; |
| 25 | 26 | import org.springframework.transaction.annotation.Transactional; |
| 26 | 27 | |
| 27 | 28 | import javax.annotation.Resource; |
| 28 | -import java.util.ArrayList; | |
| 29 | -import java.util.List; | |
| 30 | -import java.util.Map; | |
| 31 | -import java.util.Set; | |
| 29 | +import java.util.*; | |
| 32 | 30 | import java.util.stream.Collectors; |
| 33 | 31 | |
| 34 | 32 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -266,27 +264,8 @@ public class CodegenServiceImpl implements CodegenService { |
| 266 | 264 | // TODO 强制移除 Quartz 的表,未来做成可配置 |
| 267 | 265 | tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); |
| 268 | 266 | tables.removeIf(table -> table.getTableName().startsWith("ACT_")); |
| 267 | + tables.removeIf(table -> table.getTableName().startsWith("FLW_")); | |
| 269 | 268 | return tables; |
| 270 | 269 | } |
| 271 | 270 | |
| 272 | -// /** | |
| 273 | -// * 修改保存参数校验 | |
| 274 | -// * | |
| 275 | -// * @param genTable 业务信息 | |
| 276 | -// */ | |
| 277 | -// @Override | |
| 278 | -// public void validateEdit(GenTable genTable) { | |
| 279 | -// if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { | |
| 280 | -// String options = JSON.toJSONString(genTable.getParams()); | |
| 281 | -// JSONObject paramsObj = JSONObject.parseObject(options); | |
| 282 | -// if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { | |
| 283 | -// throw new CustomException("树编码字段不能为空"); | |
| 284 | -// } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { | |
| 285 | -// throw new CustomException("树父编码字段不能为空"); | |
| 286 | -// } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { | |
| 287 | -// throw new CustomException("树名称字段不能为空"); | |
| 288 | -// } | |
| 289 | -// } | |
| 290 | -// } | |
| 291 | - | |
| 292 | 271 | } | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java
| ... | ... | @@ -121,14 +121,13 @@ public class CodegenBuilder { |
| 121 | 121 | private void initTableDefault(CodegenTableDO table) { |
| 122 | 122 | // 以 system_dept 举例子。moduleName 为 system、businessName 为 dept、className 为 SystemDept |
| 123 | 123 | // 如果不希望 System 前缀,则可以手动在【代码生成 - 修改生成配置 - 基本信息】,将实体类名称改为 Dept 即可 |
| 124 | - table.setModuleName(StrUtil.subBefore(table.getTableName(), | |
| 125 | - '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 | |
| 124 | + table.setModuleName(subBefore(table.getTableName(), '_', false)); // 第一个 _ 前缀的前面,作为 module 名字 | |
| 126 | 125 | table.setBusinessName(toCamelCase(subAfter(table.getTableName(), |
| 127 | 126 | '_', false))); // 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰 |
| 128 | - table.setClassName(upperFirst(toCamelCase(table.getTableName()))); // 驼峰 + 首字母大写 | |
| 127 | + table.setClassName(upperFirst(toCamelCase( // 驼峰 + 首字母大写 | |
| 128 | + subAfter(table.getTableName(), '_', false)))); // 第一个 _ 前缀的前面,作为 class 名字 | |
| 129 | 129 | table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表,作为类描述 |
| 130 | 130 | '表', true)); |
| 131 | - table.setAuthor("芋艿"); // TODO 稍后改成创建人 | |
| 132 | 131 | table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType()); |
| 133 | 132 | } |
| 134 | 133 | |
| ... | ... | @@ -157,7 +156,7 @@ public class CodegenBuilder { |
| 157 | 156 | column.setJavaField(toCamelCase(column.getColumnName())); |
| 158 | 157 | // 处理 dictType 字段,暂无 |
| 159 | 158 | // 处理 javaType 字段 |
| 160 | - String dbType = StrUtil.subBefore(column.getColumnType(), '(', false); | |
| 159 | + String dbType = subBefore(column.getColumnType(), '(', false); | |
| 161 | 160 | javaTypeMappings.entrySet().stream() |
| 162 | 161 | .filter(entry -> entry.getValue().contains(dbType)) |
| 163 | 162 | .findFirst().ifPresent(entry -> column.setJavaType(entry.getKey())); | ... | ... |
yudao-ui-admin/src/views/infra/codegen/basicInfoForm.vue
| ... | ... | @@ -13,7 +13,13 @@ |
| 13 | 13 | </el-col> |
| 14 | 14 | |
| 15 | 15 | <el-col :span="12"> |
| 16 | - <el-form-item label="实体类名称" prop="className"> | |
| 16 | + <el-form-item prop="className"> | |
| 17 | + <span slot="label"> | |
| 18 | + 实体类名称 | |
| 19 | + <el-tooltip content="默认去除表名的前缀。如果存在重复,则需要手动添加前缀,避免 MyBatis 报 Alias 重复的问题。" placement="top"> | |
| 20 | + <i class="el-icon-question"></i> | |
| 21 | + </el-tooltip> | |
| 22 | + </span> | |
| 17 | 23 | <el-input placeholder="请输入" v-model="info.className" /> |
| 18 | 24 | </el-form-item> |
| 19 | 25 | </el-col> | ... | ... |