RenSheJuJob.java
12.2 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.subsidy.jobs;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.ResponseData;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.RenSheJuService;
import com.subsidy.util.IpAddressUtil;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.opr.InsertLastStudyRecordVO;
import com.subsidy.vo.renshe.DailyAnswerVO;
import com.subsidy.vo.vod.DailyClassMembersVO;
import com.subsidy.vo.vod.VodPlayStateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/**
* 企业职工线上培训
*/
@Component
public class RenSheJuJob {
@Autowired
private RenSheJuService renSheJuService;
@Autowired
private OprMemDictMapper oprMemDictMapper;
@Autowired
private ImageCheckRecordMapper imageCheckRecordMapper;
@Autowired
private ActivityDetectionMapper activityDetectionMapper;
@Autowired
private VodPlayHistoryMapper vodPlayHistoryMapper;
@Autowired
private SignInRecordMapper signInRecordMapper;
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private VodDictMapper vodDictMapper;
@Value("${spring.profiles.active}")
private String env;
/**
// * POST-2:班级基本信息信息采集接口
// */
@Scheduled(cron = "0 0 1 * * ?")
public void classBaseInfo() throws IOException {
if ("prod".equals(env)) {
renSheJuService.classBaseInfo();
}
}
/**
* POST-3:学时信息采集接口
*/
@Scheduled(cron = "0 5 1 * * ?")
public void classHourBehavior() throws IOException {
if ("prod".equals(env)) {
renSheJuService.classHourBehavior();
}
}
/**
* POST-4:考试信息采集接口
*/
@Scheduled(cron = "0 10 1 * * ?")
public void uploadChapterBehavior() throws IOException {
if ("prod".equals(env)) {
renSheJuService.uploadChapterBehavior();
}
}
/**
* POST-5:答疑辅导采集接口
*/
@Scheduled(cron = "0 15 1 * * ?")
public void uploadClassAnswerQuestionBehavior() throws IOException {
if ("prod".equals(env)) {
renSheJuService.uploadClassAnswerQuestionBehavior();
}
}
/**
* POST-6 班级活跃度/实名认证照片信息采集接口
*/
@Scheduled(cron = "0 20 1 * * ?")
public void uploadImage() throws IOException {
if ("prod".equals(env)) {
renSheJuService.uploadImage();
}
}
/**
* POST-7 获取培训待绑定的(班级编号,项目编号)列表
*/
@Scheduled(cron = "0 25 1 * * ?")
public void getClassCodeByPrivateKey() throws IOException {
if ("prod".equals(env)) {
renSheJuService.getClassCodeByPrivateKey();
}
}
/**
* POST-8 上下游班级数据绑定接口
*/
@Scheduled(cron = "0 30 1 * * ?")
public void uploadClassCode() throws IOException {
if ("prod".equals(env)) {
renSheJuService.uploadClassCode();
}
System.gc();
}
// /**
// * POST-9 获取推送失败班级列表
// */
// @Scheduled(cron = "0 35 1 * * ?")
// public void getErrorClass()throws IOException{
// renSheJuService.getErrorClass();
// }
// /**
// * 定时gc
// */
// @Scheduled(cron = "0 10 16 * * ?")
// public void gc(){
// Runtime.getRuntime().gc();
// }
/**
* 强制用户用户下线(websocket强制下线)
*/
@Scheduled(cron = "0 00 23 * * ?")
@Transactional(rollbackFor = Exception.class)
public void logout() {
//让当前用户下线
ConcurrentHashMap<Long, WebSocketSession> webSocketMap = WebSocketUtil.webSocketMap;
//查看当天登录过的人最后一次活跃数据
List<InsertLastStudyRecordVO> insertLastStudyRecordVOS = oprMemDictMapper.insertLastStudyRecord();
for (InsertLastStudyRecordVO ilsr : insertLastStudyRecordVOS) {
try {
if (null != webSocketMap.get(ilsr.getMemberId())) {
webSocketMap.get(ilsr.getMemberId()).sendMessage(new TextMessage(JSONObject.toJSONString(ResponseData.generateCreatedResponse(17001))));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 补当天有学习记录但没有签到的签到数据
*/
@Scheduled(cron = "0 10 23 * * ?")
@Transactional(rollbackFor = Exception.class)
public void fillSignInRecord(){
//查找有视频的学生
List<DailyClassMembersVO> dailyClassMembersVOS = vodPlayHistoryMapper.dailyClassMembers();
for (DailyClassMembersVO dailyClassMembersVO : dailyClassMembersVOS){
try {
//去看签到表当天有没有数据,没有的话就要补
SignInRecordDO dailySignInRecord = signInRecordMapper.getDailySignInRecord(dailyClassMembersVO.getMemberId(), dailyClassMembersVO.getClassId());
if (null == dailySignInRecord){
//没有签到数据,补
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.exPlayInfoAsc(dailyClassMembersVO.getMemberId(), dailyClassMembersVO.getClassId());
List<SignInRecordDO> signInRecordDOS = signInRecordMapper.selectList(new QueryWrapper<SignInRecordDO>()
.lambda()
.eq(SignInRecordDO::getMemberId,dailyClassMembersVO.getMemberId())
.eq(SignInRecordDO::getClassId,dailyClassMembersVO.getClassId())
.orderByDesc(SignInRecordDO::getSignInDate));
SignInRecordDO signInRecordDO = signInRecordDOS.get(0);
LocalDateTime localDateTime = vodPlayHistoryDOS.get(0).getCreateDate()
.minusSeconds(vodPlayHistoryDOS.get(0).getPlayLength())
.minusSeconds(vodPlayHistoryDOS.get(0).getSuspendLength())
.minusSeconds(random0to9());
signInRecordMapper.insertRecord(dailyClassMembersVO.getClassId(),dailyClassMembersVO.getMemberId(),localDateTime,signInRecordDO.getIpAddress(),signInRecordDO.getDeviceNo(),localDateTime);
}
}catch (Exception e){
e.printStackTrace();
}
}
}
@Scheduled(cron = "0 15 23 * * ?")
public void clearErrorData(){
//查看当天产生视频学习的班级
List<Long> classIds = vodPlayHistoryMapper.dailyVodRecord();
HashMap<Long, HashSet<Long>> hashMap = new HashMap();
for (Long classId : classIds) {
List<ClassMemberMappingDO> classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classId));
HashSet<Long> memberIds = new HashSet<>();
for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) {
List<VodPlayStateVO> vodPlayStateVOS = vodDictMapper.testPlays(classMemberMappingDO.getMemberId(), Long.valueOf(classId));
for (int i = 0; i < vodPlayStateVOS.size() - 1; i++) {
VodPlayStateVO vodPlayStateVO = vodPlayStateVOS.get(i + 1); //后面
VodPlayStateVO vodPlayStateVO1 = vodPlayStateVOS.get(i); //前面
if (vodPlayStateVO1.getEndDate().getTime() > vodPlayStateVO.getStartDate().getTime()) {
memberIds.add(vodPlayStateVO.getMemberId());
}
}
}
hashMap.put(classId, memberIds);
}
for (Long clsId : hashMap.keySet()) {
HashSet<Long> memberIds = hashMap.get(clsId);
for (Long memberId : memberIds) {
//查看这个人这个班当天的签到时间
SignInRecordDO signInRecordDO = signInRecordMapper.getDailySignInRecord(memberId, clsId);
if (null != signInRecordDO) {
LocalDateTime signInDate = signInRecordDO.getSignInDate();
//查看这个人当天的学习数据
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.exPlayInfoAsc(memberId, clsId);
//从签到时间开始依次“展开”数据
int currentLength = 0;
for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryDOS) {
currentLength += random0to9() + vodPlayHistoryDO.getPlayLength() + vodPlayHistoryDO.getSuspendLength();
LocalDateTime newCreateDate = signInDate.plusSeconds(currentLength);
vodPlayHistoryMapper.updatePlayRecord(vodPlayHistoryDO.getId(), newCreateDate);
}
}
}
}
}
/**
* 随机0-9秒
*/
public int random0to9() {
return (int) (Math.random() * 10+3);
}
/**
* 删掉有登录数据 做过人脸 没有学习数据(视频+考试+答疑)
*/
@Scheduled(cron = "0 35 23 * * ?")
@Transactional(rollbackFor = Exception.class)
public void deleteNoStudyMembers() {
//查看登陆过做过人脸,但是没视频记录的人
List<ImageCheckRecordDO> vodHistoryMembers = imageCheckRecordMapper.noVodHistoryMembers();
vodHistoryMembers.stream().forEach(x -> {
imageCheckRecordMapper.deleteById(x.getId());
ActivityDetectionDO activityDetectionDO = activityDetectionMapper.selectOne(new QueryWrapper<ActivityDetectionDO>()
.lambda()
.eq(ActivityDetectionDO::getFaceCheckId, x.getId()));
if (null != activityDetectionDO) {
activityDetectionMapper.deleteById(activityDetectionDO.getId());
}
});
//查看登陆过做过人脸,但是没考试记录的人
List<ImageCheckRecordDO> examHistoryMembers = imageCheckRecordMapper.noExamHistoryMembers();
examHistoryMembers.stream().forEach(x -> {
imageCheckRecordMapper.deleteById(x.getId());
ActivityDetectionDO activityDetectionDO = activityDetectionMapper.selectOne(new QueryWrapper<ActivityDetectionDO>()
.lambda()
.eq(ActivityDetectionDO::getFaceCheckId, x.getId()));
if (null != activityDetectionDO) {
activityDetectionMapper.deleteById(activityDetectionDO.getId());
}
});
}
/**
* 补登录登出数据
*/
@Scheduled(cron = "0 40 23 * * ?")
@Transactional(rollbackFor = Exception.class)
public void cancelLogin() {
//让当前用户下线
// ConcurrentHashMap<Long, WebSocketSession> webSocketMap = WebSocketUtil.webSocketMap;
//查看当天登录过的人最后一次活跃数据
List<InsertLastStudyRecordVO> insertLastStudyRecordVOS = oprMemDictMapper.insertLastStudyRecord();
for (InsertLastStudyRecordVO ilsr : insertLastStudyRecordVOS) {
oprMemDictMapper.insertOrUpdate(ilsr.getMemberId(), "登录", 1, ilsr.getIpAddress(), ilsr.getSignInDate());
if (null == ilsr.getMt()) {
//补23:58的数据
oprMemDictMapper.insertOrUpdate(ilsr.getMemberId(), "登出", 1, null, new Date());
} else {
//最后一次学习的数据
oprMemDictMapper.insertOrUpdate(ilsr.getMemberId(), "登出", 1, null, ilsr.getMt());
}
}
}
}