<?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.zcloud.safetyDutyList.persistence.mapper.tasklist.FeedbackExceptionMapper">

    <select id="exceptionPage" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
        SELECT fe.*,
        tl.task_list_name AS taskListName,
        td.execute_content AS executeContent,
        CASE
            WHEN fe.exception_type = 1 THEN '未按时反馈'
            WHEN fe.exception_type = 2 THEN '反馈内容异常'
            WHEN fe.exception_type = 3 THEN '其他'
            ELSE ''
        END AS exceptionTypeName
        FROM safety_accountability_feedback_exception fe
        LEFT JOIN safety_accountability_task_list tl ON fe.task_list_id = tl.task_list_id
        LEFT JOIN safety_accountability_task_detail td ON fe.task_detail_id = td.task_detail_id
        <where>
            <if test="params.taskListId != null and params.taskListId != ''">
                AND fe.task_list_id = #{params.taskListId}
            </if>
            <if test="params.exceptionType != null">
                AND fe.exception_type = #{params.exceptionType}
            </if>
            <if test="params.exceptionPeriodFlag != null and params.exceptionPeriodFlag != ''">
                AND fe.exception_period_flag = #{params.exceptionPeriodFlag}
            </if>
        </where>
        ORDER BY fe.create_time DESC
    </select>

    <select id="listByFeedbackId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
        SELECT * FROM safety_accountability_feedback_exception
        WHERE task_detail_id = #{feedbackId}
        ORDER BY create_time DESC
    </select>

    <select id="listByTaskListId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
        SELECT * FROM safety_accountability_feedback_exception
        WHERE task_list_id = #{taskListId}
        ORDER BY create_time DESC
    </select>

    <select id="listByTaskDetailId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
        SELECT * FROM safety_accountability_feedback_exception
        WHERE task_detail_id = #{taskDetailId}
        ORDER BY create_time DESC
    </select>

    <select id="getByExceptionId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
        SELECT * FROM safety_accountability_feedback_exception WHERE feedback_exception_id = #{exceptionId}
    </select>

</mapper>
