<?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.QwAutoTagsRulesMapper">
    
    <resultMap type="QwAutoTagsRules" id="QwAutoTagsRulesResult">
        <result property="id"    column="id"    />
        <result property="autoTagsId"    column="auto_tags_id"    />
        <result property="rules"    column="rules"    />
        <result property="tags"    column="tags"    />
        <result property="isApply"    column="is_apply"    />
        <result property="createTime"    column="create_time"    />
        <result property="type"    column="type"    />
        <result property="companyId"    column="company_id"    />
        <result property="corpId"    column="corp_id"    />
    </resultMap>

    <sql id="selectQwAutoTagsRulesVo">
        select id, auto_tags_id, rules, tags, is_apply, create_time, type, company_id, corp_id from qw_auto_tags_rules
    </sql>

    <select id="selectQwAutoTagsRulesList" parameterType="QwAutoTagsRules" resultMap="QwAutoTagsRulesResult">
        <include refid="selectQwAutoTagsRulesVo"/>
        <where>  
            <if test="autoTagsId != null "> and auto_tags_id = #{autoTagsId}</if>
            <if test="rules != null  and rules != ''"> and rules = #{rules}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="isApply != null "> and is_apply = #{isApply}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
        </where>
    </select>
    
    <select id="selectQwAutoTagsRulesById" parameterType="Long" resultMap="QwAutoTagsRulesResult">
        <include refid="selectQwAutoTagsRulesVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQwAutoTagsRules" parameterType="QwAutoTagsRules">
        insert into qw_auto_tags_rules
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="autoTagsId != null">auto_tags_id,</if>
            <if test="rules != null">rules,</if>
            <if test="tags != null">tags,</if>
            <if test="isApply != null">is_apply,</if>
            <if test="createTime != null">create_time,</if>
            <if test="type != null">type,</if>
            <if test="companyId != null">company_id,</if>
            <if test="corpId != null">corp_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="autoTagsId != null">#{autoTagsId},</if>
            <if test="rules != null">#{rules},</if>
            <if test="tags != null">#{tags},</if>
            <if test="isApply != null">#{isApply},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="type != null">#{type},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="corpId != null">#{corpId},</if>
         </trim>
    </insert>

    <update id="updateQwAutoTagsRules" parameterType="QwAutoTagsRules">
        update qw_auto_tags_rules
        <trim prefix="SET" suffixOverrides=",">
            <if test="autoTagsId != null">auto_tags_id = #{autoTagsId},</if>
            <if test="rules != null">rules = #{rules},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="isApply != null">is_apply = #{isApply},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="type != null">type = #{type},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwAutoTagsRulesById" parameterType="Long">
        delete from qw_auto_tags_rules where id = #{id}
    </delete>

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

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