1
|
1
|
package org.thingsboard.server.dao.util.yunteng.task;
|
2
|
2
|
|
|
3
|
+import com.google.common.util.concurrent.FutureCallback;
|
|
4
|
+import com.google.common.util.concurrent.Futures;
|
|
5
|
+import com.google.common.util.concurrent.ListenableFuture;
|
|
6
|
+import com.google.common.util.concurrent.MoreExecutors;
|
3
|
7
|
import lombok.RequiredArgsConstructor;
|
4
|
8
|
import lombok.extern.slf4j.Slf4j;
|
|
9
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
5
|
10
|
import org.springframework.stereotype.Component;
|
6
|
11
|
import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
|
12
|
+import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
|
7
|
13
|
import org.thingsboard.server.common.data.yunteng.dto.ReportFormConfigDTO;
|
8
|
14
|
import org.thingsboard.server.common.data.yunteng.dto.request.ExecuteAttributesDTO;
|
|
15
|
+import org.thingsboard.server.dao.yunteng.service.TkDeviceService;
|
9
|
16
|
import org.thingsboard.server.dao.yunteng.service.TkReportFormConfigService;
|
10
|
17
|
import org.thingsboard.server.dao.yunteng.service.TkReportGenerateRecordService;
|
11
|
18
|
import java.util.*;
|
...
|
...
|
@@ -18,6 +25,8 @@ public class ReportTask { |
18
|
25
|
|
19
|
26
|
private final TkReportGenerateRecordService tkReportGenerateRecordService;
|
20
|
27
|
|
|
28
|
+ private final TkDeviceService tkDeviceService;
|
|
29
|
+
|
21
|
30
|
public void multipleParams(String s, Boolean b, Long l, Double d, Integer i) {
|
22
|
31
|
System.out.println("执行多参方法: s=" + s + "b=" + b + "l=" + l + "d" + d + "i=" + i);
|
23
|
32
|
}
|
...
|
...
|
@@ -32,28 +41,40 @@ public class ReportTask { |
32
|
41
|
}
|
33
|
42
|
|
34
|
43
|
public void generateReport(String reportId, String reportGenerateRecordId) {
|
35
|
|
- ReportFormConfigDTO formConfigDTO =
|
|
44
|
+ ListenableFuture<ReportFormConfigDTO> future =
|
36
|
45
|
tkReportFormConfigService.findReportFormConfigById(reportId);
|
37
|
|
- // 关联设备
|
38
|
|
- List<ExecuteAttributesDTO> dtoList = formConfigDTO.getExecuteAttributes();
|
39
|
|
- if (!dtoList.isEmpty()) {
|
40
|
|
- if (dtoList.size() == FastIotConstants.MagicNumber.ONE) {
|
41
|
|
- try {
|
42
|
|
- ExecuteAttributesDTO attributesDTO = dtoList.get(0);
|
43
|
|
- getTsKvForGenerateExcel(
|
44
|
|
- formConfigDTO, attributesDTO, reportGenerateRecordId, dtoList.size());
|
|
46
|
+ Futures.addCallback(
|
|
47
|
+ future,
|
|
48
|
+ new FutureCallback<>() {
|
|
49
|
+ @Override
|
|
50
|
+ public void onSuccess(@Nullable ReportFormConfigDTO reportFormConfigDTO) {
|
|
51
|
+ // 关联设备
|
|
52
|
+ List<ExecuteAttributesDTO> dtoList = reportFormConfigDTO.getExecuteAttributes();
|
|
53
|
+ if (!dtoList.isEmpty()) {
|
|
54
|
+ if (dtoList.size() == FastIotConstants.MagicNumber.ONE) {
|
|
55
|
+ try {
|
|
56
|
+ ExecuteAttributesDTO attributesDTO = dtoList.get(0);
|
|
57
|
+ getTsKvForGenerateExcel(
|
|
58
|
+ reportFormConfigDTO, attributesDTO, reportGenerateRecordId, dtoList.size());
|
45
|
59
|
|
46
|
|
- } catch (Exception e) {
|
47
|
|
- log.error(e.getMessage());
|
48
|
|
- }
|
49
|
|
- } else {
|
50
|
|
- int surplus = dtoList.size();
|
51
|
|
- for (ExecuteAttributesDTO dto : dtoList) {
|
52
|
|
- getTsKvForGenerateExcel(formConfigDTO, dto, reportGenerateRecordId, surplus);
|
53
|
|
- surplus--;
|
54
|
|
- }
|
55
|
|
- }
|
56
|
|
- }
|
|
60
|
+ } catch (Exception e) {
|
|
61
|
+ log.error(e.getMessage());
|
|
62
|
+ }
|
|
63
|
+ } else {
|
|
64
|
+ int surplus = dtoList.size();
|
|
65
|
+ for (ExecuteAttributesDTO dto : dtoList) {
|
|
66
|
+ getTsKvForGenerateExcel(
|
|
67
|
+ reportFormConfigDTO, dto, reportGenerateRecordId, surplus);
|
|
68
|
+ surplus--;
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ @Override
|
|
75
|
+ public void onFailure(Throwable throwable) {}
|
|
76
|
+ },
|
|
77
|
+ MoreExecutors.directExecutor());
|
57
|
78
|
}
|
58
|
79
|
|
59
|
80
|
private void getTsKvForGenerateExcel(
|
...
|
...
|
@@ -61,7 +82,11 @@ public class ReportTask { |
61
|
82
|
ExecuteAttributesDTO dto,
|
62
|
83
|
String reportGenerateRecordId,
|
63
|
84
|
int surplus) {
|
64
|
|
- tkReportGenerateRecordService.generateExcelUpdateReportRecord(
|
65
|
|
- formConfigDTO, dto, reportGenerateRecordId, surplus);
|
|
85
|
+ //检查设备是否存在
|
|
86
|
+ DeviceDTO deviceDTO = tkDeviceService.findDeviceInfoByTbDeviceId(formConfigDTO.getTenantId(),dto.getDevice());
|
|
87
|
+ if(null != deviceDTO){
|
|
88
|
+ tkReportGenerateRecordService.generateExcelUpdateReportRecord(
|
|
89
|
+ formConfigDTO, dto, reportGenerateRecordId, surplus);
|
|
90
|
+ }
|
66
|
91
|
}
|
67
|
92
|
} |
...
|
...
|
|