ClassDictServiceImpl.java
12.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
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
package com.subsidy.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.ResponseData;
import com.subsidy.common.constant.CourseNotification;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.classDict.AddClassDTO;
import com.subsidy.dto.classDict.AddMemberToClassDTO;
import com.subsidy.dto.classDict.GetClassBaseInfoDTO;
import com.subsidy.dto.classDict.GetSpareMembersDTO;
import com.subsidy.jobs.CourseNotificationJob;
import com.subsidy.mapper.AnsweringQuestionMapper;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ClassMemberMappingMapper;
import com.subsidy.mapper.ClassNoticeMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.AnsweringQuestionDO;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassMemberMappingDO;
import com.subsidy.model.ClassNoticeDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.FieldDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.service.ClassDictService;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.QuartzUtil;
import com.subsidy.util.SMSUtils;
import com.subsidy.util.websocket.WebSocketUtil;
import com.subsidy.vo.classdict.ClassSettingsVO;
import com.subsidy.vo.classdict.GetAllClassesVO;
import com.subsidy.vo.classdict.GetClassBaseInfoVO;
import com.subsidy.vo.classdict.SystemSettings;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 班级id 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-12
*/
@Service
public class ClassDictServiceImpl extends ServiceImpl<ClassDictMapper, ClassDictDO> implements ClassDictService {
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private CourseDictMapper courseDictMapper;
@Autowired
private CompanyDictMapper companyDictMapper;
@Autowired
private ClassNoticeMapper classNoticeMapper;
@Autowired
private AnsweringQuestionMapper answeringQuestionMapper;
@Autowired
private QuartzUtil quartzUtil;
@Autowired
private VodDictMapper vodDictMapper;
@Autowired
private VodPlayHistoryMapper vodPlayHistoryMapper;
public List<GetAllClassesVO> getAllClasses(ClassDictDO classDictDO) throws Exception {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
List<GetAllClassesVO> getAllClassesVOS = this.baseMapper.getAllClasses(classDictDO);
for (GetAllClassesVO getAllClassesVO : getAllClassesVOS) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(fmt.parse(getAllClassesVO.getEndDate()));
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
if (new Date().before(fmt.parse(getAllClassesVO.getStartDate()))) {
getAllClassesVO.setOpenStatus("1"); //待开始
} else if (new Date().after(calendar.getTime())) {
getAllClassesVO.setOpenStatus("2");
} else {
getAllClassesVO.setOpenStatus("0");
}
}
return getAllClassesVOS;
}
@Transactional
public String deleteClasses(ClassDictDO classDictDO) {
this.baseMapper.deleteById(classDictDO.getId());
classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classDictDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public Long addClass(AddClassDTO addClassDTO) {
//新建一个班级
ClassDictDO classDictDO = new ClassDictDO();
BeanUtils.copyProperties(addClassDTO, classDictDO);
this.baseMapper.insert(classDictDO);
//班级里添加成员
List<Long> memberIds = addClassDTO.getMemberIds();
for (Long lg : memberIds) {
ClassMemberMappingDO classMemberMappingDO = new ClassMemberMappingDO();
classMemberMappingDO.setMemberId(lg);
classMemberMappingDO.setClassId(classDictDO.getId());
classMemberMappingMapper.insert(classMemberMappingDO);
}
//添加通知
if (null != addClassDTO.getClassNoticeDOS()) {
List<ClassNoticeDO> classNoticeDOS = addClassDTO.getClassNoticeDOS();
for (ClassNoticeDO classNoticeDO : classNoticeDOS) {
if (DateFormatUtil.parse(classNoticeDO.getNoticeTime(), "yyyy-MM-dd HH").before(new Date())) {
throw new HttpException(70001);
}
classNoticeDO.setClassId(classDictDO.getId());
classNoticeDO.setStatus(CourseNotification.UNSENT);
classNoticeMapper.insert(classNoticeDO);
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 HH:mm:ss"), params, name, "CourseNotificationJob");
}
}
return classDictDO.getId();
}
public String updateClass(ClassDictDO classDictDO) {
this.baseMapper.updateById(classDictDO);
//班级所在公司
SystemSettings systemSettings = this.baseMapper.getCompanySettings(classDictDO.getId());
List<ClassMemberMappingDO> list = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classDictDO.getId()));
if(CollectionUtils.isNotEmpty(list)) {
for (ClassMemberMappingDO classMemberMappingDO : list) {
WebSocketSession webSocketSession = WebSocketUtil.webSocketMap.get(classMemberMappingDO.getMemberId());
if(null != webSocketSession && webSocketSession.isOpen()) {
try {
//班级的配置
List<ClassSettingsVO> classSettings = this.baseMapper.getClassSettings(classMemberMappingDO.getMemberId());
systemSettings.setClassSettingsVOS(classSettings);
String data = JSONObject.toJSONString(ResponseData.generateCreatedResponse(0, systemSettings), SerializerFeature.WriteMapNullValue);
webSocketSession.sendMessage(new TextMessage(data));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return ConstantUtils.SET_SUCCESS;
}
public ClassDictDO classDetail(ClassDictDO classDictDO) {
return this.baseMapper.selectById(classDictDO.getId());
}
public String removeMember(ClassMemberMappingDO classMemberMappingDO) {
classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classMemberMappingDO.getClassId())
.eq(ClassMemberMappingDO::getMemberId, classMemberMappingDO.getMemberId()));
//签到记录
//做题记录
//答疑记录也删除
answeringQuestionMapper.delete(new QueryWrapper<AnsweringQuestionDO>()
.lambda()
.eq(AnsweringQuestionDO::getAskId, classMemberMappingDO.getMemberId())
.eq(AnsweringQuestionDO::getClassId, classMemberMappingDO.getClassId()));
return ConstantUtils.DELETE_SUCCESS;
}
public List<MemberDO> getSpareMembers(GetSpareMembersDTO getSpareMembersDTO) {
return this.baseMapper.getSpareMembers(getSpareMembersDTO);
}
public String addMemberToClass(AddMemberToClassDTO addMemberToClassDTO) {
List<Long> memberIds = addMemberToClassDTO.getMemberIds();
for (Long lg : memberIds) {
ClassMemberMappingDO classMemberMappingDO = new ClassMemberMappingDO();
classMemberMappingDO.setClassId(addMemberToClassDTO.getClassId());
classMemberMappingDO.setMemberId(lg);
classMemberMappingMapper.insert(classMemberMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
public String batchSms(ClassDictDO classDictDO) {
ClassDictDO classDictDO1 = this.baseMapper.selectById(classDictDO.getId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO1.getCourseId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO1.getCompanyId());
//查找这个班级里的学员的手机号
List<MemberDO> memberDOS = this.baseMapper.classMembers(classDictDO.getId());
StringBuilder telephone = new StringBuilder();
String param = "{\"company\":\"" + companyDictDO.getCompanyName() + "\",\"course\":\"" + courseDictDO.getCourseName() + "\",\"startDate\":\"" + classDictDO1.getStartDate() + "\",\"endDate\":\"" + classDictDO1.getEndDate() + "\"}";
if (memberDOS.size() > 0) {
for (int i = 0; i < memberDOS.size(); i++) {
telephone.append(memberDOS.get(i).getTelephone());
if (i != memberDOS.size() - 1) {
telephone.append(",");
}
}
SMSUtils.sendNoticeSMS("SMS_228137810", telephone.toString(), param);
}
return ConstantUtils.SUCCESS_SEND_OUT;
}
public GetClassBaseInfoVO getClassBaseInfo(GetClassBaseInfoDTO getClassBaseInfoDTO) {
GetClassBaseInfoVO getClassBaseInfoVO = this.baseMapper.getClassBaseInfo(getClassBaseInfoDTO.getId());
//查看课程完成状态
//查看某个课程都有哪些视频
List<VodDictDO> vodDictDOS = vodDictMapper.getCourseVods(getClassBaseInfoVO.getCourseId(),null);
int completeNum = 0 ;
//查看每个视频的状态
for (VodDictDO vodDictDO : vodDictDOS){
int i = vodPlayHistoryMapper.completeVodOrNot(getClassBaseInfoDTO.getUserId(),vodDictDO.getId(),getClassBaseInfoDTO.getId());
completeNum += i;
}
if (completeNum == vodDictDOS.size()){
getClassBaseInfoVO.setTestFlag(true);
}else {
getClassBaseInfoVO.setTestFlag(false);
}
return getClassBaseInfoVO;
}
public String email(ClassMemberMappingDO classMemberMappingDO){
ClassMemberMappingDO classMemberMappingDO1 = classMemberMappingMapper.selectOne(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getMemberId,classMemberMappingDO.getMemberId())
.eq(ClassMemberMappingDO::getClassId,classMemberMappingDO.getClassId()));
if (null != classMemberMappingDO1){
classMemberMappingDO1.setEmail(classMemberMappingDO.getEmail());
classMemberMappingDO1.setEmailStatus(classMemberMappingDO.getEmailStatus());
classMemberMappingMapper.updateById(classMemberMappingDO1);
}
return ConstantUtils.SUCCESS_UPDATE;
}
}