|
@@ -1,19 +1,10 @@
|
1
|
1
|
package com.xhkjedu.sclass.service.classroom;
|
2
|
2
|
|
3
|
3
|
import com.alibaba.fastjson.JSON;
|
4
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperFileMapper;
|
5
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperMapper;
|
6
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperQtypeMapper;
|
7
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperScantronMapper;
|
8
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperStudentMapper;
|
9
|
|
-import com.xhkjedu.sclass.mapper.classroom.ClassroomPaperStudentScantronMapper;
|
10
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaper;
|
11
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaperFile;
|
12
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaperQtype;
|
13
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaperScantron;
|
14
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaperStudent;
|
15
|
|
-import com.xhkjedu.sclass.model.classroom.TClassroomPaperStudentScantron;
|
|
4
|
+import com.xhkjedu.sclass.mapper.classroom.*;
|
|
5
|
+import com.xhkjedu.sclass.model.classroom.*;
|
16
|
6
|
import com.xhkjedu.sclass.model.paperstudent.TPaperStudentScantron;
|
|
7
|
+import com.xhkjedu.sclass.utils.ArithUtil;
|
17
|
8
|
import com.xhkjedu.utils.N_Utils;
|
18
|
9
|
import lombok.extern.slf4j.Slf4j;
|
19
|
10
|
import org.springframework.stereotype.Service;
|
|
@@ -21,7 +12,9 @@ import org.springframework.transaction.annotation.Transactional;
|
21
|
12
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
22
|
13
|
|
23
|
14
|
import javax.annotation.Resource;
|
|
15
|
+import java.text.DecimalFormat;
|
24
|
16
|
import java.util.ArrayList;
|
|
17
|
+import java.util.Arrays;
|
25
|
18
|
import java.util.List;
|
26
|
19
|
import java.util.Map;
|
27
|
20
|
import java.util.stream.Collectors;
|
|
@@ -47,6 +40,7 @@ public class ClassroomPaperService {
|
47
|
40
|
private ClassroomPaperStudentMapper classroomPaperStudentMapper;
|
48
|
41
|
@Resource
|
49
|
42
|
private ClassroomPaperStudentScantronMapper classroomPaperStudentScantronMapper;
|
|
43
|
+ private static Integer[] QTYPE = {1, 2, 4, 5, 6, 7, 8, 10};
|
50
|
44
|
|
51
|
45
|
/**
|
52
|
46
|
* 答题卡作业--保存
|
|
@@ -148,14 +142,106 @@ public class ClassroomPaperService {
|
148
|
142
|
try {
|
149
|
143
|
classroomPaperStudentMapper.insertUseGeneratedKeys(student);
|
150
|
144
|
Integer psid = student.getId();
|
|
145
|
+ Double userscore = 0.0;
|
|
146
|
+ Integer checknum = 0;
|
151
|
147
|
List<TClassroomPaperStudentScantron> scantrons = student.getScantrons();
|
152
|
148
|
int qorder = 1;//试题序号
|
153
|
149
|
for (TClassroomPaperStudentScantron s : scantrons) {
|
154
|
150
|
s.setPsid(psid);
|
155
|
151
|
s.setQorder(qorder);
|
156
|
152
|
qorder++;
|
|
153
|
+ //获取原试题情况
|
|
154
|
+ Double qscore = s.getQscore();
|
|
155
|
+ TClassroomPaperScantron scantronBean = classroomPaperScantronMapper.selectByPrimaryKey(s.getPscaid());
|
|
156
|
+ //判断是否作答1.提交但未作答设置零分,2.作答设置答题状态为2,3.选择题提交为空判错
|
|
157
|
+ String useranswer = s.getUseranswer();
|
|
158
|
+ List<String> userAnswers = JSON.parseArray(useranswer, String.class);
|
|
159
|
+ String psanswer = scantronBean.getPsanswer();
|
|
160
|
+ List<String> psanswers = JSON.parseArray(psanswer, String.class);
|
|
161
|
+ //计算用户得分
|
|
162
|
+ Double userScore = 0.0;
|
|
163
|
+ //设置保留位数
|
|
164
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
165
|
+ if (N_Utils.isListEmpty(userAnswers)) {
|
|
166
|
+ s.setStuscore(userScore);
|
|
167
|
+ s.setChecked(1);
|
|
168
|
+ s.setCheckid(0);
|
|
169
|
+ s.setChecktime(N_Utils.getSecondTimestamp());
|
|
170
|
+ s.setAnswered(0);
|
|
171
|
+ checknum++;
|
|
172
|
+ } else {
|
|
173
|
+ s.setAnswered(1);
|
|
174
|
+ //自动批改判断得分
|
|
175
|
+ Integer ctype = scantronBean.getCtype();
|
|
176
|
+ if (Arrays.asList(QTYPE).contains(ctype)) {
|
|
177
|
+ checknum++;
|
|
178
|
+ if (ctype == 1) {//单选
|
|
179
|
+ if (useranswer.equalsIgnoreCase(psanswer)) {
|
|
180
|
+ userScore = qscore;
|
|
181
|
+ }
|
|
182
|
+ } else if (ctype == 2) {//多选
|
|
183
|
+ //多选不得分,或者选错不得分,不用处理
|
|
184
|
+ if (useranswer.length() <= psanswer.length()) {
|
|
185
|
+ String[] qanswerList = psanswers.get(0).split("");
|
|
186
|
+ String[] userAnswerList = userAnswers.get(0).split("");
|
|
187
|
+ int rightNum = 0;//选对个数
|
|
188
|
+ for (String userAnswer : userAnswerList) {
|
|
189
|
+ int right = 0;
|
|
190
|
+ for (String qanswer : qanswerList) {
|
|
191
|
+ if (qanswer.equals(userAnswer)) {
|
|
192
|
+ right = 1;
|
|
193
|
+ rightNum += 1;
|
|
194
|
+ }
|
|
195
|
+ }
|
|
196
|
+ if (right == 0) {//选错直接0分,结束循环
|
|
197
|
+ rightNum = 0;
|
|
198
|
+ break;
|
|
199
|
+ }
|
|
200
|
+ }
|
|
201
|
+ if (rightNum > 0) {//选对计算得分
|
|
202
|
+ if (qanswerList.length == rightNum) {//1.全选对满分
|
|
203
|
+ userScore = qscore;
|
|
204
|
+ } else if (qanswerList.length > rightNum) {//2.少选得一半分
|
|
205
|
+ userScore = ArithUtil.div(qscore, 2, 1);
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+ }
|
|
209
|
+ } else if (ctype == 4 || ctype == 5 || ctype == 6) {
|
|
210
|
+ //判断题
|
|
211
|
+ if (useranswer.equalsIgnoreCase(psanswer)) {
|
|
212
|
+ userScore = qscore;
|
|
213
|
+ }
|
|
214
|
+ } else if (ctype == 7 || ctype == 8 || ctype == 10) {//完型填空、阅读理解、任务型阅读
|
|
215
|
+ //计算每小题分数
|
|
216
|
+ Double score = ArithUtil.div(qscore, psanswers.size());
|
|
217
|
+ Double userScoreDouble = 0D;
|
|
218
|
+ for (int j = 0; j < psanswers.size(); j++) {
|
|
219
|
+ if (psanswers.get(j).equalsIgnoreCase(userAnswers.get(j))) {
|
|
220
|
+ userScoreDouble = ArithUtil.add(userScoreDouble, score);
|
|
221
|
+ }
|
|
222
|
+ }
|
|
223
|
+ userScore = ArithUtil.round(userScoreDouble, 1);
|
|
224
|
+ }
|
|
225
|
+ if (userScore.compareTo(qscore) == 1) {
|
|
226
|
+ userScore = qscore;
|
|
227
|
+ }
|
|
228
|
+ s.setStuscore(userScore);
|
|
229
|
+ s.setChecked(1);
|
|
230
|
+ s.setCheckid(0);
|
|
231
|
+ s.setChecktime(N_Utils.getSecondTimestamp());
|
|
232
|
+ }
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ userscore = ArithUtil.add(userscore, userScore);
|
157
|
236
|
}
|
158
|
237
|
classroomPaperStudentScantronMapper.insertList(scantrons);
|
|
238
|
+
|
|
239
|
+ Integer pschecked = 0;
|
|
240
|
+ if (checknum == scantrons.size()) {//如果自动批改试题数量等于试题总量,批改状态改为1已批改
|
|
241
|
+ pschecked = 1;
|
|
242
|
+ }
|
|
243
|
+ //修改学生得分和批改状态
|
|
244
|
+ classroomPaperStudentMapper.updateScantronStuScoreAndChecked(psid, userscore, pschecked);
|
159
|
245
|
} catch (Exception e) {
|
160
|
246
|
log.error("保存学生作答详情失败:"+e.getMessage());
|
161
|
247
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|