<?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="cn.com.xingxi.store.data.mapper.WxaStoreRecommendProductMapper">

    <resultMap id="ShopRecommendDTOResult" type="ShopRecommendDTO" >
        <id property="mercRecId" column="mercRecId"/>
        <id property="recTitle" column="recTitle"/>
        <result property="headImageUrl"    column="fileUrl"    />
        <collection property="productDTOS"
                    select="selectShopRecommendProductsByMercRecId"
                    column="{mercRecId=mercRecId,mercId=mercId}"/>
    </resultMap>

    <resultMap id="ProductOneResult" type="ProductDTO">
        <id property="productId"    column="prodId"/>
        <result property="prodName"    column="prodName"/>
        <result property="subTitle"    column="subTitle"/>
        <result property="prodType"    column="prodType"/>
        <result property="description"    column="prodContent"/>
<!--        <association property="productPrice" select="cn.com.wingxi.xingxi.store.data.repository.ProductRepository.selectMinProdPriceBy"-->
<!--                     column="mercId=mercId,prodId=prodId"/>-->
        <collection property="imageUrls" ofType="ImageDTO" javaType="java.util.List">
            <result property="imageId"    column="fileId"/>
            <result property="imageUrl"    column="fileUrl"/>
        </collection>
    </resultMap>

    <select id="selectShopRecommendProductsByMercRecId" resultMap="ProductOneResult">
        SELECT t_shop_recommend_prod.mercRecProdId, t_shop_recommend_prod.prodId, m_prod.prodName, m_prod.prodType, t_attch_file.fileId, t_attch_file.fileUrl
        FROM t_shop_recommend_prod
            INNER JOIN m_prod ON t_shop_recommend_prod.prodId = m_prod.prodId
            INNER JOIN m_merc_prod ON t_shop_recommend_prod.prodId = m_merc_prod.prodId
            LEFT JOIN m_prod_picture ON m_prod.prodId = m_prod_picture.prodId
            LEFT JOIN t_attch_file ON m_prod_picture.picImgId = t_attch_file.fileId
        WHERE t_shop_recommend_prod.delFlag = '0'
            AND m_prod.delFlag = '0'
            AND m_prod.appStatus = 'APPROVED'
            AND t_shop_recommend_prod.mercRecId = #{mercRecId}
            AND m_merc_prod.mercId = #{mercId}
            AND m_merc_prod.delFlag = '0'
            AND m_merc_prod.supplyFlag = '1'
            AND m_merc_prod.shelfFlag = '1'
        ORDER BY t_shop_recommend_prod.sort
    </select>

    <select id="selectShopRecommendByMercId" parameterType="String" resultMap="ShopRecommendDTOResult">
        SELECT t_shop_recommend.recTitle,t_shop_recommend.mercId, t_attch_file.fileId, t_attch_file.fileUrl,
               t_shop_recommend.recImg, t_shop_recommend.mercRecId
        FROM t_shop_recommend
        INNER JOIN t_attch_file ON t_shop_recommend.recImg = t_attch_file.fileId
        WHERE t_shop_recommend.delFlag = '0'
          AND t_shop_recommend.mercId = #{mercId}
    </select>




</mapper>
