Browse Source

优化保存单个单元格

tags/正式3.2.0
王宁 2 years ago
parent
commit
5d698add8d
1 changed files with 75 additions and 64 deletions
  1. 75
    64
      slive/src/main/java/com/xhkjedu/slive/service/xz/XzService.java

+ 75
- 64
slive/src/main/java/com/xhkjedu/slive/service/xz/XzService.java View File

@@ -372,6 +372,10 @@ public class XzService {
372 372
             List classidlst = xjTeas.stream().map(XzDateKjTeaVo::getClassid).collect(Collectors.toList());
373 373
             List<Map> users = courseMapper.listUid(classidlst);//获取课班级下学生
374 374
 
375
+            if(users==null || users.size()==0){
376
+                throw new Exception("所选班级无学生");
377
+            }
378
+
375 379
             //新生成直播班班级信息
376 380
             TClass c = new TClass();
377 381
             c.setClassname(course.getCoursename() + "班");
@@ -570,7 +574,7 @@ public class XzService {
570 574
             //先判断是保存当前课程还是后续日期的课
571 575
             if (N_Utils.isEmptyInteger(kjTeaVo.getKfollow())) {
572 576
                 //kfollow为0或者空,则只需要保存当前选中的课程
573
-                courseid = ((XzService) applicationContext.getBean("xzService")).saveOneXzkjDygForDetail(kjTeaVo);
577
+                courseid = saveOneXzkjDygForDetail(kjTeaVo);
574 578
             } else {
575 579
                 //需要保存后续和当前日期相同的星期相同课节的课程,判断后续日期是否有课程,如果有则提示先删除后再添加
576 580
                 //获取已生成课程的往后日期
@@ -589,7 +593,7 @@ public class XzService {
589 593
                 for (int i = 0; i < savedates.size(); i++) {
590 594
                     kjTeaVo.setSeldate(savedates.get(i));
591 595
 
592
-                    Integer rtnid = ((XzService)applicationContext.getBean("xzService")).saveOneXzkjDygForDetail(kjTeaVo);
596
+                    Integer rtnid = saveOneXzkjDygForDetail(kjTeaVo);
593 597
                     if(i==0){
594 598
                         courseid = rtnid;
595 599
                     }
@@ -603,73 +607,80 @@ public class XzService {
603 607
         }
604 608
     }
605 609
 
606
-    //保存单个课程
607
-    @Transactional(rollbackFor = Exception.class)
608
-    public Integer saveOneXzkjDygForDetail(XzDateKjTeaVo kjTeaVo) {
610
+    //判断单个课程是否存在如果存在只需要合并班级不存在保存单个课程
611
+    private Integer saveOneXzkjDygForDetail(XzDateKjTeaVo kjTeaVo) {
609 612
         Integer courseid = 0;
613
+        //先看新选择的教师情况,先判断选中的同一日期课节教师是否还有其他直播课
614
+        CourseVo courseVo = courseMapper.getCourseByDateKjTeacher(kjTeaVo);
615
+        if (courseVo == null) {
616
+            //说明该老师之前没有直播课,则直接保存为新的课程
617
+            LCourse course = new LCourse();
618
+            course.setGradeid(kjTeaVo.getGradeid());
619
+            course.setBegindate(kjTeaVo.getSeldate());
620
+            course.setEnddate(kjTeaVo.getSeldate());
621
+            course.setCoursenum(1);
622
+            course.setCoursetype(1);
623
+            course.setCourseclass(1);
624
+            course.setCoursestate(0);
625
+            course.setDeleted(1);
626
+            course.setCourseselected(0);
627
+            course.setCreateid(kjTeaVo.getCreateid());
628
+            course.setCreatetime(N_Utils.getSecondTimestamp());
629
+            course.setSchoolid(kjTeaVo.getSchoolid());
630
+
631
+            String datezhou = LiveUtil.getDateZhou(kjTeaVo.getSeldate());
632
+            LXzKj kj = xzKjMapper.selectByPrimaryKey(kjTeaVo.getKjid());//课节详情
633
+
634
+            //单个教师课程信息
635
+            String coursename = datezhou + kj.getKjname() + kjTeaVo.getSubjectname() + "(" + kjTeaVo.getTeachername() + ")";
636
+
637
+            course.setCoursename(coursename);
638
+            course.setSubjectid(kjTeaVo.getSubjectid());
639
+            course.setTeacherid(kjTeaVo.getTeacherid());
640
+            course.setBegintime(kj.getBegintime());
641
+            course.setEndtime(kj.getEndtime());
642
+            course.setKjid(kjTeaVo.getKjid());
643
+            //保存行政直播课程表,调用保存整个课表时的方法
644
+            List<XzDateKjTeaVo> lst = new ArrayList<>();
645
+            lst.add(kjTeaVo);
646
+            courseid = ((XzService) applicationContext.getBean("xzService")).saveCourseAll(lst, course);
647
+        } else {
648
+            courseid = courseVo.getCourseid();
649
+            ((XzService) applicationContext.getBean("xzService")).saveOneXzkjDygForDetailExist(kjTeaVo,courseVo);
650
+        }
651
+        return courseid;
652
+    }
653
+
654
+    //保存单个表格时同日期同课节教师合并成一个直播课
655
+    @Transactional(rollbackFor = Exception.class)
656
+    public void saveOneXzkjDygForDetailExist(XzDateKjTeaVo kjTeaVo, CourseVo courseVo){
610 657
         try {
611
-            //先看新选择的教师情况,先判断选中的同一日期课节教师是否还有其他直播课
612
-            CourseVo courseVo = courseMapper.getCourseByDateKjTeacher(kjTeaVo);
613
-            if (courseVo == null) {
614
-                //说明该老师之前没有直播课,则直接保存为新的课程
615
-                LCourse course = new LCourse();
616
-                course.setGradeid(kjTeaVo.getGradeid());
617
-                course.setBegindate(kjTeaVo.getSeldate());
618
-                course.setEnddate(kjTeaVo.getSeldate());
619
-                course.setCoursenum(1);
620
-                course.setCoursetype(1);
621
-                course.setCourseclass(1);
622
-                course.setCoursestate(0);
623
-                course.setDeleted(1);
624
-                course.setCourseselected(0);
625
-                course.setCreateid(kjTeaVo.getCreateid());
626
-                course.setCreatetime(N_Utils.getSecondTimestamp());
627
-                course.setSchoolid(kjTeaVo.getSchoolid());
628
-
629
-                String datezhou = LiveUtil.getDateZhou(kjTeaVo.getSeldate());
630
-                LXzKj kj = xzKjMapper.selectByPrimaryKey(kjTeaVo.getKjid());//课节详情
631
-
632
-                //单个教师课程信息
633
-                String coursename = datezhou + kj.getKjname() + kjTeaVo.getSubjectname() + "(" + kjTeaVo.getTeachername() + ")";
634
-
635
-                course.setCoursename(coursename);
636
-                course.setSubjectid(kjTeaVo.getSubjectid());
637
-                course.setTeacherid(kjTeaVo.getTeacherid());
638
-                course.setBegintime(kj.getBegintime());
639
-                course.setEndtime(kj.getEndtime());
640
-                course.setKjid(kjTeaVo.getKjid());
641
-                //保存行政直播课程表,调用保存整个课表时的方法
642
-                List<XzDateKjTeaVo> lst = new ArrayList<>();
643
-                lst.add(kjTeaVo);
644
-                courseid = ((XzService) applicationContext.getBean("xzService")).saveCourseAll(lst, course);
645
-            } else {
646
-                courseid = courseVo.getCourseid();
647
-                //保存直播关联班级
648
-                LCourseClass courseClass = new LCourseClass();
649
-                courseClass.setCourseid(courseid);
650
-                courseClass.setClassid(kjTeaVo.getClassid());
651
-                courseClass.setCreateid(kjTeaVo.getTeacherid());
652
-                courseClass.setCreatetime(N_Utils.getSecondTimestamp());
653
-                courseClassMapper.insertUseGeneratedKeys(courseClass);
654
-
655
-                //说明该教师当前有其他直播课,则把班级加入课程,完成直播课学生数量
656
-                TClassStudent cs = new TClassStudent();
657
-                cs.setSchoolid(kjTeaVo.getSchoolid());
658
-                cs.setClassid(kjTeaVo.getClassid());
659
-                cs.setCreateid(kjTeaVo.getCreateid());
660
-                classStudentMapper.saveAllClassStu(cs, courseVo.getClassid());
661
-                //获取直播班对应全班学生分组id
662
-                Integer groupid = groupMapper.getGroupIdByClassid(courseVo.getClassid());
663
-                groupMapper.saveAllClassGroupStu(cs, courseVo.getClassid(), groupid);
664
-                classMapper.updateNum2(courseVo.getClassid());//更改直播班级以及班级分组人数
665
-                courseMapper.updateStuNum(courseVo.getCourseid());//更新直播课学生数量
666
-            }
667
-        } catch (Exception e) {
668
-            log.error("保存单个课程出错:" + e.getMessage());
658
+
659
+            //保存直播关联班级
660
+            LCourseClass courseClass = new LCourseClass();
661
+            courseClass.setCourseid(courseVo.getCourseid());
662
+            courseClass.setClassid(kjTeaVo.getClassid());
663
+            courseClass.setCreateid(kjTeaVo.getTeacherid());
664
+            courseClass.setCreatetime(N_Utils.getSecondTimestamp());
665
+            courseClassMapper.insertUseGeneratedKeys(courseClass);
666
+
667
+            //说明该教师当前有其他直播课,则把班级加入课程,完成直播课学生数量
668
+            TClassStudent cs = new TClassStudent();
669
+            cs.setSchoolid(kjTeaVo.getSchoolid());
670
+            cs.setClassid(kjTeaVo.getClassid());
671
+            cs.setCreateid(kjTeaVo.getCreateid());
672
+            classStudentMapper.saveAllClassStu(cs, courseVo.getClassid());
673
+            //获取直播班对应全班学生分组id
674
+            Integer groupid = groupMapper.getGroupIdByClassid(courseVo.getClassid());
675
+            groupMapper.saveAllClassGroupStu(cs, courseVo.getClassid(), groupid);
676
+            classMapper.updateNum2(courseVo.getClassid());//更改直播班级以及班级分组人数
677
+            courseMapper.updateStuNum(courseVo.getCourseid());//更新直播课学生数量
678
+        }catch (Exception e){
679
+            log.error("保存单个课程(课程已存在合并班级)出错:" + e.getMessage());
669 680
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
670 681
         }
671
-        return courseid;
672 682
     }
673 683
 
674 684
 
685
+
675 686
 }

Loading…
Cancel
Save