<?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="cn.com.oa.mapper.AttendanceRecordMapper">

    <resultMap id="BaseResultMap" type="cn.com.oa.model.AttendanceRecord">
            <id property="recordId" column="record_id" jdbcType="BIGINT"/>
            <result property="attUserId" column="att_user_id" jdbcType="VARCHAR"/>
            <result property="attUserName" column="att_user_name" jdbcType="VARCHAR"/>
            <result property="sysUserId" column="sys_user_id" jdbcType="BIGINT"/>
            <result property="attTime" column="att_time" jdbcType="TIMESTAMP"/>
            <result property="attDate" column="att_date" jdbcType="DATE"/>
            <result property="attTypeId" column="att_type_id" jdbcType="VARCHAR"/>
            <result property="signType" column="sign_type" jdbcType="CHAR"/>
            <result property="longitude" column="longitude" jdbcType="VARCHAR"/>
            <result property="latitude" column="latitude" jdbcType="VARCHAR"/>
            <result property="location" column="location" jdbcType="VARCHAR"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="createUser" column="create_user" jdbcType="BIGINT"/>
            <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
            <result property="unitId" column="unit_id" jdbcType="BIGINT"/>
            <result property="outType" column="out_type" jdbcType="CHAR"/>
            <result property="outAddress" column="out_address" jdbcType="VARCHAR"/>
            <result property="allday" column="allDay" jdbcType="VARCHAR"/>
            <result property="specialType" column="special_type" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        record_id,att_user_id,att_user_name,
        sys_user_id,att_time,att_date,
        att_type_id,sign_type,longitude,
        latitude,location,remark,
        create_user,create_date,unit_id,
        out_type,out_address,allDay,
        special_type
    </sql>
    <select id="getRecordList" resultType="cn.com.oa.model.dto.AttendanceRecordDTO">
        SELECT
            t.att_user_name,
            MIN(t.att_time) AS first_att_time,
            MAX(t.att_time) AS last_att_time
        FROM hr_attendance_record t
        WHERE t.special_type = '1'
          AND t.unit_id = #{unitId}
          AND t.att_date = CURDATE()
        GROUP BY t.att_user_name
        ORDER BY first_att_time DESC
    </select>
    <select id="getResultListDay" resultType="cn.com.oa.model.dto.AttendanceRecordDTO">
        SELECT
            har.att_user_name,
            tg.GROUPNAME as dept_name,
            MIN( har.att_time ) AS first_att_time,
            MAX( har.att_time ) AS last_att_time
        FROM
            hr_attendance_record har
                JOIN t_user tu ON har.sys_user_id = tu.UNIVERSALID
                JOIN t_group tg ON tg.UNIVERSALID =(
                SELECT
                    gu.GROUPID
                FROM
                    t_groupxuser gu
                WHERE
                    gu.USERNAME = tu.UNIVERSALID
                  AND gu.state != 0
            AND gu.postype = 1
            )
        WHERE
            har.special_type = '1'
          AND har.unit_id = #{unitId}
          AND har.att_date = CURDATE()
          AND tu.UNIVERSALID NOT IN ('347517210967865','284381380647600','284381382211000','284381384120700')
        GROUP BY
            har.att_user_name
        ORDER BY
            first_att_time DESC
    </select>
</mapper>
