Commit 94572d37 authored by 刘林's avatar 刘林

fix(equip):添加tdengine

parent 820d798e
package com.yeejoin.equip.config; package com.yeejoin.equip.config;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.equip.entity.EquipmentIndexVO; import com.yeejoin.equip.entity.EquipmentIndexVO;
import com.yeejoin.equip.mapper.mysql.EquipmentSpecificIndexMapper; import com.yeejoin.equip.mapper.mysql.EquipmentSpecificIndexMapper;
import com.yeejoin.equip.service.HandleESMessage2TDService;
import com.yeejoin.equip.service.InitTDEngineDbService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -27,11 +25,6 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner { ...@@ -27,11 +25,6 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner {
@Resource @Resource
private EquipmentSpecificIndexMapper equipmentSpecificIndexMapper; private EquipmentSpecificIndexMapper equipmentSpecificIndexMapper;
@Autowired
private InitTDEngineDbService initTDEngineDbService;
@Autowired
private HandleESMessage2TDService handleESMessage2TDService;
@Value("${spring.redis.host}") @Value("${spring.redis.host}")
private String redisHost; private String redisHost;
...@@ -42,15 +35,14 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner { ...@@ -42,15 +35,14 @@ public class EquipmentIndexCacheRunner implements CommandLineRunner {
private String redisPassword; private String redisPassword;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) {
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();
List<EquipmentIndexVO> equipSpecificIndexList = equipmentSpecificIndexMapper.getEquipSpecificIndexList(null); List<EquipmentIndexVO> equipSpecificIndexList = equipmentSpecificIndexMapper.getEquipSpecificIndexList(null);
equipSpecificIndexList.forEach(vo->{ equipSpecificIndexList.forEach(vo->{
String key = vo.getIndexAddress() + "_" + vo.getGatewayId(); String key = vo.getIndexAddress() + "_" + vo.getGatewayId();
pipeline.del(key); pipeline.set(key, JSONObject.toJSONString(vo));
pipeline.set(key, String.valueOf(vo));
}); });
pipeline.syncAndReturnAll(); pipeline.syncAndReturnAll();
log.info(">>>>>>>>>>>>>>>>服务启动执行Redis缓存预加载指标数据完成!>>>>>>>>>>>>>>>>"); log.info(">>>>>>>>>>>>>>>>服务启动执行Redis缓存预加载指标数据完成!>>>>>>>>>>>>>>>>");
......
package com.yeejoin.equip.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @description:
* @author: duanwei
**/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
Jackson2JsonRedisSerializer<Object> j2jrs = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 解决jackson2无法反序列化LocalDateTime的问题
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
om.registerModule(new JavaTimeModule());
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
j2jrs.setObjectMapper(om);
// 序列化 value 时使用此序列化方法
//template.setValueSerializer(j2jrs);
template.setHashValueSerializer(j2jrs);
StringRedisSerializer srs = new StringRedisSerializer();
// 序列化 key 时
template.setKeySerializer(srs);
template.setHashKeySerializer(srs);
template.afterPropertiesSet();
// 序列化 value 时
template.setValueSerializer(srs);
return template;
}
}
...@@ -2,11 +2,17 @@ package com.yeejoin.equip.entity; ...@@ -2,11 +2,17 @@ package com.yeejoin.equip.entity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@Data @Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "性能指标详情返回vo实体", description = "性能指标详情返回vo实体") @ApiModel(value = "性能指标详情返回vo实体", description = "性能指标详情返回vo实体")
public class EquipmentIndexVO implements Serializable { public class EquipmentIndexVO implements Serializable {
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
......
...@@ -37,8 +37,8 @@ public class MessageTransfer { ...@@ -37,8 +37,8 @@ public class MessageTransfer {
String[] topicItems = topic.split(TOPIC_SPLITTER); String[] topicItems = topic.split(TOPIC_SPLITTER);
indicatorData.setMqttTopicEnum(MqttTopicEnum.of(topicItems[topicItems.length - 1])); indicatorData.setMqttTopicEnum(MqttTopicEnum.of(topicItems[topicItems.length - 1]));
String key = indicatorData.getAddress() + "_" + indicatorData.getGatewayId(); String key = indicatorData.getAddress() + "_" + indicatorData.getGatewayId();
if (redisUtils.get(key)!=null) { if (redisUtils.hasKey(key)) {
EquipmentIndexVO equipmentSpeIndex = (EquipmentIndexVO) redisUtils.get(key); EquipmentIndexVO equipmentSpeIndex = JSONObject.parseObject(redisUtils.get(key),EquipmentIndexVO.class) ;
String valueLabel = valueTranslate(indicatorData.getValue(), equipmentSpeIndex.getValueEnum()); String valueLabel = valueTranslate(indicatorData.getValue(), equipmentSpeIndex.getValueEnum());
indicatorData.setIsAlarm(String.valueOf(equipmentSpeIndex.getIsAlarm())); indicatorData.setIsAlarm(String.valueOf(equipmentSpeIndex.getIsAlarm()));
indicatorData.setEquipmentIndexName(equipmentSpeIndex.getEquipmentIndexName()); indicatorData.setEquipmentIndexName(equipmentSpeIndex.getEquipmentIndexName());
......
...@@ -10,14 +10,38 @@ import org.springframework.stereotype.Component; ...@@ -10,14 +10,38 @@ import org.springframework.stereotype.Component;
public class RedisUtils { public class RedisUtils {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate<String, Object> redisTemplate;
/** /**
* 普通缓存获取 * 普通缓存获取
* *
* @param key 键 * @param key 键
* @return 值 * @return 值
*/ */
public Object get(String key) { public String get(String key) {
return redisTemplate.opsForValue().get(key); return (String) redisTemplate.opsForValue().get(key);
} }
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public boolean set(String key, Object value) {
redisTemplate.opsForValue().set(key, value);
return true;
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public boolean hasKey(String key) {
return Boolean.TRUE.equals(redisTemplate.hasKey(key));
}
} }
...@@ -18,7 +18,7 @@ spring.datasource.tdengine-server.jdbc-url = jdbc:TAOS-RS://139.9.170.47:6041/io ...@@ -18,7 +18,7 @@ spring.datasource.tdengine-server.jdbc-url = jdbc:TAOS-RS://139.9.170.47:6041/io
spring.datasource.tdengine-server.username=root spring.datasource.tdengine-server.username=root
spring.datasource.tdengine-server.password=taosdata spring.datasource.tdengine-server.password=taosdata
spring.redis.database=1 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
...@@ -42,7 +42,6 @@ eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${sprin ...@@ -42,7 +42,6 @@ eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${sprin
spring.security.user.name=admin spring.security.user.name=admin
spring.security.user.password=a1234560 spring.security.user.password=a1234560
## emqx
emqx.clean-session=true emqx.clean-session=true
emqx.client-id=${spring.application.name}-${random.int[1024,65536]} emqx.client-id=${spring.application.name}-${random.int[1024,65536]}
emqx.biz-client-id=consumer-${random.int[1024,65536]} emqx.biz-client-id=consumer-${random.int[1024,65536]}
...@@ -80,7 +79,6 @@ spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.Str ...@@ -80,7 +79,6 @@ spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.Str
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.fetch-max-wait= 1000 spring.kafka.consumer.fetch-max-wait= 1000
spring.kafka.consumer.max-poll-records=1000 spring.kafka.consumer.max-poll-records=1000
spring.kafka.listener.ack-mode=manual_immediate spring.kafka.listener.ack-mode=manual_immediate
spring.kafka.listener.type=batch spring.kafka.listener.type=batch
kafka.alarm.topic=EQUIPMENT_ALARM kafka.alarm.topic=EQUIPMENT_ALARM
......
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