package com.fs.app.task;

import com.fs.common.core.redis.RedisCache;
import com.fs.course.mapper.FsCourseWatchLogMapper;
import com.fs.course.service.IFsCourseWatchLogService;
import com.fs.store.service.IFsUserCourseCountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserCourseWatchCountTask {

    @Autowired
    private FsCourseWatchLogMapper courseWatchLogMapper;

    @Autowired
    RedisCache redisCache;

    @Autowired
    private IFsCourseWatchLogService courseWatchLogService;

    @Autowired
    private IFsUserCourseCountService userCourseCountService;


    /**
     * 每天两点进行会员看课统计
     */
    @Scheduled(cron = "0 0 2 * * ?")  // 2点0分0秒执行
    public void userCourseCountTask() {
        try {
            log.info("==============会员看课统计任务执行===============开始");
            long startTime = System.currentTimeMillis();

            userCourseCountService.insertFsUserCourseCountTask();

            log.info("会员看课统计任务执行==============结束");
            long endTime = System.currentTimeMillis();
            log.info("会员看课统计任务执行----------执行时长：{}", (endTime - startTime));
        } catch (Exception e) {
            log.error("会员看课统计任务执行----------定时任务执行失败", e);
        }

    }


}
