Showing
2 changed files
with
71 additions
and
5 deletions
... | ... | @@ -10,9 +10,12 @@ import org.springframework.web.bind.annotation.*; |
10 | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
13 | 15 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationActDTO; |
14 | 16 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationDatasourceDTO; |
15 | 17 | import org.thingsboard.server.common.data.yunteng.dto.ConfigurationEventDTO; |
18 | +import org.thingsboard.server.common.data.yunteng.dto.ConfigurationNodeDTO; | |
16 | 19 | import org.thingsboard.server.controller.BaseController; |
17 | 20 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationActService; |
18 | 21 | import org.thingsboard.server.dao.yunteng.service.YtConfigurationDatasourceService; |
... | ... | @@ -21,6 +24,7 @@ import org.thingsboard.server.dao.yunteng.service.YtConfigurationEventService; |
21 | 24 | import java.util.HashMap; |
22 | 25 | import java.util.List; |
23 | 26 | import java.util.Map; |
27 | +import java.util.Optional; | |
24 | 28 | |
25 | 29 | /** |
26 | 30 | * @author Administrator |
... | ... | @@ -35,6 +39,39 @@ public class YtConfigurationNodeController extends BaseController { |
35 | 39 | private final YtConfigurationEventService eventService; |
36 | 40 | private final YtConfigurationActService actService; |
37 | 41 | |
42 | + @PostMapping | |
43 | + @ApiOperation("编辑节点信息") | |
44 | + public ResponseEntity<ConfigurationNodeDTO> saveNode( | |
45 | + @Validated({AddGroup.class}) @RequestBody ConfigurationNodeDTO nodeDTO) | |
46 | + throws ThingsboardException { | |
47 | + String tenantId = getCurrentUser().getCurrentTenantId(); | |
48 | + Optional.ofNullable(nodeDTO.getDataSources()).ifPresent(datas ->{ | |
49 | + datas.forEach(one -> { | |
50 | + if(!one.getTenantId().equals(tenantId)){ | |
51 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | |
52 | + } | |
53 | + datasourceService.saveConfigurationDatasource(one); | |
54 | + }); | |
55 | + }); | |
56 | + Optional.ofNullable(nodeDTO.getEvent()).ifPresent(datas ->{ | |
57 | + datas.forEach(one -> { | |
58 | + if(!one.getTenantId().equals(tenantId)){ | |
59 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | |
60 | + } | |
61 | + eventService.saveConfigurationEvent(one); | |
62 | + }); | |
63 | + }); | |
64 | + Optional.ofNullable(nodeDTO.getAct()).ifPresent(datas ->{ | |
65 | + datas.forEach(one -> { | |
66 | + if(!one.getTenantId().equals(tenantId)){ | |
67 | + throw new YtDataValidationException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | |
68 | + } | |
69 | + actService.saveConfigurationAct(one); | |
70 | + }); | |
71 | + }); | |
72 | + return ResponseEntity.ok(nodeDTO); | |
73 | + } | |
74 | + | |
38 | 75 | @PostMapping("datascource") |
39 | 76 | @ApiOperation("编辑数据源") |
40 | 77 | public ResponseEntity<ConfigurationDatasourceDTO> saveDatascource( |
... | ... | @@ -92,7 +129,7 @@ public class YtConfigurationNodeController extends BaseController { |
92 | 129 | |
93 | 130 | @GetMapping("/{levelType}/{levelId}") |
94 | 131 | @ApiOperation("组件信息") |
95 | - public ResponseEntity<Map<String, List>> nodeInform( | |
132 | + public ResponseEntity<ConfigurationNodeDTO> nodeInform( | |
96 | 133 | @ApiParam(value = "组态资源类型,例如:CONFIGURE、CONTENT、NODE", required = true, defaultValue = "NODE") @PathVariable("levelType") String levelType, |
97 | 134 | @ApiParam(value = "组态资源ID", required = true) @PathVariable("levelId") String levelId) throws ThingsboardException { |
98 | 135 | String tenantId = getCurrentUser().getCurrentTenantId(); |
... | ... | @@ -100,15 +137,15 @@ public class YtConfigurationNodeController extends BaseController { |
100 | 137 | List<ConfigurationDatasourceDTO> sources = datasourceService.listConfigurationDatasource(tenantId, levelType, levelId); |
101 | 138 | List<ConfigurationEventDTO> events = eventService.listConfigurationEvent(tenantId, levelType, levelId); |
102 | 139 | List<ConfigurationActDTO> acts = actService.listConfigurationAct(tenantId, levelType, levelId); |
103 | - Map<String, List> result = new HashMap<>(); | |
140 | + ConfigurationNodeDTO result = new ConfigurationNodeDTO(); | |
104 | 141 | if (sources != null && sources.size() > 0) { |
105 | - result.put("dataSources", sources); | |
142 | + result.setDataSources(sources); | |
106 | 143 | } |
107 | 144 | if (events != null && events.size() > 0) { |
108 | - result.put("event", events); | |
145 | + result.setEvent(events); | |
109 | 146 | } |
110 | 147 | if (acts != null && acts.size() > 0) { |
111 | - result.put("act", acts); | |
148 | + result.setAct(acts); | |
112 | 149 | } |
113 | 150 | return ResponseEntity.ok(result); |
114 | 151 | } | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/ConfigurationNodeDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
8 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.ActTypeEnum; | |
10 | + | |
11 | +import javax.validation.constraints.NotEmpty; | |
12 | +import java.util.List; | |
13 | + | |
14 | +/** | |
15 | + * 组态节点动画效果 | |
16 | + * @author Administrator | |
17 | + */ | |
18 | +@EqualsAndHashCode(callSuper = true) | |
19 | +@Data | |
20 | +public class ConfigurationNodeDTO extends TenantDTO { | |
21 | + @ApiModelProperty(value = "数据源") | |
22 | + private List<ConfigurationDatasourceDTO> dataSources; | |
23 | + | |
24 | + @ApiModelProperty(value = "事件集合") | |
25 | + private List<ConfigurationEventDTO> event; | |
26 | + | |
27 | + @ApiModelProperty(value = "动画集合") | |
28 | + private List<ConfigurationActDTO> act; | |
29 | +} | ... | ... |