|
@@ -2,6 +2,7 @@ package com.xhkjedu.sstudy.service.question;
|
2
|
2
|
|
3
|
3
|
import com.xhkjedu.sstudy.mapper.question.QuestionMapper;
|
4
|
4
|
import com.xhkjedu.sstudy.mapper.question.UserBasketMapper;
|
|
5
|
+import com.xhkjedu.sstudy.mapper.subjectbook.SubjectMapper;
|
5
|
6
|
import com.xhkjedu.sstudy.model.question.TUserBasket;
|
6
|
7
|
import com.xhkjedu.utils.N_Utils;
|
7
|
8
|
import com.xhkjedu.sstudy.vo.question.QuestionVo;
|
|
@@ -9,6 +10,7 @@ import com.xhkjedu.sstudy.vo.question.UserBasketVo;
|
9
|
10
|
import org.springframework.stereotype.Service;
|
10
|
11
|
|
11
|
12
|
import javax.annotation.Resource;
|
|
13
|
+import java.util.ArrayList;
|
12
|
14
|
import java.util.List;
|
13
|
15
|
import java.util.stream.Collectors;
|
14
|
16
|
|
|
@@ -24,6 +26,8 @@ public class UserBasketService {
|
24
|
26
|
private UserBasketMapper userBasketMapper;
|
25
|
27
|
@Resource
|
26
|
28
|
private QuestionMapper questionMapper;
|
|
29
|
+ @Resource
|
|
30
|
+ private SubjectMapper subjectMapper;
|
27
|
31
|
|
28
|
32
|
//添加
|
29
|
33
|
public Integer save(TUserBasket model) {
|
|
@@ -57,11 +61,42 @@ public class UserBasketService {
|
57
|
61
|
//获取列表
|
58
|
62
|
public List <UserBasketVo> findAll(Integer userid, String subjectid) {
|
59
|
63
|
List<UserBasketVo> baskets = userBasketMapper.findAll(userid, subjectid);
|
60
|
|
- for (UserBasketVo b : baskets) {
|
61
|
|
- List<QuestionVo> questions = b.getQuestions();
|
62
|
|
- b.setPtnum(questions.size());
|
63
|
|
- Double scoretotal = questions.stream().collect(Collectors.summingDouble(QuestionVo::getScore));
|
64
|
|
- b.setPtscore(scoretotal);
|
|
64
|
+ String sujectname = subjectMapper.getSubjectnameById(subjectid);
|
|
65
|
+ //英语学科时处理听力题
|
|
66
|
+ if(sujectname.contains("英语")){
|
|
67
|
+ List<QuestionVo> hearqs = new ArrayList<>();
|
|
68
|
+ for (UserBasketVo b : baskets) {
|
|
69
|
+ List<QuestionVo> questions = b.getQuestions();
|
|
70
|
+
|
|
71
|
+ List<QuestionVo> tllist = questions.stream().filter( o -> o.getHashear() ==1).collect(Collectors.toList());
|
|
72
|
+ if(N_Utils.isNotEmpty(tllist)){
|
|
73
|
+ hearqs.addAll(tllist);
|
|
74
|
+
|
|
75
|
+ questions = questions.stream().filter( o -> o.getHashear() ==0).collect(Collectors.toList());
|
|
76
|
+ }
|
|
77
|
+ b.setPtnum(questions.size());
|
|
78
|
+ Double scoretotal = questions.stream().collect(Collectors.summingDouble(QuestionVo::getScore));
|
|
79
|
+ b.setPtscore(scoretotal);
|
|
80
|
+ b.setQuestions(questions);
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ if(N_Utils.isNotEmpty(hearqs)){
|
|
84
|
+ UserBasketVo tlvo = new UserBasketVo();
|
|
85
|
+ tlvo.setQtypename("听力题");
|
|
86
|
+ tlvo.setPtnum(hearqs.size());
|
|
87
|
+ Double scoretotal = hearqs.stream().collect(Collectors.summingDouble(QuestionVo::getScore));
|
|
88
|
+ tlvo.setPtscore(scoretotal);
|
|
89
|
+ tlvo.setQuestions(hearqs);
|
|
90
|
+ baskets.add(0,tlvo);
|
|
91
|
+
|
|
92
|
+ }
|
|
93
|
+ }else{
|
|
94
|
+ for (UserBasketVo b : baskets) {
|
|
95
|
+ List<QuestionVo> questions = b.getQuestions();
|
|
96
|
+ b.setPtnum(questions.size());
|
|
97
|
+ Double scoretotal = questions.stream().collect(Collectors.summingDouble(QuestionVo::getScore));
|
|
98
|
+ b.setPtscore(scoretotal);
|
|
99
|
+ }
|
65
|
100
|
}
|
66
|
101
|
return baskets;
|
67
|
102
|
}
|