Commit 777d64f065b0501c76e447fa3660d48c7a536ce3

Authored by puhui999
1 parent 39d1954e

feat: infra 模块新增批量删除接口

Showing 18 changed files with 252 additions and 0 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java
@@ -122,6 +122,15 @@ public class CodegenController { @@ -122,6 +122,15 @@ public class CodegenController {
122 return success(true); 122 return success(true);
123 } 123 }
124 124
  125 + @Operation(summary = "批量删除数据库的表和字段定义")
  126 + @DeleteMapping("/delete-list")
  127 + @Parameter(name = "tableIds", description = "表编号列表", required = true)
  128 + @PreAuthorize("@ss.hasPermission('infra:codegen:delete')")
  129 + public CommonResult<Boolean> deleteCodegenList(@RequestParam("tableIds") List<Long> tableIds) {
  130 + codegenService.deleteCodegenList(tableIds);
  131 + return success(true);
  132 + }
  133 +
125 @Operation(summary = "预览生成代码") 134 @Operation(summary = "预览生成代码")
126 @GetMapping("/preview") 135 @GetMapping("/preview")
127 @Parameter(name = "tableId", description = "表编号", required = true, example = "1024") 136 @Parameter(name = "tableId", description = "表编号", required = true, example = "1024")
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java
@@ -62,6 +62,15 @@ public class ConfigController { @@ -62,6 +62,15 @@ public class ConfigController {
62 return success(true); 62 return success(true);
63 } 63 }
64 64
  65 + @DeleteMapping("/delete-list")
  66 + @Operation(summary = "批量删除参数配置")
  67 + @Parameter(name = "ids", description = "编号列表", required = true)
  68 + @PreAuthorize("@ss.hasPermission('infra:config:delete')")
  69 + public CommonResult<Boolean> deleteConfigList(@RequestParam("ids") List<Long> ids) {
  70 + configService.deleteConfigList(ids);
  71 + return success(true);
  72 + }
  73 +
65 @GetMapping(value = "/get") 74 @GetMapping(value = "/get")
66 @Operation(summary = "获得参数配置") 75 @Operation(summary = "获得参数配置")
67 @Parameter(name = "id", description = "编号", required = true, example = "1024") 76 @Parameter(name = "id", description = "编号", required = true, example = "1024")
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/DataSourceConfigController.java
@@ -52,6 +52,15 @@ public class DataSourceConfigController { @@ -52,6 +52,15 @@ public class DataSourceConfigController {
52 return success(true); 52 return success(true);
53 } 53 }
54 54
  55 + @DeleteMapping("/delete-list")
  56 + @Operation(summary = "批量删除数据源配置")
  57 + @Parameter(name = "ids", description = "编号列表", required = true)
  58 + @PreAuthorize("@ss.hasPermission('infra:data-source-config:delete')")
  59 + public CommonResult<Boolean> deleteDataSourceConfigList(@RequestParam("ids") List<Long> ids) {
  60 + dataSourceConfigService.deleteDataSourceConfigList(ids);
  61 + return success(true);
  62 + }
  63 +
55 @GetMapping("/get") 64 @GetMapping("/get")
56 @Operation(summary = "获得数据源配置") 65 @Operation(summary = "获得数据源配置")
57 @Parameter(name = "id", description = "编号", required = true, example = "1024") 66 @Parameter(name = "id", description = "编号", required = true, example = "1024")
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java
@@ -17,6 +17,8 @@ import org.springframework.security.access.prepost.PreAuthorize; @@ -17,6 +17,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
17 import org.springframework.validation.annotation.Validated; 17 import org.springframework.validation.annotation.Validated;
18 import org.springframework.web.bind.annotation.*; 18 import org.springframework.web.bind.annotation.*;
19 19
  20 +import java.util.List;
  21 +
20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
21 23
22 @Tag(name = "管理后台 - 文件配置") 24 @Tag(name = "管理后台 - 文件配置")
@@ -60,6 +62,15 @@ public class FileConfigController { @@ -60,6 +62,15 @@ public class FileConfigController {
60 return success(true); 62 return success(true);
61 } 63 }
62 64
  65 + @DeleteMapping("/delete-list")
  66 + @Operation(summary = "批量删除文件配置")
  67 + @Parameter(name = "ids", description = "编号列表", required = true)
  68 + @PreAuthorize("@ss.hasPermission('infra:file-config:delete')")
  69 + public CommonResult<Boolean> deleteFileConfigList(@RequestParam("ids") List<Long> ids) {
  70 + fileConfigService.deleteFileConfigList(ids);
  71 + return success(true);
  72 + }
  73 +
63 @GetMapping("/get") 74 @GetMapping("/get")
64 @Operation(summary = "获得文件配置") 75 @Operation(summary = "获得文件配置")
65 @Parameter(name = "id", description = "编号", required = true, example = "1024") 76 @Parameter(name = "id", description = "编号", required = true, example = "1024")
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
@@ -26,6 +26,8 @@ import org.springframework.validation.annotation.Validated; @@ -26,6 +26,8 @@ import org.springframework.validation.annotation.Validated;
26 import org.springframework.web.bind.annotation.*; 26 import org.springframework.web.bind.annotation.*;
27 import org.springframework.web.multipart.MultipartFile; 27 import org.springframework.web.multipart.MultipartFile;
28 28
  29 +import java.util.List;
  30 +
29 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 31 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
30 import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment; 32 import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
31 33
@@ -75,6 +77,15 @@ public class FileController { @@ -75,6 +77,15 @@ public class FileController {
75 return success(true); 77 return success(true);
76 } 78 }
77 79
  80 + @DeleteMapping("/delete-list")
  81 + @Operation(summary = "批量删除文件")
  82 + @Parameter(name = "ids", description = "编号列表", required = true)
  83 + @PreAuthorize("@ss.hasPermission('infra:file:delete')")
  84 + public CommonResult<Boolean> deleteFileList(@RequestParam("ids") List<Long> ids) throws Exception {
  85 + fileService.deleteFileList(ids);
  86 + return success(true);
  87 + }
  88 +
78 @GetMapping("/{configId}/get/**") 89 @GetMapping("/{configId}/get/**")
79 @PermitAll 90 @PermitAll
80 @TenantIgnore 91 @TenantIgnore
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java
@@ -81,6 +81,16 @@ public class JobController { @@ -81,6 +81,16 @@ public class JobController {
81 return success(true); 81 return success(true);
82 } 82 }
83 83
  84 + @DeleteMapping("/delete-list")
  85 + @Operation(summary = "批量删除定时任务")
  86 + @Parameter(name = "ids", description = "编号列表", required = true)
  87 + @PreAuthorize("@ss.hasPermission('infra:job:delete')")
  88 + public CommonResult<Boolean> deleteJobList(@RequestParam("ids") List<Long> ids)
  89 + throws SchedulerException {
  90 + jobService.deleteJobList(ids);
  91 + return success(true);
  92 + }
  93 +
84 @PutMapping("/trigger") 94 @PutMapping("/trigger")
85 @Operation(summary = "触发定时任务") 95 @Operation(summary = "触发定时任务")
86 @Parameter(name = "id", description = "编号", required = true, example = "1024") 96 @Parameter(name = "id", description = "编号", required = true, example = "1024")
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java
@@ -49,6 +49,13 @@ public interface CodegenService { @@ -49,6 +49,13 @@ public interface CodegenService {
49 void deleteCodegen(Long tableId); 49 void deleteCodegen(Long tableId);
50 50
51 /** 51 /**
  52 + * 批量删除数据库的表和字段定义
  53 + *
  54 + * @param tableIds 数据编号列表
  55 + */
  56 + void deleteCodegenList(List<Long> tableIds);
  57 +
  58 + /**
52 * 获得表定义列表 59 * 获得表定义列表
53 * 60 *
54 * @param dataSourceConfigId 数据源配置的编号 61 * @param dataSourceConfigId 数据源配置的编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java
@@ -223,6 +223,25 @@ public class CodegenServiceImpl implements CodegenService { @@ -223,6 +223,25 @@ public class CodegenServiceImpl implements CodegenService {
223 } 223 }
224 224
225 @Override 225 @Override
  226 + @Transactional(rollbackFor = Exception.class)
  227 + public void deleteCodegenList(List<Long> tableIds) {
  228 + if (CollUtil.isEmpty(tableIds)) {
  229 + return;
  230 + }
  231 +
  232 + // 校验是否都存在
  233 + List<CodegenTableDO> tables = codegenTableMapper.selectByIds(tableIds);
  234 + if (tables.size() != tableIds.size()) {
  235 + throw exception(CODEGEN_TABLE_NOT_EXISTS);
  236 + }
  237 +
  238 + // 批量删除 table 表定义
  239 + codegenTableMapper.deleteByIds(tableIds);
  240 + // 批量删除 column 字段定义
  241 + tableIds.forEach(tableId -> codegenColumnMapper.deleteListByTableId(tableId));
  242 + }
  243 +
  244 + @Override
226 public List<CodegenTableDO> getCodegenTableList(Long dataSourceConfigId) { 245 public List<CodegenTableDO> getCodegenTableList(Long dataSourceConfigId) {
227 return codegenTableMapper.selectListByDataSourceConfigId(dataSourceConfigId); 246 return codegenTableMapper.selectListByDataSourceConfigId(dataSourceConfigId);
228 } 247 }
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigService.java
@@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
6 import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; 6 import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 8
  9 +import java.util.List;
  10 +
9 /** 11 /**
10 * 参数配置 Service 接口 12 * 参数配置 Service 接口
11 * 13 *
@@ -36,6 +38,13 @@ public interface ConfigService { @@ -36,6 +38,13 @@ public interface ConfigService {
36 void deleteConfig(Long id); 38 void deleteConfig(Long id);
37 39
38 /** 40 /**
  41 + * 批量删除参数配置
  42 + *
  43 + * @param ids 配置编号列表
  44 + */
  45 + void deleteConfigList(List<Long> ids);
  46 +
  47 + /**
39 * 获得参数配置 48 * 获得参数配置
40 * 49 *
41 * @param id 配置编号 50 * @param id 配置编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
1 package cn.iocoder.yudao.module.infra.service.config; 1 package cn.iocoder.yudao.module.infra.service.config;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; 5 import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO;
5 import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; 6 import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
@@ -13,6 +14,8 @@ import lombok.extern.slf4j.Slf4j; @@ -13,6 +14,8 @@ import lombok.extern.slf4j.Slf4j;
13 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
14 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
15 16
  17 +import java.util.List;
  18 +
16 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 19 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
17 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; 20 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
18 21
@@ -64,6 +67,28 @@ public class ConfigServiceImpl implements ConfigService { @@ -64,6 +67,28 @@ public class ConfigServiceImpl implements ConfigService {
64 } 67 }
65 68
66 @Override 69 @Override
  70 + public void deleteConfigList(List<Long> ids) {
  71 + if (CollUtil.isEmpty(ids)) {
  72 + return;
  73 + }
  74 + // 校验配置存在
  75 + List<ConfigDO> configs = configMapper.selectByIds(ids);
  76 + if (configs.size() != ids.size()) {
  77 + throw exception(CONFIG_NOT_EXISTS);
  78 + }
  79 +
  80 + // 校验是否有内置配置
  81 + for (ConfigDO config : configs) {
  82 + if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
  83 + throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
  84 + }
  85 + }
  86 +
  87 + // 批量删除
  88 + configMapper.deleteByIds(ids);
  89 + }
  90 +
  91 + @Override
67 public ConfigDO getConfig(Long id) { 92 public ConfigDO getConfig(Long id) {
68 return configMapper.selectById(id); 93 return configMapper.selectById(id);
69 } 94 }
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigService.java
@@ -36,6 +36,13 @@ public interface DataSourceConfigService { @@ -36,6 +36,13 @@ public interface DataSourceConfigService {
36 void deleteDataSourceConfig(Long id); 36 void deleteDataSourceConfig(Long id);
37 37
38 /** 38 /**
  39 + * 批量删除数据源配置
  40 + *
  41 + * @param ids 编号列表
  42 + */
  43 + void deleteDataSourceConfigList(List<Long> ids);
  44 +
  45 + /**
39 * 获得数据源配置 46 * 获得数据源配置
40 * 47 *
41 * @param id 编号 48 * @param id 编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java
1 package cn.iocoder.yudao.module.infra.service.db; 1 package cn.iocoder.yudao.module.infra.service.db;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
4 import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; 5 import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
5 import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; 6 import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
@@ -63,6 +64,17 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService { @@ -63,6 +64,17 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
63 dataSourceConfigMapper.deleteById(id); 64 dataSourceConfigMapper.deleteById(id);
64 } 65 }
65 66
  67 + @Override
  68 + public void deleteDataSourceConfigList(List<Long> ids) {
  69 + if (CollUtil.isEmpty(ids)) {
  70 + return;
  71 + }
  72 + // 校验存在
  73 + ids.forEach(this::validateDataSourceConfigExists);
  74 + // 批量删除
  75 + dataSourceConfigMapper.deleteByIds(ids);
  76 + }
  77 +
66 private void validateDataSourceConfigExists(Long id) { 78 private void validateDataSourceConfigExists(Long id) {
67 if (dataSourceConfigMapper.selectById(id) == null) { 79 if (dataSourceConfigMapper.selectById(id) == null) {
68 throw exception(DATA_SOURCE_CONFIG_NOT_EXISTS); 80 throw exception(DATA_SOURCE_CONFIG_NOT_EXISTS);
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO;
7 import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient; 7 import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
8 import jakarta.validation.Valid; 8 import jakarta.validation.Valid;
9 9
  10 +import java.util.List;
  11 +
10 /** 12 /**
11 * 文件配置 Service 接口 13 * 文件配置 Service 接口
12 * 14 *
@@ -44,6 +46,13 @@ public interface FileConfigService { @@ -44,6 +46,13 @@ public interface FileConfigService {
44 void deleteFileConfig(Long id); 46 void deleteFileConfig(Long id);
45 47
46 /** 48 /**
  49 + * 批量删除文件配置
  50 + *
  51 + * @param ids 编号列表
  52 + */
  53 + void deleteFileConfigList(List<Long> ids);
  54 +
  55 + /**
47 * 获得文件配置 56 * 获得文件配置
48 * 57 *
49 * @param id 编号 58 * @param id 编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
1 package cn.iocoder.yudao.module.infra.service.file; 1 package cn.iocoder.yudao.module.infra.service.file;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.hutool.core.io.resource.ResourceUtil; 4 import cn.hutool.core.io.resource.ResourceUtil;
4 import cn.hutool.core.util.IdUtil; 5 import cn.hutool.core.util.IdUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional; @@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
25 import org.springframework.validation.annotation.Validated; 26 import org.springframework.validation.annotation.Validated;
26 27
27 import java.time.Duration; 28 import java.time.Duration;
  29 +import java.util.List;
28 import java.util.Map; 30 import java.util.Map;
29 import java.util.Objects; 31 import java.util.Objects;
30 32
@@ -134,6 +136,34 @@ public class FileConfigServiceImpl implements FileConfigService { @@ -134,6 +136,34 @@ public class FileConfigServiceImpl implements FileConfigService {
134 clearCache(id, null); 136 clearCache(id, null);
135 } 137 }
136 138
  139 + @Override
  140 + public void deleteFileConfigList(List<Long> ids) {
  141 + if (CollUtil.isEmpty(ids)) {
  142 + return;
  143 + }
  144 +
  145 + // 校验存在
  146 + List<FileConfigDO> configs = fileConfigMapper.selectByIds(ids);
  147 + if (configs.size() != ids.size()) {
  148 + throw exception(FILE_CONFIG_NOT_EXISTS);
  149 + }
  150 +
  151 + // 校验是否有主配置
  152 + for (FileConfigDO config : configs) {
  153 + if (Boolean.TRUE.equals(config.getMaster())) {
  154 + throw exception(FILE_CONFIG_DELETE_FAIL_MASTER);
  155 + }
  156 + }
  157 +
  158 + // 批量删除
  159 + fileConfigMapper.deleteByIds(ids);
  160 +
  161 + // 清空缓存
  162 + for (Long id : ids) {
  163 + clearCache(id, null);
  164 + }
  165 + }
  166 +
137 /** 167 /**
138 * 清空指定文件配置 168 * 清空指定文件配置
139 * 169 *
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresigned @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresigned
7 import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; 7 import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
8 import jakarta.validation.constraints.NotEmpty; 8 import jakarta.validation.constraints.NotEmpty;
9 9
  10 +import java.util.List;
  11 +
10 /** 12 /**
11 * 文件 Service 接口 13 * 文件 Service 接口
12 * 14 *
@@ -60,6 +62,13 @@ public interface FileService { @@ -60,6 +62,13 @@ public interface FileService {
60 void deleteFile(Long id) throws Exception; 62 void deleteFile(Long id) throws Exception;
61 63
62 /** 64 /**
  65 + * 批量删除文件
  66 + *
  67 + * @param ids 编号列表
  68 + */
  69 + void deleteFileList(List<Long> ids) throws Exception;
  70 +
  71 + /**
63 * 获得文件内容 72 * 获得文件内容
64 * 73 *
65 * @param configId 配置编号 74 * @param configId 配置编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
1 package cn.iocoder.yudao.module.infra.service.file; 1 package cn.iocoder.yudao.module.infra.service.file;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.hutool.core.date.LocalDateTimeUtil; 4 import cn.hutool.core.date.LocalDateTimeUtil;
4 import cn.hutool.core.io.FileUtil; 5 import cn.hutool.core.io.FileUtil;
5 import cn.hutool.core.lang.Assert; 6 import cn.hutool.core.lang.Assert;
@@ -20,6 +21,10 @@ import jakarta.annotation.Resource; @@ -20,6 +21,10 @@ import jakarta.annotation.Resource;
20 import lombok.SneakyThrows; 21 import lombok.SneakyThrows;
21 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
22 23
  24 +import java.util.List;
  25 +import java.util.Map;
  26 +import java.util.stream.Collectors;
  27 +
23 import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN; 28 import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
24 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 29 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
25 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS; 30 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
@@ -156,6 +161,36 @@ public class FileServiceImpl implements FileService { @@ -156,6 +161,36 @@ public class FileServiceImpl implements FileService {
156 fileMapper.deleteById(id); 161 fileMapper.deleteById(id);
157 } 162 }
158 163
  164 + @Override
  165 + public void deleteFileList(List<Long> ids) throws Exception {
  166 + if (CollUtil.isEmpty(ids)) {
  167 + return;
  168 + }
  169 +
  170 + // 校验存在
  171 + List<FileDO> files = fileMapper.selectByIds(ids);
  172 + if (files.size() != ids.size()) {
  173 + throw exception(FILE_NOT_EXISTS);
  174 + }
  175 +
  176 + // 按照配置分组,批量删除
  177 + Map<Long, List<FileDO>> configFiles = files.stream()
  178 + .collect(Collectors.groupingBy(FileDO::getConfigId));
  179 + for (Map.Entry<Long, List<FileDO>> entry : configFiles.entrySet()) {
  180 + // 获取客户端
  181 + FileClient client = fileConfigService.getFileClient(entry.getKey());
  182 + Assert.notNull(client, "客户端({}) 不能为空", entry.getKey());
  183 +
  184 + // 批量删除文件
  185 + for (FileDO file : entry.getValue()) {
  186 + client.delete(file.getPath());
  187 + }
  188 + }
  189 +
  190 + // 删除记录
  191 + fileMapper.deleteByIds(ids);
  192 + }
  193 +
159 private FileDO validateFileExists(Long id) { 194 private FileDO validateFileExists(Long id) {
160 FileDO fileDO = fileMapper.selectById(id); 195 FileDO fileDO = fileMapper.selectById(id);
161 if (fileDO == null) { 196 if (fileDO == null) {
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 import org.quartz.SchedulerException; 8 import org.quartz.SchedulerException;
9 9
  10 +import java.util.List;
  11 +
10 /** 12 /**
11 * 定时任务 Service 接口 13 * 定时任务 Service 接口
12 * 14 *
@@ -59,6 +61,13 @@ public interface JobService { @@ -59,6 +61,13 @@ public interface JobService {
59 void deleteJob(Long id) throws SchedulerException; 61 void deleteJob(Long id) throws SchedulerException;
60 62
61 /** 63 /**
  64 + * 批量删除定时任务
  65 + *
  66 + * @param ids 编号列表
  67 + */
  68 + void deleteJobList(List<Long> ids) throws SchedulerException;
  69 +
  70 + /**
62 * 获得定时任务 71 * 获得定时任务
63 * 72 *
64 * @param id 编号 73 * @param id 编号
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java
@@ -169,6 +169,28 @@ public class JobServiceImpl implements JobService { @@ -169,6 +169,28 @@ public class JobServiceImpl implements JobService {
169 schedulerManager.deleteJob(job.getHandlerName()); 169 schedulerManager.deleteJob(job.getHandlerName());
170 } 170 }
171 171
  172 + @Override
  173 + @Transactional(rollbackFor = Exception.class)
  174 + public void deleteJobList(List<Long> ids) throws SchedulerException {
  175 + if (ids == null || ids.isEmpty()) {
  176 + return;
  177 + }
  178 +
  179 + // 校验存在
  180 + List<JobDO> jobs = jobMapper.selectByIds(ids);
  181 + if (jobs.size() != ids.size()) {
  182 + throw exception(JOB_NOT_EXISTS);
  183 + }
  184 +
  185 + // 批量删除
  186 + jobMapper.deleteByIds(ids);
  187 +
  188 + // 删除 Job 到 Quartz 中
  189 + for (JobDO job : jobs) {
  190 + schedulerManager.deleteJob(job.getHandlerName());
  191 + }
  192 + }
  193 +
172 private JobDO validateJobExists(Long id) { 194 private JobDO validateJobExists(Long id) {
173 JobDO job = jobMapper.selectById(id); 195 JobDO job = jobMapper.selectById(id);
174 if (job == null) { 196 if (job == null) {