<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.demo.mapper.AttentionPoolStatisticsDao">
    <resultMap type="com.ruoyi.demo.entity.AttentionPoolStatistics" id="StatisticsResult">
        <result property="statId" column="stat_id"/>
        <result property="attentionCount" column="attention_count"/>
        <result property="clueCount" column="clue_count"/>
        <result property="onlineCount" column="online_count"/>
        <result property="offlineCount" column="offline_count"/>
        <result property="userId" column="user_id"/>
        <result property="statTime" column="stat_time"/>
    </resultMap>
    <resultMap type="com.ruoyi.demo.entity.bo.AttentionPoolStatisticsBo" id="StatisticsBoResult">
        <result property="attentionCount" column="attention_count"/>
        <result property="clueCount" column="clue_count"/>
        <result property="onlineCount" column="online_count"/>
        <result property="offlineCount" column="offline_count"/>
        <result property="time" column="stat_time"/>
    </resultMap>
    <select id="searchAllByUserId" resultMap="StatisticsResult">
        select * from `bl_attention_pool_statistics`
        <where>
            <if test="userId != null">
                user_id = #{userId}
            </if>
        </where>
    </select>
    <select id="selectAllByUserIdAndDay" resultMap="StatisticsBoResult">
        SELECT
            SUM(attention_count) attention_count,
            SUM(clue_count) clue_count,
            SUM(online_count) online_count,
            SUM(offline_count) offline_count,
            DATE_FORMAT(stat_time,'%Y-%m-%d') stat_time
        FROM
            `bl_attention_pool_statistics`
        WHERE
            user_id = #{userId}
        <foreach collection="days" item="day" open="and DATE_FORMAT(stat_time,'%Y-%m-%d') in (" separator="," close=")">
            #{day,jdbcType=VARCHAR}
        </foreach>
        GROUP BY
            DATE_FORMAT(stat_time,'%Y-%m-%d');
    </select>
    <select id="selectAllByUserIdAndMonth" resultMap="StatisticsBoResult">
        SELECT
            SUM(attention_count) attention_count,
            SUM(clue_count) clue_count,
            SUM(online_count) online_count,
            SUM(offline_count) offline_count,
            DATE_FORMAT(stat_time,'%Y-%m') stat_time
        FROM
            `bl_attention_pool_statistics`
        WHERE
            user_id = #{userId}
        <foreach collection="months" item="month" open="and DATE_FORMAT(stat_time,'%Y-%m') in (" separator="," close=")">
            #{month,jdbcType=VARCHAR}
        </foreach>
        GROUP BY
            DATE_FORMAT(stat_time,'%Y-%m');
    </select>
    <select id="selectAllByUserIdAndYear" resultMap="StatisticsBoResult">
        SELECT
            SUM(attention_count) attention_count,
            SUM(clue_count) clue_count,
            SUM(online_count) online_count,
            SUM(offline_count) offline_count,
            DATE_FORMAT(stat_time,'%Y') stat_time
        FROM
            `bl_attention_pool_statistics`
        WHERE
            user_id = #{userId}
        <foreach collection="years" item="year" open="and DATE_FORMAT(stat_time,'%Y') in (" separator="," close=")">
            #{year,jdbcType=VARCHAR}
        </foreach>
        GROUP BY
            DATE_FORMAT(stat_time,'%Y');
    </select>
</mapper>
