1、数据库PG切换为达梦的修改版本。

This commit is contained in:
2026-05-28 14:58:00 +08:00
parent a360895292
commit a168f74653
119 changed files with 2758 additions and 2090 deletions
@@ -13,11 +13,21 @@ import org.springframework.context.annotation.Configuration;
import java.time.Duration;
import java.util.Collections;
import org.springframework.cache.annotation.EnableCaching;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import java.io.IOException;
@Configuration
@EnableCaching // 启用缓存
public class CacheConfig {
@@ -35,6 +45,33 @@ public class CacheConfig {
// 禁用将日期序列化为时间戳
mapper.disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// 注册达梦 JDBC 安全序列化器 — 拦截 dm.jdbc.* 类,直接返回 null 防止循环引用 StackOverflow
SimpleModule dmSafeModule = new SimpleModule("dm-safe");
dmSafeModule.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
BeanDescription beanDesc,
JsonSerializer<?> serializer) {
if (beanDesc.getBeanClass().getName().startsWith("dm.jdbc.")) {
return new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen,
SerializerProvider serializers) throws IOException {
gen.writeNull();
}
@Override
public void serializeWithType(Object value, JsonGenerator gen,
SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
gen.writeNull();
}
};
}
return serializer;
}
});
mapper.registerModule(dmSafeModule);
// 启用类型信息,解决 LinkedHashMap 转换问题
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder()
.allowIfSubType("com.common.entity.") // 允许你的实体类包
@@ -50,7 +87,6 @@ public class CacheConfig {
ObjectMapper.DefaultTyping.NON_FINAL,
com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY
);
return mapper;
}
@@ -1,4 +1,13 @@
package com.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -7,7 +16,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
@Configuration
public class RedisConfig {
@@ -22,6 +31,32 @@ public class RedisConfig {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
// 注册达梦 JDBC 安全序列化器 — 拦截 dm.jdbc.* 类,直接返回 null 防止循环引用 StackOverflow
SimpleModule dmSafeModule = new SimpleModule("dm-safe");
dmSafeModule.setSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
BeanDescription beanDesc,
JsonSerializer<?> serializer) {
if (beanDesc.getBeanClass().getName().startsWith("dm.jdbc.")) {
return new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen,
SerializerProvider serializers) throws IOException {
gen.writeNull();
}
@Override
public void serializeWithType(Object value, JsonGenerator gen,
SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
gen.writeNull();
}
};
}
return serializer;
}
});
mapper.registerModule(dmSafeModule);
mapper.activateDefaultTyping(
mapper.getPolymorphicTypeValidator(),
ObjectMapper.DefaultTyping.NON_FINAL
@@ -4,6 +4,7 @@ import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import java.io.File;
import com.typesafe.config.ConfigValueFactory;
import java.nio.charset.Charset;
import java.util.Map;
public class AppConfig {
@@ -101,6 +102,17 @@ public class AppConfig {
return config.getInt("syslog.buffer.size");
}
/**
* syslog 消息字符编码,默认 GBK(国内安全设备普遍使用 GBK)
* 配置示例: syslog.charset=GBK
*/
public static Charset getSyslogCharset() {
if (config.hasPath("syslog.charset")) {
return Charset.forName(config.getString("syslog.charset"));
}
return Charset.forName("GBK");
}
// app service 配置
public static String getAppServieDeviceId() {
return config.getString("app.service.device_id");
@@ -54,9 +54,9 @@ public class InterlockingService {
/**
* 定时任务:检查并执行待处理的封禁指令
* 每30秒执行一次
* 每60秒执行一次
*/
@Scheduled(fixedDelay = 30000)
@Scheduled(fixedDelay = 60000)
public void processPendingCommands() {
if (!interlockingEnabled) {
return;
@@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import com.kafka.kafkaProducer;
import com.Modules.Device.DeviceProcess;
import com.haobang.util.Sm4Util;
@@ -16,6 +17,7 @@ import com.haobang.config.AppConfig;
*/
public class SyslogMessageHandler extends SimpleChannelInboundHandler<Object> {
private static final Logger logger = LoggerFactory.getLogger(SyslogMessageHandler.class);
private static final Charset SYSLOG_CHARSET = AppConfig.getSyslogCharset();
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
@@ -27,7 +29,7 @@ public class SyslogMessageHandler extends SimpleChannelInboundHandler<Object> {
if (msg instanceof DatagramPacket) {
// UDP 消息处理
DatagramPacket packet = (DatagramPacket) msg;
message = packet.content().toString(io.netty.util.CharsetUtil.UTF_8);
message = packet.content().toString(SYSLOG_CHARSET);
source_ip=packet.sender().getAddress().getHostAddress();
source_port=packet.sender().getPort();
source = packet.sender().getAddress().getHostAddress() + ":" + packet.sender().getPort();
@@ -9,13 +9,14 @@ import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import java.nio.charset.Charset;
/**
* TCP 通道初始化器
*/
public class SyslogTcpChannelInitializer extends ChannelInitializer<SocketChannel> {
private static final int MAX_FRAME_LENGTH = AppConfig.getSyslogMaxFrameLength();
private static final Charset SYSLOG_CHARSET = AppConfig.getSyslogCharset();
@Override
protected void initChannel(SocketChannel ch) throws Exception {
@@ -26,9 +27,9 @@ public class SyslogTcpChannelInitializer extends ChannelInitializer<SocketChanne
MAX_FRAME_LENGTH,
Delimiters.lineDelimiter()));
// 添加字符串解码器和编码器
pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
// 添加字符串解码器和编码器(使用可配置的字符集)
pipeline.addLast("decoder", new StringDecoder(SYSLOG_CHARSET));
pipeline.addLast("encoder", new StringEncoder(SYSLOG_CHARSET));
// 添加业务处理器
pipeline.addLast("handler", new SyslogMessageHandler());
@@ -1,23 +1,26 @@
package com.netty;
import com.haobang.config.AppConfig;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.DatagramChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import java.nio.charset.Charset;
/**
* UDP 通道初始化器
*/
public class SyslogUdpChannelInitializer extends ChannelInitializer<DatagramChannel> {
private static final Charset SYSLOG_CHARSET = AppConfig.getSyslogCharset();
@Override
protected void initChannel(DatagramChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 添加字符串解码器和编码器
pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
// 添加字符串解码器和编码器(使用可配置的字符集)
pipeline.addLast("decoder", new StringDecoder(SYSLOG_CHARSET));
pipeline.addLast("encoder", new StringEncoder(SYSLOG_CHARSET));
// 添加业务处理器
pipeline.addLast("handler", new SyslogMessageHandler());