Commit bcd6ed4c4cca5477d9190e5b2855d15148886de4
Committed by
Gitee
!1366 feat: system、infra 模块新增批量删除接口
Merge pull request !1366 from puhui999/master-jdk17
Showing
32 changed files
with
414 additions
and
10 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) { |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java
| @@ -58,11 +58,20 @@ public class DictDataController { | @@ -58,11 +58,20 @@ public class DictDataController { | ||
| 58 | @Operation(summary = "删除字典数据") | 58 | @Operation(summary = "删除字典数据") |
| 59 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 59 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 60 | @PreAuthorize("@ss.hasPermission('system:dict:delete')") | 60 | @PreAuthorize("@ss.hasPermission('system:dict:delete')") |
| 61 | - public CommonResult<Boolean> deleteDictData(Long id) { | 61 | + public CommonResult<Boolean> deleteDictData(@RequestParam("id") Long id) { |
| 62 | dictDataService.deleteDictData(id); | 62 | dictDataService.deleteDictData(id); |
| 63 | return success(true); | 63 | return success(true); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | + @DeleteMapping("/delete-list") | ||
| 67 | + @Operation(summary = "批量删除字典数据") | ||
| 68 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 69 | + @PreAuthorize("@ss.hasPermission('system:dict:delete')") | ||
| 70 | + public CommonResult<Boolean> deleteDictDataList(@RequestParam("ids") List<Long> ids) { | ||
| 71 | + dictDataService.deleteDictDataList(ids); | ||
| 72 | + return success(true); | ||
| 73 | + } | ||
| 74 | + | ||
| 66 | @GetMapping(value = {"/list-all-simple", "simple-list"}) | 75 | @GetMapping(value = {"/list-all-simple", "simple-list"}) |
| 67 | @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地") | 76 | @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地") |
| 68 | // 无需添加权限认证,因为前端全局都需要 | 77 | // 无需添加权限认证,因为前端全局都需要 |
| @@ -73,7 +82,7 @@ public class DictDataController { | @@ -73,7 +82,7 @@ public class DictDataController { | ||
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | @GetMapping("/page") | 84 | @GetMapping("/page") |
| 76 | - @Operation(summary = "/获得字典类型的分页列表") | 85 | + @Operation(summary = "获得字典类型的分页") |
| 77 | @PreAuthorize("@ss.hasPermission('system:dict:query')") | 86 | @PreAuthorize("@ss.hasPermission('system:dict:query')") |
| 78 | public CommonResult<PageResult<DictDataRespVO>> getDictTypePage(@Valid DictDataPageReqVO pageReqVO) { | 87 | public CommonResult<PageResult<DictDataRespVO>> getDictTypePage(@Valid DictDataPageReqVO pageReqVO) { |
| 79 | PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(pageReqVO); | 88 | PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(pageReqVO); |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictTypeController.java
| @@ -62,6 +62,15 @@ public class DictTypeController { | @@ -62,6 +62,15 @@ public class DictTypeController { | ||
| 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('system:dict:delete')") | ||
| 69 | + public CommonResult<Boolean> deleteDictTypeList(@RequestParam("ids") List<Long> ids) { | ||
| 70 | + dictTypeService.deleteDictTypeList(ids); | ||
| 71 | + return success(true); | ||
| 72 | + } | ||
| 73 | + | ||
| 65 | @GetMapping("/page") | 74 | @GetMapping("/page") |
| 66 | @Operation(summary = "获得字典类型的分页列表") | 75 | @Operation(summary = "获得字典类型的分页列表") |
| 67 | @PreAuthorize("@ss.hasPermission('system:dict:query')") | 76 | @PreAuthorize("@ss.hasPermission('system:dict:query')") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java
| @@ -12,12 +12,12 @@ import cn.iocoder.yudao.module.system.service.permission.MenuService; | @@ -12,12 +12,12 @@ import cn.iocoder.yudao.module.system.service.permission.MenuService; | ||
| 12 | import io.swagger.v3.oas.annotations.Operation; | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | import io.swagger.v3.oas.annotations.Parameter; | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | +import jakarta.annotation.Resource; | ||
| 16 | +import jakarta.validation.Valid; | ||
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 17 | import org.springframework.web.bind.annotation.*; | 19 | import org.springframework.web.bind.annotation.*; |
| 18 | 20 | ||
| 19 | -import jakarta.annotation.Resource; | ||
| 20 | -import jakarta.validation.Valid; | ||
| 21 | import java.util.Comparator; | 21 | import java.util.Comparator; |
| 22 | import java.util.List; | 22 | import java.util.List; |
| 23 | 23 | ||
| @@ -57,6 +57,15 @@ public class MenuController { | @@ -57,6 +57,15 @@ public class MenuController { | ||
| 57 | return success(true); | 57 | return success(true); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | + @DeleteMapping("/delete-list") | ||
| 61 | + @Operation(summary = "批量删除菜单") | ||
| 62 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 63 | + @PreAuthorize("@ss.hasPermission('system:menu:delete')") | ||
| 64 | + public CommonResult<Boolean> deleteMenuList(@RequestParam("ids") List<Long> ids) { | ||
| 65 | + menuService.deleteMenuList(ids); | ||
| 66 | + return success(true); | ||
| 67 | + } | ||
| 68 | + | ||
| 60 | @GetMapping("/list") | 69 | @GetMapping("/list") |
| 61 | @Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面") | 70 | @Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面") |
| 62 | @PreAuthorize("@ss.hasPermission('system:menu:query')") | 71 | @PreAuthorize("@ss.hasPermission('system:menu:query')") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java
| @@ -7,7 +7,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; | @@ -7,7 +7,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*; | 10 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleRespVO; | ||
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | ||
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 12 | import cn.iocoder.yudao.module.system.service.permission.RoleService; | 14 | import cn.iocoder.yudao.module.system.service.permission.RoleService; |
| 13 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| @@ -61,6 +63,15 @@ public class RoleController { | @@ -61,6 +63,15 @@ public class RoleController { | ||
| 61 | return success(true); | 63 | return success(true); |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 66 | + @DeleteMapping("/delete-list") | ||
| 67 | + @Operation(summary = "批量删除角色") | ||
| 68 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 69 | + @PreAuthorize("@ss.hasPermission('system:role:delete')") | ||
| 70 | + public CommonResult<Boolean> deleteRoleList(@RequestParam("ids") List<Long> ids) { | ||
| 71 | + roleService.deleteRoleList(ids); | ||
| 72 | + return success(true); | ||
| 73 | + } | ||
| 74 | + | ||
| 64 | @GetMapping("/get") | 75 | @GetMapping("/get") |
| 65 | @Operation(summary = "获得角色信息") | 76 | @Operation(summary = "获得角色信息") |
| 66 | @PreAuthorize("@ss.hasPermission('system:role:query')") | 77 | @PreAuthorize("@ss.hasPermission('system:role:query')") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java
| @@ -39,6 +39,13 @@ public interface PostService { | @@ -39,6 +39,13 @@ public interface PostService { | ||
| 39 | void deletePost(Long id); | 39 | void deletePost(Long id); |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | + * 批量删除岗位信息 | ||
| 43 | + * | ||
| 44 | + * @param ids 岗位编号数组 | ||
| 45 | + */ | ||
| 46 | + void deletePostList(List<Long> ids); | ||
| 47 | + | ||
| 48 | + /** | ||
| 42 | * 获得岗位列表 | 49 | * 获得岗位列表 |
| 43 | * | 50 | * |
| 44 | * @param ids 岗位编号数组 | 51 | * @param ids 岗位编号数组 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
| @@ -8,10 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqV | @@ -8,10 +8,10 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqV | ||
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; | 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; |
| 11 | +import jakarta.annotation.Resource; | ||
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 13 | 14 | ||
| 14 | -import jakarta.annotation.Resource; | ||
| 15 | import java.util.Collection; | 15 | import java.util.Collection; |
| 16 | import java.util.Collections; | 16 | import java.util.Collections; |
| 17 | import java.util.List; | 17 | import java.util.List; |
| @@ -58,10 +58,16 @@ public class PostServiceImpl implements PostService { | @@ -58,10 +58,16 @@ public class PostServiceImpl implements PostService { | ||
| 58 | public void deletePost(Long id) { | 58 | public void deletePost(Long id) { |
| 59 | // 校验是否存在 | 59 | // 校验是否存在 |
| 60 | validatePostExists(id); | 60 | validatePostExists(id); |
| 61 | - // 删除部门 | 61 | + // 删除岗位 |
| 62 | postMapper.deleteById(id); | 62 | postMapper.deleteById(id); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | + @Override | ||
| 66 | + public void deletePostList(List<Long> ids) { | ||
| 67 | + // 删除岗位 | ||
| 68 | + postMapper.deleteByIds(ids); | ||
| 69 | + } | ||
| 70 | + | ||
| 65 | private void validatePostForCreateOrUpdate(Long id, String name, String code) { | 71 | private void validatePostForCreateOrUpdate(Long id, String name, String code) { |
| 66 | // 校验自己存在 | 72 | // 校验自己存在 |
| 67 | validatePostExists(id); | 73 | validatePostExists(id); |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java
| @@ -39,6 +39,13 @@ public interface DictDataService { | @@ -39,6 +39,13 @@ public interface DictDataService { | ||
| 39 | void deleteDictData(Long id); | 39 | void deleteDictData(Long id); |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | + * 批量删除字典数据 | ||
| 43 | + * | ||
| 44 | + * @param ids 字典数据编号列表 | ||
| 45 | + */ | ||
| 46 | + void deleteDictDataList(List<Long> ids); | ||
| 47 | + | ||
| 48 | + /** | ||
| 42 | * 获得字典数据列表 | 49 | * 获得字典数据列表 |
| 43 | * | 50 | * |
| 44 | * @param status 状态 | 51 | * @param status 状态 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java
| @@ -99,6 +99,18 @@ public class DictDataServiceImpl implements DictDataService { | @@ -99,6 +99,18 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | @Override | 101 | @Override |
| 102 | + public void deleteDictDataList(List<Long> ids) { | ||
| 103 | + if (CollUtil.isEmpty(ids)) { | ||
| 104 | + return; | ||
| 105 | + } | ||
| 106 | + // 校验是否存在 | ||
| 107 | + ids.forEach(this::validateDictDataExists); | ||
| 108 | + | ||
| 109 | + // 批量删除字典数据 | ||
| 110 | + dictDataMapper.deleteByIds(ids); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + @Override | ||
| 102 | public long getDictDataCountByDictType(String dictType) { | 114 | public long getDictDataCountByDictType(String dictType) { |
| 103 | return dictDataMapper.selectCountByDictType(dictType); | 115 | return dictDataMapper.selectCountByDictType(dictType); |
| 104 | } | 116 | } |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeService.java
| @@ -37,6 +37,13 @@ public interface DictTypeService { | @@ -37,6 +37,13 @@ public interface DictTypeService { | ||
| 37 | void deleteDictType(Long id); | 37 | void deleteDictType(Long id); |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | + * 批量删除字典类型 | ||
| 41 | + * | ||
| 42 | + * @param ids 字典类型编号列表 | ||
| 43 | + */ | ||
| 44 | + void deleteDictTypeList(List<Long> ids); | ||
| 45 | + | ||
| 46 | + /** | ||
| 40 | * 获得字典类型分页列表 | 47 | * 获得字典类型分页列表 |
| 41 | * | 48 | * |
| 42 | * @param pageReqVO 分页请求 | 49 | * @param pageReqVO 分页请求 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java
| @@ -9,9 +9,9 @@ import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSave | @@ -9,9 +9,9 @@ import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeSave | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.dict.DictTypeMapper; |
| 11 | import com.google.common.annotations.VisibleForTesting; | 11 | import com.google.common.annotations.VisibleForTesting; |
| 12 | +import jakarta.annotation.Resource; | ||
| 12 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 13 | 14 | ||
| 14 | -import jakarta.annotation.Resource; | ||
| 15 | import java.time.LocalDateTime; | 15 | import java.time.LocalDateTime; |
| 16 | import java.util.List; | 16 | import java.util.List; |
| 17 | 17 | ||
| @@ -88,6 +88,27 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -88,6 +88,27 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | @Override | 90 | @Override |
| 91 | + public void deleteDictTypeList(List<Long> ids) { | ||
| 92 | + if (ids == null || ids.isEmpty()) { | ||
| 93 | + return; | ||
| 94 | + } | ||
| 95 | + // 校验是否存在 | ||
| 96 | + ids.forEach(this::validateDictTypeExists); | ||
| 97 | + | ||
| 98 | + // 校验是否有字典数据 | ||
| 99 | + List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids); | ||
| 100 | + for (DictTypeDO dictType : dictTypes) { | ||
| 101 | + if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) { | ||
| 102 | + throw exception(DICT_TYPE_HAS_CHILDREN); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + // 批量删除字典类型 | ||
| 107 | + LocalDateTime now = LocalDateTime.now(); | ||
| 108 | + ids.forEach(id -> dictTypeMapper.updateToDelete(id, now)); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + @Override | ||
| 91 | public List<DictTypeDO> getDictTypeList() { | 112 | public List<DictTypeDO> getDictTypeList() { |
| 92 | return dictTypeMapper.selectList(); | 113 | return dictTypeMapper.selectList(); |
| 93 | } | 114 | } |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java
| 1 | package cn.iocoder.yudao.module.system.service.permission; | 1 | package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | ||
| 4 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; | 3 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| 4 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | ||
| 5 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; | 5 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 6 | 6 | ||
| 7 | import java.util.Collection; | 7 | import java.util.Collection; |
| @@ -37,6 +37,13 @@ public interface MenuService { | @@ -37,6 +37,13 @@ public interface MenuService { | ||
| 37 | void deleteMenu(Long id); | 37 | void deleteMenu(Long id); |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | + * 批量删除菜单 | ||
| 41 | + * | ||
| 42 | + * @param ids 菜单编号数组 | ||
| 43 | + */ | ||
| 44 | + void deleteMenuList(List<Long> ids); | ||
| 45 | + | ||
| 46 | + /** | ||
| 40 | * 获得所有菜单列表 | 47 | * 获得所有菜单列表 |
| 41 | * | 48 | * |
| 42 | * @return 菜单列表 | 49 | * @return 菜单列表 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| @@ -105,6 +105,31 @@ public class MenuServiceImpl implements MenuService { | @@ -105,6 +105,31 @@ public class MenuServiceImpl implements MenuService { | ||
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | @Override | 107 | @Override |
| 108 | + @Transactional(rollbackFor = Exception.class) | ||
| 109 | + @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, allEntries = true) | ||
| 110 | + public void deleteMenuList(List<Long> ids) { | ||
| 111 | + if (CollUtil.isEmpty(ids)) { | ||
| 112 | + return; | ||
| 113 | + } | ||
| 114 | + // 校验是否还有子菜单 | ||
| 115 | + for (Long id : ids) { | ||
| 116 | + if (menuMapper.selectCountByParentId(id) > 0) { | ||
| 117 | + throw exception(MENU_EXISTS_CHILDREN); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + // 校验删除的菜单是否存在 | ||
| 121 | + List<MenuDO> menus = menuMapper.selectByIds(ids); | ||
| 122 | + if (menus.size() != ids.size()) { | ||
| 123 | + throw exception(MENU_NOT_EXISTS); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + // 标记删除 | ||
| 127 | + menuMapper.deleteByIds(ids); | ||
| 128 | + // 删除授予给角色的权限 | ||
| 129 | + ids.forEach(id -> permissionService.processMenuDeleted(id)); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 108 | public List<MenuDO> getMenuList() { | 133 | public List<MenuDO> getMenuList() { |
| 109 | return menuMapper.selectList(); | 134 | return menuMapper.selectList(); |
| 110 | } | 135 | } |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java
| @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 7 | - | ||
| 8 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | + | ||
| 9 | import java.util.Collection; | 9 | import java.util.Collection; |
| 10 | import java.util.List; | 10 | import java.util.List; |
| 11 | import java.util.Set; | 11 | import java.util.Set; |
| @@ -41,6 +41,13 @@ public interface RoleService { | @@ -41,6 +41,13 @@ public interface RoleService { | ||
| 41 | void deleteRole(Long id); | 41 | void deleteRole(Long id); |
| 42 | 42 | ||
| 43 | /** | 43 | /** |
| 44 | + * 批量删除角色 | ||
| 45 | + * | ||
| 46 | + * @param ids 角色编号数组 | ||
| 47 | + */ | ||
| 48 | + void deleteRoleList(List<Long> ids); | ||
| 49 | + | ||
| 50 | + /** | ||
| 44 | * 设置角色的数据权限 | 51 | * 设置角色的数据权限 |
| 45 | * | 52 | * |
| 46 | * @param id 角色编号 | 53 | * @param id 角色编号 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java
| @@ -122,6 +122,21 @@ public class RoleServiceImpl implements RoleService { | @@ -122,6 +122,21 @@ public class RoleServiceImpl implements RoleService { | ||
| 122 | LogRecordContext.putVariable("role", role); | 122 | LogRecordContext.putVariable("role", role); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | + @Override | ||
| 126 | + @Transactional(rollbackFor = Exception.class) | ||
| 127 | + public void deleteRoleList(List<Long> ids) { | ||
| 128 | + if (CollUtil.isEmpty(ids)) { | ||
| 129 | + return; | ||
| 130 | + } | ||
| 131 | + // 1. 校验是否可以更新 | ||
| 132 | + ids.forEach(this::validateRoleForUpdate); | ||
| 133 | + | ||
| 134 | + // 2.1 标记删除 | ||
| 135 | + roleMapper.deleteByIds(ids); | ||
| 136 | + // 2.2 删除相关数据 | ||
| 137 | + ids.forEach(id -> permissionService.processRoleDeleted(id)); | ||
| 138 | + } | ||
| 139 | + | ||
| 125 | /** | 140 | /** |
| 126 | * 校验角色的唯一字段是否重复 | 141 | * 校验角色的唯一字段是否重复 |
| 127 | * | 142 | * |