Ver código fonte

完善修改答案

tags/正式版本
王宁 2 anos atrás
pai
commit
23e183c23c

+ 3
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentMapper.java Ver arquivo

@@ -42,4 +42,7 @@ public interface EPaperStudentMapper extends TkMapper<EPaperStudent> {
42 42
 
43 43
     //学生提交试卷
44 44
     int updateStudentPaper(@Param("ps")EPaperStudent ps);
45
+
46
+    //根据试卷id批量修改该试卷学生得分
47
+    void updateBathStudentPaperScoreByEpid(@Param("epid")Integer epid);
45 48
 }

+ 7
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java Ver arquivo

@@ -5,6 +5,7 @@ import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
5 5
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
6 6
 import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
7 7
 import org.apache.ibatis.annotations.Param;
8
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
8 9
 import org.springframework.stereotype.Repository;
9 10
 
10 11
 import java.util.List;
@@ -37,4 +38,10 @@ public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuest
37 38
 
38 39
     //批量提交试题
39 40
     void updateBatchStuQuestion(@Param("list")List<EPaperStudentQuestion> list);
41
+
42
+    //获取试卷中指定试题作答情况
43
+    List<EPaperStudentQuestion> listPaperStudentQuestionByeptqid(@Param("epid")Integer epid, @Param("eptqids")List<Integer> eptqids);
44
+
45
+    //批量修改学生试题分值
46
+    void updateBatchStuQuestionScore(@Param("list")List<EPaperStudentQuestion> list);
40 47
 }

+ 102
- 1
sexam/src/main/java/com/xhkjedu/sexam/service/paper/EPaperQtypeService.java Ver arquivo

@@ -3,8 +3,12 @@ package com.xhkjedu.sexam.service.paper;
3 3
 import com.alibaba.fastjson.JSON;
4 4
 import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
5 5
 import com.xhkjedu.sexam.mapper.paper.*;
6
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
7
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
6 8
 import com.xhkjedu.sexam.mapper.system.UserBasketMapper;
7 9
 import com.xhkjedu.sexam.model.paper.*;
10
+import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
11
+import com.xhkjedu.sexam.utils.ExamUtil;
8 12
 import com.xhkjedu.sexam.vo.paper.*;
9 13
 import com.xhkjedu.utils.N_Utils;
10 14
 import com.xhkjedu.vo.ResultVo;
@@ -12,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
12 16
 import org.springframework.beans.BeanUtils;
13 17
 import org.springframework.stereotype.Service;
14 18
 import org.springframework.transaction.annotation.Transactional;
19
+import org.w3c.dom.stylesheets.LinkStyle;
15 20
 
16 21
 import javax.annotation.Resource;
17 22
 import java.util.*;
@@ -40,6 +45,10 @@ public class EPaperQtypeService {
40 45
     private EPaperFileMapper ePaperFileMapper;
41 46
     @Resource
42 47
     private UserBasketMapper userBasketMapper;
48
+    @Resource
49
+    private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
50
+    @Resource
51
+    private EPaperStudentMapper ePaperStudentMapper;
43 52
 
44 53
 
45 54
     /**
@@ -517,9 +526,101 @@ public class EPaperQtypeService {
517 526
         ePaperQtypeMapper.updateBatchQuestionAnswer(questions);
518 527
         ePaper.setAnswered(1);
519 528
         ePaperMapper.updateEPaperAnswered(ePaper);
529
+        //设置完答案进行匹配
530
+    }
531
+
532
+    private void setChangeQuestionAnswer(List<EPaperQtypeQuestion> questions,Integer epid){
520 533
         //获取考试对应的状态,如果考试状态未进行中或者已结束,则需要更改学生已提交试卷中对应试题的答案
521
-        Map map = ePaperMapper.getExamPaperAndSubject(ePaper.getEpid());
534
+        Map map = ePaperMapper.getExamPaperAndSubject(epid);
522 535
         Integer examstate = Integer.parseInt(map.get("examstate").toString());
536
+        if(examstate > 0){
537
+            //获取试卷中原试题答案
538
+            List<EPaperQtypeQuestion> yqlist = ePaperQtypeMapper.listQuestionsByEpid(epid);
539
+            List<EPaperQtypeQuestion> changeQs = new ArrayList<>();//改变答案的试题
540
+            for(EPaperQtypeQuestion tq : questions){
541
+                EPaperQtypeQuestion yq = yqlist.stream().filter(y -> y.getEptqid().equals(tq.getEptqid())).findFirst().orElse(null);
542
+                if(!tq.getAnswer().equalsIgnoreCase(yq.getAnswer())){
543
+                    //说明新设置的答案和原设置的答案不一致,则为变动的
544
+                    tq.setCtype(yq.getCtype());
545
+                    tq.setScore(yq.getScore());
546
+                    changeQs.add(tq);
547
+                }
548
+            }
549
+            if(changeQs.size()>0){
550
+                //说明有试题答案变更,则更改学生试卷试题表中原批改内容
551
+                List<Integer> eptqids = changeQs.stream().map(EPaperQtypeQuestion::getEptqid).collect(Collectors.toList());
552
+                //学生试卷试题情况
553
+                List<EPaperStudentQuestion> psqlist = ePaperStudentQuestionMapper.listPaperStudentQuestionByeptqid(epid,eptqids);
554
+                if(N_Utils.isListNotEmpty(psqlist)){
555
+                    List<EPaperStudentQuestion> uplist = new ArrayList<>();//要更新的
556
+                    for(EPaperQtypeQuestion q : changeQs){
557
+                        List<String> qanswers = JSON.parseArray(q.getAnswer(),String.class);
558
+                        //处理指定试题
559
+                        List<EPaperStudentQuestion> cqlist = psqlist.stream().filter(s -> s.getEptqid().equals(q.getEptqid())).collect(Collectors.toList());
560
+                        for(EPaperStudentQuestion cq : cqlist){
561
+                            Double stuscore = 0D;
562
+                            List<String> stuanswers = JSON.parseArray(cq.getStuanswer(),String.class);
563
+                            if(N_Utils.isListEmpty(stuanswers)){
564
+                                break;
565
+                            }else{
566
+                                if(q.getCtype() == 1 || q.getCtype() == 4 || q.getCtype() == 5 || q.getCtype() == 6){
567
+                                    if(q.getAnswer().equalsIgnoreCase(cq.getStuanswer())){
568
+                                        stuscore = q.getScore();
569
+                                    }
570
+                                }else if(q.getCtype() == 2){
571
+                                    if(stuanswers.get(0).length() <= qanswers.get(0).length()){
572
+                                        String[] qanswerList = qanswers.get(0).split("");
573
+                                        String[] stuanswerList = stuanswers.get(0).split("");
574
+                                        int rightNum = 0;//选对个数
575
+                                        for(String sa : stuanswerList){
576
+                                            int right = 0;
577
+                                            for(String qa : qanswerList){
578
+                                                if(qa.equals(sa)){
579
+                                                    right = 1;
580
+                                                    rightNum ++;
581
+                                                }
582
+                                            }
583
+                                            if(right == 0){//说明选错
584
+                                                rightNum = 0;
585
+                                                break;
586
+                                            }
587
+                                        }
588
+                                        if(rightNum>0){
589
+                                            if(qanswerList.length == rightNum){
590
+                                                //全选对
591
+                                                stuscore = q.getScore();
592
+                                            }else if (qanswerList.length > rightNum){
593
+                                                //少选得半分
594
+                                                stuscore = ExamUtil.div(q.getScore(), 2, 1);
595
+                                            }
596
+                                        }
597
+                                    }
598
+                                }else if(q.getCtype() == 7 || q.getCtype() == 8 || q.getCtype() == 10){
599
+                                    //完形填空、阅读理解、任务型阅读
600
+                                    Double qscore = ExamUtil.div(q.getScore(),qanswers.size());
601
+                                    Double stuScoreDouble = 0d;
602
+                                    for(int i=0;i<qanswers.size();i++){
603
+                                        if(qanswers.get(i).equalsIgnoreCase(stuanswers.get(i))){
604
+                                            stuScoreDouble = ExamUtil.add(stuScoreDouble,qscore);
605
+                                        }
606
+                                    }
607
+                                    stuscore = ExamUtil.round(stuScoreDouble,1);
608
+                                }
609
+                                cq.setStuscore(stuscore);
610
+                                uplist.add(cq);
611
+                            }
612
+                        }
613
+                    }
614
+
615
+                    if(N_Utils.isListNotEmpty(uplist)){
616
+                        //批量更新学生试题分值
617
+                        ePaperStudentQuestionMapper.updateBatchStuQuestionScore(uplist);
618
+                        //更新学生试卷分值
619
+                        ePaperStudentMapper.updateBathStudentPaperScoreByEpid(epid);
620
+                    }
621
+                }
622
+            }
623
+        }
523 624
     }
524 625
 
525 626
     /**

+ 10
- 4
sexam/src/main/resources/mapper/paperstudent/EPaperStudentMapper.xml Ver arquivo

@@ -8,7 +8,7 @@
8 8
         e.examname,e.gradeid,e.examtype,ep.epid,ep.ptype
9 9
         from e_paper_student eps left join e_subject es on eps.esid=es.esid
10 10
          left join e_paper ep on eps.epid=ep.epid left join e_base e on eps.examid=e.examid
11
-        where e.deleted=1 and e.monitored=1 and eps.studentid=#{studentid} and e.examstate=1 GROUP BY eps.epsid
11
+        where e.deleted=1 and e.exammode=1 and eps.studentid=#{studentid} and e.examstate=1 GROUP BY eps.epsid
12 12
         order by abs(UNIX_TIMESTAMP(concat(es.sdate,' ',es.begintime))-UNIX_TIMESTAMP())
13 13
     </select>
14 14
 
@@ -44,13 +44,13 @@
44 44
         select ps.epsid,ps.examid,ps.esid,ps.classid,ps.studentid,es.subjectid,es.subjectname,es.sdate,es.begintime,es.endtime,
45 45
                e.examname,ps.epid,p.ptype,p.pnum,p.pscore
46 46
         from e_paper_student ps left join e_subject es on ps.esid=es.esid
47
-        left join e_base e on ps.examid=ps.examid
47
+        left join e_base e on ps.examid=e.examid
48 48
         left join e_paper p on ps.epid=p.epid
49 49
         where ps.epsid=#{epsid}
50 50
     </select>
51 51
     <!--学生试卷题库(android)-->
52 52
     <select id="listStuPaperQuestionsForAndroid" resultType="java.util.Map">
53
-        select distinct psq.epsqid,psq.questionid,psq.qn,psq.qorder,psq.answered,psq.ansertype,psq.stuanswer,
53
+        select distinct psq.epsqid,psq.questionid,psq.qn,psq.qorder,psq.answered,psq.answertype,psq.stuanswer,
54 54
         psq.stuanswertxt,psq.eptqid,pq.score,q.qstem,q.qoption,q.ctype,q.hearfile,q.qtypeid,
55 55
         q.qtypename,q.qlevel,q.snum,q.sorder,q.questionpid,mq.questionid mquestionid,mq.qstem mqstem,
56 56
         mq.qoption mqoption,mq.ctype mctype,mq.qtypeid mqtypeid,mq.qtypename mqtypename
@@ -152,9 +152,15 @@
152 152
 
153 153
     <!--学生提交试卷-->
154 154
     <update id="updateStudentPaper">
155
-        update t_paper_student set endtime=#{endtime},costtime=#{ps.costtime}
155
+        update e_paper_student set endtime=#{endtime},costtime=#{ps.costtime}
156 156
          ,sstate=#{ps.sstate},checked=#{ps.checked}
157 157
          ,stuscore=(SELECT SUM(IFNULL(q.stuscore,0)) FROM e_paper_student_question q WHERE q.epsid=#{ps.epsid})
158 158
         where epsid=#{ps.epsid}
159 159
     </update>
160
+
161
+    <!--批量更新学生试卷分值-->
162
+    <update id="updateBathStudentPaperScoreByEpid">
163
+        update e_paper_student ps set ps.stuscore=(SELECT SUM(IFNULL(q.stuscore,0)) FROM e_paper_student_question q
164
+        WHERE q.epid=#{epid} and q.epsid=ps.epsid) where ps.epid=#{epid}
165
+    </update>
160 166
 </mapper>

+ 36
- 10
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml Ver arquivo

@@ -47,53 +47,79 @@
47 47
         <trim prefix="set" suffixOverrides=",">
48 48
             <trim prefix="answered = case" suffix="end,">
49 49
                 <foreach collection="list" item="q">
50
-                    when eptqid=#{q.eptqid} then #{q.answered}
50
+                    when epsqid=#{q.epsqid} then #{q.answered}
51 51
                 </foreach>
52 52
             </trim>
53 53
             <trim prefix="answertype = case" suffix="end,">
54 54
                 <foreach collection="list" item="q">
55
-                    when eptqid=#{q.eptqid} then #{q.answertype}
55
+                    when epsqid=#{q.epsqid} then #{q.answertype}
56 56
                 </foreach>
57 57
             </trim>
58 58
             <trim prefix="stuanswer = case" suffix="end,">
59 59
                 <foreach collection="list" item="q">
60
-                    when eptqid=#{q.eptqid} then #{q.stuanswer}
60
+                    when epsqid=#{q.epsqid} then #{q.stuanswer}
61 61
                 </foreach>
62 62
             </trim>
63 63
             <trim prefix="stuanswertxt = case" suffix="end,">
64 64
                 <foreach collection="list" item="q">
65
-                    when eptqid=#{q.eptqid} then #{q.stuanswertxt}
65
+                    when epsqid=#{q.epsqid} then #{q.stuanswertxt}
66 66
                 </foreach>
67 67
             </trim>
68 68
             <trim prefix="converted = case" suffix="end,">
69 69
                 <foreach collection="list" item="q">
70
-                    when eptqid=#{q.eptqid} then #{q.converted}
70
+                    when epsqid=#{q.epsqid} then #{q.converted}
71 71
                 </foreach>
72 72
             </trim>
73 73
             <trim prefix="answertime = case" suffix="end,">
74 74
                 <foreach collection="list" item="q">
75
-                    when eptqid=#{q.eptqid} then #{q.answertime}
75
+                    when epsqid=#{q.epsqid} then #{q.answertime}
76 76
                 </foreach>
77 77
             </trim>
78 78
             <trim prefix="stuscore = case" suffix="end,">
79 79
                 <foreach collection="list" item="q">
80
-                    when eptqid=#{q.eptqid} then #{q.stuscore}
80
+                    when epsqid=#{q.epsqid} then #{q.stuscore}
81 81
                 </foreach>
82 82
             </trim>
83 83
             <trim prefix="checked = case" suffix="end,">
84 84
                 <foreach collection="list" item="q">
85
-                    when eptqid=#{q.eptqid} then #{q.checked}
85
+                    when epsqid=#{q.epsqid} then #{q.checked}
86 86
                 </foreach>
87 87
             </trim>
88 88
             <trim prefix="checktime = case" suffix="end,">
89 89
                 <foreach collection="list" item="q">
90
-                    when eptqid=#{q.eptqid} then #{q.checktime}
90
+                    when epsqid=#{q.epsqid} then #{q.checktime}
91 91
                 </foreach>
92 92
             </trim>
93 93
         </trim>
94 94
         <where>
95 95
             <foreach collection="list" item="q" separator="or">
96
-                eptqid=#{q.eptqid}
96
+                epsqid=#{q.epsqid}
97
+            </foreach>
98
+        </where>
99
+    </update>
100
+
101
+    <!--获取试卷中指定试题作答情况-->
102
+    <select id="listPaperStudentQuestionByeptqid" resultType="com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion">
103
+        select epsqid,eptqid,stuanswer,stuscore from e_paper_student_question
104
+        where epid=#{epid} and answered=1 and answertype=1 and eptqid in
105
+        <foreach collection="eptqids" item="eptqid" separator="," open="(" close=")">
106
+            #{eptqid}
107
+        </foreach>
108
+    </select>
109
+
110
+    <!--批量更新试卷中试题分值-->
111
+    <update id="updateBatchStuQuestionScore">
112
+        update e_paper_student_question
113
+        <trim prefix="set" suffixOverrides=",">
114
+            <trim prefix="stuscore = case" suffix="end,">
115
+                <foreach collection="list" item="q">
116
+                    when epsqid=#{q.epsqid} then #{q.stuscore}
117
+                </foreach>
118
+            </trim>
119
+        </trim>
120
+        <where>
121
+            <foreach collection="list" item="q" separator="or">
122
+                epsqid=#{q.epsqid}
97 123
             </foreach>
98 124
         </where>
99 125
     </update>

Carregando…
Cancelar
Salvar