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

    <select id="feedbackPage" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
        SELECT f.*,
        td.execute_content AS executeContent,
        tl.task_list_name AS taskListName,
        fb_user.name AS feedbackUserName,
        fb_dept.name AS feedbackDepartmentName,
        fb_corp.corp_name AS feedbackCorpName
        FROM safety_accountability_feedback f
        LEFT JOIN safety_accountability_task_detail td ON f.task_detail_id = td.task_detail_id and td.delete_enum = 'FALSE'
        LEFT JOIN safety_accountability_task_list tl ON f.task_list_id = tl.task_list_id and tl.delete_enum = 'FALSE'
        LEFT JOIN user fb_user ON f.feedback_user_id = fb_user.id
        LEFT JOIN department fb_dept ON f.feedback_department_id = fb_dept.id
        LEFT JOIN corp_info fb_corp ON f.feedback_corp_id = fb_corp.id
        <where>
            f.delete_enum = 'FALSE'
            <if test="params.feedbackCorpId != null">
                AND f.feedback_corp_id = #{params.feedbackCorpId}
            </if>
            <if test="params.taskListId != null and params.taskListId != ''">
                AND f.task_list_id = #{params.taskListId}
            </if>
            <if test="params.taskDetailId != null and params.taskDetailId != ''">
                AND f.task_detail_id = #{params.taskDetailId}
            </if>
            <if test="params.feedbackPeriodFlag != null and params.feedbackPeriodFlag != ''">
                AND f.feedback_period_flag = #{params.feedbackPeriodFlag}
            </if>
        </where>
        ORDER BY f.feedback_time DESC
    </select>

    <select id="listByTaskListId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
        SELECT * FROM safety_accountability_feedback
        WHERE task_list_id = #{taskListId} AND delete_enum = 'FALSE'
        ORDER BY create_time DESC
    </select>

    <select id="listByTaskDetailId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
        SELECT f.*,
        td.execute_content AS executeContent,
        tl.task_list_name AS taskListName,
        fb_user.name AS feedbackUserName,
        fb_dept.name AS feedbackDepartmentName,
        fb_corp.corp_name AS feedbackCorpName
        FROM safety_accountability_feedback f
        LEFT JOIN safety_accountability_task_detail td ON f.task_detail_id = td.task_detail_id AND td.delete_enum = 'FALSE'
        LEFT JOIN safety_accountability_task_list tl ON f.task_list_id = tl.task_list_id AND tl.delete_enum = 'FALSE'
        LEFT JOIN user fb_user ON f.feedback_user_id = fb_user.id
        LEFT JOIN department fb_dept ON f.feedback_department_id = fb_dept.id
        LEFT JOIN corp_info fb_corp ON f.feedback_corp_id = fb_corp.id
        WHERE f.task_detail_id = #{taskDetailId} AND f.delete_enum = 'FALSE'
        ORDER BY f.feedback_time DESC
    </select>

    <select id="getByFeedbackId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackDO">
        SELECT f.*,
        td.execute_content AS executeContent,
        tl.task_list_name AS taskListName,
        fb_user.name AS feedbackUserName,
        fb_dept.name AS feedbackDepartmentName,
        fb_corp.corp_name AS feedbackCorpName
        FROM safety_accountability_feedback f
        LEFT JOIN safety_accountability_task_detail td ON f.task_detail_id = td.task_detail_id AND td.delete_enum = 'FALSE'
        LEFT JOIN safety_accountability_task_list tl ON f.task_list_id = tl.task_list_id AND tl.delete_enum = 'FALSE'
        LEFT JOIN user fb_user ON f.feedback_user_id = fb_user.id
        LEFT JOIN department fb_dept ON f.feedback_department_id = fb_dept.id
        LEFT JOIN corp_info fb_corp ON f.feedback_corp_id = fb_corp.id
        WHERE f.feedback_id = #{feedbackId} AND f.delete_enum = 'FALSE'
    </select>

</mapper>
