Merge branch 'scenic-microservice'

# Conflicts:
#	src/main/java/com/ycwl/basic/integration/scenic/service/ScenicConfigIntegrationService.java
#	src/main/java/com/ycwl/basic/repository/ScenicRepository.java
This commit is contained in:
2025-09-09 14:04:43 +08:00
2 changed files with 25 additions and 13 deletions

View File

@@ -24,14 +24,28 @@ public class ScenicConfigIntegrationService {
public List<ScenicConfigV2DTO> listConfigs(Long scenicId) { public List<ScenicConfigV2DTO> listConfigs(Long scenicId) {
log.debug("获取景区配置列表, scenicId: {}", scenicId); log.debug("获取景区配置列表, scenicId: {}", scenicId);
CommonResponse<List<ScenicConfigV2DTO>> response = scenicConfigV2Client.listConfigs(scenicId); return fallbackService.executeWithFallback(
return handleResponse(response, "获取景区配置列表失败"); SERVICE_NAME,
"scenic:configs:" + scenicId,
() -> {
CommonResponse<List<ScenicConfigV2DTO>> response = scenicConfigV2Client.listConfigs(scenicId);
return handleResponse(response, "获取景区配置列表失败");
},
List.class
);
} }
public ScenicConfigV2DTO getConfigByKey(Long scenicId, String configKey) { public ScenicConfigV2DTO getConfigByKey(Long scenicId, String configKey) {
log.debug("根据键获取景区配置, scenicId: {}, configKey: {}", scenicId, configKey); log.debug("根据键获取景区配置, scenicId: {}, configKey: {}", scenicId, configKey);
CommonResponse<ScenicConfigV2DTO> response = scenicConfigV2Client.getConfigByKey(scenicId, configKey); return fallbackService.executeWithFallback(
return handleResponse(response, "根据键获取景区配置失败"); SERVICE_NAME,
"scenic:config:" + scenicId + ":" + configKey,
() -> {
CommonResponse<ScenicConfigV2DTO> response = scenicConfigV2Client.getConfigByKey(scenicId, configKey);
return handleResponse(response, "根据键获取景区配置失败");
},
ScenicConfigV2DTO.class
);
} }
public Map<String, Object> getFlatConfigs(Long scenicId) { public Map<String, Object> getFlatConfigs(Long scenicId) {

View File

@@ -24,10 +24,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.stream.Collectors; import java.util.Objects;
@Component @Component
public class ScenicRepository { public class ScenicRepository {
@@ -335,10 +336,7 @@ public class ScenicRepository {
public ScenicConfigManager getScenicConfigManager(Long scenicId) { public ScenicConfigManager getScenicConfigManager(Long scenicId) {
try { try {
List<ScenicConfigV2DTO> configList = scenicConfigIntegrationService.listConfigs(scenicId); List<ScenicConfigV2DTO> configList = scenicConfigIntegrationService.listConfigs(scenicId);
if (configList != null) { return new ScenicConfigManager(Objects.requireNonNullElse(configList, Collections.emptyList()));
return new ScenicConfigManager(configList);
}
return null;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
@@ -371,7 +369,7 @@ public class ScenicRepository {
if (scenicIds == null || scenicIds.isEmpty()) { if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>(); return new HashMap<>();
} }
Map<Long, String> result = new HashMap<>(); Map<Long, String> result = new HashMap<>();
for (Long scenicId : scenicIds) { for (Long scenicId : scenicIds) {
try { try {
@@ -389,14 +387,14 @@ public class ScenicRepository {
/** /**
* 批量获取景区完整信息 * 批量获取景区完整信息
* @param scenicIds 景区ID列表 * @param scenicIds 景区ID列表
* @return 景区ID到景区实体的映射 * @return 景区ID到景区实体的映射
*/ */
public Map<Long, ScenicEntity> batchGetScenics(List<Long> scenicIds) { public Map<Long, ScenicEntity> batchGetScenics(List<Long> scenicIds) {
if (scenicIds == null || scenicIds.isEmpty()) { if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>(); return new HashMap<>();
} }
Map<Long, ScenicEntity> result = new HashMap<>(); Map<Long, ScenicEntity> result = new HashMap<>();
for (Long scenicId : scenicIds) { for (Long scenicId : scenicIds) {
try { try {
@@ -421,7 +419,7 @@ public class ScenicRepository {
if (scenicIds == null || scenicIds.isEmpty()) { if (scenicIds == null || scenicIds.isEmpty()) {
return new HashMap<>(); return new HashMap<>();
} }
Map<Long, ScenicV2DTO> result = new HashMap<>(); Map<Long, ScenicV2DTO> result = new HashMap<>();
for (Long scenicId : scenicIds) { for (Long scenicId : scenicIds) {
try { try {