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

import java.util.function.Supplier;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 在 PageHelper 分页上下文中执行「单条查询」时，避免与 XML 中 {@code limit 1} 叠加导致双 LIMIT。
 */
public final class DiagnosisPageHelperGuard
{
    private DiagnosisPageHelperGuard()
    {
    }

    public static <T> T withoutPaging(Supplier<T> action)
    {
        Page<?> saved = PageHelper.getLocalPage();
        try
        {
            PageHelper.clearPage();
            return action.get();
        }
        finally
        {
            if (saved != null)
            {
                PageHelper.startPage(saved.getPageNum(), saved.getPageSize(), saved.getOrderBy());
            }
        }
    }
}
