<?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.gic.haoban.manage.service.dao.mapper.contact.TabContactConfigMapper">

    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.contact.TabContactConfig">
        <id column="config_id" property="configId" />
        <result column="contact_auto" property="contactAuto" />
        <result column="remark_flag" property="remarkFlag" />
        <result column="remark_content" property="remarkContent" />
        <result column="enterprise_id" property="enterpriseId" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <sql id="Base_Column_List">
        config_id, contact_auto, remark_flag, remark_content, enterprise_id, delete_flag, create_time, update_time
    </sql>

    <select id="queryById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM tab_contact_config
        WHERE config_id = #{configId}
    </select>

    <select id="queryByEnterpriseId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM tab_contact_config
        WHERE enterprise_id = #{enterpriseId}
        AND delete_flag = 0
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="configId">
        INSERT INTO tab_contact_config (
        config_id, contact_auto, remark_flag, remark_content, enterprise_id
        )
        VALUES (
        #{configId}, #{contactAuto}, #{remarkFlag}, #{remarkContent}, #{enterpriseId}
        )
    </insert>

    <insert id="insertBatch">
        INSERT INTO tab_contact_config (
        config_id, contact_auto, remark_flag, remark_content, enterprise_id, delete_flag, create_time, update_time
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.configId}, #{item.contactAuto}, #{item.remarkFlag}, #{item.remarkContent}, #{item.enterpriseId}, #{item.deleteFlag}, #{item.createTime}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="update">
        UPDATE tab_contact_config
        <set>
            <if test="contactAuto != null">contact_auto = #{contactAuto},</if>
            <if test="remarkFlag != null">remark_flag = #{remarkFlag},</if>
            <if test="remarkContent != null">remark_content = #{remarkContent},</if>
        </set>
        WHERE config_id = #{configId}
    </update>

    <delete id="deleteById">
        DELETE FROM tab_contact_config
        WHERE config_id = #{configId}
    </delete>

</mapper>