SignStatisticsDataScheduler.java 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.cyksj.task;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.cyksj.common.constant.Constant;
  6. import com.cyksj.common.constant.PointsRecordConst;
  7. import com.cyksj.mapper.manage.statistics.SignStatisticsDataMapper;
  8. import com.cyksj.mapper.market.sign.SignUserMapper;
  9. import com.cyksj.mapper.market.sign.UserPointsRecordMapper;
  10. import com.cyksj.model.entity.SignStatisticsData;
  11. import com.cyksj.model.entity.SignUser;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.scheduling.annotation.Scheduled;
  15. import org.springframework.stereotype.Component;
  16. import java.util.Date;
  17. /*
  18. *项目名: netflix
  19. *文件名: SignStatisticsDataScheduler
  20. *创建者: JavaZou
  21. *创建时间:2022/12/27 18:27
  22. */
  23. @Component
  24. @Slf4j
  25. @RequiredArgsConstructor
  26. public class SignStatisticsDataScheduler {
  27. private final SignStatisticsDataMapper signStatisticsDataMapper;
  28. private final UserPointsRecordMapper userPointsRecordMapper;
  29. private final SignUserMapper signUserMapper;
  30. @Scheduled(cron = "0 0 0 * * ?")
  31. public void signStatisticsData() {
  32. Date thisZeroDate = DateUtil.beginOfDay(DateTime.now());
  33. Date yesZeroDate = DateTime.of(thisZeroDate.getTime() - Constant.DAY_MILLS);
  34. SignStatisticsData signStatisticsData = new SignStatisticsData();
  35. //今日签到人数
  36. Integer todayNumOfSign = signUserMapper.selectCount(Wrappers.lambdaQuery(SignUser.class)
  37. .between(SignUser::getUpdateTime, yesZeroDate, thisZeroDate));
  38. signStatisticsData.setTodayNumOfSign(todayNumOfSign);
  39. //今日发放积分
  40. Integer todayNumOfPoints = userPointsRecordMapper.getTodayNumOfPoints(yesZeroDate, thisZeroDate);
  41. signStatisticsData.setTodayNumOfPoints(todayNumOfPoints);
  42. //累计发放积分
  43. Integer sumOfPoints = userPointsRecordMapper.getSumOfPoints();
  44. signStatisticsData.setSumOfPoints(sumOfPoints);
  45. //今日使用积分
  46. Integer todayUseOfPoints = userPointsRecordMapper.getTodayUseOfPoints(yesZeroDate, thisZeroDate);
  47. signStatisticsData.setTodayUseOfPoints(todayUseOfPoints);
  48. //累计使用积分
  49. Integer sumUseOfPoints = userPointsRecordMapper.getSumUseOfPoints();
  50. signStatisticsData.setSumUseOfPoints(sumUseOfPoints);
  51. //今日抽奖次数
  52. Integer todayNumOfLottery = userPointsRecordMapper.getTodayNumOfLottery(PointsRecordConst.LOTTERY, yesZeroDate, thisZeroDate);
  53. signStatisticsData.setTodayNumOfLottery(todayNumOfLottery);
  54. //连签2天
  55. Integer sign2Day = userPointsRecordMapper.getSignDayByCondition(2, yesZeroDate, thisZeroDate);
  56. signStatisticsData.setT2(sign2Day);
  57. //连签3天
  58. Integer sign3Day = userPointsRecordMapper.getSignDayByCondition(3, yesZeroDate, thisZeroDate);
  59. signStatisticsData.setT3(sign3Day);
  60. //连签4天
  61. Integer sign4Day = userPointsRecordMapper.getSignDayByCondition(4, yesZeroDate, thisZeroDate);
  62. signStatisticsData.setT4(sign4Day);
  63. //连签5天
  64. Integer sign5Day = userPointsRecordMapper.getSignDayByCondition(5, yesZeroDate, thisZeroDate);
  65. signStatisticsData.setT5(sign5Day);
  66. //连签6天
  67. Integer sign6Day = userPointsRecordMapper.getSignDayByCondition(6, yesZeroDate, thisZeroDate);
  68. signStatisticsData.setT6(sign6Day);
  69. //连签7天
  70. Integer sign7Day = userPointsRecordMapper.getSignDayByCondition(7, yesZeroDate, thisZeroDate);
  71. signStatisticsData.setT7(sign7Day);
  72. signStatisticsData.setStatisticsDate(yesZeroDate);
  73. }
  74. }