Compare commits

...

2 Commits

  1. 3
      Dockerfile
  2. 50
      pom.xml
  3. 30
      src/main/java/com/techsor/datacenter/sender/service/TrendLogService.java

3
Dockerfile

@ -1,7 +1,8 @@
# FROM registry.ap-northeast-1.aliyuncs.com/southwave/jdk17-template:latest
FROM amazoncorretto:17-alpine
# 安装 fontconfig 和 DejaVu 字体 (这是一个通用且免费的字体包)
RUN apk --no-cache add fontconfig ttf-dejavu
RUN apk --no-cache upgrade && \
apk --no-cache add fontconfig ttf-dejavu
WORKDIR /app
COPY target/data-center-sender.jar app.jar

50
pom.xml

@ -469,40 +469,19 @@
</configuration>
</plugin>
<!-- 正式环境 -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.1</version>
<configuration>
<authConfig>
<username>AKIAR26KHSVRUEAKRBPZ</username>
<password>wmMPx9vypaNi5ZIlyz4c018hKCb2M1dnGBdA+oh2</password>
</authConfig>
<images>
<image>
<name>${aws.ecr.registry}/aeon-prod/${aws.ecr.repositoryProd}:latest</name>
<registry>${aws.ecr.registry}</registry>
<build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
</build>
</image>
</images>
</configuration>
</plugin>
<!-- &lt;!&ndash; 测试环境 &ndash;&gt;-->
<!--&lt;!&ndash; 正式环境 &ndash;&gt;-->
<!-- <plugin>-->
<!-- <groupId>io.fabric8</groupId>-->
<!-- <artifactId>docker-maven-plugin</artifactId>-->
<!-- <version>0.38.1</version>-->
<!-- <configuration>-->
<!-- <authConfig>-->
<!-- <username>AKIAVSKFRQDPNWHJDSHL</username>-->
<!-- <password>DqGyOiVFKI50/Ix+cjvj25vPL2tC7NJrJ7fqzn/g</password>-->
<!-- <username>AKIAR26KHSVRUEAKRBPZ</username>-->
<!-- <password>wmMPx9vypaNi5ZIlyz4c018hKCb2M1dnGBdA+oh2</password>-->
<!-- </authConfig>-->
<!-- <images>-->
<!-- <image>-->
<!-- <name>${aws.ecr.registryTest}/aeon/${aws.ecr.repository}:latest</name>-->
<!-- <name>${aws.ecr.registry}/aeon-prod/${aws.ecr.repositoryProd}:latest</name>-->
<!-- <registry>${aws.ecr.registry}</registry>-->
<!-- <build>-->
<!-- <dockerFile>${project.basedir}/Dockerfile</dockerFile>-->
@ -511,6 +490,27 @@
<!-- </images>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- 测试环境 -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.1</version>
<configuration>
<authConfig>
<username>AKIAVSKFRQDPNWHJDSHL</username>
<password>DqGyOiVFKI50/Ix+cjvj25vPL2tC7NJrJ7fqzn/g</password>
</authConfig>
<images>
<image>
<name>${aws.ecr.registryTest}/aeon/${aws.ecr.repository}:latest</name>
<registry>${aws.ecr.registry}</registry>
<build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>

30
src/main/java/com/techsor/datacenter/sender/service/TrendLogService.java

@ -9,6 +9,7 @@ import com.techsor.datacenter.sender.dao.KingIOServerDAO;
import com.techsor.datacenter.sender.dao.TypeDAO;
import com.techsor.datacenter.sender.entitiy.DeviceEntity;
import com.techsor.datacenter.sender.entitiy.kingio.*;
import com.techsor.datacenter.sender.utils.RedisUtils;
import com.techsor.datacenter.sender.utils.TimeUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
@ -28,6 +29,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 服务类用于处理TrendLog的数据
@ -44,6 +46,8 @@ public class TrendLogService {
KingIOServerDAO kingIOServerDAO;
@Autowired
private CommonOpt commonOpt;
@Autowired
private RedisUtils redisUtils;
private final ObjectMapper objectMapper = new ObjectMapper();
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
@ -102,6 +106,22 @@ public class TrendLogService {
if (deviceItem==null){
continue;
}
boolean shouldProcess = true;
String redisKey = "trendLog_data_cache:" + data.getDeviceId() + ":" + dataItem.getTimestamp();
// 1. Check if data exists in Redis cache (with error handling)
try {
if (redisUtils.hasKey(redisKey)) {
log.info("TrendLog data exists in cache, skipping: deviceId={}, timestamp={}", data.getDeviceId(), dataItem.getTimestamp());
DataSourceContextHolder.clearCurrentDataSourceKey();
continue;
}
} catch (Exception e) {
log.warn("Failed to check Redis cache, continuing to process data: deviceId={}, timestamp={}, error={}",
data.getDeviceId(), dataItem.getTimestamp(), e.getMessage());
}
log.info("TrendLog process item:{},{},{}",data.getDeviceId(),dataItem.getLogData(),dataItem.getTimestamp());
tempEntity.setDeviceId(deviceItem.getDeviceId());
tempEntity.setContent(generateDBMStr(deviceItem,dataItem.getLogData()));
@ -112,7 +132,17 @@ public class TrendLogService {
log.error("Received Time : "+dataItem.getTimestamp());
tempEntity.setTs("");
}
dbmValues.add(tempEntity);
// 2. Write deviceId and timestamp to Redis cache with 30 minutes expiration (with error handling)
try {
redisUtils.add(redisKey, "1", 60, TimeUnit.MINUTES);
log.info("TrendLog data written to cache: key={}", redisKey);
} catch (Exception e) {
log.error("Failed to write to Redis cache, data would insert without dump remove: key={}, error={}", redisKey, e.getMessage());
}
DataSourceContextHolder.clearCurrentDataSourceKey();
}

Loading…
Cancel
Save