Ver código fonte

课堂保存事务优化,删除无用代码

tags/正式3.14.2^2
王宁 3 meses atrás
pai
commit
bdf4576ae9

+ 2
- 177
sclass/src/main/java/com/xhkjedu/sclass/service/classroom/ClassroomService.java Ver arquivo

@@ -13,10 +13,8 @@ import com.xhkjedu.utils.N_Utils;
13 13
 import com.xhkjedu.vo.ResultVo;
14 14
 import com.xhkjedu.vo.system.UserVo;
15 15
 import lombok.extern.slf4j.Slf4j;
16
-import org.springframework.dao.DuplicateKeyException;
17 16
 import org.springframework.stereotype.Service;
18 17
 import org.springframework.transaction.annotation.Transactional;
19
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
20 18
 import org.springframework.util.CollectionUtils;
21 19
 
22 20
 import javax.annotation.Resource;
@@ -63,178 +61,6 @@ public class ClassroomService {
63 61
     @Resource
64 62
     private ClassroomProfileStudentMapper classroomProfileStudentMapper;
65 63
 
66
-    /**
67
-     * 开始课堂
68
-     *
69
-     * @return void
70
-     * @Param [room]
71
-     * @Author ywx
72
-     * @Date 2020/7/14 17:17
73
-     **/
74
-    @Transactional(rollbackFor = Exception.class)
75
-    public boolean startClass(TClassroom room) {
76
-        boolean rtn = false;//课堂是否重复请求
77
-        try {
78
-            room.setRoomstate(1);
79
-            Integer num = classroomMapper.getStudentNumById(room.getClassid());//根据班级id获取学生数量
80
-            room.setClassnum(num);
81
-            classroomMapper.save(room);
82
-            classroomActivestudentMapper.saveStuActive(room.getRoomid(), room.getClassid(), room.getSchoolid(), N_Utils.getSecondTimestamp());
83
-        } catch (Exception e) {
84
-            if (e instanceof DuplicateKeyException) {
85
-                rtn = true;
86
-                log.error("接口重复请求,课堂id:" + room.getRoomid() + ",课堂名称:" + room.getRoomname());
87
-            } else {
88
-                log.error("开始课堂失败:" + e.getMessage());
89
-            }
90
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
91
-        }
92
-        return rtn;
93
-    }
94
-
95
-    /**
96
-     * 结束课堂
97
-     *
98
-     * @return void
99
-     * @Param [room]
100
-     * @Author ywx
101
-     * @Date 2020/7/14 17:17
102
-     **/
103
-    @Transactional(rollbackFor = Exception.class)
104
-    public void stopClass(TClassroom room) {
105
-        try {
106
-            Long roomid = room.getRoomid();
107
-            if (N_Utils.isEmptyInteger(room.getEndtime())) {//异常结束:结束时间=开始时间+45分钟
108
-                TClassroom tClassroom = classroomMapper.selectByPrimaryKey(roomid);
109
-                room.setEndtime(tClassroom.getCreatetime() + 60 * 45);
110
-            }
111
-            classroomMapper.endClass(room);//结束课堂
112
-            classroomActivestudentMapper.updateActiveRank(roomid);//更新活跃值排名
113
-        } catch (Exception e) {
114
-            log.error("结束课堂失败:" + e.getMessage());
115
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
116
-        }
117
-    }
118
-
119
-    /**
120
-     * 保存学生签到信息
121
-     *
122
-     * @return void
123
-     * @Param [sign]
124
-     * @Author ywx
125
-     * @Date 2020/7/14 16:32
126
-     **/
127
-    @Transactional(rollbackFor = Exception.class)
128
-    public void saveStudentSign(TClassroomSign sign) {
129
-        try {
130
-            Long roomid = sign.getRoomid();
131
-            Integer userid = sign.getUserid();
132
-            List<Integer> studentids = classroomMapper.listStudentId(roomid);//获取班级学生id集合
133
-            if (N_Utils.numInList(userid, studentids)) {//签到学生是本课堂所在班级学生,添加签到信息
134
-                classroomSignMapper.save(sign);
135
-                //如果一个学生退出课堂再进来数据就不对了,最后计算
136
-                //classroomMapper.updateRealStuNum(sign.getRoomid());//更新班级实际签到学生数量
137
-                classroomActivestudentMapper.updateActiveNum(roomid, userid);//更新学生活跃值
138
-            }
139
-        } catch (Exception e) {
140
-            log.error("保存学生签到信息失败:" + e.getMessage());
141
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
142
-        }
143
-    }
144
-
145
-    /**
146
-     * 功能描述 最后更新课堂名称
147
-     *
148
-     * @param * @param roomlist
149
-     * @return void
150
-     * @author WN
151
-     * @date 2020/8/14
152
-     */
153
-    public void updateBatchRoomRealStunum(List<Long> roomlist) {
154
-        classroomMapper.updateBatchRoomRealStunum(roomlist);
155
-    }
156
-
157
-    /**
158
-     * 互动发起
159
-     *
160
-     * @return void
161
-     * @Param [teacher]
162
-     * @Author ywx
163
-     * @Date 2020/6/15 9:58
164
-     **/
165
-    public void saveWork(TClassroomAskteacher teacher) {
166
-        try {
167
-            if (teacher.getPaperid() == null) {
168
-                teacher.setPaperid(0L);
169
-            }
170
-            if (teacher.getRadionum() == null) {
171
-                teacher.setRadionum(0);
172
-            }
173
-            classroomAskteacherMapper.save(teacher);
174
-        } catch (Exception e) {
175
-            log.error("互动发起失败:" + e.getMessage());
176
-        }
177
-    }
178
-
179
-    /**
180
-     * 保存学生作答情况
181
-     *
182
-     * @return void
183
-     * @Param [student]
184
-     * @Author ywx
185
-     * @Date 2020/7/14 16:34
186
-     **/
187
-    @Transactional(rollbackFor = Exception.class)
188
-    public void saveStuAnswer(TClassroomAskstudent student) {
189
-        try {
190
-            if (student.getStudentradio() == null) {
191
-                student.setStudentradio("");
192
-            }
193
-            if (student.getStudentpic() == null) {
194
-                student.setStudentpic("");
195
-            }
196
-            if (student.getRadiocorrect() == null) {
197
-                student.setRadiocorrect(0);
198
-            }
199
-            if (student.getStudentselected() == null) {
200
-                student.setStudentselected(0);
201
-            }
202
-            classroomAskstudentMapper.save(student);
203
-            //保存成功更新学生活跃值
204
-            classroomActivestudentMapper.updateActiveNum(student.getRoomid(), student.getStudentid());
205
-        } catch (Exception e) {
206
-            log.error("保存学生作答情况失败:" + e.getMessage());
207
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
208
-        }
209
-    }
210
-
211
-    /**
212
-     * 保存课堂图片
213
-     *
214
-     * @return void
215
-     * @Param [file]
216
-     * @Author ywx
217
-     * @Date 2020/7/14 16:42
218
-     **/
219
-    public void saveFile(TClassroomFile file) {
220
-        try {
221
-            classroomFileMapper.save(file);
222
-        } catch (Exception e) {
223
-            log.error("批量保存课堂图片失败:" + e.getMessage());
224
-        }
225
-    }
226
-
227
-    /**
228
-     * 功能描述 批量结束班级之前的课堂
229
-     *
230
-     * @param * @param classidlist
231
-     * @return void
232
-     * @author WN
233
-     * @date 2020/8/14
234
-     */
235
-    public void updateBatchRoomState(List<Integer> classidlist) {
236
-        classroomMapper.updateBatchRoomState(classidlist);
237
-    }
238 64
 
239 65
     /**
240 66
      * 获取批阅信息
@@ -632,7 +458,7 @@ public class ClassroomService {
632 458
             log.error("批量保存课堂数据失败:" + e.getMessage());
633 459
             log.error(JSON.toJSONString(rooms));
634 460
             resultVo.setMsg("保存失败");
635
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
461
+            throw new RuntimeException(e.getMessage());
636 462
         }
637 463
         return resultVo;
638 464
     }
@@ -851,8 +677,7 @@ public class ClassroomService {
851 677
             log.error("批量保存课堂数据失败:" + e.getMessage());
852 678
             log.error(JSON.toJSONString(r));
853 679
             resultVo.setMsg("保存失败");
854
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
855
-            return resultVo;
680
+            throw new RuntimeException("保存失败");
856 681
         }
857 682
         return resultVo;
858 683
     }

Carregando…
Cancelar
Salvar