Commit f0a9df5e authored by 刘林's avatar 刘林

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

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