package com.fs.live.mapper;

import java.util.List;
import com.fs.live.domain.LiveTrafficLog;
import com.fs.live.param.LiveTrafficLogParam;
import com.fs.live.vo.LiveTrafficLogListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 直播流量记录Mapper接口
 *
 * @author fs
 * @date 2025-10-13
 */
public interface LiveTrafficLogMapper
{
    /**
     * 查询直播流量记录
     *
     * @param logId 直播流量记录ID
     * @return 直播流量记录
     */
    public LiveTrafficLog selectLiveTrafficLogById(Long logId);

    /**
     * 查询直播流量记录列表
     *
     * @param liveTrafficLog 直播流量记录
     * @return 直播流量记录集合
     */
    public List<LiveTrafficLog> selectLiveTrafficLogList(LiveTrafficLog liveTrafficLog);

    /**
     * 新增直播流量记录
     *
     * @param liveTrafficLog 直播流量记录
     * @return 结果
     */
    public int insertLiveTrafficLog(LiveTrafficLog liveTrafficLog);

    /**
     * 修改直播流量记录
     *
     * @param liveTrafficLog 直播流量记录
     * @return 结果
     */
    public int updateLiveTrafficLog(LiveTrafficLog liveTrafficLog);

    /**
     * 删除直播流量记录
     *
     * @param logId 直播流量记录ID
     * @return 结果
     */
    public int deleteLiveTrafficLogById(Long logId);

    /**
     * 批量删除直播流量记录
     *
     * @param logIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteLiveTrafficLogByIds(Long[] logIds);

    @Select({"<script> " +
            " select ifnull(c.company_name,'总台') as company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
            " ,DATE_FORMAT(l.create_time, '%Y-%m') AS `month`  from live_traffic_log l " +
            " left join live lv on lv.live_id = l.live_id " +
            " left join company c on c.company_id = lv.company_id " +
            " where 1 = 1 " +
            " <if test= 'maps.year != null '>" +
            " and YEAR(l.create_time) = #{maps.year} " +
            " </if>" +
            " <if test= 'maps.month != null '>"+
            " and MONTH(l.create_time) = #{maps.month} " +
            " </if>" +
            " <if test = ' maps.companyId !=null '> " +
            " and c.company_id = #{maps.companyId} " +
            " </if>" +
            " group by c.company_name,`month` "+
            " </script>"})
    List<LiveTrafficLogListVO> selectTrafficByCompany(@Param("maps") LiveTrafficLogParam param);

    void insertOrUpdateLiveTrafficLog(LiveTrafficLog trafficLog);

    void batchInsert(@Param("list") List<LiveTrafficLog> list);
}
