<?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.huijy.management.mapper.LabelMapper">
    
    <resultMap type="Label" id="LabelResult">
        <result property="labelId"    column="label_id"    />
        <result property="markerType"    column="marker_type"    />
        <result property="name"    column="name"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createAt"    column="create_at"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectLabelVo">
        select label_id, marker_type, name, status, create_time, create_at, remarks from t_label
    </sql>

    <select id="selectLabelList" parameterType="Label" resultMap="LabelResult">
        <include refid="selectLabelVo"/>
        <where>  
            <if test="markerType != null  and markerType != ''"> and marker_type = #{markerType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectLabelByLabelId" parameterType="Long" resultMap="LabelResult">
        <include refid="selectLabelVo"/>
        where label_id = #{labelId}
    </select>
        
    <insert id="insertLabel" parameterType="Label" useGeneratedKeys="true" keyProperty="labelId">
        insert into t_label
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="markerType != null">marker_type,</if>
            <if test="name != null">name,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createAt != null">create_at,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="markerType != null">#{markerType},</if>
            <if test="name != null">#{name},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateLabel" parameterType="Label">
        update t_label
        <trim prefix="SET" suffixOverrides=",">
            <if test="markerType != null">marker_type = #{markerType},</if>
            <if test="name != null">name = #{name},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where label_id = #{labelId}
    </update>

    <delete id="deleteLabelByLabelId" parameterType="Long">
        delete from t_label where label_id = #{labelId}
    </delete>

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