<?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.ics.admin.mapper.meeting.StaffCustomerMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.StaffCustomer" id="StaffCustomerResult">
        <result property="id"    column="id"    />
        <result property="icsCustomerId"    column="ics_customer_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="deleteFlag"    column="delete_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="parkId"    column="park_id"    />
    </resultMap>

    <sql id="selectStaffCustomerVo">
        SELECT id, ics_customer_id, staff_id, create_time, delete_flag, create_by, tenant_id, park_id FROM tb_staff_customer
    </sql>

    <select id="selectStaffCustomerList" parameterType="StaffCustomer" resultMap="StaffCustomerResult">
        <include refid="selectStaffCustomerVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectStaffCustomerById" parameterType="Long" resultMap="StaffCustomerResult">
        <include refid="selectStaffCustomerVo"/>
        WHERE id = #{id}
    </select>
    <select id="selectStaffCustomerByStaffId" resultType="com.ics.admin.domain.meeting.StaffCustomer">
        <include refid="selectStaffCustomerVo"/>
        WHERE staff_id = #{id}
    </select>
    <select id="selectStaffCustomerByStaffIdAndParkId" resultType="com.ics.admin.domain.meeting.StaffCustomer">
        <include refid="selectStaffCustomerVo"/>
        WHERE staff_id = #{staffId} AND park_id = #{parkId}
    </select>

    <insert id="insertStaffCustomer" parameterType="StaffCustomer">
        INSERT INTO tb_staff_customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="icsCustomerId != null ">ics_customer_id,</if>
            <if test="staffId != null ">staff_id,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="deleteFlag != null  and deleteFlag != ''">delete_flag,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="tenantId != null ">tenant_id,</if>
            <if test="parkId != null ">park_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="icsCustomerId != null ">#{icsCustomerId},</if>
            <if test="staffId != null ">#{staffId},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="deleteFlag != null  and deleteFlag != ''">#{deleteFlag},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="tenantId != null ">#{tenantId},</if>
            <if test="parkId != null ">#{parkId},</if>
         </trim>
    </insert>

    <update id="updateStaffCustomer" parameterType="StaffCustomer">
        UPDATE tb_staff_customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="icsCustomerId != null ">ics_customer_id = #{icsCustomerId},</if>
            <if test="staffId != null ">staff_id = #{staffId},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="deleteFlag != null  and deleteFlag != ''">delete_flag = #{deleteFlag},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="tenantId != null ">tenant_id = #{tenantId},</if>
            <if test="parkId != null ">park_id = #{parkId},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteStaffCustomerById" parameterType="Long">
        DELETE FROM tb_staff_customer WHERE id = #{id}
    </delete>

    <delete id="deleteStaffCustomerByIds" parameterType="String">
        DELETE FROM tb_staff_customer where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>