Commit cbeabb15291607daca77687980465eb61c99b90f
1 parent
9d0dcf47
fix(DEFECT-582): 告警配置被占用,提示信息修改
1、细化提示内容
Showing
2 changed files
with
30 additions
and
8 deletions
... | ... | @@ -59,7 +59,7 @@ public enum ErrorMessage { |
59 | 59 | DEVICE_LOSED(400039,"设备相关参数丢失"), |
60 | 60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), |
61 | 61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), |
62 | - SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动正在使用该告警配置"), | |
62 | + SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动【%s】正在使用该告警配置"), | |
63 | 63 | APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"), |
64 | 64 | THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"), |
65 | 65 | DEVICE_NOT_EXTIED(400045,"设备不存在"), | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 6 | import lombok.RequiredArgsConstructor; |
6 | 7 | import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -15,8 +16,10 @@ import org.thingsboard.server.common.data.yunteng.dto.*; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
16 | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
17 | 18 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; |
19 | +import org.thingsboard.server.dao.yunteng.entities.SceneLinkage; | |
18 | 20 | import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; |
19 | 21 | import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; |
22 | +import org.thingsboard.server.dao.yunteng.mapper.SceneLinkageMapper; | |
20 | 23 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | 24 | import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; |
22 | 25 | import org.thingsboard.server.dao.yunteng.service.DoActionService; |
... | ... | @@ -35,6 +38,7 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap |
35 | 38 | private final UserOrganizationMappingServiceImpl userOrganizationMappingService; |
36 | 39 | |
37 | 40 | private final OrganizationMapper ytOrganizationMapper; |
41 | + private final SceneLinkageMapper sceneLinkageMapper; | |
38 | 42 | |
39 | 43 | @Override |
40 | 44 | public YtPageData<AlarmProfileDTO> page( |
... | ... | @@ -74,10 +78,9 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap |
74 | 78 | if (!alarmProfile.getOrganizationId().equals(alarmProfileDTO.getOrganizationId())) { |
75 | 79 | Set<String> profiles = new HashSet<>(); |
76 | 80 | profiles.add(alarmProfileDTO.getId()); |
77 | - List<DoActionDTO> list = | |
78 | - doActionService.findDoActionByAlarmProfileIds(alarmProfileDTO.getTenantId(), profiles); | |
79 | - if (list.size() > FastIotConstants.MagicNumber.ZERO) { | |
80 | - throw new YtDataValidationException(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage()); | |
81 | + Set<String>names = alarmProfileUsed(alarmProfileDTO.getTenantId(), profiles); | |
82 | + if(!names.isEmpty()){ | |
83 | + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names)); | |
81 | 84 | } |
82 | 85 | } |
83 | 86 | baseMapper.updateById(alarmProfileDTO.getEntity(AlarmProfile.class)); |
... | ... | @@ -106,13 +109,32 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap |
106 | 109 | @Override |
107 | 110 | @Transactional |
108 | 111 | public boolean deleteAlarmProFile(DeleteDTO deleteDTO) { |
112 | + Set<String>names = alarmProfileUsed(deleteDTO.getTenantId(), deleteDTO.getIds()); | |
113 | + if(!names.isEmpty()){ | |
114 | + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names)); | |
115 | + } | |
116 | + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | |
117 | + } | |
118 | + | |
119 | + private Set<String> alarmProfileUsed(String tenantId, Set<String> profileIds) { | |
120 | + | |
121 | + Set<String> sceneNames = new HashSet<>(); | |
109 | 122 | // 如果有场景联动使用告警配置,则不能删除 |
110 | 123 | List<DoActionDTO> list = |
111 | - doActionService.findDoActionByAlarmProfileIds(deleteDTO.getTenantId(), deleteDTO.getIds()); | |
124 | + doActionService.findDoActionByAlarmProfileIds(tenantId, profileIds); | |
112 | 125 | if (list.size() > FastIotConstants.MagicNumber.ZERO) { |
113 | - throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage()); | |
126 | + Set<String> sceneIds = new HashSet<>(); | |
127 | + for(DoActionDTO action:list){ | |
128 | + sceneIds.add(action.getSceneLinkageId()); | |
129 | + } | |
130 | + List<SceneLinkage> scenes = sceneLinkageMapper.selectList(new QueryWrapper<SceneLinkage>().lambda() | |
131 | + .eq(SceneLinkage::getId, sceneIds) | |
132 | + ); | |
133 | + for(SceneLinkage item: scenes){ | |
134 | + sceneNames.add(item.getName()); | |
135 | + } | |
114 | 136 | } |
115 | - return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | |
137 | + return sceneNames; | |
116 | 138 | } |
117 | 139 | |
118 | 140 | @Override | ... | ... |