<?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.school.userLeave.mapper.EduLeaveRequestProcessConfigMapper">


  <select id="findPage" resultType="com.yida.data.school.vo.userLeave.EduLeaveRequestProcessConfigVO">
    SELECT *
    FROM edu_leave_request_process_config
    WHERE del_flag = 0
    <if test="schoolId != null">
      and school_id = #{schoolId}
    </if>
    <if test="processName != null">
      and process_name LIKE CONCAT('%',#{processName},'%')
    </if>
    ORDER BY create_date DESC
  </select>

  <select id="findConfigByDeptIds" resultType="com.yida.data.common.core.entity.userLeave.EduLeaveRequestProcessConfig">
    SELECT
    ec.*
    FROM
    edu_leave_request_process_config ec
    LEFT JOIN edu_leave_request_process_config_applicable_departments ed ON ed.process_id = ec.id
    where ec.del_flag = 0
    <if test="type != null">
      and ec.process_type = #{type}
    </if>
    <if test="requestDays != null">
      <![CDATA[
      and ec.min_days <= #{requestDays} and #{requestDays} < ec.max_days
      ]]>
    </if>
    <if test="deptIds != null and deptIds.size()>0">
      and ed.user_dept_id in
      <foreach collection="deptIds" separator="," close=")" open="(" item="item">
        #{item}
      </foreach>
    </if>
  </select>

</mapper>
