<?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.dsk.system.mapper.BusinessLabelMapper">

    <resultMap type="com.dsk.common.core.domain.entity.BusinessLabel" id="BusinessLabelResult">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="label" column="label"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBusinessLabelVo">
        select id, business_id, label, create_time, update_time
        from business_label
    </sql>

    <select id="selectBusinessLabelList" parameterType="com.dsk.common.core.domain.entity.BusinessLabel"
            resultMap="BusinessLabelResult">
        <include refid="selectBusinessLabelVo"/>
        <where>
            <if test="businessId != null ">and business_id = #{businessId}</if>
            <if test="label != null  and label != ''">and label = #{label}</if>
        </where>
    </select>

    <select id="selectBusinessLabelById" parameterType="Long" resultMap="BusinessLabelResult">
        <include refid="selectBusinessLabelVo"/>
        where id = #{id}
    </select>

    <insert id="insertBusinessLabel" parameterType="com.dsk.common.core.domain.entity.BusinessLabel"
            useGeneratedKeys="true" keyProperty="id">
        insert into business_label
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="label != null">label,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="label != null">#{label},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateBusinessLabel" parameterType="com.dsk.common.core.domain.entity.BusinessLabel">
        update business_label
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="label != null">label = #{label},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusinessLabelById">
        delete
        from business_label
        where business_id = #{businessId} and label = #{label}
    </delete>

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