<?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.ruoyi.zhushi.mapper.DkAttendanceGroupMapper">
    <resultMap id="DkAttendanceGroupRusult" type="com.ruoyi.zhushi.entity.AppDTO">
        <id property="id" column="id"/>
        <result property="attendanceGroupName" column="name"/>
        <result property="description" column="description"/>
        <result property="workStartTime" column="workStartTime"/>
        <result property="workEndTime" column="workEndTime"/>
        <result property="lng" column="lng"/>
        <result property="lat" column="lat"/>
        <result property="radius" column="radius"/>
        <result property="areaName" column="areaName"/>
        <result property="workDays" column="workDays"/>
        <result property="attendanceGroupId" column="attendanceGroupId"/>
        <result property="timeZone" column="timeZone"/>
    </resultMap>

    <select id="queryAttendanceGroupBYUserId" resultMap="DkAttendanceGroupRusult">
        select DISTINCT t.`name`, t.description,
                        t.work_start_time workStartTime,
                        t.work_end_time workEndTime,
                        t.allow_early allowEarly,
                        t.early_range earlyRange,
                        t.allow_late allowLate,
                        t.late_range lateRange,
                        c.lng lng, c.lat lat, c.radius,
                        c.`name` areaName,
                        t.work_days workDays,
                        t.id attendanceGroupId,
                        t.time_zone timeZone
        from dk_check_in_attendance_team_and_user u
        LEFT JOIN dk_check_in_attendance_team t on t.id = u.attendance_team_id
        left JOIN dk_check_in_config c on c.id = t.area_id
        <where>
                t.work_start_time is not null
            <if test="userId != null and userId != ''">
                AND u.user_id = #{userId}
            </if>
        </where>
    </select>

</mapper>
