package com.fs.live.mapper;


import com.fs.live.domain.LiveRewardRecord;
import com.fs.live.vo.LiveRewardRecordStatisticsVo;
import com.fs.live.vo.LiveRewardRecordVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * 用户直播间奖励记录Mapper接口
 *
 * @author fs
 * @date 2025-08-27
 */
public interface LiveRewardRecordMapper {
    /**
     * 查询用户直播间奖励记录
     *
     * @param id 用户直播间奖励记录主键
     * @return 用户直播间奖励记录
     */
    LiveRewardRecord selectLiveRewardRecordById(Long id);

    /**
     * 查询用户直播间奖励记录列表
     *
     * @param liveRewardRecord 用户直播间奖励记录
     * @return 用户直播间奖励记录集合
     */
    List<LiveRewardRecord> selectLiveRewardRecordList(LiveRewardRecord liveRewardRecord);

    /**
     * 新增用户直播间奖励记录
     *
     * @param liveRewardRecord 用户直播间奖励记录
     * @return 结果
     */
    int insertLiveRewardRecord(LiveRewardRecord liveRewardRecord);

    /**
     * 修改用户直播间奖励记录
     *
     * @param liveRewardRecord 用户直播间奖励记录
     * @return 结果
     */
    int updateLiveRewardRecord(LiveRewardRecord liveRewardRecord);

    /**
     * 删除用户直播间奖励记录
     *
     * @param id 用户直播间奖励记录主键
     * @return 结果
     */
    int deleteLiveRewardRecordById(Long id);

    /**
     * 批量删除用户直播间奖励记录
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteLiveRewardRecordByIds(Long[] ids);

    @Select({
            "<script> SELECT lrr.*, l.live_name,ifnull(c.company_name,'总台') as company_name ",
            "FROM live_reward_record lrr ",
            "LEFT JOIN live l ON lrr.live_id = l.live_id ",
            " left join company c on l.company_id=c.company_id ",
            "WHERE lrr.source_id = #{companyId} ",
            "AND DATE_FORMAT(lrr.create_time, '%Y-%m') IN ",
            "<foreach collection='step' item='date' open='(' separator=',' close=')'>",
            "DATE_FORMAT(#{date}, '%Y-%m')",
            "</foreach> </script> "
    })
    List<LiveRewardRecord> selectLiveRewardRecordListByCompanyId(@Param("step") List<Date> step,@Param("companyId") Long companyId);

    @Select({
            "<script> SELECT lrr.*, l.live_name,ifnull(c.company_name,'总台') as company_name",
            "FROM live_reward_record lrr ",
            "LEFT JOIN live l ON lrr.live_id = l.live_id " ,
            " left join company c on l.company_id=c.company_id " ,
            "WHERE ",
            " DATE_FORMAT(lrr.create_time, '%Y-%m') IN ",
            "<foreach collection='step' item='date' open='(' separator=',' close=')'>",
            "DATE_FORMAT(#{date}, '%Y-%m')",
            "</foreach> </script> "
    })
    List<LiveRewardRecord> selectLiveRewardRecordListByStep(@Param("step") List<Date> step);

    List<LiveRewardRecordStatisticsVo> selectRewardSummary(LiveRewardRecordVo param);
}
