|
@@ -4,6 +4,7 @@ import com.gyee.redis2taos.config.RedisConfig;
|
|
|
import com.gyee.redis2taos.config.TaosConfig;
|
|
|
import com.gyee.redis2taos.timeseries.TsDataType;
|
|
|
import com.gyee.redis2taos.util.ChangedSave;
|
|
|
+import com.taosdata.jdbc.TSDBPreparedStatement;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
@@ -12,6 +13,8 @@ import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.Pipeline;
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -39,11 +42,13 @@ public class TaskRedis2Taos implements Runnable {
|
|
|
|
|
|
String pointid = null;
|
|
|
|
|
|
+ //String sql = "insert into ? values(?,?)";
|
|
|
+
|
|
|
try (Jedis jedis = redisConfig.getJedis(); Pipeline pipelined = jedis.pipelined();) {
|
|
|
- //TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class);
|
|
|
|
|
|
Connection conn = taosConfig.getInstance();
|
|
|
|
|
|
+ //TSDBPreparedStatement pstmt = (TSDBPreparedStatement)conn.prepareStatement(sql);
|
|
|
for (String key : keys) {
|
|
|
//pipelined.hscan(key, "0");
|
|
|
pipelined.hmget(key, "pointid", "value", "timestamp");
|
|
@@ -74,16 +79,30 @@ public class TaskRedis2Taos implements Runnable {
|
|
|
pointid = response.get(0);
|
|
|
if (StringUtils.isEmpty(pointid)) continue;
|
|
|
|
|
|
- if(ChangedSave.map.containsKey(pointid)){
|
|
|
- if(!Objects.equals(ChangedSave.map.get(pointid),value)){
|
|
|
- ChangedSave.map.put(pointid, value);
|
|
|
+
|
|
|
+ /*ts = Long.valueOf(datetime) * 1000;
|
|
|
+ bl = Double.valueOf(value)==1;
|
|
|
+ pstmt.setTableName(pointid.toLowerCase());
|
|
|
+ ArrayList<Long> objects1 = new ArrayList<>();
|
|
|
+ objects1.add(ts);
|
|
|
+ pstmt.setTimestamp(0,objects1);
|
|
|
+ ArrayList<Boolean> objects2 = new ArrayList<>();
|
|
|
+ objects2.add(false);
|
|
|
+ pstmt.setBoolean(1,objects2);
|
|
|
+ pstmt.columnDataAddBatch();
|
|
|
+ pstmt.columnDataExecuteBatch();*/
|
|
|
+
|
|
|
+
|
|
|
+ if (ChangedSave.map.containsKey(pointid)) {
|
|
|
+ if (!Objects.equals(ChangedSave.map.get(pointid), datetime)) {
|
|
|
+ ChangedSave.map.put(pointid, datetime);
|
|
|
ts = Long.valueOf(datetime) * 1000;
|
|
|
- bl = "0".equals(value) ? false : true;
|
|
|
+ bl = Double.valueOf(value) == 1;
|
|
|
|
|
|
sb.append(pointid).append(" VALUES (").append(ts).append(",").append(bl).append(") ");
|
|
|
}
|
|
|
- }else {
|
|
|
- ChangedSave.map.put(pointid, value);
|
|
|
+ } else {
|
|
|
+ ChangedSave.map.put(pointid, datetime);
|
|
|
}
|
|
|
|
|
|
i++;
|
|
@@ -109,16 +128,16 @@ public class TaskRedis2Taos implements Runnable {
|
|
|
pointid = response.get(0);
|
|
|
if (StringUtils.isEmpty(pointid)) continue;
|
|
|
|
|
|
- if(ChangedSave.map.containsKey(pointid)){
|
|
|
- if(!Objects.equals(ChangedSave.map.get(pointid),value)){
|
|
|
- ChangedSave.map.put(pointid, value);
|
|
|
+ if (ChangedSave.map.containsKey(pointid)) {
|
|
|
+ if (!Objects.equals(ChangedSave.map.get(pointid), datetime)) {
|
|
|
+ ChangedSave.map.put(pointid, datetime);
|
|
|
ts = Long.valueOf(datetime) * 1000;
|
|
|
val = Double.valueOf(value);
|
|
|
|
|
|
sb.append(pointid).append(" VALUES (").append(ts).append(",").append(val).append(") ");
|
|
|
}
|
|
|
- }else {
|
|
|
- ChangedSave.map.put(pointid, value);
|
|
|
+ } else {
|
|
|
+ ChangedSave.map.put(pointid, datetime);
|
|
|
}
|
|
|
|
|
|
i++;
|