feat: 优化设备冷却管理,增加原子设备占用逻辑和过期记录处理
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.gameplatform.server;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@@ -9,8 +11,13 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@MapperScan("com.gameplatform.server.mapper")
|
||||
@EnableScheduling
|
||||
public class GamePlatformServerApplication {
|
||||
private static final Logger log = LoggerFactory.getLogger(GamePlatformServerApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
log.info("=== 游戏平台服务器启动中 ===");
|
||||
log.debug("Debug 日志级别已启用");
|
||||
SpringApplication.run(GamePlatformServerApplication.class, args);
|
||||
log.info("=== 游戏平台服务器启动完成 ===");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class AuthController {
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Mono<LoginResponse> login(@Valid @RequestBody LoginRequest req) {
|
||||
// Avoid logging raw usernames at info level
|
||||
log.debug("/api/auth/login called");
|
||||
log.info("/api/auth/login called");
|
||||
return authService.login(req);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.gameplatform.server.model.dto.link.UserLinkStatusResponse;
|
||||
import com.gameplatform.server.model.dto.link.TargetScoreResponse;
|
||||
import com.gameplatform.server.service.link.LinkGenerationService;
|
||||
import com.gameplatform.server.service.link.LinkListService;
|
||||
import com.gameplatform.server.service.link.LinkStatusService;
|
||||
import com.gameplatform.server.service.external.ScriptClient;
|
||||
import com.gameplatform.server.service.link.LinkStatusService;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
@@ -115,4 +115,14 @@ public interface LinkTaskMapper extends BaseMapper<LinkTask> {
|
||||
* 根据状态查询所有链接任务
|
||||
*/
|
||||
List<LinkTask> findByStatus(@Param("status") String status);
|
||||
|
||||
/**
|
||||
* 原子方式占用设备:仅当该设备当前未被 USING/LOGGED_IN 占用时,
|
||||
* 才将指定任务更新为 USING 并写入设备与时间字段。
|
||||
* 返回受影响行数(1=成功,0=设备已被占用)。
|
||||
*/
|
||||
int reserveDeviceIfFree(@Param("id") Long id,
|
||||
@Param("region") String region,
|
||||
@Param("deviceId") String deviceId,
|
||||
@Param("qrExpireSeconds") int qrExpireSeconds);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,12 @@ public interface MachineCooldownMapper extends BaseMapper<MachineCooldown> {
|
||||
* 清理指定时间之前的已过期冷却记录
|
||||
*/
|
||||
int cleanupExpiredCooldowns(@Param("beforeTime") LocalDateTime beforeTime);
|
||||
|
||||
/**
|
||||
* 删除将要过期(ACTIVE→EXPIRED)的设备,已存在的 EXPIRED 记录,避免唯一键 (machine_id,status) 冲突。
|
||||
* 使用当前时间参数筛选出需要过期的设备列表。
|
||||
*/
|
||||
int deleteExistingExpiredForMachinesToExpire(@Param("currentTime") LocalDateTime currentTime);
|
||||
|
||||
/**
|
||||
* 获取指定设备的冷却历史记录
|
||||
@@ -69,3 +75,4 @@ public interface MachineCooldownMapper extends BaseMapper<MachineCooldown> {
|
||||
@Param("limit") int limit,
|
||||
@Param("offset") int offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,3 +182,4 @@ public class MachineCooldown {
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,3 +197,4 @@ public class GameCompletionLog {
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.gameplatform.server.service.detection;
|
||||
import com.gameplatform.server.mapper.agent.LinkTaskMapper;
|
||||
import com.gameplatform.server.model.entity.agent.LinkTask;
|
||||
import com.gameplatform.server.model.entity.detection.GameCompletionLog;
|
||||
import com.gameplatform.server.service.cooldown.MachineCooldownService;
|
||||
import com.gameplatform.server.service.cooldown.MemoryMachineCooldownService;
|
||||
import com.gameplatform.server.mapper.detection.GameCompletionLogMapper;
|
||||
import com.gameplatform.server.mapper.history.LinkTaskStatusHistoryMapper;
|
||||
import com.gameplatform.server.model.entity.history.LinkTaskStatusHistory;
|
||||
@@ -37,7 +37,7 @@ public class GameCompletionDetectionService {
|
||||
private static final int COMPLETION_CONFIRMATION_INTERVAL_SECONDS = 10;
|
||||
|
||||
private final LinkTaskMapper linkTaskMapper;
|
||||
private final MachineCooldownService machineCooldownService;
|
||||
private final MemoryMachineCooldownService machineCooldownService;
|
||||
private final GameCompletionLogMapper gameCompletionLogMapper;
|
||||
private final LinkTaskStatusHistoryMapper statusHistoryMapper;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class GameCompletionDetectionService {
|
||||
private final ConcurrentMap<String, LocalDateTime> recentLogins = new ConcurrentHashMap<>();
|
||||
|
||||
public GameCompletionDetectionService(LinkTaskMapper linkTaskMapper,
|
||||
MachineCooldownService machineCooldownService,
|
||||
MemoryMachineCooldownService machineCooldownService,
|
||||
GameCompletionLogMapper gameCompletionLogMapper,
|
||||
LinkTaskStatusHistoryMapper statusHistoryMapper) {
|
||||
this.linkTaskMapper = linkTaskMapper;
|
||||
@@ -297,3 +297,4 @@ public class GameCompletionDetectionService {
|
||||
LOW // 低置信度:不可信的状态变化
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
package com.gameplatform.server.task;
|
||||
|
||||
import com.gameplatform.server.service.cooldown.MachineCooldownService;
|
||||
import com.gameplatform.server.service.cooldown.MemoryMachineCooldownService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@@ -14,9 +14,9 @@ import org.springframework.stereotype.Component;
|
||||
public class MachineCooldownCleanupTask {
|
||||
private static final Logger log = LoggerFactory.getLogger(MachineCooldownCleanupTask.class);
|
||||
|
||||
private final MachineCooldownService machineCooldownService;
|
||||
private final MemoryMachineCooldownService machineCooldownService;
|
||||
|
||||
public MachineCooldownCleanupTask(MachineCooldownService machineCooldownService) {
|
||||
public MachineCooldownCleanupTask(MemoryMachineCooldownService machineCooldownService) {
|
||||
this.machineCooldownService = machineCooldownService;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user