package com.fs.course.mapper;

import java.util.List;
import com.fs.course.domain.FsCourseTrafficLog;
import com.fs.course.param.FsCourseTrafficLogParam;
import com.fs.course.vo.FsCourseTrafficLogListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 短链课程流量记录Mapper接口
 *
 * @author fs
 * @date 2024-10-31
 */
public interface FsCourseTrafficLogMapper
{
    /**
     * 查询短链课程流量记录
     *
     * @param logId 短链课程流量记录主键
     * @return 短链课程流量记录
     */
    public FsCourseTrafficLog selectFsCourseTrafficLogByLogId(Long logId);

    /**
     * 查询短链课程流量记录列表
     *
     * @param fsCourseTrafficLog 短链课程流量记录
     * @return 短链课程流量记录集合
     */
    public List<FsCourseTrafficLog> selectFsCourseTrafficLogList(FsCourseTrafficLog fsCourseTrafficLog);

    /**
     * 新增短链课程流量记录
     *
     * @param fsCourseTrafficLog 短链课程流量记录
     * @return 结果
     */
    public int insertFsCourseTrafficLog(FsCourseTrafficLog fsCourseTrafficLog);

    /**
     * 修改短链课程流量记录
     *
     * @param fsCourseTrafficLog 短链课程流量记录
     * @return 结果
     */
    public int updateFsCourseTrafficLog(FsCourseTrafficLog fsCourseTrafficLog);

    /**
     * 删除短链课程流量记录
     *
     * @param logId 短链课程流量记录主键
     * @return 结果
     */
    public int deleteFsCourseTrafficLogByLogId(Long logId);

    /**
     * 批量删除短链课程流量记录
     *
     * @param logIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsCourseTrafficLogByLogIds(Long[] logIds);

    @Select({"<script> " +
            "select c.company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
            ",DATE_FORMAT(l.create_time, '%Y-%m') AS `month`  from fs_course_traffic_log l " +
            "left join company c on c.company_id = l.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 l.company_id = #{maps.companyId} " +
            "</if>" +
            "group by l.company_id,`month` "+
            "</script>"})
    List<FsCourseTrafficLogListVO> selectTrafficByCompany(@Param("maps") FsCourseTrafficLogParam param);

    @Select("select * from fs_course_traffic_log where uu_id = #{uuId}")
    FsCourseTrafficLog selectFsCourseTrafficLogByuuId(@Param("uuId") String uuId);

    void insertOrUpdateTrafficLog(FsCourseTrafficLog trafficLog);
}
