...
|
...
|
@@ -9,6 +9,7 @@ import lombok.Data; |
9
|
9
|
import org.springframework.beans.BeanUtils;
|
10
|
10
|
import org.springframework.http.ResponseEntity;
|
11
|
11
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
12
|
+import org.springframework.util.CollectionUtils;
|
12
|
13
|
import org.springframework.util.StringUtils;
|
13
|
14
|
import org.springframework.web.bind.annotation.*;
|
14
|
15
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
...
|
...
|
@@ -25,13 +26,15 @@ import javax.annotation.Resource; |
25
|
26
|
import java.util.ArrayList;
|
26
|
27
|
import java.util.HashMap;
|
27
|
28
|
import java.util.List;
|
|
29
|
+import java.util.Set;
|
|
30
|
+import java.util.stream.Collectors;
|
28
|
31
|
|
29
|
32
|
import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
|
30
|
33
|
import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE;
|
31
|
34
|
|
32
|
35
|
/**
|
33
|
36
|
* <p>
|
34
|
|
- * 前端控制器
|
|
37
|
+ * 前端控制器
|
35
|
38
|
* </p>
|
36
|
39
|
*
|
37
|
40
|
* @author 黎剑发
|
...
|
...
|
@@ -44,12 +47,13 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
44
|
47
|
public class Tk3dComponentController extends BaseController {
|
45
|
48
|
@Resource
|
46
|
49
|
Tk3dComponentService tk3dComponentService;
|
|
50
|
+
|
47
|
51
|
@GetMapping(path = "/page")
|
48
|
52
|
@ApiOperation(value = "分页")
|
49
|
53
|
public TkPageData<Tk3dComponentDTO> page(
|
50
|
|
- @RequestParam(value ="id", required = false) String id,
|
51
|
|
- @RequestParam(value ="name", required = false) String name,
|
52
|
|
- @RequestParam(value ="state", required = false) Integer state,
|
|
54
|
+ @RequestParam(value = "id", required = false) String id,
|
|
55
|
+ @RequestParam(value = "name", required = false) String name,
|
|
56
|
+ @RequestParam(value = "state", required = false) Integer state,
|
53
|
57
|
@RequestParam(PAGE_SIZE) int pageSize,
|
54
|
58
|
@RequestParam(PAGE) int page,
|
55
|
59
|
@RequestParam(value = ORDER_FILED, required = false) String orderBy,
|
...
|
...
|
@@ -59,30 +63,30 @@ public class Tk3dComponentController extends BaseController { |
59
|
63
|
HashMap<String, Object> queryMap = new HashMap<>();
|
60
|
64
|
queryMap.put(PAGE, page);
|
61
|
65
|
queryMap.put(PAGE_SIZE, pageSize);
|
62
|
|
- queryMap.put(ORDER_FILED, orderBy!=null?orderBy:"create_time");
|
63
|
|
- queryMap.put(ORDER_TYPE, orderType!=null?orderType.name():OrderTypeEnum.DESC.name());
|
64
|
|
- queryMap.put(TENANT_ID,getTenantId().getId().toString());
|
65
|
|
- if(StringUtils.hasLength(id)){
|
66
|
|
- queryMap.put("id",id);
|
|
66
|
+ queryMap.put(ORDER_FILED, orderBy != null ? orderBy : "create_time");
|
|
67
|
+ queryMap.put(ORDER_TYPE, orderType != null ? orderType.name() : OrderTypeEnum.DESC.name());
|
|
68
|
+ queryMap.put(TENANT_ID, getTenantId().getId().toString());
|
|
69
|
+ if (StringUtils.hasLength(id)) {
|
|
70
|
+ queryMap.put("id", id);
|
67
|
71
|
}
|
68
|
|
- if(StringUtils.hasLength(name)){
|
69
|
|
- queryMap.put("name",name);
|
|
72
|
+ if (StringUtils.hasLength(name)) {
|
|
73
|
+ queryMap.put("name", name);
|
70
|
74
|
}
|
71
|
|
- if(state!=null){
|
72
|
|
- queryMap.put("state",state);
|
|
75
|
+ if (state != null) {
|
|
76
|
+ queryMap.put("state", state);
|
73
|
77
|
}
|
74
|
78
|
|
75
|
|
- return tk3dComponentService.page(queryMap,getTenantId().getId().toString());
|
|
79
|
+ return tk3dComponentService.page(queryMap, getTenantId().getId().toString());
|
76
|
80
|
}
|
77
|
81
|
|
78
|
82
|
|
79
|
83
|
@PostMapping
|
80
|
84
|
@ApiOperation("保存")
|
81
|
|
- public ResponseEntity<Tk3dComponentDTO> save(@ApiParam("id")@RequestParam("id") String id, @RequestParam("imageUrl") String imageUrl,@RequestBody JsonNode jsonNode) throws ThingsboardException {
|
82
|
|
- if(!StringUtils.hasLength(id)){
|
|
85
|
+ public ResponseEntity<Tk3dComponentDTO> save(@ApiParam("id") @RequestParam("id") String id, @RequestParam("imageUrl") String imageUrl, @RequestBody JsonNode jsonNode) throws ThingsboardException {
|
|
86
|
+ if (!StringUtils.hasLength(id)) {
|
83
|
87
|
throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
|
84
|
88
|
}
|
85
|
|
- Tk3dComponentDTO dto=new Tk3dComponentDTO();
|
|
89
|
+ Tk3dComponentDTO dto = new Tk3dComponentDTO();
|
86
|
90
|
dto.setId(id);
|
87
|
91
|
dto.setImageUrl(imageUrl);
|
88
|
92
|
dto.setTenantId(getTenantId().getId().toString());
|
...
|
...
|
@@ -92,11 +96,11 @@ public class Tk3dComponentController extends BaseController { |
92
|
96
|
|
93
|
97
|
@PutMapping("/{id}/{name}")
|
94
|
98
|
@ApiOperation("修改名称")
|
95
|
|
- public ResponseEntity<Tk3dComponentDTO> put(@PathVariable("id") String id,@PathVariable("name") String name) throws ThingsboardException {
|
96
|
|
- if(!StringUtils.hasLength(id)){
|
|
99
|
+ public ResponseEntity<Tk3dComponentDTO> put(@PathVariable("id") String id, @PathVariable("name") String name) throws ThingsboardException {
|
|
100
|
+ if (!StringUtils.hasLength(id)) {
|
97
|
101
|
throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
|
98
|
102
|
}
|
99
|
|
- Tk3dComponentDTO dto=tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
|
|
103
|
+ Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
|
100
|
104
|
dto.setName(name);
|
101
|
105
|
return ResponseEntity.ok(tk3dComponentService.save(dto));
|
102
|
106
|
}
|
...
|
...
|
@@ -104,15 +108,47 @@ public class Tk3dComponentController extends BaseController { |
104
|
108
|
|
105
|
109
|
@PutMapping("/publish/{id}/{state}")
|
106
|
110
|
@ApiOperation("发布")
|
107
|
|
- public ResponseEntity<Tk3dComponentDTO> publish(@PathVariable("id") String id,@PathVariable("state") Integer state) throws ThingsboardException {
|
108
|
|
- if(!StringUtils.hasLength(id)){
|
|
111
|
+ public ResponseEntity<Tk3dComponentDTO> publish(@PathVariable("id") String id, @PathVariable("state") Integer state) throws ThingsboardException {
|
|
112
|
+ if (!StringUtils.hasLength(id)) {
|
109
|
113
|
throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
|
110
|
114
|
}
|
111
|
|
- Tk3dComponentDTO dto=tk3dComponentService.get(id,getCurrentUser().getCurrentTenantId());
|
|
115
|
+ Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
|
112
|
116
|
dto.setState(state);
|
113
|
117
|
return ResponseEntity.ok(tk3dComponentService.save(dto));
|
114
|
118
|
}
|
115
|
119
|
|
|
120
|
+
|
|
121
|
+ @PutMapping("/publish/{state}")
|
|
122
|
+ public ResponseEntity<Boolean> publish(@PathVariable("state") Integer state, @RequestBody List<String> ids) throws ThingsboardException {
|
|
123
|
+ if (!CollectionUtils.isEmpty(ids)) {
|
|
124
|
+
|
|
125
|
+ return ResponseEntity.ok(
|
|
126
|
+
|
|
127
|
+ tk3dComponentService.save(
|
|
128
|
+
|
|
129
|
+ ids.stream().map(id -> {
|
|
130
|
+
|
|
131
|
+ try {
|
|
132
|
+ return tk3dComponentService.get(id, getTenantId().getId().toString());
|
|
133
|
+ } catch (ThingsboardException e) {
|
|
134
|
+ throw new RuntimeException(e);
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ }).filter(e -> {
|
|
138
|
+ return e != null;
|
|
139
|
+ })
|
|
140
|
+ .map(e -> {
|
|
141
|
+ e.setState(state);
|
|
142
|
+ return e;
|
|
143
|
+ }).collect(Collectors.toList())
|
|
144
|
+
|
|
145
|
+ )
|
|
146
|
+ );
|
|
147
|
+ } else {
|
|
148
|
+ return ResponseEntity.ok(false);
|
|
149
|
+ }
|
|
150
|
+ }
|
|
151
|
+
|
116
|
152
|
@GetMapping("/{id}")
|
117
|
153
|
@ApiOperation("获取详情信息")
|
118
|
154
|
public ResponseEntity<Tk3dComponentDTO> get(@PathVariable("id") String id)
|
...
|
...
|
@@ -127,7 +163,7 @@ public class Tk3dComponentController extends BaseController { |
127
|
163
|
|
128
|
164
|
@GetMapping("/json/{id}/{key}.json")
|
129
|
165
|
@ApiOperation("获取json数据")
|
130
|
|
- public ResponseEntity<JsonNode> json(@PathVariable("id") String id,@PathVariable("key") String key)
|
|
166
|
+ public ResponseEntity<JsonNode> json(@PathVariable("id") String id, @PathVariable("key") String key)
|
131
|
167
|
throws Exception {
|
132
|
168
|
Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
|
133
|
169
|
if (null == dto) {
|
...
|
...
|
@@ -139,12 +175,12 @@ public class Tk3dComponentController extends BaseController { |
139
|
175
|
@DeleteMapping
|
140
|
176
|
@ApiOperation("删除")
|
141
|
177
|
public ResponseEntity<Boolean> del(DeleteDTO deleteDTO) throws ThingsboardException {
|
142
|
|
- List<String> ids = deleteDTO.getIds()==null?null:new ArrayList<>(deleteDTO.getIds());
|
143
|
|
- return ResponseEntity.ok(tk3dComponentService.delete(getCurrentUser().getCurrentTenantId(),ids));
|
|
178
|
+ List<String> ids = deleteDTO.getIds() == null ? null : new ArrayList<>(deleteDTO.getIds());
|
|
179
|
+ return ResponseEntity.ok(tk3dComponentService.delete(getCurrentUser().getCurrentTenantId(), ids));
|
144
|
180
|
}
|
145
|
181
|
|
146
|
182
|
@Data
|
147
|
|
- private static class ComponentParam{
|
|
183
|
+ private static class ComponentParam {
|
148
|
184
|
|
149
|
185
|
@ApiModelProperty("ID")
|
150
|
186
|
String id;
|
...
|
...
|
|