<?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.AttendanceStatisticsMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.attendance.dto.AttendanceStatisticsPageDto" resultType="com.xjrsoft.module.attendance.vo.AttendanceStatisticsPageVo">
        SELECT t1.id,t1.year,t1.month,t1.name,t1.start_date,t1.end_date,t2.name AS rule_name,
        t1.person_count,t1.attendance_days, t1.status,t1.is_need_refresh,t1.time_period FROM attendance_statistics t1
        LEFT JOIN attendance_rule_category t2 ON t1.attendance_rule_category_id = t2.id
        WHERE t1.delete_mark = 0
        <if test="dto.name != null and dto.name != ''">
            and t1.name like concat('%', #{dto.name},'%')
        </if>
        <if test="dto.year != null">
            and t1.year = #{dto.year}
        </if>
        <if test="dto.month != null">
            and t1.month = #{dto.month}
        </if>
        <if test="dto.status != null">
            and t1.status = #{dto.status}
        </if>
        ORDER BY t1.create_date DESC
    </select>

    <select id="getRecordList" parameterType="com.xjrsoft.module.attendance.dto.AttendanceStatisticsRecordDto" resultType="com.xjrsoft.module.attendance.vo.AttendanceStatisticsRecordVo">
        SELECT t1.id,t2.name,t2.user_name,t1.normal_count,t1.leave_count,t1.absentee_count,t1.dept_name,t1.days_data FROM attendance_statistics_record t1
        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        WHERE t1.delete_mark = 0 AND t1.attendance_statistics_id = #{dto.id}
        <if test="dto.name != null and dto.name != ''">
            and t2.name like concat('%', #{dto.name},'%')
        </if>
    </select>
</mapper>