CrawlerUsageLogMapper.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.xuekairui.user.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.xuekairui.user.entity.CrawlerUsageLog;
  4. import org.apache.ibatis.annotations.Mapper;
  5. import org.apache.ibatis.annotations.Param;
  6. import org.apache.ibatis.annotations.Select;
  7. import java.util.List;
  8. import java.util.Map;
  9. /**
  10. * 爬虫使用记录数据访问层
  11. */
  12. @Mapper
  13. public interface CrawlerUsageLogMapper extends BaseMapper<CrawlerUsageLog> {
  14. /**
  15. * 统计用户今日已使用爬虫次数
  16. */
  17. @Select("SELECT COALESCE(SUM(usage_count), 0) FROM t_crawler_usage_log WHERE user_id = #{userId} AND usage_date = CURDATE()")
  18. int sumTodayUsage(@Param("userId") Long userId);
  19. /**
  20. * 统计用户本月已使用爬虫次数
  21. */
  22. @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())")
  23. int sumMonthlyUsage(@Param("userId") Long userId);
  24. /**
  25. * 统计用户本年已使用爬虫次数
  26. */
  27. @Select("SELECT COALESCE(SUM(usage_count), 0) FROM t_crawler_usage_log WHERE user_id = #{userId} AND YEAR(usage_date) = YEAR(CURDATE())")
  28. int sumYearlyUsage(@Param("userId") Long userId);
  29. /**
  30. * 统计用户各平台今日使用次数
  31. * @return List<Map<String, Object>> 包含 platform 和 today_usage
  32. */
  33. @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as today_usage " +
  34. "FROM t_crawler_usage_log " +
  35. "WHERE user_id = #{userId} AND usage_date = CURDATE() " +
  36. "GROUP BY platform")
  37. List<Map<String, Object>> sumTodayUsageByPlatform(@Param("userId") Long userId);
  38. /**
  39. * 统计用户各平台本月使用次数
  40. * @return List<Map<String, Object>> 包含 platform 和 monthly_usage
  41. */
  42. @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as monthly_usage " +
  43. "FROM t_crawler_usage_log " +
  44. "WHERE user_id = #{userId} AND YEAR(usage_date) = YEAR(CURDATE()) AND MONTH(usage_date) = MONTH(CURDATE()) " +
  45. "GROUP BY platform")
  46. List<Map<String, Object>> sumMonthlyUsageByPlatform(@Param("userId") Long userId);
  47. /**
  48. * 统计用户各平台总使用次数
  49. * @return List<Map<String, Object>> 包含 platform 和 total_usage
  50. */
  51. @Select("SELECT platform, COALESCE(SUM(usage_count), 0) as total_usage " +
  52. "FROM t_crawler_usage_log " +
  53. "WHERE user_id = #{userId} " +
  54. "GROUP BY platform")
  55. List<Map<String, Object>> sumTotalUsageByPlatform(@Param("userId") Long userId);
  56. }