<?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.fastbee.ggroup.mapper.GLegendMapper">

    <resultMap type="GLegend" id="GLegendResult">
        <result property="id"    column="id"    />
        <result property="icon"    column="icon"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="name"    column="name"    />
        <result property="projectId"    column="project_id"    />
        <result property="category"    column="category"    />
        <result property="description"    column="description"    />
    </resultMap>

    <sql id="selectGLegendVo">
        select id, icon, create_time, create_by, update_time, update_by, name, project_id, category, description from g_legend
    </sql>

    <select id="selectGLegendList" parameterType="GLegend" resultMap="GLegendResult">
        <include refid="selectGLegendVo"/>
        <where>
            <if test="icon != null  and icon != ''"> and icon = #{icon}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
        </where>
    </select>

    <select id="selectGLegendById" parameterType="Long" resultMap="GLegendResult">
        <include refid="selectGLegendVo"/>
        where id = #{id}
    </select>

    <insert id="insertGLegend" parameterType="GLegend" useGeneratedKeys="true" keyProperty="id">
        insert into g_legend
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="icon != null">icon,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="name != null">name,</if>
            <if test="projectId != null">project_id,</if>
            <if test="category != null">category,</if>
            <if test="description != null">description,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="icon != null">#{icon},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="name != null">#{name},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="category != null">#{category},</if>
            <if test="description != null">#{description},</if>
        </trim>
    </insert>

    <update id="updateGLegend" parameterType="GLegend">
        update g_legend
        <trim prefix="SET" suffixOverrides=",">
            <if test="icon != null">icon = #{icon},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="name != null">name = #{name},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="category != null">category = #{category},</if>
            <if test="description != null">description = #{description},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGLegendById" parameterType="Long">
        delete from g_legend where id = #{id}
    </delete>

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