对比新文件 |
| | |
| | | package com.iailab; |
| | | |
| | | import com.iailab.module.model.common.enums.DataTypeEnum; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO; |
| | | import com.iailab.module.model.influxdb.service.InfluxDBService; |
| | | import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2023年12月10日 12:19:00 |
| | | */ |
| | | @SpringBootTest |
| | | public class InfluxDBTest { |
| | | |
| | | @Resource |
| | | private InfluxDBService influxDBService; |
| | | |
| | | |
| | | @Test |
| | | public void testWrite() { |
| | | try { |
| | | List<InfluxModelResultPOJO> pointValues = new ArrayList<>(); |
| | | InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO(); |
| | | pojo.setOutPutId("0001"); |
| | | pojo.setType(DataTypeEnum.FLOAT.getCode()); |
| | | pojo.setTimestamp(new Date().toInstant()); |
| | | pojo.setValue(Double.valueOf(0.001)); |
| | | pointValues.add(pojo); |
| | | |
| | | InfluxModelResultSimPOJO pojo1 = new InfluxModelResultSimPOJO(); |
| | | pojo1.setOutPutId("0002"); |
| | | pojo1.setType(DataTypeEnum.FLOAT.getCode()); |
| | | pojo1.setTimestamp(new Date().toInstant()); |
| | | pojo1.setValue(Double.valueOf(0.002)); |
| | | pointValues.add(pojo1); |
| | | |
| | | influxDBService.asyncWriteModelResults(pointValues); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void testQuery() { |
| | | InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
| | | pojo.setType("float"); |
| | | pojo.setOutPutId("0001"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | |
| | | List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, calendar.getTime(), Calendar.getInstance().getTime()); |
| | | |
| | | System.out.println("value=" + influxModelResultVOS); |
| | | |
| | | } |
| | | } |