<?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.ximai.mes.md.mapper.MdClientContactMapper">

    <resultMap type="MdClientContact" id="MdClientContactResult">
        <result property="id"    column="id"    />
        <result property="clientCode"    column="client_code"    />
        <result property="brandId"    column="brand_id"    />
        <result property="brandName"    column="brand_name"    />
        <result property="department"    column="department"    />
        <result property="position"    column="position"    />
        <result property="contact"    column="contact"    />
        <result property="tel"    column="tel"    />
        <result property="email"    column="email"    />
        <result property="businessType"    column="business_type"    />
        <result property="factoryCode"    column="factory_code"    />
        <result property="merchandiser"    column="merchandiser"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMdClientContactVo">
        select id, client_code, brand_id, brand_name, department, position, contact, tel, email, business_type, factory_code, merchandiser, create_by, create_time, update_by, update_time from md_client_contact
    </sql>

    <select id="selectMdClientContactList" parameterType="MdClientContact" resultMap="MdClientContactResult">
        <include refid="selectMdClientContactVo"/>
        <where>
            <if test="clientCode != null "> and client_code = #{clientCode}</if>
            <if test="brandId != null "> and brand_id = #{brandId}</if>
            <if test="brandName != null  and brandName != '' "> and brand_name = #{brandName}</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="tel != null  and tel != ''"> and tel = #{tel}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="businessType != null  and businessType != ''"> and business_type = #{businessType}</if>
            <if test="factoryCode != null  and factoryCode != ''"> and factory_code = #{factoryCode}</if>
            <if test="merchandiser != null  and merchandiser != ''"> and merchandiser = #{merchandiser}</if>
        </where>
    </select>

    <select id="selectMdClientContactById" parameterType="String" resultMap="MdClientContactResult">
        <include refid="selectMdClientContactVo"/>
        where id = #{id}
    </select>

    <insert id="insertMdClientContact" parameterType="MdClientContact" useGeneratedKeys="true" keyProperty="id">
        insert into md_client_contact
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientCode != null">client_code,</if>
            <if test="brandId != null">brand_id,</if>
            <if test="brandName != null">brand_name,</if>
            <if test="department != null">department,</if>
            <if test="position != null">position,</if>
            <if test="contact != null">contact,</if>
            <if test="tel != null">tel,</if>
            <if test="email != null">email,</if>
            <if test="businessType != null">business_type,</if>
            <if test="factoryCode != null">factory_code,</if>
            <if test="merchandiser != null">merchandiser,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientCode != null">#{clientCode},</if>
            <if test="brandId != null">#{brandId},</if>
            <if test="brandName != null">#{brandName},</if>
            <if test="department != null">#{department},</if>
            <if test="position != null">#{position},</if>
            <if test="contact != null">#{contact},</if>
            <if test="tel != null">#{tel},</if>
            <if test="email != null">#{email},</if>
            <if test="businessType != null">#{businessType},</if>
            <if test="factoryCode != null">#{factoryCode},</if>
            <if test="merchandiser != null">#{merchandiser},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMdClientContact" parameterType="MdClientContact">
        update md_client_contact
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientCode != null">client_code = #{clientCode},</if>
            <if test="brandId != null">brand_id = #{brandId},</if>
            <if test="brandName != null">brand_name = #{brandName},</if>
            <if test="department != null">department = #{department},</if>
            <if test="position != null">position = #{position},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="tel != null">tel = #{tel},</if>
            <if test="email != null">email = #{email},</if>
            <if test="businessType != null">business_type = #{businessType},</if>
            <if test="factoryCode != null">factory_code = #{factoryCode},</if>
            <if test="merchandiser != null">merchandiser = #{merchandiser},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMdClientContactById" parameterType="String">
        delete from md_client_contact where id = #{id}
    </delete>

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