...
|
...
|
@@ -12,6 +12,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
12
|
12
|
import org.thingsboard.server.common.data.yunteng.common.AddGroup;
|
13
|
13
|
import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
|
14
|
14
|
import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
|
|
15
|
+import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
15
|
16
|
import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
|
16
|
17
|
import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
|
17
|
18
|
import org.thingsboard.server.common.data.yunteng.dto.DataBoardDTO;
|
...
|
...
|
@@ -28,7 +29,7 @@ import java.util.List; |
28
|
29
|
|
29
|
30
|
@RestController
|
30
|
31
|
@RequiredArgsConstructor
|
31
|
|
-@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
|
|
32
|
+@PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
|
32
|
33
|
@RequestMapping("api/yt/data_component")
|
33
|
34
|
@Api(tags = {"数据组件"})
|
34
|
35
|
public class YtDataComponentController extends BaseController {
|
...
|
...
|
@@ -37,6 +38,8 @@ public class YtDataComponentController extends BaseController { |
37
|
38
|
|
38
|
39
|
@GetMapping("/{boardId}")
|
39
|
40
|
@ApiOperation(value = "查询看板下的所有组件信息")
|
|
41
|
+ @PreAuthorize(
|
|
42
|
+ "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_component:list'})")
|
40
|
43
|
public ResponseResult<MoreDataComponentInfoDTO> getDataComponentsByBoardId(
|
41
|
44
|
@PathVariable("boardId") String boardId) throws ThingsboardException {
|
42
|
45
|
DataBoardDTO dataBoardDTO = checkDataBoardInfo(boardId);
|
...
|
...
|
@@ -51,6 +54,8 @@ public class YtDataComponentController extends BaseController { |
51
|
54
|
|
52
|
55
|
@PostMapping("/{boardId}/add")
|
53
|
56
|
@ApiOperation(value = "新增组件")
|
|
57
|
+ @PreAuthorize(
|
|
58
|
+ "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_component:add:post'})")
|
54
|
59
|
public ResponseResult<DataComponentDTO> save(
|
55
|
60
|
@PathVariable("boardId") String boardId,
|
56
|
61
|
@RequestBody @Validated(AddGroup.class) DataComponentDTO dataComponent)
|
...
|
...
|
@@ -73,6 +78,8 @@ public class YtDataComponentController extends BaseController { |
73
|
78
|
|
74
|
79
|
@PostMapping("/{boardId}/update")
|
75
|
80
|
@ApiOperation(value = "编辑组件")
|
|
81
|
+ @PreAuthorize(
|
|
82
|
+ "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_component:update:update'})")
|
76
|
83
|
public ResponseResult<DataComponentDTO> update(
|
77
|
84
|
@PathVariable("boardId") String boardId,
|
78
|
85
|
@RequestBody @Validated(UpdateGroup.class) DataComponentDTO dataComponent)
|
...
|
...
|
@@ -86,12 +93,33 @@ public class YtDataComponentController extends BaseController { |
86
|
93
|
return saveOrUpdate(dataComponent);
|
87
|
94
|
}
|
88
|
95
|
|
89
|
|
- @DeleteMapping
|
|
96
|
+ @DeleteMapping("/{dataBoardId}")
|
90
|
97
|
@ApiOperation(value = "删除数据组件")
|
|
98
|
+ @PreAuthorize(
|
|
99
|
+ "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:data_component:delete'})")
|
91
|
100
|
public ResponseResult<Boolean> deleteDataBoard(
|
92
|
|
- @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException {
|
93
|
|
- deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId());
|
94
|
|
- return ResponseResult.success(ytDataComponentService.deleteDataComponent(deleteDTO));
|
|
101
|
+ @PathVariable("dataBoardId") String dataBoardId,
|
|
102
|
+ @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO)
|
|
103
|
+ throws ThingsboardException {
|
|
104
|
+ String tenantId = getCurrentUser().getCurrentTenantId();
|
|
105
|
+ deleteDTO.setTenantId(tenantId);
|
|
106
|
+ int deleteNum = ytDataComponentService.deleteDataComponent(deleteDTO);
|
|
107
|
+
|
|
108
|
+ int zero = FastIotConstants.MagicNumber.ZERO;
|
|
109
|
+ boolean result = deleteNum > zero;
|
|
110
|
+ if (result) {
|
|
111
|
+ DataBoardDTO dataBoardDTO = ytDataBoardService.findDataBoardInfoById(dataBoardId, tenantId);
|
|
112
|
+ if (null != dataBoardDTO) {
|
|
113
|
+ int count =
|
|
114
|
+ dataBoardDTO.getComponentNum() != null
|
|
115
|
+ ? dataBoardDTO.getComponentNum() - deleteNum < zero
|
|
116
|
+ ? zero
|
|
117
|
+ : dataBoardDTO.getComponentNum() - deleteNum
|
|
118
|
+ : zero;
|
|
119
|
+ ytDataBoardService.updateDataBoardComponentNum(dataBoardId, tenantId, count);
|
|
120
|
+ }
|
|
121
|
+ }
|
|
122
|
+ return ResponseResult.success(result);
|
95
|
123
|
}
|
96
|
124
|
|
97
|
125
|
private ResponseResult<DataComponentDTO> saveOrUpdate(DataComponentDTO dataComponent)
|
...
|
...
|
|