<?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.yida.data.attendance.mapper.EduAttendanceRuleTimeMapper">
    <select id="listDeptRuleTime" resultType="com.yida.data.attendance.vo.RuleTimeVO">
        select b.id timeId,group_concat(DATE_FORMAT(b.time1,'%H:%i'),'-' ,DATE_FORMAT(b.time2,'%H:%i')) timeName,a.type
        ruleType
        from edu_attendance_rule a
        left join edu_attendance_rule_time b on a.id = b.rule_id
        left join edu_attendance_rule_dept c on a.id = c.rule_id
        left join edu_attendance_rule_date d on a.id=d.rule_id
        <where>
            c.dept_id in
            <foreach collection="deptIds" close=")" open="(" separator="," item="item">
                #{item}
            </foreach>
            and b.day_of_week=#{week}
            <if test="type!=null">
                and a.type=#{type}
            </if>
            and d.start_date <![CDATA[<=]]> #{date}
            and d.end_date <![CDATA[>=]]> #{date}
        </where>
        group by b.id
        order by timeName
    </select>
</mapper>
