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

    <resultMap id="baseMap" type="com.yida.data.attendance.vo.StaffRuleVO">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="createDate" column="create_date"/>
        <result property="createName" column="create_name"/>


        <collection property="staffList" select="findStaffList" ofType="java.lang.Long" column="id">
            <result column="staff_id"/>
        </collection>

    </resultMap>
    <select id="findStaffRuleList" resultMap="baseMap">
    SELECT
	id,
	create_date,
	create_name,
	name
    FROM
	edu_attendance_staff_rule
	WHERE
	del_flag =0
	<if test="ruleName != null and ruleName != ''">
	and name like concat('%',#{ruleName},'%')
    </if>
    <if test="ruleIds != null and ruleIds.size>0">
        and id in
        <foreach collection="ruleIds" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
    </if>
    <if test="schoolId != null">
        and school_id = #{schoolId}
    </if>
    order by create_date desc
    </select>

    <select id="findStaffList" resultType="java.lang.Long">
    select staff_id from edu_attendance_staff_rule_admin where rule_id = #{id}
    </select>

    <select id="findObjList" resultType="java.lang.Long">
    select obj_id from edu_attendance_staff_rule_obj where obj_id = #{id}
    </select>
    <select id="findStaffRuleById" resultType="com.yida.data.attendance.vo.FindStaffRuleVO">
    SELECT * FROM edu_attendance_staff_rule
    WHERE del_flag = 0
    and id = #{ruleId}
    </select>
	
	<!-- 查询教职工适用的考勤规则 -->
	<select id="selectMatchStaffRule" parameterType="com.yida.data.common.core.entity.attendance.EduAttendanceStaffRecord"
			resultType="com.yida.data.attendance.vo.FindStaffRuleVO">
		SELECT
			r.*
		FROM
			edu_attendance_staff_rule r
		LEFT JOIN edu_attendance_staff_rule_staff s ON r.id = s.rule_id
		WHERE
			r.del_flag = 0
		  AND r.school_id = #{schoolId}
		  AND s.staff_id = #{staffId}
	</select>
</mapper>
