This commit is contained in:
caixiang 2023-01-03 16:29:18 +08:00
джерело 9b545a9a03
коміт c1d37a3dbc
4 змінених файлів з 96 додано та 9 видалено

@ -141,13 +141,18 @@ public enum InfluxClient {
public List<FluxTable> query(QueryDataParam param){
String measurement = param.getMeasurement();
List<String> dropedTagNames = param.getDropedTagNames();
Range range = param.getRange();
String bucket = param.getBucket();
PageInfo pageInfo = param.getPageInfo();
String flux = "from(bucket:\""+bucket+"\")";
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
if(param.getRange() != null){
Range range = param.getRange();
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
}
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
if(param.getTags()!=null && param.getTags().size()>0){
@ -161,12 +166,16 @@ public enum InfluxClient {
//调整时区查询出的结果 +8个小时
//flux += "|> timeShift(duration: 8h)";
for(String dropName:dropedTagNames){
flux += "|> drop(columns: [\""+dropName+"\"])";
if(param.getDropedTagNames() != null){
List<String> dropedTagNames = param.getDropedTagNames();
for(String dropName:dropedTagNames){
flux += "|> drop(columns: [\""+dropName+"\"])";
}
}
flux += "|> sort(columns: [\"_time\"], desc: true)";
if(pageInfo!=null){
if(param.getPageInfo() != null){
PageInfo pageInfo = param.getPageInfo();
flux += "|> limit(n: "+pageInfo.getSize()+", offset: "+(pageInfo.getCurrent()-1)* pageInfo.getSize()+")";
}
return queryApi.query(flux);

@ -0,0 +1,25 @@
package com.cnbm.influx.controller;
import com.cnbm.influx.template.Event;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.Instant;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/12/9 15:53
*/
@Data
@ApiModel(value = "Events")
public class InfluxData {
@ApiModelProperty("ID (transationId、argName、argValue、time 必填)")
private List<Event> events;
@ApiModelProperty("measurement(相当于mysql 中的table一台工艺设备一个measurement)")
private String measurement;
}

@ -0,0 +1,49 @@
package com.cnbm.influx.controller;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.param.Range;
import com.cnbm.influx.param.Tag;
import com.cnbm.influx.template.Event;
import com.influxdb.query.FluxTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
import java.util.*;
@RestController
@RequestMapping("/spcData")
public class SPCController {
private static final Logger logger = LoggerFactory.getLogger(SPCController.class);
@PostMapping("/getData")
public Result getData(@RequestBody QueryDataParam param) throws InterruptedException {
List<FluxTable> query = InfluxClient.Client.query(param);
return new Result<List<FluxTable>>().ok(query);
}
@PostMapping("/insertOrUpdate")
public Result insertBatchForNew(@RequestBody InfluxData data){
if(data.getEvents()== null || data.getMeasurement()== null){
return new Result().error("传入events 或者 measurement为空");
}
try {
InfluxClient.Client.batchInsert(data.getEvents(),data.getMeasurement());
}catch (Exception e){
return new Result().ok("influxdb 操作异常");
}
return new Result().error("成功");
}
}

@ -1,10 +1,12 @@
package com.cnbm.influx.controller;
import com.cnbm.influx.template.Event;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.Instant;
import java.util.List;
/**
* @Desc: ""
@ -14,7 +16,9 @@ import java.time.Instant;
@Data
@ApiModel(value = "检验样本 DTO对象")
public class TIMETest {
@ApiModelProperty(value = "时间2")
@ApiModelProperty(value = "Events")
private Instant time2;
}