You've already forked FrameTour-BE
Compare commits
2 Commits
079c5dc540
...
864fc2c127
Author | SHA1 | Date | |
---|---|---|---|
864fc2c127 | |||
ab7deb5c8f |
@@ -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;
|
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.common.response.PageResponse;
|
||||||
import com.ycwl.basic.integration.render.dto.worker.CreateRenderWorkerRequest;
|
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.RenderWorkerV2DTO;
|
||||||
import com.ycwl.basic.integration.render.dto.worker.UpdateRenderWorkerRequest;
|
import com.ycwl.basic.integration.render.dto.worker.UpdateRenderWorkerRequest;
|
||||||
import com.ycwl.basic.integration.render.service.RenderWorkerIntegrationService;
|
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 com.ycwl.basic.utils.ApiResponse;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染工作器管理 V2 版本控制器
|
* 渲染工作器管理 V2 版本控制器
|
||||||
* 基于 zt-render-worker 微服务标准接口实现
|
* 基于 zt-render-worker 微服务标准接口实现
|
||||||
@@ -25,24 +32,25 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
public class RenderWorkerV2Controller {
|
public class RenderWorkerV2Controller {
|
||||||
|
|
||||||
private final RenderWorkerIntegrationService renderWorkerIntegrationService;
|
private final RenderWorkerIntegrationService renderWorkerIntegrationService;
|
||||||
|
private final RenderWorkerRepository renderWorkerRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询渲染工作器列表
|
* 分页查询渲染工作器列表(带保活信息)
|
||||||
*
|
*
|
||||||
* @param page 页码,从1开始
|
* @param page 页码,从1开始
|
||||||
* @param pageSize 每页大小,默认10,最大100
|
* @param pageSize 每页大小,默认10,最大100
|
||||||
* @param isEnabled 是否启用(0-禁用,1-启用)
|
* @param isEnabled 是否启用(0-禁用,1-启用)
|
||||||
* @param name 工作器名称(模糊搜索)
|
* @param name 工作器名称(模糊搜索)
|
||||||
* @return 分页查询结果
|
* @return 分页查询结果(包含保活信息)
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ApiResponse<PageResponse<RenderWorkerV2DTO>> listWorkers(
|
public ApiResponse<PageResponse<RenderWorkerWithStatusDTO>> listWorkers(
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
@RequestParam(required = false) Integer isEnabled,
|
@RequestParam(required = false) Integer isEnabled,
|
||||||
@RequestParam(required = false) String name) {
|
@RequestParam(required = false) String name) {
|
||||||
|
|
||||||
log.info("分页查询渲染工作器列表, page: {}, pageSize: {}, isEnabled: {}, name: {}",
|
log.debug("分页查询渲染工作器列表, page: {}, pageSize: {}, isEnabled: {}, name: {}",
|
||||||
page, pageSize, isEnabled, name);
|
page, pageSize, isEnabled, name);
|
||||||
|
|
||||||
// 参数验证:限制pageSize最大值为100
|
// 参数验证:限制pageSize最大值为100
|
||||||
@@ -51,8 +59,33 @@ public class RenderWorkerV2Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PageResponse<RenderWorkerV2DTO> result = renderWorkerIntegrationService.listWorkers(
|
// 获取基础工作器列表
|
||||||
|
PageResponse<RenderWorkerV2DTO> basicResult = renderWorkerIntegrationService.listWorkers(
|
||||||
page, pageSize, isEnabled, name);
|
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);
|
return ApiResponse.success(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("分页查询渲染工作器列表失败", e);
|
log.error("分页查询渲染工作器列表失败", e);
|
||||||
@@ -68,7 +101,7 @@ public class RenderWorkerV2Controller {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ApiResponse<RenderWorkerV2DTO> getWorker(@PathVariable Long id) {
|
public ApiResponse<RenderWorkerV2DTO> getWorker(@PathVariable Long id) {
|
||||||
log.info("获取渲染工作器详情, id: {}", id);
|
log.debug("获取渲染工作器详情, id: {}", id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RenderWorkerV2DTO worker = renderWorkerIntegrationService.getWorker(id);
|
RenderWorkerV2DTO worker = renderWorkerIntegrationService.getWorker(id);
|
||||||
@@ -87,7 +120,7 @@ public class RenderWorkerV2Controller {
|
|||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ApiResponse<RenderWorkerV2DTO> createWorker(@Valid @RequestBody CreateRenderWorkerRequest request) {
|
public ApiResponse<RenderWorkerV2DTO> createWorker(@Valid @RequestBody CreateRenderWorkerRequest request) {
|
||||||
log.info("创建渲染工作器, name: {}, key: {}, isActive: {}",
|
log.debug("创建渲染工作器, name: {}, key: {}, isActive: {}",
|
||||||
request.getName(), request.getKey(), request.getIsActive());
|
request.getName(), request.getKey(), request.getIsActive());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -109,7 +142,7 @@ public class RenderWorkerV2Controller {
|
|||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public ApiResponse<Void> updateWorker(@PathVariable Long id,
|
public ApiResponse<Void> updateWorker(@PathVariable Long id,
|
||||||
@Valid @RequestBody UpdateRenderWorkerRequest request) {
|
@Valid @RequestBody UpdateRenderWorkerRequest request) {
|
||||||
log.info("更新渲染工作器, id: {}, name: {}, isActive: {}",
|
log.debug("更新渲染工作器, id: {}, name: {}, isActive: {}",
|
||||||
id, request.getName(), request.getIsActive());
|
id, request.getName(), request.getIsActive());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -129,7 +162,7 @@ public class RenderWorkerV2Controller {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ApiResponse<Void> deleteWorker(@PathVariable Long id) {
|
public ApiResponse<Void> deleteWorker(@PathVariable Long id) {
|
||||||
log.info("删除渲染工作器, id: {}", id);
|
log.debug("删除渲染工作器, id: {}", id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
renderWorkerIntegrationService.deleteWorker(id);
|
renderWorkerIntegrationService.deleteWorker(id);
|
||||||
|
Reference in New Issue
Block a user