SchedulerJob.java
5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.subsidy.jobs;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.RedisPrefixConstant;
import com.subsidy.mapper.OprAdmDictMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.mapper.SignInRecordMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.OprAdmDictDO;
import com.subsidy.model.SignInRecordDO;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* <p>
* 定时器
* </p>
*
* @author DengMin
* @since 2021/12/21
*/
@Component
public class SchedulerJob {
@Autowired
private OprAdmDictMapper oprAdmDictMapper;
@Autowired
private OprMemDictMapper oprMemDictMapper;
@Autowired
private VodPlayHistoryMapper vodPlayHistoryMapper;
@Autowired
private SignInRecordMapper signInRecordMapper;
@Autowired
private RedisUtil redisUtil;
@Autowired
private MongoTemplate mongoTemplate;
/**
删除十天前登录记录(管理端)
*/
//@Scheduled(cron = "0 42 18 * * ?")
public void delOprAdmRecord() {
List<OprAdmDictDO> list = oprAdmDictMapper.getRecordByDate();
if(list != null) {
for (OprAdmDictDO oprAdmDictDO : list) {
//oprAdmDictMapper.deleteById(oprAdmDictDO.getId());
}
}
}
///**
// * 删除十天前登录记录(学员)
// */
////@Scheduled(cron = "0 42 18 * * ?")
//public void delOprMemRecord() {
// List<OprMemDictDO> list = oprMemDictMapper.getRecordByDate();
// if(list != null) {
// for (OprMemDictDO oprMemDictDO : list) {
// oprMemDictMapper.deleteById(oprMemDictDO.getId());
// }
// }
//}
///**
// * 用户数据审计记录添加(学员)
// */
////@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);
// }
// }
//}
/**
* 视频播放记录缩量
*/
// @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);
// }
// }
/**
* 定时同步Redis签到数据
* 1天前的
* 增量版
*/
@Transactional(rollbackFor = Exception.class)
public void synchronizeSignInRecord() {
List<SignInRecordDO> list = signInRecordMapper.getSignInRecord();
if(list != null && list.size() > 0) {
for (SignInRecordDO signInRecordDO : list) {
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);
}
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);
}
}
}