feat: 增加设备空闲状态检测配置

主要修改:
1. 在SystemConfigService中新增获取设备空闲状态的方法。
2. 更新DeviceStatusService和DeviceStatusCheckService,使用可配置的空闲状态字符串替代硬编码。
3. 在文档中添加设备检测相关配置的说明,提升系统灵活性和可维护性。

技术细节:
- 通过引入设备空闲状态的配置,支持多语言环境下的设备状态标识,便于系统维护和扩展。
This commit is contained in:
zyh
2025-08-27 21:39:07 +08:00
parent 9277f0dcb9
commit 87741fd8c2
6 changed files with 122 additions and 5 deletions

View File

@@ -116,6 +116,11 @@ public class SystemConfigService {
return getConfigValue("user.assets_base_url", "http://36.138.184.60:12345");
}
// 获取设备检测相关配置
public String getDeviceIdleStatus() {
return getConfigValue("device.idle_status", "空闲");
}
// 批量更新配置
public boolean updateConfigs(List<SystemConfig> configs) {
if (configs == null || configs.isEmpty()) {

View File

@@ -2,6 +2,7 @@ package com.gameplatform.server.service.device;
import com.gameplatform.server.mapper.agent.LinkTaskMapper;
import com.gameplatform.server.model.entity.agent.LinkTask;
import com.gameplatform.server.service.admin.SystemConfigService;
import com.gameplatform.server.service.external.ScriptClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -17,10 +18,12 @@ public class DeviceStatusCheckService {
private final ScriptClient scriptClient;
private final LinkTaskMapper linkTaskMapper;
private final SystemConfigService systemConfigService;
public DeviceStatusCheckService(ScriptClient scriptClient, LinkTaskMapper linkTaskMapper) {
public DeviceStatusCheckService(ScriptClient scriptClient, LinkTaskMapper linkTaskMapper, SystemConfigService systemConfigService) {
this.scriptClient = scriptClient;
this.linkTaskMapper = linkTaskMapper;
this.systemConfigService = systemConfigService;
}
/**
@@ -82,7 +85,8 @@ public class DeviceStatusCheckService {
if (f1.get("val") != null) {
String status = f1.get("val").toString();
info.setStatus(status);
info.setIdle("空闲".equals(status));
String idleStatus = systemConfigService.getDeviceIdleStatus();
info.setIdle(idleStatus.equals(status));
}
}

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gameplatform.server.model.dto.device.DeviceStatusResponse;
import com.gameplatform.server.service.admin.SystemConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,12 +22,14 @@ public class DeviceStatusService {
private static final Logger log = LoggerFactory.getLogger(DeviceStatusService.class);
private final ObjectMapper objectMapper;
private final SystemConfigService systemConfigService;
// 设备编号解析正则
private static final Pattern DEVICE_PATTERN = Pattern.compile("^(f|s|g|d|ss|gg)(\\d+)$");
public DeviceStatusService(ObjectMapper objectMapper) {
public DeviceStatusService(ObjectMapper objectMapper, SystemConfigService systemConfigService) {
this.objectMapper = objectMapper;
this.systemConfigService = systemConfigService;
}
/**
@@ -128,7 +131,8 @@ public class DeviceStatusService {
* 判断设备是否空闲
*/
private boolean isDeviceAvailable(String val) {
return "空闲".equals(val);
String idleStatus = systemConfigService.getDeviceIdleStatus();
return idleStatus.equals(val);
}
/**