<?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.liquidnet.service.sweet.mapper.SweetIntegralActivityDrawMapper">

    <select id="selectExcelList" resultType="com.liquidnet.service.sweet.dto.SweetActivityDrawListDao">
        select a.prize_title,a.prize_type,a.prize_type_num,a.nickname,a.receiving_status,a.created_at,
               CONCAT(a.receiving_province,a.receiving_city,a.receiving_county,a.receiving_address) as receiving_address_all,
        u.mobile
        from sweet_integral_activity_draw as a
        left join sweet_integral_activity_prize as b on b.prize_id = a.prize_id
        left join sweet_integral_activity as c on a.integral_activity_id = c.integral_activity_id
        left join adam_user as u on u.uid = a.user_id
        <where>
            <if test="integralActivityId != null  and integralActivityId != ''">
                and a.integral_activity_id = #{integralActivityId}
            </if>
        </where>
        ORDER BY a.mid DESC
    </select>
    <select id="searchLists"
            parameterType="com.liquidnet.service.sweet.dto.admin.SweetIntegralActivityDrawListSearchParam"
            resultType="com.liquidnet.service.sweet.dto.SweetActivityDrawListDao">
        select a.*,
        u.mobile
        from sweet_integral_activity_draw as a
        left join adam_user as u on u.uid = a.user_id
        <where>
            <if test="mobile != null  and mobile != ''">
                and u.mobile = #{mobile}
            </if>
            <if test="integralActivityId != null  and integralActivityId != ''">
                and a.integral_activity_id = #{integralActivityId}
            </if>
            <if test="prizeTitle != null  and prizeTitle != ''">
                and a.prize_title like concat('%', #{prizeTitle}, '%')
            </if>
            <if test="nickname != null  and nickname != ''">
                and a.nickname like concat('%', #{nickname}, '%')
            </if>
            <if test="prizeType != null  and prizeType != ''">
                and a.prize_type = #{prizeType}
            </if>
            <if test="receivingStatus != null  and receivingStatus != ''">
                and a.receiving_status = #{receivingStatus}
            </if>
        </where>
        ORDER BY a.mid DESC
    </select>
    <select id="sureOutPrizeNum" resultType="java.lang.Integer">
        select COUNT(*)
        from sweet_integral_activity_draw
        <where>
            <if test="integralActivityId != null  and integralActivityId != ''">
                and integral_activity_id = #{integralActivityId}
            </if>
            and prize_type in (3, 4, 5)
        </where>
    </select>
    <select id="totalDrawNum" resultType="java.lang.Integer">
        select COUNT(*)
        from sweet_integral_activity_draw
        <where>
            <if test="integralActivityId != null  and integralActivityId != ''">
                and integral_activity_id = #{integralActivityId}
            </if>
        </where>
    </select>
    <select id="otherOutPrizeNum" resultType="java.lang.Integer">
        select COUNT(*)
        from sweet_integral_activity_draw
        <where>
            <if test="integralActivityId != null  and integralActivityId != ''">
                and integral_activity_id = #{integralActivityId}
            </if>
            and prize_type in (1, 2)
        </where>
    </select>
</mapper>
