package com.fs.statis.mapper;

import com.fs.statis.domain.FsStatisEveryDayWatch;
import com.fs.statis.domain.FsStatisSalerWatch;
import com.fs.statis.dto.StatsWatchLogPageListDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

/**
 * 每日统计数据Mapper接口
 */
@Mapper
public interface FsStatisEveryDayWatchMapper {

    /**
     * 根据主键ID查询每日统计数据
     * @param id 主键ID
     * @return 每日统计数据对象，如果不存在则返回null
     */
    @Select("SELECT id, data_date AS dataDate, period_id AS periodId, period_num AS periodNum, " +
            "not_reg_num AS notRegNum, registered_num AS registeredNum, reg_rate AS regRate, " +
            "completed_rate AS completedRate, offline_total AS offlineTotal, " +
            "offline_not_reg_num AS offlineNotRegNum, offline_not_watch_num AS offlineNotWatchNum, " +
            "online_total AS onlineTotal, online_rate AS onlineRate, " +
            "online_completed_rate AS onlineCompletedRate, online_not_comp_rate_num AS onlineNotCompRateNum, " +
            "online_completed_num AS onlineCompletedNum, company_user_id AS companyUserId " +
            "FROM fs_statis_every_day_watch WHERE id = #{id}")
    FsStatisEveryDayWatch findById(@Param("id") Integer id);

    /**
     * 新增每日统计数据
     * @param fsStatisEveryDayWatch 待插入的每日统计数据对象
     * @return 影响的行数
     */
    @Insert("INSERT INTO fs_statis_every_day_watch (id, data_date, period_id, period_num, not_reg_num, " +
            "registered_num, reg_rate, completed_rate, offline_total, offline_not_reg_num, " +
            "offline_not_watch_num, online_total, online_rate, online_completed_rate, " +
            "online_not_comp_rate_num, online_completed_num, company_user_id) " +
            "VALUES (#{id}, #{dataDate}, #{periodId}, #{periodNum}, #{notRegNum}, #{registeredNum}, " +
            "#{regRate}, #{completedRate}, #{offlineTotal}, #{offlineNotRegNum}, #{offlineNotWatchNum}, " +
            "#{onlineTotal}, #{onlineRate}, #{onlineCompletedRate}, #{onlineNotCompRateNum}, " +
            "#{onlineCompletedNum}, #{companyUserId})")
    int insert(FsStatisEveryDayWatch fsStatisEveryDayWatch);

    /**
     * 更新每日统计数据
     * @param fsStatisEveryDayWatch 待更新的每日统计数据对象 (必须包含ID)
     * @return 影响的行数
     */
    @Update("UPDATE fs_statis_every_day_watch SET " +
            "data_date = #{dataDate}, " +
            "period_id = #{periodId}, " +
            "period_num = #{periodNum}, " +
            "not_reg_num = #{notRegNum}, " +
            "registered_num = #{registeredNum}, " +
            "reg_rate = #{regRate}, " +
            "completed_rate = #{completedRate}, " +
            "offline_total = #{offlineTotal}, " +
            "offline_not_reg_num = #{offlineNotRegNum}, " +
            "offline_not_watch_num = #{offlineNotWatchNum}, " +
            "online_total = #{onlineTotal}, " +
            "online_rate = #{onlineRate}, " +
            "online_completed_rate = #{onlineCompletedRate}, " +
            "online_not_comp_rate_num = #{onlineNotCompRateNum}, " +
            "online_completed_num = #{onlineCompletedNum}, " +
            "company_user_id = #{companyUserId} " +
            "WHERE id = #{id}")
    int update(FsStatisEveryDayWatch fsStatisEveryDayWatch);

    /**
     * 查询所有每日统计数据 (示例，根据需要添加更多查询方法)
     * @return 每日统计数据列表
     */
    @Select("SELECT id, data_date AS dataDate, period_id AS periodId, period_num AS periodNum, " +
            "not_reg_num AS notRegNum, registered_num AS registeredNum, reg_rate AS regRate, " +
            "completed_rate AS completedRate, offline_total AS offlineTotal, " +
            "offline_not_reg_num AS offlineNotRegNum, offline_not_watch_num AS offlineNotWatchNum, " +
            "online_total AS onlineTotal, online_rate AS onlineRate, " +
            "online_completed_rate AS onlineCompletedRate, online_not_comp_rate_num AS onlineNotCompRateNum, " +
            "online_completed_num AS onlineCompletedNum, company_user_id AS companyUserId " +
            "FROM fs_statis_every_day_watch")
    List<FsStatisEveryDayWatch> findAll();

    List<FsStatisSalerWatch> queryList(StatsWatchLogPageListDTO param);

}
