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

    <resultMap type="QwAutoTags" id="QwAutoTagsResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="createName"    column="create_name"    />
        <result property="applyUsers"    column="apply_users"    />
        <result property="ruleName"    column="rule_name"    />
        <result property="rulesTags"    column="rules_tags"    />
        <result property="totalNumTags"    column="total_num_tags"    />
        <result property="numTagsTaday"    column="num_tags_taday"    />
        <result property="isApply"    column="is_apply"    />
        <result property="createTime"    column="create_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="corpId"    column="corp_id"    />
    </resultMap>

    <sql id="selectQwAutoTagsVo">
        select id, type, create_name,corp_id, apply_users, rule_name, rules_tags, total_num_tags, num_tags_taday, is_apply, create_time, company_id from qw_auto_tags
    </sql>

    <select id="selectQwAutoTagsList" parameterType="QwAutoTags" resultMap="QwAutoTagsResult">
        <include refid="selectQwAutoTagsVo"/>
        <where>
            <if test="type != null "> and type = #{type}</if>
            <if test="createName != null  and createName != ''"> and create_name like concat('%', #{createName}, '%')</if>
            <if test="applyUsers != null  and applyUsers != ''"> and apply_users = #{applyUsers}</if>
            <if test="ruleName != null  and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
            <if test="rulesTags != null  and rulesTags != ''"> and rules_tags = #{rulesTags}</if>
            <if test="totalNumTags != null "> and total_num_tags = #{totalNumTags}</if>
            <if test="numTagsTaday != null "> and num_tags_taday = #{numTagsTaday}</if>
            <if test="isApply != null "> and is_apply = #{isApply}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectQwAutoTagsById" parameterType="Long" resultMap="QwAutoTagsResult">
        <include refid="selectQwAutoTagsVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwAutoTags" parameterType="QwAutoTags">
        insert into qw_auto_tags
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="type != null">type,</if>
            <if test="createName != null">create_name,</if>
            <if test="applyUsers != null">apply_users,</if>
            <if test="ruleName != null">rule_name,</if>
            <if test="rulesTags != null">rules_tags,</if>
            <if test="totalNumTags != null">total_num_tags,</if>
            <if test="numTagsTaday != null">num_tags_taday,</if>
            <if test="isApply != null">is_apply,</if>
            <if test="createTime != null">create_time,</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="type != null">#{type},</if>
            <if test="createName != null">#{createName},</if>
            <if test="applyUsers != null">#{applyUsers},</if>
            <if test="ruleName != null">#{ruleName},</if>
            <if test="rulesTags != null">#{rulesTags},</if>
            <if test="totalNumTags != null">#{totalNumTags},</if>
            <if test="numTagsTaday != null">#{numTagsTaday},</if>
            <if test="isApply != null">#{isApply},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="corpId != null">#{corpId},</if>
         </trim>
    </insert>

    <update id="updateQwAutoTags" parameterType="QwAutoTags">
        update qw_auto_tags
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="createName != null">create_name = #{createName},</if>
            <if test="applyUsers != null">apply_users = #{applyUsers},</if>
            <if test="ruleName != null">rule_name = #{ruleName},</if>
            <if test="rulesTags != null">rules_tags = #{rulesTags},</if>
            <if test="totalNumTags != null">total_num_tags = #{totalNumTags},</if>
            <if test="numTagsTaday != null">num_tags_taday = #{numTagsTaday},</if>
            <if test="isApply != null">is_apply = #{isApply},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwAutoTagsById" parameterType="Long">
        delete from qw_auto_tags where id = #{id}
    </delete>

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