ExerciseDictServiceImpl.java
4.67 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
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.exercise.GetAllExercisesDTO;
import com.subsidy.dto.exercise.SubmitDTO;
import com.subsidy.mapper.ExerciseDoneResultMapper;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.ExerciseDictDO;
import com.subsidy.mapper.ExerciseDictMapper;
import com.subsidy.model.ExerciseDoneResultDO;
import com.subsidy.service.ExerciseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.course.ExerciseVO;
import com.subsidy.vo.exercise.MemberExerciseVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 习题库 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-12
*/
@Service
public class ExerciseDictServiceImpl extends ServiceImpl<ExerciseDictMapper, ExerciseDictDO> implements ExerciseDictService {
@Autowired
private ExerciseDoneResultMapper exerciseDoneResultMapper;
public IPage<ExerciseDictDO> getAllExercises(GetAllExercisesDTO getAllExercisesDTO) {
Page pager = new Page(getAllExercisesDTO.getPageNum(), getAllExercisesDTO.getPageSize());
return this.baseMapper.selectPage(pager, new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getCourseId, getAllExercisesDTO.getCourseId())
.like(ExerciseDictDO::getDifficulty, getAllExercisesDTO.getDifficulty())
.like(ExerciseDictDO::getExerciseType, getAllExercisesDTO.getExerciseType())
.like(ExerciseDictDO::getTitle, getAllExercisesDTO.getTitle())
.orderByAsc(ExerciseDictDO::getOrderNo));
}
public String addExercise(ExerciseDictDO exerciseDictDO){
List<ExerciseDictDO> exerciseDictDOS = this.baseMapper.selectList(new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getCourseId,exerciseDictDO.getCourseId())
.orderByDesc(ExerciseDictDO::getOrderNo));
int orderNo = 1;
if (exerciseDictDOS.size() >0){
orderNo = exerciseDictDOS.get(0).getOrderNo()+1;
}
exerciseDictDO.setOrderNo(orderNo);
this.baseMapper.insert(exerciseDictDO);
return ConstantUtils.ADD_SUCCESS;
}
public String deleteExercise(ExerciseDictDO exerciseDictDO){
this.baseMapper.deleteById(exerciseDictDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
public String updateExercise(ExerciseDictDO exerciseDictDO){
this.baseMapper.updateById(exerciseDictDO);
return ConstantUtils.SET_SUCCESS;
}
public List<ExerciseVO> getCourseExercises(CourseDictDO courseDictDO){
List<ExerciseVO> exerciseVOS = new ArrayList<>();
List<ExerciseDictDO> exerciseDictDOS = this.baseMapper.selectList(new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getCourseId,courseDictDO.getId()));
for (ExerciseDictDO exerciseDictDO : exerciseDictDOS){
ExerciseVO exerciseVO = new ExerciseVO();
BeanUtils.copyProperties(exerciseDictDO,exerciseVO);
exerciseVOS.add(exerciseVO);
}
return exerciseVOS;
}
public String submit(SubmitDTO submitDTO){
ExerciseDoneResultDO exerciseDoneResultDO = new ExerciseDoneResultDO();
List<MemberExerciseVO> memberExerciseVOS = submitDTO.getMemberExerciseVOS();
int rightCounts = 0 ;
for (MemberExerciseVO exerciseVO : memberExerciseVOS){
ExerciseDictDO exerciseDictDO = this.baseMapper.selectById(exerciseVO.getId());
if (exerciseDictDO.getRightAnswer().equals(exerciseVO.getSelectAnswer())){
rightCounts++;
}
}
exerciseDoneResultDO.setClassId(submitDTO.getClassId());
exerciseDoneResultDO.setRightCounts(rightCounts);
exerciseDoneResultDO.setTotalCounts(memberExerciseVOS.size());
exerciseDoneResultDO.setCourseId(submitDTO.getCourseId());
exerciseDoneResultDO.setMemberId(submitDTO.getMemberId());
exerciseDoneResultMapper.delete(new QueryWrapper<ExerciseDoneResultDO>()
.lambda()
.eq(ExerciseDoneResultDO::getMemberId,submitDTO.getMemberId())
.eq(ExerciseDoneResultDO::getCourseId,submitDTO.getCourseId()));
exerciseDoneResultMapper.insert(exerciseDoneResultDO);
return ConstantUtils.COMMIT_SUCCESS;
}
}