<?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.WxaStoreMaterialMapper">

    <resultMap id="MaterialImageResult" type="MaterialImageDTO">
        <result property="materialId"    column="mateId"/>
        <result property="materialName"    column="mateName"/>
        <result property="price"    column="price"/>
        <association property="imageDTO"  javaType="ImageDTO">
            <result property="imageId"    column="fileId"/>
            <result property="imageUrl"    column="fileUrl"/>
            <result property="height"    column="thumbImgHeight"/>
            <result property="width"    column="thumbImgWidth"/>
        </association>
    </resultMap>

    <resultMap id="MaterialCategoryResult" type="CategoryDTO">
        <result property="categoryId"    column="mateKindId"/>
        <result property="categoryName"    column="mateKindName"/>
    </resultMap>

    <resultMap  id="MaterialFontDTOResult" type="MaterialFontDTO">
        <result property="fontId"    column="fontId"    />
        <result property="fontType"    column="fontType"    />
        <result property="fontName"    column="fontName"    />
        <result property="fontUrl"    column="fontUrl"    />
        <result property="fontFamily" column="fontFamily"/>
    </resultMap>

    <select id="selectMaterialImageList"  parameterType="MaterialImageDTO" resultMap="MaterialImageResult">
        SELECT m_material.*, t_attch_file.fileId,t_attch_file.fileUrl,m_mate_price.price,m_merc_mate.mercId
        FROM m_merc_mate
        LEFT JOIN m_material ON m_merc_mate.mateId = m_material.mateId
        INNER JOIN t_attch_file ON t_attch_file.fileId = m_material.thumbMateImgId
        INNER JOIN m_mate_price ON m_mate_price.mateId = m_merc_mate.mateId
        <where>
            m_merc_mate.delFlag = '0'
            AND m_merc_mate.mercId = #{mercId}
            AND m_mate_price.costItem = 'DESIGN'
            AND m_mate_price.buyerRoleKey = 'CUSTOMER'
            <if test="mateKindId != null and mateKindId != ''"> AND m_merc_mate.mateKindId = #{mateKindId}</if>
        </where>
        ORDER BY m_merc_mate.mateSort
    </select>


    <select id="selectMaterialFontList" parameterType="java.lang.String" resultMap="MaterialFontDTOResult">
        select fontId, fontType,fontFamily, fontName, fontUrl from m_font
        <where>
            delFlag = '0'
            <if test="fontType != null  and fontType != ''"> and fontType = #{lang}</if>
        </where>
    </select>

    <select id="selectMaterialCategoryList" parameterType="java.lang.String" resultMap="MaterialCategoryResult">
        SELECT m_merc_mate_kind.*, m_material_kind.mateKindName
        FROM m_merc_mate_kind
        LEFT JOIN m_material_kind ON m_merc_mate_kind.mateKindId = m_material_kind.mateKindId
        WHERE m_merc_mate_kind.delFlag = '0'
          AND m_merc_mate_kind.supplyFlag = '1'
          AND m_merc_mate_kind.mercId = #{mercId}
        ORDER BY m_merc_mate_kind.kindSort
    </select>

    <select id="selectMaterialKindByMaterialId" parameterType="Long" resultType="MaterialKind">
        SELECT m_material_kind.*
        FROM m_material
        INNER JOIN m_material_kind ON m_material.mateKindId = m_material_kind.mateKindId
        WHERE m_material.mateId = #{materialId}
    </select>


    <select id="selectMatePriceByMateId" resultType="MatePrice">
        SELECT m_mate_price.* FROM m_merc_mate
        INNER JOIN m_mate_price ON m_mate_price.mateId = m_merc_mate.mateId AND m_mate_price.salesmanId = m_merc_mate.mercId
        WHERE m_merc_mate.delFlag = '0'
          AND m_mate_price.costItem = 'DESIGN'
          AND m_mate_price.buyerRoleKey = 'CUSTOMER'
          AND m_mate_price.mateId = #{materialId}
          AND m_merc_mate.mercId = #{mercId}
    </select>
</mapper>
