ExerciseDictServiceImpl.java
13.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
289
290
291
package com.meishu.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.meishu.dto.exercise.AddExerciseDTO;
import com.meishu.dto.exercise.CheckExerciseDTO;
import com.meishu.dto.exercise.GetTreeExercisesDTO;
import com.meishu.dto.voddict.GetToCheckVodCountsDTO;
import com.meishu.dto.voddict.PublicCheckingDTO;
import com.meishu.mapper.*;
import com.meishu.model.*;
import com.meishu.service.ExerciseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.exercise.GetExerciseDetailVO;
import com.meishu.vo.exercise.GetTreeExercisesVO;
import com.meishu.vo.voddict.GetToCheckCountsVO;
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.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 习题库 服务实现类
* </p>
*
* @author Tuyp
* @since 2021-04-27
*/
@Service
public class ExerciseDictServiceImpl extends ServiceImpl<ExerciseDictMapper, ExerciseDictDO> implements ExerciseDictService {
@Autowired
private ExerciseTreeMappingMapper exerciseTreeMappingMapper;
@Autowired
private KnowledgeSubjectDictMapper knowledgeSubjectDictMapper;
@Autowired
private AdministerMapper administerMapper;
public IPage<GetTreeExercisesVO> getTreeExercises(GetTreeExercisesDTO getTreeExercisesDTO) {
Page pager = new Page(getTreeExercisesDTO.getPageNum(), getTreeExercisesDTO.getPageSize());
KnowledgeSubjectDictDO subjectDictDO = knowledgeSubjectDictMapper.selectById(getTreeExercisesDTO.getSubjectId());
if ("1".equals(getTreeExercisesDTO.getShareStatus())) {
getTreeExercisesDTO.setUserId(null);
}
//查看该老师的科目信息
List<KnowledgeSubjectDictDO> subjectDictDOS = administerMapper.getTeacherSubjects(getTreeExercisesDTO.getUserId());
List<String> strings = new ArrayList<>();
for (KnowledgeSubjectDictDO subjectDictDO1 : subjectDictDOS) {
strings.add(subjectDictDO1.getSubjectEn());
}
IPage<GetTreeExercisesVO> getTreeExercisesVOIPage = this.baseMapper.getTreeExercises(pager, getTreeExercisesDTO.getUserId(), subjectDictDO.getSubjectEn(), getTreeExercisesDTO.getTreeId(), getTreeExercisesDTO.getExerciseType(), getTreeExercisesDTO.getDifficulty(), getTreeExercisesDTO.getTitle(), getTreeExercisesDTO.getShareStatus(),getTreeExercisesDTO.getCheckStatus(),strings);
List<GetTreeExercisesVO> getTreeExercisesVOS = getTreeExercisesVOIPage.getRecords();
for (GetTreeExercisesVO getTreeExercisesVO : getTreeExercisesVOS) {
//找知识树
List<SubjectTreeDO> subjectTreeDOS = this.baseMapper.getTrees(getTreeExercisesVO.getId());
getTreeExercisesVO.setSubjectTreeDOS(subjectTreeDOS);
}
getTreeExercisesVOIPage.setRecords(getTreeExercisesVOS);
return getTreeExercisesVOIPage;
}
public IPage<GetTreeExercisesVO> getCheckTreeExercises(GetTreeExercisesDTO getTreeExercisesDTO){
Page pager = new Page(getTreeExercisesDTO.getPageNum(), getTreeExercisesDTO.getPageSize());
KnowledgeSubjectDictDO subjectDictDO = knowledgeSubjectDictMapper.selectById(getTreeExercisesDTO.getSubjectId());
//查看该老师的科目信息
List<KnowledgeSubjectDictDO> subjectDictDOS = administerMapper.getTeacherSubjects(getTreeExercisesDTO.getUserId());
List<String> strings = new ArrayList<>();
for (KnowledgeSubjectDictDO subjectDictDO1 : subjectDictDOS) {
strings.add(subjectDictDO1.getSubjectEn());
}
IPage<GetTreeExercisesVO> getTreeExercisesVOIPage = this.baseMapper.getTreeExercises(pager, null, subjectDictDO.getSubjectEn(), getTreeExercisesDTO.getTreeId(), getTreeExercisesDTO.getExerciseType(), getTreeExercisesDTO.getDifficulty(), getTreeExercisesDTO.getTitle(), getTreeExercisesDTO.getShareStatus(),getTreeExercisesDTO.getCheckStatus(),strings);
List<GetTreeExercisesVO> getTreeExercisesVOS = getTreeExercisesVOIPage.getRecords();
for (GetTreeExercisesVO getTreeExercisesVO : getTreeExercisesVOS) {
//找知识树
List<SubjectTreeDO> subjectTreeDOS = this.baseMapper.getTrees(getTreeExercisesVO.getId());
getTreeExercisesVO.setSubjectTreeDOS(subjectTreeDOS);
}
getTreeExercisesVOIPage.setRecords(getTreeExercisesVOS);
return getTreeExercisesVOIPage;
}
@Transactional(rollbackFor = Exception.class)
public String deleteExercise(ExerciseDictDO exerciseDictDO) {
// Integer count = exerciseCourseTreeMappingMapper.selectCount(new QueryWrapper<ExerciseCourseTreeMappingDO>()
// .lambda()
// .eq(ExerciseCourseTreeMappingDO::getExerciseId, exerciseDictDO.getId()));
//
// if (count > 0) {
// throw new HttpException(30003);
// }
//
this.baseMapper.deleteById(exerciseDictDO.getId());
//删相关树
exerciseTreeMappingMapper.delete(new QueryWrapper<ExerciseTreeMappingDO>()
.lambda()
.eq(ExerciseTreeMappingDO::getExerciseId, exerciseDictDO.getId()));
// //删相关做题记录
// exerciseDoneHistoryMapper.delete(new QueryWrapper<ExerciseDoneHistoryDO>()
// .lambda()
// .eq(ExerciseDoneHistoryDO::getExerciseId, exerciseDictDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String addExercise(AddExerciseDTO addExerciseDTO) {
ExerciseDictDO exerciseDictDO = new ExerciseDictDO();
KnowledgeSubjectDictDO subjectDictDO = knowledgeSubjectDictMapper.selectById(addExerciseDTO.getSubjectId());
BeanUtils.copyProperties(addExerciseDTO, exerciseDictDO);
exerciseDictDO.setShareStatus("0");
exerciseDictDO.setCheckStatus("0");
exerciseDictDO.setSubjectId(subjectDictDO.getSubjectEn());
this.baseMapper.insert(exerciseDictDO);
List<Long> longs = addExerciseDTO.getTreeIds();
for (Long lg : longs) {
ExerciseTreeMappingDO exerciseTreeMappingDO = new ExerciseTreeMappingDO();
exerciseTreeMappingDO.setTreeId(lg);
exerciseTreeMappingDO.setExerciseId(exerciseDictDO.getId());
exerciseTreeMappingMapper.insert(exerciseTreeMappingDO);
// //新增的题目也要加到courseTree里去
// List<CourseTreeDO> courseTreeDOS = courseTreeMapper.selectList(new QueryWrapper<CourseTreeDO>()
// .lambda()
// .eq(CourseTreeDO::getTreeId, lg));
//
// for (CourseTreeDO courseTreeDO : courseTreeDOS) {
// ExerciseCourseTreeMappingDO exerciseCourseTreeMappingDO = new ExerciseCourseTreeMappingDO();
// exerciseCourseTreeMappingDO.setExerciseId(exerciseDictDO.getId());
// exerciseCourseTreeMappingDO.setStatus("0");
// exerciseCourseTreeMappingDO.setCourseTreeId(courseTreeDO.getId());
// exerciseCourseTreeMappingDO.setCourseId(lg);
// exerciseCourseTreeMappingMapper.insert(exerciseCourseTreeMappingDO);
// }
}
return ConstantUtils.ADD_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String updateExercise(AddExerciseDTO addExerciseDTO) {
ExerciseDictDO exerciseDictDO = new ExerciseDictDO();
BeanUtils.copyProperties(addExerciseDTO, exerciseDictDO);
KnowledgeSubjectDictDO subjectDictDO = knowledgeSubjectDictMapper.selectById(addExerciseDTO.getSubjectId());
if (null!=subjectDictDO){
exerciseDictDO.setSubjectId(subjectDictDO.getSubjectEn());
}
this.baseMapper.updateById(exerciseDictDO);
exerciseTreeMappingMapper.delete(new QueryWrapper<ExerciseTreeMappingDO>()
.lambda()
.in(ExerciseTreeMappingDO::getExerciseId, addExerciseDTO.getId()));
List<Long> longs = addExerciseDTO.getTreeIds();
for (Long lg : longs) {
ExerciseTreeMappingDO exerciseTreeMappingDO = new ExerciseTreeMappingDO();
exerciseTreeMappingDO.setTreeId(lg);
exerciseTreeMappingDO.setExerciseId(exerciseDictDO.getId());
exerciseTreeMappingMapper.insert(exerciseTreeMappingDO);
}
return ConstantUtils.SUCCESS_UPDATE;
}
public GetToCheckCountsVO getToCheckExeCounts(GetToCheckVodCountsDTO getToCheckVodCountsDTO) {
GetToCheckCountsVO getToCheckCountsVO = new GetToCheckCountsVO();
KnowledgeSubjectDictDO subjectDictDO = knowledgeSubjectDictMapper.selectById(getToCheckVodCountsDTO.getSubjectId());
Integer count = this.baseMapper.selectCount(new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getCheckStatus, "2")
.eq(ExerciseDictDO::getSubjectId, subjectDictDO.getSubjectEn()));
getToCheckCountsVO.setToCheckCounts(count);
//已审核 包括已通过 未通过
Integer counts1 = this.baseMapper.selectCount(new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getSubjectId, subjectDictDO.getSubjectEn())
.in(ExerciseDictDO::getCheckStatus, new String[]{"1", "3"}));
getToCheckCountsVO.setCheckCounts(counts1);
return getToCheckCountsVO;
}
public String checkExercise(CheckExerciseDTO checkExerciseDTO) {
//审核通过
if ("1".equals(checkExerciseDTO.getCheckStatus())) {
ExerciseDictDO exerciseDictDO = this.baseMapper.selectById(checkExerciseDTO.getId());
exerciseDictDO.setCheckStatus("1");// 已通过审核
this.baseMapper.updateById(exerciseDictDO);
exerciseDictDO.setShareStatus("1"); //已共享
exerciseDictDO.setDifficulty(checkExerciseDTO.getDifficulty());
exerciseDictDO.setAdviceLength(checkExerciseDTO.getAdviceLength());
exerciseDictDO.setCreateDate(LocalDateTime.now());
exerciseDictDO.setUpdateDate(LocalDateTime.now());
this.baseMapper.insert(exerciseDictDO);
List<Long> ids = checkExerciseDTO.getTreeIds();
// //取消之前的关联
// exerciseTreeMappingMapper.delete(new QueryWrapper<ExerciseTreeMappingDO>()
// .lambda()
// .eq(ExerciseTreeMappingDO::getExerciseId, checkExerciseDTO.getId()));
for (Long lg : ids) {
//知识点关联
ExerciseTreeMappingDO exerciseTreeMappingDO = new ExerciseTreeMappingDO();
exerciseTreeMappingDO.setExerciseId(exerciseDictDO.getId());
exerciseTreeMappingDO.setTreeId(lg);
exerciseDictDO.setStatus("0"); //不是关联习题
exerciseTreeMappingMapper.insert(exerciseTreeMappingDO);
}
} else {
//不通过
ExerciseDictDO exerciseDictDO = new ExerciseDictDO();
BeanUtils.copyProperties(checkExerciseDTO, exerciseDictDO);
this.baseMapper.updateById(exerciseDictDO);
}
return ConstantUtils.CHECK_STATUS;
}
public IPage<ExerciseDictDO> publicUpload(PublicCheckingDTO publicCheckingDTO) {
Page pager = new Page(publicCheckingDTO.getPageNum(), publicCheckingDTO.getPageSize());
return this.baseMapper.selectPage(pager, new QueryWrapper<ExerciseDictDO>()
.lambda()
.eq(ExerciseDictDO::getAdministerId, publicCheckingDTO.getUserId())
.eq(ExerciseDictDO::getCheckStatus, publicCheckingDTO.getCheckStatus()));
}
public String withdraw(ExerciseDictDO exerciseDictDO) {
exerciseDictDO.setShareStatus("0");
exerciseDictDO.setCheckStatus("0");
this.baseMapper.updateById(exerciseDictDO);
return ConstantUtils.SET_SUCCESS;
}
public GetExerciseDetailVO getExerciseDetail(ExerciseDictDO exerciseDictDO) {
GetExerciseDetailVO getExerciseDetailVO = new GetExerciseDetailVO();
ExerciseDictDO exerciseDictDO1 = this.baseMapper.selectById(exerciseDictDO.getId());
BeanUtils.copyProperties(exerciseDictDO1, getExerciseDetailVO);
List<SubjectTreeDO> subjectTreeDOS = this.baseMapper.getTrees(exerciseDictDO.getId());
getExerciseDetailVO.setSubjectTreeDOS(subjectTreeDOS);
return getExerciseDetailVO;
}
public String setRelatedExercise(ExerciseTreeMappingDO exerciseTreeMappingDO){
ExerciseTreeMappingDO exerciseTreeMappingDO1 = new ExerciseTreeMappingDO();
exerciseTreeMappingDO1.setStatus(exerciseTreeMappingDO.getStatus());
exerciseTreeMappingMapper.update(exerciseTreeMappingDO1,new QueryWrapper<ExerciseTreeMappingDO>()
.lambda()
.eq(ExerciseTreeMappingDO::getExerciseId,exerciseTreeMappingDO.getExerciseId()));
return ConstantUtils.SUCCESS_UPDATE;
}
}