<?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.qywx.mapper.QywxTagMapper">
    
    <resultMap type="QywxTag" id="QywxTagResult">
        <result property="id"    column="id"    />
        <result property="tagId"    column="tag_id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="order"    column="order"    />
        <result property="corpId"    column="corp_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQywxTagVo">
        select id, tag_id, name, type, order, corp_id, create_time, update_time from qywx_tag
    </sql>

    <select id="selectQywxTagList" parameterType="QywxTag" resultMap="QywxTagResult">
        <include refid="selectQywxTagVo"/>
        <where>  
            <if test="tagId != null  and tagId != ''"> and tag_id = #{tagId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="order != null  and order != ''"> and order = #{order}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
        </where>
    </select>
    
    <select id="selectQywxTagById" parameterType="Long" resultMap="QywxTagResult">
        <include refid="selectQywxTagVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQywxTag" parameterType="QywxTag">
        insert into qywx_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tagId != null">tag_id,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="order != null">order,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tagId != null">#{tagId},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="order != null">#{order},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateQywxTag" parameterType="QywxTag">
        update qywx_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="tagId != null">tag_id = #{tagId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="order != null">order = #{order},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQywxTagById" parameterType="Long">
        delete from qywx_tag where id = #{id}
    </delete>

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