feat:【INFRA 基础设施】代码生成时,可生成批量删除接口
This commit is contained in:
parent
7a3634d8c0
commit
9295d61030
|
@ -1,6 +1,7 @@
|
||||||
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;
|
||||||
|
@ -45,6 +46,9 @@ 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;
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,10 @@ 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;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -60,6 +61,15 @@ public class Demo01ContactController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete-batch")
|
||||||
|
@Parameter(name = "ids", description = "编号", required = true)
|
||||||
|
@Operation(summary = "批量删除示例联系人")
|
||||||
|
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')")
|
||||||
|
public CommonResult<Boolean> deleteDemo01Contact(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List<Long> ids) {
|
||||||
|
demo01ContactService.deleteDemo01ContactByIds(ids);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获得示例联系人")
|
@Operation(summary = "获得示例联系人")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
import java.util.*;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.*;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import com.alibaba.excel.annotation.*;
|
|
||||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 示例联系人 Response VO")
|
@Schema(description = "管理后台 - 示例联系人 Response VO")
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO")
|
@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO")
|
||||||
|
|
|
@ -108,6 +108,12 @@ public class CodegenTableDO extends BaseDO {
|
||||||
* 枚举 {@link CodegenFrontTypeEnum}
|
* 枚举 {@link CodegenFrontTypeEnum}
|
||||||
*/
|
*/
|
||||||
private Integer frontType;
|
private Integer frontType;
|
||||||
|
/**
|
||||||
|
* 是否生成批量删除接口
|
||||||
|
* -true 是
|
||||||
|
* -false 否
|
||||||
|
*/
|
||||||
|
private Boolean deleteBatch;
|
||||||
|
|
||||||
// ========== 菜单相关字段 ==========
|
// ========== 菜单相关字段 ==========
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01;
|
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.*;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package cn.iocoder.yudao.module.infra.service.demo.demo01;
|
package cn.iocoder.yudao.module.infra.service.demo.demo01;
|
||||||
|
|
||||||
import jakarta.validation.*;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
|
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 示例联系人 Service 接口
|
* 示例联系人 Service 接口
|
||||||
|
@ -36,6 +36,13 @@ public interface Demo01ContactService {
|
||||||
*/
|
*/
|
||||||
void deleteDemo01Contact(Long id);
|
void deleteDemo01Contact(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除示例联系人
|
||||||
|
*
|
||||||
|
* @param ids 编号
|
||||||
|
*/
|
||||||
|
void deleteDemo01ContactByIds(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得示例联系人
|
* 获得示例联系人
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
package cn.iocoder.yudao.module.infra.service.demo.demo01;
|
package cn.iocoder.yudao.module.infra.service.demo.demo01;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper;
|
import cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 示例联系人 Service 实现类
|
* 示例联系人 Service 实现类
|
||||||
|
@ -53,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService {
|
||||||
demo01ContactMapper.deleteById(id);
|
demo01ContactMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDemo01ContactByIds(List<Long> ids) {
|
||||||
|
// 校验存在
|
||||||
|
validateDemo01ContactExists(ids);
|
||||||
|
// 删除
|
||||||
|
demo01ContactMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateDemo01ContactExists(List<Long> ids) {
|
||||||
|
List<Demo01ContactDO> list = demo01ContactMapper.selectByIds(ids);
|
||||||
|
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||||
|
throw exception(DEMO01_CONTACT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void validateDemo01ContactExists(Long id) {
|
private void validateDemo01ContactExists(Long id) {
|
||||||
if (demo01ContactMapper.selectById(id) == null) {
|
if (demo01ContactMapper.selectById(id) == null) {
|
||||||
throw exception(DEMO01_CONTACT_NOT_EXISTS);
|
throw exception(DEMO01_CONTACT_NOT_EXISTS);
|
||||||
|
|
|
@ -74,6 +74,19 @@ public class ${sceneEnum.prefixClass}${table.className}Controller {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 && $table.deleteBatch)
|
||||||
|
@DeleteMapping("/delete-batch")
|
||||||
|
@Parameter(name = "ids", description = "编号", required = true)
|
||||||
|
@Operation(summary = "批量删除${table.classComment}")
|
||||||
|
#if ($sceneEnum.scene == 1)
|
||||||
|
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||||
|
#end
|
||||||
|
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("ids") @Size(max = 100, message = "最多允许100个") List<${primaryColumn.javaType}> ids) {
|
||||||
|
${classNameVar}Service.delete${simpleClassName}ByIds(ids);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获得${table.classComment}")
|
@Operation(summary = "获得${table.classComment}")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
|
|
@ -54,4 +54,10 @@ 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)
|
||||||
|
default int deleteBy${SubJoinColumnName}s(List<${subJoinColumn.javaType}> ${subJoinColumn.javaField}s) {
|
||||||
|
return delete(${subTable.className}DO::get${SubJoinColumnName}, ${subJoinColumn.javaField}s);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,15 @@ public interface ${table.className}Service {
|
||||||
*/
|
*/
|
||||||
void delete${simpleClassName}(${primaryColumn.javaType} id);
|
void delete${simpleClassName}(${primaryColumn.javaType} id);
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 && $table.deleteBatch)
|
||||||
|
/**
|
||||||
|
* 批量删除${table.classComment}
|
||||||
|
*
|
||||||
|
* @param ids 编号
|
||||||
|
*/
|
||||||
|
void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids);
|
||||||
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得${table.classComment}
|
* 获得${table.classComment}
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
package ${basePackage}.module.${table.moduleName}.service.${table.businessName};
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ${jakartaPackage}.annotation.Resource;
|
import ${jakartaPackage}.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -154,6 +155,39 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ( $table.templateType != 2 && $table.deleteBatch)
|
||||||
|
@Override
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
#end
|
||||||
|
public void delete${simpleClassName}ByIds(List<${primaryColumn.javaType}> ids) {
|
||||||
|
// 校验存在
|
||||||
|
validate${simpleClassName}Exists(ids);
|
||||||
|
// 删除
|
||||||
|
${classNameVar}Mapper.deleteByIds(ids);
|
||||||
|
## 特殊:主子表专属逻辑
|
||||||
|
#if ( $subTables && $subTables.size() > 0)
|
||||||
|
|
||||||
|
// 删除子表
|
||||||
|
#foreach ($subTable in $subTables)
|
||||||
|
#set ($index = $foreach.count - 1)
|
||||||
|
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||||
|
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||||
|
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||||
|
delete${subSimpleClassName}By${SubJoinColumnName}s(ids);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) {
|
||||||
|
List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids);
|
||||||
|
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||||
if (${classNameVar}Mapper.selectById(id) == null) {
|
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
@ -347,5 +381,11 @@ 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)
|
||||||
|
private void delete${subSimpleClassName}By${SubJoinColumnName}s(List<${primaryColumn.javaType}> ${subJoinColumn.javaField}s) {
|
||||||
|
${subClassNameVars.get($index)}Mapper.deleteBy${SubJoinColumnName}s(${subJoinColumn.javaField}s);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
Loading…
Reference in New Issue