From f7712f184a9d5cae6c2e190797bb2aeec7672501 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Thu, 1 Dec 2022 15:33:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E8=AF=BB=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cnbm/influx/config/InfluxClient.java | 28 ++++++++++----- .../influx/controller/S7DemoController.java | 36 ++++++++++--------- .../java/com/cnbm/influx/template/Event.java | 13 ++++--- 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java b/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java index be3628b..e311485 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java +++ b/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java @@ -76,21 +76,28 @@ public enum InfluxClient { return isConnected; } + /** + * desc: 异步批量 写入数据/更新数据 + * notes: 如果是更新数据,要保证time字段不能改变 + * auth: caixaing + * */ public void insert(Event event, String measurement){ Point point = null; if(event.getBatchNum()==null){ point = Point.measurement(measurement) .addTag("transationId", event.getTransationId()) - .addTag("inspectionSheetId", event.getInspectionSheetId()) .addTag("argName", event.getArgName()) .addField("argValue", event.getArgValue()) .time(event.getTime().toEpochMilli(), WritePrecision.MS); }else { point = Point.measurement(measurement) .addTag("transationId", event.getTransationId()) - //.addTag("inspectionSheetId", event.getInspectionSheetId()) - .addTag("batchNum", event.getBatchNum().toString()) + + .addTag("inspectionSheetId", event.getInspectionSheetId()) + .addTag("sampleNumber", event.getSampleNumber()) + .addTag("batchNum", event.getBatchNum()) + .addTag("argName", event.getArgName()) .addField("argValue", event.getArgValue()) .time(event.getTime().toEpochMilli(), WritePrecision.MS); @@ -99,8 +106,11 @@ public enum InfluxClient { } - //异步 批量写入数据 - //如果要批量插入的话,一次也只能写入 + /** + * desc: 异步批量 写入数据/更新数据 + * notes: 如果是更新数据,要保证time字段不能改变 + * auth: caixaing + * */ public void batchInsert(List events, String measurement){ List list = new ArrayList<>(); for(Event event:events){ @@ -108,15 +118,17 @@ public enum InfluxClient { if(event.getBatchNum()==null){ point = Point.measurement(measurement) .addTag("transationId", event.getTransationId()) - .addTag("inspectionSheetId", event.getInspectionSheetId()) .addTag("argName", event.getArgName()) .addField("argValue", event.getArgValue()) .time(event.getTime().toEpochMilli(), WritePrecision.MS); }else { point = Point.measurement(measurement) .addTag("transationId", event.getTransationId()) - //.addTag("inspectionSheetId", event.getInspectionSheetId()) - .addTag("batchNum", event.getBatchNum().toString()) + + .addTag("inspectionSheetId", event.getInspectionSheetId()) + .addTag("sampleNumber", event.getSampleNumber()) + .addTag("batchNum", event.getBatchNum()) + .addTag("argName", event.getArgName()) .addField("argValue", event.getArgValue()) .time(event.getTime().toEpochMilli(), WritePrecision.MS); diff --git a/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java b/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java index bf0c388..2d9adc4 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java +++ b/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java @@ -103,30 +103,34 @@ public class S7DemoController { public void insertAndQuery() throws InterruptedException { Event event = new Event(); +// long l = System.currentTimeMillis(); +// System.out.println("l:"+l); +// event.setTime(new Date(1669874900889l).toInstant()); +// event.setTime(new Date().toInstant()); - event.setTransationId("2344"); - event.setBatchNum("22"); + event.setTransationId("4444"); + event.setBatchNum("44"); event.setArgName("forUpdate"); - event.setArgValue("124.1"); - InfluxClient.Client.insert(event,"FORUPDATEEEE"); + event.setArgValue("5555.1"); + InfluxClient.Client.insert(event,"FORUPDATECAIXIANG"); // Thread.sleep(50000); // // event.setArgValue(333.3); // InfluxClient.Client.insert(event,"FORUPDATE"); - QueryDataParam queryDataParam = new QueryDataParam(); - queryDataParam.setBucket("qgs-bucket"); - queryDataParam.setMeasurement("FORUPDATEEEE"); - List dropNames = new ArrayList<>(); - dropNames.add("transationId"); - dropNames.add("inspectionSheetId"); - queryDataParam.setDropedTagNames(dropNames); - queryDataParam.setTag(new Tag("argName","forUpdate")); - queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(),DataUtils.getAfterDate(999).toInstant())); - queryDataParam.setPageInfo(new PageInfo(1,10)); - List query = InfluxClient.Client.query(queryDataParam); - System.out.println(); +// QueryDataParam queryDataParam = new QueryDataParam(); +// queryDataParam.setBucket("qgs-bucket"); +// queryDataParam.setMeasurement("FORUPDATECAIXIANG"); +// List dropNames = new ArrayList<>(); +// dropNames.add("transationId"); +// dropNames.add("inspectionSheetId"); +// queryDataParam.setDropedTagNames(dropNames); +// queryDataParam.setTag(new Tag("argName","forUpdate")); +// queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(),DataUtils.getAfterDate(999).toInstant())); +// queryDataParam.setPageInfo(new PageInfo(1,10)); +// List query = InfluxClient.Client.query(queryDataParam); +// System.out.println(); } diff --git a/ym-influx/src/main/java/com/cnbm/influx/template/Event.java b/ym-influx/src/main/java/com/cnbm/influx/template/Event.java index 1d6205d..24c8124 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/template/Event.java +++ b/ym-influx/src/main/java/com/cnbm/influx/template/Event.java @@ -23,12 +23,17 @@ public class Event { private String argValue; - private String BatchNum; + //batchNumber(必填), 作为区分 手动录入 和 自动录入的区别 + private String batchNum; - private String InspectionSheetId; + private String inspectionSheetId; + + private String sampleNumber; public Event() { - BatchNum = "1"; - InspectionSheetId = "1"; + //自动录入,给个默认值 + this.batchNum = "-1"; + this.inspectionSheetId = "-1"; + this.sampleNumber = "-1"; } } \ No newline at end of file