package com.ruoyi.web.modules.diagnosis.support;

import org.springframework.stereotype.Component;

/**
 * 会话级 AI 处理中锁（防止同会话并发提问）。
 */
@Component
public class ConsultSessionProcessingLock
{
    private final java.util.concurrent.ConcurrentHashMap<Long, Boolean> locks =
            new java.util.concurrent.ConcurrentHashMap<>();

    public boolean tryLock(Long sessionId)
    {
        if (sessionId == null)
        {
            return false;
        }
        return locks.putIfAbsent(sessionId, Boolean.TRUE) == null;
    }

    public void unlock(Long sessionId)
    {
        if (sessionId != null)
        {
            locks.remove(sessionId);
        }
    }
}
