<?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.yd.dal.mapper.marketing.MarketMapper">
    <resultMap id="PosterQueryResultMap" type="com.yd.dal.entity.marketing.PosterInfo">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="itemType" jdbcType="BIGINT" property="itemType"/>
        <result column="itemId" jdbcType="BIGINT" property="itemId"/>
        <result column="productCategoryId" jdbcType="BIGINT" property="productCategoryId"/>
        <result column="title" jdbcType="LONGVARCHAR" property="title"/>
        <result column="productPosterPath" jdbcType="LONGVARCHAR" property="productPosterPath"/>
        <result column="isPlan" jdbcType="LONGVARCHAR" property="isPlan"/>
    </resultMap>
    <select id="posterQuery" resultMap="PosterQueryResultMap">
        select
         t.id id,
         t.item_type itemType,
         t.item_id itemId,
         t.item_name title,
         t.file_path_oss productPosterPath,
         p.product_category_id productCategoryId,
         if(t.item_type = 2 ,0,1) isPlan
        from
         ag_product_file_upload t
         LEFT JOIN ag_product p on p.id = (if (t.item_type= 1,t.item_id,(SELECT pp.product_id from ag_product_plan pp where pp.id = t.item_id) ))
        where
         t.is_active = 1
         AND t.file_category = 22 and t.display_type in ('0','1')
         <if test="mdDropOptionId != null">
             and t.md_drop_option_id = #{mdDropOptionId,jdbcType=BIGINT}
         </if>
        ORDER BY t.seq DESC ,t.created_at DESC
    </select>
</mapper>