Commit 037e3427628d101caca090e7a8f834a27b056db1
1 parent
0bcfe92b
feat: add component layout to data board detail
Showing
4 changed files
with
48 additions
and
13 deletions
... | ... | @@ -17,6 +17,8 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; |
19 | 19 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
20 | +import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; | |
21 | +import org.thingsboard.server.common.data.yunteng.dto.board.MoreDataComponentInfoDTO; | |
20 | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
21 | 23 | import org.thingsboard.server.controller.BaseController; |
22 | 24 | import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; |
... | ... | @@ -35,12 +37,16 @@ public class YtDataComponentController extends BaseController { |
35 | 37 | |
36 | 38 | @GetMapping("/{boardId}") |
37 | 39 | @ApiOperation(value = "查询看板下的所有组件信息") |
38 | - public ResponseResult<List<DataComponentDTO>> getDataComponentsByBoardId( | |
40 | + public ResponseResult<MoreDataComponentInfoDTO> getDataComponentsByBoardId( | |
39 | 41 | @PathVariable("boardId") String boardId) throws ThingsboardException { |
40 | - checkDataBoardInfo(boardId); | |
41 | - return ResponseResult.success( | |
42 | + DataBoardDTO dataBoardDTO = checkDataBoardInfo(boardId); | |
43 | + MoreDataComponentInfoDTO moreDataComponentInfoDTO = new MoreDataComponentInfoDTO(); | |
44 | + List<DataComponentDTO> data = | |
42 | 45 | ytDataComponentService.getDataComponentsByBoardId( |
43 | - getCurrentUser().getCurrentTenantId(), boardId)); | |
46 | + getCurrentUser().getCurrentTenantId(), boardId); | |
47 | + moreDataComponentInfoDTO.setComponentLayout(dataBoardDTO.getLayout()); | |
48 | + moreDataComponentInfoDTO.setComponentData(data); | |
49 | + return ResponseResult.success(moreDataComponentInfoDTO); | |
44 | 50 | } |
45 | 51 | |
46 | 52 | @PostMapping("/{boardId}/add") |
... | ... | @@ -87,11 +93,12 @@ public class YtDataComponentController extends BaseController { |
87 | 93 | return ResponseResult.success(ytDataComponentService.saveOrUpdateDataBoard(dataComponent)); |
88 | 94 | } |
89 | 95 | |
90 | - private void checkDataBoardInfo(String boardId) throws ThingsboardException { | |
96 | + private DataBoardDTO checkDataBoardInfo(String boardId) throws ThingsboardException { | |
91 | 97 | DataBoardDTO dto = |
92 | 98 | ytDataBoardService.findDataBoardInfoById(boardId, getCurrentUser().getCurrentTenantId()); |
93 | 99 | if (null == dto) { |
94 | 100 | throw new YtDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); |
95 | 101 | } |
102 | + return dto; | |
96 | 103 | } |
97 | 104 | } | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto.board; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | +import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; | |
6 | + | |
7 | +import java.io.Serializable; | |
8 | +import java.util.List; | |
9 | + | |
10 | +@Data | |
11 | +public class MoreDataComponentInfoDTO implements Serializable { | |
12 | + | |
13 | + private static final long serialVersionUID = 5702474912490319623L; | |
14 | + | |
15 | + @ApiModelProperty("组件数据信息") | |
16 | + private List<DataComponentDTO> componentData; | |
17 | + | |
18 | + @ApiModelProperty("组件布局信息") | |
19 | + private List<ComponentLayoutDTO> componentLayout; | |
20 | +} | ... | ... |
... | ... | @@ -12,7 +12,6 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
14 | 14 | import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; |
15 | -import org.thingsboard.server.common.data.yunteng.enums.ViewType; | |
16 | 15 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
17 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
18 | 17 | import org.thingsboard.server.dao.yunteng.entities.DataBoard; |
... | ... | @@ -20,6 +19,7 @@ import org.thingsboard.server.dao.yunteng.mapper.DataBoardMapper; |
20 | 19 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | 20 | import org.thingsboard.server.dao.yunteng.service.YtDataBoardService; |
22 | 21 | |
22 | +import java.util.ArrayList; | |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Map; |
25 | 25 | import java.util.Optional; |
... | ... | @@ -66,9 +66,6 @@ public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
66 | 66 | throw new YtDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage()); |
67 | 67 | }); |
68 | 68 | } |
69 | - // 公有视图,生成访问路径 | |
70 | - if (dataBoard.getViewType() == ViewType.PUBLIC_VIEW) {} | |
71 | - | |
72 | 69 | return dataBoard.getDTO(DataBoardDTO.class); |
73 | 70 | } |
74 | 71 | |
... | ... | @@ -111,7 +108,18 @@ public class YtDataBoardServiceImpl extends AbstractBaseService<DataBoardMapper, |
111 | 108 | new LambdaQueryWrapper<DataBoard>() |
112 | 109 | .eq(DataBoard::getTenantId, tenantId) |
113 | 110 | .eq(DataBoard::getId, id))) |
114 | - .map(obj -> obj.getDTO(DataBoardDTO.class)) | |
111 | + .map( | |
112 | + obj -> { | |
113 | + DataBoardDTO returnBoard = obj.getDTO(DataBoardDTO.class); | |
114 | + List<ComponentLayoutDTO> layout = new ArrayList<>(); | |
115 | + if (obj.getLayout().isArray()) { | |
116 | + for (JsonNode jsonNode : obj.getLayout()) { | |
117 | + layout.add(JacksonUtil.convertValue(jsonNode, ComponentLayoutDTO.class)); | |
118 | + } | |
119 | + } | |
120 | + returnBoard.setLayout(layout); | |
121 | + return returnBoard; | |
122 | + }) | |
115 | 123 | .orElse(null); |
116 | 124 | } |
117 | 125 | } | ... | ... |
... | ... | @@ -42,9 +42,9 @@ public interface YtDataBoardService { |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * 根据租户ID和看板ID查询看板信息 |
45 | - * @param id | |
46 | - * @param tenantId | |
47 | - * @return | |
45 | + * @param id 看板ID | |
46 | + * @param tenantId 租户ID | |
47 | + * @return 看板信息 | |
48 | 48 | */ |
49 | 49 | DataBoardDTO findDataBoardInfoById(String id,String tenantId); |
50 | 50 | } | ... | ... |