Commit f0a9df5e authored by 刘林's avatar 刘林

fix(equip):优化对接IOT代码,添加ES同步时间

parent bf88f772
......@@ -34,8 +34,14 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner {
@Value("${spring.redis.password}")
private String redisPassword;
//@Autowired
//private HandleESMessage2TDService handleESMessage2TDService;
//@Autowired
//private InitTDEngineDbService initTDEngineDbService;
@Override
public void run(String... args) {
public void run(String... args) throws Exception {
Jedis jedis = new Jedis(redisHost, redisPort);
jedis.auth(redisPassword);
Pipeline pipeline = jedis.pipelined();
......@@ -47,5 +53,6 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner {
pipeline.syncAndReturnAll();
log.info(">>>>>>>>>>>>>>>>服务启动执行Redis缓存预加载指标数据完成!>>>>>>>>>>>>>>>>");
//initTDEngineDbService.init();
//handleESMessage2TDService.syncEsData2TDEngine();
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.yeejoin.equip.mapper.tdengine;
import com.yeejoin.equip.entity.ESEquipments;
import com.yeejoin.equip.entity.IndicatorData;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
......@@ -14,7 +15,7 @@ import java.util.List;
*/
@Component
public interface ESEquipmentsMapper {
int batchInsert(List<ESEquipments> esEquipmentsList);
int batchInsert(@Param("list")List<ESEquipments> esEquipmentsList,@Param("time")String time);
int insert(ESEquipments esEquipments);
......
......@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.List;
/**
* @author LiuLin
......@@ -26,6 +27,7 @@ public class HandleESMessage2TDService {
private ESEquipmentsMapper esEquipmentsMapper;
@Autowired
private ElasticSearchUtil elasticSearchUtil;
private static final String datePattern = "yyyy-MM-dd HH:mm:ss.SSS";
/**
* 十分钟拉取ES数据存入TdEngine
......@@ -33,11 +35,13 @@ public class HandleESMessage2TDService {
@Scheduled(cron = "0 */10 * * * ?")
@Transactional(rollbackFor = Exception.class)
public void syncEsData2TDEngine() throws Exception {
SimpleDateFormat format = new SimpleDateFormat(datePattern);
List<ESEquipments> result = elasticSearchUtil.searchResponse(ES_INDEX, null, hit -> JSONObject.parseObject(hit.getSourceAsString(), ESEquipments.class));
List<List<ESEquipments>> allDataList = Lists.partition(result, SIZE);
String time = format.format(System.currentTimeMillis());
for (List<ESEquipments> tempDataList : allDataList) {
if (CollectionUtils.isNotEmpty(tempDataList)) {
esEquipmentsMapper.batchInsert(tempDataList);
esEquipmentsMapper.batchInsert(tempDataList,time);
}
}
log.info("同步ES数据至TDEngine成功!共同步{}条!",result.size());
......
......@@ -22,9 +22,10 @@ spring.redis.database=0
spring.redis.host=172.16.11.201
spring.redis.port=6379
spring.redis.password=yeejoin@2020
spring.redis.lettuce.pool.max-active=200
spring.redis.timeout=3000
spring.redis.lettuce.pool.max-active=300
spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.max-idle=64
spring.redis.lettuce.pool.min-idle=0
eureka.client.registry-fetch-interval-seconds=5
......@@ -38,7 +39,7 @@ eureka.instance.status-page-url-path=/actuator/info
eureka.instance.metadata-map.management.api-docs=http://localhost:${server.port}${server.servlet.context-path}/doc.html
eureka.instance.hostname= 172.16.11.201
eureka.instance.prefer-ip-address = true
eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@172.16.10.220:10001/eureka/
eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@172.16.11.201:10001/eureka/
spring.security.user.name=admin
spring.security.user.password=a1234560
......
......@@ -4,7 +4,7 @@
<mapper namespace="com.yeejoin.equip.mapper.tdengine.ESEquipmentsMapper">
<insert id="batchInsert" parameterType="java.util.List" >
insert into indicator_data
(createdTime,
(ts,
id,
address,
gateway_id,
......@@ -17,7 +17,8 @@
`value_f` ,
value_label,
equipment_number,
display_name)
display_name,
created_time)
values
<foreach separator=" " collection="list" item="equip" index="index" >
(now + #{index}a,
......@@ -33,7 +34,8 @@
#{equip.valueF},
#{equip.valueLabel},
#{equip.equipmentNumber},
#{equip.displayName})
#{equip.displayName},
#{time})
</foreach>
</insert>
......@@ -73,7 +75,7 @@
<!--创建表-->
<update id="createTable" >
create table if not exists indicator_data
(createdTime timestamp,
(ts TIMESTAMP,
id binary(64),
address binary(64),
gateway_id binary(64),
......@@ -83,9 +85,10 @@
equipment_index_name VARCHAR(255) ,
equipment_specific_name VARCHAR(255),
`value` VARCHAR(12),
`value_f` float,
`value_f` FLOAT,
value_label VARCHAR(64),
equipment_number binary(64),
display_name VARCHAR(200));
equipment_number BINARY(64),
display_name VARCHAR(200),
created_time VARCHAR(64));
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment