You've already forked FrameTour-BE
feat(RenderWorkerV2Controller): 添加带保活信息的渲染工作器DTO并更新控制器新增了RenderWorkerWithStatusDTO
类,用于封装带有保活信息的渲染工作器数据。在RenderWorkerV2Controller
中更新了listWorkers
方法,使其返回包含保活信息的工作器列表。
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.ycwl.basic.controller.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 带保活信息的渲染工作器DTO
|
||||
*/
|
||||
@Data
|
||||
public class RenderWorkerWithStatusDTO {
|
||||
|
||||
/**
|
||||
* 工作器ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 工作器名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 工作器标识
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 是否启用 (0-禁用,1-启用)
|
||||
*/
|
||||
@JsonProperty("isActive")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonProperty("createTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonProperty("updateTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 主机保活状态信息
|
||||
*/
|
||||
private ClientStatusReqVo hostStatus;
|
||||
|
||||
/**
|
||||
* 是否在线(基于保活信息判断)
|
||||
*/
|
||||
private Boolean isOnline;
|
||||
}
|
@@ -1,16 +1,23 @@
|
||||
package com.ycwl.basic.controller.pc;
|
||||
|
||||
import com.ycwl.basic.controller.dto.RenderWorkerWithStatusDTO;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.render.dto.worker.CreateRenderWorkerRequest;
|
||||
import com.ycwl.basic.integration.render.dto.worker.RenderWorkerV2DTO;
|
||||
import com.ycwl.basic.integration.render.dto.worker.UpdateRenderWorkerRequest;
|
||||
import com.ycwl.basic.integration.render.service.RenderWorkerIntegrationService;
|
||||
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
|
||||
import com.ycwl.basic.repository.RenderWorkerRepository;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 渲染工作器管理 V2 版本控制器
|
||||
* 基于 zt-render-worker 微服务标准接口实现
|
||||
@@ -25,18 +32,19 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class RenderWorkerV2Controller {
|
||||
|
||||
private final RenderWorkerIntegrationService renderWorkerIntegrationService;
|
||||
private final RenderWorkerRepository renderWorkerRepository;
|
||||
|
||||
/**
|
||||
* 分页查询渲染工作器列表
|
||||
* 分页查询渲染工作器列表(带保活信息)
|
||||
*
|
||||
* @param page 页码,从1开始
|
||||
* @param pageSize 每页大小,默认10,最大100
|
||||
* @param isEnabled 是否启用(0-禁用,1-启用)
|
||||
* @param name 工作器名称(模糊搜索)
|
||||
* @return 分页查询结果
|
||||
* @return 分页查询结果(包含保活信息)
|
||||
*/
|
||||
@GetMapping
|
||||
public ApiResponse<PageResponse<RenderWorkerV2DTO>> listWorkers(
|
||||
public ApiResponse<PageResponse<RenderWorkerWithStatusDTO>> listWorkers(
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) Integer isEnabled,
|
||||
@@ -51,8 +59,33 @@ public class RenderWorkerV2Controller {
|
||||
}
|
||||
|
||||
try {
|
||||
PageResponse<RenderWorkerV2DTO> result = renderWorkerIntegrationService.listWorkers(
|
||||
// 获取基础工作器列表
|
||||
PageResponse<RenderWorkerV2DTO> basicResult = renderWorkerIntegrationService.listWorkers(
|
||||
page, pageSize, isEnabled, name);
|
||||
|
||||
// 转换为带保活信息的DTO列表
|
||||
List<RenderWorkerWithStatusDTO> workersWithStatus = new ArrayList<>();
|
||||
for (RenderWorkerV2DTO worker : basicResult.getList()) {
|
||||
RenderWorkerWithStatusDTO workerWithStatus = new RenderWorkerWithStatusDTO();
|
||||
|
||||
// 复制基础信息
|
||||
BeanUtils.copyProperties(worker, workerWithStatus);
|
||||
|
||||
// 查询保活信息
|
||||
ClientStatusReqVo hostStatus = renderWorkerRepository.getWorkerHostStatus(worker.getId());
|
||||
workerWithStatus.setHostStatus(hostStatus);
|
||||
workerWithStatus.setIsOnline(hostStatus != null);
|
||||
|
||||
workersWithStatus.add(workerWithStatus);
|
||||
}
|
||||
|
||||
// 构建带保活信息的分页响应
|
||||
PageResponse<RenderWorkerWithStatusDTO> result = new PageResponse<>();
|
||||
result.setList(workersWithStatus);
|
||||
result.setTotal(basicResult.getTotal());
|
||||
result.setPage(basicResult.getPage());
|
||||
result.setPageSize(basicResult.getPageSize());
|
||||
|
||||
return ApiResponse.success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("分页查询渲染工作器列表失败", e);
|
||||
|
Reference in New Issue
Block a user