diff --git a/pom.xml b/pom.xml index 1cc97e5..6c50320 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.qyi e5 - 1.0.7 + 1.0.8 e5 Demo project for Spring Boot diff --git a/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java b/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java index 2502999..7a5c75f 100644 --- a/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java +++ b/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java @@ -17,7 +17,7 @@ public class InfluxdbConfig { @Bean public InfluxDBClient influxDBClient() { InfluxDBClient influxDBClient = InfluxDBClientFactory.create(influxDBUrl, token.toCharArray()); - influxDBClient.setLogLevel(LogLevel.BASIC); + influxDBClient.setLogLevel(LogLevel.NONE); return influxDBClient; } diff --git a/src/main/java/io/qyi/e5/config/Start.java b/src/main/java/io/qyi/e5/config/Start.java index 9030b97..84d6c8d 100644 --- a/src/main/java/io/qyi/e5/config/Start.java +++ b/src/main/java/io/qyi/e5/config/Start.java @@ -38,13 +38,17 @@ public class Start { @Value("${e5.system.threadPool}") Integer poolSize; + @Value("${isdebug:true}") + private boolean isdebug; + + private ExecutorService threadPool; @PostConstruct public void init() { - log.info("清空redis...... "); - redisUtil.delAll(); + // log.info("清空redis...... "); + // redisUtil.delAll(); threadPool = new ThreadPoolExecutor( //指定了线程池中的线程数量,它的数量决定了添加的任务是开辟新的线程去执行,还是放到workQueue任务队列中去; poolSize, @@ -64,8 +68,12 @@ public class Start { } - // @Scheduled(cron = "0 0/1 * * * ? ") + @Scheduled(cron = "0 0/1 * * * ? ") private void distributeTask() { + if (isdebug) { + log.debug("Debug模式,跳过执行"); + return; + } List runOutlookList = outlookService.findRunOutlookList(); CountDownLatch cdl = new CountDownLatch(runOutlookList.size()); diff --git a/src/main/java/io/qyi/e5/controller/web/WebController.java b/src/main/java/io/qyi/e5/controller/web/WebController.java index 04acdb7..7687d21 100644 --- a/src/main/java/io/qyi/e5/controller/web/WebController.java +++ b/src/main/java/io/qyi/e5/controller/web/WebController.java @@ -59,7 +59,7 @@ public class WebController { public Result delete(){ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); /*删除数据库信息*/ - int outlooklog = iOutlookLogService.deleteInfo(authentication.getGithub_id()); + // int outlooklog = iOutlookLogService.deleteInfo(authentication.getGithub_id()); int outlook = outlookService.deleteInfo(authentication.getGithub_id()); int github = GithubService.deleteInfo(authentication.getGithub_id()); /*删除redis中信息*/ @@ -69,7 +69,7 @@ public class WebController { } /*返回结果信息*/ Map map = new HashMap<>(); - map.put("outlooklog", outlooklog); + // map.put("outlooklog", outlooklog); map.put("outlook", outlook); map.put("github", github); return ResultUtil.success(map); 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 6424c7f..1f9d1c6 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 @@ -1,15 +1,7 @@ package io.qyi.e5.outlook_log.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.influxdb.client.InfluxDBClient; -import com.influxdb.client.QueryApi; -import com.influxdb.client.WriteApi; -import com.influxdb.client.WriteOptions; -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.bean.result.Result; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.service.IOutlookService; @@ -17,8 +9,6 @@ import io.qyi.e5.outlook_log.bena.LogVo; import io.qyi.e5.outlook_log.entity.OutlookLog; import io.qyi.e5.outlook_log.service.IOutlookLogService; import io.qyi.e5.util.ResultUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -29,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import java.time.Instant; -import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -73,20 +61,8 @@ public class OutlookLogController { public Result findLog(@RequestParam int outlookId){ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); - - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("github_id", github_id).eq("outlook_id", outlookId).orderByAsc("call_time"); - List list = outlookLogService.findAllList(github_id, outlookId); - Iterator iterator = list.iterator(); - List logVo = new LinkedList<>(); - while (iterator.hasNext()) { - OutlookLog next = iterator.next(); - LogVo vo = new LogVo(); - BeanUtils.copyProperties(next,vo); - logVo.add(vo); - } - return ResultUtil.success(logVo); + return ResultUtil.success(list); } } 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 1b1514b..38e6c7a 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 @@ -43,14 +43,14 @@ public class OutlookLog { /** * 调用时间 */ - @Column(timestamp = true) - private Instant callTime; + @Column + private long callTime; /** * 调用结果 */ @Column - private Number resultc; + private Number result; /** * 如果有错误原因则记录 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 fbdf8d2..a8ddb7e 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 @@ -15,6 +15,6 @@ import java.util.List; */ public interface IOutlookLogService { void addLog(int githubId,int outlookId, String msg,int result,String original_msg); - int deleteInfo(int github_id); + // 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 8d44681..fd7be19 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,12 +1,15 @@ package io.qyi.e5.outlook_log.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.influxdb.client.InfluxDBClient; -import com.influxdb.client.InfluxDBClientFactory; +import com.influxdb.client.QueryApi; +import com.influxdb.client.WriteApi; +import com.influxdb.client.domain.WritePrecision; import io.qyi.e5.outlook_log.entity.OutlookLog; import io.qyi.e5.outlook_log.service.IOutlookLogService; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.List; /** @@ -20,33 +23,40 @@ import java.util.List; @Service public class OutlookLogServiceImpl implements IOutlookLogService { + @Resource + private InfluxDBClient influxDBClient; + @Value("${spring.influx.org}") + private String org; + + @Value("${spring.influx.bucket}") + private String bucket; @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) - // .setMsg(msg) - // .setOriginalMsg(original_msg); + try (WriteApi writeApi = influxDBClient.getWriteApi()) { + OutlookLog log = new OutlookLog(); + log.setCallTime(System.currentTimeMillis()) + .setGithubId(String.valueOf(githubId)) + .setOutlookId(String.valueOf(outlookId)) + .setMsg(msg) + .setOriginalMsg(original_msg) + .setResult(result); + writeApi.writeMeasurement(bucket, org, WritePrecision.NS, log); - // 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 0; } @Override public List findAllList(int githubId, int outlookId) { - // return baseMapper.findAllList(githubId, outlookId); - return null; + String flux = "from(bucket:\"" + bucket + "\") |> range(start: 0)" + + "|> filter(fn: (r) => r[\"_measurement\"] == \"OutlookLog\")" + + "|> filter(fn: (r) => r[\"githubId\"] == \"" + githubId + "\")" + + "|> filter(fn: (r) => r[\"outlookId\"] == \"" + outlookId + "\")" + + "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; + QueryApi queryApi = influxDBClient.getQueryApi(); + List tables = queryApi.query(flux, org, OutlookLog.class); + return tables; } } diff --git a/src/test/java/influxdb2Test.java b/src/test/java/influxdb2Test.java index edd9314..b32c266 100644 --- a/src/test/java/influxdb2Test.java +++ b/src/test/java/influxdb2Test.java @@ -8,11 +8,12 @@ import io.qyi.e5.outlook_log.entity.OutlookLog; import org.junit.jupiter.api.Test; import org.springframework.cglib.beans.BeanMap; -import java.time.Instant; import java.util.*; public class influxdb2Test { - InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://127.0.0.1:8086", "ko6GtE_P5R2AlMkCBkEgBwW7rVBl46GYx0IoCrG-Dd5VFxTDSnFJ--BB2f8FRFcGd6Tb_yu6-MlMAD-lMSbH6A==".toCharArray() + String token = "HquxNXwOyfgW-f8wzkSUuBz0tswWiFPsTbEnr5jKFS3BY3RcKezDdQF0o5yeoNfaiwQUJhy8YJSIUrVrWSQn8Q=="; + + InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://127.0.0.1:8086", token.toCharArray() ); private String org = "luoye"; @@ -22,7 +23,7 @@ public class influxdb2Test { .build(); @Test - public void save(){ + public void save() { influxDBClient.setLogLevel(LogLevel.BASIC); WriteOptions writeOptions = WriteOptions.builder() @@ -36,13 +37,13 @@ public class influxdb2Test { List list = new ArrayList<>(); for (int i = 0; i < 100; i++) { OutlookLog outlookLog = new OutlookLog(); - outlookLog.setMsg(i + "- ok").setOriginalMsg("加入成功").setCallTime(Instant.now()); + outlookLog.setMsg(i + "- ok").setOriginalMsg("加入成功").setCallTime(System.currentTimeMillis()); list.add(outlookLog); } try (WriteApi writeApi = influxDBClient.getWriteApi()) { // writeApi.writeMeasurement("e5", org ,WritePrecision.NS,outlookLog); - writeApi.writeMeasurements("e5", org ,WritePrecision.NS,list); + writeApi.writeMeasurements("e5", org, WritePrecision.NS, list); List list1 = new ArrayList<>(); list.forEach(outlookLog -> { @@ -57,70 +58,70 @@ public class influxdb2Test { System.out.println("list 大小:" + list1.size()); Map aa = new HashMap<>(); aa.put("a1", 1); - writeApi.writePoint("e5",org,list1.get(0)); + writeApi.writePoint("e5", org, list1.get(0)); } influxDBClient.close(); } @Test - public void saveLog(){ + public void saveLog() { influxDBClient.setLogLevel(LogLevel.BASIC); - - addLog(1002, 37,"error", 0, "检测到3次连续错误,下次将不再自动调用,请修正错误后再授权开启续订。"); - for (int i = 0; i < 10000; i++) { - - } - + // for (int i = 0; i < 1000; i++) { + addLog(19658189, 4959, "error", 1, "检测到3次连续错误,下次将不再自动调用,请修正错误后再授权开启续订。"); + // } + influxDBClient.close(); } public void addLog(int githubId, int outlookId, String msg, int result, String original_msg) { try (WriteApi writeApi = influxDBClient.getWriteApi()) { - List list = new ArrayList<>(); - for (int i = 0; i < 10000; i++) { + // List + // for (int i = 0; i < 10000; i++) { OutlookLog log = new OutlookLog(); - log.setCallTime(Instant.now()) - .setGithubId(String.valueOf(githubId) ) + log.setCallTime(System.currentTimeMillis()) + .setGithubId(String.valueOf(githubId)) .setOutlookId(String.valueOf(outlookId)) .setMsg(msg) .setOriginalMsg(original_msg) - .setResultc(result) - .setCallTime(Instant.now()); - list.add(log); + .setResult(result); + Thread.sleep(1); + writeApi.writeMeasurement("e5", org, WritePrecision.NS, log); + // } - } - writeApi.writeMeasurements("e5",org, WritePrecision.NS, list); - influxDBClient.close(); + + } catch (InterruptedException e) { + e.printStackTrace(); } } + public void addLog2(int githubId, int outlookId, String msg, int result, String original_msg) { try (WriteApi writeApi = influxDBClient.getWriteApi()) { Point point = Point.measurement("OutlookLog") - .addTag("githubId",String.valueOf(githubId)) - .addTag("outlookId",String.valueOf(outlookId)) + .addTag("githubId", String.valueOf(githubId)) + .addTag("outlookId", String.valueOf(outlookId)) .addField("msg", msg) .addField("resultc", result) .addField("originalMsg", original_msg); - writeApi.writePoint("e5",org,point); + writeApi.writePoint("e5", org, point); } } @Test - public void find(){ + public void find() { String flux = "from(bucket:\"e5\") |> range(start: 0)" + "|> filter(fn: (r) => r[\"_measurement\"] == \"OutlookLog\")" + "|> filter(fn: (r) => r[\"githubId\"] == \"1002\")" + "|> filter(fn: (r) => r[\"outlookId\"] == \"37\")" + "|> limit(n: 100)"; QueryApi queryApi = influxDBClient.getQueryApi(); - List tables = queryApi.query(flux,org); + List tables = queryApi.query(flux, org); for (FluxTable fluxTable : tables) { - List records = fluxTable .getRecords(); + List records = fluxTable.getRecords(); for (FluxRecord fluxRecord : records) { // System.out.println(fluxRecord.getField()); @@ -132,14 +133,15 @@ public class influxdb2Test { } @Test - public void findPojo(){ + public void findPojo() { String flux = "from(bucket:\"e5\") |> range(start: 0)" + "|> filter(fn: (r) => r[\"_measurement\"] == \"OutlookLog\")" + "|> filter(fn: (r) => r[\"githubId\"] == \"1002\")" + + "|> filter(fn: (r) => r[\"outlookId\"] == \"38\")" + "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; QueryApi queryApi = influxDBClient.getQueryApi(); System.out.println(System.currentTimeMillis()); - List tables = queryApi.query(flux,org,OutlookLog.class); + List tables = queryApi.query(flux, org, OutlookLog.class); System.out.println(System.currentTimeMillis()); for (OutlookLog table : tables) { if (table.getMsg() == null) { @@ -155,13 +157,14 @@ public class influxdb2Test { public void findPojoAsync() throws InterruptedException { String flux = "from(bucket:\"e5\") |> range(start: 0)" + "|> filter(fn: (r) => r[\"_measurement\"] == \"OutlookLog\")" + - "|> filter(fn: (r) => r[\"githubId\"] == \"1002\")" + - "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")" ; + "|> filter(fn: (r) => r[\"githubId\"] == \"1003\")" + + "|> filter(fn: (r) => r[\"outlookId\"] == \"39\")" + + "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")"; QueryApi queryApi = influxDBClient.getQueryApi(); - queryApi.query(flux,org,OutlookLog.class,(cancellable, outlookLog) -> { - if (outlookLog.getMsg() != null) { - System.out.println(outlookLog); - } + queryApi.query(flux, org, OutlookLog.class, (cancellable, outlookLog) -> { + if (outlookLog.getMsg() != null) { + System.out.println(outlookLog); + } }); System.out.println("查询完成");