diff --git a/pom.xml b/pom.xml
index 43327cf..b6eb38c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,7 +38,17 @@
org.springframework.boot
spring-boot-starter-web
-
+
+ org.hibernate
+ hibernate-core
+ 5.6.15.Final
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+
org.postgresql
postgresql
@@ -57,7 +67,12 @@
org.springframework.boot
spring-boot-starter-data-jpa
- 3.4.5
+
+
+ org.hibernate.javax.persistence
+ hibernate-jpa-2.1-api
+
+
org.springframework.boot
@@ -75,18 +90,47 @@
org.mybatis.spring.boot
mybatis-spring-boot-starter
- 3.0.4
+ 2.3.1
org.apache.commons
commons-lang3
- 3.12.0
+ 3.17.0
org.mapstruct
mapstruct
1.5.5.Final
+
+ com.kingbase8
+ kingbase8
+ 9.0.0
+
+
+ com.github.pagehelper
+ pagehelper-spring-boot-starter
+ 1.4.7
+
+
+ org.springframework.boot
+ spring-boot-starter-redis
+ 1.4.7.RELEASE
+
+
+ com.mysql
+ mysql-connector-j
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ com.baomidou
+ mybatis-plus-generator
+ 3.5.6
+
+
diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/IntelligentApplicationOrchestrationServiceApplication.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/IntelligentApplicationOrchestrationServiceApplication.java
index c592c40..520a423 100644
--- a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/IntelligentApplicationOrchestrationServiceApplication.java
+++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/IntelligentApplicationOrchestrationServiceApplication.java
@@ -1,8 +1,10 @@
package com.bipt.intelligentapplicationorchestrationservice;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+@MapperScan("com.bipt.intelligentapplicationorchestrationservice.gpu.dao")
@SpringBootApplication
public class IntelligentApplicationOrchestrationServiceApplication {
diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/CacheManager.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/CacheManager.java
new file mode 100644
index 0000000..4b65b7f
--- /dev/null
+++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/CacheManager.java
@@ -0,0 +1,145 @@
+package com.bipt.intelligentapplicationorchestrationservice.gpu.cache;
+
+import com.bipt.intelligentapplicationorchestrationservice.gpu.dao.GpuResourceDao;
+import com.bipt.intelligentapplicationorchestrationservice.gpu.exception.CacheInitException;
+import com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource;
+import jakarta.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.RedisConnectionFailureException;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
+
+@Component
+public class CacheManager {
+ @Autowired
+ private RedisTemplate redisTemplate;
+
+ @Autowired
+ private GpuResourceDao gpuResourceDao;
+
+ private final ReentrantLock lock = new ReentrantLock();
+
+ @Value("${cache.redis-key-prefix:gpu:}")
+ private String keyPrefix;
+
+ @Value("${cache.ttl-base:7200}")
+ private int ttlBase;
+
+ @Value("${cache.init-batch-size:500}")
+ private int initBatchSize;
+
+ // 全量加载(带分页和分布式锁)
+ @PostConstruct
+ public void loadFullCache() {
+ if (tryLock()) {
+ try {
+ int page = 0;
+ while (true) {
+ List batch = gpuResourceDao.findByPage(page * initBatchSize, initBatchSize);
+ if (batch.isEmpty()) break;
+
+ batch.forEach(this::setCacheWithTTL);
+ page++;
+ }
+ } finally {
+ unlock();
+ }
+ }
+ }
+
+ // 单条缓存刷新(带版本控制)
+ public void refreshCache(Long gpuId) {
+ GpuResource latest = gpuResourceDao.selectByIdWithLock(gpuId);
+ if (latest != null) {
+ setCacheWithTTL(latest);
+ }
+ }
+
+ // 批量增量同步
+ public void syncCache(LocalDateTime lastSyncTime) {
+ List updates = gpuResourceDao.findModifiedSince(lastSyncTime);
+ updates.forEach(entity -> {
+ if (entity.getIsDeleted()) {
+ redisTemplate.delete(buildKey(entity.getGPUId().toString()));
+ } else {
+ setCacheWithTTL(entity);
+ }
+ });
+ }
+
+ // 带随机TTL的缓存设置
+ private void setCacheWithTTL(GpuResource entity) {
+ String key = buildKey(entity.getGPUId().toString());
+ redisTemplate.opsForValue().set(
+ key,
+ entity,
+ ttlBase + (int)(Math.random() * 600), // 随机TTL防止雪崩
+ TimeUnit.SECONDS
+ );
+ }
+
+ // 构建缓存键
+ private String buildKey(String gpuId) {
+ return keyPrefix + gpuId;
+ }
+
+ // 分布式锁操作
+ private boolean tryLock() {
+ try {
+ return lock.tryLock(30, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return false;
+ }
+ }
+
+ private void unlock() {
+ lock.unlock();
+ }
+ // 分页加载入口
+ public void loadFullCache(int batchSize) {
+ int page = 0;
+ while (true) {
+ List batch = gpuResourceDao.findByPage(page * batchSize, batchSize);
+ if (batch.isEmpty()) break;
+
+ batch.forEach(this::refreshWithRetry); // 带重试的刷新逻辑
+ page++;
+ }
+ }
+
+ // 带重试机制的缓存刷新
+ private void refreshWithRetry(GpuResource entity) {
+ try {
+ setCacheWithTTL(entity);
+ } catch (RedisConnectionFailureException ex) {
+ // 3次重试逻辑
+ for (int i = 0; i < 3; i++) {
+ try {
+ Thread.sleep(1000);
+ setCacheWithTTL(entity);
+ return;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ throw new CacheInitException("缓存刷新失败: " + entity.getGPUId().toString());
+ }
+ }
+
+ // 获取当前缓存数量(调试用)
+ public long getCacheCount() {
+ return redisTemplate.keys(keyPrefix + "*").size();
+ }
+
+ public void evictCache(Long gpuId) {
+ String key = buildKey(gpuId.toString());
+ redisTemplate.delete(key);
+ }
+}
diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/RedisCacheService.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/RedisCacheService.java
new file mode 100644
index 0000000..a3de985
--- /dev/null
+++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/gpu/cache/RedisCacheService.java
@@ -0,0 +1,126 @@
+package com.bipt.intelligentapplicationorchestrationservice.gpu.cache;
+
+
+import com.bipt.intelligentapplicationorchestrationservice.gpu.model.entity.GpuResource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.stereotype.Service;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class RedisCacheService {
+
+ private final RedisTemplate redisTemplate;
+
+ @Value("${cache.redis-key-prefix:gpu:}")
+ private String keyPrefix;
+
+ @Value("${cache.ttl-base:7200}")
+ private int baseTTL;
+ private final RedisSerializer