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

    <resultMap type="QwTagGroup" id="QwTagGroupResult">
        <result property="id"    column="id"    />
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="order"    column="order"    />
        <result property="corpId"    column="corp_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="groupFrom"    column="group_from"    />
    </resultMap>

    <sql id="selectQwTagGroupVo">
        select id, group_id, name, `order`, corp_id, company_id, create_time, update_time, group_from from qw_tag_group
    </sql>

    <select id="selectQwTagGroupList" parameterType="QwTagGroup" resultMap="QwTagGroupResult">
        <include refid="selectQwTagGroupVo"/>
        <where>
            <if test="groupId != null  and groupId != ''"> and group_id = #{groupId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="order != null  and order != ''"> and order = #{order}</if>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="groupFrom != null "> and group_from = #{groupFrom}</if>
        </where>
    </select>

    <select id="selectQwTagGroupById" parameterType="Long" resultMap="QwTagGroupResult">
        <include refid="selectQwTagGroupVo"/>
        where id = #{id}
    </select>

    <select id="selectQwTagGroupListByIds" resultType="com.fs.qw.vo.QwTagGroupListVO">
        SELECT *
        FROM qw_tag_group
        WHERE group_id IN
        <foreach collection="groupIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertQwTagGroup" parameterType="QwTagGroup">
        insert into qw_tag_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="name != null">`name`,</if>
            <if test="order != null">`order`,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="groupFrom != null">group_from,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="name != null">#{name},</if>
            <if test="order != null">#{order},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="groupFrom != null">#{groupFrom},</if>
         </trim>
    </insert>

    <update id="updateQwTagGroup" parameterType="QwTagGroup">
        update qw_tag_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="order != null">`order` = #{order},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="groupFrom != null">group_from = #{groupFrom},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwTagGroupById" parameterType="Long">
        delete from qw_tag_group where id = #{id}
    </delete>

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