<?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.QwAutoTagsLogsMapper">

    <resultMap type="QwAutoTagsLogs" id="QwAutoTagsLogsResult">
        <result property="id"    column="id"    />
        <result property="autoTagId"    column="auto_tag_id"    />
        <result property="type"    column="type"    />
        <result property="qwUserid"    column="qw_userid"    />
        <result property="corpId"    column="corp_id"    />
        <result property="externalUserId"    column="external_user_id"    />
        <result property="effectiveRules"    column="effective_rules"    />
        <result property="addTime"    column="add_time"    />
        <result property="chatId"    column="chat_id"    />
        <result property="joinScene"    column="join_scene"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectQwAutoTagsLogsVo">
        select id, auto_tag_id, type, qw_userid, external_user_id, effective_rules, add_time, chat_id, join_scene, company_id ,corp_id from qw_auto_tags_logs
    </sql>

    <select id="selectQwAutoTagsLogsList" parameterType="QwAutoTagsLogs" resultMap="QwAutoTagsLogsResult">
        <include refid="selectQwAutoTagsLogsVo"/>
        <where>
            <if test="autoTagId != null "> and auto_tag_id = #{autoTagId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="qwUserid != null  and qwUserid != ''"> and qw_userid = #{qwUserid}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
            <if test="externalUserId != null  and externalUserId != ''"> and external_user_id = #{externalUserId}</if>
            <if test="effectiveRules != null  and effectiveRules != ''"> and effective_rules = #{effectiveRules}</if>
            <if test="addTime != null "> and add_time = #{addTime}</if>
            <if test="chatId != null  and chatId != ''"> and chat_id = #{chatId}</if>
            <if test="joinScene != null  and joinScene != ''"> and join_scene = #{joinScene}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>

        </where>
        order by addTime desc
    </select>

    <select id="selectQwAutoTagsLogsById" parameterType="Long" resultMap="QwAutoTagsLogsResult">
        <include refid="selectQwAutoTagsLogsVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwAutoTagsLogs" parameterType="QwAutoTagsLogs">
        insert into qw_auto_tags_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="autoTagId != null">auto_tag_id,</if>
            <if test="type != null">type,</if>
            <if test="qwUserid != null">qw_userid,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="externalUserId != null">external_user_id,</if>
            <if test="effectiveRules != null">effective_rules,</if>
            <if test="addTime != null">add_time,</if>
            <if test="chatId != null">chat_id,</if>
            <if test="joinScene != null">join_scene,</if>
            <if test="companyId != null">company_id,</if>

         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="autoTagId != null">#{autoTagId},</if>
            <if test="type != null">#{type},</if>
            <if test="qwUserid != null">#{qwUserid},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="externalUserId != null">#{externalUserId},</if>
            <if test="effectiveRules != null">#{effectiveRules},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="chatId != null">#{chatId},</if>
            <if test="joinScene != null">#{joinScene},</if>
            <if test="companyId != null">#{companyId},</if>

         </trim>
    </insert>

    <insert id="insertOrUpdateQwAutoTagsLogs" parameterType="QwAutoTagsLogs">
        insert into qw_auto_tags_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="autoTagId != null">auto_tag_id,</if>
            <if test="type != null">type,</if>
            <if test="qwUserid != null">qw_userid,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="externalUserId != null">external_user_id,</if>
            <if test="effectiveRules != null">effective_rules,</if>
            <if test="addTime != null">add_time,</if>
            <if test="chatId != null">chat_id,</if>
            <if test="joinScene != null">join_scene,</if>
            <if test="companyId != null">company_id,</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="autoTagId != null">#{autoTagId},</if>
            <if test="type != null">#{type},</if>
            <if test="qwUserid != null">#{qwUserid},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="externalUserId != null">#{externalUserId},</if>
            <if test="effectiveRules != null">#{effectiveRules},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="chatId != null">#{chatId},</if>
            <if test="joinScene != null">#{joinScene},</if>
            <if test="companyId != null">#{companyId},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="autoTagId != null">auto_tag_id = #{autoTagId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="qwUserid != null">qw_userid = #{qwUserid},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
            <if test="effectiveRules != null">effective_rules = #{effectiveRules},</if>
            <if test="addTime != null">add_time = #{addTime},</if>
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="joinScene != null">join_scene = #{joinScene},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>

    </insert>

    <update id="updateQwAutoTagsLogs" parameterType="QwAutoTagsLogs">
        update qw_auto_tags_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="autoTagId != null">auto_tag_id = #{autoTagId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="qwUserid != null">qw_userid = #{qwUserid},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="externalUserId != null">external_user_id = #{externalUserId},</if>
            <if test="effectiveRules != null">effective_rules = #{effectiveRules},</if>
            <if test="addTime != null">add_time = #{addTime},</if>
            <if test="chatId != null">chat_id = #{chatId},</if>
            <if test="joinScene != null">join_scene = #{joinScene},</if>
            <if test="companyId != null">company_id = #{companyId},</if>

        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwAutoTagsLogsById" parameterType="Long">
        delete from qw_auto_tags_logs where id = #{id}
    </delete>

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