package org.dromara.app.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.dromara.app.domain.AppWateringLog;
import org.dromara.app.domain.vo.AppWateringLogVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;

/**
 * 浇水记录Mapper接口
 *
 * @author Lion Li
 * @date 2026-04-25
 */
public interface AppWateringLogMapper extends BaseMapperPlus<AppWateringLog, AppWateringLogVo> {

    @Select("SELECT count(id) FROM app_watering_log\n" +
            "WHERE user_id=#{userId} AND YEAR(create_time) = YEAR(CURDATE()) AND MONTH(create_time) = MONTH(CURDATE());")
    Long selectByMonCout(@Param("userId") Long userId);


    @Select("SELECT COUNT(id) \n" +
            "FROM app_watering_log \n" +
            "WHERE  user_id=#{userId} AND WEEK(create_time) = WEEK(CURDATE());")
    Long selectByWeekCount(@Param("userId") Long userId);




    @Select("SELECT COUNT(id) \n" +
            "FROM app_watering_log \n" +
            "WHERE user_id=#{userId} AND trigger_type =#{triggerType}")
    Long selectByTriggerTypeCount(@Param("userId") Long userId, @Param("triggerType") String triggerType);

    @Select("SELECT SUM(duration_min)\n" +
            "FROM app_watering_log \n" +
            "WHERE user_id=#{userId}")
    Long selectByTotalWateringTime(@Param("userId") Long userId);
}
