<?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.ruixuan.isc.mapper.KuaishouLabelMapper">

    <resultMap type="com.ruixuan.isc.entity.KuaishouLabel" id="KuaishouLabelResult">
        <result property="id" column="id"/>
        <result property="labelName" column="label_name"/>
        <result property="labelColour" column="label_colour"/>
        <result property="labelType" column="label_type"/>
        <result property="labelLevel" column="label_level"/>
    </resultMap>

    <sql id="selectKuaishouLabelVo">
        select id, label_name, label_colour, label_type, label_level
        from kuaishou_label
    </sql>

    <select id="selectKuaishouLabelList" parameterType="com.ruixuan.isc.entity.KuaishouLabel"
            resultMap="KuaishouLabelResult">
        <include refid="selectKuaishouLabelVo"/>
        <where>
            <if test="labelName != null  and labelName != ''">and label_name like concat('%', #{labelName}, '%')</if>
            <if test="labelColour != null  and labelColour != ''">and label_colour = #{labelColour}</if>
            <if test="labelType != null  and labelType != ''">and label_type = #{labelType}</if>
            <if test="labelLevel != null  and labelLevel != ''">and label_level = #{labelLevel}</if>
        </where>
    </select>

    <select id="selectKuaishouLabelById" parameterType="Long" resultMap="KuaishouLabelResult">
        <include refid="selectKuaishouLabelVo"/>
        where id = #{id}
    </select>

    <insert id="insertKuaishouLabel" parameterType="com.ruixuan.isc.entity.KuaishouLabel" useGeneratedKeys="true"
            keyProperty="id">
        insert into kuaishou_label
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="labelName != null">label_name,</if>
            <if test="labelColour != null">label_colour,</if>
            <if test="labelType != null">label_type,</if>
            <if test="labelLevel != null">label_level,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="labelName != null">#{labelName},</if>
            <if test="labelColour != null">#{labelColour},</if>
            <if test="labelType != null">#{labelType},</if>
            <if test="labelLevel != null">#{labelLevel},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLabel" parameterType="com.ruixuan.isc.entity.KuaishouLabel">
        update kuaishou_label
        <trim prefix="SET" suffixOverrides=",">
            <if test="labelName != null">label_name = #{labelName},</if>
            <if test="labelColour != null">label_colour = #{labelColour},</if>
            <if test="labelType != null">label_type = #{labelType},</if>
            <if test="labelLevel != null">label_level = #{labelLevel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouLabelById" parameterType="Long">
        delete
        from kuaishou_label
        where id = #{id}
    </delete>

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

    <update id="updateLabelColourStatus">
        update kuaishou_label_colour
        set colour_status = 0
        where colour_code = #{labelColour}
    </update>

    <select id="getLabelColour" resultType="String">
        select colour_code
        from kuaishou_label_colour
        where colour_status = 1 Limit 1
    </select>
</mapper>