版本迭代
This commit is contained in:
parent
e3d52ffd3c
commit
fba665ec49
6
pom.xml
6
pom.xml
|
@ -139,6 +139,12 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!--caffeine本地缓存-->
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package com.bootdo.datasend.dianxin.cache;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.bootdo.datasend.dianxin.domain.DevopsDeviceInfo;
|
||||
import com.bootdo.datasend.dianxin.service.DevopsDeviceInfoService;
|
||||
import com.bootdo.util.StringKit;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 区域缓存
|
||||
*
|
||||
* @since 2023-09-16 11:04
|
||||
*/
|
||||
@Component
|
||||
public class DeviceCache {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeviceCache.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final Cache<String, String> cache = Caffeine.newBuilder().build();
|
||||
|
||||
private static DevopsDeviceInfoService devopsDeviceInfoService;
|
||||
|
||||
@Autowired
|
||||
DeviceCache(DevopsDeviceInfoService devopsDeviceInfoService) {
|
||||
DeviceCache.devopsDeviceInfoService = devopsDeviceInfoService;
|
||||
//初始化
|
||||
load();
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return cache.get(key, s -> {
|
||||
try {
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void put(DevopsDeviceInfo bean) {
|
||||
cache.put(bean.getGbsChannelNo(), JSON.toJSONString(bean));
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存刷新
|
||||
*/
|
||||
@Scheduled(cron = "0 */30 * * * ?")
|
||||
public static void refresh() {
|
||||
load();
|
||||
}
|
||||
|
||||
private static void load() {
|
||||
logger.info("设备表缓存重新加载");
|
||||
List<DevopsDeviceInfo> list = devopsDeviceInfoService.list();
|
||||
Map<String, String> dictMapCode = list.stream().collect(Collectors.toMap(
|
||||
e -> "".equals(StringKit.toString(e.getDeviceIp())) ? "err" : e.getDeviceIp(),
|
||||
e -> JSON.toJSONString(e), (v1, v2) -> v2));
|
||||
cache.putAll(dictMapCode);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ public class RabbitConfig {
|
|||
@Bean
|
||||
public Queue myQueue() {
|
||||
// 创建队列 myQueue
|
||||
return new Queue("myQueue", true);
|
||||
return new Queue("warnrecord", true);
|
||||
}
|
||||
@Bean
|
||||
public TopicExchange exchange() {
|
||||
|
|
|
@ -12,12 +12,12 @@ public class MessageConsumer {
|
|||
private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
|
||||
|
||||
//测试消费kafka
|
||||
// 监听队列 "myQueue"
|
||||
// @RabbitListener(queues = "myQueue")
|
||||
// 监听队列 "warnrecord"
|
||||
// @RabbitListener(queues = "warnrecord")
|
||||
public void receiveMessage(String message) {
|
||||
try {
|
||||
// 处理接收到的消息
|
||||
logger.info("Received message: " + message.toString());
|
||||
logger.info("Received message: " + message);
|
||||
// 在这里添加你对消息的处理逻辑
|
||||
} catch (Exception e) {
|
||||
// 捕获并打印异常
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.bootdo.datasend.dianxin.task;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.bootdo.datasend.dianxin.cache.DeviceCache;
|
||||
import com.bootdo.datasend.dianxin.domain.BaseHighThrowRecord;
|
||||
import com.bootdo.datasend.dianxin.domain.DevopsDeviceInfo;
|
||||
import com.bootdo.datasend.dianxin.domain.dto.HighThrowDto;
|
||||
import com.bootdo.datasend.dianxin.domain.dto.HighThrowRequestDataDTO;
|
||||
import com.bootdo.datasend.dianxin.domain.dto.HighThrowRequestDataListDTO;
|
||||
|
@ -40,13 +43,25 @@ public class StandardTask {
|
|||
|
||||
for (BaseHighThrowRecord h : highThrowRecords) {
|
||||
|
||||
String deviceId = h.getDeviceIp();
|
||||
String deviceCacheStr = DeviceCache.get(deviceId);
|
||||
DevopsDeviceInfo deviceInfo = null;
|
||||
if ("".equals(StringKit.toString(deviceCacheStr))) {
|
||||
logger.info("当前设备缓存中不存在:" + deviceId);
|
||||
}else {
|
||||
logger.info("当前设备获取到缓存:" + deviceId);
|
||||
deviceInfo = JSON.parseObject(deviceCacheStr, DevopsDeviceInfo.class, Feature.IgnoreNotMatch);
|
||||
}
|
||||
|
||||
HighThrowDto dto = new HighThrowDto();
|
||||
|
||||
HighThrowRequestDataDTO dataDTO = new HighThrowRequestDataDTO();
|
||||
dataDTO.setRequestFlag("1");
|
||||
|
||||
HighThrowRequestDataListDTO requestDataListDTO = new HighThrowRequestDataListDTO();
|
||||
requestDataListDTO.setGatewaySN(h.getGeminiSn());
|
||||
if(deviceInfo!=null){
|
||||
requestDataListDTO.setGatewaySN(deviceInfo.getGeminiSn());
|
||||
}
|
||||
requestDataListDTO.setWarnType("1001");
|
||||
requestDataListDTO.setDeviceType("302");
|
||||
requestDataListDTO.setDeviceSN(h.getGbsChannelNo());
|
||||
|
|
|
@ -4,7 +4,7 @@ spring:
|
|||
username: root
|
||||
password: '1qaz!QAZ'
|
||||
# url: jdbc:mysql://221.229.107.118:30519/multidimensional_box?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT
|
||||
url: jdbc:mysql://127.0.0.1:30519/multidimensional_box?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT
|
||||
url: jdbc:mysql://127.0.0.1:55306/multidimensional_box?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
initialSize: 5 # 配置初始化大小、最小、最大
|
||||
minIdle: 5
|
||||
|
@ -31,18 +31,18 @@ spring:
|
|||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
rabbitmq:
|
||||
host: 221.229.107.118
|
||||
port: 30529
|
||||
username: root
|
||||
password: 'sm@rtC@m!n23ty'
|
||||
dynamic: true
|
||||
# rabbitmq:
|
||||
# host: 110.1.200.11
|
||||
# port: 19000
|
||||
# host: 221.229.107.118
|
||||
# port: 30529
|
||||
# username: root
|
||||
# password: 'sm@rtC@m!n23ty'
|
||||
# dynamic: true
|
||||
rabbitmq:
|
||||
host: 110.1.200.11
|
||||
port: 19000
|
||||
username: root
|
||||
password: 'sm@rtC@m!n23ty'
|
||||
dynamic: true
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue