<?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="jnpf.culture.mapper.CultureClockInMapper" >

    <!-- 查询打卡记录列表 -->
    <select id="getClockInList" resultType="jnpf.entity.culture.CultureClockIn">
        select r.F_Id id, r.F_UserId userId, r.F_ClockInDate clockInDate, r.F_ClockInTime clockInTime, r.F_ContentId contentId, r.F_PicId picId, r.F_PicUrl picUrl,
               r.F_CreatorTime creatorTime, r.F_LastModifyTime lastModifyTime
        from ftb_culture_clock_in r
        join (
            select F_UserId, max(F_ClockInTime) as maxTime
            from ftb_culture_clock_in
            where F_DeleteMark = 0
            group by F_UserId
        ) t on r.F_UserId = t.F_UserId and r.F_ClockInTime = t.maxTime
        where r.F_DeleteMark = 0
        <if test="null != startDate and '' != startDate">
            and r.F_ClockInDate <![CDATA[ >= ]]> #{startDate}
        </if>
        <if test="null != endDate and '' != endDate">
            and r.F_ClockInDate <![CDATA[ <= ]]> #{endDate}
        </if>
        <if test="null != list and list.size > 0">
            and r.F_UserId in
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        order by F_ClockInTime desc
    </select>
    <!-- 查询一年的打卡日期 -->
    <select id="getClockInDateByYear" resultType="java.lang.String">
        select distinct r.F_ClockInDate
        from ftb_culture_clock_in r
        where r.F_DeleteMark = 0 and r.F_UserId = #{userId}
        and r.F_ClockInDate <![CDATA[ >= ]]> #{startDate} and r.F_ClockInDate <![CDATA[ < ]]> #{endDate}
        order by r.F_ClockInDate desc
    </select>
    <!-- 查询日期游标列表 -->
    <select id="getClockInDateList" resultType="java.time.LocalDate">
        select distinct r.F_ClockInDate
        from ftb_culture_clock_in r
        where r.F_DeleteMark = 0
        and r.F_UserId = #{userId}
        <if test="cursorDate != null and cursorDate != ''">
            and r.F_ClockInDate <![CDATA[ < ]]> #{cursorDate}
        </if>
        order by r.F_ClockInDate desc
        limit #{limitPlusOne}
    </select>
    <!-- 查询这些日期下的打卡记录 -->
    <select id="getClockInListByDates" resultType="jnpf.entity.culture.CultureClockIn">
        select  r.F_Id id, r.F_UserId userId, r.F_ClockInDate clockInDate, r.F_ClockInTime clockInTime, r.F_ContentId contentId, r.F_PicId picId, r.F_PicUrl picUrl,
            r.F_CreatorTime creatorTime, r.F_LastModifyTime lastModifyTime
        from ftb_culture_clock_in r
        where r.F_DeleteMark = 0 and r.F_UserId = #{userId} and r.F_ClockInDate in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by r.F_ClockInDate desc, r.F_ClockInTime desc
    </select>
</mapper>