| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package com.xuekairui.user.mapper;
- import com.baomidou.mybatisplus.core.mapper.BaseMapper;
- import com.xuekairui.user.entity.CrawlerUsageLog;
- import org.apache.ibatis.annotations.Mapper;
- import org.apache.ibatis.annotations.Param;
- import org.apache.ibatis.annotations.Select;
- import java.util.List;
- import java.util.Map;
- /**
- * 爬虫使用记录数据访问层
- */
- @Mapper
- public interface CrawlerUsageLogMapper extends BaseMapper<CrawlerUsageLog> {
- /**
- * 统计用户今日已使用爬虫次数
- */
- @Select("SELECT COALESCE(SUM(usage_count), 0) FROM t_crawler_usage_log WHERE user_id = #{userId} AND usage_date = CURDATE()")
- int sumTodayUsage(@Param("userId") Long userId);
- /**
- * 统计用户本月已使用爬虫次数
- */
- @Select("SELECT COALESCE(SUM(usage_count), 0) FROM t_crawler_usage_log WHERE user_id = #{userId} AND YEAR(usage_date) = YEAR(CURDATE()) AND MONTH(usage_date) = MONTH(CURDATE())")
- int sumMonthlyUsage(@Param("userId") Long userId);
- /**
- * 统计用户本年已使用爬虫次数
- */
- @Select("SELECT COALESCE(SUM(usage_count), 0) FROM t_crawler_usage_log WHERE user_id = #{userId} AND YEAR(usage_date) = YEAR(CURDATE())")
- int sumYearlyUsage(@Param("userId") Long userId);
- /**
- * 统计用户各平台今日使用次数
- * @return List<Map<String, Object>> 包含 platform 和 today_usage
- */
- @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as today_usage " +
- "FROM t_crawler_usage_log " +
- "WHERE user_id = #{userId} AND usage_date = CURDATE() " +
- "GROUP BY platform")
- List<Map<String, Object>> sumTodayUsageByPlatform(@Param("userId") Long userId);
- /**
- * 统计用户各平台本月使用次数
- * @return List<Map<String, Object>> 包含 platform 和 monthly_usage
- */
- @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as monthly_usage " +
- "FROM t_crawler_usage_log " +
- "WHERE user_id = #{userId} AND YEAR(usage_date) = YEAR(CURDATE()) AND MONTH(usage_date) = MONTH(CURDATE()) " +
- "GROUP BY platform")
- List<Map<String, Object>> sumMonthlyUsageByPlatform(@Param("userId") Long userId);
- /**
- * 统计用户各平台总使用次数
- * @return List<Map<String, Object>> 包含 platform 和 total_usage
- */
- @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as total_usage " +
- "FROM t_crawler_usage_log " +
- "WHERE user_id = #{userId} " +
- "GROUP BY platform")
- List<Map<String, Object>> sumTotalUsageByPlatform(@Param("userId") Long userId);
- }
|