CourseNotificationJob.java
3.24 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
package com.subsidy.jobs;
import com.subsidy.common.constant.CourseNotification;
import com.subsidy.common.constant.SmsCode;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ClassNoticeMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.model.ClassNoticeDO;
import com.subsidy.model.MemberDO;
import com.subsidy.util.SMSUtils;
import com.subsidy.vo.classdict.ClassAndCompanyInfoVO;
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.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 课程通知
* </p>
*
* @author DengMin
* @since 2022/2/14
*/
@Component
public class CourseNotificationJob implements Job {
@Autowired
private MemberMapper memberMapper;
@Autowired
private ClassNoticeMapper classNoticeMapper;
@Autowired
private ClassDictMapper classDictMapper;
@Override
public void execute(JobExecutionContext jobExecutionContext) {
Map<String, Object> map = jobExecutionContext.getJobDetail().getJobDataMap();
Map<String, Object> params = (Map<String, Object>) map.get("params");
if(params != null) {
ClassNoticeDO classNoticeDO = classNoticeMapper.selectById((Long) params.get("id"));
if(classNoticeDO != null) {
ClassAndCompanyInfoVO cmInfo = classDictMapper.getClassAndCompanyInfoVO((Long) params.get("classId"));
List<MemberDO> list = memberMapper.getMemberList((Long) params.get("classId"));
if(list != null && list.size() > 0) {
for (MemberDO memberDO : list) {
if(memberDO != null) {
String sms = "";
if(classNoticeDO.getNoticeType().equals(SmsCode.CLASS_START.getType())) {
sms = "{\"company\":\""+ cmInfo.getCompany() +"\", \"course\":\""+ cmInfo.getCourseName() +"\", \"startDate\": \""+ cmInfo.getStartDate()+"\", \"endDate\": \""+ cmInfo.getEndDate()+"\"}";
} else if(classNoticeDO.getNoticeType().equals(SmsCode.SIGN_IN.getType())) {
sms = "{ \"name\": \""+ cmInfo.getName() +"\", \"course\":\""+ cmInfo.getCourseName()+"\"}";
} else if(classNoticeDO.getNoticeType().equals(SmsCode.TEST.getType())) {
sms = "{ \"name\": \""+ cmInfo.getName() +"\", \"course\":\""+ cmInfo.getCourseName()+"\"}";
}
Map<String, String> data = Arrays.stream(SmsCode.values()).collect(Collectors.toMap(SmsCode::getType, SmsCode::getCode));
SMSUtils.sendNoticeSMS(data.get(classNoticeDO.getNoticeType()), memberDO.getTelephone(), sms);
}
}
}
ClassNoticeDO classNotice = new ClassNoticeDO();
classNotice.setId(classNoticeDO.getId());
classNotice.setStatus(CourseNotification.SENT);
classNoticeMapper.updateById(classNotice);
}
}
}
}