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

    <select id="selectForProTable" resultType="com.dlink.model.JobInstance">
        select
        a.*,
        dh.type as type,
        (select dc.alias FROM dlink_cluster dc where dc.id=a.cluster_id) as clusterAlias
        from
        dlink_job_instance a
        left join dlink_history dh on a.history_id = dh.id
        <where>
            1=1
            <if test='param.status!=null and param.status!=""'>
                and a.status = #{param.status}
            </if>
            <if test='param.type!=null and param.type!=""'>
                and dh.type = #{param.type}
            </if>
            <if test='param.name!=null and param.name!=""'>
                and a.name like "%${param.name}%"
            </if>
            <if test='param.jid!=null and param.jid!=""'>
                and a.jid like "%${param.jid}%"
            </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')
                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[0]},'%Y-%m-%d %H:%i:%s')
                and a.update_time <![CDATA[<=]]> str_to_date( #{param.updateTime[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>

    <select id="countStatus" resultType="com.dlink.model.JobInstanceCount">
        select
        status,
        count(1) as counts
        from
        dlink_job_instance
        group by status
    </select>

    <select id="listJobInstanceActive" resultType="com.dlink.model.JobInstance">
        select
        *
        from
        dlink_job_instance
        where status not in ('FAILED','CANCELED','FINISHED','UNKNOWN')
        order by id desc
    </select>
</mapper>
