<?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.sundot.airport.exam.mapper.DailyTaskConfigMapper">

    <!-- 根据用户角色和部门ID查询有效的配置 -->
    <select id="findEffectiveConfigByRoleAndDept" resultType="com.sundot.airport.exam.domain.DailyTaskConfig">
        SELECT
            id,
            dtc_id,
            dtc_name,
            dtc_roles,
            dtc_dept_ids,
            dtc_daily_sets,
            dtc_questions_per_set,
            dtc_time_limit,
            dtc_total_score,
            dtc_enable_status,
            dtc_start_date,
            dtc_end_date,
            del_status,
            create_time,
            create_uid,
            update_time,
            update_uid,
            remark
        FROM edu_cs_daily_task_config
        WHERE del_status = 0
          AND dtc_enable_status = 1
          AND (dtc_start_date IS NULL OR dtc_start_date &lt;= #{currentDate})
          AND (dtc_end_date IS NULL OR dtc_end_date &gt;= #{currentDate})
          AND FIND_IN_SET(#{role}, dtc_roles) > 0
          AND (dtc_dept_ids IS NULL OR dtc_dept_ids = '' OR FIND_IN_SET(#{deptId}, dtc_dept_ids) > 0)
        ORDER BY create_time DESC
        LIMIT 1
    </select>

</mapper>
