package com.sonic.frog.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sonic.frog.domain.entity.AiUserHeartbeatRank;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface AiUserHeartbeatRankDao extends BaseMapper<AiUserHeartbeatRank> {

    /**
     * 更新数据
     * @param id
     * @param heartbeatVal
     * @return
     */
    @Update("update ai_user_heartbeat_rank set heartbeat_val_total = if(heartbeat_val_total + #{heartbeatVal} > 0, heartbeat_val_total + #{heartbeatVal}, 0) where id = #{id}")
    Integer incrementHeartbeatVal(@Param("id") Long id, @Param("heartbeatVal") BigDecimal heartbeatVal);

    /**
     * 获取榜单数据
     * @param ps
     * @return
     */
    @Select("select user_id from ai_user_heartbeat_rank order by heartbeat_val_total desc limit #{ps}")
    List<Long> getAiUserHeartbeatRankList(@Param("ps") Integer ps);

}
