<?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.designer.mapper.DesignerMapper">
    <resultMap type="Designer" id="DesignerResult">
        <result property="id"               column="id"    />
        <result property="designerName"     column="designerName"    />
        <result property="designerAvatar"   column="designerAvatar"    />
        <result property="description"      column="description"    />
        <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="selectDesigner">
        select id, designerName, designerAvatar, description, delFlag, createUser, createTime, updateUser, updateTime from m_designer
    </sql>

    <select id="selectDesignerList" parameterType="Designer" resultMap="DesignerResult">
        <include refid="selectDesigner"/>
        <where>  
            <if test="designerName != null  and designerName != ''"> and designerName like concat('%', #{designerName}, '%')</if>
            <if test="designerAvatar != null  and designerAvatar != ''"> and designerAvatar = #{designerAvatar}</if>
            <if test="description != null  and description != ''"> and description = #{description}</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="selectDesignerById" parameterType="Long" resultMap="DesignerResult">
        <include refid="selectDesigner"/>
        where id = #{id}
    </select>
        
    <insert id="insertDesigner" parameterType="Designer" useGeneratedKeys="true" keyProperty="id">
        insert into m_designer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="designerName != null">designerName,</if>
            <if test="designerAvatar != null">designerAvatar,</if>
            <if test="description != null">description,</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="designerName != null">#{designerName},</if>
            <if test="designerAvatar != null">#{designerAvatar},</if>
            <if test="description != null">#{description},</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="batchInsertDesigner">
        insert into m_designer( designerName, designerAvatar, description, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.designerName}, #{item.designerAvatar}, #{item.description}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateDesigner" parameterType="Designer">
        update m_designer
        <trim prefix="SET" suffixOverrides=",">
            <if test="designerName != null">designerName = #{designerName},</if>
            <if test="designerAvatar != null">designerAvatar = #{designerAvatar},</if>
            <if test="description != null">description = #{description},</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 id = #{id}
    </update>

    <delete id="deleteDesignerById" parameterType="Long">
        delete from m_designer where id = #{id}
    </delete>

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

    <update id="logicDeleteDesignerById" parameterType="Long">
        update m_designer
            set delFlag = '1'
        where id = #{id}
    </update>

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

    <update id="logicDeleteDesignerByCondition" parameterType="Designer">
        update m_designer
        set delFlag = '1'
        <where>
            <if test="designerName != null  and designerName != ''"> and designerName like concat('%', #{designerName}, '%')</if>
            <if test="designerAvatar != null  and designerAvatar != ''"> and designerAvatar = #{designerAvatar}</if>
            <if test="description != null  and description != ''"> and description = #{description}</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>