feat:【INFRA 基础设施】代码生成时,可生成批量删除接口

This commit is contained in:
puhui999
2025-05-19 11:50:07 +08:00
parent 7a3634d8c0
commit 9295d61030
14 changed files with 146 additions and 30 deletions

View File

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

View File

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

View File

@@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -60,6 +61,15 @@ public class Demo01ContactController {
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")
@Operation(summary = "获得示例联系人")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@@ -82,12 +92,12 @@ public class Demo01ContactController {
@PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<Demo01ContactDO> list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class,
BeanUtils.toBean(list, Demo01ContactRespVO.class));
BeanUtils.toBean(list, Demo01ContactRespVO.class));
}
}

View File

@@ -1,10 +1,12 @@
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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

View File

@@ -1,14 +1,13 @@
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.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")
@Data

View File

@@ -1,10 +1,10 @@
package cn.iocoder.yudao.module.infra.controller.admin.demo.demo01.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO")

View File

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

View File

@@ -1,9 +1,9 @@
package cn.iocoder.yudao.module.infra.dal.mysql.demo.demo01;
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.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 org.apache.ibatis.annotations.Mapper;

View File

@@ -1,11 +1,11 @@
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.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 接口
@@ -36,6 +36,13 @@ public interface Demo01ContactService {
*/
void deleteDemo01Contact(Long id);
/**
* 批量删除示例联系人
*
* @param ids 编号
*/
void deleteDemo01ContactByIds(List<Long> ids);
/**
* 获得示例联系人
*

View File

@@ -1,19 +1,20 @@
package cn.iocoder.yudao.module.infra.service.demo.demo01;
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 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.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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 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.module.infra.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS;
/**
* 示例联系人 Service 实现类
@@ -53,6 +54,21 @@ public class Demo01ContactServiceImpl implements Demo01ContactService {
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) {
if (demo01ContactMapper.selectById(id) == null) {
throw exception(DEMO01_CONTACT_NOT_EXISTS);