|
|
@ -8,11 +8,7 @@ import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
@ -21,33 +17,9 @@ public class SysApiPlatformConfigServiceImpl implements ISysApiPlatformConfigSer |
|
|
|
|
|
|
|
|
private final SysApiPlatformConfigMapper sysApiPlatformConfigMapper; |
|
|
private final SysApiPlatformConfigMapper sysApiPlatformConfigMapper; |
|
|
|
|
|
|
|
|
private final Map<String, SysApiPlatformConfigEntity> consumerCache = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
|
|
public void init() { |
|
|
|
|
|
refreshCache(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void refreshCache() { |
|
|
|
|
|
List<SysApiPlatformConfigEntity> list = sysApiPlatformConfigMapper.selectList( |
|
|
|
|
|
new LambdaQueryWrapper<SysApiPlatformConfigEntity>() |
|
|
|
|
|
.eq(SysApiPlatformConfigEntity::getStatus, "0") |
|
|
|
|
|
); |
|
|
|
|
|
Map<String, SysApiPlatformConfigEntity> newMap = new ConcurrentHashMap<>(); |
|
|
|
|
|
for (SysApiPlatformConfigEntity entity : list) { |
|
|
|
|
|
newMap.put(entity.getAppKey(), entity); |
|
|
|
|
|
} |
|
|
|
|
|
consumerCache.clear(); |
|
|
|
|
|
consumerCache.putAll(newMap); |
|
|
|
|
|
log.info("API接入配置缓存刷新, 共加载{}个渠道", newMap.size()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Optional<SysApiPlatformConfigEntity> findByAppKey(String appKey) { |
|
|
|
|
|
return Optional.ofNullable(consumerCache.get(appKey)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Optional<SysApiPlatformConfigEntity> findByAppKeyFromDb(String appKey) { |
|
|
public Optional<SysApiPlatformConfigEntity> findByAppKey(String appKey) { |
|
|
SysApiPlatformConfigEntity entity = sysApiPlatformConfigMapper.selectOne( |
|
|
SysApiPlatformConfigEntity entity = sysApiPlatformConfigMapper.selectOne( |
|
|
new LambdaQueryWrapper<SysApiPlatformConfigEntity>() |
|
|
new LambdaQueryWrapper<SysApiPlatformConfigEntity>() |
|
|
.eq(SysApiPlatformConfigEntity::getAppKey, appKey) |
|
|
.eq(SysApiPlatformConfigEntity::getAppKey, appKey) |
|
|
@ -55,4 +27,5 @@ public class SysApiPlatformConfigServiceImpl implements ISysApiPlatformConfigSer |
|
|
); |
|
|
); |
|
|
return Optional.ofNullable(entity); |
|
|
return Optional.ofNullable(entity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|