Browse Source

完善修改答案

tags/正式版本
王宁 2 years ago
parent
commit
23e183c23c

+ 3
- 0
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentMapper.java View File

42
 
42
 
43
     //学生提交试卷
43
     //学生提交试卷
44
     int updateStudentPaper(@Param("ps")EPaperStudent ps);
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 View File

5
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
5
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
6
 import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
6
 import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
7
 import org.apache.ibatis.annotations.Param;
7
 import org.apache.ibatis.annotations.Param;
8
+import org.springframework.jmx.export.annotation.ManagedOperationParameter;
8
 import org.springframework.stereotype.Repository;
9
 import org.springframework.stereotype.Repository;
9
 
10
 
10
 import java.util.List;
11
 import java.util.List;
37
 
38
 
38
     //批量提交试题
39
     //批量提交试题
39
     void updateBatchStuQuestion(@Param("list")List<EPaperStudentQuestion> list);
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 View File

3
 import com.alibaba.fastjson.JSON;
3
 import com.alibaba.fastjson.JSON;
4
 import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
4
 import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
5
 import com.xhkjedu.sexam.mapper.paper.*;
5
 import com.xhkjedu.sexam.mapper.paper.*;
6
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
7
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
6
 import com.xhkjedu.sexam.mapper.system.UserBasketMapper;
8
 import com.xhkjedu.sexam.mapper.system.UserBasketMapper;
7
 import com.xhkjedu.sexam.model.paper.*;
9
 import com.xhkjedu.sexam.model.paper.*;
10
+import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
11
+import com.xhkjedu.sexam.utils.ExamUtil;
8
 import com.xhkjedu.sexam.vo.paper.*;
12
 import com.xhkjedu.sexam.vo.paper.*;
9
 import com.xhkjedu.utils.N_Utils;
13
 import com.xhkjedu.utils.N_Utils;
10
 import com.xhkjedu.vo.ResultVo;
14
 import com.xhkjedu.vo.ResultVo;
12
 import org.springframework.beans.BeanUtils;
16
 import org.springframework.beans.BeanUtils;
13
 import org.springframework.stereotype.Service;
17
 import org.springframework.stereotype.Service;
14
 import org.springframework.transaction.annotation.Transactional;
18
 import org.springframework.transaction.annotation.Transactional;
19
+import org.w3c.dom.stylesheets.LinkStyle;
15
 
20
 
16
 import javax.annotation.Resource;
21
 import javax.annotation.Resource;
17
 import java.util.*;
22
 import java.util.*;
40
     private EPaperFileMapper ePaperFileMapper;
45
     private EPaperFileMapper ePaperFileMapper;
41
     @Resource
46
     @Resource
42
     private UserBasketMapper userBasketMapper;
47
     private UserBasketMapper userBasketMapper;
48
+    @Resource
49
+    private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
50
+    @Resource
51
+    private EPaperStudentMapper ePaperStudentMapper;
43
 
52
 
44
 
53
 
45
     /**
54
     /**
517
         ePaperQtypeMapper.updateBatchQuestionAnswer(questions);
526
         ePaperQtypeMapper.updateBatchQuestionAnswer(questions);
518
         ePaper.setAnswered(1);
527
         ePaper.setAnswered(1);
519
         ePaperMapper.updateEPaperAnswered(ePaper);
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
         Integer examstate = Integer.parseInt(map.get("examstate").toString());
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 View File

8
         e.examname,e.gradeid,e.examtype,ep.epid,ep.ptype
8
         e.examname,e.gradeid,e.examtype,ep.epid,ep.ptype
9
         from e_paper_student eps left join e_subject es on eps.esid=es.esid
9
         from e_paper_student eps left join e_subject es on eps.esid=es.esid
10
          left join e_paper ep on eps.epid=ep.epid left join e_base e on eps.examid=e.examid
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
         order by abs(UNIX_TIMESTAMP(concat(es.sdate,' ',es.begintime))-UNIX_TIMESTAMP())
12
         order by abs(UNIX_TIMESTAMP(concat(es.sdate,' ',es.begintime))-UNIX_TIMESTAMP())
13
     </select>
13
     </select>
14
 
14
 
44
         select ps.epsid,ps.examid,ps.esid,ps.classid,ps.studentid,es.subjectid,es.subjectname,es.sdate,es.begintime,es.endtime,
44
         select ps.epsid,ps.examid,ps.esid,ps.classid,ps.studentid,es.subjectid,es.subjectname,es.sdate,es.begintime,es.endtime,
45
                e.examname,ps.epid,p.ptype,p.pnum,p.pscore
45
                e.examname,ps.epid,p.ptype,p.pnum,p.pscore
46
         from e_paper_student ps left join e_subject es on ps.esid=es.esid
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
         left join e_paper p on ps.epid=p.epid
48
         left join e_paper p on ps.epid=p.epid
49
         where ps.epsid=#{epsid}
49
         where ps.epsid=#{epsid}
50
     </select>
50
     </select>
51
     <!--学生试卷题库(android)-->
51
     <!--学生试卷题库(android)-->
52
     <select id="listStuPaperQuestionsForAndroid" resultType="java.util.Map">
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
         psq.stuanswertxt,psq.eptqid,pq.score,q.qstem,q.qoption,q.ctype,q.hearfile,q.qtypeid,
54
         psq.stuanswertxt,psq.eptqid,pq.score,q.qstem,q.qoption,q.ctype,q.hearfile,q.qtypeid,
55
         q.qtypename,q.qlevel,q.snum,q.sorder,q.questionpid,mq.questionid mquestionid,mq.qstem mqstem,
55
         q.qtypename,q.qlevel,q.snum,q.sorder,q.questionpid,mq.questionid mquestionid,mq.qstem mqstem,
56
         mq.qoption mqoption,mq.ctype mctype,mq.qtypeid mqtypeid,mq.qtypename mqtypename
56
         mq.qoption mqoption,mq.ctype mctype,mq.qtypeid mqtypeid,mq.qtypename mqtypename
152
 
152
 
153
     <!--学生提交试卷-->
153
     <!--学生提交试卷-->
154
     <update id="updateStudentPaper">
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
          ,sstate=#{ps.sstate},checked=#{ps.checked}
156
          ,sstate=#{ps.sstate},checked=#{ps.checked}
157
          ,stuscore=(SELECT SUM(IFNULL(q.stuscore,0)) FROM e_paper_student_question q WHERE q.epsid=#{ps.epsid})
157
          ,stuscore=(SELECT SUM(IFNULL(q.stuscore,0)) FROM e_paper_student_question q WHERE q.epsid=#{ps.epsid})
158
         where epsid=#{ps.epsid}
158
         where epsid=#{ps.epsid}
159
     </update>
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
 </mapper>
166
 </mapper>

+ 36
- 10
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml View File

47
         <trim prefix="set" suffixOverrides=",">
47
         <trim prefix="set" suffixOverrides=",">
48
             <trim prefix="answered = case" suffix="end,">
48
             <trim prefix="answered = case" suffix="end,">
49
                 <foreach collection="list" item="q">
49
                 <foreach collection="list" item="q">
50
-                    when eptqid=#{q.eptqid} then #{q.answered}
50
+                    when epsqid=#{q.epsqid} then #{q.answered}
51
                 </foreach>
51
                 </foreach>
52
             </trim>
52
             </trim>
53
             <trim prefix="answertype = case" suffix="end,">
53
             <trim prefix="answertype = case" suffix="end,">
54
                 <foreach collection="list" item="q">
54
                 <foreach collection="list" item="q">
55
-                    when eptqid=#{q.eptqid} then #{q.answertype}
55
+                    when epsqid=#{q.epsqid} then #{q.answertype}
56
                 </foreach>
56
                 </foreach>
57
             </trim>
57
             </trim>
58
             <trim prefix="stuanswer = case" suffix="end,">
58
             <trim prefix="stuanswer = case" suffix="end,">
59
                 <foreach collection="list" item="q">
59
                 <foreach collection="list" item="q">
60
-                    when eptqid=#{q.eptqid} then #{q.stuanswer}
60
+                    when epsqid=#{q.epsqid} then #{q.stuanswer}
61
                 </foreach>
61
                 </foreach>
62
             </trim>
62
             </trim>
63
             <trim prefix="stuanswertxt = case" suffix="end,">
63
             <trim prefix="stuanswertxt = case" suffix="end,">
64
                 <foreach collection="list" item="q">
64
                 <foreach collection="list" item="q">
65
-                    when eptqid=#{q.eptqid} then #{q.stuanswertxt}
65
+                    when epsqid=#{q.epsqid} then #{q.stuanswertxt}
66
                 </foreach>
66
                 </foreach>
67
             </trim>
67
             </trim>
68
             <trim prefix="converted = case" suffix="end,">
68
             <trim prefix="converted = case" suffix="end,">
69
                 <foreach collection="list" item="q">
69
                 <foreach collection="list" item="q">
70
-                    when eptqid=#{q.eptqid} then #{q.converted}
70
+                    when epsqid=#{q.epsqid} then #{q.converted}
71
                 </foreach>
71
                 </foreach>
72
             </trim>
72
             </trim>
73
             <trim prefix="answertime = case" suffix="end,">
73
             <trim prefix="answertime = case" suffix="end,">
74
                 <foreach collection="list" item="q">
74
                 <foreach collection="list" item="q">
75
-                    when eptqid=#{q.eptqid} then #{q.answertime}
75
+                    when epsqid=#{q.epsqid} then #{q.answertime}
76
                 </foreach>
76
                 </foreach>
77
             </trim>
77
             </trim>
78
             <trim prefix="stuscore = case" suffix="end,">
78
             <trim prefix="stuscore = case" suffix="end,">
79
                 <foreach collection="list" item="q">
79
                 <foreach collection="list" item="q">
80
-                    when eptqid=#{q.eptqid} then #{q.stuscore}
80
+                    when epsqid=#{q.epsqid} then #{q.stuscore}
81
                 </foreach>
81
                 </foreach>
82
             </trim>
82
             </trim>
83
             <trim prefix="checked = case" suffix="end,">
83
             <trim prefix="checked = case" suffix="end,">
84
                 <foreach collection="list" item="q">
84
                 <foreach collection="list" item="q">
85
-                    when eptqid=#{q.eptqid} then #{q.checked}
85
+                    when epsqid=#{q.epsqid} then #{q.checked}
86
                 </foreach>
86
                 </foreach>
87
             </trim>
87
             </trim>
88
             <trim prefix="checktime = case" suffix="end,">
88
             <trim prefix="checktime = case" suffix="end,">
89
                 <foreach collection="list" item="q">
89
                 <foreach collection="list" item="q">
90
-                    when eptqid=#{q.eptqid} then #{q.checktime}
90
+                    when epsqid=#{q.epsqid} then #{q.checktime}
91
                 </foreach>
91
                 </foreach>
92
             </trim>
92
             </trim>
93
         </trim>
93
         </trim>
94
         <where>
94
         <where>
95
             <foreach collection="list" item="q" separator="or">
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
             </foreach>
123
             </foreach>
98
         </where>
124
         </where>
99
     </update>
125
     </update>

Loading…
Cancel
Save