方法引入调整
This commit is contained in:
@@ -61,7 +61,7 @@ public class DataTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "123456", "http://192.168.1.18:8086", "pqsbase_sjzx", "");
|
InfluxDbUtils influxDBUtil = new InfluxDbUtils("root", "123456", "http://127.0.0.1:8086", "pqsadmin_jb", "");
|
||||||
|
|
||||||
insert(influxDBUtil);
|
insert(influxDBUtil);
|
||||||
}
|
}
|
||||||
@@ -72,16 +72,88 @@ public class DataTest {
|
|||||||
|
|
||||||
//单条数据插入
|
//单条数据插入
|
||||||
public static void insert(InfluxDbUtils influxDBUtil) {
|
public static void insert(InfluxDbUtils influxDBUtil) {
|
||||||
|
|
||||||
|
// Map<String, String> tags = new HashMap<>();
|
||||||
|
// long time = Long.parseLong("1719921600000");
|
||||||
|
// tags.put("line_id", "82a9bad93e784c37135db4589794e6b0");
|
||||||
|
// tags.put("phasic_type", "A");
|
||||||
|
// tags.put("value_type","CP95");
|
||||||
|
// tags.put("quality_flag","0");
|
||||||
|
//
|
||||||
|
// Map<String, Object> fields = new HashMap<>();
|
||||||
|
// fields.put("i_2",0);
|
||||||
|
// fields.put("i_3",0);
|
||||||
|
// fields.put("i_4",0);
|
||||||
|
// fields.put("i_5",6.02);
|
||||||
|
// fields.put("i_6",0);
|
||||||
|
// fields.put("i_7",0);
|
||||||
|
// fields.put("i_8",0);
|
||||||
|
// fields.put("i_9",0);
|
||||||
|
// fields.put("i_10",0);
|
||||||
|
// fields.put("i_11",0);
|
||||||
|
// fields.put("i_12",0);
|
||||||
|
// fields.put("i_13",0);
|
||||||
|
// fields.put("i_14",0);
|
||||||
|
// fields.put("i_15",3.25);
|
||||||
|
// fields.put("i_16",0);
|
||||||
|
// fields.put("i_17",0);
|
||||||
|
// fields.put("i_18",0);
|
||||||
|
// fields.put("i_19",0);
|
||||||
|
// fields.put("i_20",0);
|
||||||
|
// fields.put("i_21",0);
|
||||||
|
// fields.put("i_22",0);
|
||||||
|
// fields.put("i_23",0);
|
||||||
|
// fields.put("i_24",3.52);
|
||||||
|
// fields.put("i_25",0);
|
||||||
|
// influxDBUtil.insert("data_i", tags, fields, time, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
Map<String, String> tags = new HashMap<>();
|
Map<String, String> tags = new HashMap<>();
|
||||||
long time = Long.parseLong("1675958400000");
|
long time = Long.parseLong("1719842400000");
|
||||||
tags.put("dev_id", "57d121d45a26f3cc1d7b6ba541f895c0");
|
tags.put("line_id", "ebdf6cbc275c5d7ed8104fcb3792fb0a");
|
||||||
|
tags.put("phasic_type", "A");
|
||||||
|
tags.put("value_type","CP95");
|
||||||
|
tags.put("quality_flag","0");
|
||||||
|
|
||||||
Map<String, Object> fields = new HashMap<>();
|
Map<String, Object> fields = new HashMap<>();
|
||||||
|
fields.put("v_1",10.0);
|
||||||
|
fields.put("v_2",0);
|
||||||
|
fields.put("v_3",0);
|
||||||
|
fields.put("v_4",0);
|
||||||
|
fields.put("v_5",6.02);
|
||||||
|
fields.put("v_6",0);
|
||||||
|
fields.put("v_7",0);
|
||||||
|
fields.put("v_8",0);
|
||||||
|
fields.put("v_9",0);
|
||||||
|
fields.put("v_10",0);
|
||||||
|
fields.put("v_11",0);
|
||||||
|
fields.put("v_12",0);
|
||||||
|
fields.put("v_13",0);
|
||||||
|
fields.put("v_14",0);
|
||||||
|
fields.put("v_15",3.25);
|
||||||
|
fields.put("v_16",0);
|
||||||
|
fields.put("v_17",0);
|
||||||
|
fields.put("v_18",0);
|
||||||
|
fields.put("v_19",0);
|
||||||
|
fields.put("v_20",0);
|
||||||
|
fields.put("v_21",0);
|
||||||
|
fields.put("v_22",0);
|
||||||
|
fields.put("v_23",0);
|
||||||
|
fields.put("v_24",3.52);
|
||||||
|
fields.put("v_25",0);
|
||||||
|
influxDBUtil.insert("data_inharm_v", tags, fields, time, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Map<String, String> tags = new HashMap<>();
|
||||||
|
// long time = Long.parseLong("1675958400000");
|
||||||
|
// tags.put("dev_id", "57d121d45a26f3cc1d7b6ba541f895c0");
|
||||||
|
// Map<String, Object> fields = new HashMap<>();
|
||||||
// fields.put("due",1440);
|
// fields.put("due",1440);
|
||||||
// fields.put("real",1200);
|
// fields.put("real",1200);
|
||||||
fields.put("online_min", 0);
|
// fields.put("online_min", 0);
|
||||||
fields.put("offline_min", 1440);
|
// fields.put("offline_min", 1440);
|
||||||
fields.put("online_rate", 0.0000);
|
// fields.put("online_rate", 0.0000);
|
||||||
influxDBUtil.insert("pqs_onlinerate", tags, fields, time, TimeUnit.MILLISECONDS);
|
// influxDBUtil.insert("pqs_onlinerate", tags, fields, time, TimeUnit.MILLISECONDS);
|
||||||
// long time = Long.parseLong("1655135328135");
|
// long time = Long.parseLong("1655135328135");
|
||||||
// Map<String, String> tags = new HashMap<>();
|
// Map<String, String> tags = new HashMap<>();
|
||||||
// // tags.put("line_id", "127fad1dcb0077ac2979141b8473a5e4");
|
// // tags.put("line_id", "127fad1dcb0077ac2979141b8473a5e4");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package com.njcn.energy.pojo.dto;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
|
||||||
import com.njcn.common.pojo.constant.PatternRegex;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import com.njcn.energy.pojo.param.LineParam;
|
|
||||||
import com.njcn.web.constant.ValidMessage;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.Pattern;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类的介绍:
|
* 类的介绍:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类的介绍:
|
* 类的介绍:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.njcn.energy.pojo.dto;
|
package com.njcn.energy.pojo.dto;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;;
|
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -1,39 +1,27 @@
|
|||||||
package com.njcn.energy.handler;
|
package com.njcn.energy.handler;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||||
import com.github.tocrhz.mqtt.annotation.NamedValue;
|
import com.github.tocrhz.mqtt.annotation.NamedValue;
|
||||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||||
import com.njcn.energy.pojo.constant.ApiParam;
|
import com.njcn.energy.pojo.constant.ApiParam;
|
||||||
import com.njcn.energy.pojo.dto.AirStrategyDTO;
|
|
||||||
import com.njcn.energy.pojo.dto.DeviceOperateDTO;
|
import com.njcn.energy.pojo.dto.DeviceOperateDTO;
|
||||||
import com.njcn.energy.pojo.dto.RegisterDTO;
|
import com.njcn.energy.pojo.dto.RegisterDTO;
|
||||||
import com.njcn.energy.pojo.enums.EnergyResponseEnum;
|
import com.njcn.energy.pojo.enums.EnergyResponseEnum;
|
||||||
import com.njcn.energy.pojo.po.AirStrategy;
|
|
||||||
import com.njcn.energy.pojo.po.EleLogs;
|
import com.njcn.energy.pojo.po.EleLogs;
|
||||||
import com.njcn.energy.service.IEleLogsService;
|
import com.njcn.energy.service.IEleLogsService;
|
||||||
import com.njcn.energy.service.IModelService;
|
import com.njcn.energy.service.IModelService;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.json.JSON;
|
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongawen
|
* @author hongawen
|
||||||
@@ -54,139 +42,134 @@ public class MqttMessageHandler {
|
|||||||
private final IEleLogsService eleLogsService;
|
private final IEleLogsService eleLogsService;
|
||||||
|
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * 设备注册
|
* 设备注册
|
||||||
// */
|
*/
|
||||||
// @MqttSubscribe(value = "/device/register",qos = 1)
|
@MqttSubscribe(value = "/device/register",qos = 1)
|
||||||
// public void register(String topic, MqttMessage message, @Payload String payload) {
|
public void register(String topic, MqttMessage message, @Payload String payload) {
|
||||||
// String result = modelService.deviceRegister(new String(message.getPayload(), StandardCharsets.UTF_8));
|
String result = modelService.deviceRegister(new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||||
// publisher.send("/platform/register",result,1,false);
|
publisher.send("/platform/register",result,1,false);
|
||||||
// EleLogs eleLogs = new EleLogs();
|
EleLogs eleLogs = new EleLogs();
|
||||||
// eleLogs.setType(1);
|
eleLogs.setType(1);
|
||||||
// //设备取消注册,需要通知平台
|
//设备取消注册,需要通知平台
|
||||||
|
Gson gson = new Gson();
|
||||||
|
RegisterDTO.RegisterRequest registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterRequest.class);
|
||||||
|
RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
||||||
|
if (registerDTO.getParam().getType() == 0){
|
||||||
|
eleLogs.setType(0);
|
||||||
|
if (response.getCode() == 200 && response.getParam().getRes() == 1){
|
||||||
|
DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
||||||
|
deviceOperateDTO.setNdid(registerDTO.getParam().getNDid());
|
||||||
|
deviceOperateDTO.setDid(response.getParam().getDid());
|
||||||
|
deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
||||||
|
deviceOperateDTO.setMessage("装置取消注册");
|
||||||
|
deviceOperateDTO.setType("003");
|
||||||
|
publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//将日志存库
|
||||||
|
eleLogs.setNdid(registerDTO.getParam().getNDid());
|
||||||
|
eleLogs.setReqTime(LocalDateTime.ofEpochSecond(Long.parseLong(registerDTO.getTimestamp()), 0, ZoneOffset.ofHours(8)));
|
||||||
|
eleLogs.setInfo(response.getMsg());
|
||||||
|
eleLogs.setCreateTime(LocalDateTime.now());
|
||||||
|
eleLogsService.addLogs(eleLogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备接入
|
||||||
|
*/
|
||||||
|
@MqttSubscribe(value = "/device/pltreq/{version}/{edgeId}",qos = 1)
|
||||||
|
public void access(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId,@NamedValue("version") String version, @Payload String payload) throws InterruptedException {
|
||||||
|
String result = modelService.deviceAccess(new String(message.getPayload(), StandardCharsets.UTF_8),edgeId);
|
||||||
|
Gson gson = new Gson();
|
||||||
|
RegisterDTO.RegisterRequest registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterRequest.class);
|
||||||
|
RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
||||||
|
//设备接入成功,需要通知平台
|
||||||
|
if (response.getCode() == 200 && Objects.equals(response.getType(), ApiParam.REP_LINKUP)){
|
||||||
|
DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
||||||
|
deviceOperateDTO.setNdid(edgeId);
|
||||||
|
deviceOperateDTO.setDid(registerDTO.getParam().getDid());
|
||||||
|
deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
||||||
|
deviceOperateDTO.setMessage("装置上线");
|
||||||
|
deviceOperateDTO.setType("004");
|
||||||
|
publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
||||||
|
deviceOperateDTO.setMessage("主题更新");
|
||||||
|
deviceOperateDTO.setType("002");
|
||||||
|
publisher.send("/device/operate",gson.toJson(deviceOperateDTO),1,false);
|
||||||
|
}
|
||||||
|
//有装置异常需要主动下线,需要通知平台
|
||||||
|
if (response.getCode() == 300 && Objects.equals(response.getType(), ApiParam.REP_HEARTBEAT)){
|
||||||
|
DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
||||||
|
deviceOperateDTO.setNdid(edgeId);
|
||||||
|
deviceOperateDTO.setDid(registerDTO.getParam().getDid());
|
||||||
|
deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
||||||
|
deviceOperateDTO.setMessage("装置下线");
|
||||||
|
deviceOperateDTO.setType("005");
|
||||||
|
publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
||||||
|
response.setCode(Integer.parseInt(EnergyResponseEnum.SUCCESS.getCode()));
|
||||||
|
result = gson.toJson(response);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 如果心跳超过3分钟,下线当前网关所有装置,需要通知平台,记录数据库掉线时间
|
||||||
|
* 使用redis的过期时间做处理
|
||||||
|
*/
|
||||||
|
redisUtil.saveByKeyWithExpire("MQTT:" + edgeId,registerDTO.getTimestamp(),180L);
|
||||||
|
redisUtil.saveByKeyWithExpire(edgeId,registerDTO.getTimestamp(),200L);
|
||||||
|
//将日志存库
|
||||||
|
if (!Objects.equals(response.getType(), ApiParam.REP_HEARTBEAT)){
|
||||||
|
EleLogs eleLogs = new EleLogs();
|
||||||
|
eleLogs.setType(2);
|
||||||
|
eleLogs.setNdid(edgeId);
|
||||||
|
eleLogs.setReqTime(LocalDateTime.ofEpochSecond(Long.parseLong(registerDTO.getTimestamp()), 0, ZoneOffset.ofHours(8)));
|
||||||
|
eleLogs.setInfo(response.getMsg());
|
||||||
|
eleLogs.setCreateTime(LocalDateTime.now());
|
||||||
|
eleLogsService.addLogs(eleLogs);
|
||||||
|
}
|
||||||
|
//回复装置信息
|
||||||
|
publisher.send("/device/pltrep/"+version+"/" + edgeId,result,1,false);
|
||||||
|
|
||||||
|
// 询问模板数据 暂时线下传递模板数据
|
||||||
// Gson gson = new Gson();
|
// Gson gson = new Gson();
|
||||||
// RegisterDTO.RegisterRequest registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterRequest.class);
|
// AccessDTO.AccessResponse response = gson.fromJson(result,AccessDTO.AccessResponse.class);
|
||||||
// RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
// if (response.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){
|
||||||
// if (registerDTO.getParam().getType() == 0){
|
// AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest();
|
||||||
// eleLogs.setType(0);
|
// askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000));
|
||||||
// if (response.getCode() == 200 && response.getParam().getRes() == 1){
|
// askDataDTO.setLevel(0);
|
||||||
// DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
// askDataDTO.setType(ApiParam.CMD_DEV_DATA);
|
||||||
// deviceOperateDTO.setNdid(registerDTO.getParam().getNDid());
|
// AskDataParamDTO askDataParamDTO = new AskDataParamDTO();
|
||||||
// deviceOperateDTO.setDid(response.getParam().getDid());
|
// askDataParamDTO.setDataType(DataType.TEMPLATE);
|
||||||
// deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
// askDataParamDTO.setOperate(ModelState.READ);
|
||||||
// deviceOperateDTO.setMessage("装置取消注册");
|
// askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000));
|
||||||
// deviceOperateDTO.setType("003");
|
// askDataDTO.setParam(askDataParamDTO);
|
||||||
// publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
// publisher.send("/platform/command/v1/" + edgeId,gson.toJson(askDataDTO),1,false);
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// //将日志存库
|
}
|
||||||
// eleLogs.setNdid(registerDTO.getParam().getNDid());
|
|
||||||
// eleLogs.setReqTime(LocalDateTime.ofEpochSecond(Long.parseLong(registerDTO.getTimestamp()), 0, ZoneOffset.ofHours(8)));
|
|
||||||
// eleLogs.setInfo(response.getMsg());
|
|
||||||
// eleLogs.setCreateTime(LocalDateTime.now());
|
|
||||||
// eleLogsService.addLogs(eleLogs);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 设备接入
|
|
||||||
// */
|
|
||||||
// @MqttSubscribe(value = "/device/pltreq/{version}/{edgeId}",qos = 1)
|
|
||||||
// public void access(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId,@NamedValue("version") String version, @Payload String payload) throws InterruptedException {
|
|
||||||
// String result = modelService.deviceAccess(new String(message.getPayload(), StandardCharsets.UTF_8),edgeId);
|
|
||||||
// Gson gson = new Gson();
|
|
||||||
// RegisterDTO.RegisterRequest registerDTO = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), RegisterDTO.RegisterRequest.class);
|
|
||||||
// RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
|
||||||
// //设备接入成功,需要通知平台
|
|
||||||
// if (response.getCode() == 200 && Objects.equals(response.getType(), ApiParam.REP_LINKUP)){
|
|
||||||
// DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
|
||||||
// deviceOperateDTO.setNdid(edgeId);
|
|
||||||
// deviceOperateDTO.setDid(registerDTO.getParam().getDid());
|
|
||||||
// deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
|
||||||
// deviceOperateDTO.setMessage("装置上线");
|
|
||||||
// deviceOperateDTO.setType("004");
|
|
||||||
// publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
|
||||||
// deviceOperateDTO.setMessage("主题更新");
|
|
||||||
// deviceOperateDTO.setType("002");
|
|
||||||
// publisher.send("/device/operate",gson.toJson(deviceOperateDTO),1,false);
|
|
||||||
// }
|
|
||||||
// //有装置异常需要主动下线,需要通知平台
|
|
||||||
// if (response.getCode() == 300 && Objects.equals(response.getType(), ApiParam.REP_HEARTBEAT)){
|
|
||||||
// DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
|
||||||
// deviceOperateDTO.setNdid(edgeId);
|
|
||||||
// deviceOperateDTO.setDid(registerDTO.getParam().getDid());
|
|
||||||
// deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()/1000));
|
|
||||||
// deviceOperateDTO.setMessage("装置下线");
|
|
||||||
// deviceOperateDTO.setType("005");
|
|
||||||
// publisher.send("/device/platform",gson.toJson(deviceOperateDTO),1,false);
|
|
||||||
// response.setCode(Integer.parseInt(EnergyResponseEnum.SUCCESS.getCode()));
|
|
||||||
// result = gson.toJson(response);
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * 如果心跳超过3分钟,下线当前网关所有装置,需要通知平台,记录数据库掉线时间
|
|
||||||
// * 使用redis的过期时间做处理
|
|
||||||
// */
|
|
||||||
// redisUtil.saveByKeyWithExpire("MQTT:" + edgeId,registerDTO.getTimestamp(),180L);
|
|
||||||
// redisUtil.saveByKeyWithExpire(edgeId,registerDTO.getTimestamp(),200L);
|
|
||||||
// //将日志存库
|
|
||||||
// if (!Objects.equals(response.getType(), ApiParam.REP_HEARTBEAT)){
|
|
||||||
// EleLogs eleLogs = new EleLogs();
|
|
||||||
// eleLogs.setType(2);
|
|
||||||
// eleLogs.setNdid(edgeId);
|
|
||||||
// eleLogs.setReqTime(LocalDateTime.ofEpochSecond(Long.parseLong(registerDTO.getTimestamp()), 0, ZoneOffset.ofHours(8)));
|
|
||||||
// eleLogs.setInfo(response.getMsg());
|
|
||||||
// eleLogs.setCreateTime(LocalDateTime.now());
|
|
||||||
// eleLogsService.addLogs(eleLogs);
|
|
||||||
// }
|
|
||||||
// //回复装置信息
|
|
||||||
// publisher.send("/device/pltrep/"+version+"/" + edgeId,result,1,false);
|
|
||||||
//
|
|
||||||
//// 询问模板数据 暂时线下传递模板数据
|
|
||||||
//// Gson gson = new Gson();
|
|
||||||
//// AccessDTO.AccessResponse response = gson.fromJson(result,AccessDTO.AccessResponse.class);
|
|
||||||
//// if (response.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){
|
|
||||||
//// AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest();
|
|
||||||
//// askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000));
|
|
||||||
//// askDataDTO.setLevel(0);
|
|
||||||
//// askDataDTO.setType(ApiParam.CMD_DEV_DATA);
|
|
||||||
//// AskDataParamDTO askDataParamDTO = new AskDataParamDTO();
|
|
||||||
//// askDataParamDTO.setDataType(DataType.TEMPLATE);
|
|
||||||
//// askDataParamDTO.setOperate(ModelState.READ);
|
|
||||||
//// askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000));
|
|
||||||
//// askDataDTO.setParam(askDataParamDTO);
|
|
||||||
//// publisher.send("/platform/command/v1/" + edgeId,gson.toJson(askDataDTO),1,false);
|
|
||||||
//// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 获取模板信息
|
|
||||||
// */
|
|
||||||
// @MqttSubscribe(value = "/platform/reply/{version}/{edgeId}",qos = 1)
|
|
||||||
// public void replyTemplate(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) {
|
|
||||||
// String result = modelService.deviceData(new String(message.getPayload(), StandardCharsets.UTF_8));
|
|
||||||
// //模板发生变更通知其他云服务
|
|
||||||
// Gson gson = new Gson();
|
|
||||||
// RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
|
||||||
// if (Objects.equals(response.getCode(),200)){
|
|
||||||
// DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
|
||||||
// deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()));
|
|
||||||
// deviceOperateDTO.setMessage("模板更新");
|
|
||||||
// deviceOperateDTO.setType("001");
|
|
||||||
// publisher.send("/device/operate",gson.toJson(deviceOperateDTO),1,false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 获取网关订阅的主题
|
|
||||||
// */
|
|
||||||
// @MqttSubscribe(value = "/device/topic/{edgeId}",qos = 1)
|
|
||||||
// public void subscribeTopic(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) {
|
|
||||||
// modelService.subscribeTopic(new String(message.getPayload(), StandardCharsets.UTF_8),edgeId);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取模板信息
|
||||||
|
*/
|
||||||
|
@MqttSubscribe(value = "/platform/reply/{version}/{edgeId}",qos = 1)
|
||||||
|
public void replyTemplate(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) {
|
||||||
|
String result = modelService.deviceData(new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||||
|
//模板发生变更通知其他云服务
|
||||||
|
Gson gson = new Gson();
|
||||||
|
RegisterDTO.RegisterResponse response = gson.fromJson(result, RegisterDTO.RegisterResponse.class);
|
||||||
|
if (Objects.equals(response.getCode(),200)){
|
||||||
|
DeviceOperateDTO deviceOperateDTO = new DeviceOperateDTO();
|
||||||
|
deviceOperateDTO.setTime(Long.toString(System.currentTimeMillis()));
|
||||||
|
deviceOperateDTO.setMessage("模板更新");
|
||||||
|
deviceOperateDTO.setType("001");
|
||||||
|
publisher.send("/device/operate",gson.toJson(deviceOperateDTO),1,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取网关订阅的主题
|
||||||
|
*/
|
||||||
|
@MqttSubscribe(value = "/device/topic/{edgeId}",qos = 1)
|
||||||
|
public void subscribeTopic(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) {
|
||||||
|
modelService.subscribeTopic(new String(message.getPayload(), StandardCharsets.UTF_8),edgeId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user