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

    <select id="listPage" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskDetailDO">
        SELECT td.*,
        tl.task_list_name AS taskListName,
        tl.task_level AS taskLevel,
        tl.responsibility_post AS responsibilityPost
        FROM safety_accountability_task_detail td
        LEFT JOIN safety_accountability_task_list tl ON td.task_list_id = tl.task_list_id AND tl.delete_enum = 'FALSE'
        <where>
            td.delete_enum = 'FALSE'
            <if test="params.taskListId != null and params.taskListId != ''">
                AND td.task_list_id = #{params.taskListId}
            </if>
            <if test="params.taskContent != null and params.taskContent != ''">
                AND td.execute_content LIKE CONCAT('%', #{params.taskContent}, '%')
            </if>
            <if test="params.feedbackCycleType != null">
                AND td.feedback_cycle_type = #{params.feedbackCycleType}
            </if>
        </where>
        ORDER BY td.id ASC
    </select>

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

    <select id="getByTaskDetailId" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskDetailDO">
        SELECT td.*,
        tl.task_list_name AS taskListName,
        tl.task_level AS taskLevel,
        tl.responsibility_post AS responsibilityPost
        FROM safety_accountability_task_detail td
        LEFT JOIN safety_accountability_task_list tl ON td.task_list_id = tl.task_list_id AND tl.delete_enum = 'FALSE'
        WHERE td.task_detail_id = #{taskDetailId} AND td.delete_enum = 'FALSE'
    </select>

    <delete id="deleteByTaskListId">
        DELETE FROM safety_accountability_task_detail WHERE task_list_id = #{taskListId}
    </delete>

</mapper>
