he2802 4 år sedan
förälder
incheckning
4335881678

+ 18 - 8
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseChapterSectionServiceImpl.java

@@ -8,6 +8,7 @@ import com.zhongzheng.modules.course.bo.CourseChapterSectionAddBo;
 import com.zhongzheng.modules.course.bo.CourseChapterSectionEditBo;
 import com.zhongzheng.modules.course.bo.CourseChapterSectionQueryBo;
 import com.zhongzheng.modules.course.domain.CourseChapterSection;
+import com.zhongzheng.modules.course.domain.CourseStreamingBusiness;
 import com.zhongzheng.modules.course.mapper.CourseChapterMapper;
 import com.zhongzheng.modules.course.mapper.CourseChapterSectionMapper;
 import com.zhongzheng.modules.course.service.ICourseChapterSectionService;
@@ -18,9 +19,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.pagehelper.Page;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -81,17 +84,24 @@ public class CourseChapterSectionServiceImpl extends ServiceImpl<CourseChapterSe
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Boolean insertByAddBo(CourseChapterSectionAddBo bo) {
         Boolean result = false;
-        for(int i=0;i<bo.getSectionIdList().size();i++){
-            Long sectionId = bo.getSectionIdList().get(i).getSectionId();
-            Long sort = bo.getSectionIdList().get(i).getSort();
-            CourseChapterSection add = new CourseChapterSection();
-            add.setChapterId(bo.getChapterId());
-            add.setSectionId(sectionId);
-            add.setSort(sort);
-            result = this.save(add);
+        if(bo.getSectionIdList()!=null){
+            this.remove(new LambdaQueryWrapper<CourseChapterSection>().eq(CourseChapterSection::getChapterId, bo.getChapterId()));
+            Collection<CourseChapterSection> coll = new HashSet<>();
+            for(int i=0;i<bo.getSectionIdList().size();i++){
+                Long sectionId = bo.getSectionIdList().get(i).getSectionId();
+                Long sort = bo.getSectionIdList().get(i).getSort();
+                CourseChapterSection add = new CourseChapterSection();
+                add.setChapterId(bo.getChapterId());
+                add.setSectionId(sectionId);
+                add.setSort(sort);
+                coll.add(add);
+            }
+            this.saveBatch(coll);
         }
+
         return result;
     }