ClassNoticeServiceImpl.java
4.63 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
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.constant.CourseNotification;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.classNotice.SendNotificationDTO;
import com.subsidy.jobs.CourseNotificationJob;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassNoticeDO;
import com.subsidy.mapper.ClassNoticeMapper;
import com.subsidy.model.MemberDO;
import com.subsidy.service.ClassDictService;
import com.subsidy.service.ClassNoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.QuartzUtil;
import com.subsidy.util.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务实现类
* </p>
*
* @author DengMin
* @since 2022-01-21
*/
@Service
public class ClassNoticeServiceImpl extends ServiceImpl<ClassNoticeMapper, ClassNoticeDO> implements ClassNoticeService {
@Autowired
private QuartzUtil quartzUtil;
@Autowired
private ClassDictService classDictService;
@Autowired
private MemberMapper memberMapper;
@Autowired
private SMSUtils smsUtils;
@Transactional(rollbackFor = Exception.class)
@Override
public String addNotice(ClassNoticeDO classNoticeDO) {
if(DateFormatUtil.parse(classNoticeDO.getNoticeTime(),"yyyy-MM-dd").before(new Date())) {
throw new HttpException(70001);
}
classNoticeDO.setStatus(CourseNotification.UNSENT);
this.baseMapper.insert(classNoticeDO);
ClassDictDO classDictDO = classDictService.getById(classNoticeDO.getClassId());
Map<String, Object> params = new HashMap<>();
params.put("classId", classNoticeDO.getClassId());
params.put("id", classNoticeDO.getId());
String name = classDictDO.getClassName()+"-"+classNoticeDO.getNoticeType()+"-"+classNoticeDO.getNoticeTime();
quartzUtil.addSimpleJob(CourseNotificationJob.class,DateFormatUtil.parse(classNoticeDO.getNoticeTime(), "yyyy-MM-dd") , params, name, "CourseNotificationJob");
return ConstantUtils.ADD_SUCCESS;
}
public String updateNotice(ClassNoticeDO classNoticeDO) {
this.baseMapper.updateById(classNoticeDO);
return ConstantUtils.SET_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String deleteNotice(ClassNoticeDO classNoticeDO) {
ClassNoticeDO noticeDO = this.baseMapper.selectById(classNoticeDO.getId());
this.baseMapper.deleteById(classNoticeDO.getId());
ClassDictDO classDictDO = classDictService.getById(noticeDO.getClassId());
String name = classDictDO.getClassName()+"-"+noticeDO.getNoticeType()+"-"+noticeDO.getNoticeTime();
quartzUtil.deleteJob(name, "CourseNotificationJob");
return ConstantUtils.DELETE_SUCCESS;
}
public List<ClassNoticeDO> queryClassNotices(ClassNoticeDO classNoticeDO){
return this.baseMapper.selectList(new QueryWrapper<ClassNoticeDO>()
.lambda()
.eq(ClassNoticeDO::getStatus, classNoticeDO.getStatus())
.eq(ClassNoticeDO::getClassId,classNoticeDO.getClassId()));
}
@Override
public void sendNotification(SendNotificationDTO sendNotificationDTO) {
if(sendNotificationDTO.getSendType().equals(CourseNotification.ALL)) {
List<MemberDO> list = memberMapper.getMemberList(sendNotificationDTO.getClassId());
if(list != null) {
for (MemberDO memberDO : list) {
smsUtils.send(memberDO.getTelephone(), "");
}
}
} else if(sendNotificationDTO.getSendType().equals(CourseNotification.NOT_SIGNED_IN)) {
List<MemberDO> list = memberMapper.getMemberListBySignInRecord(sendNotificationDTO.getClassId());
if(list != null) {
for (MemberDO memberDO : list) {
smsUtils.send(memberDO.getTelephone(), "");
}
}
} else if(sendNotificationDTO.getSendType().equals(CourseNotification.UNFINISHED)) {
List<MemberDO> list = memberMapper.getUnfinishedMemberList(sendNotificationDTO.getClassId());
if(list != null) {
for (MemberDO memberDO : list) {
smsUtils.send(memberDO.getTelephone(), "");
}
}
}
}
}