Blame view

SchedulerJob.java 5.51 KB
邓敏 committed
1 2
package com.subsidy.jobs;

3 4
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.RedisPrefixConstant;
邓敏 committed
5 6
import com.subsidy.mapper.OprAdmDictMapper;
import com.subsidy.mapper.OprMemDictMapper;
7
import com.subsidy.mapper.SignInRecordMapper;
邓敏 committed
8
import com.subsidy.mapper.VodPlayHistoryMapper;
涂亚平 committed
9
import com.subsidy.model.OprAdmDictDO;
10 11
import com.subsidy.model.SignInRecordDO;
import com.subsidy.util.DateFormatUtil;
邓敏 committed
12 13
import com.subsidy.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.data.mongodb.core.MongoTemplate;
15
import org.springframework.scheduling.annotation.Scheduled;
邓敏 committed
16
import org.springframework.stereotype.Component;
17
import org.springframework.transaction.annotation.Transactional;
18

19 20
import java.util.ArrayList;
import java.util.Date;
邓敏 committed
21
import java.util.List;
22
import java.util.Set;
邓敏 committed
23 24 25 26 27 28 29 30 31 32 33

/**
 * <p>
 *  定时器
 * </p>
 *
 * @author DengMin
 * @since 2021/12/21
 */

@Component
邓敏 committed
34
public class SchedulerJob {
邓敏 committed
35 36 37 38 39 40 41 42 43 44 45

    @Autowired
    private OprAdmDictMapper oprAdmDictMapper;

    @Autowired
    private OprMemDictMapper oprMemDictMapper;

    @Autowired
    private VodPlayHistoryMapper vodPlayHistoryMapper;

    @Autowired
46 47 48
    private SignInRecordMapper signInRecordMapper;

    @Autowired
邓敏 committed
49 50
    private RedisUtil redisUtil;

51 52
    @Autowired
    private MongoTemplate mongoTemplate;
邓敏 committed
53 54 55
    /**
        删除十天前登录记录(管理端)
     */
涂亚平 committed
56
    //@Scheduled(cron = "0 42 18 * * ?")
邓敏 committed
57 58 59 60
    public void delOprAdmRecord() {
        List<OprAdmDictDO> list = oprAdmDictMapper.getRecordByDate();
        if(list != null) {
            for (OprAdmDictDO oprAdmDictDO : list) {
61
                //oprAdmDictMapper.deleteById(oprAdmDictDO.getId());
邓敏 committed
62 63 64 65
            }
        }
    }

66 67 68 69 70 71 72 73 74 75 76 77
    ///**
    // * 删除十天前登录记录(学员)
    // */
    ////@Scheduled(cron = "0 42 18 * * ?")
    //public void delOprMemRecord() {
    //    List<OprMemDictDO> list = oprMemDictMapper.getRecordByDate();
    //    if(list != null) {
    //        for (OprMemDictDO oprMemDictDO : list) {
    //            oprMemDictMapper.deleteById(oprMemDictDO.getId());
    //        }
    //    }
    //}
邓敏 committed
78

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    ///**
    // * 用户数据审计记录添加(学员)
    // */
    ////@Scheduled(cron = "0 39 18 * * ?")
    //public void getOprMemRecord() {
    //    Set<String> set = redisUtil.scan("*memberLogin*");
    //    if(set != null) {
    //        for (String str : set) {
    //            int result = (Integer) redisUtil.get(str);
    //            OprMemDictDO oprMemDictDO = new OprMemDictDO();
    //            String [] opr = str.split("_");
    //            LocalDateTime createDate = DateFormatUtil.secondToLocalDateTime(Long.valueOf(opr[3]));
    //            oprMemDictDO.setResult(result);
    //            oprMemDictDO.setOprType("登录");
    //            oprMemDictDO.setUserId(Long.valueOf(opr[2]));
    //            oprMemDictDO.setCreateDate(createDate);
    //            oprMemDictMapper.insert(oprMemDictDO);
    //            redisUtil.del(str);
    //        }
    //    }
    //}
邓敏 committed
100 101 102 103

    /**
     * 视频播放记录缩量
     */
涂亚平 committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117
//    @Scheduled(cron = "0 48 14 * * ?")
//    @Transactional(rollbackFor = Exception.class)
//    public void condenseVodPlayHistory() {
//        List<VodPlayHistoryDO> list = vodPlayHistoryMapper.getVodPlayHistory();
//        vodPlayHistoryMapper.delete(null);
//        //List<VodPlayHistoryDO> vodPlayHistoryList = vodPlayHistoryMapper.selectList(null);
//        //for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryList) {
//            vodPlayHistoryMapper.deleteById(null);
//        //}
//
//        for (VodPlayHistoryDO vodPlayHistoryDO : list) {
//            vodPlayHistoryMapper.insert(vodPlayHistoryDO);
//        }
//    }
118

119 120 121 122 123 124 125 126 127 128
    /**
     * 定时同步Redis签到数据
     * 1天前的
     * 增量版
     */
    @Transactional(rollbackFor = Exception.class)
    public void synchronizeSignInRecord() {
        List<SignInRecordDO> list = signInRecordMapper.getSignInRecord();
        if(list != null && list.size() > 0) {
            for (SignInRecordDO signInRecordDO : list) {
涂亚平 committed
129 130 131 132
                Set<String> set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + signInRecordDO.getMemberId() + ":classId:" + signInRecordDO.getClassId() + ":" + DateFormatUtil.format(signInRecordDO.getSignInDate(), "yyyy-MM-dd")+":*");
                if(set != null && set.size() > 0) {
                    redisUtil.del(set);
                }
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
                redisUtil.set(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + signInRecordDO.getMemberId() + ":classId:" + signInRecordDO.getClassId() + ":" + DateFormatUtil.format(signInRecordDO.getSignInDate(), "yyyy-MM-dd") + ":" + DateFormatUtil.LocalDateTimeToSecond(signInRecordDO.getSignInDate()), null);
            }
        }
    }

    /**
     * 全部同步Redis签到数据
     */
    @Transactional(rollbackFor = Exception.class)
    public void synchronizeSignInRecordAll() {
        Set<String> set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX+"*");
        if(set != null && set.size() > 0) {
            redisUtil.del(set);
        }

        List<SignInRecordDO> list = signInRecordMapper.selectList(new QueryWrapper<>());
        for (SignInRecordDO signInRecordDO : list) {
            redisUtil.set(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + signInRecordDO.getMemberId() + ":classId:" + signInRecordDO.getClassId() + ":" + DateFormatUtil.format(signInRecordDO.getSignInDate(), "yyyy-MM-dd") + ":" + DateFormatUtil.LocalDateTimeToSecond(signInRecordDO.getSignInDate()), null);
        }

    }
邓敏 committed
154
}