<?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.LabelCodeMapper">
    
    <resultMap type="LabelCode" id="LabelCodeResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="automatic"    column="automatic"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="labelTypeId"    column="label_type_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLabelCodeVo">
        select id, name, automatic, del_flag, label_type_id, create_time from label_code
    </sql>

    <select id="selectLabelCodeList" parameterType="LabelCode" resultMap="LabelCodeResult">
        <include refid="selectLabelCodeVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="automatic != null "> and automatic = #{automatic}</if>
            <if test="labelTypeId != null "> and label_type_id = #{labelTypeId}</if>
        </where>
    </select>
    
    <select id="selectLabelCodeById" parameterType="Long" resultMap="LabelCodeResult">
        <include refid="selectLabelCodeVo"/>
        where id = #{id}
    </select>

    <insert id="insertLabelCode" parameterType="LabelCode" useGeneratedKeys="true" keyProperty="id">
        insert into label_code
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="automatic != null">automatic,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="labelTypeId != null">label_type_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="automatic != null">#{automatic},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="labelTypeId != null">#{labelTypeId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLabelCode" parameterType="LabelCode">
        update label_code
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="automatic != null">automatic = #{automatic},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="labelTypeId != null">label_type_id = #{labelTypeId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLabelCodeById" parameterType="Long">
        delete from label_code where id = #{id}
    </delete>

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