|
|
|
@ -1,12 +1,22 @@ |
|
|
|
|
package com.teaching.backend.service.impl.chapter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.annotation.Link; |
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.teaching.backend.mapper.chapter.ChapterMapper; |
|
|
|
|
import com.teaching.backend.model.entity.chapter.Chapter; |
|
|
|
|
import com.teaching.backend.model.vo.chapter.ChapterVo; |
|
|
|
|
import com.teaching.backend.model.vo.courses.CoursesVO; |
|
|
|
|
import com.teaching.backend.service.chapter.IChapterService; |
|
|
|
|
import org.jetbrains.annotations.TestOnly; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @author author |
|
|
|
@ -14,4 +24,214 @@ import org.springframework.stereotype.Service; |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> implements IChapterService { |
|
|
|
|
@Autowired |
|
|
|
|
private ChapterMapper chapterMapper; |
|
|
|
|
// private int count=0;
|
|
|
|
|
List<Chapter> list=new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String updateNumShow(Chapter chapter) { |
|
|
|
|
|
|
|
|
|
String finalNumShow; |
|
|
|
|
String courseid = chapter.getCourseid(); |
|
|
|
|
String pid = chapter.getPid(); |
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
Long countChapter ; |
|
|
|
|
// pid为0时,说明为章
|
|
|
|
|
if("0".equals(pid)|| "".equals(pid)){ |
|
|
|
|
wrapper.eq(Chapter::getCourseid,courseid); |
|
|
|
|
countChapter = chapterMapper.selectCount(wrapper); |
|
|
|
|
finalNumShow=String.valueOf(countChapter+1); |
|
|
|
|
// chapter.setNumshow(String.valueOf(countChapter+1));
|
|
|
|
|
// System.out.println(chapter.getNumshow());
|
|
|
|
|
}else{ |
|
|
|
|
// 为小节
|
|
|
|
|
Chapter chapter1 = chapterMapper.selectById(pid); |
|
|
|
|
String parentNumShow =chapter1.getNumshow(); |
|
|
|
|
System.out.println("909090"); |
|
|
|
|
System.out.println(parentNumShow); |
|
|
|
|
wrapper.eq(Chapter::getCourseid,courseid) |
|
|
|
|
.eq(Chapter::getPid,pid); |
|
|
|
|
countChapter = chapterMapper.selectCount(wrapper); |
|
|
|
|
System.out.println("-=-=-=-=-="+countChapter); |
|
|
|
|
finalNumShow=parentNumShow + "-" + String.valueOf(countChapter + 1); |
|
|
|
|
} |
|
|
|
|
System.out.println("-=-=-=-=11"); |
|
|
|
|
System.out.println(finalNumShow); |
|
|
|
|
return finalNumShow; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedList<Chapter> getAll() { |
|
|
|
|
List<Chapter> list = chapterMapper.selectList(null); |
|
|
|
|
LinkedList<Chapter> linkedList = new LinkedList<>(list); |
|
|
|
|
int i=0; |
|
|
|
|
for (Chapter chapter:linkedList){ |
|
|
|
|
System.out.println(linkedList.get(i)); |
|
|
|
|
System.out.println(i+"----"+chapter); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
System.out.println(linkedList); |
|
|
|
|
return linkedList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedList<Chapter> getCourseChapter(String courseid) { |
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseid,courseid) |
|
|
|
|
.orderByAsc(Chapter::getNumshow); |
|
|
|
|
List<Chapter> list = chapterMapper.selectList(wrapper); |
|
|
|
|
LinkedList<Chapter> linkedList = new LinkedList<>(list); |
|
|
|
|
return linkedList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedList<ChapterVo> getChapterSection(String courseid){ |
|
|
|
|
// LinkedList<Chapter> list = new LinkedList<>();
|
|
|
|
|
// 获得所有的节,并按顺序进行排列
|
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseid,courseid) |
|
|
|
|
.like(Chapter::getNumshow,"-") |
|
|
|
|
.orderByAsc(Chapter::getNumshow); |
|
|
|
|
List<Chapter> prelist = chapterMapper.selectList(wrapper); |
|
|
|
|
System.out.println("所有的节"); |
|
|
|
|
System.out.println(prelist); |
|
|
|
|
// 获得所有的章节信息
|
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper1 = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper1.eq(Chapter::getCourseid,courseid) |
|
|
|
|
.notLike(Chapter::getNumshow,"-") |
|
|
|
|
.orderByAsc(Chapter::getNumshow); |
|
|
|
|
List<Chapter> chapterList = chapterMapper.selectList(wrapper1); |
|
|
|
|
System.out.println("0-0-0-0所有的章------------"); |
|
|
|
|
System.out.println(chapterList); |
|
|
|
|
// 类型转换chapter => chapterVo
|
|
|
|
|
List<ChapterVo> chapterVoList = BeanUtil.copyToList(chapterList, ChapterVo.class); |
|
|
|
|
chapterVoList = chapterVoList.stream().map((item) ->{ |
|
|
|
|
for (int i=0;i<prelist.size();i++){ |
|
|
|
|
System.out.println("====================="); |
|
|
|
|
// System.out.println(prelist.get(i).getNumshow().split("-")[0].equals(item.getNumshow()));
|
|
|
|
|
if (prelist.get(i).getNumshow().split("-")[0].equals(item.getNumshow())){ |
|
|
|
|
// System.out.println(item.getNumshow()+"[][][]"+i);
|
|
|
|
|
System.out.println("88888888888888888888888888"+prelist.get(i).getNumshow().split("-")[0]); |
|
|
|
|
// Chapter chapter = prelist.get(i);
|
|
|
|
|
list.add(prelist.get(i)); |
|
|
|
|
item.setChapterSection(list); |
|
|
|
|
System.out.println(prelist.get(i).getNumshow()+"-------------+121--"); |
|
|
|
|
}else { |
|
|
|
|
// list1=list;
|
|
|
|
|
// System.out.println(item.getNumshow() + "[8888][][]");
|
|
|
|
|
// System.out.println(prelist.get(i).getNumshow().split("-")[0]);
|
|
|
|
|
// item.setChapterSection(list1);
|
|
|
|
|
System.out.println("000000000"); |
|
|
|
|
System.out.println(list); |
|
|
|
|
list = new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return item; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
System.out.println("11111111111111111111111111111111111111111"); |
|
|
|
|
System.out.println(chapterVoList); |
|
|
|
|
LinkedList<ChapterVo> list2 = new LinkedList<>(chapterVoList); |
|
|
|
|
return list2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean deleteAfterUpdate(String id) { |
|
|
|
|
Chapter chapter = chapterMapper.selectById(id); |
|
|
|
|
String numshow = chapter.getNumshow(); |
|
|
|
|
String courseid = chapter.getCourseid(); |
|
|
|
|
updateNumShow(numshow, courseid); |
|
|
|
|
chapterMapper.deleteById(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
public void updateNumShow(String numshow, String courseid){ |
|
|
|
|
// 查询课程章节 getCourseChapter
|
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseid,courseid) |
|
|
|
|
.orderByAsc(Chapter::getNumshow); |
|
|
|
|
List<Chapter> chapterList = chapterMapper.selectList(wrapper); |
|
|
|
|
System.out.println("0-0-0-0-00-------"); |
|
|
|
|
System.out.println(chapterList); |
|
|
|
|
List<Chapter> newlist = new ArrayList<>(); |
|
|
|
|
int count=0,j=0; |
|
|
|
|
int i = numshow.indexOf("-"); |
|
|
|
|
// 删除的为章
|
|
|
|
|
if(i==-1){ |
|
|
|
|
System.out.println("9999999"); |
|
|
|
|
for(int k=0;k<chapterList.size();k++){ |
|
|
|
|
// System.out.println("=-=-=--="+k+"-=-=-==-"+numshow);
|
|
|
|
|
// System.out.println(chapterList.get(k).getNumshow());
|
|
|
|
|
// System.out.println(chapterList.get(k).getNumshow().equals(numshow));
|
|
|
|
|
if (chapterList.get(k).getNumshow().equals(numshow)){ |
|
|
|
|
j=k; |
|
|
|
|
}else if (chapterList.get(k).getNumshow().contains(numshow+"-")){ |
|
|
|
|
count++; |
|
|
|
|
chapterMapper.deleteById(chapterList.get(k).getId()); |
|
|
|
|
}else{ |
|
|
|
|
System.out.println(chapterList.get(k)); |
|
|
|
|
newlist.add(chapterList.get(k)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println("======"+count+"======"+j); |
|
|
|
|
System.out.println(newlist); |
|
|
|
|
for (int k=j;k< newlist.size();k++){ |
|
|
|
|
Chapter chapter= newlist.get(k); |
|
|
|
|
if (newlist.get(k).getNumshow().indexOf("-")==-1){ |
|
|
|
|
chapter.setNumshow(String.valueOf(Integer.parseInt(newlist.get(k).getNumshow())-1)); |
|
|
|
|
chapterMapper.updateById(chapter); |
|
|
|
|
newlist.set(k,chapter); |
|
|
|
|
}else{ |
|
|
|
|
String[] split = newlist.get(k).getNumshow().split("-"); |
|
|
|
|
String s = String.valueOf(Integer.parseInt(split[0]) - 1); |
|
|
|
|
chapter.setNumshow(s+"-"+split[1]); |
|
|
|
|
chapterMapper.updateById(chapter); |
|
|
|
|
System.out.println(chapter); |
|
|
|
|
newlist.set(k,chapter); |
|
|
|
|
} |
|
|
|
|
// if (list.get(k).getNumshow().contains(numshow+"-") ){
|
|
|
|
|
// chapterMapper.deleteById(list.get(i).getId());
|
|
|
|
|
// }else{
|
|
|
|
|
// int num = Integer.parseInt(list.get(i).getNumshow()) - 1;
|
|
|
|
|
// list.get(i).setNumshow( String.valueOf(num) );
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
String[] split = numshow.split("-"); |
|
|
|
|
for (int k=0;k< chapterList.size();k++){ |
|
|
|
|
System.out.println("009988"+String.valueOf(Integer.parseInt(split[0])+1)); |
|
|
|
|
// 找到下一章的起始点
|
|
|
|
|
if (chapterList.get(k).getNumshow().equals(String.valueOf(Integer.parseInt(split[0])+1))){ |
|
|
|
|
count=k; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (chapterList.get(k).getNumshow().equals(numshow)){ |
|
|
|
|
j=k; |
|
|
|
|
chapterMapper.deleteById(chapterList.get(k).getId()); |
|
|
|
|
}else{ |
|
|
|
|
newlist.add(chapterList.get(k)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println(count+"''''''"+j); |
|
|
|
|
for (int k=j;k<count-1;k++){ |
|
|
|
|
// System.out.println(newlist.get(k));
|
|
|
|
|
String[] split1 = newlist.get(k).getNumshow().split("-"); |
|
|
|
|
String s = split1[0]+"-"+String.valueOf(Integer.parseInt(split1[1]) - 1); |
|
|
|
|
Chapter chapter= newlist.get(k); |
|
|
|
|
chapter.setNumshow(s); |
|
|
|
|
chapterMapper.updateById(chapter); |
|
|
|
|
newlist.set(k,chapter); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println("111111111110-0-0-0-00-------"); |
|
|
|
|
System.out.println(newlist); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// public LinkedList<ChapterVo> deleteChapterSection(String courseid,String numshow){
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|