From cfeab18dd0019d9104814229f4c5effb6919ea68 Mon Sep 17 00:00:00 2001 From: LuoYe Date: Tue, 17 Aug 2021 17:56:15 +0800 Subject: [PATCH] backup --- .../controller/OutlookLogController.java | 70 +---------------- .../qyi/e5/outlook_log/entity/OutlookLog.java | 19 +++-- .../outlook_log/mapper/OutlookLogMapper.java | 24 ------ .../service/IOutlookLogService.java | 3 +- .../service/impl/OutlookLogServiceImpl.java | 29 ++++--- src/test/java/influxdb2Test.java | 76 ++++++++++++++++--- 6 files changed, 93 insertions(+), 128 deletions(-) delete mode 100644 src/main/java/io/qyi/e5/outlook_log/mapper/OutlookLogMapper.java diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index 1ca57ee..6424c7f 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -57,6 +57,7 @@ public class OutlookLogController { @Autowired InfluxDBClient influxDBClient; + @Value("${spring.influx.org:''}") private String org; @@ -64,8 +65,6 @@ public class OutlookLogController { private String bucket; - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Value("${page.size}") private int pageSize; @@ -90,71 +89,4 @@ public class OutlookLogController { return ResultUtil.success(logVo); } - - @GetMapping("/save") - public String save(){ - ArrayList arrayList = new ArrayList<>(); - for (int i = 0; i < 1000; i++) { - OutlookLog outlookLog = new OutlookLog(); - Point point = Point.measurement(bucket) - .addTag("githubid", "22121") - .addField("aaaaaa1", i) - .addField("aaaaaa2", i) - .addField("aaaaaa3", i) - .time(Instant.now().toEpochMilli(), WritePrecision.MS); - arrayList.add(point); - } - - - try (WriteApi writeApi = influxDBClient.getWriteApi()) { - // writeApi.writePoint(bucket, org, point); - writeApi.writePoints(bucket,org, arrayList); - } - return "ok"; - } - - @GetMapping("/find") - public void find(){ - String flux = "from(bucket:\"e5\") |> range(start: 0)" + - "|> filter(fn: (r) => r[\"_measurement\"] == \"e5s\")" + - // "|> filter(fn: (r) => r[\"_field\"] == \"aaaaaa1\")" + - "|> limit(n: 100)"; - - QueryApi queryApi = influxDBClient.getQueryApi(); - List tables = queryApi.query(flux,org); - for (FluxTable fluxTable : tables) { - List records = fluxTable.getRecords(); - - for (FluxRecord fluxRecord : records) { - System.out.println(fluxRecord.getField()); - System.out.println(fluxRecord.getTime() + " ->" + fluxRecord.getValueByKey("_value")); - } - } - - /*queryApi.query(flux,org,(cancellable, fluxRecord) -> { - - // - // The callback to consume a FluxRecord. - // - // cancelable - object has the cancel method to stop asynchronous query - // - System.out.println(fluxRecord.getTime() + ": " + fluxRecord.getValueByKey("_value")); - - }, throwable -> { - - // - // The callback to consume any error notification. - // - System.out.println("Error occurred: " + throwable.getMessage()); - - }, () -> { - // - // The callback to consume a notification about successfully end of stream. - // - System.out.println("Query completed"); - - });*/ - - } - } diff --git a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java index 45734e1..bea9df7 100644 --- a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java +++ b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java @@ -2,10 +2,14 @@ package io.qyi.e5.outlook_log.entity; import java.io.Serializable; import java.sql.Timestamp; +import java.time.Instant; import java.time.LocalDateTime; +import java.util.Date; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import com.influxdb.annotations.Column; +import com.influxdb.annotations.Measurement; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -19,42 +23,43 @@ import lombok.experimental.Accessors; * @since 2020-03-03 */ @Data -@EqualsAndHashCode(callSuper = false) @Accessors(chain = true) +@Measurement(name = "OutlookLog") public class OutlookLog implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.AUTO) - private Integer id; - /** * github_id */ - private Integer githubId; + // private Integer githubId; /** * outlook_id */ - private Integer outlookId; + // private Integer outlookId; /** * 调用时间 */ - private Timestamp callTime; + @Column(timestamp = true) + private Instant callTime; /** * 调用结果 */ + @Column private Integer result; /** * 如果有错误原因则记录 */ + @Column private String msg; /** * 原始错误消息 */ + @Column private String originalMsg; diff --git a/src/main/java/io/qyi/e5/outlook_log/mapper/OutlookLogMapper.java b/src/main/java/io/qyi/e5/outlook_log/mapper/OutlookLogMapper.java deleted file mode 100644 index ad24f75..0000000 --- a/src/main/java/io/qyi/e5/outlook_log/mapper/OutlookLogMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.qyi.e5.outlook_log.mapper; - -import io.qyi.e5.outlook_log.entity.OutlookLog; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.util.List; - -/** - *

- * Mapper 接口 - *

- * - * @author 落叶 - * @since 2020-03-03 - */ -public interface OutlookLogMapper extends BaseMapper { - - @Select("select * from e5.d_#{githubId}_#{outlookId}") - List findAllList(@Param("githubId") int githubId,@Param("outlookId") int outlookId); - - -} diff --git a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java index 5ca3582..fbdf8d2 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java @@ -13,9 +13,8 @@ import java.util.List; * @author 落叶 * @since 2020-03-03 */ -public interface IOutlookLogService extends IService { +public interface IOutlookLogService { void addLog(int githubId,int outlookId, String msg,int result,String original_msg); int deleteInfo(int github_id); - List findAllList(int githubId, int outlookId); } diff --git a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java index 0a8ffea..37e3549 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java @@ -1,11 +1,8 @@ package io.qyi.e5.outlook_log.service.impl; -import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.qyi.e5.outlook_log.entity.OutlookLog; -import io.qyi.e5.outlook_log.mapper.OutlookLogMapper; import io.qyi.e5.outlook_log.service.IOutlookLogService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import java.util.List; @@ -19,30 +16,32 @@ import java.util.List; * @since 2020-03-03 */ @Service -@DS("td") -public class OutlookLogServiceImpl extends ServiceImpl implements IOutlookLogService { +public class OutlookLogServiceImpl implements IOutlookLogService { + + @Override public void addLog(int githubId,int outlookId, String msg, int result,String original_msg) { - OutlookLog outlookLog = new OutlookLog(); - outlookLog.setGithubId(githubId) - .setOutlookId(outlookId) - .setResult(result) - // .setCallTime((int) (System.currentTimeMillis() / 1000)) - .setMsg(msg) - .setOriginalMsg(original_msg); + // OutlookLog outlookLog = new OutlookLog(); + // outlookLog.setGithubId(githubId) + // .setOutlookId(outlookId) + // .setResult(result) + // .setMsg(msg) + // .setOriginalMsg(original_msg); - baseMapper.insert(outlookLog); + // baseMapper.insert(outlookLog); } @Override public int deleteInfo(int github_id) { QueryWrapper outlookLogQueryWrapper = new QueryWrapper<>(); outlookLogQueryWrapper.eq("github_id", github_id); - return baseMapper.delete(outlookLogQueryWrapper); + // return baseMapper.delete(outlookLogQueryWrapper); + return 0; } @Override public List findAllList(int githubId, int outlookId) { - return baseMapper.findAllList(githubId, outlookId); + // return baseMapper.findAllList(githubId, outlookId); + return null; } } diff --git a/src/test/java/influxdb2Test.java b/src/test/java/influxdb2Test.java index b50697c..38e67c1 100644 --- a/src/test/java/influxdb2Test.java +++ b/src/test/java/influxdb2Test.java @@ -1,22 +1,76 @@ -import io.qyi.e5.bean.influx2.InfluxdbConfig; -import io.qyi.e5.outlook_log.service.IOutlookLogService; +import com.influxdb.LogLevel; +import com.influxdb.client.*; +import com.influxdb.client.domain.WritePrecision; +import com.influxdb.client.write.Point; +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; +import io.qyi.e5.outlook_log.entity.OutlookLog; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; +import org.springframework.cglib.beans.BeanMap; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; public class influxdb2Test { + InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://127.0.0.1:8086", "o-oFFLbRCFHmGFMMYR7kLFGb4jTUXkJkTCmPBeZxn32prCKxwVpS-FM3pLyCvv0gVao-Cm6c_s2Yl-7Ud_xH_Q==".toCharArray() + ); - @InjectMocks - InfluxdbConfig influxdbConfig; + private String org = "luoye"; - @Mock - IOutlookLogService outlookLogService; + @Test + public void save(){ + influxDBClient.setLogLevel(LogLevel.BASIC); + WriteOptions writeOptions = WriteOptions.builder() + .batchSize(5000) + .flushInterval(1000) + .bufferLimit(10000) + .jitterInterval(1000) + .retryInterval(5000) + .build(); + + List list = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + OutlookLog outlookLog = new OutlookLog(); + outlookLog.setResult(0).setMsg(i + "- ok").setOriginalMsg("加入成功").setCallTime(Instant.now()); + list.add(outlookLog); + } + OutlookLog outlookLog = new OutlookLog(); + outlookLog.setResult(0).setMsg(i + "- ok").setOriginalMsg("加入成功").setCallTime(Instant.now()); + BeanMap.create(outlookLog).getBean(); + try (WriteApi writeApi = influxDBClient.getWriteApi(writeOptions)) { + // writeApi.writeMeasurement(); + // writeApi.writeMeasurements("e5", org ,WritePrecision.NS,list); + Point point = Point + .measurement("githubId_123") + .addTag("githubId","123465") + .addFields(fields) + .time(Instant.now(), WritePrecision.NS); + + } + influxDBClient.close(); + } @Test - public void test1(){ - // outlookLogService.findAllList(1000, 2000); - influxdbConfig.influxDBClient(); + public void find(){ + String flux = "from(bucket:\"e5\") |> range(start: 0)" + + "|> filter(fn: (r) => r[\"_measurement\"] == \"OutlookLog\")" + + // "|> filter(fn: (r) => r[\"_field\"] == \"aaaaaa1\")" + + "|> limit(n: 100)"; + QueryApi queryApi = influxDBClient.getQueryApi(); + List tables = queryApi.query(flux,org); + for (FluxTable fluxTable : tables) { + List records = fluxTable.getRecords(); + + for (FluxRecord fluxRecord : records) { + System.out.println(fluxRecord.getField()); + System.out.println(fluxRecord.getTime() + " ->" + fluxRecord.getValueByKey("_value")); + } + } + influxDBClient.close(); } + }