<?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.tuoheng.admin.mapper.WorkOrderMapper">

    <select id="questionPage" resultType="com.tuoheng.admin.entity.vo.WorkOrderQuestionVO">
        SELECT
        q.type,
        q.id AS questionId,
        q.question_name AS questionName,
        q.question_desc AS questionDesc,
        q.file_original_url AS fileOriginalUrl,
        q.file_marker_url AS fileMarkerUrl,
        q.lng AS lng,
        q.lat AS lat,
        woq.`status` AS status,
        q.create_time AS createTime,
        qh.handler_user AS handlerUser,
        qh.handler_image AS handlerImage,
        qh.handler_result AS handlerResult,
        qh.handler_time AS handlerTime,
        u.realname AS handlerUserName
        FROM th_work_order wo
        LEFT JOIN th_work_order_question  woq on wo.id = woq.work_order_id
        LEFT JOIN th_question q on woq.question_id = q.id
        LEFT JOIN th_question_handle qh on q.id = qh.question_id
        LEFT JOIN sys_user u on qh.handler_user = u.id
        WHERE
        wo.tenant_id = #{tenantId}
        AND wo.mark = 1
        AND wo.id = #{request.workOrderId}
        <if test="request.questionType != '' and request.questionType != null">
            AND q.type = #{request.questionType}
        </if>
        <if test="request.status != null">
            AND woq.`status` = #{request.status}
        </if>
    </select>

</mapper>