<?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.ProdClassMapper">
    <resultMap type="ProdClass" id="ProdClassResult">
        <result property="prodClassId"    column="prodClassId"    />
        <result property="className"    column="className"    />
        <result property="classUrl"    column="classUrl"    />
        <result property="sort"    column="sort"    />
        <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="selectProdClass">
        select prodClassId, className, classUrl, sort, delFlag, createUser, createTime, updateUser, updateTime from m_prod_class
    </sql>

    <select id="selectProdClassList" parameterType="ProdClass" resultMap="ProdClassResult">
        <include refid="selectProdClass"/>
        <where>  
            <if test="className != null  and className != ''"> and className like concat('%', #{className}, '%')</if>
            <if test="classUrl != null  and classUrl != ''"> and classUrl = #{classUrl}</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>
        order by sort
    </select>
    
    <select id="selectProdClassByProdClassId" parameterType="Long" resultMap="ProdClassResult">
        <include refid="selectProdClass"/>
        where prodClassId = #{prodClassId}
        order by sort
    </select>
        
    <insert id="insertProdClass" parameterType="ProdClass" useGeneratedKeys="true" keyProperty="prodClassId">
        insert into m_prod_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="className != null">className,</if>
            <if test="classUrl != null">classUrl,</if>
            <if test="sort != null">sort,</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="className != null">#{className},</if>
            <if test="classUrl != null">#{classUrl},</if>
            <if test="sort != null">#{sort},</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="batchInsertProdClass">
        insert into m_prod_class( className, classUrl, sort, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.className}, #{item.classUrl}, #{item.sort}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateProdClass" parameterType="ProdClass">
        update m_prod_class
        <trim prefix="SET" suffixOverrides=",">
            <if test="className != null">className = #{className},</if>
            <if test="classUrl != null">classUrl = #{classUrl},</if>
            <if test="sort != null">sort = #{sort},</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 prodClassId = #{prodClassId}
    </update>

    <delete id="deleteProdClassByProdClassId" parameterType="Long">
        delete from m_prod_class where prodClassId = #{prodClassId}
    </delete>

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

    <update id="logicDeleteProdClassByProdClassId" parameterType="Long">
        update m_prod_class
            set delFlag = '1'
        where prodClassId = #{prodClassId}
    </update>

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

    <update id="logicDeleteProdClassByCondition" parameterType="ProdClass">
        update m_prod_class
        set delFlag = '1'
        <where>
            <if test="className != null  and className != ''"> and className like concat('%', #{className}, '%')</if>
            <if test="classUrl != null  and classUrl != ''"> and classUrl = #{classUrl}</if>
            <if test="sort != null "> and sort = #{sort}</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>