feat: 增加设备空闲状态检测配置
主要修改: 1. 在SystemConfigService中新增获取设备空闲状态的方法。 2. 更新DeviceStatusService和DeviceStatusCheckService,使用可配置的空闲状态字符串替代硬编码。 3. 在文档中添加设备检测相关配置的说明,提升系统灵活性和可维护性。 技术细节: - 通过引入设备空闲状态的配置,支持多语言环境下的设备状态标识,便于系统维护和扩展。
This commit is contained in:
26
docs/database_migration_add_device_idle_status.sql
Normal file
26
docs/database_migration_add_device_idle_status.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- =====================================================
|
||||||
|
-- 添加设备空闲状态检测系统配置项
|
||||||
|
-- 创建日期: 2024-01-15
|
||||||
|
-- 描述: 添加可配置的设备空闲状态字符串,用于检测设备是否空闲
|
||||||
|
-- =====================================================
|
||||||
|
|
||||||
|
-- 插入设备空闲状态配置项
|
||||||
|
INSERT INTO `system_config` (`config_key`, `config_value`, `config_type`, `description`, `is_system`, `created_at`, `updated_at`)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
'device.idle_status',
|
||||||
|
'空闲',
|
||||||
|
'STRING',
|
||||||
|
'设备空闲状态的字符串标识,用于判断设备是否处于空闲状态',
|
||||||
|
1,
|
||||||
|
CURRENT_TIMESTAMP(3),
|
||||||
|
CURRENT_TIMESTAMP(3)
|
||||||
|
)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`config_value` = VALUES(`config_value`),
|
||||||
|
`description` = VALUES(`description`),
|
||||||
|
`is_system` = VALUES(`is_system`),
|
||||||
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
||||||
|
|
||||||
|
-- 验证插入结果
|
||||||
|
SELECT * FROM `system_config` WHERE `config_key` = 'device.idle_status';
|
||||||
@@ -31,6 +31,9 @@
|
|||||||
- `script.server_url`: 脚本服务器地址(默认值:http://36.138.184.60:12345)
|
- `script.server_url`: 脚本服务器地址(默认值:http://36.138.184.60:12345)
|
||||||
- `script.qr_path_template`: 二维码图片路径模板(默认值:/{machineId}/二维码.png)
|
- `script.qr_path_template`: 二维码图片路径模板(默认值:/{machineId}/二维码.png)
|
||||||
|
|
||||||
|
### 设备检测相关配置
|
||||||
|
- `device.idle_status`: 设备空闲状态的字符串标识(默认值:空闲)
|
||||||
|
|
||||||
## 参数说明
|
## 参数说明
|
||||||
|
|
||||||
### 链接生成接口参数
|
### 链接生成接口参数
|
||||||
@@ -119,6 +122,9 @@ Integer refreshInterval = systemConfigService.getRefreshInterval();
|
|||||||
|
|
||||||
// 获取脚本服务器地址
|
// 获取脚本服务器地址
|
||||||
String serverUrl = systemConfigService.getScriptServerUrl();
|
String serverUrl = systemConfigService.getScriptServerUrl();
|
||||||
|
|
||||||
|
// 获取设备空闲状态字符串
|
||||||
|
String idleStatus = systemConfigService.getDeviceIdleStatus();
|
||||||
```
|
```
|
||||||
|
|
||||||
### 动态修改配置
|
### 动态修改配置
|
||||||
@@ -148,4 +154,23 @@ systemConfigService.updateConfig(config);
|
|||||||
- 游戏规则配置
|
- 游戏规则配置
|
||||||
- 第三方服务配置
|
- 第三方服务配置
|
||||||
- 日志级别配置
|
- 日志级别配置
|
||||||
- 性能调优参数
|
- 性能调优参数
|
||||||
|
- 设备状态检测相关配置
|
||||||
|
|
||||||
|
## 配置变更说明
|
||||||
|
|
||||||
|
### 设备空闲状态检测优化
|
||||||
|
|
||||||
|
为了提高系统的灵活性,将设备空闲状态的判断字符串从硬编码改为可配置:
|
||||||
|
|
||||||
|
**影响的服务:**
|
||||||
|
- `DeviceStatusService`: 设备状态解析服务
|
||||||
|
- `DeviceStatusCheckService`: 设备状态检查服务
|
||||||
|
|
||||||
|
**配置项:**
|
||||||
|
- `device.idle_status`: 用于判断设备是否空闲的字符串(默认:空闲)
|
||||||
|
|
||||||
|
**使用场景:**
|
||||||
|
- 当设备管理系统返回的空闲状态字符串发生变化时,只需修改配置即可
|
||||||
|
- 支持多语言环境下的设备状态标识
|
||||||
|
- 便于系统维护和扩展
|
||||||
@@ -116,6 +116,11 @@ public class SystemConfigService {
|
|||||||
return getConfigValue("user.assets_base_url", "http://36.138.184.60:12345");
|
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) {
|
public boolean updateConfigs(List<SystemConfig> configs) {
|
||||||
if (configs == null || configs.isEmpty()) {
|
if (configs == null || configs.isEmpty()) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.gameplatform.server.service.device;
|
|||||||
|
|
||||||
import com.gameplatform.server.mapper.agent.LinkTaskMapper;
|
import com.gameplatform.server.mapper.agent.LinkTaskMapper;
|
||||||
import com.gameplatform.server.model.entity.agent.LinkTask;
|
import com.gameplatform.server.model.entity.agent.LinkTask;
|
||||||
|
import com.gameplatform.server.service.admin.SystemConfigService;
|
||||||
import com.gameplatform.server.service.external.ScriptClient;
|
import com.gameplatform.server.service.external.ScriptClient;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -17,10 +18,12 @@ public class DeviceStatusCheckService {
|
|||||||
|
|
||||||
private final ScriptClient scriptClient;
|
private final ScriptClient scriptClient;
|
||||||
private final LinkTaskMapper linkTaskMapper;
|
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.scriptClient = scriptClient;
|
||||||
this.linkTaskMapper = linkTaskMapper;
|
this.linkTaskMapper = linkTaskMapper;
|
||||||
|
this.systemConfigService = systemConfigService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +85,8 @@ public class DeviceStatusCheckService {
|
|||||||
if (f1.get("val") != null) {
|
if (f1.get("val") != null) {
|
||||||
String status = f1.get("val").toString();
|
String status = f1.get("val").toString();
|
||||||
info.setStatus(status);
|
info.setStatus(status);
|
||||||
info.setIdle("空闲".equals(status));
|
String idleStatus = systemConfigService.getDeviceIdleStatus();
|
||||||
|
info.setIdle(idleStatus.equals(status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.gameplatform.server.model.dto.device.DeviceStatusResponse;
|
import com.gameplatform.server.model.dto.device.DeviceStatusResponse;
|
||||||
|
import com.gameplatform.server.service.admin.SystemConfigService;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -21,12 +22,14 @@ public class DeviceStatusService {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(DeviceStatusService.class);
|
private static final Logger log = LoggerFactory.getLogger(DeviceStatusService.class);
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
private final SystemConfigService systemConfigService;
|
||||||
|
|
||||||
// 设备编号解析正则
|
// 设备编号解析正则
|
||||||
private static final Pattern DEVICE_PATTERN = Pattern.compile("^(f|s|g|d|ss|gg)(\\d+)$");
|
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.objectMapper = objectMapper;
|
||||||
|
this.systemConfigService = systemConfigService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +131,8 @@ public class DeviceStatusService {
|
|||||||
* 判断设备是否空闲
|
* 判断设备是否空闲
|
||||||
*/
|
*/
|
||||||
private boolean isDeviceAvailable(String val) {
|
private boolean isDeviceAvailable(String val) {
|
||||||
return "空闲".equals(val);
|
String idleStatus = systemConfigService.getDeviceIdleStatus();
|
||||||
|
return idleStatus.equals(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
53
test_device_idle_config.http
Normal file
53
test_device_idle_config.http
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
### 测试设备空闲状态配置项
|
||||||
|
### 测试前请确保已执行数据库迁移脚本: docs/database_migration_add_device_idle_status.sql
|
||||||
|
|
||||||
|
### 1. 获取设备空闲状态配置
|
||||||
|
GET http://localhost:8080/api/admin/config/key/device.idle_status
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
### 2. 创建设备空闲状态配置(如果不存在)
|
||||||
|
POST http://localhost:8080/api/admin/config
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"configKey": "device.idle_status",
|
||||||
|
"configValue": "空闲",
|
||||||
|
"configType": "STRING",
|
||||||
|
"description": "设备空闲状态的字符串标识,用于判断设备是否处于空闲状态",
|
||||||
|
"isSystem": true
|
||||||
|
}
|
||||||
|
|
||||||
|
### 3. 更新设备空闲状态配置为其他值(测试灵活性)
|
||||||
|
PUT http://localhost:8080/api/admin/config/{{configId}}
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"configKey": "device.idle_status",
|
||||||
|
"configValue": "idle",
|
||||||
|
"configType": "STRING",
|
||||||
|
"description": "设备空闲状态的字符串标识,用于判断设备是否处于空闲状态",
|
||||||
|
"isSystem": true
|
||||||
|
}
|
||||||
|
|
||||||
|
### 4. 恢复默认值
|
||||||
|
PUT http://localhost:8080/api/admin/config/{{configId}}
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"configKey": "device.idle_status",
|
||||||
|
"configValue": "空闲",
|
||||||
|
"configType": "STRING",
|
||||||
|
"description": "设备空闲状态的字符串标识,用于判断设备是否处于空闲状态",
|
||||||
|
"isSystem": true
|
||||||
|
}
|
||||||
|
|
||||||
|
### 5. 获取所有系统配置查看是否包含新配置项
|
||||||
|
GET http://localhost:8080/api/admin/config/list?page=1&size=50
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
### 6. 根据类型获取STRING类型配置
|
||||||
|
GET http://localhost:8080/api/admin/config/type/STRING
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
Reference in New Issue
Block a user