mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-14 02:01:53 +08:00
codegen:1)增加 vue3 + crud 模式下的单测;2)增加主子表的 db 字段
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.column.CodegenColumnBaseVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -43,6 +44,12 @@ public class CodegenUpdateReqVO {
|
||||
|| getParentMenuId() != null;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "关联的子表与字段不能为空")
|
||||
public boolean isSubValid() {
|
||||
return ObjectUtil.notEqual(getTemplateType(), CodegenTemplateTypeEnum.MASTER_SUB)
|
||||
|| (getSubTableId() != null && getSubColumnId() != null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "更新表定义")
|
||||
|
@@ -58,4 +58,9 @@ public class CodegenTableBaseVO {
|
||||
@Schema(description = "父菜单编号", example = "1024")
|
||||
private Long parentMenuId;
|
||||
|
||||
@Schema(description = "子表的表编号", example = "2048")
|
||||
private Long subTableId;
|
||||
@Schema(description = "子表的关联字段编号", example = "4096")
|
||||
private Long subColumnId;
|
||||
|
||||
}
|
||||
|
@@ -116,4 +116,19 @@ public class CodegenTableDO extends BaseDO {
|
||||
*/
|
||||
private Long parentMenuId;
|
||||
|
||||
// ========== 主子表相关字段 ==========
|
||||
|
||||
/**
|
||||
* 子表的表编号
|
||||
*
|
||||
* 关联 {@link CodegenTableDO#getId()}
|
||||
*/
|
||||
private Long subTableId;
|
||||
/**
|
||||
* 子表的关联字段编号
|
||||
*
|
||||
* 关联 {@link CodegenColumnDO#getId()}
|
||||
*/
|
||||
private Long subColumnId;
|
||||
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ public enum CodegenTemplateTypeEnum {
|
||||
|
||||
CRUD(1), // 单表(增删改查)
|
||||
TREE(2), // 树表(增删改查)
|
||||
MASTER_SUB(3), // 主子表
|
||||
;
|
||||
|
||||
/**
|
||||
|
@@ -235,8 +235,16 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
throw exception(CODEGEN_COLUMN_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验子表是否已经存在
|
||||
CodegenTableDO subTable = null;
|
||||
List<CodegenColumnDO> subColumns = null;
|
||||
if (table.getSubTableId() != null) {
|
||||
subTable = codegenTableMapper.selectById(table.getSubTableId());
|
||||
subColumns = codegenColumnMapper.selectListByTableId(table.getSubTableId());
|
||||
}
|
||||
|
||||
// 执行生成
|
||||
return codegenEngine.execute(table, columns);
|
||||
return codegenEngine.execute(table, columns, subTable, subColumns);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -26,6 +26,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
|
||||
import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Table;
|
||||
@@ -37,6 +38,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static cn.hutool.core.map.MapUtil.getStr;
|
||||
import static cn.hutool.core.text.CharSequenceUtil.*;
|
||||
@@ -149,7 +151,8 @@ public class CodegenEngine {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void initGlobalBindingMap() {
|
||||
@VisibleForTesting
|
||||
void initGlobalBindingMap() {
|
||||
// 全局配置
|
||||
globalBindingMap.put("basePackage", codegenProperties.getBasePackage());
|
||||
globalBindingMap.put("baseFrameworkPackage", codegenProperties.getBasePackage()
|
||||
@@ -176,13 +179,28 @@ public class CodegenEngine {
|
||||
globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName());
|
||||
}
|
||||
|
||||
public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns) {
|
||||
/**
|
||||
* 生成代码
|
||||
*
|
||||
* @param table 表定义
|
||||
* @param columns table 的字段定义数组
|
||||
* @param subTable 子表定义,当且仅当主子表时使用
|
||||
* @param subColumns subTable 的字段定义数组
|
||||
* @return 生成的代码,key 是路径,value 是对应代码
|
||||
*/
|
||||
public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns,
|
||||
CodegenTableDO subTable, List<CodegenColumnDO> subColumns) {
|
||||
// 创建 bindingMap
|
||||
Map<String, Object> bindingMap = new HashMap<>(globalBindingMap);
|
||||
bindingMap.put("table", table);
|
||||
bindingMap.put("columns", columns);
|
||||
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段
|
||||
bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene()));
|
||||
if (subTable != null) {
|
||||
bindingMap.put("subTable", subTable);
|
||||
bindingMap.put("subColumns", subColumns);
|
||||
bindingMap.put("subColumn", CollectionUtils.findFirst(subColumns, column -> column.getId().equals(table.getSubColumnId())));
|
||||
}
|
||||
|
||||
// className 相关
|
||||
// 去掉指定前缀,将 TestDictType 转换成 DictType. 因为在 create 等方法后,不需要带上 Test 前缀
|
||||
|
@@ -108,4 +108,4 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
||||
ExcelUtils.write(response, "${table.classComment}.xls", "数据", ${sceneEnum.prefixClass}${table.className}ExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
## 提供给 baseVO、createVO、updateVO 生成字段
|
||||
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
|
||||
#if (!${column.nullable})## 判断 @NotEmpty 和 @NotNull 注解
|
||||
#if (${field.fieldType} == 'String')
|
||||
#if (${column.javaType} == 'String')
|
||||
@NotEmpty(message = "${column.columnComment}不能为空")
|
||||
#else
|
||||
@NotNull(message = "${column.columnComment}不能为空")
|
||||
|
@@ -27,4 +27,4 @@ public class ${sceneEnum.prefixClass}${table.className}CreateReqVO extends ${sce
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -42,4 +42,4 @@ public class ${sceneEnum.prefixClass}${table.className}ExcelVO {
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -36,4 +36,4 @@ public class ${sceneEnum.prefixClass}${table.className}ExportReqVO {
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -38,4 +38,4 @@ public class ${sceneEnum.prefixClass}${table.className}PageReqVO extends PagePar
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -22,4 +22,4 @@ public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnu
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -27,4 +27,4 @@ public class ${sceneEnum.prefixClass}${table.className}UpdateReqVO extends ${sce
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
@@ -31,4 +31,4 @@ public interface ${table.className}Convert {
|
||||
|
||||
List<${sceneEnum.prefixClass}${table.className}ExcelVO> convertList02(List<${table.className}DO> list);
|
||||
|
||||
}
|
||||
}
|
@@ -44,4 +44,4 @@ public class ${table.className}DO extends BaseDO {
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
}
|
@@ -63,4 +63,4 @@ public interface ${table.className}Mapper extends BaseMapperX<${table.className}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -9,4 +9,4 @@
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
@@ -1,3 +1,3 @@
|
||||
// TODO 待办:请将下面的错误码复制到 yudao-module-${table.moduleName}-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!!
|
||||
// ========== ${table.classComment} TODO 补充编号 ==========
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在");
|
@@ -67,4 +67,4 @@ public interface ${table.className}Service {
|
||||
*/
|
||||
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
}
|
@@ -85,4 +85,4 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
return ${classNameVar}Mapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -162,4 +162,4 @@ public class ${table.className}ServiceImplTest extends BaseDbUnitTest {
|
||||
assertPojoEquals(db${simpleClassName}, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -32,4 +32,4 @@ CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" (
|
||||
) COMMENT '${table.tableComment}';
|
||||
|
||||
-- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-biz 模块的 test/resources/sql/clean.sql 文件里
|
||||
DELETE FROM "${table.tableName}";
|
||||
DELETE FROM "${table.tableName}";
|
@@ -25,4 +25,4 @@ VALUES (
|
||||
'${table.classComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
#end
|
||||
#end
|
@@ -43,4 +43,4 @@ export const delete${simpleClassName} = async (id: number) => {
|
||||
// 导出${table.classComment} Excel
|
||||
export const export${simpleClassName} = async (params) => {
|
||||
return await request.download({ url: `${baseURL}/export-excel`, params })
|
||||
}
|
||||
}
|
@@ -231,4 +231,4 @@ const resetForm = () => {
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
</script>
|
@@ -286,4 +286,4 @@ const handleExport = async () => {
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
</script>
|
Reference in New Issue
Block a user