EduSendMsgJob.java
4.1 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
package com.skua.modules.edu.job;
import com.skua.core.util.DateUtils;
import com.skua.modules.edu.entity.Paper;
import com.skua.modules.edu.service.IPaperService;
import com.skua.modules.system.service.ISysUserService;
import com.skua.modules.system.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 发送消息任务
* (2)、考试开始时间前1天推送一次
* (3)、考试结束时间前1天推送一次(如果还未完成的话)
*/
@Slf4j
@Component
public class EduSendMsgJob implements Job {
@Autowired
private ISysUserService userService;
@Autowired
private IPaperService paperService;
@Autowired
private SmsService smsService;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info(String.format(" Jeecg-Boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp()));
// 获取当前日期
LocalDate today = LocalDate.now();
// 获取昨天的日期
LocalDate yesterday = today.minusDays(1);
LocalDate tomorrowDay = today.plusDays(1);
// 创建一个DateTimeFormatter对象,指定格式为yyyy-MM-dd
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 使用formatter格式化LocalDate对象
String yesterDate = yesterday.format(formatter);
String tomorrowDate = tomorrowDay.format(formatter);
String messageTitle = null;
String messageBody = null;
String userIds = null;
String msgCategory = "12";
List<Paper> paperList = paperService.queryExamUserIds(yesterDate,null);
if(paperList != null && !paperList.isEmpty()){
for(Paper paper : paperList){
messageTitle = "考试任务:<"+paper.getPaperTitle() +">明天开始,请参加考试";
//messageBody = "明天考试任务:"+paper.getPaperTitle() +",请参加考试";
messageBody = "考试任务:<"+paper.getPaperTitle() +">明天开始,考试时间:"+paper.getStartTime() +"至"+paper.getEndTime()+",请准时参加考试";
userIds = getNoExamUserIds(paper.getExamUserIds(),paper.getUserIds());
if(StringUtils.isNotEmpty(userIds)){
//pushMsgNoProcess(messageTitle,messageBody,userIds);
smsService.pushMsgNoProcess( messageTitle , messageBody , userIds, "Paper", msgCategory,"H");
}
}
}
paperList = paperService.queryExamUserIds(null,tomorrowDate);
if(paperList != null && !paperList.isEmpty()){
for(Paper paper : paperList){
messageTitle = "考试任务:<"+paper.getPaperTitle() +">明天结束,请尽快考试";
//messageBody = "考试:"+paper.getPaperTitle() +"明天结束,请尽快参加考试";
messageBody = "考试任务:<"+paper.getPaperTitle() +">明天结束,考试时间:"+paper.getStartTime() +"至"+paper.getEndTime()+",请准时参加考试";
userIds = getNoExamUserIds(paper.getExamUserIds(),paper.getUserIds());
if(StringUtils.isNotEmpty(userIds)){
//pushMsgNoProcess(messageTitle,messageBody,userIds);
smsService.pushMsgNoProcess( messageTitle , messageBody , userIds, "Paper", msgCategory,"H");
}
}
}
}
/***
* 获取第一个字符串列表中存在而第二个字符串列表中不存在的元素
* @param string1
* @param string2
* @return
*/
private String getNoExamUserIds(String string1 , String string2){
// 分割字符串
String[] array1 = string1.split(",");
String[] array2 = string2.split(",");
// 将array2转换为Set集合
Set<String> set2 = new HashSet<>(Arrays.asList(array2));
// 获取在array1中但不在set2中的元素
String result = Arrays.stream(array1)
.filter(element -> !set2.contains(element))
.collect(Collectors.joining(","));
return result;
}
}