package com.haha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haha.entity.MarketingStatistics;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface MarketingStatisticsMapper extends BaseMapper<MarketingStatistics> {

    @Select("SELECT * FROM t_marketing_statistics WHERE activity_id = #{activityId} ORDER BY stat_date DESC")
    List<MarketingStatistics> selectByActivityId(@Param("activityId") Long activityId);

    @Select("SELECT * FROM t_marketing_statistics WHERE activity_id = #{activityId} AND stat_date BETWEEN #{startDate} AND #{endDate} ORDER BY stat_date")
    List<MarketingStatistics> selectByActivityIdAndDateRange(@Param("activityId") Long activityId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    @Select("SELECT SUM(participant_count), SUM(new_user_count), SUM(order_count), SUM(order_amount), SUM(discount_amount), SUM(actual_amount), SUM(coupon_receive_count), SUM(coupon_use_count) " +
            "FROM t_marketing_statistics WHERE activity_id = #{activityId}")
    Object[] sumByActivityId(@Param("activityId") Long activityId);
}
