<?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="LogicalClusterDao">
    <resultMap id="LogicalClusterMap"   type="com.xiaojukeji.kafka.manager.common.entity.pojo.LogicalClusterDO">
        <id column="id"                 property="id" />
        <result column="gmt_create"     property="gmtCreate" />
        <result column="gmt_modify"     property="gmtModify" />

        <result column="name"           property="name" />
        <result column="identification" property="identification" />
        <result column="app_id"         property="appId" />
        <result column="cluster_id"     property="clusterId" />
        <result column="region_list"    property="regionList" />
        <result column="mode"           property="mode" />
        <result column="description"    property="description" />
    </resultMap>

    <insert id="insert" parameterType="com.xiaojukeji.kafka.manager.common.entity.pojo.LogicalClusterDO">
        INSERT INTO logical_cluster
          (name, identification, app_id, cluster_id, region_list, mode, description)
        VALUES
          (#{name}, #{identification}, #{appId}, #{clusterId}, #{regionList}, #{mode}, #{description})
    </insert>

    <delete id="deleteById" parameterType="java.lang.Long">
        DELETE FROM logical_cluster WHERE id = #{id}
    </delete>

    <update id="updateById" parameterType="com.xiaojukeji.kafka.manager.common.entity.pojo.LogicalClusterDO">
        UPDATE logical_cluster SET
            name=#{name},
            <!-- identification=#{identification}, 不允许修改 identification, 会影响到上报的数据 -->
            cluster_id=#{clusterId},
            region_list=#{regionList},
            description=#{description},
            app_id=#{appId},
            mode=#{mode}
        WHERE id=#{id}
    </update>

    <select id="getById" parameterType="java.lang.Long" resultMap="LogicalClusterMap">
        SELECT * FROM logical_cluster WHERE id=#{id}
    </select>

    <select id="getByClusterId" parameterType="java.lang.Long" resultMap="LogicalClusterMap">
        SELECT * FROM logical_cluster WHERE cluster_id=#{clusterId}
    </select>

    <select id="listAll" resultMap="LogicalClusterMap">
        <![CDATA[
      SELECT * FROM logical_cluster
    ]]>
    </select>
</mapper>