Compare commits

...

2 Commits

2 changed files with 105 additions and 12 deletions

View File

@@ -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;
}

View File

@@ -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,24 +32,25 @@ 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,
@RequestParam(required = false) String name) {
log.info("分页查询渲染工作器列表, page: {}, pageSize: {}, isEnabled: {}, name: {}",
log.debug("分页查询渲染工作器列表, page: {}, pageSize: {}, isEnabled: {}, name: {}",
page, pageSize, isEnabled, name);
// 参数验证:限制pageSize最大值为100
@@ -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);
@@ -68,7 +101,7 @@ public class RenderWorkerV2Controller {
*/
@GetMapping("/{id}")
public ApiResponse<RenderWorkerV2DTO> getWorker(@PathVariable Long id) {
log.info("获取渲染工作器详情, id: {}", id);
log.debug("获取渲染工作器详情, id: {}", id);
try {
RenderWorkerV2DTO worker = renderWorkerIntegrationService.getWorker(id);
@@ -87,7 +120,7 @@ public class RenderWorkerV2Controller {
*/
@PostMapping
public ApiResponse<RenderWorkerV2DTO> createWorker(@Valid @RequestBody CreateRenderWorkerRequest request) {
log.info("创建渲染工作器, name: {}, key: {}, isActive: {}",
log.debug("创建渲染工作器, name: {}, key: {}, isActive: {}",
request.getName(), request.getKey(), request.getIsActive());
try {
@@ -109,7 +142,7 @@ public class RenderWorkerV2Controller {
@PutMapping("/{id}")
public ApiResponse<Void> updateWorker(@PathVariable Long id,
@Valid @RequestBody UpdateRenderWorkerRequest request) {
log.info("更新渲染工作器, id: {}, name: {}, isActive: {}",
log.debug("更新渲染工作器, id: {}, name: {}, isActive: {}",
id, request.getName(), request.getIsActive());
try {
@@ -129,7 +162,7 @@ public class RenderWorkerV2Controller {
*/
@DeleteMapping("/{id}")
public ApiResponse<Void> deleteWorker(@PathVariable Long id) {
log.info("删除渲染工作器, id: {}", id);
log.debug("删除渲染工作器, id: {}", id);
try {
renderWorkerIntegrationService.deleteWorker(id);