commit for pull

This commit is contained in:
caixiang 2023-01-03 16:29:18 +08:00
parent 9b545a9a03
commit c1d37a3dbc
4 changed files with 96 additions and 9 deletions

View File

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

View File

@ -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;
}

View File

@ -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("成功");
}
}

View File

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