package org.jk.rag.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Select;
import org.jk.common.mybatis.core.mapper.BaseMapperPlus;
import org.jk.rag.domain.SysTokenLog;
import org.jk.rag.domain.vo.SysTokenLogVo;
import org.jk.rag.domain.vo.SysUserOnlineLogVo;

import java.util.List;

/**
 * token记录Mapper接口
 *
 * @author Lion Li
 * @date 2026-01-27
 */
public interface SysTokenLogMapper extends BaseMapperPlus<SysTokenLog, SysTokenLogVo> {

    @InterceptorIgnore(dataPermission = "true", tenantLine = "true")
    @Select("<script>" +
        " SELECT " +
        "        t.id," +
        "        t.token_speed," +
        "        t.create_time" +
        "    FROM (" +
        "        SELECT " +
        "            id," +
        "            token_speed," +
        "            create_time," +
        "            ROW_NUMBER() OVER (" +
        "                PARTITION BY DATE(create_time) " +
        "                ORDER BY CAST(token_speed AS UNSIGNED) DESC" +
        "            ) AS rn" +
        "        FROM sys_token_log" +
        "        WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)" +
        "    ) t" +
        "    WHERE t.rn = 1" +
        "    ORDER BY t.create_time;" +
        "</script>")
    List<SysTokenLogVo> queryThirtyDayData();
    @InterceptorIgnore(dataPermission = "true", tenantLine = "true")
    @Select("<script>" +
        " SELECT " +
        "    t.id," +
        "    t.token_speed," +
        "    t.create_time" +
        " FROM (" +
        "    SELECT " +
        "        id," +
        "        token_speed," +
        "        create_time," +
        "        ROW_NUMBER() OVER (" +
        "            PARTITION BY DATE_FORMAT(create_time, '%Y-%m') " +
        "            ORDER BY CAST(token_speed AS UNSIGNED) DESC" +
        "        ) AS rn" +
        "    FROM sys_token_log" +
        "    WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)" +
        ") t " +
        "WHERE t.rn = 1  " +
        "ORDER BY t.create_time; " +
        "</script>")
    List<SysTokenLogVo> queryTwelveMonthData();

}
