<?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.fs.qw.mapper.QwAppContactWayLogsMapper">

    <resultMap type="QwAppContactWayLogs" id="QwAppContactWayLogsResult">
        <result property="id"    column="id"    />
        <result property="appWayId"    column="app_way_id"    />
        <result property="source"    column="source"    />
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="externalUserId"    column="external_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="qwUserId"    column="qw_user_id"    />
    </resultMap>

    <sql id="selectQwAppContactWayLogsVo">
        select id, app_way_id,qw_user_id, source, user_id, company_id, company_user_id, corp_id, external_user_id, create_time from qw_app_contact_way_logs
    </sql>

    <select id="selectQwAppContactWayLogsList" parameterType="QwAppContactWayLogs" resultMap="QwAppContactWayLogsResult">
        <include refid="selectQwAppContactWayLogsVo"/>
        <where>
            <if test="appWayId != null "> and app_way_id = #{appWayId}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="externalUserId != null "> and external_user_id = #{externalUserId}</if>
        </where>
    </select>

    <select id="selectQwAppContactWayLogsById" parameterType="Long" resultMap="QwAppContactWayLogsResult">
        <include refid="selectQwAppContactWayLogsVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwAppContactWayLogs" parameterType="QwAppContactWayLogs" useGeneratedKeys="true" keyProperty="id">
        insert into qw_app_contact_way_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appWayId != null">app_way_id,</if>
            <if test="source != null">source,</if>
            <if test="userId != null">user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="externalUserId != null">external_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="qwUserId != null">qw_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appWayId != null">#{appWayId},</if>
            <if test="source != null">#{source},</if>
            <if test="userId != null">#{userId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="externalUserId != null">#{externalUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
         </trim>
    </insert>

    <update id="updateQwAppContactWayLogs" parameterType="QwAppContactWayLogs">
        update qw_app_contact_way_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="appWayId != null">app_way_id = #{appWayId},</if>
            <if test="source != null">source = #{source},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwAppContactWayLogsById" parameterType="Long">
        delete from qw_app_contact_way_logs where id = #{id}
    </delete>


    <select id="selectQwAppContactWayLogsByAppWayId" parameterType="Long" resultMap="QwAppContactWayLogsResult">
        <include refid="selectQwAppContactWayLogsVo"/>
        where app_way_id = #{id}
         limit 1
    </select>

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