<?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.xjrsoft.module.attendance.mapper.AttendanceRuleDetailsMapper">
    <select id="getTodayRules" resultType="com.xjrsoft.module.attendance.entity.AttendanceRuleDetails">
        SELECT t2.* FROM attendance_rule_category t1
        INNER JOIN attendance_rule_details t2 ON t1.id = t2.attendance_rule_category_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 AND NOW() BETWEEN start_date AND end_date
        AND t2.date_type = #{dayOfWeek}
    </select>
    <select id="getAllTeacherTodyRule" resultType="com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo">
        SELECT t2.*,t5.user_id FROM attendance_rule_category t1
        INNER JOIN attendance_rule_details t2 ON t1.id = t2.attendance_rule_category_id
        INNER JOIN attendance_user_relation t3 ON t1.id = t3.attendance_rule_category_id
        INNER JOIN xjr_user t4 ON t3.user_id = t4.id
        INNER JOIN base_teacher t5 ON t4.id = t5.user_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 AND NOW() BETWEEN start_date AND end_date
        AND t2.date_type = #{dayOfWeek}
    </select>
    <select id="getAllStudentTodyRule" resultType="com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo">
        SELECT t2.*,t5.user_id FROM attendance_rule_category t1
        INNER JOIN attendance_rule_details t2 ON t1.id = t2.attendance_rule_category_id
        INNER JOIN attendance_user_relation t3 ON t1.id = t3.attendance_rule_category_id
        INNER JOIN xjr_user t4 ON t3.user_id = t4.id
        INNER JOIN base_student t5 ON t4.id = t5.user_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 AND NOW() BETWEEN start_date AND end_date
        AND t2.date_type = #{dayOfWeek}
    </select>

    <select id="getTodayRulesByUserId" resultType="com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo">
        SELECT t2.*,t5.user_id FROM attendance_rule_category t1
        INNER JOIN attendance_rule_details t2 ON t1.id = t2.attendance_rule_category_id
        INNER JOIN attendance_user_relation t3 ON t1.id = t3.attendance_rule_category_id
        INNER JOIN xjr_user t4 ON t3.user_id = t4.id
        INNER JOIN base_teacher t5 ON t4.id = t5.user_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 and t3.delete_mark = 0
        AND NOW() BETWEEN start_date AND end_date
        AND t2.date_type = #{dayOfWeek}
        <if test="userIds != null and !userIds.isEmpty()">
            and t5.user_id in
            <foreach item="id" index="index" collection="userIds" open="(" close=")" separator=",">
            #{id}
            </foreach>
        </if>
    </select>
</mapper>