package com.cyksj.task; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.cyksj.common.constant.Constant; import com.cyksj.common.constant.PointsRecordConst; import com.cyksj.mapper.manage.statistics.SignStatisticsDataMapper; import com.cyksj.mapper.market.sign.SignUserMapper; import com.cyksj.mapper.market.sign.UserPointsRecordMapper; import com.cyksj.model.entity.SignStatisticsData; import com.cyksj.model.entity.SignUser; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; /* *项目名: netflix *文件名: SignStatisticsDataScheduler *创建者: JavaZou *创建时间:2022/12/27 18:27 */ @Component @Slf4j @RequiredArgsConstructor public class SignStatisticsDataScheduler { private final SignStatisticsDataMapper signStatisticsDataMapper; private final UserPointsRecordMapper userPointsRecordMapper; private final SignUserMapper signUserMapper; @Scheduled(cron = "0 0 0 * * ?") public void signStatisticsData() { Date thisZeroDate = DateUtil.beginOfDay(DateTime.now()); Date yesZeroDate = DateTime.of(thisZeroDate.getTime() - Constant.DAY_MILLS); SignStatisticsData signStatisticsData = new SignStatisticsData(); //今日签到人数 Integer todayNumOfSign = signUserMapper.selectCount(Wrappers.lambdaQuery(SignUser.class) .between(SignUser::getUpdateTime, yesZeroDate, thisZeroDate)); signStatisticsData.setTodayNumOfSign(todayNumOfSign); //今日发放积分 Integer todayNumOfPoints = userPointsRecordMapper.getTodayNumOfPoints(yesZeroDate, thisZeroDate); signStatisticsData.setTodayNumOfPoints(todayNumOfPoints); //累计发放积分 Integer sumOfPoints = userPointsRecordMapper.getSumOfPoints(); signStatisticsData.setSumOfPoints(sumOfPoints); //今日使用积分 Integer todayUseOfPoints = userPointsRecordMapper.getTodayUseOfPoints(yesZeroDate, thisZeroDate); signStatisticsData.setTodayUseOfPoints(todayUseOfPoints); //累计使用积分 Integer sumUseOfPoints = userPointsRecordMapper.getSumUseOfPoints(); signStatisticsData.setSumUseOfPoints(sumUseOfPoints); //今日抽奖次数 Integer todayNumOfLottery = userPointsRecordMapper.getTodayNumOfLottery(PointsRecordConst.LOTTERY, yesZeroDate, thisZeroDate); signStatisticsData.setTodayNumOfLottery(todayNumOfLottery); //连签2天 Integer sign2Day = userPointsRecordMapper.getSignDayByCondition(2, yesZeroDate, thisZeroDate); signStatisticsData.setT2(sign2Day); //连签3天 Integer sign3Day = userPointsRecordMapper.getSignDayByCondition(3, yesZeroDate, thisZeroDate); signStatisticsData.setT3(sign3Day); //连签4天 Integer sign4Day = userPointsRecordMapper.getSignDayByCondition(4, yesZeroDate, thisZeroDate); signStatisticsData.setT4(sign4Day); //连签5天 Integer sign5Day = userPointsRecordMapper.getSignDayByCondition(5, yesZeroDate, thisZeroDate); signStatisticsData.setT5(sign5Day); //连签6天 Integer sign6Day = userPointsRecordMapper.getSignDayByCondition(6, yesZeroDate, thisZeroDate); signStatisticsData.setT6(sign6Day); //连签7天 Integer sign7Day = userPointsRecordMapper.getSignDayByCondition(7, yesZeroDate, thisZeroDate); signStatisticsData.setT7(sign7Day); signStatisticsData.setStatisticsDate(yesZeroDate); } }