|
@@ -2,14 +2,16 @@ package com.xhkjedu.smarking.service.paper;
|
2
|
2
|
|
3
|
3
|
import com.xhkjedu.smarking.mapper.exam.MsSubjectMapper;
|
4
|
4
|
import com.xhkjedu.smarking.mapper.paper.*;
|
5
|
|
-import com.xhkjedu.smarking.model.paper.MsTemplate;
|
|
5
|
+import com.xhkjedu.smarking.model.paper.*;
|
6
|
6
|
import com.xhkjedu.utils.N_Utils;
|
7
|
7
|
import org.springframework.stereotype.Service;
|
8
|
8
|
import org.springframework.transaction.annotation.Transactional;
|
9
|
9
|
|
10
|
10
|
import javax.annotation.Resource;
|
|
11
|
+import java.util.ArrayList;
|
11
|
12
|
import java.util.List;
|
12
|
13
|
import java.util.Map;
|
|
14
|
+import java.util.stream.Collectors;
|
13
|
15
|
|
14
|
16
|
/**
|
15
|
17
|
* @Description 阅卷扫描模板表 服务实现类
|
|
@@ -25,6 +27,12 @@ public class MsTemplateService {
|
25
|
27
|
@Resource
|
26
|
28
|
private MsTemplateBlockQuestionMapper msTemplateBlockQuestionMapper;
|
27
|
29
|
@Resource
|
|
30
|
+ private MsPaperQtypeQuestionMapper msPaperQtypeQuestionMapper;
|
|
31
|
+ @Resource
|
|
32
|
+ private MsPaperBlockMapper msPaperBlockMapper;
|
|
33
|
+ @Resource
|
|
34
|
+ private MsPaperBlockQuestionMapper msPaperBlockQuestionMapper;
|
|
35
|
+ @Resource
|
28
|
36
|
private MsSubjectMapper msSubjectMapper;
|
29
|
37
|
|
30
|
38
|
/*
|
|
@@ -49,7 +57,7 @@ public class MsTemplateService {
|
49
|
57
|
public MsTemplate add(MsTemplate msTemplate){
|
50
|
58
|
msTemplate.setCreatetime(N_Utils.getSecondTimestamp());
|
51
|
59
|
msTemplate.setCurrstep(1);
|
52
|
|
- msTemplateMapper.insert(msTemplate);
|
|
60
|
+ msTemplateMapper.insertUseGeneratedKeys(msTemplate);
|
53
|
61
|
int mtid = msTemplate.getId();
|
54
|
62
|
msTemplate.setMtid(mtid);
|
55
|
63
|
|
|
@@ -61,15 +69,86 @@ public class MsTemplateService {
|
61
|
69
|
@Transactional(rollbackFor = Exception.class)
|
62
|
70
|
public MsTemplate updateTemplate(MsTemplate msTemplate){
|
63
|
71
|
msTemplateMapper.updateTemplateForCurrstep(msTemplate);
|
64
|
|
-
|
|
72
|
+ Integer mpid = msTemplate.getMpid();
|
65
|
73
|
//如果当前保存为6,则需要保存客观题信息
|
66
|
74
|
if(msTemplate.getCurrstep() == 6){
|
67
|
|
- //保存题块信息
|
68
|
|
-
|
69
|
|
- //保存模块板题块信息
|
|
75
|
+ //模版题块信息
|
|
76
|
+ List<MsTemplateBlock> tblocks = msTemplate.getTblocks();
|
|
77
|
+ savePaperBlock(tblocks,msTemplate);
|
70
|
78
|
}
|
71
|
79
|
return msTemplate;
|
72
|
80
|
}
|
73
|
81
|
|
|
82
|
+ private void savePaperBlock(List<MsTemplateBlock> tblocks,MsTemplate msTemplate){
|
|
83
|
+ Integer mpid = msTemplate.getMpid();
|
|
84
|
+ Integer timestamp = N_Utils.getSecondTimestamp();
|
|
85
|
+ Integer createid = msTemplate.getCreateid();
|
|
86
|
+
|
|
87
|
+ //客观题题块试题信息
|
|
88
|
+ List<MsPaperBlockQuestion> savePbquestions = new ArrayList<>();
|
|
89
|
+ //客观题模块试题信息
|
|
90
|
+ List<MsTemplateBlockQuestion> saveTbquestions = new ArrayList<>();
|
|
91
|
+ //获取试卷中所有试题信息
|
|
92
|
+ List<MsPaperQtypeQuestion> questions = msPaperQtypeQuestionMapper.listQuestionsByMpid(mpid);
|
|
93
|
+ int i = 1;
|
|
94
|
+ for(MsTemplateBlock tblock : tblocks){
|
|
95
|
+ //获取客观题单题
|
|
96
|
+ List<MsTemplateBlockQuestion> tbquestions = tblock.getTbquestions();
|
|
97
|
+ //获取客观题题号
|
|
98
|
+ List<String> tbqns = tbquestions.stream().map(MsTemplateBlockQuestion::getQn).collect(Collectors.toList());
|
|
99
|
+ //包含的试题信息
|
|
100
|
+ List<MsPaperQtypeQuestion> selQuestions = questions.stream().filter(q -> tbqns.contains(q.getQn())).collect(Collectors.toList());
|
|
101
|
+ if(selQuestions == null || selQuestions.size() == 0 || selQuestions.size() != tbquestions.size()){
|
|
102
|
+ throw new RuntimeException("试题信息和试卷不匹配");
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ Double tbqScores = selQuestions.stream().mapToDouble(MsPaperQtypeQuestion::getQscore).sum();//题块下试题总分值
|
|
106
|
+
|
|
107
|
+ //保存试卷题块信息
|
|
108
|
+ MsPaperBlock paperBlock = new MsPaperBlock();
|
|
109
|
+ paperBlock.setMpid(mpid);
|
|
110
|
+ paperBlock.setBlockname("客观题题块" + (i++));
|
|
111
|
+ paperBlock.setBlocktype(1);
|
|
112
|
+ paperBlock.setBlockorder(tblock.getBlockorder());
|
|
113
|
+ paperBlock.setBqnum(tbquestions.size());
|
|
114
|
+ paperBlock.setBqscore(tbqScores);
|
|
115
|
+ paperBlock.setCreateid(createid);
|
|
116
|
+ paperBlock.setCreatetime(timestamp);
|
|
117
|
+ msPaperBlockMapper.insertUseGeneratedKeys(paperBlock);
|
|
118
|
+ Integer mblockid = paperBlock.getId();//题块ID
|
|
119
|
+
|
|
120
|
+ //保存模块题块信息
|
|
121
|
+ tblock.setBlockname(paperBlock.getBlockname());
|
|
122
|
+ tblock.setMttype(1);
|
|
123
|
+ tblock.setMblockid(mblockid);
|
|
124
|
+ tblock.setCreateid(createid);
|
|
125
|
+ tblock.setCreatetime(timestamp);
|
|
126
|
+ msTemplateBlockMapper.insertUseGeneratedKeys(tblock);
|
|
127
|
+ Integer mtbid = tblock.getId();
|
|
128
|
+
|
|
129
|
+ for(MsTemplateBlockQuestion tbquestion : tbquestions) {
|
|
130
|
+ tbquestion.setMtbid(mtbid);
|
|
131
|
+ saveTbquestions.add(tbquestion);
|
|
132
|
+
|
|
133
|
+ MsPaperQtypeQuestion q = selQuestions.stream().filter(q1 -> q1.getQn().equals(tbquestion.getQn())).findFirst().get();
|
|
134
|
+
|
|
135
|
+ MsPaperBlockQuestion pbquestion = new MsPaperBlockQuestion();
|
|
136
|
+ pbquestion.setMblockid(mblockid);
|
|
137
|
+ pbquestion.setMpid(mpid);
|
|
138
|
+ pbquestion.setMbqtype(1);
|
|
139
|
+ pbquestion.setMptqid(q.getMptqid());
|
|
140
|
+ pbquestion.setBqn(tbquestion.getQn());
|
|
141
|
+ pbquestion.setBqscore(q.getQscore());
|
|
142
|
+ pbquestion.setBqorder(tbquestion.getBqorder());
|
|
143
|
+ pbquestion.setCreateid(createid);
|
|
144
|
+ pbquestion.setCreatetime(timestamp);
|
|
145
|
+ savePbquestions.add(pbquestion);
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ msPaperBlockQuestionMapper.insertList(savePbquestions);
|
|
150
|
+ msTemplateBlockQuestionMapper.insertList(saveTbquestions);
|
|
151
|
+ }
|
|
152
|
+
|
74
|
153
|
|
75
|
154
|
}
|