<?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.qs.mp.user.mapper.MarketingHitPrizeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.MarketingHitPrize">
        <id column="id" property="id" />
        <result column="marketing_id" property="marketingId" />
        <result column="user_id" property="userId" />
        <result column="user_type" property="userType" />
        <result column="awards_id" property="awardsId" />
        <result column="prize_id" property="prizeId" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
        <result column="is_deleted" property="isDeleted" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, marketing_id, user_id, user_type, awards_id, prize_id, created_time, updated_time, is_deleted
    </sql>

    <select id="listHitPrizeByQueryWrapper" resultType="com.qs.mp.user.domain.vo.UserMarketingHitPrizeListVO">
        select t4.nick_name,
               t4.avatar,
               t5.code,
               t2.name awardName,
               t3.title prizeTitle,
               t3.pic_url prizePicUrl,
                t3.prize_type,
                t3.value
        from mp_marketing_hit_prize t1
             left join mp_marketing_awards t2 on t1.awards_id = t2.id
             left join mp_marketing_awards_prize t3 on t1.prize_id = t3.id
             left join sys_user t4 on t1.user_id = t4.user_id
             left join mp_marketing_user_code t5 on t1.marketing_user_code_id = t5.id
        ${ew.customSqlSegment}
    </select>

    <select id="listHitPrizeExportByQueryWrapper" resultType="com.qs.mp.admin.domain.excel.MarketingHitPrizeExcel">
        select t2.title,
               t2.id marketingId,
               t2.end_time,
               t3.name awardsName,
               t4.title prizeTitle,
               t4.ref_id,
               t5.nick_name,
               t5.phonenumber userPhone
        from mp_marketing_hit_prize t1
                 left join mp_marketing t2 on t1.marketing_id = t2.id
                 left join mp_marketing_awards t3 on t1.awards_id = t3.id
                 left join mp_marketing_awards_prize t4 on t1.prize_id = t4.id
                 left join sys_user t5 on t1.user_id = t5.user_id
        ${ew.customSqlSegment}
    </select>
</mapper>