<?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.ExamTaskReviewLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.ExamTaskReviewLog">
    <result column="id" property="id" />
        <result column="exam_task_id" property="examTaskId" />
        <result column="review_status" property="reviewStatus" />
        <result column="reason" property="reason" />
        <result column="operate_id" property="operateId" />
        <result column="operate_time" property="operateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        exam_task_id, review_status, reason, operate_id, operate_time
    </sql>

    <select id="list" resultType="com.qmth.distributed.print.business.bean.dto.ReviewLogDto">
        select
            tffl.id,
            tffl.approve_operation as approvePass,
            tffl.approve_remark as reason,
            tffl.approve_setup as setUp,
            tffl.approve_id as operateId,
            su.real_name as operateName,
            tffl.create_time as operateTime
        from
            t_f_flow_log tffl
        left join sys_user su on tffl.approve_id = su.id
        where tffl.flow_id = #{flowId}
        order by tffl.create_time desc
    </select>

    <select id="findOnePassBySetUp"
            resultType="com.qmth.distributed.print.business.bean.dto.ApprovalForm.ApprovalInfo">
        SELECT
            tffl.approve_remark AS remark,
            tffl.approve_setup AS level,
            tffl.approve_id AS approveId,
            su.real_name AS approveName,
            tffl.create_time AS time
        FROM
            t_f_flow_log tffl
                LEFT JOIN
            sys_user su ON tffl.approve_id = su.id
        <where>
            AND tffl.approve_operation = 'APPROVE'
            <if test="flowId > 0 and flowId != ''">
                AND tffl.flow_id = #{flowId}
            </if>
            <if test="setup != null and setup != ''">
                AND tffl.approve_setup = #{setup}
            </if>
        </where>
        ORDER BY tffl.create_time DESC
        LIMIT 1
    </select>

</mapper>
