RenSheJuJob.java
7.09 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
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.ActivityDetectionMapper;
import com.subsidy.mapper.ImageCheckRecordMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.model.ActivityDetectionDO;
import com.subsidy.model.ImageCheckRecordDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.service.RenSheJuService;
import com.subsidy.util.IpAddressUtil;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.opr.InsertLastStudyRecordVO;
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.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;
@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();
}
}
// /**
// * POST-9 获取推送失败班级列表
// */
// @Scheduled(cron = "0 35 1 * * ?")
// public void getErrorClass()throws IOException{
// renSheJuService.getErrorClass();
// }
/**
* 强制用户用户下线(websocket强制下线)
*/
@Scheduled(cron = "0 30 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 01 16 * * ?")
@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());
}
}
}
}