<?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.sqx.modules.activity.dao.ActivityPartRecordDao">

    <select id="getVoById" resultType="com.sqx.modules.activity.vo.ActivityPartRecordVO">
        select
            apr.*,
            o.is_pay orderPayStatus,
            u.avatar userImg,
            u.phone userPhone,
            a.title activityTitle,
            a.image activityImg,
            a.content activityContent,
            a.type activityType
        from
            activity_part_record apr
        left join activity a on a.id = apr.activity_id
        left join tb_order o on o.order_id = apr.order_id
        left join tb_user u on u.user_id = apr.user_id
        where
            apr.id = #{recordId}
    </select>

    <select id="pageByQuery" resultType="com.sqx.modules.activity.vo.ActivityPartRecordVO">
        select
            apr.*,
            o.is_pay orderPayStatus,
            u.avatar userImg,
            u.phone userPhone,
            a.title activityTitle,
            a.image activityImg,
            a.content activityContent,
            a.type activityType,
            gh.shop_name
        from
            activity_part_record apr
                left join activity a on a.id = apr.activity_id
                left join tb_order o on o.order_id = apr.order_id
                left join tb_user u on u.user_id = apr.user_id
                left join goods_shop gh on gh.shop_id = o.shop_id
        <where>
            <if test="queryDTO.orderId != null">
                and apr.order_id = #{queryDTO.orderId}
            </if>
            <if test="queryDTO.orderPayStatus != null and queryDTO.orderPayStatus != ''">
                and o.is_pay = #{queryDTO.orderPayStatus}
            </if>
            <if test="queryDTO.userPhone != null and queryDTO.userPhone != ''">
                and u.phone = #{queryDTO.userPhone}
            </if>
            <if test="queryDTO.activityTitle != null and queryDTO.activityTitle != ''">
                and a.title = #{queryDTO.activityTitle}
            </if>
            <if test="queryDTO.activityType != null and queryDTO.activityType != ''">
                and a.type = #{queryDTO.activityType}
            </if>
            <if test="queryDTO.shopName != null and queryDTO.shopName != ''">
                and gh.shop_name like concat('%', #{queryDTO.shopName},'%')
            </if>
        </where>
        order by apr.create_time desc
    </select>
</mapper>