Commit e91096e4e077cd067ba6db152d35798bac46ebd5

Authored by puhui999
1 parent 775cb889

feat: 新增短信渠道批量删除接口

yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsChannelController.java
... ... @@ -12,11 +12,11 @@ import cn.iocoder.yudao.module.system.service.sms.SmsChannelService;
12 12 import io.swagger.v3.oas.annotations.Operation;
13 13 import io.swagger.v3.oas.annotations.Parameter;
14 14 import io.swagger.v3.oas.annotations.tags.Tag;
  15 +import jakarta.annotation.Resource;
  16 +import jakarta.validation.Valid;
15 17 import org.springframework.security.access.prepost.PreAuthorize;
16 18 import org.springframework.web.bind.annotation.*;
17 19  
18   -import jakarta.annotation.Resource;
19   -import jakarta.validation.Valid;
20 20 import java.util.Comparator;
21 21 import java.util.List;
22 22  
... ... @@ -54,6 +54,15 @@ public class SmsChannelController {
54 54 return success(true);
55 55 }
56 56  
  57 + @DeleteMapping("/delete-list")
  58 + @Parameter(name = "ids", description = "编号列表", required = true)
  59 + @Operation(summary = "批量删除短信渠道")
  60 + @PreAuthorize("@ss.hasPermission('system:sms-channel:delete')")
  61 + public CommonResult<Boolean> deleteSmsChannelList(@RequestParam("ids") List<Long> ids) {
  62 + smsChannelService.deleteSmsChannelList(ids);
  63 + return success(true);
  64 + }
  65 +
57 66 @GetMapping("/get")
58 67 @Operation(summary = "获得短信渠道")
59 68 @Parameter(name = "id", description = "编号", required = true, example = "1024")
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelService.java
1 1 package cn.iocoder.yudao.module.system.service.sms;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient;
5 4 import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
6 5 import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO;
7 6 import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
8   -
  7 +import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient;
9 8 import jakarta.validation.Valid;
  9 +
10 10 import java.util.List;
11 11  
12 12 /**
... ... @@ -40,6 +40,13 @@ public interface SmsChannelService {
40 40 void deleteSmsChannel(Long id);
41 41  
42 42 /**
  43 + * 批量删除短信渠道
  44 + *
  45 + * @param ids 编号数组
  46 + */
  47 + void deleteSmsChannelList(List<Long> ids);
  48 +
  49 + /**
43 50 * 获得短信渠道
44 51 *
45 52 * @param id 编号
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java
1 1 package cn.iocoder.yudao.module.system.service.sms;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 6 import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
... ... @@ -65,6 +66,23 @@ public class SmsChannelServiceImpl implements SmsChannelService {
65 66 smsChannelMapper.deleteById(id);
66 67 }
67 68  
  69 + @Override
  70 + public void deleteSmsChannelList(List<Long> ids) {
  71 + if (CollUtil.isEmpty(ids)) {
  72 + return;
  73 + }
  74 + // 校验存在
  75 + validateSmsChannelBatchExists(ids);
  76 + // 校验是否有在使用该账号的模版
  77 + for (Long id : ids) {
  78 + if (smsTemplateService.getSmsTemplateCountByChannelId(id) > 0) {
  79 + throw exception(SMS_CHANNEL_HAS_CHILDREN);
  80 + }
  81 + }
  82 + // 批量删除
  83 + smsChannelMapper.deleteByIds(ids);
  84 + }
  85 +
68 86 private SmsChannelDO validateSmsChannelExists(Long id) {
69 87 SmsChannelDO channel = smsChannelMapper.selectById(id);
70 88 if (channel == null) {
... ... @@ -73,6 +91,13 @@ public class SmsChannelServiceImpl implements SmsChannelService {
73 91 return channel;
74 92 }
75 93  
  94 + private void validateSmsChannelBatchExists(List<Long> ids) {
  95 + List<SmsChannelDO> channels = smsChannelMapper.selectByIds(ids);
  96 + if (channels.size() != ids.size()) {
  97 + throw exception(SMS_CHANNEL_NOT_EXISTS);
  98 + }
  99 + }
  100 +
76 101 @Override
77 102 public SmsChannelDO getSmsChannel(Long id) {
78 103 return smsChannelMapper.selectById(id);
... ...