<?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.qmth.themis.business.dao.TBTaskHistoryMapper">

    <select id="taskQuery" resultType="com.qmth.themis.business.dto.response.TBTaskDto">
        select
            tbth.id,
            tbth.`type`,
            tbth.entity_id as entityId,
            tbth.status,
            tbth.summary,
            TRUNCATE(tbth.progress,2) as progress,
            if(ISNULL(tbth.result_file_path),0,1) as hasResultFile,
            if(ISNULL(tbth.report_file_path),0,1) as hasReportFile,
            tbth.create_time as createTime,
            tbth.start_time as startTime,
            tbth.finish_time as finishTime,
            tbth.create_id as createId,
            tbth.import_file_name as importFileName,
            h.name examName,
            tee1.name as entityName,
            tbu.name as createName
        from
            t_b_task_history tbth
            left join t_e_exam tee1 on tee1.id =  tbth.entity_id
            left join t_b_user tbu on tbu.id = tbth.create_id
            left join t_e_exam h on tbth.exam_id = h.id
            <where>
            	<if test="examId != null">
                    and h.id = #{examId}
                </if>
                <if test="taskId != null and taskId != ''">
                    and tbth.id = #{taskId}
                </if>
                <if test="orgId != null and orgId != ''">
                    and tbth.org_id = #{orgId}
                </if>
                <if test="entityId != null and entityId != ''">
                    and tbth.entity_id = #{entityId}
                </if>
                <if test="type != null and type != '' or type == 0">
                    and tbth.`type` = #{type}
                </if>
                <if test="status != null and status != '' or status == 0">
                    and tbth.`status` = #{status}
                </if>
            </where>
            order by tbth.create_time desc
    </select>
</mapper>
