|
|
|
@ -4,24 +4,32 @@ package com.teaching.backend.service.impl.chapter; |
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.teaching.backend.common.ErrorCode; |
|
|
|
|
import com.teaching.backend.exception.BusinessException; |
|
|
|
|
|
|
|
|
|
import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; |
|
|
|
|
import com.teaching.backend.mapper.chapter.ChapterMapper; |
|
|
|
|
import com.teaching.backend.mapper.chapter.TemporaryChapterMapper; |
|
|
|
|
import com.teaching.backend.model.dto.chapter.ChapterDTO; |
|
|
|
|
|
|
|
|
|
import com.teaching.backend.model.entity.chapter.Chapter; |
|
|
|
|
import com.teaching.backend.model.entity.chapter.TemporaryChapter; |
|
|
|
|
import com.teaching.backend.model.entity.knowtmp.Knowtmp; |
|
|
|
|
import com.teaching.backend.model.vo.chapter.ChapterVo; |
|
|
|
|
|
|
|
|
|
import com.teaching.backend.service.Know.KnowService; |
|
|
|
|
import com.teaching.backend.service.chapter.IChapterService; |
|
|
|
|
import com.teaching.backend.utils.Chapter.ExcelUtils; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -33,14 +41,16 @@ import java.util.stream.Collectors; |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> implements IChapterService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ChapterMapper chapterMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private KnowtmpMapper knowtmpMapper; |
|
|
|
|
// private int count=0;
|
|
|
|
|
List<Chapter> list=new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
private TemporaryChapterMapper temporaryChapterMapper; |
|
|
|
|
@Autowired |
|
|
|
|
private KnowtmpMapper knowtmpMapper; |
|
|
|
|
// private int count=0;
|
|
|
|
|
List<Chapter> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -50,26 +60,26 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
String courseid = chapter.getCourseId(); |
|
|
|
|
Long pid = chapter.getPid(); |
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
Long countChapter ; |
|
|
|
|
Long countChapter; |
|
|
|
|
// pid为0时,说明为章
|
|
|
|
|
if("0".equals(pid)|| "".equals(pid)){ |
|
|
|
|
wrapper.eq(Chapter::getCourseId,courseid); |
|
|
|
|
if ("0".equals(pid) || "".equals(pid)) { |
|
|
|
|
wrapper.eq(Chapter::getCourseId, courseid); |
|
|
|
|
countChapter = chapterMapper.selectCount(wrapper); |
|
|
|
|
|
|
|
|
|
finalNumShow=String.valueOf(countChapter+1); |
|
|
|
|
finalNumShow = String.valueOf(countChapter + 1); |
|
|
|
|
// chapter.setNumshow(String.valueOf(countChapter+1));
|
|
|
|
|
// System.out.println(chapter.getNumshow());
|
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
// 为小节
|
|
|
|
|
Chapter chapter1 = chapterMapper.selectById(pid); |
|
|
|
|
String parentNumShow =chapter1.getNumshow(); |
|
|
|
|
String parentNumShow = chapter1.getNumshow(); |
|
|
|
|
System.out.println("909090"); |
|
|
|
|
System.out.println(parentNumShow); |
|
|
|
|
wrapper.eq(Chapter::getCourseId,courseid) |
|
|
|
|
.eq(Chapter::getPid,pid); |
|
|
|
|
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("-=-=-=-=-=" + countChapter); |
|
|
|
|
finalNumShow = parentNumShow + "-" + String.valueOf(countChapter + 1); |
|
|
|
|
} |
|
|
|
|
System.out.println("-=-=-=-=11"); |
|
|
|
|
System.out.println(finalNumShow); |
|
|
|
@ -80,10 +90,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
public LinkedList<Chapter> getAll() { |
|
|
|
|
List<Chapter> list = chapterMapper.selectList(null); |
|
|
|
|
LinkedList<Chapter> linkedList = new LinkedList<>(list); |
|
|
|
|
int i=0; |
|
|
|
|
for (Chapter chapter:linkedList){ |
|
|
|
|
int i = 0; |
|
|
|
|
for (Chapter chapter : linkedList) { |
|
|
|
|
System.out.println(linkedList.get(i)); |
|
|
|
|
System.out.println(i+"----"+chapter); |
|
|
|
|
System.out.println(i + "----" + chapter); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
System.out.println(linkedList); |
|
|
|
@ -93,7 +103,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
@Override |
|
|
|
|
public LinkedList<Chapter> getCourseChapter(String courseid) { |
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseId,courseid) |
|
|
|
|
wrapper.eq(Chapter::getCourseId, courseid) |
|
|
|
|
.orderByAsc(Chapter::getNumshow); |
|
|
|
|
List<Chapter> list = chapterMapper.selectList(wrapper); |
|
|
|
|
LinkedList<Chapter> linkedList = new LinkedList<>(list); |
|
|
|
@ -101,38 +111,38 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public LinkedList<ChapterVo> getChapterSection(String courseid){ |
|
|
|
|
public LinkedList<ChapterVo> getChapterSection(String courseid) { |
|
|
|
|
// LinkedList<Chapter> list = new LinkedList<>();
|
|
|
|
|
// 获得所有的节,并按顺序进行排列
|
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseId,courseid) |
|
|
|
|
.like(Chapter::getNumshow,"-") |
|
|
|
|
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,"-") |
|
|
|
|
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++){ |
|
|
|
|
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())){ |
|
|
|
|
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]); |
|
|
|
|
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 { |
|
|
|
|
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]);
|
|
|
|
@ -166,27 +176,27 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
@Override |
|
|
|
|
public List<Chapter> getChapterTree(String courseId) { |
|
|
|
|
|
|
|
|
|
List<Chapter> chapters=baseMapper.selectSectionsByCourseId(courseId); |
|
|
|
|
List<Chapter> chapters = baseMapper.selectSectionsByCourseId(courseId); |
|
|
|
|
|
|
|
|
|
Map<Long,Chapter> chapterMap=new HashMap<>(); |
|
|
|
|
Map<Long, Chapter> chapterMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
List<Chapter> roots=new ArrayList<>(); |
|
|
|
|
List<Chapter> roots = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (Chapter chapter:chapters){ |
|
|
|
|
for (Chapter chapter : chapters) { |
|
|
|
|
|
|
|
|
|
chapter.setChildren(new ArrayList<>()); |
|
|
|
|
chapter.setKnowledgePoints(new ArrayList<>()); |
|
|
|
|
chapterMap.put(chapter.getId(),chapter); |
|
|
|
|
chapterMap.put(chapter.getId(), chapter); |
|
|
|
|
} |
|
|
|
|
for (Chapter chapter:chapters){ |
|
|
|
|
Long parentId=chapter.getPid(); |
|
|
|
|
if (parentId!=0){ |
|
|
|
|
Chapter parentChapter=chapterMap.get(parentId); |
|
|
|
|
for (Chapter chapter : chapters) { |
|
|
|
|
Long parentId = chapter.getPid(); |
|
|
|
|
if (parentId != 0) { |
|
|
|
|
Chapter parentChapter = chapterMap.get(parentId); |
|
|
|
|
if (parentChapter != null) { |
|
|
|
|
parentChapter.getChildren().add(chapter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
roots.add(chapter); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -208,15 +218,16 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
chapter.setChildren(sortedChildren); |
|
|
|
|
QueryWrapper<Knowtmp>queryWrapper = new QueryWrapper<>(); |
|
|
|
|
QueryWrapper<Knowtmp> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
for (Chapter child : sortedChildren) { |
|
|
|
|
queryWrapper.eq("chapterId",child.getId()); |
|
|
|
|
queryWrapper.eq("chapterId", child.getId()); |
|
|
|
|
List<Knowtmp> knows = knowtmpMapper.selectList(queryWrapper); |
|
|
|
|
child.setKnowledgePoints(new ArrayList<>(knows)); |
|
|
|
|
|
|
|
|
|
loadKnowledgePointsRecursively(child); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void saveChapter(ChapterDTO chapterDTO) { |
|
|
|
|
|
|
|
|
@ -227,7 +238,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
throw new RuntimeException("复制数据出错", e); |
|
|
|
|
} |
|
|
|
|
Long pid = chapter.getPid(); |
|
|
|
|
if (pid == null ) { |
|
|
|
|
if (pid == null) { |
|
|
|
|
chapter.setPid(0L); |
|
|
|
|
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
maxSortWrapper.eq(Chapter::getPid, 0).orderByDesc(Chapter::getOrderNum).last("limit 1"); |
|
|
|
@ -247,7 +258,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
if (parentChapter != null) { |
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
maxSortWrapper.eq(Chapter::getPid,pid).orderByDesc(Chapter::getOrderNum).last("limit 1"); |
|
|
|
|
maxSortWrapper.eq(Chapter::getPid, pid).orderByDesc(Chapter::getOrderNum).last("limit 1"); |
|
|
|
|
|
|
|
|
|
parentChapter.setUpdateTime(LocalDateTime.now()); |
|
|
|
|
Chapter maxSortChapter = this.getOne(maxSortWrapper); |
|
|
|
@ -264,11 +275,65 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
chapter.setUpdateTime(LocalDateTime.now()); |
|
|
|
|
this.save(chapter); |
|
|
|
|
} else { |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR,"未找到父章节,ID 为: " + pid); |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "未找到父章节,ID 为: " + pid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Long saveExcelChapter2(ChapterDTO chapterDTO, boolean isParent) { |
|
|
|
|
Chapter chapter = new Chapter(); |
|
|
|
|
try { |
|
|
|
|
BeanUtils.copyProperties(chapterDTO, chapter); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("复制数据出错", e); // 使用自定义异常
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
chapter.setCreateTime(now); |
|
|
|
|
chapter.setUpdateTime(now); |
|
|
|
|
|
|
|
|
|
Long pid = chapter.getPid(); |
|
|
|
|
if (isParent) { |
|
|
|
|
if (pid == null || pid == 0) { |
|
|
|
|
chapter.setPid(0L); |
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
maxSortWrapper.eq(Chapter::getPid, 0).orderByDesc(Chapter::getOrderNum).last("limit 1"); |
|
|
|
|
|
|
|
|
|
Chapter maxSortChapter = this.getOne(maxSortWrapper); |
|
|
|
|
double newSort = (maxSortChapter != null) ? maxSortChapter.getOrderNum() + 1 : 1; |
|
|
|
|
|
|
|
|
|
chapter.setOrderNum(newSort); |
|
|
|
|
this.save(chapter); |
|
|
|
|
|
|
|
|
|
return chapter.getId(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Chapter parentChapter = this.getById(pid); |
|
|
|
|
if (parentChapter != null) { |
|
|
|
|
LambdaQueryWrapper<Chapter> maxSortWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
maxSortWrapper.eq(Chapter::getPid, pid).orderByDesc(Chapter::getOrderNum).last("limit 1"); |
|
|
|
|
|
|
|
|
|
Chapter maxSortChapter = this.getOne(maxSortWrapper); |
|
|
|
|
double newSort = (maxSortChapter != null) ? maxSortChapter.getOrderNum() + 1 : 1; |
|
|
|
|
|
|
|
|
|
chapter.setOrderNum(newSort); |
|
|
|
|
|
|
|
|
|
parentChapter.setUpdateTime(now); |
|
|
|
|
this.updateById(parentChapter); |
|
|
|
|
|
|
|
|
|
this.save(chapter); |
|
|
|
|
|
|
|
|
|
return chapter.getId(); |
|
|
|
|
} else { |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "未找到父章节,ID 为: " + pid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void insertChapter(Long chapterId1, Long chapterId2, ChapterDTO newChapterDTO) { |
|
|
|
|
|
|
|
|
@ -279,13 +344,14 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
throw new RuntimeException("复制数据出错", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (chapterId1 == null && chapterId2 == null||chapterId1!=null && chapterId2==null) { |
|
|
|
|
if (chapterId1 == null && chapterId2 == null || chapterId1 != null && chapterId2 == null) { |
|
|
|
|
handleRootChapterInsertion(chapter); |
|
|
|
|
} else { |
|
|
|
|
handleChapterInsertion(chapterId1, chapterId2, chapter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void handleRootChapterInsertion(Chapter chapter) { |
|
|
|
|
Long pid = chapter.getPid(); |
|
|
|
|
if (pid == null) { |
|
|
|
@ -343,11 +409,149 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
public void upChapter(Long chapterId) { |
|
|
|
|
moveChapter(chapterId, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void downChapter(Long chapterId) { |
|
|
|
|
moveChapter(chapterId, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void downExcel(HttpServletResponse response) throws IOException { |
|
|
|
|
ExcelUtils.createTemplateExcel(response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Page<Chapter> getAllChapters(int page, int pageSize) { |
|
|
|
|
|
|
|
|
|
Page<Chapter> pageInfo = new Page<>(page, pageSize); |
|
|
|
|
LambdaQueryWrapper<Chapter> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
this.page(pageInfo, queryWrapper); |
|
|
|
|
|
|
|
|
|
return pageInfo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Chapter selectChapter(Long chapterId) { |
|
|
|
|
LambdaQueryWrapper<Chapter> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
lambdaQueryWrapper.eq(Chapter::getId, chapterId); |
|
|
|
|
|
|
|
|
|
Chapter chapter = this.getOne(lambdaQueryWrapper); |
|
|
|
|
if (chapter == null) { |
|
|
|
|
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "请求数据不存在"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (chapter.getPid() == 0) { |
|
|
|
|
String courseId = chapter.getCourseId(); |
|
|
|
|
List<Chapter> subChapters = chapterMapper.selectByIdAndPid(chapterId, courseId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal totalClassHours = BigDecimal.ZERO; |
|
|
|
|
for (Chapter subChapter : subChapters) { |
|
|
|
|
try { |
|
|
|
|
BigDecimal classHours = new BigDecimal(subChapter.getTotalClassHours()); |
|
|
|
|
totalClassHours = totalClassHours.add(classHours); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "无效的总学时数据"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chapter.setTotalClassHours(String.valueOf(totalClassHours)); |
|
|
|
|
} else { |
|
|
|
|
chapter.setTotalClassHours(chapter.getTotalClassHours()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return chapter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void downLoadXlsx(HttpServletResponse response, String courseId) throws IOException { |
|
|
|
|
LambdaQueryWrapper<Chapter> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
lambdaQueryWrapper.eq(Chapter::getCourseId, courseId); |
|
|
|
|
|
|
|
|
|
List<Chapter> chapterList = this.list(lambdaQueryWrapper); |
|
|
|
|
ExcelUtils.createDataExcel(response, chapterList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void moveDataFromTemporaryToFinal() { |
|
|
|
|
List<TemporaryChapter> temporaryChapters = temporaryChapterMapper.selectAll(); |
|
|
|
|
Map<Long, Long> tempIdToFinalIdMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
for (TemporaryChapter tempChapter : temporaryChapters) { |
|
|
|
|
|
|
|
|
|
Chapter existingChapter = chapterMapper.selectByNameAndCourseId(tempChapter.getName(), tempChapter.getCourseId()); |
|
|
|
|
if (existingChapter != null) { |
|
|
|
|
tempIdToFinalIdMap.put(tempChapter.getId(), existingChapter.getId()); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chapter finalChapter = new Chapter(); |
|
|
|
|
try { |
|
|
|
|
BeanUtils.copyProperties(tempChapter, finalChapter); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("复制数据出错", e); |
|
|
|
|
} |
|
|
|
|
finalChapter.setId(null); |
|
|
|
|
this.save(finalChapter); |
|
|
|
|
tempIdToFinalIdMap.put(tempChapter.getId(), finalChapter.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (TemporaryChapter tempChapter : temporaryChapters) { |
|
|
|
|
if (tempChapter.getPid() != 0) { |
|
|
|
|
Long newPid = tempIdToFinalIdMap.get(tempChapter.getPid()); |
|
|
|
|
if (newPid != null) { |
|
|
|
|
chapterMapper.updatePidById(tempIdToFinalIdMap.get(tempChapter.getId()), newPid); |
|
|
|
|
} else { |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "未找到父章节,临时表 ID 为: " + tempChapter.getPid()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
temporaryChapterMapper.deleteAll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Long saveToTemporaryTable(ChapterDTO chapterDTO) { |
|
|
|
|
TemporaryChapter temporaryChapter = new TemporaryChapter(); |
|
|
|
|
try { |
|
|
|
|
BeanUtils.copyProperties(chapterDTO, temporaryChapter); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("复制数据出错", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Long pid = temporaryChapter.getPid(); |
|
|
|
|
if (pid == null || pid == 0) { |
|
|
|
|
temporaryChapter.setPid(0L); |
|
|
|
|
setChapterOrder(temporaryChapter, 0L); |
|
|
|
|
} else { |
|
|
|
|
TemporaryChapter parentChapter = temporaryChapterMapper.selectById(pid); |
|
|
|
|
if (parentChapter != null) { |
|
|
|
|
temporaryChapter.setPid(parentChapter.getId()); |
|
|
|
|
setChapterOrder(temporaryChapter, pid); |
|
|
|
|
} else { |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "未找到父章节,ID 为: " + pid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
temporaryChapterMapper.insert(temporaryChapter); |
|
|
|
|
return temporaryChapter.getId(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setChapterOrder(TemporaryChapter chapter, Long pid) { |
|
|
|
|
TemporaryChapter maxSortChapter = temporaryChapterMapper.selectOneByPidAndOrderNumDesc(pid); |
|
|
|
|
double newSort = (maxSortChapter != null) ? maxSortChapter.getOrderNum() + 1 : 1; |
|
|
|
|
chapter.setOrderNum(newSort); |
|
|
|
|
chapter.setCreateTime(LocalDateTime.now()); |
|
|
|
|
chapter.setUpdateTime(LocalDateTime.now()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void moveChapter(Long chapterId, boolean moveUp) { |
|
|
|
@ -402,79 +606,80 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
updateChapter.setOrderNum(newOrderNum); |
|
|
|
|
this.updateById(updateChapter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void deleteChapter(Long id) { |
|
|
|
|
if (id==null){ |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR,"请求参数不能为空"); |
|
|
|
|
if (id == null) { |
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); |
|
|
|
|
} |
|
|
|
|
LambdaQueryWrapper<Chapter>queryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
|
queryWrapper.eq(Chapter::getId,id); |
|
|
|
|
LambdaQueryWrapper<Chapter> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
queryWrapper.eq(Chapter::getId, id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Chapter>lambdaQueryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
|
lambdaQueryWrapper.eq(Chapter::getPid,id); |
|
|
|
|
Long count= this.count(lambdaQueryWrapper); |
|
|
|
|
LambdaQueryWrapper<Chapter> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
lambdaQueryWrapper.eq(Chapter::getPid, id); |
|
|
|
|
Long count = this.count(lambdaQueryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count>0){ |
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除"); |
|
|
|
|
} |
|
|
|
|
QueryWrapper<Knowtmp>queryWrapper1 = new QueryWrapper<>(); |
|
|
|
|
queryWrapper1.eq("chapterId",id); |
|
|
|
|
if (count > 0) { |
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "存在子章节,无法删除"); |
|
|
|
|
} |
|
|
|
|
QueryWrapper<Knowtmp> queryWrapper1 = new QueryWrapper<>(); |
|
|
|
|
queryWrapper1.eq("chapterId", id); |
|
|
|
|
List<Knowtmp> knows = knowtmpMapper.selectList(queryWrapper1); |
|
|
|
|
|
|
|
|
|
if (!knows.isEmpty()) { |
|
|
|
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除"); |
|
|
|
|
} |
|
|
|
|
this.remove(queryWrapper); |
|
|
|
|
this.remove(queryWrapper); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateNumShow(String numshow, String courseid){ |
|
|
|
|
public void updateNumShow(String numshow, String courseid) { |
|
|
|
|
// 查询课程章节 getCourseChapter
|
|
|
|
|
LambdaQueryWrapper<Chapter> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
wrapper.eq(Chapter::getCourseId,courseid) |
|
|
|
|
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 count = 0, j = 0; |
|
|
|
|
int i = numshow.indexOf("-"); |
|
|
|
|
// 删除的为章
|
|
|
|
|
if(i==-1){ |
|
|
|
|
if (i == -1) { |
|
|
|
|
System.out.println("9999999"); |
|
|
|
|
for(int k=0;k<chapterList.size();k++){ |
|
|
|
|
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+"-")){ |
|
|
|
|
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{ |
|
|
|
|
} else { |
|
|
|
|
System.out.println(chapterList.get(k)); |
|
|
|
|
newlist.add(chapterList.get(k)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println("======"+count+"======"+j); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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{
|
|
|
|
@ -482,32 +687,31 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl |
|
|
|
|
// list.get(i).setNumshow( String.valueOf(num) );
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
} else { |
|
|
|
|
String[] split = numshow.split("-"); |
|
|
|
|
for (int k=0;k< chapterList.size();k++){ |
|
|
|
|
System.out.println("009988"+String.valueOf(Integer.parseInt(split[0])+1)); |
|
|
|
|
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(String.valueOf(Integer.parseInt(split[0]) + 1))) { |
|
|
|
|
count = k; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (chapterList.get(k).getNumshow().equals(numshow)){ |
|
|
|
|
j=k; |
|
|
|
|
if (chapterList.get(k).getNumshow().equals(numshow)) { |
|
|
|
|
j = k; |
|
|
|
|
chapterMapper.deleteById(chapterList.get(k).getId()); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
newlist.add(chapterList.get(k)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println(count+"''''''"+j); |
|
|
|
|
for (int k=j;k<count-1;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); |
|
|
|
|
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); |
|
|
|
|
newlist.set(k, chapter); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|