|
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+package com.water.bi.controller;
|
|
|
2
|
+
|
|
|
3
|
+import com.water.bi.entity.SelfServiceDashboard;
|
|
|
4
|
+import com.water.bi.service.SelfServiceDashboardService;
|
|
|
5
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
6
|
+import org.springframework.http.ResponseEntity;
|
|
|
7
|
+import org.springframework.web.bind.annotation.*;
|
|
|
8
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
9
|
+
|
|
|
10
|
+import java.util.*;
|
|
|
11
|
+
|
|
|
12
|
+/**
|
|
|
13
|
+ * 自助服务看板控制器
|
|
|
14
|
+ */
|
|
|
15
|
+@RestController
|
|
|
16
|
+@RequestMapping("/api/bi/self-service")
|
|
|
17
|
+@CrossOrigin(origins = "*")
|
|
|
18
|
+public class SelfServiceDashboardController {
|
|
|
19
|
+
|
|
|
20
|
+ @Autowired
|
|
|
21
|
+ private SelfServiceDashboardService selfServiceDashboardService;
|
|
|
22
|
+
|
|
|
23
|
+ /**
|
|
|
24
|
+ * 创建自助服务看板
|
|
|
25
|
+ */
|
|
|
26
|
+ @PostMapping("/dashboards")
|
|
|
27
|
+ public ResponseEntity<Map<String, Object>> createDashboard(@RequestBody SelfServiceDashboard dashboard) {
|
|
|
28
|
+ try {
|
|
|
29
|
+ String dashboardId = selfServiceDashboardService.createSelfServiceDashboard(dashboard);
|
|
|
30
|
+
|
|
|
31
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
32
|
+ response.put("success", true);
|
|
|
33
|
+ response.put("message", "成功创建自助服务看板");
|
|
|
34
|
+ response.put("dashboardId", dashboardId);
|
|
|
35
|
+ response.put("dashboard", dashboard);
|
|
|
36
|
+ response.put("features", Arrays.asList(
|
|
|
37
|
+ "drag_drop", "real_time", "export", "share", "schedule", "theme", "responsive"
|
|
|
38
|
+ ));
|
|
|
39
|
+
|
|
|
40
|
+ return ResponseEntity.ok(response);
|
|
|
41
|
+ } catch (Exception e) {
|
|
|
42
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
43
|
+ response.put("success", false);
|
|
|
44
|
+ response.put("message", "创建看板失败: " + e.getMessage());
|
|
|
45
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
46
|
+ }
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ /**
|
|
|
50
|
+ * 获取看板详情
|
|
|
51
|
+ */
|
|
|
52
|
+ @GetMapping("/dashboards/{dashboardId}")
|
|
|
53
|
+ public ResponseEntity<Map<String, Object>> getDashboard(@PathVariable String dashboardId) {
|
|
|
54
|
+ try {
|
|
|
55
|
+ SelfServiceDashboard dashboard = selfServiceDashboardService.getDashboardById(dashboardId);
|
|
|
56
|
+
|
|
|
57
|
+ if (dashboard != null) {
|
|
|
58
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
59
|
+ response.put("success", true);
|
|
|
60
|
+ response.put("message", "获取看板成功");
|
|
|
61
|
+ response.put("dashboard", dashboard);
|
|
|
62
|
+ response.put("editable", true); // 默认可编辑
|
|
|
63
|
+
|
|
|
64
|
+ return ResponseEntity.ok(response);
|
|
|
65
|
+ } else {
|
|
|
66
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
67
|
+ response.put("success", false);
|
|
|
68
|
+ response.put("message", "看板不存在");
|
|
|
69
|
+ return ResponseEntity.notFound().build();
|
|
|
70
|
+ }
|
|
|
71
|
+ } catch (Exception e) {
|
|
|
72
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
73
|
+ response.put("success", false);
|
|
|
74
|
+ response.put("message", "获取看板失败: " + e.getMessage());
|
|
|
75
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
76
|
+ }
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ /**
|
|
|
80
|
+ * 获取用户的所有看板
|
|
|
81
|
+ */
|
|
|
82
|
+ @GetMapping("/dashboards")
|
|
|
83
|
+ public ResponseEntity<Map<String, Object>> getUserDashboards(
|
|
|
84
|
+ @RequestParam String userId,
|
|
|
85
|
+ @RequestParam(defaultValue = "0") int page,
|
|
|
86
|
+ @RequestParam(defaultValue = "10") int size) {
|
|
|
87
|
+
|
|
|
88
|
+ try {
|
|
|
89
|
+ List<SelfServiceDashboard> dashboards = selfServiceDashboardService.getUserDashboards(userId);
|
|
|
90
|
+
|
|
|
91
|
+ // 分页处理
|
|
|
92
|
+ int total = dashboards.size();
|
|
|
93
|
+ int start = page * size;
|
|
|
94
|
+ int end = Math.min(start + size, total);
|
|
|
95
|
+
|
|
|
96
|
+ List<SelfServiceDashboard> paginatedDashboards =
|
|
|
97
|
+ dashboards.subList(start, end);
|
|
|
98
|
+
|
|
|
99
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
100
|
+ response.put("success", true);
|
|
|
101
|
+ response.put("message", "获取看板列表成功");
|
|
|
102
|
+ response.put("dashboards", paginatedDashboards);
|
|
|
103
|
+ response.put("total", total);
|
|
|
104
|
+ response.put("page", page);
|
|
|
105
|
+ response.put("size", size);
|
|
|
106
|
+ response.put("hasNext", end < total);
|
|
|
107
|
+
|
|
|
108
|
+ return ResponseEntity.ok(response);
|
|
|
109
|
+ } catch (Exception e) {
|
|
|
110
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
111
|
+ response.put("success", false);
|
|
|
112
|
+ response.put("message", "获取看板列表失败: " + e.getMessage());
|
|
|
113
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
114
|
+ }
|
|
|
115
|
+ }
|
|
|
116
|
+
|
|
|
117
|
+ /**
|
|
|
118
|
+ * 更新看板
|
|
|
119
|
+ */
|
|
|
120
|
+ @PutMapping("/dashboards/{dashboardId}")
|
|
|
121
|
+ public ResponseEntity<Map<String, Object>> updateDashboard(
|
|
|
122
|
+ @PathVariable String dashboardId,
|
|
|
123
|
+ @RequestBody SelfServiceDashboard dashboard) {
|
|
|
124
|
+
|
|
|
125
|
+ try {
|
|
|
126
|
+ boolean success = selfServiceDashboardService.updateDashboard(dashboardId, dashboard);
|
|
|
127
|
+
|
|
|
128
|
+ if (success) {
|
|
|
129
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
130
|
+ response.put("success", true);
|
|
|
131
|
+ response.put("message", "更新看板成功");
|
|
|
132
|
+ response.put("dashboardId", dashboardId);
|
|
|
133
|
+
|
|
|
134
|
+ return ResponseEntity.ok(response);
|
|
|
135
|
+ } else {
|
|
|
136
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
137
|
+ response.put("success", false);
|
|
|
138
|
+ response.put("message", "看板不存在");
|
|
|
139
|
+ return ResponseEntity.notFound().build();
|
|
|
140
|
+ }
|
|
|
141
|
+ } catch (Exception e) {
|
|
|
142
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
143
|
+ response.put("success", false);
|
|
|
144
|
+ response.put("message", "更新看板失败: " + e.getMessage());
|
|
|
145
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
146
|
+ }
|
|
|
147
|
+ }
|
|
|
148
|
+
|
|
|
149
|
+ /**
|
|
|
150
|
+ * 删除看板
|
|
|
151
|
+ */
|
|
|
152
|
+ @DeleteMapping("/dashboards/{dashboardId}")
|
|
|
153
|
+ public ResponseEntity<Map<String, Object>> deleteDashboard(@PathVariable String dashboardId) {
|
|
|
154
|
+ try {
|
|
|
155
|
+ boolean success = selfServiceDashboardService.deleteDashboard(dashboardId);
|
|
|
156
|
+
|
|
|
157
|
+ if (success) {
|
|
|
158
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
159
|
+ response.put("success", true);
|
|
|
160
|
+ response.put("message", "删除看板成功");
|
|
|
161
|
+ response.put("dashboardId", dashboardId);
|
|
|
162
|
+
|
|
|
163
|
+ return ResponseEntity.ok(response);
|
|
|
164
|
+ } else {
|
|
|
165
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
166
|
+ response.put("success", false);
|
|
|
167
|
+ response.put("message", "看板不存在");
|
|
|
168
|
+ return ResponseEntity.notFound().build();
|
|
|
169
|
+ }
|
|
|
170
|
+ } catch (Exception e) {
|
|
|
171
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
172
|
+ response.put("success", false);
|
|
|
173
|
+ response.put("message", "删除看板失败: " + e.getMessage());
|
|
|
174
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
175
|
+ }
|
|
|
176
|
+ }
|
|
|
177
|
+
|
|
|
178
|
+ /**
|
|
|
179
|
+ * 发布看板
|
|
|
180
|
+ */
|
|
|
181
|
+ @PostMapping("/dashboards/{dashboardId}/publish")
|
|
|
182
|
+ public ResponseEntity<Map<String, Object>> publishDashboard(@PathVariable String dashboardId) {
|
|
|
183
|
+ try {
|
|
|
184
|
+ boolean success = selfServiceDashboardService.publishDashboard(dashboardId);
|
|
|
185
|
+
|
|
|
186
|
+ if (success) {
|
|
|
187
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
188
|
+ response.put("success", true);
|
|
|
189
|
+ response.put("message", "看板发布成功");
|
|
|
190
|
+ response.put("dashboardId", dashboardId);
|
|
|
191
|
+
|
|
|
192
|
+ return ResponseEntity.ok(response);
|
|
|
193
|
+ } else {
|
|
|
194
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
195
|
+ response.put("success", false);
|
|
|
196
|
+ response.put("message", "看板不存在");
|
|
|
197
|
+ return ResponseEntity.notFound().build();
|
|
|
198
|
+ }
|
|
|
199
|
+ } catch (Exception e) {
|
|
|
200
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
201
|
+ response.put("success", false);
|
|
|
202
|
+ response.put("message", "发布看板失败: " + e.getMessage());
|
|
|
203
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
204
|
+ }
|
|
|
205
|
+ }
|
|
|
206
|
+
|
|
|
207
|
+ /**
|
|
|
208
|
+ * 添加组件
|
|
|
209
|
+ */
|
|
|
210
|
+ @PostMapping("/dashboards/{dashboardId}/components")
|
|
|
211
|
+ public ResponseEntity<Map<String, Object>> addComponent(
|
|
|
212
|
+ @PathVariable String dashboardId,
|
|
|
213
|
+ @RequestBody SelfServiceDashboard.DashboardComponent component) {
|
|
|
214
|
+
|
|
|
215
|
+ try {
|
|
|
216
|
+ boolean success = selfServiceDashboardService.addComponent(dashboardId, component);
|
|
|
217
|
+
|
|
|
218
|
+ if (success) {
|
|
|
219
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
220
|
+ response.put("success", true);
|
|
|
221
|
+ response.put("message", "添加组件成功");
|
|
|
222
|
+ response.put("componentId", component.getId());
|
|
|
223
|
+ response.put("component", component);
|
|
|
224
|
+
|
|
|
225
|
+ return ResponseEntity.ok(response);
|
|
|
226
|
+ } else {
|
|
|
227
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
228
|
+ response.put("success", false);
|
|
|
229
|
+ response.put("message", "操作失败");
|
|
|
230
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
231
|
+ }
|
|
|
232
|
+ } catch (Exception e) {
|
|
|
233
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
234
|
+ response.put("success", false);
|
|
|
235
|
+ response.put("message", "添加组件失败: " + e.getMessage());
|
|
|
236
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
237
|
+ }
|
|
|
238
|
+ }
|
|
|
239
|
+
|
|
|
240
|
+ /**
|
|
|
241
|
+ * 更新组件布局
|
|
|
242
|
+ */
|
|
|
243
|
+ @PutMapping("/dashboards/{dashboardId}/components/{componentId}/layout")
|
|
|
244
|
+ public ResponseEntity<Map<String, Object>> updateComponentLayout(
|
|
|
245
|
+ @PathVariable String dashboardId,
|
|
|
246
|
+ @PathVariable String componentId,
|
|
|
247
|
+ @RequestParam int x,
|
|
|
248
|
+ @RequestParam int y,
|
|
|
249
|
+ @RequestParam int width,
|
|
|
250
|
+ @RequestParam int height) {
|
|
|
251
|
+
|
|
|
252
|
+ try {
|
|
|
253
|
+ boolean success = selfServiceDashboardService.updateComponentLayout(
|
|
|
254
|
+ dashboardId, componentId, x, y, width, height);
|
|
|
255
|
+
|
|
|
256
|
+ if (success) {
|
|
|
257
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
258
|
+ response.put("success", true);
|
|
|
259
|
+ response.put("message", "更新组件布局成功");
|
|
|
260
|
+ response.put("componentId", componentId);
|
|
|
261
|
+ response.put("layout", Map.of(
|
|
|
262
|
+ "x", x, "y", y, "width", width, "height", height
|
|
|
263
|
+ ));
|
|
|
264
|
+
|
|
|
265
|
+ return ResponseEntity.ok(response);
|
|
|
266
|
+ } else {
|
|
|
267
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
268
|
+ response.put("success", false);
|
|
|
269
|
+ response.put("message", "操作失败");
|
|
|
270
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
271
|
+ }
|
|
|
272
|
+ } catch (Exception e) {
|
|
|
273
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
274
|
+ response.put("success", false);
|
|
|
275
|
+ response.put("message", "更新组件布局失败: " + e.getMessage());
|
|
|
276
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
277
|
+ }
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ /**
|
|
|
281
|
+ * 删除组件
|
|
|
282
|
+ */
|
|
|
283
|
+ @DeleteMapping("/dashboards/{dashboardId}/components/{componentId}")
|
|
|
284
|
+ public ResponseEntity<Map<String, Object>> removeComponent(
|
|
|
285
|
+ @PathVariable String dashboardId,
|
|
|
286
|
+ @PathVariable String componentId) {
|
|
|
287
|
+
|
|
|
288
|
+ try {
|
|
|
289
|
+ boolean success = selfServiceDashboardService.removeComponent(dashboardId, componentId);
|
|
|
290
|
+
|
|
|
291
|
+ if (success) {
|
|
|
292
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
293
|
+ response.put("success", true);
|
|
|
294
|
+ response.put("message", "删除组件成功");
|
|
|
295
|
+ response.put("componentId", componentId);
|
|
|
296
|
+
|
|
|
297
|
+ return ResponseEntity.ok(response);
|
|
|
298
|
+ } else {
|
|
|
299
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
300
|
+ response.put("success", false);
|
|
|
301
|
+ response.put("message", "操作失败");
|
|
|
302
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
303
|
+ }
|
|
|
304
|
+ } catch (Exception e) {
|
|
|
305
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
306
|
+ response.put("success", false);
|
|
|
307
|
+ response.put("message", "删除组件失败: " + e.getMessage());
|
|
|
308
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
309
|
+ }
|
|
|
310
|
+ }
|
|
|
311
|
+
|
|
|
312
|
+ /**
|
|
|
313
|
+ * 分享看板
|
|
|
314
|
+ */
|
|
|
315
|
+ @PostMapping("/dashboards/{dashboardId}/share")
|
|
|
316
|
+ public ResponseEntity<Map<String, Object>> shareDashboard(
|
|
|
317
|
+ @PathVariable String dashboardId,
|
|
|
318
|
+ @RequestParam String userId,
|
|
|
319
|
+ @RequestParam(defaultValue = "viewer") String role) {
|
|
|
320
|
+
|
|
|
321
|
+ try {
|
|
|
322
|
+ boolean success = selfServiceDashboardService.shareDashboard(dashboardId, userId, role);
|
|
|
323
|
+
|
|
|
324
|
+ if (success) {
|
|
|
325
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
326
|
+ response.put("success", true);
|
|
|
327
|
+ response.put("message", "分享看板成功");
|
|
|
328
|
+ response.put("dashboardId", dashboardId);
|
|
|
329
|
+ response.put("sharedUserId", userId);
|
|
|
330
|
+ response.put("sharedUserRole", role);
|
|
|
331
|
+
|
|
|
332
|
+ return ResponseEntity.ok(response);
|
|
|
333
|
+ } else {
|
|
|
334
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
335
|
+ response.put("success", false);
|
|
|
336
|
+ response.put("message", "操作失败");
|
|
|
337
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
338
|
+ }
|
|
|
339
|
+ } catch (Exception e) {
|
|
|
340
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
341
|
+ response.put("success", false);
|
|
|
342
|
+ response.put("message", "分享看板失败: " + e.getMessage());
|
|
|
343
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
344
|
+ }
|
|
|
345
|
+ }
|
|
|
346
|
+
|
|
|
347
|
+ /**
|
|
|
348
|
+ * 取消分享
|
|
|
349
|
+ */
|
|
|
350
|
+ @DeleteMapping("/dashboards/{dashboardId}/share/{userId}")
|
|
|
351
|
+ public ResponseEntity<Map<String, Object>> unshareDashboard(
|
|
|
352
|
+ @PathVariable String dashboardId,
|
|
|
353
|
+ @PathVariable String userId) {
|
|
|
354
|
+
|
|
|
355
|
+ try {
|
|
|
356
|
+ boolean success = selfServiceDashboardService.unshareDashboard(dashboardId, userId);
|
|
|
357
|
+
|
|
|
358
|
+ if (success) {
|
|
|
359
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
360
|
+ response.put("success", true);
|
|
|
361
|
+ response.put("message", "取消分享成功");
|
|
|
362
|
+ response.put("dashboardId", dashboardId);
|
|
|
363
|
+ response.put("removedUserId", userId);
|
|
|
364
|
+
|
|
|
365
|
+ return ResponseEntity.ok(response);
|
|
|
366
|
+ } else {
|
|
|
367
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
368
|
+ response.put("success", false);
|
|
|
369
|
+ response.put("message", "操作失败");
|
|
|
370
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
371
|
+ }
|
|
|
372
|
+ } catch (Exception e) {
|
|
|
373
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
374
|
+ response.put("success", false);
|
|
|
375
|
+ response.put("message", "取消分享失败: " + e.getMessage());
|
|
|
376
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
377
|
+ }
|
|
|
378
|
+ }
|
|
|
379
|
+
|
|
|
380
|
+ /**
|
|
|
381
|
+ * 配置刷新计划
|
|
|
382
|
+ */
|
|
|
383
|
+ @PostMapping("/dashboards/{dashboardId}/schedule")
|
|
|
384
|
+ public ResponseEntity<Map<String, Object>> configureSchedule(
|
|
|
385
|
+ @PathVariable String dashboardId,
|
|
|
386
|
+ @RequestBody SelfServiceDashboard.ScheduleConfig schedule) {
|
|
|
387
|
+
|
|
|
388
|
+ try {
|
|
|
389
|
+ boolean success = selfServiceDashboardService.configureSchedule(dashboardId, schedule);
|
|
|
390
|
+
|
|
|
391
|
+ if (success) {
|
|
|
392
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
393
|
+ response.put("success", true);
|
|
|
394
|
+ response.put("message", "配置刷新计划成功");
|
|
|
395
|
+ response.put("dashboardId", dashboardId);
|
|
|
396
|
+ response.put("schedule", schedule);
|
|
|
397
|
+
|
|
|
398
|
+ return ResponseEntity.ok(response);
|
|
|
399
|
+ } else {
|
|
|
400
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
401
|
+ response.put("success", false);
|
|
|
402
|
+ response.put("message", "操作失败");
|
|
|
403
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
404
|
+ }
|
|
|
405
|
+ } catch (Exception e) {
|
|
|
406
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
407
|
+ response.put("success", false);
|
|
|
408
|
+ response.put("message", "配置刷新计划失败: " + e.getMessage());
|
|
|
409
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
410
|
+ }
|
|
|
411
|
+ }
|
|
|
412
|
+
|
|
|
413
|
+ /**
|
|
|
414
|
+ * 设置主题
|
|
|
415
|
+ */
|
|
|
416
|
+ @PutMapping("/dashboards/{dashboardId}/theme")
|
|
|
417
|
+ public ResponseEntity<Map<String, Object>> setTheme(
|
|
|
418
|
+ @PathVariable String dashboardId,
|
|
|
419
|
+ @RequestParam String theme) {
|
|
|
420
|
+
|
|
|
421
|
+ try {
|
|
|
422
|
+ boolean success = selfServiceDashboardService.setTheme(dashboardId, theme);
|
|
|
423
|
+
|
|
|
424
|
+ if (success) {
|
|
|
425
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
426
|
+ response.put("success", true);
|
|
|
427
|
+ response.put("message", "设置主题成功");
|
|
|
428
|
+ response.put("dashboardId", dashboardId);
|
|
|
429
|
+ response.put("theme", theme);
|
|
|
430
|
+
|
|
|
431
|
+ return ResponseEntity.ok(response);
|
|
|
432
|
+ } else {
|
|
|
433
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
434
|
+ response.put("success", false);
|
|
|
435
|
+ response.put("message", "操作失败");
|
|
|
436
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
437
|
+ }
|
|
|
438
|
+ } catch (Exception e) {
|
|
|
439
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
440
|
+ response.put("success", false);
|
|
|
441
|
+ response.put("message", "设置主题失败: " + e.getMessage());
|
|
|
442
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
443
|
+ }
|
|
|
444
|
+ }
|
|
|
445
|
+
|
|
|
446
|
+ /**
|
|
|
447
|
+ * 复制看板
|
|
|
448
|
+ */
|
|
|
449
|
+ @PostMapping("/dashboards/{dashboardId}/copy")
|
|
|
450
|
+ public ResponseEntity<Map<String, Object>> copyDashboard(
|
|
|
451
|
+ @PathVariable String dashboardId,
|
|
|
452
|
+ @RequestParam String newName) {
|
|
|
453
|
+
|
|
|
454
|
+ try {
|
|
|
455
|
+ String newDashboardId = selfServiceDashboardService.copyDashboard(dashboardId, newName);
|
|
|
456
|
+
|
|
|
457
|
+ if (newDashboardId != null) {
|
|
|
458
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
459
|
+ response.put("success", true);
|
|
|
460
|
+ response.put("message", "复制看板成功");
|
|
|
461
|
+ response.put("originalDashboardId", dashboardId);
|
|
|
462
|
+ response.put("newDashboardId", newDashboardId);
|
|
|
463
|
+ response.put("newDashboardName", newName);
|
|
|
464
|
+
|
|
|
465
|
+ return ResponseEntity.ok(response);
|
|
|
466
|
+ } else {
|
|
|
467
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
468
|
+ response.put("success", false);
|
|
|
469
|
+ response.put("message", "原看板不存在");
|
|
|
470
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
471
|
+ }
|
|
|
472
|
+ } catch (Exception e) {
|
|
|
473
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
474
|
+ response.put("success", false);
|
|
|
475
|
+ response.put("message", "复制看板失败: " + e.getMessage());
|
|
|
476
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
477
|
+ }
|
|
|
478
|
+ }
|
|
|
479
|
+
|
|
|
480
|
+ /**
|
|
|
481
|
+ * 获取看板统计
|
|
|
482
|
+ */
|
|
|
483
|
+ @GetMapping("/dashboards/{dashboardId}/stats")
|
|
|
484
|
+ public ResponseEntity<Map<String, Object>> getDashboardStats(@PathVariable String dashboardId) {
|
|
|
485
|
+ try {
|
|
|
486
|
+ Map<String, Object> stats = selfServiceDashboardService.getDashboardStats(dashboardId);
|
|
|
487
|
+
|
|
|
488
|
+ return ResponseEntity.ok(stats);
|
|
|
489
|
+ } catch (Exception e) {
|
|
|
490
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
491
|
+ response.put("success", false);
|
|
|
492
|
+ response.put("message", "获取统计信息失败: " + e.getMessage());
|
|
|
493
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
494
|
+ }
|
|
|
495
|
+ }
|
|
|
496
|
+
|
|
|
497
|
+ /**
|
|
|
498
|
+ * 搜索看板
|
|
|
499
|
+ */
|
|
|
500
|
+ @GetMapping("/dashboards/search")
|
|
|
501
|
+ public ResponseEntity<Map<String, Object>> searchDashboards(
|
|
|
502
|
+ @RequestParam String keyword,
|
|
|
503
|
+ @RequestParam String userId,
|
|
|
504
|
+ @RequestParam(defaultValue = "0") int page,
|
|
|
505
|
+ @RequestParam(defaultValue = "10") int size) {
|
|
|
506
|
+
|
|
|
507
|
+ try {
|
|
|
508
|
+ List<SelfServiceDashboard> dashboards = selfServiceDashboardService.searchDashboards(keyword, userId);
|
|
|
509
|
+
|
|
|
510
|
+ // 分页处理
|
|
|
511
|
+ int total = dashboards.size();
|
|
|
512
|
+ int start = page * size;
|
|
|
513
|
+ int end = Math.min(start + size, total);
|
|
|
514
|
+
|
|
|
515
|
+ List<SelfServiceDashboard> paginatedDashboards =
|
|
|
516
|
+ dashboards.subList(start, end);
|
|
|
517
|
+
|
|
|
518
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
519
|
+ response.put("success", true);
|
|
|
520
|
+ response.put("message", "搜索看板成功");
|
|
|
521
|
+ response.put("dashboards", paginatedDashboards);
|
|
|
522
|
+ response.put("total", total);
|
|
|
523
|
+ response.put("page", page);
|
|
|
524
|
+ response.put("size", size);
|
|
|
525
|
+ response.put("hasNext", end < total);
|
|
|
526
|
+ response.put("keyword", keyword);
|
|
|
527
|
+
|
|
|
528
|
+ return ResponseEntity.ok(response);
|
|
|
529
|
+ } catch (Exception e) {
|
|
|
530
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
531
|
+ response.put("success", false);
|
|
|
532
|
+ response.put("message", "搜索看板失败: " + e.getMessage());
|
|
|
533
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
534
|
+ }
|
|
|
535
|
+ }
|
|
|
536
|
+
|
|
|
537
|
+ /**
|
|
|
538
|
+ * 获取可用主题列表
|
|
|
539
|
+ */
|
|
|
540
|
+ @GetMapping("/themes")
|
|
|
541
|
+ public ResponseEntity<Map<String, Object>> getAvailableThemes() {
|
|
|
542
|
+ try {
|
|
|
543
|
+ List<Map<String, String>> themes = Arrays.asList(
|
|
|
544
|
+ Map.of("id", "light", "name", "浅色主题", "description", "清爽明亮的浅色主题"),
|
|
|
545
|
+ Map.of("id", "dark", "name", "深色主题", "优雅专业的深色主题"),
|
|
|
546
|
+ Map.of("id", "blue", "name", "蓝色主题", "科技感的蓝色主题"),
|
|
|
547
|
+ Map.of("id", "green", "name", "绿色主题", "自然清新的绿色主题"),
|
|
|
548
|
+ Map.of("id", "custom", "name", "自定义主题", "用户自定义的主题配置")
|
|
|
549
|
+ );
|
|
|
550
|
+
|
|
|
551
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
552
|
+ response.put("success", true);
|
|
|
553
|
+ response.put("message", "获取主题列表成功");
|
|
|
554
|
+ response.put("themes", themes);
|
|
|
555
|
+
|
|
|
556
|
+ return ResponseEntity.ok(response);
|
|
|
557
|
+ } catch (Exception e) {
|
|
|
558
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
559
|
+ response.put("success", false);
|
|
|
560
|
+ response.put("message", "获取主题列表失败: " + e.getMessage());
|
|
|
561
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
562
|
+ }
|
|
|
563
|
+ }
|
|
|
564
|
+
|
|
|
565
|
+ /**
|
|
|
566
|
+ * 获取可用组件类型
|
|
|
567
|
+ */
|
|
|
568
|
+ @GetMapping("/components/types")
|
|
|
569
|
+ public ResponseEntity<Map<String, Object>> getComponentTypes() {
|
|
|
570
|
+ try {
|
|
|
571
|
+ List<Map<String, String>> types = Arrays.asList(
|
|
|
572
|
+ Map.of("id", "metric", "name": "指标卡片", "description": "显示单个数值指标的卡片"),
|
|
|
573
|
+ Map.of("id", "chart", "name": "图表组件", "description": "包含折线图、柱状图、饼图等"),
|
|
|
574
|
+ Map.of("id", "table", "name": "数据表格", "description": "显示表格形式的数据"),
|
|
|
575
|
+ Map.of("id", "text", "name": "文本组件", "description": "显示文本内容"),
|
|
|
576
|
+ Map.of("id", "gauge", "name": "仪表盘", "description": "显示进度或状态的仪表盘"),
|
|
|
577
|
+ Map.of("id", "filter", "name": "筛选器", "description": "数据筛选和过滤组件")
|
|
|
578
|
+ );
|
|
|
579
|
+
|
|
|
580
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
581
|
+ response.put("success", true);
|
|
|
582
|
+ response.put("message", "获取组件类型成功");
|
|
|
583
|
+ response.put("componentTypes", types);
|
|
|
584
|
+
|
|
|
585
|
+ return ResponseEntity.ok(response);
|
|
|
586
|
+ } catch (Exception e) {
|
|
|
587
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
588
|
+ response.put("success", false);
|
|
|
589
|
+ response.put("message", "获取组件类型失败: " + e.getMessage());
|
|
|
590
|
+ return ResponseEntity.badRequest().body(response);
|
|
|
591
|
+ }
|
|
|
592
|
+ }
|
|
|
593
|
+}
|