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

    <resultMap type="QwLabel" id="QwLabelResult">
        <result property="id"    column="id"    />
        <result property="labelId"    column="label_id"    />
        <result property="labelName"    column="label_name"    />
        <result property="deleted"    column="deleted"    />
        <result property="createTime"    column="create_time"    />
        <result property="labelType"    column="label_type"    />
        <result property="dataType"    column="data_type"    />
        <result property="groupId"    column="group_id"    />
        <result property="homeUserId"    column="home_user_id"    />
    </resultMap>

    <sql id="selectQwLabelVo">
        select id, label_id, label_name, deleted, create_time, label_type, data_type, group_id, home_user_id from qw_label
    </sql>

    <select id="selectQwLabelList" parameterType="QwLabel" resultMap="QwLabelResult">
        <include refid="selectQwLabelVo"/>
        <where>
            <if test="labelId != null "> and label_id = #{labelId}</if>
            <if test="labelName != null  and labelName != ''"> and label_name like concat('%', #{labelName}, '%')</if>
            <if test="deleted != null "> and deleted = #{deleted}</if>
            <if test="labelType != null "> and label_type = #{labelType}</if>
            <if test="dataType != null "> and data_type = #{dataType}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="homeUserId != null  and homeUserId != ''"> and home_user_id = #{homeUserId}</if>
        </where>
    </select>

    <select id="selectQwLabelById" parameterType="Long" resultMap="QwLabelResult">
        <include refid="selectQwLabelVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwLabel" parameterType="QwLabel" useGeneratedKeys="true" keyProperty="id">
        insert into qw_label
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="labelId != null">label_id,</if>
            <if test="labelName != null">label_name,</if>
            <if test="deleted != null">deleted,</if>
            <if test="createTime != null">create_time,</if>
            <if test="labelType != null">label_type,</if>
            <if test="dataType != null">data_type,</if>
            <if test="groupId != null">group_id,</if>
            <if test="homeUserId != null">home_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="labelId != null">#{labelId},</if>
            <if test="labelName != null">#{labelName},</if>
            <if test="deleted != null">#{deleted},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="labelType != null">#{labelType},</if>
            <if test="dataType != null">#{dataType},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="homeUserId != null">#{homeUserId},</if>
        </trim>
    </insert>

    <update id="updateQwLabel" parameterType="QwLabel">
        update qw_label
        <trim prefix="SET" suffixOverrides=",">
            <if test="labelId != null">label_id = #{labelId},</if>
            <if test="labelName != null">label_name = #{labelName},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="labelType != null">label_type = #{labelType},</if>
            <if test="dataType != null">data_type = #{dataType},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="homeUserId != null">home_user_id = #{homeUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwLabelById" parameterType="Long">
        delete from qw_label where id = #{id}
    </delete>

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