Commit 34f132f1a059e43e5912bc0d15b5bdbbdfcdc7d9
1 parent
4dea45d3
fix: delete dataBoard and dataComponent bug
Showing
4 changed files
with
63 additions
and
18 deletions
... | ... | @@ -25,6 +25,7 @@ import org.thingsboard.server.controller.BaseController; |
25 | 25 | import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; |
26 | 26 | import org.thingsboard.server.dao.yunteng.service.YtDataComponentService; |
27 | 27 | |
28 | +import java.util.ArrayList; | |
28 | 29 | import java.util.List; |
29 | 30 | |
30 | 31 | @RestController |
... | ... | @@ -129,6 +130,18 @@ public class YtDataComponentController extends BaseController { |
129 | 130 | ? Math.max(dataBoardDTO.getComponentNum() - deleteNum, zero) |
130 | 131 | : zero; |
131 | 132 | ytDataBoardService.updateDataBoardComponentNum(dataBoardId, tenantId, count); |
133 | + // 更新dataBoard的layout信息 | |
134 | + DataBoardDTO dto = ytDataBoardService.findDataBoardInfoById(dataBoardId, tenantId); | |
135 | + List<ComponentLayoutDTO> layoutResult = new ArrayList<>(); | |
136 | + for (ComponentLayoutDTO componentLayout : dto.getLayout()) { | |
137 | + for (String id : deleteDTO.getIds()) { | |
138 | + if (!componentLayout.getId().equals(id)) { | |
139 | + layoutResult.add(componentLayout); | |
140 | + } | |
141 | + } | |
142 | + } | |
143 | + dto.setLayout(layoutResult); | |
144 | + ytDataBoardService.saveOrUpdateDataBoard(dto); | |
132 | 145 | } |
133 | 146 | return ResponseResult.success(result); |
134 | 147 | } | ... | ... |
... | ... | @@ -10,10 +10,7 @@ import org.springframework.transaction.annotation.Transactional; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
13 | -import org.thingsboard.server.common.data.yunteng.dto.BaseDTO; | |
14 | -import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | |
15 | -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
16 | -import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.*; | |
17 | 14 | import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; |
18 | 15 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
19 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
... | ... | @@ -23,6 +20,7 @@ import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; |
23 | 20 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
24 | 21 | import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; |
25 | 22 | import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; |
23 | +import org.thingsboard.server.dao.yunteng.service.YtDataComponentService; | |
26 | 24 | |
27 | 25 | import java.util.*; |
28 | 26 | import java.util.stream.Collectors; |
... | ... | @@ -33,6 +31,7 @@ public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
33 | 31 | implements YtDataBoardService { |
34 | 32 | private final OrganizationMapper organizationMapper; |
35 | 33 | private final UserOrganizationMappingService userOrganizationMappingService; |
34 | + private final YtDataComponentService ytDataComponentService; | |
36 | 35 | |
37 | 36 | @Override |
38 | 37 | public YtPageData<DataBoardDTO> dataBoardPage(Map<String, Object> queryMap, boolean tenantAdmin) { |
... | ... | @@ -89,6 +88,9 @@ public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
89 | 88 | e.printStackTrace(); |
90 | 89 | } |
91 | 90 | } else { |
91 | + if (null != dataBoardDTO.getLayout() && !dataBoardDTO.getLayout().isEmpty()) { | |
92 | + dataBoard.setLayout(JacksonUtil.convertValue(dataBoardDTO.getLayout(), JsonNode.class)); | |
93 | + } | |
92 | 94 | DataBoard board = |
93 | 95 | baseMapper.selectOne( |
94 | 96 | new LambdaQueryWrapper<DataBoard>() |
... | ... | @@ -107,6 +109,12 @@ public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
107 | 109 | @Override |
108 | 110 | @Transactional |
109 | 111 | public boolean deleteDataBoard(DeleteDTO deleteDTO) { |
112 | + List<DataComponentDTO> dataComponentDTOList = | |
113 | + ytDataComponentService.findDataComponentsByDataBoardIds( | |
114 | + deleteDTO.getTenantId(), deleteDTO.getIds()); | |
115 | + if (null != dataComponentDTOList && !dataComponentDTOList.isEmpty()) { | |
116 | + throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage()); | |
117 | + } | |
110 | 118 | return baseMapper.delete( |
111 | 119 | new LambdaQueryWrapper<DataBoard>() |
112 | 120 | .eq(DataBoard::getTenantId, deleteDTO.getTenantId()) | ... | ... |
... | ... | @@ -19,6 +19,7 @@ import org.thingsboard.server.dao.yunteng.service.YtDataComponentService; |
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.List; |
21 | 21 | import java.util.Optional; |
22 | +import java.util.Set; | |
22 | 23 | import java.util.stream.Collectors; |
23 | 24 | |
24 | 25 | @Service |
... | ... | @@ -36,18 +37,7 @@ public class YtDataComponentServiceImpl |
36 | 37 | return null; |
37 | 38 | } |
38 | 39 | return dataComponentList.stream() |
39 | - .map( | |
40 | - obj -> { | |
41 | - DataComponentDTO dto = obj.getDTO(DataComponentDTO.class); | |
42 | - List<DataSourceInfoDTO> list = new ArrayList<>(); | |
43 | - if (null != obj.getDataSource() && obj.getDataSource().isArray()) { | |
44 | - for (JsonNode jsonNode : obj.getDataSource()) { | |
45 | - list.add(JacksonUtil.convertValue(jsonNode, DataSourceInfoDTO.class)); | |
46 | - } | |
47 | - } | |
48 | - dto.setDataSource(list); | |
49 | - return dto; | |
50 | - }) | |
40 | + .map(this::getDataSourceByJsonNode) | |
51 | 41 | .collect(Collectors.toList()); |
52 | 42 | } |
53 | 43 | |
... | ... | @@ -81,8 +71,33 @@ public class YtDataComponentServiceImpl |
81 | 71 | @Transactional |
82 | 72 | public int deleteDataComponent(DeleteDTO deleteDTO) { |
83 | 73 | return baseMapper.delete( |
74 | + new LambdaQueryWrapper<DataComponent>() | |
75 | + .eq(DataComponent::getTenantId, deleteDTO.getTenantId()) | |
76 | + .in(DataComponent::getId, deleteDTO.getIds())); | |
77 | + } | |
78 | + | |
79 | + @Override | |
80 | + public List<DataComponentDTO> findDataComponentsByDataBoardIds( | |
81 | + String tenantId, Set<String> dataBoardIds) { | |
82 | + List<DataComponent> dataComponents = | |
83 | + baseMapper.selectList( | |
84 | 84 | new LambdaQueryWrapper<DataComponent>() |
85 | - .eq(DataComponent::getTenantId, deleteDTO.getTenantId()) | |
86 | - .in(DataComponent::getId, deleteDTO.getIds())); | |
85 | + .eq(DataComponent::getTenantId, tenantId) | |
86 | + .in(DataComponent::getDataBoardId, dataBoardIds)); | |
87 | + return Optional.ofNullable(dataComponents) | |
88 | + .map(obj -> obj.stream().map(this::getDataSourceByJsonNode).collect(Collectors.toList())) | |
89 | + .orElse(null); | |
90 | + } | |
91 | + | |
92 | + private DataComponentDTO getDataSourceByJsonNode(DataComponent obj) { | |
93 | + DataComponentDTO dto = obj.getDTO(DataComponentDTO.class); | |
94 | + List<DataSourceInfoDTO> list = new ArrayList<>(); | |
95 | + if (null != obj.getDataSource() && obj.getDataSource().isArray()) { | |
96 | + for (JsonNode jsonNode : obj.getDataSource()) { | |
97 | + list.add(JacksonUtil.convertValue(jsonNode, DataSourceInfoDTO.class)); | |
98 | + } | |
99 | + } | |
100 | + dto.setDataSource(list); | |
101 | + return dto; | |
87 | 102 | } |
88 | 103 | } | ... | ... |
... | ... | @@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; |
4 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
5 | 5 | |
6 | 6 | import java.util.List; |
7 | +import java.util.Set; | |
7 | 8 | |
8 | 9 | public interface YtDataComponentService { |
9 | 10 | /** |
... | ... | @@ -27,4 +28,12 @@ public interface YtDataComponentService { |
27 | 28 | * @param deleteDTO 删除IDS |
28 | 29 | */ |
29 | 30 | int deleteDataComponent(DeleteDTO deleteDTO); |
31 | + | |
32 | + /** | |
33 | + * 查询数据看板下面是否还有组件 | |
34 | + * @param tenantId 租户ID | |
35 | + * @param dataBoardIds 数据看板IDS | |
36 | + * @return 组件信息 | |
37 | + */ | |
38 | + List<DataComponentDTO> findDataComponentsByDataBoardIds(String tenantId, Set<String> dataBoardIds); | |
30 | 39 | } | ... | ... |