Browse Source

保存单个课堂数据

tags/正式3.3.0
雍文秀 2 years ago
parent
commit
e850cd0b98

+ 108
- 0
sclass/src/main/java/com/xhkjedu/sclass/controller/classroom/ClassroomController.java View File

@@ -163,6 +163,114 @@ public class ClassroomController {
163 163
                 , paperList, stupaperList, paperFileList, paperQtypeList, paperScantronList);
164 164
     }
165 165
 
166
+    /**
167
+     * 保存单个课堂数据
168
+     *
169
+     * @return com.xhkjedu.vo.ResultVo
170
+     * @Param [r]
171
+     * @Author ywx
172
+     * @Date 2022/6/30 11:23
173
+     **/
174
+    @PostMapping("/save_class")
175
+    public ResultVo saveOneClass(@RequestBody RoomPVo r) {
176
+        String roomname = classroomService.getNameById(r.getRoomid());
177
+        //课堂数据已经存在直接返回保存成功
178
+        if (N_Utils.isNotEmpty(roomname)) return new ResultVo(0, "保存成功");
179
+
180
+        TClassroom startclass = new TClassroom();//开始课堂
181
+        TClassroom stopclass = new TClassroom();//结束课堂
182
+        List<TClassroomFile> savefileList = new ArrayList<>();//结束课堂集合
183
+        List<TClassroomAskteacher> askteacherList = new ArrayList<>();//结束课堂集合
184
+        List<TClassroomAskstudent> askstudentList = new ArrayList<>();//结束课堂集合
185
+        List<TClassroomSign> signList = new ArrayList<>();//结束课堂集合
186
+        List<TClassroomActivestudent> activestudentList = new ArrayList<>();//结束课堂集合
187
+        List<TClassroomPaper> paperList = new ArrayList<>();//结束课堂集合
188
+        List<TClassroomPaperStudent> stupaperList = new ArrayList<>();//结束课堂集合
189
+        List<TClassroomPaperFile> paperFileList = new ArrayList<>();//堂测附件集合
190
+        List<TClassroomPaperQtype> paperQtypeList = new ArrayList<>();//堂测答题卡集合
191
+        List<TClassroomPaperScantron> paperScantronList = new ArrayList<>();//堂测答题卡--题型试题集合
192
+        List<RoomParamVo> params = r.getParams();
193
+        for (RoomParamVo param : params) {
194
+            String rtype = param.getRtype();
195
+            String jsonstr = param.getJsonstr();
196
+            N_Utils.validation(new Object[]{rtype, "请求类型", 2, jsonstr, "请求json", 2});
197
+            if (rtype.equals("startclass")) {//课堂--开始
198
+                startclass = JSON.parseObject(jsonstr, TClassroom.class);
199
+            } else if (rtype.equals("stopclass")) {//课堂--结束
200
+                stopclass = JSON.parseObject(jsonstr, TClassroom.class);
201
+            } else if (rtype.equals("savefile")) {//课堂--保存图片
202
+                TClassroomFile file = JSON.parseObject(jsonstr, TClassroomFile.class);
203
+                if (N_Utils.isNotEmpty(file.getRfpath())) savefileList.add(file);
204
+            } else if (rtype.equals("askteacher")) {//互动--发起
205
+                TClassroomAskteacher teacher = JSON.parseObject(jsonstr, TClassroomAskteacher.class);
206
+                askteacherList.add(teacher);
207
+            } else if (rtype.equals("askstudent")) {//互动--保存学生作答情况
208
+                TClassroomAskstudent student = JSON.parseObject(jsonstr, TClassroomAskstudent.class);
209
+                askstudentList.add(student);
210
+                TClassroomActivestudent as = new TClassroomActivestudent();
211
+                as.setRoomid(student.getRoomid());
212
+                as.setStudentid(student.getStudentid());
213
+                activestudentList.add(as);
214
+            } else if (rtype.equals("sign")) {//学生--签到
215
+                TClassroomSign sign = JSON.parseObject(jsonstr, TClassroomSign.class);
216
+                signList.add(sign);
217
+                TClassroomActivestudent as = new TClassroomActivestudent();
218
+                as.setRoomid(sign.getRoomid());
219
+                as.setStudentid(sign.getUserid());
220
+                activestudentList.add(as);
221
+            } else if (rtype.equals("paper")) {//堂测--发布
222
+                TClassroomPaper paper = JSON.parseObject(jsonstr, TClassroomPaper.class);
223
+
224
+                //堂测附件
225
+                List<TClassroomPaperFile> lst = paper.getPfiles();
226
+                for (TClassroomPaperFile pf : lst) {
227
+                    if (N_Utils.isEmpty(pf.getFilepath())) continue;//地址为空不处理
228
+                    pf.setCreateid(paper.getCreateid());
229
+                    pf.setCreatetime(N_Utils.getSecondTimestamp());
230
+                    pf.setSchoolid(paper.getSchoolid());
231
+                    pf.setPaperid(paper.getPaperid());
232
+                    paperFileList.add(pf);
233
+                }
234
+
235
+                //答题卡信息
236
+                int sorder = 1;//答题卡试题序号
237
+                int qtypeorder = 1;//答题卡题型序号
238
+                //处理答题卡--题型--试题
239
+                List<TClassroomPaperQtype> qtypes = paper.getQtypes();
240
+                for (TClassroomPaperQtype qtype : qtypes) {
241
+                    List<TClassroomPaperScantron> scanlst = qtype.getScantrons();//题型下试题
242
+                    qtype.setCreateid(paper.getCreateid());
243
+                    qtype.setCreatetime(paper.getCreatetime());
244
+                    qtype.setSchoolid(paper.getSchoolid());
245
+                    qtype.setPqnum(scanlst.size());
246
+                    Double qtypescore = scanlst.stream().collect(Collectors.summingDouble(TClassroomPaperScantron::getPsscore));
247
+                    qtype.setPqscore(qtypescore);
248
+                    qtype.setPaperid(paper.getPaperid());
249
+                    qtype.setPqorder(qtypeorder);
250
+                    paperQtypeList.add(qtype);
251
+                    qtypeorder++;
252
+
253
+                    for (TClassroomPaperScantron sc : scanlst) {
254
+                        sc.setCreateid(paper.getCreateid());
255
+                        sc.setCreatetime(N_Utils.getSecondTimestamp());
256
+                        sc.setSchoolid(paper.getSchoolid());
257
+                        sc.setPaperid(paper.getPaperid());
258
+                        sc.setPsorder(sorder);
259
+                        paperScantronList.add(sc);
260
+                        sorder++;
261
+                    }
262
+                }
263
+                paperList.add(paper);
264
+            } else if (rtype.equals("stupaper")) {//堂测--学生作答详情
265
+                TClassroomPaperStudent student = JSON.parseObject(jsonstr, TClassroomPaperStudent.class);
266
+                stupaperList.add(student);
267
+            }
268
+        }
269
+        return classroomService.saveClass(startclass, stopclass, savefileList
270
+                , askteacherList, askstudentList, signList, activestudentList
271
+                , paperList, stupaperList, paperFileList, paperQtypeList, paperScantronList);
272
+    }
273
+
166 274
     @PostMapping("/list_correct")
167 275
     public ResultVo listCorrect(@RequestBody RoomVo room) {
168 276
         Long roomid = room.getRoomid();

+ 3
- 0
sclass/src/main/java/com/xhkjedu/sclass/mapper/classroom/ClassroomMapper.java View File

@@ -270,4 +270,7 @@ public interface ClassroomMapper extends TkMapper<TClassroom> {
270 270
 
271 271
     //根据班级ids获取学生数量
272 272
     List<TClassroom> listStudentNumByClassIds(@Param("classids") List<Integer> classids);
273
+
274
+    //根据课堂id获取课堂名称
275
+    String getNameById(@Param("roomid") Long roomid);
273 276
 }

+ 79
- 0
sclass/src/main/java/com/xhkjedu/sclass/service/classroom/ClassroomService.java View File

@@ -730,4 +730,83 @@ public class ClassroomService {
730 730
             studentScoreList.add(ps);
731 731
         }
732 732
     }
733
+
734
+    /**
735
+     * 保存单个课堂数据
736
+     *
737
+     * @return com.xhkjedu.vo.ResultVo
738
+     * @Param [startclass, stopclass, savefileList, askteacherList, askstudentList, signList, activestudentList
739
+     * , paperList, stupaperList, paperFileList, paperQtypeList, paperScantronList]
740
+     * @Author ywx
741
+     * @Date 2022/6/30 11:12
742
+     **/
743
+    public ResultVo saveClass(TClassroom startclass, TClassroom stopclass, List<TClassroomFile> savefileList
744
+            , List<TClassroomAskteacher> askteacherList, List<TClassroomAskstudent> askstudentList, List<TClassroomSign> signList
745
+            , List<TClassroomActivestudent> activestudentList, List<TClassroomPaper> paperList
746
+            , List<TClassroomPaperStudent> stupaperList, List<TClassroomPaperFile> paperFileList
747
+            , List<TClassroomPaperQtype> paperQtypeList, List<TClassroomPaperScantron> paperScantronList) {
748
+        ResultVo resultVo = new ResultVo();
749
+        resultVo.setCode(1);
750
+        try {
751
+            if (startclass == null) return new ResultVo(1, "开始课程数据不能为空");
752
+            Integer classid = startclass.getClassid();
753
+            Long roomid = startclass.getRoomid();
754
+            Integer schoolid = startclass.getSchoolid();
755
+            Integer num = classroomMapper.getStudentNumById(classid);//根据班级id获取学生数量
756
+            startclass.setClassnum(num);
757
+            classroomMapper.save(startclass);//批量保存课堂
758
+            classroomActivestudentMapper.saveStuActive(roomid, classid, schoolid);//批量添加学生课堂活跃度
759
+            if (N_Utils.isListNotEmpty(signList)) classroomSignMapper.insertList(signList);//批量保存学生签到
760
+
761
+            if (N_Utils.isListNotEmpty(askteacherList)) classroomAskteacherMapper.batchSave(askteacherList);//批量保存教师互动信息
762
+            if (N_Utils.isListNotEmpty(askstudentList))
763
+                classroomAskstudentMapper.insertList(askstudentList);//批量保存学生互动信息
764
+
765
+            if (N_Utils.isListNotEmpty(activestudentList))
766
+                classroomActivestudentMapper.batchUpdateActiveNum(activestudentList);//批量更新学生活跃值
767
+
768
+            if (N_Utils.isListNotEmpty(savefileList)) classroomFileMapper.insertList(savefileList);//批量保存课堂图片
769
+
770
+            if (N_Utils.isListNotEmpty(paperList)) classroomPaperMapper.batchSave(paperList);//批量保存堂测
771
+            if (N_Utils.isListNotEmpty(paperFileList)) classroomPaperFileMapper.insertList(paperFileList);//批量保存堂测附件
772
+            if (N_Utils.isListNotEmpty(paperQtypeList)) classroomPaperQtypeMapper.batchSave(paperQtypeList);//批量保存堂测答题卡
773
+            if (N_Utils.isListNotEmpty(paperScantronList))
774
+                classroomPaperScantronMapper.batchSave(paperScantronList);//批量保存堂测答题卡--题型试题
775
+
776
+            if (N_Utils.isListNotEmpty(stupaperList)) {
777
+                classroomPaperStudentMapper.insertList(stupaperList);//批量保存堂测--学生作答详情
778
+                List<TClassroomPaperStudentScantron> studentScantronList = new ArrayList<>();//堂测--学生作答详情
779
+                List<TClassroomPaperStudent> studentScoreList = new ArrayList<>();//堂测--学生得分
780
+                setPaperStudentScantron(stupaperList, studentScantronList, studentScoreList);
781
+                classroomPaperStudentScantronMapper.insertList(studentScantronList);//批量保存堂测--学生作答详情
782
+                classroomPaperStudentMapper.batchUpdateScantronStuScoreAndChecked(studentScoreList);//批量修改学生得分和批改状态
783
+            }
784
+
785
+            if (stopclass != null) classroomMapper.endClass(stopclass);//批量结束课堂
786
+
787
+            classroomMapper.updateBatchRoomRealStunum(Arrays.asList(roomid));//批量更新班级实际签到学生数量
788
+            classroomActivestudentMapper.updateActiveRank(roomid);//批量更新活跃值排名
789
+
790
+            classroomMapper.updateBatchRoomState(Arrays.asList(classid));//批量结束之前班级的课堂状态
791
+            resultVo.setCode(0);
792
+            resultVo.setMsg("保存成功");
793
+        } catch (Exception e) {
794
+            log.error("批量保存课堂数据失败:" + e.getMessage());
795
+            resultVo.setMsg("保存失败");
796
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
797
+        }
798
+        return resultVo;
799
+    }
800
+
801
+    /**
802
+     * 根据课堂id获取课堂名称
803
+     *
804
+     * @return java.lang.String
805
+     * @Param [roomid]
806
+     * @Author ywx
807
+     * @Date 2022/6/30 11:21
808
+     **/
809
+    public String getNameById(Long roomid) {
810
+        return classroomMapper.getNameById(roomid);
811
+    }
733 812
 }

+ 6
- 1
sclass/src/main/resources/mapper/classroom/ClassroomMapper.xml View File

@@ -229,9 +229,10 @@
229 229
     </select>
230 230
     <select id="getReportStu" resultMap="stuRoomResult">
231 231
         select r.roomid,r.roomname,r.endtime,r.createtime,r.classnum,r.realstunum,#{studentid} studentid,
232
-        u.username as teachername,d.directorname
232
+        u.username as teachername,d.directorname,c.gradeid,c.classname
233 233
         from t_classroom r left join t_user u on r.teacherid=u.userid
234 234
         left join t_director d on r.directorid=d.directorid
235
+        left join t_class c on r.classid=c.classid
235 236
         where r.roomid=#{roomid} limit 1
236 237
     </select>
237 238
     <select id="listStuCall" resultType="java.util.Map">
@@ -488,4 +489,8 @@
488 489
             ${classid}
489 490
         </foreach>
490 491
     </select>
492
+    <!--根据课堂id获取课堂名称-->
493
+    <select id="getNameById" resultType="java.lang.String">
494
+        select roomname from t_classroom where roomid=#{roomid}
495
+    </select>
491 496
 </mapper>

Loading…
Cancel
Save