Commit 14323d91c45491cfbc753bf22a30e12d2ae65d65
1 parent
406f0784
refactor(DEFECT-1009): 消息配置被使用时,不能删除
Showing
2 changed files
with
17 additions
and
2 deletions
... | ... | @@ -108,7 +108,8 @@ public enum ErrorMessage { |
108 | 108 | HIKVISION_API_ERROR(400084,"海康威视视频预览API调用失败【%s】,错误码【%s】"), |
109 | 109 | RESET_PASSWORD_SUCCESS(400085,"重置成功,请使用默认密码登录"), |
110 | 110 | HAVE_NO_PERMISSION(500002,"没有修改权限"), |
111 | - NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"); | |
111 | + NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"), | |
112 | + MESSAGE_TEMPLATE_USING_CONFIG(500003,"消息模板【%s】正在使用消息配置。"); | |
112 | 113 | private final int code; |
113 | 114 | private String message; |
114 | 115 | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
3 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
4 | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 6 | import java.util.List; |
6 | 7 | import java.util.Map; |
7 | 8 | import java.util.Set; |
9 | +import java.util.stream.Collectors; | |
10 | + | |
8 | 11 | import lombok.RequiredArgsConstructor; |
9 | 12 | import lombok.extern.slf4j.Slf4j; |
10 | 13 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -18,9 +21,13 @@ import org.thingsboard.server.common.data.yunteng.dto.MessageConfigDTO; |
18 | 21 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
19 | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
20 | 23 | import org.thingsboard.server.dao.yunteng.entities.TkMessageConfigEntity; |
24 | +import org.thingsboard.server.dao.yunteng.entities.TkMessageTemplateEntity; | |
21 | 25 | import org.thingsboard.server.dao.yunteng.mapper.MessageConfigMapper; |
26 | +import org.thingsboard.server.dao.yunteng.mapper.MessageTemplateMapper; | |
22 | 27 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
23 | 28 | import org.thingsboard.server.dao.yunteng.service.TkMessageConfigService; |
29 | +import org.thingsboard.server.dao.yunteng.service.TkMessageTemplateService; | |
30 | +import org.thingsboard.server.dao.yunteng.service.TkUserService; | |
24 | 31 | |
25 | 32 | @Service |
26 | 33 | @Slf4j |
... | ... | @@ -28,7 +35,7 @@ import org.thingsboard.server.dao.yunteng.service.TkMessageConfigService; |
28 | 35 | public class TkMessageConfigServiceImpl |
29 | 36 | extends AbstractBaseService<MessageConfigMapper, TkMessageConfigEntity> |
30 | 37 | implements TkMessageConfigService { |
31 | - | |
38 | + private final MessageTemplateMapper templateMapper; | |
32 | 39 | @Override |
33 | 40 | public TkPageData<MessageConfigDTO> page(String tenantId, Map<String, Object> queryMap) { |
34 | 41 | IPage<TkMessageConfigEntity> configIPage = |
... | ... | @@ -70,6 +77,13 @@ public class TkMessageConfigServiceImpl |
70 | 77 | @Override |
71 | 78 | @Transactional |
72 | 79 | public boolean deleteMessageConfig(Set<String> ids) { |
80 | + LambdaQueryWrapper<TkMessageTemplateEntity> filter = new LambdaQueryWrapper<>(); | |
81 | + filter.in(TkMessageTemplateEntity::getMessageConfigId,ids); | |
82 | + List<TkMessageTemplateEntity> templates = templateMapper.selectList(filter); | |
83 | + if(templates.size()>0){ | |
84 | + String errMsg = String.format(ErrorMessage.MESSAGE_TEMPLATE_USING_CONFIG.getMessage(),templates.stream().map(t->t.getTemplateName()).collect(Collectors.toList())); | |
85 | + throw new TkDataValidationException(errMsg); | |
86 | + } | |
73 | 87 | return baseMapper.deleteBatchIds(ids) > 0; |
74 | 88 | } |
75 | 89 | ... | ... |