Selaa lähdekoodia

课堂学生考试计算分数和批改状态

密保问题删除
教师基本信息
tags/正式3.2.0
雍文秀 2 vuotta sitten
vanhempi
commit
390856b12f

+ 3
- 0
sclass/src/main/java/com/xhkjedu/sclass/mapper/classroom/ClassroomPaperStudentMapper.java Näytä tiedosto

@@ -27,4 +27,7 @@ public interface ClassroomPaperStudentMapper extends TkMapper<TClassroomPaperStu
27 27
 
28 28
     //考试按人统计
29 29
     List<Map> listEStudent(Long paperid);
30
+
31
+    //修改学生得分和批改状态
32
+    void updateScantronStuScoreAndChecked(Integer psid, Double userscore, Integer pschecked);
30 33
 }

+ 98
- 12
sclass/src/main/java/com/xhkjedu/sclass/service/classroom/ClassroomPaperService.java Näytä tiedosto

@@ -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();

+ 112
- 0
sclass/src/main/java/com/xhkjedu/sclass/utils/ArithUtil.java Näytä tiedosto

@@ -0,0 +1,112 @@
1
+package com.xhkjedu.sclass.utils;
2
+
3
+import java.math.BigDecimal;
4
+
5
+/**
6
+ * @author ywx
7
+ * @className ArithUtil
8
+ * @description double计算工具类
9
+ * @date 2021/10/21 13:42
10
+ **/
11
+public class ArithUtil {
12
+    // 默认除法运算精度
13
+    private static final int DEF_DIV_SCALE = 2;
14
+
15
+    /**
16
+     * 提供精确的加法运算。
17
+     * @param v1
18
+     *            被加数
19
+     * @param v2
20
+     *            加数
21
+     * @return 两个参数的和
22
+     */
23
+    public static double add(double v1, double v2)
24
+    {
25
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
26
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
27
+        return b1.add(b2).doubleValue();
28
+    }
29
+
30
+    /**
31
+     * 提供精确的减法运算。
32
+     * @param v1
33
+     *            被减数
34
+     * @param v2
35
+     *            减数
36
+     * @return 两个参数的差
37
+     */
38
+    public static double sub(double v1, double v2)
39
+    {
40
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
41
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
42
+        return b1.subtract(b2).doubleValue();
43
+    }
44
+
45
+    /**
46
+     * 提供精确的乘法运算。
47
+     * @param v1
48
+     *            被乘数
49
+     * @param v2
50
+     *            乘数
51
+     * @return 两个参数的积
52
+     */
53
+    public static double mul(double v1, double v2)
54
+    {
55
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
56
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
57
+        return b1.multiply(b2).doubleValue();
58
+    }
59
+
60
+    /**
61
+     * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字舍弃。
62
+     * @param v1
63
+     *            被除数
64
+     * @param v2
65
+     *            除数
66
+     * @return 两个参数的商
67
+     */
68
+    public static double div(double v1, double v2)
69
+    {
70
+        return div(v1, v2, DEF_DIV_SCALE);
71
+    }
72
+
73
+    /**
74
+     * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字舍弃。
75
+     * @param v1
76
+     *            被除数
77
+     * @param v2
78
+     *            除数
79
+     * @param scale
80
+     *            表示表示需要精确到小数点以后几位。
81
+     * @return 两个参数的商
82
+     */
83
+    public static double div(double v1, double v2, int scale)
84
+    {
85
+        if (scale < 0)
86
+        {
87
+            throw new IllegalArgumentException("The   scale   must   be   a   positive   integer   or   zero");
88
+        }
89
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
90
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
91
+        return b1.divide(b2, scale, BigDecimal.ROUND_DOWN).doubleValue();
92
+    }
93
+
94
+    /**
95
+     * 提供精确的小数位四舍五入处理。
96
+     * @param v
97
+     *            需要四舍五入的数字
98
+     * @param scale
99
+     *            小数点后保留几位
100
+     * @return 四舍五入后的结果
101
+     */
102
+    public static double round(double v, int scale)
103
+    {
104
+        if (scale < 0)
105
+        {
106
+            throw new IllegalArgumentException("The   scale   must   be   a   positive   integer   or   zero");
107
+        }
108
+        BigDecimal b = new BigDecimal(Double.toString(v));
109
+        BigDecimal one = new BigDecimal("1");
110
+        return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
111
+    }
112
+}

+ 4
- 0
sclass/src/main/resources/mapper/classroom/ClassroomPaperStudentMapper.xml Näytä tiedosto

@@ -31,4 +31,8 @@
31 31
         where ps.paperid=#{paperid}
32 32
         order by ps.stuscore desc
33 33
     </select>
34
+    <!--修改学生得分和批改状态-->
35
+    <update id="updateScantronStuScoreAndChecked">
36
+        update t_classroom_paper_student set stuscore=#{stuscore},pschecked=#{pschecked} where psid=#{psid}
37
+    </update>
34 38
 </mapper>

+ 1
- 1
suser/src/main/java/com/xhkjedu/suser/controller/system/UsecretController.java Näytä tiedosto

@@ -59,7 +59,7 @@ public class UsecretController {
59 59
     @PostMapping("/delete")
60 60
     public ResultVo delete(@RequestBody TUsecret usecret) {
61 61
         Integer usid = usecret.getUsid();
62
-        N_Utils.validation(new Object[]{usid, "密保问题id"});
62
+        N_Utils.validation(new Object[]{usid, "密保问题id", 1});
63 63
         return usecretService.deleteById(usid);
64 64
     }
65 65
 

+ 1
- 2
suser/src/main/java/com/xhkjedu/suser/controller/system/UserController.java Näytä tiedosto

@@ -6,7 +6,6 @@ import com.xhkjedu.suser.model.system.TUserUsecret;
6 6
 import com.xhkjedu.suser.service.system.UserService;
7 7
 import com.xhkjedu.suser.utils.UserUtil;
8 8
 import com.xhkjedu.suser.vo.assess.AssessParams;
9
-import com.xhkjedu.suser.vo.system.TeacherVo;
10 9
 import com.xhkjedu.utils.N_Utils;
11 10
 import com.xhkjedu.vo.ResultVo;
12 11
 import org.springframework.beans.factory.annotation.Autowired;
@@ -261,7 +260,7 @@ public class UserController {
261 260
     public ResultVo teacherInfo(@RequestBody TUser user) {
262 261
         Integer userid = user.getUserid();
263 262
         N_Utils.validation(new Object[]{userid, "用户id", 1, user.getSchoolid(), "学校id", 1});
264
-        TeacherVo teacherVo = userService.getTeacherInfo(user.getSchoolid(), userid, user.getClasstype());
263
+        Map teacherVo = userService.getTeacherInfo(user.getSchoolid(), userid, user.getClasstype());
265 264
         return new ResultVo(0, "获取教师基本信息成功", teacherVo);
266 265
     }
267 266
 

+ 1
- 2
suser/src/main/java/com/xhkjedu/suser/mapper/system/UserMapper.java Näytä tiedosto

@@ -3,7 +3,6 @@ package com.xhkjedu.suser.mapper.system;
3 3
 import com.xhkjedu.suser.base.TkMapper;
4 4
 import com.xhkjedu.suser.model.system.TUser;
5 5
 import com.xhkjedu.suser.vo.assess.AssessParams;
6
-import com.xhkjedu.suser.vo.system.TeacherVo;
7 6
 import com.xhkjedu.suser.vo.system.UserVo;
8 7
 import org.apache.ibatis.annotations.Param;
9 8
 import org.springframework.stereotype.Repository;
@@ -140,7 +139,7 @@ public interface UserMapper extends TkMapper<TUser> {
140 139
      * @Author ywx
141 140
      * @Date 2020/6/29 16:24
142 141
      **/
143
-    TeacherVo getTeacherInfo(Integer userid, Integer classtype, Integer year);
142
+    Map getTeacherInfo(Integer userid, Integer classtype, Integer year);
144 143
 
145 144
     /**
146 145
      * 更新学生硬件绑定信息

+ 1
- 2
suser/src/main/java/com/xhkjedu/suser/service/system/UserService.java Näytä tiedosto

@@ -20,7 +20,6 @@ import com.xhkjedu.suser.utils.PoiUtils;
20 20
 import com.xhkjedu.suser.utils.SMSSender;
21 21
 import com.xhkjedu.suser.utils.UserUtil;
22 22
 import com.xhkjedu.suser.vo.assess.AssessParams;
23
-import com.xhkjedu.suser.vo.system.TeacherVo;
24 23
 import com.xhkjedu.suser.vo.system.UserVo;
25 24
 import com.xhkjedu.suser.vo.system.ZtMsgVo;
26 25
 import com.xhkjedu.utils.*;
@@ -579,7 +578,7 @@ public class UserService extends JedisUtil {
579 578
      * @Author ywx
580 579
      * @Date 2020/6/29 16:23
581 580
      **/
582
-    public TeacherVo getTeacherInfo(Integer schoolid, Integer userid, Integer classtype) {
581
+    public Map getTeacherInfo(Integer schoolid, Integer userid, Integer classtype) {
583 582
         Integer year = schoolMapper.getYearById(schoolid);
584 583
         return userMapper.getTeacherInfo(userid, classtype, year);
585 584
     }

+ 17
- 11
suser/src/main/resources/mapper/system/UserMapper.xml Näytä tiedosto

@@ -84,23 +84,25 @@
84 84
         select count(*) from t_user where userid=#{userid} and opepassword=#{opepassword}
85 85
     </select>
86 86
 
87
-    <resultMap id="teacherInfoMap" type="com.xhkjedu.suser.vo.system.TeacherVo">
87
+    <resultMap id="teacherInfoMap" type="java.util.Map">
88 88
         <result property="userid" column="userid"></result>
89 89
         <result property="username" column="username"></result>
90 90
         <result property="headpic" column="headpic"></result>
91 91
         <result property="subjectname" column="subjectname"></result>
92
-        <collection property="classlist" ofType="com.xhkjedu.suser.vo.gradeclass.ClassVo"
92
+        <result property="loginname" column="loginname"></result>
93
+        <result property="usersex" column="usersex"></result>
94
+        <result property="userphone" column="userphone"></result>
95
+        <result property="usertime" column="usertime"></result>
96
+        <result property="createtime" column="createtime"></result>
97
+        <result property="lsbname" column="lsbname"></result>
98
+        <result property="rolename" column="rolename"></result>
99
+        <collection property="classlist" ofType="java.util.Map"
93 100
                     javaType="java.util.List" select="listTeacherClass" column="{userid=userid,classtype=classtype,year=year}">
94 101
         </collection>
95 102
     </resultMap>
96 103
 
97
-    <resultMap id="teacherClass" type="com.xhkjedu.suser.vo.gradeclass.ClassVo">
98
-        <result property="classid" column="classid"></result>
99
-        <result property="classname" column="classname"></result>
100
-        <result property="gradeid" column="gradeid"></result>
101
-    </resultMap>
102 104
     <!--教师任教班级-->
103
-    <select id="listTeacherClass" resultMap="teacherClass">
105
+    <select id="listTeacherClass" resultType="java.util.Map">
104 106
         select c.classid,c.classname,c.gradeid from t_class c
105 107
         left join t_class_teacher ct on c.classid=ct.classid
106 108
         where ct.teacherid=#{userid} and c.classstate=1 and c.year=#{year}
@@ -113,15 +115,19 @@
113 115
         </if>
114 116
         order by c.gradeid,c.classtype,c.classorder
115 117
     </select>
116
-
117 118
     <!--教师基本信息-->
118 119
     <select id="getTeacherInfo" resultMap="teacherInfoMap">
119
-        select u.userid,u.username,u.headpic,group_concat(distinct s.subjectname order by s.subjectorder)subjectname
120
-        ,#{classtype} classtype,u.usertime,#{year} year
120
+        select u.userid,u.username,u.headpic,u.loginname,u.usersex,u.userphone,u.usertime,u.createtime
121
+        ,group_concat(distinct s.subjectname order by s.subjectorder)subjectname
122
+        ,group_concat(concat(s.subjectname,'-',v.versionname,'-',sb.lsbname) separator '  ')lsbname
123
+        ,(select group_concat(r.rolename separator '  ')
124
+        from t_user_role ur left join t_role r on ur.roleid=r.roleid where ur.userid=#{userid})rolename
125
+        ,#{classtype} classtype,#{year} year
121 126
         from t_user u
122 127
         left join t_teacher_powersb ts on u.userid = ts.teacherid
123 128
         left join t_subject_book sb on ts.lsbid=sb.lsbid
124 129
         left join t_subject s on sb.subjectid=s.subjectid
130
+        LEFT JOIN t_version v ON sb.versionid=v.versionid
125 131
         where u.userid=#{userid}
126 132
     </select>
127 133
     <!--更新学生硬件绑定信息-->

Loading…
Peruuta
Tallenna