<?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.dsk.system.mapper.BusinessContactsMapper">

    <resultMap type="com.dsk.common.core.domain.entity.BusinessContacts" id="BusinessContactsResult">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="name" column="name"/>
        <result property="role" column="role"/>
        <result property="office" column="office"/>
        <result property="position" column="position"/>
        <result property="phone" column="phone"/>
        <result property="accendant" column="accendant"/>
        <result property="creatTime" column="creat_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBusinessContactsVo">
        select id,
               business_id,
               name,
               role,
               office,
               position,
               phone,
               accendant,
               creat_time,
               update_time
        from business_contacts
    </sql>

    <select id="selectBusinessContactsList" parameterType="com.dsk.common.core.domain.entity.BusinessContacts" resultMap="BusinessContactsResult">
        <include refid="selectBusinessContactsVo"/>
        <where>
            <if test="businessId != null ">and business_id = #{businessId}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="role != null  and role != ''">and role = #{role}</if>
            <if test="office != null  and office != ''">and office = #{office}</if>
            <if test="position != null  and position != ''">and position = #{position}</if>
            <if test="phone != null  and phone != ''">and phone = #{phone}</if>
            <if test="accendant != null  and accendant != ''">and accendant = #{accendant}</if>
            <if test="creatTime != null ">and creat_time = #{creatTime}</if>
        </where>
        order by creat_time desc
    </select>

    <select id="selectBusinessContactsById" parameterType="Long" resultMap="BusinessContactsResult">
        <include refid="selectBusinessContactsVo"/>
        where id = #{id}
    </select>

    <insert id="insertBusinessContacts" parameterType="com.dsk.common.core.domain.entity.BusinessContacts" useGeneratedKeys="true" keyProperty="id">
        insert into business_contacts
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="name != null">name,</if>
            <if test="role != null">role,</if>
            <if test="office != null">office,</if>
            <if test="position != null">position,</if>
            <if test="phone != null">phone,</if>
            <if test="accendant != null">accendant,</if>
            <if test="creatTime != null">creat_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="name != null">#{name},</if>
            <if test="role != null">#{role},</if>
            <if test="office != null">#{office},</if>
            <if test="position != null">#{position},</if>
            <if test="phone != null">#{phone},</if>
            <if test="accendant != null">#{accendant},</if>
            <if test="creatTime != null">#{creatTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateBusinessContacts" parameterType="com.dsk.common.core.domain.entity.BusinessContacts">
        update business_contacts
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="role != null">role = #{role},</if>
            <if test="office != null">office = #{office},</if>
            <if test="position != null">position = #{position},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="accendant != null">accendant = #{accendant},</if>
            <if test="creatTime != null">creat_time = #{creatTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusinessContactsById" parameterType="Long">
        delete
        from business_contacts
        where id = #{id}
    </delete>

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