<?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.master.product.mapper.ProdAttrMapper">
    <resultMap type="ProdAttr" id="ProdAttrResult">
        <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="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectProdAttr">
        select prodAttrId, prodId, attrName, attrType, delFlag, createUser, createTime, updateUser, updateTime from m_prod_attr
    </sql>

    <select id="selectProdAttrList" parameterType="ProdAttr" resultMap="ProdAttrResult">
        <include refid="selectProdAttr"/>
        <where>  
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="attrName != null  and attrName != ''"> and attrName like concat('%', #{attrName}, '%')</if>
            <if test="attrType != null  and attrType != ''"> and attrType = #{attrType}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectProdAttrByProdAttrId" parameterType="Long" resultMap="ProdAttrResult">
        <include refid="selectProdAttr"/>
        where prodAttrId = #{prodAttrId}
    </select>
        
    <insert id="insertProdAttr" parameterType="ProdAttr" useGeneratedKeys="true" keyProperty="prodAttrId">
        insert into m_prod_attr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prodId != null">prodId,</if>
            <if test="attrName != null">attrName,</if>
            <if test="attrType != null">attrType,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prodId != null">#{prodId},</if>
            <if test="attrName != null">#{attrName},</if>
            <if test="attrType != null">#{attrType},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertProdAttr">
        insert into m_prod_attr( prodId, attrName, attrType, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.prodId}, #{item.attrName}, #{item.attrType}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdAttr" parameterType="ProdAttr">
        update m_prod_attr
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="attrName != null">attrName = #{attrName},</if>
            <if test="attrType != null">attrType = #{attrType},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where prodAttrId = #{prodAttrId}
    </update>

    <delete id="deleteProdAttrByProdAttrId" parameterType="Long">
        delete from m_prod_attr where prodAttrId = #{prodAttrId}
    </delete>

    <delete id="deleteProdAttrByProdAttrIds" parameterType="String">
        delete from m_prod_attr where prodAttrId in 
        <foreach item="prodAttrId" collection="array" open="(" separator="," close=")">
            #{prodAttrId}
        </foreach>
    </delete>

    <update id="logicDeleteProdAttrByProdAttrId" parameterType="Long">
        update m_prod_attr
            set delFlag = '1'
        where prodAttrId = #{prodAttrId}
    </update>

    <update id="logicDeleteProdAttrByProdAttrIds" parameterType="String">
        update m_prod_attr
        set delFlag = '1'
        where prodAttrId in
        <foreach item="prodAttrId" collection="array" open="(" separator="," close=")">
            #{prodAttrId}
        </foreach>
    </update>

    <update id="logicDeleteProdAttrByCondition" parameterType="ProdAttr">
        update m_prod_attr
        set delFlag = '1'
        <where>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="attrName != null  and attrName != ''"> and attrName like concat('%', #{attrName}, '%')</if>
            <if test="attrType != null  and attrType != ''"> and attrType = #{attrType}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>