Commit 4ea44c51badcde7675101a47349d9c7a125b19dc
1 parent
05d1ad5f
feat: fix add dataComponent default layout to dataBoard
Showing
5 changed files
with
46 additions
and
13 deletions
@@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | @@ -17,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
17 | import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; | 17 | import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO; |
18 | import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; | 18 | import org.thingsboard.server.common.data.yunteng.dto.DataComponentDTO; |
19 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | 19 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
20 | +import org.thingsboard.server.common.data.yunteng.dto.board.ComponentLayoutDTO; | ||
20 | import org.thingsboard.server.common.data.yunteng.dto.board.MoreDataComponentInfoDTO; | 21 | import org.thingsboard.server.common.data.yunteng.dto.board.MoreDataComponentInfoDTO; |
21 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
22 | import org.thingsboard.server.controller.BaseController; | 23 | import org.thingsboard.server.controller.BaseController; |
@@ -57,10 +58,17 @@ public class YtDataComponentController extends BaseController { | @@ -57,10 +58,17 @@ public class YtDataComponentController extends BaseController { | ||
57 | if (StringUtils.isNotEmpty(dataComponent.getId())) { | 58 | if (StringUtils.isNotEmpty(dataComponent.getId())) { |
58 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 59 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
59 | } | 60 | } |
61 | + String tenantId = getCurrentUser().getCurrentTenantId(); | ||
60 | checkDataBoardInfo(boardId); | 62 | checkDataBoardInfo(boardId); |
61 | - dataComponent.setTenantId(getCurrentUser().getCurrentTenantId()); | 63 | + dataComponent.setTenantId(tenantId); |
62 | dataComponent.setDataBoardId(boardId); | 64 | dataComponent.setDataBoardId(boardId); |
63 | - return saveOrUpdate(dataComponent); | 65 | + DataBoardDTO dataBoardDTO = ytDataBoardService.findDataBoardInfoById(boardId, tenantId); |
66 | + List<ComponentLayoutDTO> listLayout = dataBoardDTO.getLayout(); | ||
67 | + ResponseResult<DataComponentDTO> result = saveOrUpdate(dataComponent); | ||
68 | + ComponentLayoutDTO defaultLayout = new ComponentLayoutDTO(result.getData().getId()); | ||
69 | + listLayout.add(defaultLayout); | ||
70 | + ytDataBoardService.saveComponentLayout(listLayout, boardId, tenantId); | ||
71 | + return result; | ||
64 | } | 72 | } |
65 | 73 | ||
66 | @PostMapping("/{boardId}/update") | 74 | @PostMapping("/{boardId}/update") |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/board/ComponentInfoDTO.java
@@ -25,14 +25,4 @@ public class ComponentInfoDTO implements Serializable { | @@ -25,14 +25,4 @@ public class ComponentInfoDTO implements Serializable { | ||
25 | 25 | ||
26 | @ApiModelProperty(value = "梯度信息") | 26 | @ApiModelProperty(value = "梯度信息") |
27 | private List<GradientInfo> gradientInfo; | 27 | private List<GradientInfo> gradientInfo; |
28 | - | ||
29 | - @Data | ||
30 | - class GradientInfo { | ||
31 | - | ||
32 | - @ApiModelProperty(value = "梯度key") | ||
33 | - private String key; | ||
34 | - | ||
35 | - @ApiModelProperty(value = "梯度值") | ||
36 | - private Integer value; | ||
37 | - } | ||
38 | } | 28 | } |
@@ -24,4 +24,14 @@ public class ComponentLayoutDTO implements Serializable { | @@ -24,4 +24,14 @@ public class ComponentLayoutDTO implements Serializable { | ||
24 | 24 | ||
25 | @ApiModelProperty(value = "高度", required = true) | 25 | @ApiModelProperty(value = "高度", required = true) |
26 | private Integer h; | 26 | private Integer h; |
27 | + | ||
28 | + public ComponentLayoutDTO() {} | ||
29 | + | ||
30 | + public ComponentLayoutDTO(String id) { | ||
31 | + this.id = id; | ||
32 | + this.x = 0; | ||
33 | + this.y = 0; | ||
34 | + this.w = 6; | ||
35 | + this.h = 6; | ||
36 | + } | ||
27 | } | 37 | } |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/board/GradientInfo.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto.board; | ||
2 | + | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +import java.io.Serializable; | ||
7 | + | ||
8 | +@Data | ||
9 | +public class GradientInfo implements Serializable { | ||
10 | + | ||
11 | + private static final long serialVersionUID = -4991589470363935653L; | ||
12 | + | ||
13 | + @ApiModelProperty(value = "梯度颜色") | ||
14 | + private String color; | ||
15 | + | ||
16 | + @ApiModelProperty(value = "梯度key") | ||
17 | + private String key; | ||
18 | + | ||
19 | + @ApiModelProperty(value = "梯度值") | ||
20 | + private Integer value; | ||
21 | +} |
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | import com.fasterxml.jackson.databind.JsonNode; | 4 | import com.fasterxml.jackson.databind.JsonNode; |
5 | import org.apache.commons.lang3.StringUtils; | 5 | import org.apache.commons.lang3.StringUtils; |
6 | import org.springframework.stereotype.Service; | 6 | import org.springframework.stereotype.Service; |
7 | +import org.springframework.transaction.annotation.Transactional; | ||
7 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | 8 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
8 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 9 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
9 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 10 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
@@ -52,12 +53,14 @@ public class YtDataComponentServiceImpl | @@ -52,12 +53,14 @@ public class YtDataComponentServiceImpl | ||
52 | } | 53 | } |
53 | 54 | ||
54 | @Override | 55 | @Override |
56 | + @Transactional | ||
55 | public DataComponentDTO saveOrUpdateDataBoard(DataComponentDTO dataComponentDTO) { | 57 | public DataComponentDTO saveOrUpdateDataBoard(DataComponentDTO dataComponentDTO) { |
56 | DataComponent dataComponent = dataComponentDTO.getEntity(DataComponent.class); | 58 | DataComponent dataComponent = dataComponentDTO.getEntity(DataComponent.class); |
57 | dataComponent.setDataSource( | 59 | dataComponent.setDataSource( |
58 | JacksonUtil.convertValue(dataComponentDTO.getDataSource(), JsonNode.class)); | 60 | JacksonUtil.convertValue(dataComponentDTO.getDataSource(), JsonNode.class)); |
59 | if (StringUtils.isEmpty(dataComponentDTO.getId())) { | 61 | if (StringUtils.isEmpty(dataComponentDTO.getId())) { |
60 | baseMapper.insert(dataComponent); | 62 | baseMapper.insert(dataComponent); |
63 | + dataComponentDTO.setId(dataComponent.getId()); | ||
61 | } else { | 64 | } else { |
62 | DataComponent queryEntity = | 65 | DataComponent queryEntity = |
63 | baseMapper.selectOne( | 66 | baseMapper.selectOne( |
@@ -72,10 +75,11 @@ public class YtDataComponentServiceImpl | @@ -72,10 +75,11 @@ public class YtDataComponentServiceImpl | ||
72 | ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | 75 | ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); |
73 | }); | 76 | }); |
74 | } | 77 | } |
75 | - return dataComponent.getDTO(DataComponentDTO.class); | 78 | + return dataComponentDTO; |
76 | } | 79 | } |
77 | 80 | ||
78 | @Override | 81 | @Override |
82 | + @Transactional | ||
79 | public boolean deleteDataComponent(DeleteDTO deleteDTO) { | 83 | public boolean deleteDataComponent(DeleteDTO deleteDTO) { |
80 | return baseMapper.delete( | 84 | return baseMapper.delete( |
81 | new LambdaQueryWrapper<DataComponent>() | 85 | new LambdaQueryWrapper<DataComponent>() |