<?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.distributed.print.business.mapper.TBSyncTaskMapper">
    <select id="query" resultType="com.qmth.teachcloud.common.bean.result.SyncListResult">
        SELECT
            tbst.id,
            tbst.type,
            tbst.object_id objectId,
            tbst.third_relate_id thirdRelateId,
            tbst.status,
            tbst.result,
            tbst.remark,
            if(ISNULL(tbst.report_file_path),false,true) as hasReportFile,
            tbst.error_message as errorMessage,
            tbst.create_id as createId,
            tbst.create_time as createTime,
            su.real_name as createName
        FROM
            t_b_sync_task tbst
                LEFT JOIN
            sys_user su ON tbst.create_id = su.id
        <where>
            <if test="schoolId != null and schoolId != ''">
                and tbst.school_id = #{schoolId}
            </if>
            <if test="status != null">
                and tbst.status = #{status}
            </if>
            <if test="type != null">
                and tbst.type = #{type}
            </if>
            <if test="result != null">
                and tbst.result = #{result}
            </if>
            <if test="orgIds != null and orgIds != '' and orgIds.size > 0">
                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 tbst.create_id = #{createId}
            </if>
        </where>
        order by tbst.create_time desc
    </select>
</mapper>