<?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.teachcloud.common.mapper.TBTaskMapper">

    <select id="query" resultType="com.qmth.teachcloud.common.bean.result.TaskListResult">
        select
            tbt.id,
            tbt.print_plan_id as printPlanId,
            concat_ws('-', epp.name, tbt.obj_name) as printPlanName,
            tbt.`type`,
            tbt.status,
            tbt.`result`,
            tbt.create_time as createTime,
            tbt.create_id as createId,
            su.real_name as createName,
            if(ISNULL(tbt.result_file_path),false,true) as hasResultFile,
            if(ISNULL(tbt.report_file_path),false,true) as hasReportFile,
            tbt.reset_count as resetCount,
            tbt.error_message as errorMessage
            from
            t_b_task tbt
            left join exam_print_plan epp on
            epp.id = tbt.print_plan_id
            left join sys_user su on su.id = tbt.create_id
            <where>
                <if test="schoolId != null and schoolId != ''">
                    and tbt.school_id = #{schoolId}
                </if>
                <if test="printPlanId != null and printPlanId != ''">
                    and tbt.print_plan_id = #{printPlanId}
                </if>
                <if test="status != null and status != ''">
                    and tbt.status = #{status}
                </if>
                <if test="type != null and type != ''">
                    and tbt.type = #{type}
                </if>
                <if test="result != null and result != ''">
                    and tbt.result = #{result}
                </if>
                <if test="orgIds != null">
                    AND su.org_id IN
                    <foreach collection="orgIds" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="orgIds == null and createId != null and createId != ''">
                    and tbt.create_id = #{createId}
                </if>
            </where>
            order by tbt.create_time desc
    </select>
</mapper>
