<?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.xingxi.web.controller.master.product.mapper.ProdAttrVoMapper">
    <resultMap type="ProdAttrVo" id="ProdAttrVoResult">
        <result property="prodAttrId"           column="prodAttrId" />
        <result property="prodId"               column="prodId"     />
        <result property="attrName"             column="attrName"   />
        <result property="attrType"             column="attrType"   />
        <result property="delFlag"              column="delFlag"    />
        <result property="createTime"           column="createTime" />
        <result property="createUser"           column="createUser" />
        <result property="updateUser"           column="updateUser" />
        <result property="updateTime"           column="updateTime" />
        <result property="jointId"              column="jointId" />
        <result property="prodAttrJointId"      column="prodAttrJointId" />
        <result property="prodName"             column="prodName"   />
    </resultMap>

    <sql id="selectProdAttrVo">
        select m_prod_attr.prodAttrId
             , m_prod_attr.prodId
             , m_prod_attr.attrName
             , m_prod_attr.attrType
             , m_prod_attr.delFlag
             , m_prod_attr.createUser
             , m_prod_attr.createTime
             , m_prod_attr.updateUser
             , m_prod_attr.updateTime
             , m_prod.prodName
        from m_prod_attr
        inner join m_prod on m_prod.id = m_prod_attr.prodId
    </sql>

    <select id="selectProdAttrVoByProdAttrId" parameterType="Long" resultMap="ProdAttrVoResult">
        <include refid="selectProdAttrVo"/>
        where prodAttrId = #{prodAttrId}
    </select>

    <select id="selectProdAttrVoList" parameterType="ProdAttrVo" resultMap="ProdAttrVoResult">
        <include refid="selectProdAttrVo"/>
        <where>
            <if test="prodId != null "> and m_prod_attr.prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and m_prod_attr.prodAttrId = #{prodAttrId}</if>
            <if test="attrType != null "> and m_prod_attr.attrType = #{attrType}</if>
            <if test="attrName != null  and attrName != ''"> and m_prod_attr.attrName like concat('%', #{attrName}, '%')</if>
            <if test="delFlag != null  and delFlag != ''"> and m_prod_attr.delFlag = #{delFlag}</if>
        </where>
    </select>

    <select id="selectProdAttrJointList" parameterType="ProdAttrVo" resultMap="ProdAttrVoResult">
        select m_prod_attr.prodAttrId
        , m_prod_attr.prodId
        , m_prod_attr.attrName
        , m_prod_attr.attrType
        , m_prod_attr.delFlag
        , m_prod_attr.createUser
        , m_prod_attr.createTime
        , m_prod_attr.updateUser
        , m_prod_attr.updateTime
        , m_prod_attr_joint.prodAttrId as jointId
        , m_prod_attr_joint.prodAttrJointId
        from m_prod_attr
        left join m_prod_attr_joint on m_prod_attr.prodId = m_prod_attr_joint.jointProdId and m_prod_attr.prodAttrId = m_prod_attr_joint.jointProdAttrId
        <if test="jointId != null "> and m_prod_attr_joint.prodAttrId = #{jointId}</if>
        <if test="delFlag != null  and delFlag != ''"> and m_prod_attr_joint.delFlag = #{delFlag}</if>
        <where>
            <if test="prodId != null "> and m_prod_attr.prodId = #{prodId}</if>
            <if test="prodAttrId != null "> and m_prod_attr.prodAttrId = #{prodAttrId}</if>
            <if test="attrType != null "> and m_prod_attr.attrType = #{attrType}</if>
            <if test="attrName != null  and attrName != ''"> and m_prod_attr.attrName like concat('%', #{attrName}, '%')</if>
            <if test="delFlag != null  and delFlag != ''"> and m_prod_attr.delFlag = #{delFlag}</if>
        </where>
    </select>
</mapper>