<?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.dlink.mapper.ClusterMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dlink.model.Cluster">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="alias" property="alias" />
        <result column="type" property="type" />
        <result column="hosts" property="hosts" />
        <result column="job_manager_host" property="jobManagerHost" />
        <result column="version" property="version" />
        <result column="status" property="status" />
        <result column="note" property="note" />
        <result column="auto_registers" property="autoRegisters" />
        <result column="cluster_configuration_id" property="clusterConfigurationId" />
        <result column="task_id" property="taskId" />
        <result column="enabled" property="enabled" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, alias, type,hosts,job_manager_host,version, status,note,auto_registers,cluster_configuration_id,task_id, enabled, create_time, update_time
    </sql>


    <select id="selectForProTable" resultType="com.dlink.model.Cluster">
        select
        a.*
        from
        dlink_cluster a
        <where>
            1=1
            <if test='param.name!=null and param.name!=""'>
                and a.name like "%${param.name}%"
            </if>
            <if test='param.alias!=null and param.alias!=""'>
                and a.alias like "%${param.alias}%"
            </if>
            <if test='param.createTime!=null and param.createTime!=""'>
                and a.create_time <![CDATA[>=]]> str_to_date( #{param.createTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test='param.updateTime!=null and param.updateTime!=""'>
                and a.update_time <![CDATA[>=]]> str_to_date( #{param.updateTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test='ew.sqlSegment!=null and ew.sqlSegment!="" and !ew.sqlSegment.startsWith(" ORDER BY")'>
                and
            </if>
            <if test='ew.sqlSegment!=null and ew.sqlSegment!=""'>
                ${ew.sqlSegment}
            </if>
        </where>
    </select>

    <select id="listSessionEnable" resultType="com.dlink.model.Cluster">
        select
        a.*
        from
        dlink_cluster a
        where enabled = 1
        and (type = 'standalone' or type = 'yarn-session'or type = 'kubernetes-session')
    </select>
</mapper>
