修改 influxdb query函数
Этот коммит содержится в:
родитель
515df64760
Коммит
2d9b0ea1f1
@ -44,13 +44,13 @@ public class SysRoleController {
|
||||
|
||||
@GetMapping("page")
|
||||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
|
||||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
|
||||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
|
||||
@ApiImplicitParam(name = "name", value = "角色名", paramType = "query", dataTypeClass=String.class)
|
||||
})
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
|
||||
// @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
|
||||
// @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
|
||||
// @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
|
||||
// @ApiImplicitParam(name = "name", value = "角色名", paramType = "query", dataTypeClass=String.class)
|
||||
// })
|
||||
@PreAuthorize("@ex.hasAuthority('sys:role:page')")
|
||||
public Result<PageData<SysRoleDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
PageData<SysRoleDTO> page = sysRoleService.page(params);
|
||||
|
@ -146,14 +146,21 @@ public enum InfluxClient {
|
||||
List<String> dropedTagNames = param.getDropedTagNames();
|
||||
Range range = param.getRange();
|
||||
String bucket = param.getBucket();
|
||||
String tagName = param.getTag().getTagName();
|
||||
String tagValue = param.getTag().getTagValue();
|
||||
|
||||
|
||||
|
||||
PageInfo pageInfo = param.getPageInfo();
|
||||
|
||||
String flux = "from(bucket:\""+bucket+"\")";
|
||||
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
|
||||
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
|
||||
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
|
||||
|
||||
if(param.getTag()!=null){
|
||||
String tagName = param.getTag().getTagName();
|
||||
String tagValue = param.getTag().getTagValue();
|
||||
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
|
||||
}
|
||||
|
||||
//调整时区,查询出的结果 +8个小时
|
||||
flux += "|> timeShift(duration: 8h)";
|
||||
for(String dropName:dropedTagNames){
|
||||
|
@ -29,8 +29,9 @@ public class S7DemoController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class);
|
||||
|
||||
|
||||
@PostMapping("/insertBatch")
|
||||
public void insertBatch() throws InterruptedException {
|
||||
//for 常规计量型
|
||||
@PostMapping("/insertDemoDataForMetering")
|
||||
public void insertDemoDataForMetering() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
|
||||
@ -47,17 +48,15 @@ public class S7DemoController {
|
||||
}else {
|
||||
event.setArgValue("1");
|
||||
}
|
||||
|
||||
// Double d = r.nextDouble() * 2.5 + 66;
|
||||
// event.setArgValue(d);
|
||||
|
||||
list.add(event);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weight");
|
||||
}
|
||||
|
||||
@PostMapping("/forTestInsertBatch")
|
||||
public void forTestInsertBatch() throws InterruptedException {
|
||||
|
||||
//for 常规计数型
|
||||
@PostMapping("/insertDemoDataForCount")
|
||||
public void insertDemoDataForCount() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
|
||||
@ -75,199 +74,199 @@ public class S7DemoController {
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weight");
|
||||
}
|
||||
|
||||
@PostMapping("/insertBatchJYD")
|
||||
public void insertBatchJYD() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
Instant instant = DataUtils.getBeforeDate(400).toInstant();
|
||||
|
||||
for(int j=0;j<10;j++){
|
||||
for(int i=0;i<99;i++){
|
||||
Thread.sleep(10);
|
||||
Event event = new Event();
|
||||
event.setTime(instant);
|
||||
event.setTransationId("asas"+i);
|
||||
event.setArgName("LTWeight");
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setInspectionSheetId(j+"");
|
||||
event.setArgValue(d.toString());
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"WeightHei");
|
||||
}
|
||||
|
||||
@PostMapping("/insertAndQuery")
|
||||
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("4444");
|
||||
event.setBatchNum("44");
|
||||
event.setArgName("forUpdate");
|
||||
event.setArgValue("5555.1");
|
||||
InfluxClient.Client.insert(event,"FORUPDATECAIXIANG");
|
||||
// Thread.sleep(50000);
|
||||
// @PostMapping("/insertBatchJYD")
|
||||
// public void insertBatchJYD() throws InterruptedException {
|
||||
// List<Event> list = new ArrayList<>();
|
||||
// Random r = new Random();
|
||||
// Instant instant = DataUtils.getBeforeDate(400).toInstant();
|
||||
//
|
||||
// for(int j=0;j<10;j++){
|
||||
// for(int i=0;i<99;i++){
|
||||
// Thread.sleep(10);
|
||||
// Event event = new Event();
|
||||
// event.setTime(instant);
|
||||
// event.setTransationId("asas"+i);
|
||||
// event.setArgName("LTWeight");
|
||||
// Double d = r.nextDouble() * 2.5 + 66;
|
||||
// event.setInspectionSheetId(j+"");
|
||||
// event.setArgValue(d.toString());
|
||||
// event.setBatchNum(i+"");
|
||||
// list.add(event);
|
||||
// }
|
||||
// }
|
||||
// InfluxClient.Client.batchInsert(list,"WeightHei");
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/insertAndQuery")
|
||||
// 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("4444");
|
||||
// event.setBatchNum("44");
|
||||
// event.setArgName("forUpdate");
|
||||
// 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("FORUPDATECAIXIANG");
|
||||
//// List<String> 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<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
//// System.out.println();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @PostMapping("/insertBatchJYDForTest")
|
||||
// public void insertBatchJYDForTest() throws InterruptedException {
|
||||
// List<Event> list = new ArrayList<>();
|
||||
// Random r = new Random();
|
||||
//
|
||||
// for(int i=0;i<999;i++){
|
||||
// Thread.sleep(10);
|
||||
// Event event = new Event();
|
||||
// event.setTime(DataUtils.getAfterDate(i).toInstant());
|
||||
// event.setTransationId("asas"+i);
|
||||
// event.setArgName("LostDays");
|
||||
// int i1 = r.nextInt(10);
|
||||
// if(i1<4){
|
||||
// event.setArgValue("0");
|
||||
// }else {
|
||||
// event.setArgValue("1");
|
||||
// }
|
||||
// event.setInspectionSheetId(i+"");
|
||||
//
|
||||
// event.setBatchNum(i+"");
|
||||
// list.add(event);
|
||||
// }
|
||||
// InfluxClient.Client.batchInsert(list,"Weights");
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/insertBatchForNew")
|
||||
// public void insertBatchForNew() throws InterruptedException {
|
||||
// List<Event> list = new ArrayList<>();
|
||||
// Random r = new Random();
|
||||
//
|
||||
// for(int i=0;i<999;i++){
|
||||
// Thread.sleep(10);
|
||||
// Event event = new Event();
|
||||
// event.setTime(new Date().toInstant());
|
||||
// event.setTransationId("asas"+i);
|
||||
// event.setArgName("LiuWeight");
|
||||
//// int i1 = r.nextInt(10);
|
||||
//// if(i1<4){
|
||||
//// event.setArgValue(new Double(0));
|
||||
//// }else {
|
||||
//// event.setArgValue(new Double(1));
|
||||
//// }
|
||||
// Double d = r.nextDouble() * 2.5 + 66;
|
||||
// event.setArgValue(d.toString());
|
||||
// event.setInspectionSheetId(i+"");
|
||||
//
|
||||
// event.setBatchNum(i+"");
|
||||
// list.add(event);
|
||||
// }
|
||||
// InfluxClient.Client.batchInsert(list,"Weights");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 测试连接是否正常
|
||||
// *
|
||||
// * @return
|
||||
// * true 服务正常健康
|
||||
// * false 异常
|
||||
// */
|
||||
// @PostMapping("/ping")
|
||||
// public void ping() throws InterruptedException {
|
||||
// boolean ping = InfluxClient.Client.ping();
|
||||
// System.out.println(ping);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/query")
|
||||
// public void query() throws InterruptedException {
|
||||
// List<Event> list = new ArrayList<>();
|
||||
//
|
||||
// event.setArgValue(333.3);
|
||||
// InfluxClient.Client.insert(event,"FORUPDATE");
|
||||
|
||||
|
||||
// QueryDataParam queryDataParam = new QueryDataParam();
|
||||
// queryDataParam.setBucket("qgs-bucket");
|
||||
// queryDataParam.setMeasurement("FORUPDATECAIXIANG");
|
||||
// queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||
// List<String> 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.setTag(new Tag("argName","arg6"));
|
||||
// queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||
// queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
// List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
// System.out.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/insertBatchJYDForTest")
|
||||
public void insertBatchJYDForTest() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
|
||||
for(int i=0;i<999;i++){
|
||||
Thread.sleep(10);
|
||||
Event event = new Event();
|
||||
event.setTime(DataUtils.getAfterDate(i).toInstant());
|
||||
event.setTransationId("asas"+i);
|
||||
event.setArgName("LostDays");
|
||||
int i1 = r.nextInt(10);
|
||||
if(i1<4){
|
||||
event.setArgValue("0");
|
||||
}else {
|
||||
event.setArgValue("1");
|
||||
}
|
||||
event.setInspectionSheetId(i+"");
|
||||
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weights");
|
||||
}
|
||||
|
||||
@PostMapping("/insertBatchForNew")
|
||||
public void insertBatchForNew() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
|
||||
for(int i=0;i<999;i++){
|
||||
Thread.sleep(10);
|
||||
Event event = new Event();
|
||||
event.setTime(new Date().toInstant());
|
||||
event.setTransationId("asas"+i);
|
||||
event.setArgName("LiuWeight");
|
||||
// int i1 = r.nextInt(10);
|
||||
// if(i1<4){
|
||||
// event.setArgValue(new Double(0));
|
||||
// }else {
|
||||
// event.setArgValue(new Double(1));
|
||||
//
|
||||
//
|
||||
// for (FluxTable fluxTable : query) {
|
||||
// List<FluxRecord> records = fluxTable.getRecords();
|
||||
// for (FluxRecord fluxRecord : records) {
|
||||
// System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||
// }
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setArgValue(d.toString());
|
||||
event.setInspectionSheetId(i+"");
|
||||
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weights");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试连接是否正常
|
||||
*
|
||||
* @return
|
||||
* true 服务正常健康
|
||||
* false 异常
|
||||
*/
|
||||
@PostMapping("/ping")
|
||||
public void ping() throws InterruptedException {
|
||||
boolean ping = InfluxClient.Client.ping();
|
||||
System.out.println(ping);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public void query() throws InterruptedException {
|
||||
List<Event> list = new ArrayList<>();
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
queryDataParam.setTag(new Tag("argName","arg6"));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
|
||||
|
||||
for (FluxTable fluxTable : query) {
|
||||
List<FluxRecord> records = fluxTable.getRecords();
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Event> list = new ArrayList<>();
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
queryDataParam.setTag(new Tag("argName","arg7"));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||
queryDataParam.setPageInfo(new PageInfo(2,10));
|
||||
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
|
||||
|
||||
for (FluxTable fluxTable : query) {
|
||||
List<FluxRecord> records = fluxTable.getRecords();
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Point insert(Event event, String measurement){
|
||||
Point point = Point.measurement(measurement)
|
||||
.addTag("transationId", event.getTransationId())
|
||||
.addTag("argName", event.getArgName())
|
||||
.addField("argValue", event.getArgValue())
|
||||
.time(event.getTime().toEpochMilli(), WritePrecision.MS);
|
||||
return point;
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public void insert() throws InterruptedException {
|
||||
Event event = new Event();
|
||||
event.setTime(Instant.now());
|
||||
event.setTransationId("asasd11");
|
||||
event.setArgName("argName11");
|
||||
event.setArgValue("900001");
|
||||
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
||||
InfluxClient.Client.insert(event,"ASProcessCompleteEvent");
|
||||
}
|
||||
// }
|
||||
// System.out.println();
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// List<Event> list = new ArrayList<>();
|
||||
//
|
||||
// QueryDataParam queryDataParam = new QueryDataParam();
|
||||
// queryDataParam.setBucket("qgs-bucket");
|
||||
// queryDataParam.setMeasurement("ASProcessCompleteEventAS");
|
||||
// List<String> dropNames = new ArrayList<>();
|
||||
// dropNames.add("transationId");
|
||||
// dropNames.add("inspectionSheetId");
|
||||
// queryDataParam.setDropedTagNames(dropNames);
|
||||
// queryDataParam.setTag(new Tag("argName","arg7"));
|
||||
// queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(),Instant.now()));
|
||||
// queryDataParam.setPageInfo(new PageInfo(2,10));
|
||||
// List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
//
|
||||
//
|
||||
// for (FluxTable fluxTable : query) {
|
||||
// List<FluxRecord> records = fluxTable.getRecords();
|
||||
// for (FluxRecord fluxRecord : records) {
|
||||
// System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public Point insert(Event event, String measurement){
|
||||
// Point point = Point.measurement(measurement)
|
||||
// .addTag("transationId", event.getTransationId())
|
||||
// .addTag("argName", event.getArgName())
|
||||
// .addField("argValue", event.getArgValue())
|
||||
// .time(event.getTime().toEpochMilli(), WritePrecision.MS);
|
||||
// return point;
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/insert")
|
||||
// public void insert() throws InterruptedException {
|
||||
// Event event = new Event();
|
||||
// event.setTime(Instant.now());
|
||||
// event.setTransationId("asasd11");
|
||||
// event.setArgName("argName11");
|
||||
// event.setArgValue("900001");
|
||||
// Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
||||
// InfluxClient.Client.insert(event,"ASProcessCompleteEvent");
|
||||
// }
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class QueryDataParam extends BaseParam{
|
||||
//如果tag不传,就是查询所有
|
||||
private Tag tag;
|
||||
//查询的时候,需要忽略的字段。(transationId是唯一标识会对 最终的查询结果集产生影响)
|
||||
private List<String> dropedTagNames;
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user