<?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.ruoyi.custclient.mapper.LabelTypeMapper">
    
    <resultMap type="LabelType" id="LabelTypeResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="rule"    column="rule"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLabelTypeVo">
        select id, name, rule, del_flag, create_time from label_type
    </sql>

    <select id="selectLabelTypeList" parameterType="LabelType" resultMap="LabelTypeResult">
        <include refid="selectLabelTypeVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="rule != null "> and rule = #{rule}</if>
        </where>
    </select>
    
    <select id="selectLabelTypeById" parameterType="Long" resultMap="LabelTypeResult">
        <include refid="selectLabelTypeVo"/>
        where id = #{id}
    </select>

    <insert id="insertLabelType" parameterType="LabelType" useGeneratedKeys="true" keyProperty="id">
        insert into label_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="rule != null">rule,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="rule != null">#{rule},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLabelType" parameterType="LabelType">
        update label_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="rule != null">rule = #{rule},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLabelTypeById" parameterType="Long">
        delete from label_type where id = #{id}
    </delete>

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