<?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.zhentao.mapper.MatchmakerCheckinMapper">
    
    <!-- 根据红娘ID和日期查询签到记录 -->
    <select id="selectByMakerIdAndDate" resultType="com.zhentao.entity.MatchmakerCheckin">
        SELECT * FROM matchmaker_checkin 
        WHERE maker_id = #{makerId} 
        AND checkin_date = #{checkinDate}
    </select>
    
    <!-- 查询最近一次签到记录 -->
    <select id="selectLastByMakerId" resultType="com.zhentao.entity.MatchmakerCheckin">
        SELECT * FROM matchmaker_checkin 
        WHERE maker_id = #{makerId} 
        ORDER BY checkin_date DESC 
        LIMIT 1
    </select>
    
    <!-- 查询累计签到天数 -->
    <select id="selectTotalDaysByMakerId" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM matchmaker_checkin 
        WHERE maker_id = #{makerId}
    </select>
    
    <!-- 查询指定年月的已签到日期列表 -->
    <select id="selectCheckedDatesByMakerIdAndMonth" resultType="java.lang.String">
        SELECT DATE_FORMAT(checkin_date, '%Y-%m-%d') AS checked_date FROM matchmaker_checkin 
        WHERE maker_id = #{makerId}
        AND YEAR(checkin_date) = #{year}
        AND MONTH(checkin_date) = #{month}
        ORDER BY checkin_date ASC
    </select>
    
</mapper>