mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
system:将 check 方法,统一成 validate 方法
This commit is contained in:
parent
2ba4dec0da
commit
245e557309
@ -76,7 +76,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
@Override
|
||||
public Long createNotifyTemplate(NotifyTemplateCreateReqVO createReqVO) {
|
||||
// 校验站内信编码是否重复
|
||||
checkNotifyTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
validateNotifyTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
|
||||
// 插入
|
||||
NotifyTemplateDO notifyTemplate = NotifyTemplateConvert.INSTANCE.convert(createReqVO);
|
||||
@ -93,7 +93,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
// 校验存在
|
||||
validateNotifyTemplateExists(updateReqVO.getId());
|
||||
// 校验站内信编码是否重复
|
||||
checkNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
validateNotifyTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
|
||||
// 更新
|
||||
NotifyTemplateDO updateObj = NotifyTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||
@ -136,7 +136,7 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkNotifyTemplateCodeDuplicate(Long id, String code) {
|
||||
public void validateNotifyTemplateCodeDuplicate(Long id, String code) {
|
||||
NotifyTemplateDO template = notifyTemplateMapper.selectByCode(code);
|
||||
if (template == null) {
|
||||
return;
|
||||
|
@ -105,11 +105,11 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
@Override
|
||||
public Long createSmsTemplate(SmsTemplateCreateReqVO createReqVO) {
|
||||
// 校验短信渠道
|
||||
SmsChannelDO channelDO = checkSmsChannel(createReqVO.getChannelId());
|
||||
SmsChannelDO channelDO = validateSmsChannel(createReqVO.getChannelId());
|
||||
// 校验短信编码是否重复
|
||||
checkSmsTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
validateSmsTemplateCodeDuplicate(null, createReqVO.getCode());
|
||||
// 校验短信模板
|
||||
checkApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId());
|
||||
validateApiTemplate(createReqVO.getChannelId(), createReqVO.getApiTemplateId());
|
||||
|
||||
// 插入
|
||||
SmsTemplateDO template = SmsTemplateConvert.INSTANCE.convert(createReqVO);
|
||||
@ -127,11 +127,11 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
// 校验存在
|
||||
validateSmsTemplateExists(updateReqVO.getId());
|
||||
// 校验短信渠道
|
||||
SmsChannelDO channelDO = checkSmsChannel(updateReqVO.getChannelId());
|
||||
SmsChannelDO channelDO = validateSmsChannel(updateReqVO.getChannelId());
|
||||
// 校验短信编码是否重复
|
||||
checkSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
validateSmsTemplateCodeDuplicate(updateReqVO.getId(), updateReqVO.getCode());
|
||||
// 校验短信模板
|
||||
checkApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId());
|
||||
validateApiTemplate(updateReqVO.getChannelId(), updateReqVO.getApiTemplateId());
|
||||
|
||||
// 更新
|
||||
SmsTemplateDO updateObj = SmsTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||
@ -184,7 +184,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SmsChannelDO checkSmsChannel(Long channelId) {
|
||||
public SmsChannelDO validateSmsChannel(Long channelId) {
|
||||
SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId);
|
||||
if (channelDO == null) {
|
||||
throw exception(SMS_CHANNEL_NOT_EXISTS);
|
||||
@ -196,7 +196,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkSmsTemplateCodeDuplicate(Long id, String code) {
|
||||
public void validateSmsTemplateCodeDuplicate(Long id, String code) {
|
||||
SmsTemplateDO template = smsTemplateMapper.selectByCode(code);
|
||||
if (template == null) {
|
||||
return;
|
||||
@ -217,7 +217,7 @@ public class SmsTemplateServiceImpl implements SmsTemplateService {
|
||||
* @param apiTemplateId API 模板编号
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void checkApiTemplate(Long channelId, String apiTemplateId) {
|
||||
public void validateApiTemplate(Long channelId, String apiTemplateId) {
|
||||
// 获得短信模板
|
||||
SmsClient smsClient = smsClientFactory.getSmsClient(channelId);
|
||||
Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", channelId));
|
||||
|
@ -279,7 +279,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckSmsChannel_success() {
|
||||
public void testValidateSmsChannel_success() {
|
||||
// 准备参数
|
||||
Long channelId = randomLongId();
|
||||
// mock 方法
|
||||
@ -290,23 +290,23 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
when(smsChannelService.getSmsChannel(eq(channelId))).thenReturn(channelDO);
|
||||
|
||||
// 调用
|
||||
SmsChannelDO returnChannelDO = smsTemplateService.checkSmsChannel(channelId);
|
||||
SmsChannelDO returnChannelDO = smsTemplateService.validateSmsChannel(channelId);
|
||||
// 断言
|
||||
assertPojoEquals(returnChannelDO, channelDO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckSmsChannel_notExists() {
|
||||
public void testValidateSmsChannel_notExists() {
|
||||
// 准备参数
|
||||
Long channelId = randomLongId();
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> smsTemplateService.checkSmsChannel(channelId),
|
||||
assertServiceException(() -> smsTemplateService.validateSmsChannel(channelId),
|
||||
SMS_CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckSmsChannel_disable() {
|
||||
public void testValidateSmsChannel_disable() {
|
||||
// 准备参数
|
||||
Long channelId = randomLongId();
|
||||
// mock 方法
|
||||
@ -317,30 +317,30 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
when(smsChannelService.getSmsChannel(eq(channelId))).thenReturn(channelDO);
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> smsTemplateService.checkSmsChannel(channelId),
|
||||
assertServiceException(() -> smsTemplateService.validateSmsChannel(channelId),
|
||||
SMS_CHANNEL_DISABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDictDataValueUnique_success() {
|
||||
public void testValidateDictDataValueUnique_success() {
|
||||
// 调用,成功
|
||||
smsTemplateService.checkSmsTemplateCodeDuplicate(randomLongId(), randomString());
|
||||
smsTemplateService.validateSmsTemplateCodeDuplicate(randomLongId(), randomString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckSmsTemplateCodeDuplicate_valueDuplicateForCreate() {
|
||||
public void testValidateSmsTemplateCodeDuplicate_valueDuplicateForCreate() {
|
||||
// 准备参数
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
smsTemplateMapper.insert(randomSmsTemplateDO(o -> o.setCode(code)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> smsTemplateService.checkSmsTemplateCodeDuplicate(null, code),
|
||||
assertServiceException(() -> smsTemplateService.validateSmsTemplateCodeDuplicate(null, code),
|
||||
SMS_TEMPLATE_CODE_DUPLICATE, code);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDictDataValueUnique_valueDuplicateForUpdate() {
|
||||
public void testValidateDictDataValueUnique_valueDuplicateForUpdate() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
String code = randomString();
|
||||
@ -348,7 +348,7 @@ public class SmsTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
smsTemplateMapper.insert(randomSmsTemplateDO(o -> o.setCode(code)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> smsTemplateService.checkSmsTemplateCodeDuplicate(id, code),
|
||||
assertServiceException(() -> smsTemplateService.validateSmsTemplateCodeDuplicate(id, code),
|
||||
SMS_TEMPLATE_CODE_DUPLICATE, code);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user