删除短信渠道时,增加校验是否有模板
This commit is contained in:
@@ -35,5 +35,4 @@ public class SysSmsChannelBaseVO {
|
||||
@URL(message = "回调 URL 格式不正确")
|
||||
private String callbackUrl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -41,4 +41,8 @@ public interface SysSmsTemplateMapper extends BaseMapperX<SysSmsTemplateDO> {
|
||||
.orderByDesc("id"));
|
||||
}
|
||||
|
||||
default Integer selectCountByChannelId(Long channelId) {
|
||||
return selectCount("channel_id", channelId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ public interface SysErrorCodeConstants {
|
||||
// ========== 短信渠道 1002011000 ==========
|
||||
ErrorCode SMS_CHANNEL_NOT_EXISTS = new ErrorCode(1002011000, "短信渠道不存在");
|
||||
ErrorCode SMS_CHANNEL_DISABLE = new ErrorCode(1002011001, "短信渠道不处于开启状态,不允许选择");
|
||||
ErrorCode SMS_CHANNEL_HAS_CHILDREN = new ErrorCode(1002011002, "无法删除,该短信渠道还有短信模板");
|
||||
|
||||
// ========== 短信模板 1002011000 ==========
|
||||
ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在");
|
||||
|
||||
@@ -91,4 +91,12 @@ public interface SysSmsTemplateService {
|
||||
*/
|
||||
List<SysSmsTemplateDO> getSmsTemplateList(SysSmsTemplateExportReqVO exportReqVO);
|
||||
|
||||
/**
|
||||
* 获得指定短信渠道下的短信模板数量
|
||||
*
|
||||
* @param channelId 短信渠道编号
|
||||
* @return 数量
|
||||
*/
|
||||
Integer countByChannelId(Long channelId);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsChannelConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsChannelMapper;
|
||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService;
|
||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -19,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_HAS_CHILDREN;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.SMS_CHANNEL_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -36,6 +38,9 @@ public class SysSmsChannelServiceImpl implements SysSmsChannelService {
|
||||
@Resource
|
||||
private SysSmsChannelMapper smsChannelMapper;
|
||||
|
||||
@Resource
|
||||
private SysSmsTemplateService smsTemplateService;
|
||||
|
||||
@Override
|
||||
@PostConstruct
|
||||
public void initSmsClients() {
|
||||
@@ -70,6 +75,10 @@ public class SysSmsChannelServiceImpl implements SysSmsChannelService {
|
||||
public void deleteSmsChannel(Long id) {
|
||||
// 校验存在
|
||||
this.validateSmsChannelExists(id);
|
||||
// 校验是否有字典数据
|
||||
if (smsTemplateService.countByChannelId(id) > 0) {
|
||||
throw exception(SMS_CHANNEL_HAS_CHILDREN);
|
||||
}
|
||||
// 更新
|
||||
smsChannelMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
@@ -40,7 +39,6 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
* @date 2021/1/25 9:25
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class SysSmsTemplateServiceImpl implements SysSmsTemplateService {
|
||||
|
||||
/**
|
||||
@@ -142,6 +140,11 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService {
|
||||
return smsTemplateMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countByChannelId(Long channelId) {
|
||||
return smsTemplateMapper.selectCountByChannelId(channelId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SysSmsChannelDO checkSmsChannel(Long channelId) {
|
||||
SysSmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId);
|
||||
|
||||
Reference in New Issue
Block a user