feat: 新增短信渠道批量删除接口
This commit is contained in:
parent
775cb8896b
commit
e91096e4e0
|
@ -12,11 +12,11 @@ import cn.iocoder.yudao.module.system.service.sms.SmsChannelService;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -54,6 +54,15 @@ public class SmsChannelController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true)
|
||||
@Operation(summary = "批量删除短信渠道")
|
||||
@PreAuthorize("@ss.hasPermission('system:sms-channel:delete')")
|
||||
public CommonResult<Boolean> deleteSmsChannelList(@RequestParam("ids") List<Long> ids) {
|
||||
smsChannelService.deleteSmsChannelList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得短信渠道")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package cn.iocoder.yudao.module.system.service.sms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
|
||||
|
||||
import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,13 @@ public interface SmsChannelService {
|
|||
*/
|
||||
void deleteSmsChannel(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除短信渠道
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteSmsChannelList(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得短信渠道
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.system.service.sms;
|
||||
|
||||
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.system.controller.admin.sms.vo.channel.SmsChannelPageReqVO;
|
||||
|
@ -65,6 +66,23 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||
smsChannelMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSmsChannelList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验存在
|
||||
validateSmsChannelBatchExists(ids);
|
||||
// 校验是否有在使用该账号的模版
|
||||
for (Long id : ids) {
|
||||
if (smsTemplateService.getSmsTemplateCountByChannelId(id) > 0) {
|
||||
throw exception(SMS_CHANNEL_HAS_CHILDREN);
|
||||
}
|
||||
}
|
||||
// 批量删除
|
||||
smsChannelMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private SmsChannelDO validateSmsChannelExists(Long id) {
|
||||
SmsChannelDO channel = smsChannelMapper.selectById(id);
|
||||
if (channel == null) {
|
||||
|
@ -73,6 +91,13 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
|||
return channel;
|
||||
}
|
||||
|
||||
private void validateSmsChannelBatchExists(List<Long> ids) {
|
||||
List<SmsChannelDO> channels = smsChannelMapper.selectByIds(ids);
|
||||
if (channels.size() != ids.size()) {
|
||||
throw exception(SMS_CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmsChannelDO getSmsChannel(Long id) {
|
||||
return smsChannelMapper.selectById(id);
|
||||
|
|
Loading…
Reference in New Issue