diff --git a/src/main/java/com/qgs/dc/influx/config/InfluxClient.java b/src/main/java/com/qgs/dc/influx/config/InfluxClient.java index b8b8eec..96b6886 100644 --- a/src/main/java/com/qgs/dc/influx/config/InfluxClient.java +++ b/src/main/java/com/qgs/dc/influx/config/InfluxClient.java @@ -80,20 +80,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); @@ -102,20 +110,11 @@ public enum InfluxClient { } - //异步 批量写入数据 - //如果要批量插入的话,一次也只能写入 -// public void batchInsert(List events, String measurement){ -// List list = new ArrayList<>(); -// for(Event event:events){ -// Point point = Point.measurement(measurement) -// .addTag("transationId", event.getTransationId()) -// .addTag("argName", event.getArgName()) -// .addField("argValue", event.getArgValue()) -// .time(event.getTime().toEpochMilli(), WritePrecision.MS); -// list.add(point); -// } -// writeApi.writePoints(list); -// } + /** + * desc: 异步批量 写入数据/更新数据 + * notes: 如果是更新数据,要保证time字段不能改变 + * auth: caixaing + * */ public void batchInsert(List events, String measurement){ List list = new ArrayList<>(); for(Event event:events){ @@ -123,15 +122,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/src/main/java/com/qgs/dc/influx/template/Event.java b/src/main/java/com/qgs/dc/influx/template/Event.java index c551ebc..19f997c 100644 --- a/src/main/java/com/qgs/dc/influx/template/Event.java +++ b/src/main/java/com/qgs/dc/influx/template/Event.java @@ -20,9 +20,19 @@ public class Event { private String argValue; - private String BatchNum; + //batchNumber(必填), 作为区分 手动录入 和 自动录入的区别 + private String batchNum; - private String InspectionSheetId; + private String inspectionSheetId; + + private String sampleNumber; + + public Event() { + //自动录入,给个默认值 + this.batchNum = "-1"; + this.inspectionSheetId = "-1"; + this.sampleNumber = "-1"; + } }