<?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.QuestionMapper">
    <select id="analyze" resultType="com.tuoheng.admin.entity.vo.QuestionCountVO">
        select q.status,count(q.id) as quantity
        from th_question q
        where q.mission_id=#{missionId} and tenant_id = #{tenantId}
        group by q.status;
    </select>

    <select id="analyzeType" resultType="com.tuoheng.admin.entity.vo.QuestionTypeCountVO">
        select q.type,count(q.id) as quantity
        from th_question q
        where q.mission_id=#{missionId} and tenant_id = ${tenantId} and q.status=1
        group by q.type;
    </select>

    <select id="getIndexQuestion" parameterType="com.tuoheng.admin.entity.request.index.GetQuestionListDto" resultType="com.tuoheng.admin.entity.dto.index.QuestionListDto">
        select a.create_time,a.id as questionId, a.tenant_id as tenantId, a.mission_id as missionId, a.type, b.content as typeName,
               a.mission_name as missionName, c.execution_start_time as inspectionTime,
               a.file_marker_url as fileMarkerUrl, d.handler_result as handlerResult,
               d.handler_image as handlerImage, d.handler_user as handlerUserId, e.realname as handlerUserName,
               d.handler_time as handlerTime, a.lng, a.lat
        from th_question a
                 inner join th_question_type b on b.code = a.type and b.mark = 1
                 inner join th_mission c on c.id = a.mission_id and c.mark = 1
                 left join th_question_handle d on d.question_id = a.id
                 left join sys_user e on e.id = d.handler_user
        where a.tenant_id = #{tenantId}
              and a.mark = 1 and a.status = 1 and a.create_time BETWEEN #{startTime} AND #{endTime}
        order by a.create_time desc limit 200
    </select>

</mapper>