提交 | 用户 | 时间
|
a955f1
|
1 |
package com.iailab; |
D |
2 |
|
|
3 |
import com.iailab.module.model.common.enums.DataTypeEnum; |
|
4 |
import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; |
|
5 |
import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO; |
|
6 |
import com.iailab.module.model.influxdb.service.InfluxDBService; |
|
7 |
import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; |
|
8 |
import org.junit.jupiter.api.Test; |
|
9 |
import org.springframework.boot.test.context.SpringBootTest; |
|
10 |
|
|
11 |
import javax.annotation.Resource; |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Calendar; |
|
14 |
import java.util.Date; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author PanZhibao |
|
19 |
* @Description |
|
20 |
* @createTime 2023年12月10日 12:19:00 |
|
21 |
*/ |
|
22 |
@SpringBootTest |
|
23 |
public class InfluxDBTest { |
|
24 |
|
|
25 |
@Resource |
|
26 |
private InfluxDBService influxDBService; |
|
27 |
|
|
28 |
|
|
29 |
@Test |
|
30 |
public void testWrite() { |
|
31 |
try { |
|
32 |
List<InfluxModelResultPOJO> pointValues = new ArrayList<>(); |
|
33 |
InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO(); |
|
34 |
pojo.setOutPutId("0001"); |
|
35 |
pojo.setType(DataTypeEnum.FLOAT.getCode()); |
|
36 |
pojo.setTimestamp(new Date().toInstant()); |
|
37 |
pojo.setValue(Double.valueOf(0.001)); |
|
38 |
pointValues.add(pojo); |
|
39 |
|
|
40 |
InfluxModelResultSimPOJO pojo1 = new InfluxModelResultSimPOJO(); |
|
41 |
pojo1.setOutPutId("0002"); |
|
42 |
pojo1.setType(DataTypeEnum.FLOAT.getCode()); |
|
43 |
pojo1.setTimestamp(new Date().toInstant()); |
|
44 |
pojo1.setValue(Double.valueOf(0.002)); |
|
45 |
pointValues.add(pojo1); |
|
46 |
|
|
47 |
influxDBService.asyncWriteModelResults(pointValues); |
|
48 |
} catch (Exception ex) { |
|
49 |
ex.printStackTrace(); |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
@Test |
|
55 |
public void testQuery() { |
|
56 |
InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
|
57 |
pojo.setType("float"); |
|
58 |
pojo.setOutPutId("0001"); |
|
59 |
Calendar calendar = Calendar.getInstance(); |
|
60 |
calendar.add(Calendar.HOUR_OF_DAY, -1); |
|
61 |
|
|
62 |
List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, calendar.getTime(), Calendar.getInstance().getTime()); |
|
63 |
|
|
64 |
System.out.println("value=" + influxModelResultVOS); |
|
65 |
|
|
66 |
} |
|
67 |
} |