<?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),
            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,
            (select tee.name from t_e_exam tee where tee.id = tbth.entity_id) as entityName,
            (
            select
                tbu.name
            from
                t_b_user tbu
            where
                tbu.id = tbth.create_id) as createName
        from
            t_b_task_history tbth
            <where>
                <if test="taskId != null and taskId != ''">
                    and tbth.id = #{taskId}
                </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>
    </select>
</mapper>
