feat(integration): 添加渲染工作器服务集成

- 新增 RenderWorkerConfigV2Client 和 RenderWorkerV2Client 接口
- 实现 RenderWorkerConfigIntegrationService 和 RenderWorkerIntegrationService 服务类
- 添加相关 DTO 类和 BatchConfigBuilder 工具类
- 在 IntegrationProperties 中增加 render 相关配置
- 更新 CommonResponse 类,增加 success 字段
- 新增 RenderWorkerIntegrationConfig 配置类
This commit is contained in:
2025-09-05 11:46:19 +08:00
parent 0a13bd8b12
commit 60ce65f3e4
16 changed files with 1201 additions and 6 deletions

View File

@@ -0,0 +1,59 @@
package com.ycwl.basic.integration.render.client;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.render.dto.config.BatchRenderWorkerConfigRequest;
import com.ycwl.basic.integration.render.dto.config.RenderWorkerConfigV2DTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* 渲染工作器配置V2客户端
*/
@FeignClient(name = "zt-render-worker", contextId = "render-worker-config-v2", path = "/api/render/worker/config/v2")
public interface RenderWorkerConfigV2Client {
/**
* 获取工作器所有配置
*/
@GetMapping("/{workerId}")
CommonResponse<List<RenderWorkerConfigV2DTO>> getWorkerConfigs(@PathVariable("workerId") Long workerId);
/**
* 根据配置键获取特定配置
*/
@GetMapping("/{workerId}/key/{configKey}")
CommonResponse<RenderWorkerConfigV2DTO> getWorkerConfigByKey(@PathVariable("workerId") Long workerId,
@PathVariable("configKey") String configKey);
/**
* 创建配置
*/
@PostMapping("/{workerId}")
CommonResponse<RenderWorkerConfigV2DTO> createWorkerConfig(@PathVariable("workerId") Long workerId,
@RequestBody RenderWorkerConfigV2DTO config);
/**
* 更新配置
*/
@PutMapping("/{workerId}/{id}")
CommonResponse<Void> updateWorkerConfig(@PathVariable("workerId") Long workerId,
@PathVariable("id") Long id,
@RequestBody Map<String, Object> updates);
/**
* 删除配置
*/
@DeleteMapping("/{workerId}/{id}")
CommonResponse<Void> deleteWorkerConfig(@PathVariable("workerId") Long workerId,
@PathVariable("id") Long id);
/**
* 批量更新配置
*/
@PostMapping("/{workerId}/batch")
CommonResponse<Void> batchUpdateWorkerConfigs(@PathVariable("workerId") Long workerId,
@RequestBody BatchRenderWorkerConfigRequest request);
}

View File

@@ -0,0 +1,76 @@
package com.ycwl.basic.integration.render.client;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.render.dto.worker.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* 渲染工作器V2客户端
*/
@FeignClient(name = "zt-render-worker", contextId = "render-worker-v2", path = "/api/render/worker/v2")
public interface RenderWorkerV2Client {
/**
* 获取工作器核心信息
*/
@GetMapping("/{id}")
CommonResponse<RenderWorkerV2DTO> getWorker(@PathVariable("id") Long id);
/**
* 获取工作器含配置信息
*/
@GetMapping("/{id}/with-config")
CommonResponse<RenderWorkerV2WithConfigDTO> getWorkerWithConfig(@PathVariable("id") Long id);
/**
* 创建工作器
*/
@PostMapping
CommonResponse<RenderWorkerV2DTO> createWorker(@RequestBody CreateRenderWorkerRequest request);
/**
* 更新工作器
*/
@PutMapping("/{id}")
CommonResponse<Void> updateWorker(@PathVariable("id") Long id,
@RequestBody UpdateRenderWorkerRequest request);
/**
* 删除工作器
*/
@DeleteMapping("/{id}")
CommonResponse<Void> deleteWorker(@PathVariable("id") Long id);
/**
* 分页查询工作器列表(核心信息)
*/
@GetMapping
PageResponse<RenderWorkerV2ListResponse> listWorkers(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) Integer isEnabled,
@RequestParam(required = false) String name);
/**
* 分页查询工作器列表(含配置信息)
*/
@GetMapping("/with-config")
PageResponse<RenderWorkerV2WithConfigListResponse> listWorkersWithConfig(
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) Integer isEnabled,
@RequestParam(required = false) String name);
/**
* 根据key获取工作器核心信息
*/
@GetMapping("/key/{key}")
CommonResponse<RenderWorkerV2DTO> getWorkerByKey(@PathVariable("key") String key);
/**
* 根据key获取工作器完整信息(含配置)
*/
@GetMapping("/key/{key}/with-config")
CommonResponse<RenderWorkerV2WithConfigDTO> getWorkerWithConfigByKey(@PathVariable("key") String key);
}

View File

@@ -0,0 +1,19 @@
package com.ycwl.basic.integration.render.config;
import com.ycwl.basic.integration.common.config.IntegrationProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
/**
* 渲染工作器集成配置
*/
@Configuration
@ConditionalOnProperty(prefix = "integration.render", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableFeignClients(basePackages = "com.ycwl.basic.integration.render.client")
@RequiredArgsConstructor
public class RenderWorkerIntegrationConfig {
private final IntegrationProperties integrationProperties;
}

View File

@@ -0,0 +1,17 @@
package com.ycwl.basic.integration.render.dto.config;
import lombok.Data;
import java.util.List;
/**
* 批量更新渲染工作器配置请求DTO
*/
@Data
public class BatchRenderWorkerConfigRequest {
/**
* 配置列表
*/
private List<RenderWorkerConfigV2DTO> configs;
}

View File

@@ -0,0 +1,63 @@
package com.ycwl.basic.integration.render.dto.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 渲染工作器配置DTO
*/
@Data
public class RenderWorkerConfigV2DTO {
/**
* 配置ID
*/
private Long id;
/**
* 工作器ID
*/
@JsonProperty("worker_id")
private Long workerId;
/**
* 配置键
*/
@JsonProperty("config_key")
private String configKey;
/**
* 配置值
*/
@JsonProperty("config_value")
private String configValue;
/**
* 配置类型 (string/int/float/bool/json)
*/
@JsonProperty("config_type")
private String configType;
/**
* 描述
*/
private String description;
/**
* 是否启用 (0-禁用,1-启用)
*/
@JsonProperty("is_active")
private Integer isActive;
/**
* 创建时间
*/
@JsonProperty("create_time")
private String createTime;
/**
* 更新时间
*/
@JsonProperty("update_time")
private String updateTime;
}

View File

@@ -0,0 +1,31 @@
package com.ycwl.basic.integration.render.dto.worker;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 创建渲染工作器请求DTO
*/
@Data
public class CreateRenderWorkerRequest {
/**
* 工作器名称
*/
@NotBlank(message = "工作器名称不能为空")
private String name;
/**
* 工作器标识
*/
@NotBlank(message = "工作器标识不能为空")
private String key;
/**
* 是否启用 (0-禁用,1-启用)
*/
@JsonProperty("is_active")
private Integer isActive = 1;
}

View File

@@ -0,0 +1,49 @@
package com.ycwl.basic.integration.render.dto.worker;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
/**
* 渲染工作器核心信息DTO
*/
@Data
public class RenderWorkerV2DTO {
/**
* 工作器ID
*/
private Long id;
/**
* 工作器名称
*/
private String name;
/**
* 工作器标识
*/
private String key;
/**
* 是否启用 (0-禁用,1-启用)
*/
@JsonProperty("is_active")
private Integer isActive;
/**
* 创建时间
*/
@JsonProperty("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* 更新时间
*/
@JsonProperty("update_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}

View File

@@ -0,0 +1,33 @@
package com.ycwl.basic.integration.render.dto.worker;
import lombok.Data;
import java.util.List;
/**
* 渲染工作器列表响应DTO
*/
@Data
public class RenderWorkerV2ListResponse {
/**
* 工作器列表
*/
private List<RenderWorkerV2DTO> list;
/**
* 总数
*/
private String total;
/**
* 当前页
*/
private Integer page;
/**
* 页大小
*/
@SuppressWarnings("unused")
private Integer pageSize;
}

View File

@@ -0,0 +1,55 @@
package com.ycwl.basic.integration.render.dto.worker;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
import java.util.Map;
/**
* 带配置的渲染工作器DTO
*/
@Data
public class RenderWorkerV2WithConfigDTO {
/**
* 工作器ID
*/
private Long id;
/**
* 工作器名称
*/
private String name;
/**
* 工作器标识
*/
private String key;
/**
* 是否启用 (0-禁用,1-启用)
*/
@JsonProperty("is_active")
private Integer isActive;
/**
* 创建时间
*/
@JsonProperty("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* 更新时间
*/
@JsonProperty("update_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/**
* 动态配置信息
*/
private Map<String, Object> config;
}

View File

@@ -0,0 +1,33 @@
package com.ycwl.basic.integration.render.dto.worker;
import lombok.Data;
import java.util.List;
/**
* 带配置的渲染工作器列表响应DTO
*/
@Data
public class RenderWorkerV2WithConfigListResponse {
/**
* 工作器列表
*/
private List<RenderWorkerV2WithConfigDTO> list;
/**
* 总数
*/
private String total;
/**
* 当前页
*/
private Integer page;
/**
* 页大小
*/
@SuppressWarnings("unused")
private Integer pageSize;
}

View File

@@ -0,0 +1,27 @@
package com.ycwl.basic.integration.render.dto.worker;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* 更新渲染工作器请求DTO
*/
@Data
public class UpdateRenderWorkerRequest {
/**
* 工作器名称
*/
private String name;
/**
* 工作器标识
*/
private String key;
/**
* 是否启用 (0-禁用,1-启用)
*/
@JsonProperty("is_active")
private Integer isActive;
}

View File

@@ -0,0 +1,287 @@
package com.ycwl.basic.integration.render.service;
import com.ycwl.basic.integration.common.exception.IntegrationException;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.service.IntegrationFallbackService;
import com.ycwl.basic.integration.render.client.RenderWorkerConfigV2Client;
import com.ycwl.basic.integration.render.dto.config.BatchRenderWorkerConfigRequest;
import com.ycwl.basic.integration.render.dto.config.RenderWorkerConfigV2DTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 渲染工作器配置集成服务
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class RenderWorkerConfigIntegrationService {
private final RenderWorkerConfigV2Client renderWorkerConfigV2Client;
private final IntegrationFallbackService fallbackService;
private static final String SERVICE_NAME = "zt-render-worker";
/**
* 获取工作器所有配置(带降级)
*/
public List<RenderWorkerConfigV2DTO> getWorkerConfigs(Long workerId) {
log.info("获取渲染工作器配置列表, workerId: {}", workerId);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:configs:" + workerId,
() -> {
CommonResponse<List<RenderWorkerConfigV2DTO>> response =
renderWorkerConfigV2Client.getWorkerConfigs(workerId);
List<RenderWorkerConfigV2DTO> configs = handleResponse(response, "获取渲染工作器配置列表失败");
return configs != null ? configs : Collections.emptyList();
},
List.class
);
}
/**
* 根据配置键获取特定配置(带降级)
*/
public RenderWorkerConfigV2DTO getWorkerConfigByKey(Long workerId, String configKey) {
log.info("根据配置键获取渲染工作器配置, workerId: {}, configKey: {}", workerId, configKey);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:config:" + workerId + ":" + configKey,
() -> {
CommonResponse<RenderWorkerConfigV2DTO> response =
renderWorkerConfigV2Client.getWorkerConfigByKey(workerId, configKey);
return handleResponse(response, "根据配置键获取渲染工作器配置失败");
},
RenderWorkerConfigV2DTO.class
);
}
/**
* 获取工作器平铺配置(带降级)
*/
public Map<String, Object> getWorkerFlatConfig(Long workerId) {
log.info("获取渲染工作器平铺配置, workerId: {}", workerId);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:flat:config:" + workerId,
() -> {
List<RenderWorkerConfigV2DTO> configs = getWorkerConfigsInternal(workerId);
return flattenConfigs(configs);
},
Map.class
);
}
/**
* 创建配置(直接调用,不降级)
*/
public RenderWorkerConfigV2DTO createWorkerConfig(Long workerId, RenderWorkerConfigV2DTO config) {
log.info("创建渲染工作器配置, workerId: {}, configKey: {}", workerId, config.getConfigKey());
CommonResponse<RenderWorkerConfigV2DTO> response =
renderWorkerConfigV2Client.createWorkerConfig(workerId, config);
return handleResponse(response, "创建渲染工作器配置失败");
}
/**
* 更新配置(直接调用,不降级)
*/
public void updateWorkerConfig(Long workerId, Long configId, Map<String, Object> updates) {
log.info("更新渲染工作器配置, workerId: {}, configId: {}", workerId, configId);
CommonResponse<Void> response =
renderWorkerConfigV2Client.updateWorkerConfig(workerId, configId, updates);
handleVoidResponse(response, "更新渲染工作器配置失败");
}
/**
* 删除配置(直接调用,不降级)
*/
public void deleteWorkerConfig(Long workerId, Long configId) {
log.info("删除渲染工作器配置, workerId: {}, configId: {}", workerId, configId);
CommonResponse<Void> response =
renderWorkerConfigV2Client.deleteWorkerConfig(workerId, configId);
handleVoidResponse(response, "删除渲染工作器配置失败");
}
/**
* 批量更新配置(直接调用,不降级)
*/
public void batchUpdateWorkerConfigs(Long workerId, BatchRenderWorkerConfigRequest request) {
log.info("批量更新渲染工作器配置, workerId: {}, configCount: {}",
workerId, request.getConfigs() != null ? request.getConfigs().size() : 0);
CommonResponse<Void> response =
renderWorkerConfigV2Client.batchUpdateWorkerConfigs(workerId, request);
handleVoidResponse(response, "批量更新渲染工作器配置失败");
}
/**
* 批量平铺更新配置(直接调用,不降级)
*/
public void batchFlatUpdateWorkerConfigs(Long workerId, Map<String, Object> flatConfigs) {
log.info("批量平铺更新渲染工作器配置, workerId: {}, configCount: {}",
workerId, flatConfigs.size());
BatchRenderWorkerConfigRequest request = new BatchRenderWorkerConfigRequest();
List<RenderWorkerConfigV2DTO> configs = flatConfigs.entrySet().stream()
.map(entry -> {
RenderWorkerConfigV2DTO config = new RenderWorkerConfigV2DTO();
config.setConfigKey(entry.getKey());
config.setConfigValue(String.valueOf(entry.getValue()));
config.setConfigType(determineConfigType(entry.getValue()));
config.setIsActive(1);
return config;
})
.toList();
request.setConfigs(configs);
batchUpdateWorkerConfigs(workerId, request);
}
/**
* 创建批量配置构建器
*/
public BatchConfigBuilder createBatchConfigBuilder() {
return new BatchConfigBuilder();
}
/**
* 内部获取配置方法(不使用降级)
*/
private List<RenderWorkerConfigV2DTO> getWorkerConfigsInternal(Long workerId) {
CommonResponse<List<RenderWorkerConfigV2DTO>> response =
renderWorkerConfigV2Client.getWorkerConfigs(workerId);
List<RenderWorkerConfigV2DTO> configs = handleResponse(response, "获取渲染工作器配置列表失败");
return configs != null ? configs : Collections.emptyList();
}
/**
* 将配置列表转换为平铺Map
*/
private Map<String, Object> flattenConfigs(List<RenderWorkerConfigV2DTO> configs) {
Map<String, Object> flatConfig = new HashMap<>();
for (RenderWorkerConfigV2DTO config : configs) {
if (config.getIsActive() == 1) {
Object value = convertConfigValue(config.getConfigValue(), config.getConfigType());
flatConfig.put(config.getConfigKey(), value);
}
}
return flatConfig;
}
/**
* 根据配置类型转换配置值
*/
private Object convertConfigValue(String configValue, String configType) {
if (configValue == null) return null;
return switch (configType) {
case "int" -> Integer.parseInt(configValue);
case "float" -> Double.parseDouble(configValue);
case "bool" -> Boolean.parseBoolean(configValue);
case "json" -> configValue; // 保持JSON字符串格式
default -> configValue; // string类型或其他
};
}
/**
* 自动判断配置类型
*/
private String determineConfigType(Object value) {
if (value instanceof Integer) return "int";
if (value instanceof Double || value instanceof Float) return "float";
if (value instanceof Boolean) return "bool";
return "string";
}
/**
* 处理通用响应
*/
private <T> T handleResponse(CommonResponse<T> response, String errorMessage) {
if (response == null || !response.getSuccess()) {
String msg = response != null && response.getMessage() != null ?
response.getMessage() : errorMessage;
Integer code = response != null ? response.getCode() : 5000;
throw new IntegrationException(code, msg, SERVICE_NAME);
}
return response.getData();
}
/**
* 处理空响应
*/
private void handleVoidResponse(CommonResponse<Void> response, String errorMessage) {
if (response == null || !response.getSuccess()) {
String msg = response != null && response.getMessage() != null ?
response.getMessage() : errorMessage;
Integer code = response != null ? response.getCode() : 5000;
throw new IntegrationException(code, msg, SERVICE_NAME);
}
}
/**
* 批量配置构建器
*/
public static class BatchConfigBuilder {
private final List<RenderWorkerConfigV2DTO> configs = new java.util.ArrayList<>();
/**
* 添加配置项
*/
public BatchConfigBuilder addConfig(String key, String value) {
return addConfig(key, value, "string", null);
}
/**
* 添加配置项(指定类型)
*/
public BatchConfigBuilder addConfig(String key, String value, String type) {
return addConfig(key, value, type, null);
}
/**
* 添加配置项(完整)
*/
public BatchConfigBuilder addConfig(String key, String value, String type, String description) {
RenderWorkerConfigV2DTO config = new RenderWorkerConfigV2DTO();
config.setConfigKey(key);
config.setConfigValue(value);
config.setConfigType(type);
config.setDescription(description);
config.setIsActive(1);
configs.add(config);
return this;
}
/**
* 添加渲染配置
*/
public BatchConfigBuilder addRenderConfig(String quality, String format, String resolution) {
return addConfig("render_quality", quality, "string", "渲染质量")
.addConfig("render_format", format, "string", "渲染格式")
.addConfig("render_resolution", resolution, "string", "渲染分辨率");
}
/**
* 添加性能配置
*/
public BatchConfigBuilder addPerformanceConfig(Integer maxTasks, Integer timeout) {
return addConfig("max_concurrent_tasks", String.valueOf(maxTasks), "int", "最大并发任务数")
.addConfig("task_timeout", String.valueOf(timeout), "int", "任务超时时间(秒)");
}
/**
* 构建批量配置请求
*/
public BatchRenderWorkerConfigRequest build() {
BatchRenderWorkerConfigRequest request = new BatchRenderWorkerConfigRequest();
request.setConfigs(configs);
return request;
}
}
}

View File

@@ -0,0 +1,195 @@
package com.ycwl.basic.integration.render.service;
import com.ycwl.basic.integration.common.exception.IntegrationException;
import com.ycwl.basic.integration.common.response.CommonResponse;
import com.ycwl.basic.integration.common.response.PageResponse;
import com.ycwl.basic.integration.common.service.IntegrationFallbackService;
import com.ycwl.basic.integration.render.client.RenderWorkerV2Client;
import com.ycwl.basic.integration.render.dto.worker.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/**
* 渲染工作器集成服务
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class RenderWorkerIntegrationService {
private final RenderWorkerV2Client renderWorkerV2Client;
private final IntegrationFallbackService fallbackService;
private static final String SERVICE_NAME = "zt-render-worker";
/**
* 获取工作器核心信息(带降级)
*/
public RenderWorkerV2DTO getWorker(Long id) {
log.info("获取渲染工作器信息, id: {}", id);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:" + id,
() -> {
CommonResponse<RenderWorkerV2DTO> response = renderWorkerV2Client.getWorker(id);
return handleResponse(response, "获取渲染工作器信息失败");
},
RenderWorkerV2DTO.class
);
}
/**
* 获取工作器详细信息(含配置)(带降级)
*/
public RenderWorkerV2WithConfigDTO getWorkerWithConfig(Long id) {
log.info("获取渲染工作器详细信息, id: {}", id);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:config:" + id,
() -> {
CommonResponse<RenderWorkerV2WithConfigDTO> response = renderWorkerV2Client.getWorkerWithConfig(id);
return handleResponse(response, "获取渲染工作器详细信息失败");
},
RenderWorkerV2WithConfigDTO.class
);
}
/**
* 创建工作器(直接调用,不降级)
*/
public RenderWorkerV2DTO createWorker(CreateRenderWorkerRequest request) {
log.info("创建渲染工作器, name: {}, key: {}", request.getName(), request.getKey());
CommonResponse<RenderWorkerV2DTO> response = renderWorkerV2Client.createWorker(request);
return handleResponse(response, "创建渲染工作器失败");
}
/**
* 更新工作器(直接调用,不降级)
*/
public void updateWorker(Long id, UpdateRenderWorkerRequest request) {
log.info("更新渲染工作器, id: {}, name: {}", id, request.getName());
CommonResponse<Void> response = renderWorkerV2Client.updateWorker(id, request);
handleVoidResponse(response, "更新渲染工作器失败");
}
/**
* 删除工作器(直接调用,不降级)
*/
public void deleteWorker(Long id) {
log.info("删除渲染工作器, id: {}", id);
CommonResponse<Void> response = renderWorkerV2Client.deleteWorker(id);
handleVoidResponse(response, "删除渲染工作器失败");
}
/**
* 分页查询工作器列表(核心信息)(不降级)
*/
public List<RenderWorkerV2DTO> listWorkers(Integer page, Integer pageSize, Integer isEnabled, String name) {
log.info("分页查询渲染工作器列表, page: {}, pageSize: {}, isEnabled: {}, name: {}",
page, pageSize, isEnabled, name);
try {
PageResponse<RenderWorkerV2ListResponse> response =
renderWorkerV2Client.listWorkers(page, pageSize, isEnabled, name);
RenderWorkerV2ListResponse listResponse = handlePageResponse(response, "查询渲染工作器列表失败");
return listResponse != null && listResponse.getList() != null ?
listResponse.getList() : Collections.emptyList();
} catch (Exception e) {
log.error("查询渲染工作器列表异常", e);
return Collections.emptyList();
}
}
/**
* 分页查询工作器列表(含配置信息)(不降级)
*/
public List<RenderWorkerV2WithConfigDTO> listWorkersWithConfig(Integer page, Integer pageSize,
Integer isEnabled, String name) {
log.info("分页查询渲染工作器列表(含配置), page: {}, pageSize: {}, isEnabled: {}, name: {}",
page, pageSize, isEnabled, name);
try {
PageResponse<RenderWorkerV2WithConfigListResponse> response =
renderWorkerV2Client.listWorkersWithConfig(page, pageSize, isEnabled, name);
RenderWorkerV2WithConfigListResponse listResponse =
handlePageResponse(response, "查询渲染工作器列表(含配置)失败");
return listResponse != null && listResponse.getList() != null ?
listResponse.getList() : Collections.emptyList();
} catch (Exception e) {
log.error("查询渲染工作器列表(含配置)异常", e);
return Collections.emptyList();
}
}
/**
* 根据key获取工作器核心信息(带降级)
*/
public RenderWorkerV2DTO getWorkerByKey(String key) {
log.info("根据key获取渲染工作器信息, key: {}", key);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:key:" + key,
() -> {
CommonResponse<RenderWorkerV2DTO> response = renderWorkerV2Client.getWorkerByKey(key);
return handleResponse(response, "根据key获取渲染工作器信息失败");
},
RenderWorkerV2DTO.class
);
}
/**
* 根据key获取工作器详细信息(含配置)(带降级)
*/
public RenderWorkerV2WithConfigDTO getWorkerWithConfigByKey(String key) {
log.info("根据key获取渲染工作器详细信息, key: {}", key);
return fallbackService.executeWithFallback(
SERVICE_NAME,
"worker:key:config:" + key,
() -> {
CommonResponse<RenderWorkerV2WithConfigDTO> response = renderWorkerV2Client.getWorkerWithConfigByKey(key);
return handleResponse(response, "根据key获取渲染工作器详细信息失败");
},
RenderWorkerV2WithConfigDTO.class
);
}
/**
* 处理通用响应
*/
private <T> T handleResponse(CommonResponse<T> response, String errorMessage) {
if (response == null || !response.getSuccess()) {
String msg = response != null && response.getMessage() != null ?
response.getMessage() : errorMessage;
Integer code = response != null ? response.getCode() : 5000;
throw new IntegrationException(code, msg, SERVICE_NAME);
}
return response.getData();
}
/**
* 处理空响应
*/
private void handleVoidResponse(CommonResponse<Void> response, String errorMessage) {
if (response == null || !response.getSuccess()) {
String msg = response != null && response.getMessage() != null ?
response.getMessage() : errorMessage;
Integer code = response != null ? response.getCode() : 5000;
throw new IntegrationException(code, msg, SERVICE_NAME);
}
}
/**
* 处理分页响应
*/
private <T> T handlePageResponse(PageResponse<T> response, String errorMessage) {
if (response == null || !response.getSuccess()) {
String msg = response != null && response.getMessage() != null ?
response.getMessage() : errorMessage;
Integer code = response != null ? response.getCode() : 5000;
throw new IntegrationException(code, msg, SERVICE_NAME);
}
return response.getData();
}
}