<?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.HistoryMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dlink.model.History">
        <id column="id" property="id"/>
        <result column="cluster_id" property="clusterId"/>
        <result column="cluster_configuration_id" property="clusterConfigurationId"/>
        <result column="session" property="session"/>
        <result column="jod_id" property="jobId"/>
        <result column="job_name" property="jobName"/>
        <result column="job_manager_address" property="jobManagerAddress"/>
        <result column="status" property="status"/>
        <result column="statement" property="statement"/>
        <result column="type" property="type"/>
        <result column="error" property="error"/>
        <result column="result" property="result"/>
        <result column="config" property="config"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="task_id" property="taskId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,cluster_id,cluster_configuration_id,session,jod_id,job_name,
        job_manager_address,status,statement,type, error,
        result,config,start_time,end_time,task_id
    </sql>


    <select id="selectForProTable" resultType="com.dlink.model.History">
        select
        a.*,
        (select b.alias FROM dlink_cluster b where b.id=a.cluster_id) as clusterAlias,
        (select c.alias FROM dlink_task c where c.id=a.task_id) as taskAlias
        from
        dlink_history a
        <where>
            1=1
            <if test='param.jobId!=null and param.jobId!=""'>
                and a.job_id = #{param.jobId}
            </if>
            <if test='param.jobName!=null and param.jobName!=""'>
                and a.job_name like "%${param.jobName}%"
            </if>
            <if test='param.clusterId!=null and param.clusterId!=""'>
                and a.cluster_id = #{param.clusterId}
            </if>
            <if test='param.session!=null and param.session!=""'>
                and a.session = #{param.session}
            </if>
            <if test='param.status!=null and param.status!=""'>
                and a.status = #{param.status}
            </if>
            <if test='param.startTime!=null and param.startTime!=""'>
                and a.start_time <![CDATA[>=]]> str_to_date( #{param.startTime[0]},'%Y-%m-%d %H:%i:%s')
                and a.start_time <![CDATA[<=]]> str_to_date( #{param.startTime[1]},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test='param.endTime!=null and param.endTime!=""'>
                and a.end_time <![CDATA[>=]]> str_to_date( #{param.endTime[0]},'%Y-%m-%d %H:%i:%s')
                and a.end_time <![CDATA[<=]]> str_to_date( #{param.endTime[1]},'%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>
</mapper>
