perf:【INFRA 基础设施】代码生成配置 delete-batch-enable: false # 是否生成批量删除接口

This commit is contained in:
puhui999 2025-05-19 23:52:58 +08:00
parent 05bf229a3c
commit 61cfcc283b
14 changed files with 30 additions and 37 deletions

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table; package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -46,9 +45,6 @@ public class CodegenTableRespVO {
@Schema(description = "前端类型,参见 CodegenFrontTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") @Schema(description = "前端类型,参见 CodegenFrontTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer frontType; private Integer frontType;
@Schema(description = "是否生成批量删除接口", example = "true")
private Boolean deleteBatch;
@Schema(description = "父菜单编号", example = "1024") @Schema(description = "父菜单编号", example = "1024")
private Long parentMenuId; private Long parentMenuId;

View File

@ -60,10 +60,6 @@ public class CodegenTableSaveReqVO {
@NotNull(message = "前端类型不能为空") @NotNull(message = "前端类型不能为空")
private Integer frontType; private Integer frontType;
@Schema(description = "是否生成批量删除接口", example = "true")
@NotNull(message = "是否生成批量删除接口不能为空")
private Boolean deleteBatch;
@Schema(description = "父菜单编号", example = "1024") @Schema(description = "父菜单编号", example = "1024")
private Long parentMenuId; private Long parentMenuId;

View File

@ -108,12 +108,6 @@ public class CodegenTableDO extends BaseDO {
* 枚举 {@link CodegenFrontTypeEnum} * 枚举 {@link CodegenFrontTypeEnum}
*/ */
private Integer frontType; private Integer frontType;
/**
* 是否生成批量删除接口
* -true
* -false
*/
private Boolean deleteBatch;
// ========== 菜单相关字段 ========== // ========== 菜单相关字段 ==========

View File

@ -40,4 +40,10 @@ public class CodegenProperties {
@NotNull(message = "是否生成单元测试不能为空") @NotNull(message = "是否生成单元测试不能为空")
private Boolean unitTestEnable; private Boolean unitTestEnable;
/**
* 是否生成批量删除接口
*/
@NotNull(message = "是否生成批量删除接口不能为空")
private Boolean deleteBatchEnable;
} }

View File

@ -380,7 +380,7 @@ public class CodegenEngine {
bindingMap.put("columns", columns); bindingMap.put("columns", columns);
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段 bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段
bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene())); bindingMap.put("sceneEnum", CodegenSceneEnum.valueOf(table.getScene()));
bindingMap.put("deleteBatchEnable", codegenProperties.getDeleteBatchEnable());
// className 相关 // className 相关
// 去掉指定前缀 TestDictType 转换成 DictType. 因为在 create 等方法后不需要带上 Test 前缀 // 去掉指定前缀 TestDictType 转换成 DictType. 因为在 create 等方法后不需要带上 Test 前缀
String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName() String simpleClassName = equalsAnyIgnoreCase(table.getClassName(), table.getModuleName()) ? table.getClassName()

View File

@ -74,7 +74,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
return success(true); return success(true);
} }
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
@DeleteMapping("/delete-batch") @DeleteMapping("/delete-batch")
@Parameter(name = "ids", description = "编号", required = true) @Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除${table.classComment}") @Operation(summary = "批量删除${table.classComment}")
@ -231,7 +231,7 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
return success(true); return success(true);
} }
#if ($table.deleteBatch) #if ($deleteBatchEnable)
@DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch") @DeleteMapping("/${subSimpleClassName_strikeCase}/delete-batch")
@Parameter(name = "ids", description = "编号", required = true) @Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除${subTable.classComment}") @Operation(summary = "批量删除${subTable.classComment}")

View File

@ -54,7 +54,7 @@ public interface ${subTable.className}Mapper extends BaseMapperX<${subTable.clas
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}); return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField});
} }
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) { default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) {
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s); return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s);
} }

View File

@ -40,7 +40,7 @@ public interface ${table.className}Service {
*/ */
void delete${simpleClassName}(${primaryColumn.javaType} id); void delete${simpleClassName}(${primaryColumn.javaType} id);
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
/** /**
* 批量删除${table.classComment} * 批量删除${table.classComment}
* *
@ -143,7 +143,7 @@ public interface ${table.className}Service {
*/ */
void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id); void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id);
#if ($table.deleteBatch) #if ($deleteBatchEnable)
/** /**
* 批量删除${subTable.classComment} * 批量删除${subTable.classComment}
* *

View File

@ -155,7 +155,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
#end #end
} }
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
@Override @Override
## 特殊:主子表专属逻辑 ## 特殊:主子表专属逻辑
#if ( $subTables && $subTables.size() > 0) #if ( $subTables && $subTables.size() > 0)
@ -332,7 +332,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
${subClassNameVars.get($index)}Mapper.deleteById(id); ${subClassNameVars.get($index)}Mapper.deleteById(id);
} }
#if ($table.deleteBatch) #if ($deleteBatchEnable)
@Override @Override
public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) { public void delete${subSimpleClassName}ByIds(List<${subPrimaryColumn.javaType}> ids) {
// 校验存在 // 校验存在
@ -353,7 +353,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
} }
} }
#if ($table.deleteBatch) #if ($deleteBatchEnable)
private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) { private void validate${subSimpleClassName}Exists(List<${subPrimaryColumn.javaType}> ids) {
List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids); List<${subTable.className}DO> list = ${subClassNameVar}Mapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) { if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
@ -400,7 +400,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField}); ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}(${subJoinColumn.javaField});
} }
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) { private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) {
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s); ${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s);
} }

View File

@ -89,7 +89,7 @@ export function delete${simpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/delete?id=${id}`); return requestClient.delete(`${baseURL}/delete?id=${id}`);
} }
#if ( $table.templateType != 2 && $table.deleteBatch) #if ( $table.templateType != 2 && $deleteBatchEnable)
// 批量删除${table.classComment} // 批量删除${table.classComment}
export function delete${simpleClassName}ByIds(ids: number[]) { export function delete${simpleClassName}ByIds(ids: number[]) {
return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`) return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`)
@ -151,7 +151,7 @@ export function delete${subSimpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`);
} }
#if ($table.deleteBatch) #if ($deleteBatchEnable)
// 批量删除${subTable.classComment} // 批量删除${subTable.classComment}
export function delete${subSimpleClassName}ByIds(ids: number[]) { export function delete${subSimpleClassName}ByIds(ids: number[]) {
return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`) return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete-batch?ids=${ids.join(',')}`)

View File

@ -193,7 +193,7 @@ export function useGridColumns(
onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>, onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { ): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
return [ return [
#if ($table.templateType != 2 && $table.deleteBatch) #if ($table.templateType != 2 && $deleteBatchEnable)
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },
#end #end
#if ($table.templateType == 12) ## 内嵌情况 #if ($table.templateType == 12) ## 内嵌情况
@ -431,7 +431,7 @@ export function use${subSimpleClassName}GridColumns(
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
return [ return [
#if ($table.templateType != 2 && $table.deleteBatch) #if ($table.templateType != 2 && $deleteBatchEnable)
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },
#end #end
#foreach($column in $subColumns) #foreach($column in $subColumns)

View File

@ -22,7 +22,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
#if (${table.templateType} == 2)## 树表接口 #if (${table.templateType} == 2)## 树表接口
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#else## 标准表接口 #else## 标准表接口
import { get${simpleClassName}Page, delete${simpleClassName},#if ($table.deleteBatch) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#end #end
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
@ -92,7 +92,7 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
} }
} }
#if ($table.templateType != 2 && $table.deleteBatch) #if ($table.templateType != 2 && $deleteBatchEnable)
const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
function setDeleteIds({ function setDeleteIds({
@ -204,14 +204,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true, search: true,
}, },
} as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>,
#if (${table.templateType} == 11 || $table.deleteBatch) #if (${table.templateType} == 11 || $deleteBatchEnable)
gridEvents:{ gridEvents:{
#if(${table.templateType} == 11) #if(${table.templateType} == 11)
cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => { cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => {
select${simpleClassName}.value = row; select${simpleClassName}.value = row;
}, },
#end #end
#if($table.deleteBatch) #if($deleteBatchEnable)
checkboxAll: setDeleteIds, checkboxAll: setDeleteIds,
checkboxChange: setDeleteIds, checkboxChange: setDeleteIds,
#end #end
@ -262,7 +262,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
> >
{{ $t('ui.actionTitle.export') }} {{ $t('ui.actionTitle.export') }}
</Button> </Button>
#if ($table.templateType != 2 && $table.deleteBatch) #if ($table.templateType != 2 && $deleteBatchEnable)
<Button <Button
:icon="h(Trash2)" :icon="h(Trash2)"
type="primary" type="primary"

View File

@ -21,7 +21,7 @@
#if ($table.templateType == 11) ## erp #if ($table.templateType == 11) ## erp
import { delete${subSimpleClassName},#if ($table.deleteBatch) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}';
import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data';
import { isEmpty } from '@vben/utils'; import { isEmpty } from '@vben/utils';
#else #else
@ -73,7 +73,7 @@ async function onDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
} }
} }
#if ($table.deleteBatch) #if ($deleteBatchEnable)
const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID const deleteIds = ref<number[]>([]) // 待删除${subTable.classComment} ID
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value)); const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
function setDeleteIds({ function setDeleteIds({
@ -164,7 +164,7 @@ function onActionClick({
isHover: true, isHover: true,
}, },
} as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>,
#if (${table.templateType} == 11 && $table.deleteBatch) #if (${table.templateType} == 11 && $deleteBatchEnable)
gridEvents:{ gridEvents:{
checkboxAll: setDeleteIds, checkboxAll: setDeleteIds,
checkboxChange: setDeleteIds, checkboxChange: setDeleteIds,
@ -207,7 +207,7 @@ const onRefresh = async ()=> {
<Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']">
{{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }}
</Button> </Button>
#if ($table.templateType == 11 && $table.deleteBatch) #if ($table.templateType == 11 && $deleteBatchEnable)
<Button <Button
:icon="h(Trash2)" :icon="h(Trash2)"
type="primary" type="primary"

View File

@ -270,6 +270,7 @@ yudao:
db-schemas: ${spring.datasource.dynamic.datasource.master.name} db-schemas: ${spring.datasource.dynamic.datasource.master.name}
front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
unit-test-enable: false # 是否生成单元测试 unit-test-enable: false # 是否生成单元测试
delete-batch-enable: false # 是否生成批量删除接口
tenant: # 多租户相关配置项 tenant: # 多租户相关配置项
enable: true enable: true
ignore-urls: ignore-urls: