MemberServiceImpl.java
20.7 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
import com.subsidy.dto.member.AddMemberDTO;
import com.subsidy.dto.member.ContentMemberDTO;
import com.subsidy.dto.member.GetAllDTO;
import com.subsidy.dto.member.StudyHistoryDTO;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.MemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.MathUtil;
import com.subsidy.vo.administer.UserRoleVO;
import com.subsidy.vo.member.*;
import com.subsidy.vo.vod.StudyHistoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Member;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 学生表 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-11
*/
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> implements MemberService {
@Autowired
private SmsVerifyCodeMapper smsVerifyCodeMapper;
@Autowired
private CourseContentMapper courseContentMapper;
@Autowired
private VodPlayHistoryMapper vodPlayHistoryMapper;
@Autowired
private CourseDictMapper courseDictMapper;
@Autowired
private VodDictMapper vodDictMapper;
@Autowired
private FileDictMapper fileDictMapper;
@Autowired
private ExerciseDoneResultMapper exerciseDoneResultMapper;
@Autowired
private ExerciseDictMapper exerciseDictMapper;
@Autowired
private DepartmentDictMapper departmentDictMapper;
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private ClassDictMapper classDictMapper;
@Autowired
private CompanyDictMapper companyDictMapper;
@Autowired
private MemberDepartmentMappingMapper memberDepartmentMappingMapper;
public IPage<GetAllVO> getAll(GetAllDTO getAllDTO) {
Page pager = new Page(getAllDTO.getPageNum(), getAllDTO.getPageSize());
IPage iPage = this.baseMapper.getMembers(pager, getAllDTO.getDepartmentId(), getAllDTO.getUserName(), getAllDTO.getStatus());
List<GetAllVO> getAllVOS = iPage.getRecords();
for (GetAllVO getAllVO : getAllVOS) {
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.getDepartments(getAllVO.getId());
getAllVO.setDepartmentDictDOS(departmentDictDOS);
}
return iPage;
}
public String deleteMember(MemberDO memberDO) {
this.baseMapper.deleteById(memberDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
public String addMember(AddMemberDTO addMemberDTO) {
Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, addMemberDTO.getTelephone()));
if (count > 0) {
throw new HttpException(20002);
}
Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getAccountName, addMemberDTO.getAccountName())
.eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId()));
if (count1 > 0) {
throw new HttpException(20002);
}
MemberDO memberDO = new MemberDO();
BeanUtils.copyProperties(addMemberDTO, memberDO);
memberDO.setPassword("123456");
memberDO.setStatus("启用");
this.baseMapper.insert(memberDO);
//部门
List<Long> longs = addMemberDTO.getDepartmentIds();
for (Long lg : longs) {
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setMemberId(memberDO.getId());
memberDepartmentMappingDO.setDepartmentId(lg);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
public String updateMember(AddMemberDTO addMemberDTO) {
if (null!= addMemberDTO.getDepartmentIds()){
Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
.eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId())
.ne(MemberDO::getId, addMemberDTO.getId()));
if (count > 0) {
throw new HttpException(20002);
}
Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getAccountName, addMemberDTO.getAccountName())
.eq(MemberDO::getDepartmentId, addMemberDTO.getDepartmentId())
.ne(MemberDO::getId, addMemberDTO.getId()));
if (count1 > 0) {
throw new HttpException(20002);
}
}
MemberDO memberDO = new MemberDO();
BeanUtils.copyProperties(addMemberDTO, memberDO);
this.baseMapper.updateById(memberDO);
if (null != addMemberDTO.getDepartmentIds()){
memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
.lambda()
.eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId()));
//部门
List<Long> longs = addMemberDTO.getDepartmentIds();
for (Long lg : longs) {
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setMemberId(memberDO.getId());
memberDepartmentMappingDO.setDepartmentId(lg);
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
@Override
@Transactional(rollbackFor = Exception.class)
public UserRoleVO login(VerifyCodeDTO verifyCodeDTO) {
UserRoleVO userRoleVO = new UserRoleVO();
MemberDO userRoleDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, verifyCodeDTO.getTelephone()));
if (userRoleDO == null) {
throw new HttpException(10010);
}
if ("冻结".equals(userRoleDO.getStatus())){
throw new HttpException(10013);
}
BeanUtils.copyProperties(userRoleDO, userRoleVO);
SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
.lambda()
.eq(SmsVerifyCodeDO::getTelephone, verifyCodeDTO.getTelephone())
.eq(SmsVerifyCodeDO::getVerifyCode, verifyCodeDTO.getVerifyCode()));
if (smsCodeDO == null) {
throw new HttpException(70010);
}
return userRoleVO;
}
public UserRoleVO passwordLogin(MemberDO memberDO) {
UserRoleVO userRoleVO = new UserRoleVO();
MemberDO memberDO1 = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getPassword, memberDO.getPassword())
.eq(MemberDO::getAccountName, memberDO.getAccountName()));
if (memberDO1 == null) {
throw new HttpException(10004);
}
if ("冻结".equals(memberDO1.getStatus())){
throw new HttpException(10014);
}
BeanUtils.copyProperties(memberDO1, userRoleVO);
return userRoleVO;
}
public String updatePassword(MemberDO memberDO) {
this.baseMapper.updateById(memberDO);
return ConstantUtils.SET_SUCCESS;
}
public MemberStudyPageVO studyPage(MemberDO memberDO) {
MemberStudyPageVO memberStudyPageVO = new MemberStudyPageVO();
List<StudyPageVO> studyPageVOS = this.baseMapper.studyPage(memberDO);
for (StudyPageVO studyPageVO : studyPageVOS) {
//查看课程下有几节课
List<VodDictDO> vodDictDOS = courseContentMapper.getCourseVods(studyPageVO.getId());
studyPageVO.setTotalVods(vodDictDOS.size());
int i = 0;
//该成员完成了几个视频
for (VodDictDO vodDictDO : vodDictDOS) {
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getMemberId, memberDO.getId())
.eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())
.orderByDesc(VodPlayHistoryDO::getPlayRecord));
if (vodPlayHistoryDOS.size() > 0) {
if (vodPlayHistoryDOS.get(0).getPlayRecord() > vodDictDO.getVodLength() * 0.8) {
i++;
}
}
}
studyPageVO.setDoneVods(i);
//该班级课程下有多少人
List<ClassMemberMappingDO> classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, studyPageVO.getClassId()));
studyPageVO.setTotalMember(classMemberMappingDOS.size());
//多少人完成
int completedCnt = 0;
for (ClassMemberMappingDO cmmd : classMemberMappingDOS) {
Boolean flag = true;
for (VodDictDO vodDictDO : vodDictDOS) {
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())
.eq(VodPlayHistoryDO::getMemberId, cmmd.getMemberId())
.orderByDesc(VodPlayHistoryDO::getPlayRecord));
if (vodPlayHistoryDOS.size() > 0) {
if (vodPlayHistoryDOS.get(0).getPlayRecord() < vodDictDO.getVodLength()) {
flag = false;
//break;
}
} else {
flag = false;
}
}
if (flag) {
completedCnt++;
}
}
studyPageVO.setDoneMember(completedCnt);
}
memberStudyPageVO.setStudyPageVOS(studyPageVOS);
List<DepartmentDictDO> departmentDictDOS = this.baseMapper.getDepartments(memberDO.getId());
if (departmentDictDOS.size() > 0) {
CompanyDictDO companyDictDO = companyDictMapper.selectById(departmentDictDOS.get(0).getId());
if (null != companyDictDO) {
BeanUtils.copyProperties(companyDictDO, memberStudyPageVO);
}
}
return memberStudyPageVO;
}
public ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO) {
ContentVodNewVO contentVodNewVO = new ContentVodNewVO();
List<ContentVodVO> contentVodVOS = new ArrayList<>();
List<CourseContentDO> courseContentDOS = courseContentMapper.selectList(new QueryWrapper<CourseContentDO>()
.lambda()
.eq(CourseContentDO::getCourseId, contentVodDTO.getCourseId())
.orderByAsc(CourseContentDO::getOrderNo));
for (CourseContentDO courseContentDO : courseContentDOS) {
ContentVodVO contentVodVO = new ContentVodVO();
contentVodVO.setContent(courseContentDO.getContent());
List<MemberVodVO> memberVodVOS = new ArrayList<>();
//目录下的视频
List<VodDictDO> vodDictDOS = vodDictMapper.selectList(new QueryWrapper<VodDictDO>()
.lambda()
.eq(VodDictDO::getContentId, courseContentDO.getId()));
for (VodDictDO vodDictDO : vodDictDOS) {
MemberVodVO memberVodVO = new MemberVodVO();
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getMemberId, contentVodDTO.getMemberId())
.eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())
.orderByDesc(VodPlayHistoryDO::getPlayRecord));
memberVodVO.setStatus(false);
if (vodPlayHistoryDOS.size() > 0) {
memberVodVO.setPercent(MathUtil.intDivCeil(100 * vodPlayHistoryDOS.get(0).getPlayRecord(), vodDictDO.getVodLength()));
if (memberVodVO.getPercent() >= 80) {
memberVodVO.setStatus(true);
}
} else {
memberVodVO.setPercent(0);
}
List<VodPlayHistoryDO> vodPlayHistoryDOS1 = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getMemberId, contentVodDTO.getMemberId())
.eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())
.orderByDesc(VodPlayHistoryDO::getCreateDate));
if (vodPlayHistoryDOS1.size() > 0) {
memberVodVO.setPlayRecord(vodPlayHistoryDOS1.get(0).getPlayRecord());
}
memberVodVO.setId(vodDictDO.getId());
memberVodVO.setVodUrl(vodDictDO.getVodUrl());
memberVodVO.setTeacherName(vodDictDO.getTeacherName());
memberVodVO.setVodLength(vodDictDO.getVodLength());
memberVodVO.setVodName(vodDictDO.getVodName());
memberVodVOS.add(memberVodVO);
}
contentVodVO.setMemberVodVOS(memberVodVOS);
contentVodVOS.add(contentVodVO);
}
contentVodNewVO.setContentVodVOS(contentVodVOS);
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getClassId,contentVodDTO.getClassId())
.eq(VodPlayHistoryDO::getMemberId,contentVodDTO.getMemberId())
.orderByDesc(VodPlayHistoryDO::getCreateDate));
if (vodPlayHistoryDOS.size()>0){
VodPlayHistoryDO vodPlayHistoryDO = vodPlayHistoryDOS.get(0);
VodDictDO vodDictDO = vodDictMapper.selectById(vodPlayHistoryDO.getVodId());
if (null!=vodDictDO){
BeanUtils.copyProperties(vodDictDO,contentVodNewVO);
contentVodNewVO.setPlayRecord(vodPlayHistoryDO.getPlayRecord());
}
}
return contentVodNewVO;
}
public List<ContentFilesVO> contentFiles(ContentMemberDTO contentMemberDTO) {
List<ContentFilesVO> contentFilesVOS = new ArrayList<>();
List<CourseContentDO> courseContentDOS = courseContentMapper.selectList(new QueryWrapper<CourseContentDO>()
.lambda()
.eq(CourseContentDO::getCourseId, contentMemberDTO.getCourseId())
.orderByAsc(CourseContentDO::getOrderNo));
for (CourseContentDO courseContentDO : courseContentDOS) {
ContentFilesVO contentFilesVO = new ContentFilesVO();
contentFilesVO.setContent(courseContentDO.getContent());
List<FileDictDO> fileDictDOS = fileDictMapper.selectList(new QueryWrapper<FileDictDO>()
.lambda()
.eq(FileDictDO::getContentId, courseContentDO.getId()));
contentFilesVO.setFileDictDOS(fileDictDOS);
contentFilesVOS.add(contentFilesVO);
}
return contentFilesVOS;
}
public IPage studyHistory(StudyHistoryDTO studyHistoryDTO) {
Page pager = new Page(studyHistoryDTO.getPageNum(), studyHistoryDTO.getPageSize());
IPage iPage = vodPlayHistoryMapper.studyHistory(pager, studyHistoryDTO.getMemberId());
List<StudyHistoryVO> studyHistoryVOS = iPage.getRecords();
for (StudyHistoryVO studyHistoryVO : studyHistoryVOS) {
if (studyHistoryVO.getPercent() >= 80) {
studyHistoryVO.setStatus(true);
} else {
studyHistoryVO.setStatus(false);
}
}
iPage.setRecords(studyHistoryVOS);
return iPage;
}
public GetCourseTestVO getCourseTest(ContentMemberDTO contentMemberDTO) {
GetCourseTestVO getCourseTestVO = new GetCourseTestVO();
ClassDictDO classDictDO = classDictMapper.selectById(contentMemberDTO.getClassId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
getCourseTestVO.setCourseId(courseDictDO.getId());
getCourseTestVO.setCourseName(courseDictDO.getCourseName());
getCourseTestVO.setDeadline(classDictDO.getEndDate());
ExerciseDoneResultDO exerciseDoneResultDO = exerciseDoneResultMapper.selectOne(new QueryWrapper<ExerciseDoneResultDO>()
.lambda()
.eq(ExerciseDoneResultDO::getCourseId, courseDictDO.getId())
.eq(ExerciseDoneResultDO::getMemberId, contentMemberDTO.getMemberId()));
if (null != exerciseDoneResultDO) {
getCourseTestVO.setRightCount(String.valueOf(exerciseDoneResultDO.getRightCounts()));
getCourseTestVO.setTotalCount(String.valueOf(exerciseDoneResultDO.getTotalCounts()));
//正确率
Integer percent = MathUtil.intDivFloorPercent(exerciseDoneResultDO.getRightCounts(),exerciseDoneResultDO.getTotalCounts());
if(percent>=60){
getCourseTestVO.setResult("合格");
}else {
getCourseTestVO.setResult("不合格");
}
getCourseTestVO.setPercent(String.valueOf(percent));
} else {
getCourseTestVO.setRightCount("-");
//该课程下有多少习题
Integer count = exerciseDictMapper.selectCount(new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getCourseId, courseDictDO.getId()));
getCourseTestVO.setTotalCount(String.valueOf(count));
getCourseTestVO.setPercent("-");
getCourseTestVO.setResult("不合格");
}
return getCourseTestVO;
}
public GetStudyInfoVO getStudyInfo(MemberDO memberDO) {
GetStudyInfoVO getStudyInfoVO = new GetStudyInfoVO();
MemberDO memberDO1 = this.baseMapper.selectById(memberDO.getId());
//第几天
long diff = Duration.between(LocalDateTime.now(), memberDO1.getCreateDate()).toDays();
getStudyInfoVO.setDiff(diff);
//已学课程
List<ClassMemberMappingDO> classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getMemberId, memberDO.getId()));
/**
* 遍历课程,里面的视频都看过80% 则表示已学完
*/
int i = 0; //已学课程
for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) {
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classMemberMappingDO.getClassId());
for (VodDictDO vodDictDO : vodDictDOS) {
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getMemberId, memberDO.getId())
.eq(VodPlayHistoryDO::getVodId, vodDictDO.getId())
.orderByDesc(VodPlayHistoryDO::getPlayRecord));
if (vodPlayHistoryDOS.size() > 0) {
if (vodPlayHistoryDOS.get(0).getPlayRecord() < vodDictDO.getVodLength() * 0.8) {
break;
}
}
}
i++;
}
getStudyInfoVO.setStudyCourse(i);
//累计学习时长
int studyLength = 0;
List<VodPlayHistoryDO> vodPlayHistoryDOS = vodPlayHistoryMapper.selectList(new QueryWrapper<VodPlayHistoryDO>()
.lambda()
.eq(VodPlayHistoryDO::getMemberId, memberDO.getId()));
for (VodPlayHistoryDO vodPlayHistoryDO : vodPlayHistoryDOS) {
studyLength += vodPlayHistoryDO.getPlayLength();
}
getStudyInfoVO.setStudyLength(studyLength);
return getStudyInfoVO;
}
}