<?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.persagy.adm.diagram.dao.LegendMapper">

    <resultMap id="legendBaseMap" type="com.persagy.adm.diagram.entity.LegendEntity">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="code" property="code" jdbcType="VARCHAR"/>
        <result column="bt_system" property="btSystem" jdbcType="VARCHAR"/>
        <result column="legend_content" property="legendContent" jdbcType="VARCHAR"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="creation_time" property="creationTime" jdbcType="CHAR"/>
        <result column="modifier" property="modifier" jdbcType="VARCHAR"/>
        <result column="modified_time" property="modifiedTime" jdbcType="CHAR"/>
        <result column="valid" property="valid" jdbcType="TINYINT"/>
        <result column="ts" property="ts" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="baseSql">
        id,bt_system,code,name,remark,legend_content,creator,creation_time,
        modifier,modified_time,valid,ts
    </sql>

    <insert id="saveLegend">
        INSERT INTO diagram_legend
        (id,bt_system,code,name,remark,legend_content,creator,creation_time,
        modifier,modified_time)
        VALUES (#{id},#{btSystem},#{code},#{name},#{remark},#{legendContent},#{creator},
        #{creationTime},#{modifier},#{modifiedTime})
    </insert>

    <delete id="deleteLegend">
        DELETE FROM diagram_legend
        WHERE id=#{legendId} AND bt_system=#{systemCode}
    </delete>

    <select id="getLegends" resultMap="legendBaseMap">
        SELECT
        <include refid="baseSql"/>
        FROM diagram_legend
        WHERE bt_system = #{systemCode}
    </select>

    <select id="getLegend" resultMap="legendBaseMap">
        SELECT
        <include refid="baseSql"/>
        FROM diagram_legend
        WHERE id = #{legendId} AND bt_system =#{systemCode}
    </select>


</mapper>


